annotate runtime/tools/pltags.pl @ 24476:e79d1475fc89 v8.2.2778

patch 8.2.2778: problem restoring 'packpath' in session Commit: https://github.com/vim/vim/commit/d23b714d8b9ed8e16ef553098acc6da0979e94fc Author: Bram Moolenaar <Bram@vim.org> Date: Sat Apr 17 21:04:34 2021 +0200 patch 8.2.2778: problem restoring 'packpath' in session Problem: Problem restoring 'packpath' in session. Solution: Let "skiprtp" also apply to 'packpath'.
author Bram Moolenaar <Bram@vim.org>
date Sat, 17 Apr 2021 21:15:03 +0200
parents 3fc0f57ecb91
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 # pltags - create a tags file for Perl code, for use by vi(m)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 # Distributed with Vim <http://www.vim.org/>, latest version always available
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 # at <http://www.mscha.com/mscha.html?pltags#tools>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 # Version 2.3, 28 February 2002
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 # Written by Michael Schaap <pltags@mscha.com>. Suggestions for improvement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 # are very welcome!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 # This script will not work with Perl 4 or below!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 # Revision history:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 # 1.0 1997? Original version, quickly hacked together
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 # 2.0 1999? Completely rewritten, better structured and documented,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 # support for variables, packages, Exuberant Ctags extensions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 # 2.1 Jun 2000 Fixed critical bug (typo in comment) ;-)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 # Support multiple level packages (e.g. Archive::Zip::Member)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 # 2.2 Jul 2001 'Glob' wildcards - especially useful under Windows
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 # (thanks to Serge Sivkov and Jason King)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 # Bug fix: reset package name for each file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 # 2.21 Jul 2001 Oops... bug in variable detection (/local../ -> /^local.../)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 # 2.3 Feb 2002 Support variables declared with "our"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 # (thanks to Lutz Mende)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 # Complain about undeclared variables
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 use strict;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 # Used modules
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 use Getopt::Long;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 # Options with their defaults
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 my $do_subs = 1; # --subs, --nosubs include subs in tags file?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 my $do_vars = 1; # --vars, --novars include variables in tags file?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 my $do_pkgs = 1; # --pkgs, --nopkgs include packages in tags file?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 my $do_exts = 1; # --extensions, --noextensions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 # include Exuberant Ctags extensions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 # Global variables
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 my $VERSION = "2.21"; # pltags version
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 my $status = 0; # GetOptions return value
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 my $file = ""; # File being processed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 my @tags = (); # List of produced tags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 my $is_pkg = 0; # Are we tagging a package?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 my $has_subs = 0; # Has this file any subs yet?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 my $package_name = ""; # Name of current package
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 my $var_continues = 0; # Variable declaration continues on last line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 my $line = ""; # Current line in file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 my $stmt = ""; # Current Perl statement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 my @vars = (); # List of variables in declaration
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 my $var = ""; # Variable in declaration
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 my $tagline = ""; # Tag file line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 # Create a tag file line and push it on the list of found tags
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 sub MakeTag($$$$$)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 my ($tag, # Tag name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 $type, # Type of tag
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 $is_static, # Is this a static tag?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 $file, # File in which tag appears
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 $line) = @_; # Line in which tag appears
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 my $tagline = ""; # Created tag line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 # Only process tag if not empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 if ($tag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 # Get rid of \n, and escape / and \ in line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 chomp $line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 $line =~ s/\\/\\\\/g;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 $line =~ s/\//\\\//g;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 # Create a tag line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 $tagline = "$tag\t$file\t/^$line\$/";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 # If we're told to do so, add extensions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 if ($do_exts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 $tagline .= ";\"\t$type"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 . ($is_static ? "\tfile:" : "")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 . ($package_name ? "\tclass:$package_name" : "");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 # Push it on the stack
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 push (@tags, $tagline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 # Parse package name from statement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 sub PackageName($)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 my ($stmt) = @_; # Statement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 # Look for the argument to "package". Return it if found, else return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 if ($stmt =~ /^package\s+([\w:]+)/)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 my $pkgname = $1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 # Remove any parent package name(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 $pkgname =~ s/.*://;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 return $pkgname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 return "";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 # Parse sub name from statement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 sub SubName($)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 my ($stmt) = @_; # Statement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 # Look for the argument to "sub". Return it if found, else return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 if ($stmt =~ /^sub\s+([\w:]+)/)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 my $subname = $1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 # Remove any parent package name(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 $subname =~ s/.*://;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 return $subname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 return "";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 # Parse all variable names from statement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 sub VarNames($)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 my ($stmt) = @_;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 # Remove my or local from statement, if present
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 $stmt =~ s/^(my|our|local)\s+//;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 # Remove any assignment piece
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 $stmt =~ s/\s*=.*//;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 # Now find all variable names, i.e. "words" preceded by $, @ or %
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 @vars = ($stmt =~ /[\$\@\%]([\w:]+)\b/g);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 # Remove any parent package name(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 map(s/.*://, @vars);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 return (@vars);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 ############### Start ###############
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 print "\npltags $VERSION by Michael Schaap <mscha\@mscha.com>\n\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 # Get options
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 $status = GetOptions("subs!" => \$do_subs,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 "vars!" => \$do_vars,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 "pkgs!" => \$do_pkgs,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 "extensions!" => \$do_exts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 # Usage if error in options or no arguments given
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 unless ($status && @ARGV)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 print "\n" unless ($status);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 print " Usage: $0 [options] filename ...\n\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 print " Where options can be:\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 print " --subs (--nosubs) (don't) include sub declarations in tag file\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 print " --vars (--novars) (don't) include variable declarations in tag file\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 print " --pkgs (--nopkgs) (don't) include package declarations in tag file\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 print " --extensions (--noextensions)\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 print " (don't) include Exuberant Ctags / Vim style\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 print " extensions in tag file\n\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 print " Default options: ";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 print ($do_subs ? "--subs " : "--nosubs ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 print ($do_vars ? "--vars " : "--novars ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 print ($do_pkgs ? "--pkgs " : "--nopkgs ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 print ($do_exts ? "--extensions\n\n" : "--noextensions\n\n");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 print " Example: $0 *.pl *.pm ../shared/*.pm\n\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 exit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 # Loop through files on command line - 'glob' any wildcards, since Windows
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 # doesn't do this for us
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 foreach $file (map { glob } @ARGV)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 # Skip if this is not a file we can open. Also skip tags files and backup
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 # files
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 next unless ((-f $file) && (-r $file) && ($file !~ /tags$/)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 && ($file !~ /~$/));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 print "Tagging file $file...\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 $is_pkg = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 $package_name = "";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 $has_subs = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 $var_continues = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 open (IN, $file) or die "Can't open file '$file': $!";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 # Loop through file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 foreach $line (<IN>)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 # Statement is line with comments and whitespace trimmed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 ($stmt = $line) =~ s/#.*//;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 $stmt =~ s/^\s*//;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 $stmt =~ s/\s*$//;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 # Nothing left? Never mind.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 next unless ($stmt);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 # This is a variable declaration if one was started on the previous
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 # line, or if this line starts with my or local
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 if ($var_continues or ($stmt =~/^my\b/)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 or ($stmt =~/^our\b/) or ($stmt =~/^local\b/))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 # The declaration continues if the line does not end with ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 $var_continues = ($stmt !~ /;$/);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 # Loop through all variable names in the declaration
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 foreach $var (VarNames($stmt))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 # Make a tag for this variable unless we're told not to. We
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 # assume that a variable is always static, unless it appears
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 # in a package before any sub. (Not necessarily true, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 # it's ok for most purposes and Vim works fine even if it is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 # incorrect)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 if ($do_vars)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 MakeTag($var, "v", (!$is_pkg or $has_subs), $file, $line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 # This is a package declaration if the line starts with package
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 elsif ($stmt =~/^package\b/)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 # Get name of the package
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 $package_name = PackageName($stmt);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 if ($package_name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 # Remember that we're doing a package
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 $is_pkg = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 # Make a tag for this package unless we're told not to. A
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 # package is never static.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 if ($do_pkgs)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 MakeTag($package_name, "p", 0, $file, $line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 # This is a sub declaration if the line starts with sub
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 elsif ($stmt =~/^sub\b/)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 # Remember that this file has subs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 $has_subs = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 # Make a tag for this sub unless we're told not to. We assume
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 # that a sub is static, unless it appears in a package. (Not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 # necessarily true, but it's ok for most purposes and Vim works
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 # fine even if it is incorrect)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 if ($do_subs)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 MakeTag(SubName($stmt), "s", (!$is_pkg), $file, $line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 close (IN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 # Do we have any tags? If so, write them to the tags file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 if (@tags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 # Add some tag file extensions if we're told to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 if ($do_exts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 push (@tags, "!_TAG_FILE_FORMAT\t2\t/extended format/");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 push (@tags, "!_TAG_FILE_SORTED\t1\t/0=unsorted, 1=sorted/");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 push (@tags, "!_TAG_PROGRAM_AUTHOR\tMichael Schaap\t/mscha\@mscha.com/");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 push (@tags, "!_TAG_PROGRAM_NAME\tpltags\t//");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 push (@tags, "!_TAG_PROGRAM_VERSION\t$VERSION\t/supports multiple tags and extended format/");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 print "\nWriting tags file.\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 open (OUT, ">tags") or die "Can't open tags file: $!";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 foreach $tagline (sort @tags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 print OUT "$tagline\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 close (OUT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 print "\nNo tags found.\n";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 }