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