annotate src/create_cmdidxs.pl @ 11279:b19377368387 v8.0.0525

patch 8.0.0525: completion for user command argument not tested commit https://github.com/vim/vim/commit/a33ddbbd04ca9b81cba6114708f42b8e26293b99 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Mar 29 21:30:04 2017 +0200 patch 8.0.0525: completion for user command argument not tested Solution: Completion for user command argument not tested. Problem: Add a test.
author Christian Brabandt <cb@256bit.org>
date Wed, 29 Mar 2017 21:45:04 +0200
parents 17ba19406c50
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11236
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 #!/usr/bin/perl -w
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 #
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 # This script generates the tables cmdidxs1[] and cmdidxs2[][] which,
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 # given a Ex command, determine the first value to probe to find
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 # a matching command in cmdnames[] based on the first character
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 # and the first 2 characters of the command.
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 # This is used to speed up lookup in cmdnames[].
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 #
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 # Script should be run every time new Ex commands are added in Vim,
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 # from the src/vim directory, since it reads commands from "ex_cmds.h".
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11
11256
17ba19406c50 patch 8.0.0514: script for creating cmdidxs can be improved
Christian Brabandt <cb@256bit.org>
parents: 11236
diff changeset
12 use strict;
17ba19406c50 patch 8.0.0514: script for creating cmdidxs can be improved
Christian Brabandt <cb@256bit.org>
parents: 11236
diff changeset
13
11236
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 # Find the list of Vim commands from cmdnames[] table in ex_cmds.h
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 my @cmds;
11256
17ba19406c50 patch 8.0.0514: script for creating cmdidxs can be improved
Christian Brabandt <cb@256bit.org>
parents: 11236
diff changeset
16 my $skipped_cmds;
11236
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 open(IN, "< ex_cmds.h") or die "can't open ex_cmds.h: $!\n";
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 while (<IN>) {
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 if (/^EX\(CMD_\S*,\s*"([a-z][^"]*)"/) {
11256
17ba19406c50 patch 8.0.0514: script for creating cmdidxs can be improved
Christian Brabandt <cb@256bit.org>
parents: 11236
diff changeset
20 push @cmds, $1;
11236
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 } elsif (/^EX\(CMD_/) {
11256
17ba19406c50 patch 8.0.0514: script for creating cmdidxs can be improved
Christian Brabandt <cb@256bit.org>
parents: 11236
diff changeset
22 ++$skipped_cmds;
11236
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 }
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 }
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 my %cmdidxs1;
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 my %cmdidxs2;
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 for (my $i = $#cmds; $i >= 0; --$i) {
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 my $cmd = $cmds[$i];
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 my $c1 = substr($cmd, 0, 1); # First character of command.
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 $cmdidxs1{$c1} = $i;
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 if (length($cmd) > 1) {
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 my $c2 = substr($cmd, 1, 1); # Second character of command.
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 $cmdidxs2{$c1}{$c2} = $i if (('a' lt $c2) and ($c2 lt 'z'));
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 }
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 }
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 print "/* Beginning of automatically generated code by create_cmdidxs.pl\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 " *\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 " * Table giving the index of the first command in cmdnames[] to lookup\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 " * based on the first letter of a command.\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 " */\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 "static const unsigned short cmdidxs1[26] =\n{\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 join(",\n", map(" /* $_ */ $cmdidxs1{$_}", ('a' .. 'z'))),
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 "\n};\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 "\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 "/*\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 " * Table giving the index of the first command in cmdnames[] to lookup\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 " * based on the first 2 letters of a command.\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 " * Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 " * fit in a byte.\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 " */\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 "static const unsigned char cmdidxs2[26][26] =\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 "{ /* 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 */\n";
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 for my $c1 ('a' .. 'z') {
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 print " /* $c1 */ {";
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 for my $c2 ('a' .. 'z') {
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 if (exists $cmdidxs2{$c1}{$c2}) {
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 printf "%3d,", $cmdidxs2{$c1}{$c2} - $cmdidxs1{$c1};
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 } else {
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 printf " 0,";
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 }
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 }
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 print " }";
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 print "," unless ($c1 eq 'z');
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 print "\n";
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 }
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 print "};\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 "\n",
11256
17ba19406c50 patch 8.0.0514: script for creating cmdidxs can be improved
Christian Brabandt <cb@256bit.org>
parents: 11236
diff changeset
73 "static const int command_count = ", scalar(@cmds) + $skipped_cmds, ";\n",
11236
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 "\n",
62c96fee518e patch 8.0.0504: looking up an Ex command is a bit slow
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 "/* End of automatically generated code by create_cmdidxs.pl */\n";