Initial Commit
[packages] / xemacs-packages / jde / lisp / jtags.csh
1 #! /bin/csh
2 #
3 # $Id: jtags.csh,v 1.7 2002/09/16 04:55:27 paulk Exp $
4 #
5 # Usage:     jtags [-h | srcdir]
6 #
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.
11 #
12 # Options:   -h  Print usage.
13 #
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.
18 #
19 # By:        Paul Kinnucan 
20 #            The MathWorks, Inc.
21 #            paulk@mathworks.com
22 #
23 # Thanks:    David Lim <david@ndc.com>
24 #            Michael Mirman <mmirman@mathworks.com>
25 #            Kent S. Gordon" <kgor@inetspace.com>
26 #
27
28
29 set etags_dir = ""
30 set java_dir = .
31
32 # Process command line parameters.
33 foreach arg ($*)
34     switch ($arg) 
35         case -h:
36         case -help:
37         case -usage:
38             set help = 1
39             breaksw
40         case -e*:
41             set etags_dir = `expr substr $arg 3 200`
42             breaksw
43         case -j*:
44             set java_dir = `expr substr $arg 3 200`
45             breaksw
46         default:
47             set invalid_arg = 1
48             breaksw
49     endsw
50 end
51
52 # Print help.
53 if ( $1 == "-h" || $1 == "-help" || $1 == "-usage" ) then
54     echo ""
55     echo "usage: jtags [-h | srcdir]"
56     echo ""
57     echo "srcdir   Path of the Java source directory."
58     echo ""
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."
64     echo ""
65     exit 1
66 endif
67
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."
72         exit 1
73     endif
74 endif
75
76 # If not the help option, assume parameter is the source path.
77 if ( $1 == "" ) then
78     set java_dir = "."
79 else
80     set java_dir = $1
81 endif
82
83 # Ensure that Java source directory exists.
84 if (! -e $java_dir ) then
85     echo "Java source directory $java_dir not found."
86     exit 1
87 endif
88
89 set capital = 'A-Z'
90 set letter = 'a-zA-Z_.'
91 set digit = '0-9'
92 set ws = '[ \t]'
93
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
98
99 set primitive_type3 = '\|long\|short\)\>'
100 set primitive_type_no_void = "$primitive_type1$primitive_type3"
101 set primitive_type_no_void_count = 2
102
103 set identifier = "\<\([$letter][$letter$digit]*\)\>"
104 set identifier_count = 1
105
106 set class_type = "\<\([$capital][a-zA-Z_$digit\.]*\)\>"
107 set class_type_count = 1
108
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
114
115 # Class patterns
116 set class1 = "/^$ws*\<\(class\|interface\)\>$ws*$identifier/\2/"
117 set class2 = "/^[^.*\/]*\($modifier$ws*\)*\<\(class\|interface\)\>$ws*$identifier/\7/"
118
119 # Constructor pattern
120 set constructor = "/^$ws*\($modifier$ws*\)*$class_type$ws*(/\6/"
121
122 # Pattern for methods that return primitive types, e.g.,
123 #
124 #   int[] foo()
125 #
126 set method1 = "/^[^.*\/]*$primitive_type$ws*\(\[$ws*\]$ws*\)*$identifier$ws*(/\4/"
127
128 # Pattern for methods that return class types, e.g.,
129 #
130 #   Foo[] foo()
131 #
132 set method2 = "/^[^.*\/]*$class_type$ws*\(\[$ws*\]$ws*\)*$identifier$ws*(/\3/"
133
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/"
138
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/"
143   
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.
148
149 if ( -e $java_dir/TAGS ) then
150     rm $java_dir/TAGS
151     echo "Removed old TAGS file."
152 endif
153
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
160 # append (-a) mode.
161
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"  
166
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"
171
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"
176
177 # History:
178 #
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.
182 #
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)
186 # were tagged:
187 #
188 #   class_type="\<\([$capital][a-zA-Z_$digit\.]*\)\>"
189 #
190 # Thanks to Charles Rich <rich@merl.com>
191 #
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:
196 #
197 #     ${etags_dir}etags -l none -a -o ${java_dir}/TAGS \
198 #
199 # (2) Added "\/" to the prohibited characters at the start of class2,
200 # method1 and method2 to prevent comment lines like
201 #
202 # // this is a nice interface for catching mice
203 #
204 # getting tagged:
205 #
206 #     class2="/^[^.*\/]*\($modifier$ws*\)*\<\(class\|interface\)\>$ws*$identifier/\7/"
207 #
208 # Thanks to Charles Rich <rich@merl.com>  for these improvements.
209 #
210 # Revision 1.4  1999/08/19 10:25:34  paulk
211 # Added prune clause for CVS directories.
212 #
213 # Revision 1.3  1998/02/19 04:44:48  kinnucan
214 # Updated to Bourne version.
215 #
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.
219 #
220 #
221
222 # End of jtags.csh script
223
224