Anohter ptags improvement
[p5sagit/p5-mst-13.2.git] / emacs / ptags
CommitLineData
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#
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 builitin on OS/2:
18if test ! -z "$OS2_SHELL"; then alias find=gnufind; fi
19
20# Insure proper order (.h after .c, .xs before .c in subdirs):
3419a968 21topfiles="`echo ' ' *.y *.c *.h ' ' | sed 's/ embed.h / /' | sed 's/ globals.c / /'`"
3ee700d1 22subdirfiles="`( find ./*/* -name '*.[cy]' -print | sort ; find ./*/* -name '*.[hH]' -print | sort )`"
23xsfiles="`find . -name '*.xs' -print | sort`"
24
79e58eb3 25# etags -d : process defineds too (default now)
3ee700d1 26
27# These are example lines for global variables and PP-code:
28## IEXT SV * Iparsehook;
29## IEXT char * Isplitstr IINIT(" ");
30## dEXTCONST char rcsid[] = "perl.c\nPatch level: ###\n";
31## PP(pp_const)
3aefca04 32## PERLVARI(Grsfp, PerlIO *, Nullfp)
33## PERLVAR(cvcache, HV *)
3ee700d1 34
35set x -d -l c \
36 -r '/[dI]?EXT\(CONST\)?[ \t*]+\([a-zA-Z_0-9]+[ \t*]+\)*\([a-zA-Z_0-9]+\)[ \t]*\($\|;\|\[\|[ \t]I+NIT[ \t]*(\|\/\*\)/\3/' \
37 -r '/IEXT[ \t][^\/]*[ \t*]I\([a-zA-Z_][a-zA-Z_0-9]*\)[\[; \t]/\1/' \
3aefca04 38 -r '/PERLVAR[a-zA-Z_0-9]*[ \t]*([ \t]*[GIT]?\([a-zA-Z_][a-zA-Z_0-9]*\)[ \t]*,/\1/' \
3ee700d1 39 -r '/PP[ \t]*([ \t]*\([^ \t()]*\)[ \t]*)/\1/'
40
41shift
42
43rm -f TAGS.tmp TAGS.tm2
44
45# Process lines like this: #define MEM_ALIGNBYTES $alignbytes /**/
46etags -o TAGS.tmp \
47 -l none -r '/#\(\$[a-zA-Z_0-9]+\|define\)[ \t]+\([a-zA-Z_0-9]+\)/\2/' \
48 config_h.SH
49etags -o TAGS.tmp -a "$@" $topfiles
50etags -o TAGS.tmp -a -D -l none -r '/#define.*\t\(Perl_.*\)/\1/' embed.h
3419a968 51etags -o TAGS.tmp -a globals.c
3ee700d1 52
79e58eb3 53perl -w014pe 'if (s/^( [^\n\x7F\x1]*\b # 1: TAG group
54 (\w+) # 2: word
55 [^\w\x7X\x1\n]* # Most anything
56 \x7F # End of description
57 )
58 (\d+,\d+\n) # 3: TAGS Trail
59 /$1$2\x1$3/mgx) { # Add specific marking
60 $chars = chomp;
61 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
62 $_ .= ("\f" x $chars);
63 }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
64
3ee700d1 65# Add MODULE lines to TAG files (to be postprocessed later),
66# and BOOT: lines (in DynaLoader processed twice?)
67
68# This skips too many XSUBs:
69
70# etags -o TAGS.tmp -a -d -l c \
71# -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \
72# -r '/[ \t]*BOOT:/' \
73# $xsfiles
74
75etags -o TAGS.tmp -a -d -l c \
76 -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)\([ \t]*PREFIX[ \t]*=[ \t]*\([^ \t]+\)\)?/\2/' \
77 -r '/[ \t]*BOOT:/' \
78 -r '/\([_a-zA-Z][a-zA-Z0-9_:]*\)(/' \
79 $xsfiles
80
81# -r '/MODULE[ \t=]+\(.*PACKAGE[ \t]*=[ \t]*\)?\([^ \t]+\)/\2/' \
82# -r '/MODULE.*PREFIX[ \t]*=[ \t]*\([^ \t]+\)/\1/' \
83# $xsfiles
84
85etags -o TAGS.tmp -a "$@" $subdirfiles
86
79e58eb3 87if test ! -f emacs/cperl-mode.elc ; then
3ee700d1 88 ( cd emacs; emacs -batch -q -no-site-file -f batch-byte-compile cperl-mode.el )
89fi
90
91# This should work with newer Emaxen
92
93cp TAGS.tmp TAGS
94if emacs -batch -q -no-site-file -l emacs/cperl-mode.elc -f cperl-add-tags-recurse-noxs ; then
95 mv TAGS TAGS.tmp
96fi
97
98perl -w014pe '
99 $update = s/^PP\(\177\d+,\d+\n//gm;
100 $update += s/^(I?EXT.*[ \t])IINIT[ \t]*\((\177)/$1$2/gm;
101 if (/^\n*[^\s,]+\.xs,/s) {
102 $mod = $cmod = $bmod = $pref = "";
103 s/^(.*\n)\1+/$1/mg; # Remove duplicate lines
104 $_ = join("", map {
105 if (/^MODULE[ \t]*=[ \t]*(\S+)(?:[ \t]+PACKAGE[ \t]*=[ \t]*(\S+))?[ \t\177]/m) {
106 $mod = $+;
107 ($bmod = $mod) =~ tr/:/_/;
108 $cmod = "XS_${bmod}_";
109 $pref = "";
110 if (s/[ \t]+PREFIX[ \t]*=[ \t]*([^\s\177]+)(\177)/$+/) {
111 $pref = $1;
112 $pref =~ s/([^\w\s])/\\$1/g;
113 $pref = "(?:$pref)?";
114 }
115 } elsif ($mod ne "") {
116 # Ref points for Module::subr, XS_Module_subr, subr
117 s/^($pref(\w+)[ \t()]*\177)(\d+,\d+)$/$1${mod}::${2}\01$3\n$1$2\01$3\n$1$cmod$2\01$3/gm;
118 # Ref for Module::bootstrap bootstrap boot_Module
119 s/^([ \t]*BOOT:\177)(\d+,\d+)$/$1${mod}::bootstrap\01$2\n${1}bootstrap\01$2\n${1}boot_$bmod\01$2/gm;
120 }
121 $_;
122 } split(/(\nMODULE[ \t]*=[^\n\177]+\177)/));
123
124 $update = 1;
125 }
126 if ($update) {
127 $chars = chomp;
128 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
129 $_ .= ("\f" x $chars);
130 }' TAGS.tmp > TAGS.tm2
131
132rm -f TAGS
133mv TAGS.tm2 TAGS
134rm -f TAGS.tmp
135
136
137