annotate runtime/tools/shtags.pl @ 32808:c5e4ab7ea905

Added tag v9.0.1719 for changeset 0582b3b40319ff2562c7f627694504f647a6d0fd
author Christian Brabandt <cb@256bit.org>
date Tue, 15 Aug 2023 23:30:04 +0200
parents 82a28df1e2d5
children
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
13589
1073225cb749 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
6 # Updated by: David Woodfall <dave@dawoodfall.net>
1073225cb749 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
7 # Last Changed: 2018/04/02
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 #
13589
1073225cb749 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
9
1073225cb749 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
10 use Getopt::Std;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 # obvious... :-)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 sub usage
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 print <<_EOUSAGE_ ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 USAGE: $program [-kvwVx] [-t <file>] <files>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 -t <file> Name of tags file to create. (default is 'tags')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 -s <shell> Name of the shell language in the script
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 -v Include variable definitions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 (variables mentioned at the start of a line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 -V Print version information.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 -w Suppress "duplicate tag" warnings.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 -x Explicitly create a new tags file. Normally tags are merged.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 <files> List of files to scan for tags.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 _EOUSAGE_
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 exit 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 sub version
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 # Version information
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 #
13589
1073225cb749 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
34 @id = split( ', ', 'scripts/bin/shtags, /usr/local/, LOCAL_SCRIPTS, 1.2, 18/04/02, 07:37' );
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 $id[0] =~ s,.*/,,;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 print <<_EOVERS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 $id[0]: $id[3]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 Last Modified: @id[4,5]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 Component: $id[1]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 Release: $id[2]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 _EOVERS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 exit( 1 );
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 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 # initialisations
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 ($program = $0) =~ s,.*/,,;
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 #
13589
1073225cb749 Update runtime files
Christian Brabandt <cb@256bit.org>
parents: 7
diff changeset
53 getopts( "t:s:vVwx" ) || &usage();
7
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
18750
82a28df1e2d5 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 13589
diff changeset
75 # 'sub' definition, or, if variables are wanted as well, look for a
7
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 }