Commit | Line | Data |
3ee700d1 |
1 | # Make a TAGS file for emacs ``M-x find-tag'' from all <c,h,y,xs> source files. |
2 | # (``make realclean'' first to avoid generated files, or ``make'' first |
3 | # to get tags from all files.) |
4 | # |
b61e04d6 |
5 | # |
6 | # usage: sh emacs/ptags <options> |
7 | # |
8 | # options: |
9 | # |
10 | # fullpath - use full paths in TAGS (default: relative to the root) |
11 | # |
3ee700d1 |
12 | # (IZ: to be a happier jumper: install 'imenu-go.el' from |
13 | # ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs.) |
14 | # |
15 | # (Some tags should probably live in their own subdirs, like those in x2p/, |
16 | # but I have never been interested in x2p anyway.) |
17 | # |
18 | # Hallvard B Furuseth <h.b.furuseth@usit.uio.no>, Aug -96. |
19 | # |
20 | # Ilya Zakharevich, Oct 97: minor comments, add CPerl scan; |
21 | # Use Hallvard's scan for XS files - since he processes the "C" part too - |
22 | # but with a lot of improvements: now it is no worse than CPerl's one. |
23 | |
777e9161 |
24 | # Avoid builtin on OS/2: |
3ee700d1 |
25 | if test ! -z "$OS2_SHELL"; then alias find=gnufind; fi |
26 | |
b61e04d6 |
27 | case "$1" in |
28 | fullpath) |
29 | cwd=`pwd` |
30 | echo "Building TAGS with full paths" |
31 | ;; |
32 | *) |
33 | cwd='.' |
34 | echo "Building TAGS with relative paths" |
35 | esac |
36 | |
ea544449 |
37 | emacs=`(which emacs || which xemacs) 2>/dev/null` |
38 | [ -x "$emacs" ] || { echo "can't find emacs or xemacs in PATH"; exit 1; } |
39 | |
3ee700d1 |
40 | # Insure proper order (.h after .c, .xs before .c in subdirs): |
777e9161 |
41 | # Move autogenerated less-informative files to the end: |
42 | # Hard to do embed.h and embedvar.h in one sweep: |
43 | |
b61e04d6 |
44 | topfiles="`echo ' ' *.y *.c *.h ' ' | sed 's/ / /g' | sed 's/ embedvar\.h\|embed\.h\|perlapi\.h\|os2ish\.h\|\(globals\|perlapi\| os2\)\.c / /g'| sed "s#\(^\| \)\([^ ]\)#\1$cwd/\2#g"`" |
45 | subdirs="`find $cwd/* -maxdepth 0 -type d`" |
3625ddea |
46 | subdirfiles="`find $subdirs -name '*.[cy]' -print | sort`" |
47 | subdirfiles1="`find $subdirs -name '*.[hH]' -print | sort`" |
b61e04d6 |
48 | xsfiles="`find $cwd/ -name '*.xs' -print | sort`" |
3ee700d1 |
49 | |
777e9161 |
50 | # etags -d : process defines too (default now) |
3ee700d1 |
51 | |
52 | # These are example lines for global variables and PP-code: |
53 | ## IEXT SV * Iparsehook; |
54 | ## IEXT char * Isplitstr IINIT(" "); |
55 | ## dEXTCONST char rcsid[] = "perl.c\nPatch level: ###\n"; |
56 | ## PP(pp_const) |
3aefca04 |
57 | ## PERLVARI(Grsfp, PerlIO *, Nullfp) |
58 | ## PERLVAR(cvcache, HV *) |
3ee700d1 |
59 | |
777e9161 |
60 | # Putting PL_\1 in the substitution line makes etags dump core |
61 | # Thus we do it later (but 20.2.92 does it OK). |
3ee700d1 |
62 | set x -d -l c \ |
63 | -r '/[dI]?EXT\(CONST\)?[ \t*]+\([a-zA-Z_0-9]+[ \t*]+\)*\([a-zA-Z_0-9]+\)[ \t]*\($\|;\|\[\|[ \t]I+NIT[ \t]*(\|\/\*\)/\3/' \ |
64 | -r '/IEXT[ \t][^\/]*[ \t*]I\([a-zA-Z_][a-zA-Z_0-9]*\)[\[; \t]/\1/' \ |
777e9161 |
65 | -r '/PERLVAR[a-zA-Z_0-9]*[ \t]*([ \t]*[GIT]?\([a-zA-Z_][a-zA-Z_0-9]*\)[ \t]*[\[,]/\1/' \ |
3ee700d1 |
66 | -r '/PP[ \t]*([ \t]*\([^ \t()]*\)[ \t]*)/\1/' |
67 | |
68 | shift |
69 | |
70 | rm -f TAGS.tmp TAGS.tm2 |
71 | |
72 | # Process lines like this: #define MEM_ALIGNBYTES $alignbytes /**/ |
73 | etags -o TAGS.tmp \ |
74 | -l none -r '/#\(\$[a-zA-Z_0-9]+\|define\)[ \t]+\([a-zA-Z_0-9]+\)/\2/' \ |
b61e04d6 |
75 | $cwd/config_h.SH |
3625ddea |
76 | # Process lines like this: Mcc (Loc.U): |
77 | etags -o TAGS.tmp -a \ |
78 | -l none -r '/^\([a-zA-Z_0-9]+\)[ \t]+(/\$\1/' \ |
b61e04d6 |
79 | -r '/^\([a-zA-Z_0-9]+\)[ \t]+(/\1/' $cwd/Porting/Glossary |
3625ddea |
80 | |
3ee700d1 |
81 | etags -o TAGS.tmp -a "$@" $topfiles |
777e9161 |
82 | |
83 | # Now add these PL_: |
51371543 |
84 | perl -w014pe 'if (s/^( .* PERLVAR A?I? # 1: TAG group |
777e9161 |
85 | \s* \( \s* [GIT] # |
86 | .* # |
87 | \x7F # End of description |
88 | ) |
3625ddea |
89 | ( .* \x01 ) # 2: Exact group |
777e9161 |
90 | /${1}PL_$2/mgx) { # Add PL_ |
91 | $chars = chomp; |
92 | s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e; |
93 | $_ .= ("\f" x $chars); |
94 | }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp |
95 | |
96 | |
0c9e4c8c |
97 | # Now remove these Perl_, add empty- and perl_-flavors: |
98 | perl -w014pe 'if (s/^(Perl_ # 1: First group |
99 | (\w+) \( # 2: Stripped name |
100 | \x7F # End of description |
101 | ) # End of description |
102 | (\d+,\d+\n) # 3: TAGS Trail |
103 | /$1$3$1$2\x01$3$1perl_$2\x01$3/mgx) { # Repeat, add empty and perl_ flavors |
104 | $chars = chomp; |
105 | s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e; |
106 | $_ .= ("\f" x $chars); |
107 | }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp |
108 | |
109 | # Now remove these S_, add empty-flavor: |
110 | perl -w014pe 'if (s/^(S_ # 1: First group |
111 | (\w+) \( # 2: Stripped name |
112 | \x7F # End of description |
113 | ) # End of description |
114 | (\d+,\d+\n) # 3: TAGS Trail |
115 | /$1$3$1$2\x01$3/mgx) { # Repeat, add empty_ flavor |
116 | $chars = chomp; |
117 | s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e; |
118 | $_ .= ("\f" x $chars); |
119 | }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp |
777e9161 |
120 | |
b61e04d6 |
121 | etags -o TAGS.tmp -a -D -l none -r '/#define.*\t\(Perl_.*\)/\1/' $cwd/embed.h |
122 | etags -o TAGS.tmp -a $cwd/globals.c $cwd/embedvar.h $cwd/perlapi.c $cwd/perlapi.h |
3ee700d1 |
123 | |
0c9e4c8c |
124 | # The above processes created a lot of descriptions with an |
125 | # an explicitly specified tag. Such descriptions have higher |
126 | # precedence than descriptions without an explicitely specified tag. |
127 | # To restore the justice, make all the descriptions explicit. |
3625ddea |
128 | perl -w014pe 'if (s/^( [^\n\x7F\x01]*\b # 1: TAG group |
79e58eb3 |
129 | (\w+) # 2: word |
3625ddea |
130 | [^\w\x7F\x01\n]* # Most anything |
79e58eb3 |
131 | \x7F # End of description |
132 | ) |
133 | (\d+,\d+\n) # 3: TAGS Trail |
3625ddea |
134 | /$1$2\x01$3/mgx) { # Add specific marking |
79e58eb3 |
135 | $chars = chomp; |
136 | s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e; |
137 | $_ .= ("\f" x $chars); |
138 | }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp |
139 | |
3ee700d1 |
140 | # Add MODULE lines to TAG files (to be postprocessed later), |
141 | # and BOOT: lines (in DynaLoader processed twice?) |
142 | |
143 | # This skips too many XSUBs: |
144 | |
145 | # etags -o TAGS.tmp -a -d -l c \ |
146 | # -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \ |
147 | # -r '/[ \t]*BOOT:/' \ |
148 | # $xsfiles |
149 | |
150 | etags -o TAGS.tmp -a -d -l c \ |
151 | -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \ |
152 | -r '/[ \t]*BOOT:/' \ |
153 | -r '/\([_a-zA-Z][a-zA-Z0-9_:]*\)(/' \ |
154 | $xsfiles |
155 | |
156 | # -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)/\2/' \ |
157 | # -r '/MODULE.*PREFIX[ \t]*=[ \t]*\([^ \t]+\)/\1/' \ |
158 | # $xsfiles |
159 | |
160 | etags -o TAGS.tmp -a "$@" $subdirfiles |
3625ddea |
161 | etags -o TAGS.tmp -a "$@" $subdirfiles1 |
3ee700d1 |
162 | |
79e58eb3 |
163 | if test ! -f emacs/cperl-mode.elc ; then |
ea544449 |
164 | ( cd emacs; $emacs -batch -q -no-site-file -f batch-byte-compile cperl-mode.el ) |
3ee700d1 |
165 | fi |
166 | |
167 | # This should work with newer Emaxen |
168 | |
169 | cp TAGS.tmp TAGS |
ea544449 |
170 | if $emacs -batch -q -no-site-file -l emacs/cperl-mode.elc -f cperl-add-tags-recurse-noxs ; then |
3ee700d1 |
171 | mv TAGS TAGS.tmp |
172 | fi |
173 | |
174 | perl -w014pe ' |
175 | $update = s/^PP\(\177\d+,\d+\n//gm; |
176 | $update += s/^(I?EXT.*[ \t])IINIT[ \t]*\((\177)/$1$2/gm; |
177 | if (/^\n*[^\s,]+\.xs,/s) { |
178 | $mod = $cmod = $bmod = $pref = ""; |
179 | s/^(.*\n)\1+/$1/mg; # Remove duplicate lines |
180 | $_ = join("", map { |
181 | if (/^MODULE[ \t]*=[ \t]*(\S+)(?:[ \t]+PACKAGE[ \t]*=[ \t]*(\S+))?[ \t\177]/m) { |
182 | $mod = $+; |
183 | ($bmod = $mod) =~ tr/:/_/; |
184 | $cmod = "XS_${bmod}_"; |
185 | $pref = ""; |
186 | if (s/[ \t]+PREFIX[ \t]*=[ \t]*([^\s\177]+)(\177)/$+/) { |
187 | $pref = $1; |
188 | $pref =~ s/([^\w\s])/\\$1/g; |
189 | $pref = "(?:$pref)?"; |
190 | } |
191 | } elsif ($mod ne "") { |
192 | # Ref points for Module::subr, XS_Module_subr, subr |
193 | s/^($pref(\w+)[ \t()]*\177)(\d+,\d+)$/$1${mod}::${2}\01$3\n$1$2\01$3\n$1$cmod$2\01$3/gm; |
194 | # Ref for Module::bootstrap bootstrap boot_Module |
195 | s/^([ \t]*BOOT:\177)(\d+,\d+)$/$1${mod}::bootstrap\01$2\n${1}bootstrap\01$2\n${1}boot_$bmod\01$2/gm; |
196 | } |
197 | $_; |
198 | } split(/(\nMODULE[ \t]*=[^\n\177]+\177)/)); |
199 | |
200 | $update = 1; |
201 | } |
202 | if ($update) { |
203 | $chars = chomp; |
204 | s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e; |
205 | $_ .= ("\f" x $chars); |
206 | }' TAGS.tmp > TAGS.tm2 |
207 | |
208 | rm -f TAGS |
209 | mv TAGS.tm2 TAGS |
210 | rm -f TAGS.tmp |
211 | |
212 | |
213 | |