annotate src/create_cmdidxs.vim @ 15189:9a93ea72e175

Added tag v8.1.0604 for changeset 2d8c31ae1e241a2d07364839884bcd21c3b62d4e
author Bram Moolenaar <Bram@vim.org>
date Sun, 16 Dec 2018 16:45:06 +0100
parents 889da8649221
children 854fb0ad4be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11374
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " This script generates the tables cmdidxs1[] and cmdidxs2[][] which,
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " given a Ex command, determine the first value to probe to find
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " a matching command in cmdnames[] based on the first character
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 " and the first 2 characters of the command.
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 " This is used to speed up lookup in cmdnames[].
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 "
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 " Script should be run every time new Ex commands are added in Vim,
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 " from the src/vim directory, since it reads commands from "ex_cmds.h".
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 let cmds = []
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 let skipped_cmds = 0
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 for line in readfile('ex_cmds.h')
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 if line =~ '^EX(CMD_'
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 let m = matchlist(line, '^EX(CMD_\S*,\s*"\([a-z][^"]*\)"')
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 if len(m) >= 2
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 let cmds += [ m[1] ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 else
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 let skipped_cmds += 1
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 endif
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 endif
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 endfor
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 let cmdidxs1 = {}
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 let cmdidxs2 = {}
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 for i in range(len(cmds) - 1, 0, -1)
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 let cmd = cmds[i]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 let c1 = cmd[0] " First character of command
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 let c2 = cmd[1] " Second character of command (if any)
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 let cmdidxs1{c1} = i
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 if c2 >= 'a' && c2 <= 'z'
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 let cmdidxs2{c1}{c2} = i
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 endif
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 endfor
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 let output = [ '/* Automatically generated code by create_cmdidxs.vim' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 let output += [ ' *' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 let output += [ ' * Table giving the index of the first command in cmdnames[] to lookup' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 let output += [ ' * based on the first letter of a command.' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 let output += [ ' */' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 let output += [ 'static const unsigned short cmdidxs1[26] =' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 let output += [ '{' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 let a_to_z = map(range(char2nr('a'), char2nr('z')), 'nr2char(v:val)')
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 for c1 in a_to_z
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 let line = ' /* ' . c1 . ' */ ' . cmdidxs1{c1} . ((c1 == 'z') ? '' : ',')
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 let output += [ line ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 endfor
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 let output += [ '};' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 let output += [ '' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 let output += [ '/*' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 let output += [ ' * Table giving the index of the first command in cmdnames[] to lookup' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 let output += [ ' * based on the first 2 letters of a command.' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 let output += [ ' * Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 let output += [ ' * fit in a byte.' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 let output += [ ' */' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 let output += [ 'static const unsigned char cmdidxs2[26][26] =' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 let output += [ '{ /* a b c d e f g h i j k l m n o p q r s t u v w x y z */' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 for c1 in a_to_z
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 let line = ' /* ' . c1 . ' */ {'
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 for c2 in a_to_z
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 if exists('cmdidxs2{c1}{c2}')
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 let line .= printf('%3d', cmdidxs2{c1}{c2} - cmdidxs1{c1})
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 else
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 let line .= ' 0'
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 endif
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 let line .= (c2 == 'z') ? '' : ','
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 endfor
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 let line .= ' }' . ((c1 == 'z') ? '' : ',')
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 let output += [ line ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 endfor
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 let output += [ '};' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 let output += [ '' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 let output += [ 'static const int command_count = ' . (len(cmds) + skipped_cmds) . ';' ]
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 call writefile(output, "ex_cmdidxs.h")
889da8649221 patch 8.0.0572: building the command table requires Perl
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 quit