3 # $Id: jtags.csh,v 1.7 2002/09/16 04:55:27 paulk Exp $
5 # Usage: jtags [-h | srcdir]
7 # Abstract: This C shell script produces an Emacs
8 # tags file for Java source code. The tags file
9 # contains tags for classes, interfaces,
10 # constructors, methods, and variables.
12 # Options: -h Print usage.
14 # -srcdir Path of top-level directory containing
15 # Java source(*.java) files to be tagged.
16 # If omitted, this script tags files in
17 # the working directory and its subdirectories.
23 # Thanks: David Lim <david@ndc.com>
24 # Michael Mirman <mmirman@mathworks.com>
25 # Kent S. Gordon" <kgor@inetspace.com>
32 # Process command line parameters.
41 set etags_dir = `expr substr $arg 3 200`
44 set java_dir = `expr substr $arg 3 200`
53 if ( $1 == "-h" || $1 == "-help" || $1 == "-usage" ) then
55 echo "usage: jtags [-h | srcdir]"
57 echo "srcdir Path of the Java source directory."
59 echo "This command tags all public classes, interfaces,"
60 echo "methods, and variables in the specified Java source"
61 echo "hierarchy. If you do not specify a source directory,"
62 echo "jtags searches the current directory and its"
63 echo "subdirectories."
68 # Ensure that etags directory exists.
69 if ( $etags_dir != "" ) then
70 if (! -d $etags_dir ) then
71 echo "etags directory $etags_dir not found."
76 # If not the help option, assume parameter is the source path.
83 # Ensure that Java source directory exists.
84 if (! -e $java_dir ) then
85 echo "Java source directory $java_dir not found."
90 set letter = 'a-zA-Z_.'
94 set primitive_type1 = '\<\(b\(oolean\|yte\)\|char\|double\|float\|int'
95 set primitive_type2 = '\|long\|short\|void\)\>'
96 set primitive_type = "$primitive_type1$primitive_type2"
97 set primitive_type_count = 2
99 set primitive_type3 = '\|long\|short\)\>'
100 set primitive_type_no_void = "$primitive_type1$primitive_type3"
101 set primitive_type_no_void_count = 2
103 set identifier = "\<\([$letter][$letter$digit]*\)\>"
104 set identifier_count = 1
106 set class_type = "\<\([$capital][a-zA-Z_$digit\.]*\)\>"
107 set class_type_count = 1
109 set modifier1 = '\<\(abstract\|const\|final\|native\|'
110 set modifier2 = 'p\(r\(ivate\|otected\)\|ublic\)\|'
111 set modifier3 = 's\(tatic\|ynchronized\)\|transient\|volatile\)\>'
112 set modifier = "$modifier1$modifier2$modifier3"
113 set modifier_count = 4
116 set class1 = "/^$ws*\<\(class\|interface\)\>$ws*$identifier/\2/"
117 set class2 = "/^[^.*\/]*\($modifier$ws*\)*\<\(class\|interface\)\>$ws*$identifier/\7/"
119 # Constructor pattern
120 set constructor = "/^$ws*\($modifier$ws*\)*$class_type$ws*(/\6/"
122 # Pattern for methods that return primitive types, e.g.,
126 set method1 = "/^[^.*\/]*$primitive_type$ws*\(\[$ws*\]$ws*\)*$identifier$ws*(/\4/"
128 # Pattern for methods that return class types, e.g.,
132 set method2 = "/^[^.*\/]*$class_type$ws*\(\[$ws*\]$ws*\)*$identifier$ws*(/\3/"
134 # Pattern for matching primitive variable declarations.
135 set var1a = ".*$primitive_type_no_void$ws*\(\[$ws*\]$ws*\)*$identifier"
136 set var1b = "$ws*\(=\|;\)"
137 set var1 = "/$var1a$var1b/\4/"
139 # Pattern for matching user-defined variable declarations.
140 set var2a = ".*$class_type$ws*\(\[$ws*\]$ws*\)*$identifier"
141 set var2b = "$ws*\(=\|;\)"
142 set var2 = "/$var2a$var2b/\3/"
144 # Delete the old TAGS file.
145 # Note: the old file must be deleted because we have to run
146 # etags in append mode. If we don't remove the old file,
147 # etags will append everything to the old file.
149 if ( -e $java_dir/TAGS ) then
151 echo "Removed old TAGS file."
154 # Use find to recurse through the source hierarchy,
155 # finding every java source file.
156 # Use xargs to apply etags to the source files.
157 # Note that xargs may invoke etags multiple
158 # times, depending on how many files it can batch
159 # per invocation. That is why we run etags in
162 echo "Tagging classes and constructors"
163 find $java_dir \( -name RCS -prune \) -o \( -name CVS -prune \) -o \( -name '*.java' -print \) | xargs \
164 "${etags_dir}etags" -l none -a -o ${java_dir}/TAGS \
165 "--regex=$class1" "--regex=$class2" "--regex=$constructor"
167 echo "Tagging methods"
168 find $java_dir \( -name RCS -prune \) -o \( -name CVS -prune \) -o \( -name '*.java' -print \) | xargs \
169 "${etags_dir}etags" -l none -a -o ${java_dir}/TAGS \
170 "--regex=$method1" "--regex=$method2"
172 echo "Tagging variables"
173 find $java_dir \( -name RCS -prune \) -o \( -name CVS -prune \) -o \( -name '*.java' -print \) | xargs \
174 "${etags_dir}etags" -l none -a -o ${java_dir}/TAGS \
175 "--regex=$var1" "--regex=$var2"
179 # $Log: jtags.csh,v $
180 # Revision 1.7 2002/09/16 04:55:27 paulk
181 # Quote path of etags executable to permit inclusion of spaces on Windows. Thanks to Jens Barnow.
183 # Revision 1.6 2001/01/06 05:27:49 paulk
184 # Add "\." below to the definition of class_type so
185 # that methods whose return type included a period (e.g, Foo.Bar)
188 # class_type="\<\([$capital][a-zA-Z_$digit\.]*\)\>"
190 # Thanks to Charles Rich <rich@merl.com>
192 # Revision 1.5 2000/12/23 04:28:15 paulk
193 # (1) Added "-l none" to the etags arguments (all four calls) to
194 # eliminate the additional spurious tags that were coming from etags'
195 # default java parsing:
197 # ${etags_dir}etags -l none -a -o ${java_dir}/TAGS \
199 # (2) Added "\/" to the prohibited characters at the start of class2,
200 # method1 and method2 to prevent comment lines like
202 # // this is a nice interface for catching mice
206 # class2="/^[^.*\/]*\($modifier$ws*\)*\<\(class\|interface\)\>$ws*$identifier/\7/"
208 # Thanks to Charles Rich <rich@merl.com> for these improvements.
210 # Revision 1.4 1999/08/19 10:25:34 paulk
211 # Added prune clause for CVS directories.
213 # Revision 1.3 1998/02/19 04:44:48 kinnucan
214 # Updated to Bourne version.
216 # Revision 1.2 1997/08/26 09:08:21 kinnucan
217 # 1. Exclude RCS (version control) directories from tags search.
218 # 2. Added pattern for recognizing abstract classes.
222 # End of jtags.csh script