annotate runtime/tools/shtags.pl @ 8432:6af4329b5592 v7.4.1507

commit https://github.com/vim/vim/commit/4e329fcaf7122370a6d1815a30aaf29476d3f722 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 7 15:24:03 2016 +0100 patch 7.4.1507 Problem: Crash when starting a job fails. Solution: Check for the channel to be NULL. (idea by Yasuhiro Matsumoto)
author Christian Brabandt <cb@256bit.org>
date Mon, 07 Mar 2016 15:30:05 +0100
parents 3fc0f57ecb91
children 1073225cb749
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 #!/usr/bin/env perl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 # shtags: create a tags file for perl scripts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 # Author: Stephen Riehm
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 # Last Changed: 96/11/27 19:46:06
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 # "@(#) shtags 1.1 by S. Riehm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 # obvious... :-)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 sub usage
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 print <<_EOUSAGE_ ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 USAGE: $program [-kvwVx] [-t <file>] <files>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 -t <file> Name of tags file to create. (default is 'tags')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 -s <shell> Name of the shell language in the script
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 -v Include variable definitions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 (variables mentioned at the start of a line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 -V Print version information.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 -w Suppress "duplicate tag" warnings.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 -x Explicitly create a new tags file. Normally tags are merged.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 <files> List of files to scan for tags.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 _EOUSAGE_
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 exit 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 sub version
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 # Version information
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 @id = split( ', ', 'scripts/bin/shtags, /usr/local/, LOCAL_SCRIPTS, 1.1, 96/11/27, 19:46:06' );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 $id[0] =~ s,.*/,,;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 print <<_EOVERS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 $id[0]: $id[3]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 Last Modified: @id[4,5]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 Component: $id[1]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 Release: $id[2]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 _EOVERS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 exit( 1 );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 # initialisations
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 ($program = $0) =~ s,.*/,,;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 require 'getopts.pl';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 # parse command line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 &Getopts( "t:s:vVwx" ) || &usage();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 $tags_file = $opt_t || 'tags';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 $explicit = $opt_x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 $variable_tags = $opt_v;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 $allow_warnings = ! $opt_w;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 &version if $opt_V;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 &usage() unless @ARGV != 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 # slurp up the existing tags. Some will be replaced, the ones that aren't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 # will be re-written exactly as they were read
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 if( ! $explicit && open( TAGS, "< $tags_file" ) )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 while( <TAGS> )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 /^\S+/;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 $tags{$&} = $_;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 close( TAGS );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 # for each line of every file listed on the command line, look for a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 # 'sub' definition, or, if variables are wanted aswell, look for a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 # variable definition at the start of a line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 while( <> )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 &check_shell($_), ( $old_file = $ARGV ) if $ARGV ne $old_file;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 next unless $shell;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 if( $shell eq "sh" )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 next unless /^\s*(((\w+)))\s*\(\s*\)/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 || ( $variable_tags && /^(((\w+)=))/ );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 $match = $3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 if( $shell eq "ksh" )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 # ksh
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 next unless /^\s*function\s+(((\w+)))/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 || ( $variable_tags && /^(((\w+)=))/ );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 $match = $3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 if( $shell eq "perl" )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 # perl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 next unless /^\s*sub\s+(\w+('|::))?(\w+)/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 || /^\s*(((\w+))):/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 || ( $variable_tags && /^(([(\s]*[\$\@\%]{1}(\w+).*=))/ );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 $match = $3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 if( $shell eq "tcl" )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 next unless /^\s*proc\s+(((\S+)))/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 || ( $variable_tags && /^\s*set\s+(((\w+)\s))/ );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 $match = $3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 chop;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 warn "$match - duplicate ignored\n"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 if ( $new{$match}++
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 || !( $tags{$match} = sprintf( "%s\t%s\t?^%s\$?\n", $match, $ARGV, $_ ) ) )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 && $allow_warnings;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 # write the new tags to the tags file - note that the whole file is rewritten
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 open( TAGS, "> $tags_file" );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 foreach( sort( keys %tags ) )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 print TAGS "$tags{$_}";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 close( TAGS );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 sub check_shell
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 local( $_ ) = @_;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 # read the first line of a script, and work out which shell it is,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 # unless a shell was specified on the command line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 # This routine can't handle clever scripts which start sh and then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 # use sh to start the shell they really wanted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 if( $opt_s )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 $shell = $opt_s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 $shell = "sh" if /^:$/ || /^#!.*\/bin\/sh/;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 $shell = "ksh" if /^#!.*\/ksh/;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 $shell = "perl" if /^#!.*\/perl/;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 $shell = "tcl" if /^#!.*\/wish/;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 printf "Using $shell for $ARGV\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 }