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