Skip to content

Commit 6de5e12

Browse files
committed
patch 8.0.0572: building the command table requires Perl
Problem: Building the command table requires Perl. Solution: Use a Vim script solution. (Dominique Pelle, closes #1641)
1 parent a364cdb commit 6de5e12

File tree

7 files changed

+166
-159
lines changed

7 files changed

+166
-159
lines changed

Filelist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ SRC_ALL = \
2424
src/edit.c \
2525
src/eval.c \
2626
src/evalfunc.c \
27+
src/ex_cmdidxs.h \
2728
src/ex_cmds.c \
2829
src/ex_cmds.h \
2930
src/ex_cmds2.c \
@@ -215,7 +216,7 @@ SRC_UNIX = \
215216
src/config.mk.in \
216217
src/configure \
217218
src/configure.ac \
218-
src/create_cmdidxs.pl \
219+
src/create_cmdidxs.vim \
219220
src/gui_at_fs.c \
220221
src/gui_at_sb.c \
221222
src/gui_at_sb.h \

src/Makefile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,15 +1885,12 @@ autoconf:
18851885
-rm -rf autom4te.cache
18861886
-rm -f auto/config.status auto/config.cache
18871887

1888-
# Run Perl to generate the Ex command lookup table. This only needs to be run
1889-
# when a command name has been added or changed.
1890-
# NOTE: Only works when perl and vim executables are available
1888+
# Run vim script to generate the Ex command lookup table.
1889+
# This only needs to be run when a command name has been added or changed.
1890+
# If this fails because you don't have Vim yet, first build and install Vim
1891+
# without changes.
18911892
cmdidxs: ex_cmds.h
1892-
if test X`perl -e "print 123"` = "X123"; then \
1893-
vim ex_docmd.c -c '/Beginning.*create_cmdidxs/,/End.*create_cmdidxs/! perl create_cmdidxs.pl' -c wq; \
1894-
else \
1895-
echo Cannot run Perl; \
1896-
fi
1893+
vim -u NONE -i NONE -X -S create_cmdidxs.vim
18971894

18981895
# Re-execute this Makefile to include the new auto/config.mk produced by
18991896
# configure Only used when typing "make" with a fresh auto/config.mk.

src/create_cmdidxs.pl

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/create_cmdidxs.vim

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
" This script generates the tables cmdidxs1[] and cmdidxs2[][] which,
2+
" given a Ex command, determine the first value to probe to find
3+
" a matching command in cmdnames[] based on the first character
4+
" and the first 2 characters of the command.
5+
" This is used to speed up lookup in cmdnames[].
6+
"
7+
" Script should be run every time new Ex commands are added in Vim,
8+
" from the src/vim directory, since it reads commands from "ex_cmds.h".
9+
10+
let cmds = []
11+
let skipped_cmds = 0
12+
13+
for line in readfile('ex_cmds.h')
14+
if line =~ '^EX(CMD_'
15+
let m = matchlist(line, '^EX(CMD_\S*,\s*"\([a-z][^"]*\)"')
16+
if len(m) >= 2
17+
let cmds += [ m[1] ]
18+
else
19+
let skipped_cmds += 1
20+
endif
21+
endif
22+
endfor
23+
24+
let cmdidxs1 = {}
25+
let cmdidxs2 = {}
26+
27+
for i in range(len(cmds) - 1, 0, -1)
28+
let cmd = cmds[i]
29+
let c1 = cmd[0] " First character of command
30+
let c2 = cmd[1] " Second character of command (if any)
31+
32+
let cmdidxs1{c1} = i
33+
if c2 >= 'a' && c2 <= 'z'
34+
let cmdidxs2{c1}{c2} = i
35+
endif
36+
endfor
37+
38+
let output = [ '/* Automatically generated code by create_cmdidxs.vim' ]
39+
let output += [ ' *' ]
40+
let output += [ ' * Table giving the index of the first command in cmdnames[] to lookup' ]
41+
let output += [ ' * based on the first letter of a command.' ]
42+
let output += [ ' */' ]
43+
let output += [ 'static const unsigned short cmdidxs1[26] =' ]
44+
let output += [ '{' ]
45+
46+
let a_to_z = map(range(char2nr('a'), char2nr('z')), 'nr2char(v:val)')
47+
for c1 in a_to_z
48+
let line = ' /* ' . c1 . ' */ ' . cmdidxs1{c1} . ((c1 == 'z') ? '' : ',')
49+
let output += [ line ]
50+
endfor
51+
let output += [ '};' ]
52+
let output += [ '' ]
53+
let output += [ '/*' ]
54+
let output += [ ' * Table giving the index of the first command in cmdnames[] to lookup' ]
55+
let output += [ ' * based on the first 2 letters of a command.' ]
56+
let output += [ ' * Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they' ]
57+
let output += [ ' * fit in a byte.' ]
58+
let output += [ ' */' ]
59+
let output += [ 'static const unsigned char cmdidxs2[26][26] =' ]
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 */' ]
61+
62+
for c1 in a_to_z
63+
let line = ' /* ' . c1 . ' */ {'
64+
for c2 in a_to_z
65+
if exists('cmdidxs2{c1}{c2}')
66+
let line .= printf('%3d', cmdidxs2{c1}{c2} - cmdidxs1{c1})
67+
else
68+
let line .= ' 0'
69+
endif
70+
let line .= (c2 == 'z') ? '' : ','
71+
endfor
72+
let line .= ' }' . ((c1 == 'z') ? '' : ',')
73+
let output += [ line ]
74+
endfor
75+
76+
let output += [ '};' ]
77+
let output += [ '' ]
78+
let output += [ 'static const int command_count = ' . (len(cmds) + skipped_cmds) . ';' ]
79+
80+
call writefile(output, "ex_cmdidxs.h")
81+
quit

src/ex_cmdidxs.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* Automatically generated code by create_cmdidxs.vim
2+
*
3+
* Table giving the index of the first command in cmdnames[] to lookup
4+
* based on the first letter of a command.
5+
*/
6+
static const unsigned short cmdidxs1[26] =
7+
{
8+
/* a */ 0,
9+
/* b */ 19,
10+
/* c */ 42,
11+
/* d */ 103,
12+
/* e */ 125,
13+
/* f */ 145,
14+
/* g */ 161,
15+
/* h */ 167,
16+
/* i */ 176,
17+
/* j */ 194,
18+
/* k */ 196,
19+
/* l */ 201,
20+
/* m */ 259,
21+
/* n */ 277,
22+
/* o */ 297,
23+
/* p */ 309,
24+
/* q */ 348,
25+
/* r */ 351,
26+
/* s */ 370,
27+
/* t */ 437,
28+
/* u */ 472,
29+
/* v */ 483,
30+
/* w */ 501,
31+
/* x */ 516,
32+
/* y */ 525,
33+
/* z */ 526
34+
};
35+
36+
/*
37+
* Table giving the index of the first command in cmdnames[] to lookup
38+
* based on the first 2 letters of a command.
39+
* Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they
40+
* fit in a byte.
41+
*/
42+
static const unsigned char cmdidxs2[26][26] =
43+
{ /* 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 */
44+
/* a */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 0, 0, 0, 7, 15, 0, 16, 0, 0, 0, 0, 0 },
45+
/* b */ { 2, 0, 0, 4, 5, 7, 0, 0, 0, 0, 0, 8, 9, 10, 11, 12, 0, 13, 0, 0, 0, 0, 22, 0, 0, 0 },
46+
/* c */ { 3, 10, 12, 14, 16, 18, 21, 0, 0, 0, 0, 29, 33, 36, 42, 51, 53, 54, 55, 0, 57, 0, 60, 0, 0, 0 },
47+
/* d */ { 0, 0, 0, 0, 0, 0, 0, 0, 6, 15, 0, 16, 0, 0, 17, 0, 0, 19, 20, 0, 0, 0, 0, 0, 0, 0 },
48+
/* e */ { 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0 },
49+
/* f */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0 },
50+
/* g */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 4, 5, 0, 0, 0, 0 },
51+
/* h */ { 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
52+
/* i */ { 1, 0, 0, 0, 0, 3, 0, 0, 0, 4, 0, 5, 6, 0, 0, 0, 0, 0, 13, 0, 15, 0, 0, 0, 0, 0 },
53+
/* j */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
54+
/* k */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
55+
/* l */ { 3, 9, 11, 15, 16, 20, 23, 28, 0, 0, 0, 30, 33, 36, 40, 46, 0, 48, 57, 49, 50, 54, 56, 0, 0, 0 },
56+
/* m */ { 1, 0, 0, 0, 7, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16 },
57+
/* n */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 10, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0 },
58+
/* o */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 5, 0, 0, 0, 0, 0, 0, 9, 0, 11, 0, 0, 0 },
59+
/* p */ { 1, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 16, 17, 26, 0, 27, 0, 28, 0 },
60+
/* q */ { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
61+
/* r */ { 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 18, 0, 0, 0, 0 },
62+
/* s */ { 2, 6, 15, 0, 18, 22, 0, 24, 25, 0, 0, 28, 30, 34, 38, 40, 0, 48, 0, 49, 0, 61, 62, 0, 63, 0 },
63+
/* t */ { 2, 0, 19, 0, 22, 23, 0, 24, 0, 25, 0, 26, 27, 28, 29, 30, 0, 31, 33, 0, 34, 0, 0, 0, 0, 0 },
64+
/* u */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
65+
/* v */ { 0, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 9, 12, 0, 0, 0, 0, 15, 0, 16, 0, 0, 0, 0, 0 },
66+
/* w */ { 2, 0, 0, 0, 0, 0, 0, 3, 4, 0, 0, 0, 0, 8, 0, 9, 10, 0, 12, 0, 13, 14, 0, 0, 0, 0 },
67+
/* x */ { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0 },
68+
/* y */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
69+
/* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
70+
};
71+
72+
static const int command_count = 539;

src/ex_docmd.c

Lines changed: 4 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -494,81 +494,7 @@ static void ex_folddo(exarg_T *eap);
494494
*/
495495
#define DO_DECLARE_EXCMD
496496
#include "ex_cmds.h"
497-
498-
/* Beginning of automatically generated code by create_cmdidxs.pl
499-
*
500-
* Table giving the index of the first command in cmdnames[] to lookup
501-
* based on the first letter of a command.
502-
*/
503-
static const unsigned short cmdidxs1[26] =
504-
{
505-
/* a */ 0,
506-
/* b */ 19,
507-
/* c */ 42,
508-
/* d */ 103,
509-
/* e */ 125,
510-
/* f */ 145,
511-
/* g */ 161,
512-
/* h */ 167,
513-
/* i */ 176,
514-
/* j */ 194,
515-
/* k */ 196,
516-
/* l */ 201,
517-
/* m */ 259,
518-
/* n */ 277,
519-
/* o */ 297,
520-
/* p */ 309,
521-
/* q */ 348,
522-
/* r */ 351,
523-
/* s */ 370,
524-
/* t */ 437,
525-
/* u */ 472,
526-
/* v */ 483,
527-
/* w */ 501,
528-
/* x */ 516,
529-
/* y */ 525,
530-
/* z */ 526
531-
};
532-
533-
/*
534-
* Table giving the index of the first command in cmdnames[] to lookup
535-
* based on the first 2 letters of a command.
536-
* Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they
537-
* fit in a byte.
538-
*/
539-
static const unsigned char cmdidxs2[26][26] =
540-
{ /* 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 */
541-
/* a */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 0, 0, 0, 7, 15, 0, 16, 0, 0, 0, 0, 0, },
542-
/* b */ { 0, 0, 0, 4, 5, 7, 0, 0, 0, 0, 0, 8, 9, 10, 11, 12, 0, 13, 0, 0, 0, 0, 22, 0, 0, 0, },
543-
/* c */ { 0, 10, 12, 14, 16, 18, 21, 0, 0, 0, 0, 29, 33, 36, 42, 51, 53, 54, 55, 0, 57, 0, 60, 0, 0, 0, },
544-
/* d */ { 0, 0, 0, 0, 0, 0, 0, 0, 6, 15, 0, 16, 0, 0, 17, 0, 0, 19, 20, 0, 0, 0, 0, 0, 0, 0, },
545-
/* e */ { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, },
546-
/* f */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, },
547-
/* g */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 4, 5, 0, 0, 0, 0, },
548-
/* h */ { 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
549-
/* i */ { 0, 0, 0, 0, 0, 3, 0, 0, 0, 4, 0, 5, 6, 0, 0, 0, 0, 0, 13, 0, 15, 0, 0, 0, 0, 0, },
550-
/* j */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, },
551-
/* k */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
552-
/* l */ { 0, 9, 11, 15, 16, 20, 23, 28, 0, 0, 0, 30, 33, 36, 40, 46, 0, 48, 57, 49, 50, 54, 56, 0, 0, 0, },
553-
/* m */ { 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
554-
/* n */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 10, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, },
555-
/* o */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 5, 0, 0, 0, 0, 0, 0, 9, 0, 11, 0, 0, 0, },
556-
/* p */ { 0, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 16, 17, 26, 0, 27, 0, 28, 0, },
557-
/* q */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
558-
/* r */ { 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 18, 0, 0, 0, 0, },
559-
/* s */ { 0, 6, 15, 0, 18, 22, 0, 24, 25, 0, 0, 28, 30, 34, 38, 40, 0, 48, 0, 49, 0, 61, 62, 0, 63, 0, },
560-
/* t */ { 0, 0, 19, 0, 22, 23, 0, 24, 0, 25, 0, 26, 27, 28, 29, 30, 0, 31, 33, 0, 34, 0, 0, 0, 0, 0, },
561-
/* u */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
562-
/* v */ { 0, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 9, 12, 0, 0, 0, 0, 15, 0, 16, 0, 0, 0, 0, 0, },
563-
/* w */ { 0, 0, 0, 0, 0, 0, 0, 3, 4, 0, 0, 0, 0, 8, 0, 9, 10, 0, 12, 0, 13, 14, 0, 0, 0, 0, },
564-
/* x */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, },
565-
/* y */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
566-
/* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }
567-
};
568-
569-
static const int command_count = 539;
570-
571-
/* End of automatically generated code by create_cmdidxs.pl */
497+
#include "ex_cmdidxs.h"
572498

573499
static char_u dollar_command[2] = {'$', 0};
574500

@@ -3046,7 +2972,10 @@ do_one_cmd(
30462972

30472973
doend:
30482974
if (curwin->w_cursor.lnum == 0) /* can happen with zero line number */
2975+
{
30492976
curwin->w_cursor.lnum = 1;
2977+
curwin->w_cursor.col = 0;
2978+
}
30502979

30512980
if (errormsg != NULL && *errormsg != NUL && !did_emsg)
30522981
{

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
572,
767769
/**/
768770
571,
769771
/**/

0 commit comments

Comments
 (0)