2 * Copyright (c) 1998 Shigio Yamaguchi. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement:
14 * This product includes software developed by Shigio Yamaguchi.
15 * 4. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 static int reserved __P((char *));
48 * java: read java file and pickup tag entries.
54 int level; /* brace level */
56 int startclass, startthrows, startequal;
57 char classname[MAXTOKEN];
58 char completename[MAXCOMPLETENAME];
64 } stack[MAXCLASSSTACK];
65 const char *interested = "{}=;";
67 stack[0].terminate = completename;
69 level = classlevel = 0;
70 target = (sflag) ? SYM : ((rflag) ? REF : DEF);
71 startclass = startthrows = startequal = 0;
73 while ((c = nexttoken(interested, reserved)) != EOF) {
75 case SYMBOL: /* symbol */
76 for (; c == SYMBOL && peekc(1) == '.'; c = nexttoken(interested, reserved)) {
78 PUT(token, lineno, sp);
82 if (startclass || startthrows) {
83 if (target == REF && defined(token))
84 PUT(token, lineno, sp);
85 } else if (peekc(0) == '('/* ) */) {
86 if (target == DEF && level == stack[classlevel].level && !startequal)
87 /* ignore constructor */
88 if (strcmp(stack[classlevel].classname, token))
89 PUT(token, lineno, sp);
90 if (target == REF && (level > stack[classlevel].level || startequal) && defined(token))
91 PUT(token, lineno, sp);
94 PUT(token, lineno, sp);
98 DBG_PRINT(level, "{"); /* } */
102 char *p = stack[classlevel].terminate;
105 if (++classlevel >= MAXCLASSSTACK)
106 die1("class stack over flow.[%s]", curfile);
109 stack[classlevel].classname = p;
112 stack[classlevel].terminate = p;
113 stack[classlevel].level = level;
116 startclass = startthrows = 0;
122 fprintf(stderr, "Warning: missing left '{' (at %d).\n", lineno); /* } */
125 if (level < stack[classlevel].level)
126 *(stack[--classlevel].terminate) = 0;
128 DBG_PRINT(level, "}");
134 startclass = startthrows = startequal = 0;
138 if ((c = nexttoken(interested, reserved)) == SYMBOL) {
139 strcpy(classname, token);
142 PUT(token, lineno, sp);
147 while ((c = nexttoken(interested, reserved)) == SYMBOL && peekc(1) == '.')
149 PUT(token, lineno, sp);
151 if (target == REF && defined(token))
152 PUT(token, lineno, sp);
166 if (peekc(1) == '.' && (c = nexttoken(interested, reserved)) != J_CLASS)
173 /* sorted by alphabet */
174 static struct words words[] = {
175 {"abstract", J_ABSTRACT},
176 {"boolean", J_BOOLEAN},
184 {"continue", J_CONTINUE},
185 {"default", J_DEFAULT},
187 {"double", J_DOUBLE},
189 {"extends", J_EXTENDS},
192 {"finally", J_FINALLY},
197 {"implements", J_IMPLEMENTS},
198 {"import", J_IMPORT},
199 {"instanceof", J_INSTANCEOF},
201 {"interface", J_INTERFACE},
203 {"native", J_NATIVE},
206 {"package", J_PACKAGE},
207 {"private", J_PRIVATE},
208 {"protected", J_PROTECTED},
209 {"public", J_PUBLIC},
210 {"return", J_RETURN},
212 {"static", J_STATIC},
213 {"strictfp", J_STRICTFP},
215 {"switch", J_SWITCH},
216 {"synchronized",J_SYNCHRONIZED},
219 {"throws", J_THROWS},
221 {"transient", J_TRANSIENT},
225 {"volatile", J_VOLATILE},
227 {"widefp", J_WIDEFP},
235 struct words *result;
238 result = (struct words *)bsearch(&tmp, words, sizeof(words)/sizeof(struct words), sizeof(struct words), cmp);
239 return (result != NULL) ? result->val : SYMBOL;