1 /*
2 * Copyright (c) 2000, Patrick Dehne <patrick@steidle.net>
3 *
4 * This source code is released for free distribution under the terms of the
5 * GNU General Public License version 2 or (at your option) any later version.
6 *
7 * This module contains functions for generating tags for the ASP (Active
8 * Server Pages) web page scripting language.
9 */
10
11 /*
12 * INCLUDE FILES
13 */
14 #include "general.h" /* must always come first */
15
16 #include <string.h>
17
18 #include "parse.h"
19 #include "read.h"
20 #include "routines.h"
21 #include "vstring.h"
22
23 /*
24 * DATA DEFINITIONS
25 */
26 typedef enum {
27 K_CONST, K_CLASS, K_FUNCTION, K_SUB, K_DIM
28 } aspKind;
29
30 static kindDefinition AspKinds [] = {
31 { true, 'd', "constant", "constants"},
32 { true, 'c', "class", "classes"},
33 { true, 'f', "function", "functions"},
34 { true, 's', "subroutine", "subroutines"},
35 { true, 'v', "variable", "variables"}
36 };
37
38 /*
39 * FUNCTION DEFINITIONS
40 */
41
findAspTags(void)42 static void findAspTags (void)
43 {
44 vString *name = vStringNew ();
45 const unsigned char *line;
46
47 while ((line = readLineFromInputFile ()) != NULL)
48 {
49 const unsigned char *cp = line;
50
51 while (*cp != '\0')
52 {
53 /* jump over whitespace */
54 while (isspace ((int)*cp))
55 cp++;
56
57 /* jump over strings */
58 if (*cp == '"')
59 {
60 cp++;
61 while (*cp!='"' && *cp!='\0')
62 cp++;
63 }
64
65 /* jump over comments */
66 else if (*cp == '\'')
67 break;
68
69 /* jump over end function/sub lines */
70 else if (strncasecmp ((const char*) cp, "end", (size_t) 3)== 0)
71 {
72 cp += 3;
73 if (isspace ((int)*cp))
74 {
75 while (isspace ((int)*cp))
76 ++cp;
77
78 if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
79 {
80 cp+=8;
81 break;
82 }
83
84 else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
85 {
86 cp+=3;
87 break;
88 }
89 }
90 }
91
92 /* jump over exit function/sub lines */
93 else if (strncasecmp ((const char*) cp, "exit", (size_t) 4)==0)
94 {
95 cp += 4;
96 if (isspace ((int) *cp))
97 {
98 while (isspace ((int) *cp))
99 ++cp;
100
101 if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
102 {
103 cp+=8;
104 break;
105 }
106
107 else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
108 {
109 cp+=3;
110 break;
111 }
112 }
113 }
114
115 /* class member? */
116 else if (strncasecmp ((const char*) cp, "public", (size_t) 6) == 0)
117 {
118 cp += 6;
119 if (isspace ((int) *cp))
120 {
121 while (isspace ((int) *cp))
122 ++cp;
123 if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
124 {
125 cp+=8;
126 while (isspace ((int) *cp))
127 ++cp;
128 while (isalnum ((int) *cp) || *cp == '_')
129 {
130 vStringPut (name, (int) *cp);
131 ++cp;
132 }
133 makeSimpleTag (name, K_FUNCTION);
134 vStringClear (name);
135 }
136 else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
137 {
138 cp+=3;
139 while (isspace ((int) *cp))
140 ++cp;
141 while (isalnum ((int) *cp) || *cp == '_')
142 {
143 vStringPut (name, (int) *cp);
144 ++cp;
145 }
146 makeSimpleTag (name, K_SUB);
147 vStringClear (name);
148 }
149 else {
150 while (isalnum ((int) *cp) || *cp == '_')
151 {
152 vStringPut (name, (int) *cp);
153 ++cp;
154 }
155 makeSimpleTag (name, K_DIM);
156 vStringClear (name);
157 }
158 }
159 }
160 else if (strncasecmp ((const char*) cp, "private", (size_t) 7) == 0)
161 {
162 cp += 7;
163 if (isspace ((int) *cp))
164 {
165 while (isspace ((int) *cp))
166 ++cp;
167 if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
168 {
169 cp+=8;
170 while (isspace ((int) *cp))
171 ++cp;
172 while (isalnum ((int) *cp) || *cp == '_')
173 {
174 vStringPut (name, (int) *cp);
175 ++cp;
176 }
177 makeSimpleTag (name, K_FUNCTION);
178 vStringClear (name);
179 }
180 else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
181 {
182 cp+=3;
183 while (isspace ((int) *cp))
184 ++cp;
185 while (isalnum ((int) *cp) || *cp == '_')
186 {
187 vStringPut (name, (int) *cp);
188 ++cp;
189 }
190 makeSimpleTag (name, K_SUB);
191 vStringClear (name);
192 }
193 else {
194 while (isalnum ((int) *cp) || *cp == '_')
195 {
196 vStringPut (name, (int) *cp);
197 ++cp;
198 }
199 makeSimpleTag (name, K_DIM);
200 vStringClear (name);
201 }
202 }
203 }
204
205 /* function? */
206 else if (strncasecmp ((const char*) cp, "function", (size_t) 8) == 0)
207 {
208 cp += 8;
209
210 if (isspace ((int) *cp))
211 {
212 while (isspace ((int) *cp))
213 ++cp;
214 while (isalnum ((int) *cp) || *cp == '_')
215 {
216 vStringPut (name, (int) *cp);
217 ++cp;
218 }
219 makeSimpleTag (name, K_FUNCTION);
220 vStringClear (name);
221 }
222 }
223
224 /* sub? */
225 else if (strncasecmp ((const char*) cp, "sub", (size_t) 3) == 0)
226 {
227 cp += 3;
228 if (isspace ((int) *cp))
229 {
230 while (isspace ((int) *cp))
231 ++cp;
232 while (isalnum ((int) *cp) || *cp == '_')
233 {
234 vStringPut (name, (int) *cp);
235 ++cp;
236 }
237 makeSimpleTag (name, K_SUB);
238 vStringClear (name);
239 }
240 }
241
242 /* dim variable? */
243 else if (strncasecmp ((const char*) cp, "dim", (size_t) 3) == 0)
244 {
245 cp += 3;
246 if (isspace ((int) *cp))
247 {
248 while (isspace ((int) *cp))
249 ++cp;
250 while (isalnum ((int) *cp) || *cp == '_')
251 {
252 vStringPut (name, (int) *cp);
253 ++cp;
254 }
255 makeSimpleTag (name, K_DIM);
256 vStringClear (name);
257 }
258 }
259
260 /* class declaration? */
261 else if (strncasecmp ((const char*) cp, "class", (size_t) 5) == 0)
262 {
263 cp += 5;
264 if (isspace ((int) *cp))
265 {
266 while (isspace ((int) *cp))
267 ++cp;
268 while (isalnum ((int) *cp) || *cp == '_')
269 {
270 vStringPut (name, (int) *cp);
271 ++cp;
272 }
273 makeSimpleTag (name, K_CLASS);
274 vStringClear (name);
275 }
276 }
277
278 /* const declaration? */
279 else if (strncasecmp ((const char*) cp, "const", (size_t) 5) == 0)
280 {
281 cp += 5;
282 if (isspace ((int) *cp))
283 {
284 while (isspace ((int) *cp))
285 ++cp;
286 while (isalnum ((int) *cp) || *cp == '_')
287 {
288 vStringPut (name, (int) *cp);
289 ++cp;
290 }
291 makeSimpleTag (name, K_CONST);
292 vStringClear (name);
293 }
294 }
295
296 /* nothing relevant */
297 else if (*cp != '\0')
298 cp++;
299 }
300 }
301 vStringDelete (name);
302 }
303
AspParser(void)304 extern parserDefinition* AspParser (void)
305 {
306 static const char *const extensions [] = { "asp", "asa", NULL };
307 parserDefinition* def = parserNew ("Asp");
308 def->kindTable = AspKinds;
309 def->kindCount = ARRAY_SIZE (AspKinds);
310 def->extensions = extensions;
311 def->parser = findAspTags;
312 return def;
313 }
314