This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Files names for pragmas strict and warnings can end in .pmc
[perl5.git] / emacs / ptags
index a048192..c017e66 100755 (executable)
@@ -2,6 +2,13 @@
 # (``make realclean'' first to avoid generated files, or ``make'' first
 # to get tags from all files.)
 #
+#
+# usage: sh emacs/ptags <options>
+# 
+# options:
+#
+# fullpath - use full paths in TAGS (default: relative to the root)
+#
 # (IZ: to be a happier jumper: install 'imenu-go.el' from
 #      ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs.)
 #
 # Avoid builtin on OS/2:
 if test ! -z "$OS2_SHELL"; then alias find=gnufind; fi
 
+case "$1" in
+  fullpath)
+    cwd=`pwd`
+    cperl_add_tags='cperl-add-tags-recurse-noxs-fullpath'
+    echo "Building TAGS with full paths"
+  ;;
+  *)
+    cperl_add_tags='cperl-add-tags-recurse-noxs'
+    cwd='.'
+    echo "Building TAGS with relative paths"
+esac
+
+emacs=`(which emacs || which xemacs || echo emacs) 2>/dev/null`
+[ -x "$emacs" ] || { echo "can't find emacs or xemacs in PATH"; exit 1; }
+
 # Insure proper order (.h after .c, .xs before .c in subdirs):
 # Move autogenerated less-informative files to the end:
 # Hard to do embed.h and embedvar.h in one sweep:
 
-topfiles="`echo ' ' *.y *.c *.h ' ' | sed 's/ \(embed\(var\|\)\.h\|obj\(pp\|XSUB\)\.h\|globals\.c\) \(\(embedvar\|objpp\).h \|\)/ /g'`"
-subdirs="`find ./* -maxdepth 0 -type d`"
+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"`"
+subdirs="`find $cwd/* -maxdepth 0 -type d`"
 subdirfiles="`find $subdirs -name '*.[cy]' -print | sort`"
 subdirfiles1="`find $subdirs -name '*.[hH]' -print | sort`"
-xsfiles="`find . -name '*.xs' -print | sort`"
+xsfiles="`find $cwd/ -name '*.xs' -print | sort`"
 
 # etags -d : process defines too (default now)
 
@@ -52,16 +74,16 @@ rm -f TAGS.tmp TAGS.tm2
 # Process lines like this: #define MEM_ALIGNBYTES $alignbytes      /**/
 etags -o TAGS.tmp \
        -l none -r '/#\(\$[a-zA-Z_0-9]+\|define\)[ \t]+\([a-zA-Z_0-9]+\)/\2/' \
-       config_h.SH
+       $cwd/config_h.SH
 # Process lines like this: Mcc (Loc.U):
 etags -o TAGS.tmp -a \
        -l none -r '/^\([a-zA-Z_0-9]+\)[ \t]+(/\$\1/' \
-               -r '/^\([a-zA-Z_0-9]+\)[ \t]+(/\1/' Porting/Glossary
+               -r '/^\([a-zA-Z_0-9]+\)[ \t]+(/\1/' $cwd/Porting/Glossary
 
 etags -o TAGS.tmp -a "$@" $topfiles
 
 # Now add these PL_:
-perl -w014pe 'if (s/^( .* PERLVAR I?   # 1:   TAG group
+perl -w014pe 'if (s/^( .* PERLVAR A?I? # 1:   TAG group
                       \s* \( \s* [GIT] #
                       .*               #
                     \x7F               #      End of description
@@ -74,10 +96,37 @@ perl -w014pe 'if (s/^( .* PERLVAR I?        # 1:   TAG group
              }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
 
 
+# Now remove these Perl_, add empty- and perl_-flavors:
+perl -w014pe 'if (s/^(Perl_            # 1:   First group
+                      (\w+) \(         # 2:   Stripped name
+                      \x7F             #      End of description
+                    )                  #      End of description
+                    (\d+,\d+\n)        # 3:   TAGS Trail
+                  /$1$3$1$2\x01$3$1perl_$2\x01$3/mgx) {        # Repeat, add empty and perl_ flavors
+                 $chars = chomp;
+                 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
+                 $_ .= ("\f" x $chars);
+             }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
+
+# Now remove these S_, add empty-flavor:
+perl -w014pe 'if (s/^(S_               # 1:   First group
+                      (\w+) \(         # 2:   Stripped name
+                      \x7F             #      End of description
+                    )                  #      End of description
+                    (\d+,\d+\n)        # 3:   TAGS Trail
+                  /$1$3$1$2\x01$3/mgx) {       # Repeat, add empty_ flavor
+                 $chars = chomp;
+                 s/^((\n.+,)\d+)/ $2 . (length($_) - length($1) - 1) /e;
+                 $_ .= ("\f" x $chars);
+             }' TAGS.tmp > TAGS.tm1 && mv TAGS.tm1 TAGS.tmp
 
-etags -o TAGS.tmp -a -D -l none -r '/#define.*\t\(Perl_.*\)/\1/' embed.h
-etags -o TAGS.tmp -a globals.c embedvar.h objXSUB.h objpp.h
+etags -o TAGS.tmp -a -D -l none -r '/#define.*\t\(Perl_.*\)/\1/' $cwd/embed.h
+etags -o TAGS.tmp -a $cwd/globals.c $cwd/embedvar.h $cwd/perlapi.c $cwd/perlapi.h
 
+# The above processes created a lot of descriptions with an
+# an explicitly specified tag.  Such descriptions have higher
+# precedence than descriptions without an explicitely specified tag.
+# To restore the justice, make all the descriptions explicit.
 perl -w014pe 'if (s/^( [^\n\x7F\x01]*\b        # 1:   TAG group
                       (\w+)            #   2: word
                       [^\w\x7F\x01\n]* #      Most anything
@@ -114,13 +163,13 @@ etags -o TAGS.tmp -a "$@" $subdirfiles
 etags -o TAGS.tmp -a "$@" $subdirfiles1
 
 if test ! -f emacs/cperl-mode.elc ; then
-    ( cd emacs; emacs -batch -q -no-site-file -f batch-byte-compile cperl-mode.el )
+    ( cd emacs; $emacs -batch -q -no-site-file -f batch-byte-compile cperl-mode.el )
 fi
 
 # This should work with newer Emaxen
 
 cp TAGS.tmp TAGS
-if emacs -batch -q -no-site-file -l emacs/cperl-mode.elc -f cperl-add-tags-recurse-noxs ; then
+if $emacs -batch -q -no-site-file -l emacs/cperl-mode.elc -f $cperl_add_tags ; then
     mv TAGS TAGS.tmp
 fi