Mercurial > emacs
comparison lib-src/etags.c @ 18042:c378dd0b8de7
Various cleanups on TeX, Erlang, Prolog, C.
New function new_pfnote will be used for "optimised tags", but
it depends on a constant that disables it for now.
New possibility of tagging global variables in C/C++/ObjC/Java
is enabled by default. Tags of member variables is disabled
by default. Options --(no-)members and --(no-)globals control them.
New symbol table entries for "import", "package" and "friend".
author | Francesco Potortì <pot@gnu.org> |
---|---|
date | Fri, 30 May 1997 14:53:42 +0000 |
parents | 5b92f8ba5c6d |
children | e315e4e6d40b |
comparison
equal
deleted
inserted
replaced
18041:263f17563fa5 | 18042:c378dd0b8de7 |
---|---|
29 * Regexp tags by Tom Tromey. | 29 * Regexp tags by Tom Tromey. |
30 * | 30 * |
31 * Francesco Potorti` (F.Potorti@cnuce.cnr.it) is the current maintainer. | 31 * Francesco Potorti` (F.Potorti@cnuce.cnr.it) is the current maintainer. |
32 */ | 32 */ |
33 | 33 |
34 char pot_etags_version[] = "@(#) pot revision number is 11.91"; | 34 char pot_etags_version[] = "@(#) pot revision number is 12.11"; |
35 | 35 |
36 #define TRUE 1 | 36 #define TRUE 1 |
37 #define FALSE 0 | 37 #define FALSE 0 |
38 | 38 |
39 #ifndef DEBUG | 39 #ifndef DEBUG |
40 # define DEBUG FALSE | 40 # define DEBUG FALSE |
41 #endif | |
42 | |
43 #ifndef TeX_named_tokens | |
44 # define TeX_named_tokens FALSE | |
45 #endif | 41 #endif |
46 | 42 |
47 #ifdef MSDOS | 43 #ifdef MSDOS |
48 # include <string.h> | 44 # include <string.h> |
49 # include <fcntl.h> | 45 # include <fcntl.h> |
61 #ifdef HAVE_CONFIG_H | 57 #ifdef HAVE_CONFIG_H |
62 # include <config.h> | 58 # include <config.h> |
63 /* On some systems, Emacs defines static as nothing for the sake | 59 /* On some systems, Emacs defines static as nothing for the sake |
64 of unexec. We don't want that here since we don't use unexec. */ | 60 of unexec. We don't want that here since we don't use unexec. */ |
65 # undef static | 61 # undef static |
62 # define ETAGS_REGEXPS | |
63 # define LONG_OPTIONS | |
66 #endif | 64 #endif |
67 | 65 |
68 #if !defined (MSDOS) && !defined (WINDOWSNT) && defined (STDC_HEADERS) | 66 #if !defined (MSDOS) && !defined (WINDOWSNT) && defined (STDC_HEADERS) |
69 #include <stdlib.h> | 67 #include <stdlib.h> |
70 #include <string.h> | 68 #include <string.h> |
81 | 79 |
82 #if !defined (S_ISREG) && defined (S_IFREG) | 80 #if !defined (S_ISREG) && defined (S_IFREG) |
83 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) | 81 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) |
84 #endif | 82 #endif |
85 | 83 |
86 #include <getopt.h> | 84 #ifdef LONG_OPTIONS |
85 # include <getopt.h> | |
86 #else | |
87 # define getopt_long(argc,argv,optstr,lopts,lind) getopt (argc, argv, optstr) | |
88 extern char *optarg; | |
89 extern int optind, opterr; | |
90 #endif /* LONG_OPTIONS */ | |
87 | 91 |
88 #ifdef ETAGS_REGEXPS | 92 #ifdef ETAGS_REGEXPS |
89 # include <regex.h> | 93 # include <regex.h> |
90 #endif /* ETAGS_REGEXPS */ | 94 #endif /* ETAGS_REGEXPS */ |
91 | 95 |
119 #define strneq(s,t,n) ((DEBUG && (s) == NULL && (t) == NULL \ | 123 #define strneq(s,t,n) ((DEBUG && (s) == NULL && (t) == NULL \ |
120 && (abort (), 1)) || !strncmp (s, t, n)) | 124 && (abort (), 1)) || !strncmp (s, t, n)) |
121 | 125 |
122 #define lowcase(c) tolower ((char)c) | 126 #define lowcase(c) tolower ((char)c) |
123 | 127 |
124 #define iswhite(arg) (_wht[arg]) /* T if char is white */ | 128 #define CHARS 256 /* 2^sizeof(char) */ |
125 #define begtoken(arg) (_btk[arg]) /* T if char can start token */ | 129 #define CHAR(x) ((int)x & (CHARS - 1)) |
126 #define intoken(arg) (_itk[arg]) /* T if char can be in token */ | 130 #define iswhite(c) (_wht[CHAR(c)]) /* c is white */ |
127 #define endtoken(arg) (_etk[arg]) /* T if char ends tokens */ | 131 #define notinname(c) (_nin[CHAR(c)]) /* c is not in a name */ |
132 #define begtoken(c) (_btk[CHAR(c)]) /* c can start token */ | |
133 #define intoken(c) (_itk[CHAR(c)]) /* c can be in token */ | |
134 #define endtoken(c) (_etk[CHAR(c)]) /* c ends tokens */ | |
128 | 135 |
129 #ifdef DOS_NT | 136 #ifdef DOS_NT |
130 # define absolutefn(fn) (fn[0] == '/' \ | 137 # define absolutefn(fn) (fn[0] == '/' \ |
131 || (fn[1] == ':' && fn[2] == '/')) | 138 || (fn[1] == ':' && fn[2] == '/')) |
132 #else | 139 #else |
145 (n) * sizeof (Type))) | 152 (n) * sizeof (Type))) |
146 #else | 153 #else |
147 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type))) | 154 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type))) |
148 #endif | 155 #endif |
149 | 156 |
150 typedef int logical; | 157 typedef int bool; |
151 | 158 |
152 typedef struct nd_st | 159 typedef struct nd_st |
153 { /* sorting structure */ | 160 { /* sorting structure */ |
154 char *name; /* function or type name */ | 161 char *name; /* function or type name */ |
155 char *file; /* file name */ | 162 char *file; /* file name */ |
156 logical is_func; /* use pattern or line no */ | 163 bool is_func; /* use pattern or line no */ |
157 logical been_warned; /* set if noticed dup */ | 164 bool been_warned; /* set if noticed dup */ |
158 int lno; /* line number tag is on */ | 165 int lno; /* line number tag is on */ |
159 long cno; /* character number line starts on */ | 166 long cno; /* character number line starts on */ |
160 char *pat; /* search pattern */ | 167 char *pat; /* search pattern */ |
161 struct nd_st *left, *right; /* left and right sons */ | 168 struct nd_st *left, *right; /* left and right sons */ |
162 } NODE; | 169 } NODE; |
170 char *relative_filename (), *absolute_filename (), *absolute_dirname (); | 177 char *relative_filename (), *absolute_filename (), *absolute_dirname (); |
171 void grow_linebuffer (); | 178 void grow_linebuffer (); |
172 long *xmalloc (), *xrealloc (); | 179 long *xmalloc (), *xrealloc (); |
173 | 180 |
174 typedef void Lang_function (); | 181 typedef void Lang_function (); |
175 #if FALSE /* many compilers barf on this */ | 182 /* Many compilers barf on this: |
176 Lang_function Asm_labels; | 183 Lang_function Asm_labels; |
177 Lang_function default_C_entries; | 184 so let's write it this way */ |
178 Lang_function C_entries; | |
179 Lang_function Cplusplus_entries; | |
180 Lang_function Cjava_entries; | |
181 Lang_function Cstar_entries; | |
182 Lang_function Erlang_functions; | |
183 Lang_function Fortran_functions; | |
184 Lang_function Yacc_entries; | |
185 Lang_function Lisp_functions; | |
186 Lang_function Pascal_functions; | |
187 Lang_function Perl_functions; | |
188 Lang_function Postscript_functions; | |
189 Lang_function Prolog_functions; | |
190 Lang_function Scheme_functions; | |
191 Lang_function TeX_functions; | |
192 Lang_function just_read_file; | |
193 #else /* so let's write it this way */ | |
194 void Asm_labels (); | 185 void Asm_labels (); |
195 void C_entries (); | 186 void C_entries (); |
196 void default_C_entries (); | 187 void default_C_entries (); |
197 void plain_C_entries (); | 188 void plain_C_entries (); |
198 void Cjava_entries (); | 189 void Cjava_entries (); |
190 void Cobol_paragraphs (); | |
199 void Cplusplus_entries (); | 191 void Cplusplus_entries (); |
200 void Cstar_entries (); | 192 void Cstar_entries (); |
201 void Erlang_functions (); | 193 void Erlang_functions (); |
202 void Fortran_functions (); | 194 void Fortran_functions (); |
203 void Yacc_entries (); | 195 void Yacc_entries (); |
207 void Postscript_functions (); | 199 void Postscript_functions (); |
208 void Prolog_functions (); | 200 void Prolog_functions (); |
209 void Scheme_functions (); | 201 void Scheme_functions (); |
210 void TeX_functions (); | 202 void TeX_functions (); |
211 void just_read_file (); | 203 void just_read_file (); |
212 #endif | |
213 | 204 |
214 Lang_function *get_language_from_name (); | 205 Lang_function *get_language_from_name (); |
215 Lang_function *get_language_from_interpreter (); | 206 Lang_function *get_language_from_interpreter (); |
216 Lang_function *get_language_from_suffix (); | 207 Lang_function *get_language_from_suffix (); |
217 int total_size_of_entries (); | 208 int total_size_of_entries (); |
218 long readline (); | 209 long readline (); |
219 long readline_internal (); | 210 long readline_internal (); |
220 #ifdef ETAGS_REGEXPS | 211 #ifdef ETAGS_REGEXPS |
221 void analyse_regex (); | 212 void analyse_regex (); |
222 void add_regex (); | 213 void add_regex (); |
223 #endif | 214 #endif /* ETAGS_REGEXPS */ |
224 void add_node (); | 215 void add_node (); |
225 void error (); | 216 void error (); |
226 void suggest_asking_for_help (); | 217 void suggest_asking_for_help (); |
227 void fatal (), pfatal (); | 218 void fatal (), pfatal (); |
228 void find_entries (); | 219 void find_entries (); |
229 void free_tree (); | 220 void free_tree (); |
230 void getit (); | 221 void getit (); |
231 void init (); | 222 void init (); |
232 void initbuffer (); | 223 void initbuffer (); |
233 void pfnote (); | 224 void pfnote (), new_pfnote (); |
234 void process_file (); | 225 void process_file (); |
235 void put_entries (); | 226 void put_entries (); |
236 void takeprec (); | 227 void takeprec (); |
237 | 228 |
238 | 229 |
272 long linepos; | 263 long linepos; |
273 struct linebuffer lb; /* used by C_entries instead of lb */ | 264 struct linebuffer lb; /* used by C_entries instead of lb */ |
274 } lbs[2]; | 265 } lbs[2]; |
275 | 266 |
276 /* boolean "functions" (see init) */ | 267 /* boolean "functions" (see init) */ |
277 logical _wht[0177], _etk[0177], _itk[0177], _btk[0177]; | 268 bool _wht[CHARS], _nin[CHARS], _itk[CHARS], _btk[CHARS], _etk[CHARS]; |
278 char | 269 char |
279 /* white chars */ | 270 /* white chars */ |
280 *white = " \f\t\n\013", | 271 *white = " \f\t\n\013", |
272 /* not in a name */ | |
273 *nonam =" \f\t\n\013(=,[;", | |
281 /* token ending chars */ | 274 /* token ending chars */ |
282 *endtk = " \t\n\013\"'#()[]{}=-+%*/&|^~!<>;,.:?", | 275 *endtk = " \t\n\013\"'#()[]{}=-+%*/&|^~!<>;,.:?", |
283 /* token starting chars */ | 276 /* token starting chars */ |
284 *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~@", | 277 *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~@", |
285 /* valid in-token chars */ | 278 /* valid in-token chars */ |
286 *intk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789"; | 279 *midtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789"; |
287 | 280 |
288 logical append_to_tagfile; /* -a: append to tags */ | 281 bool append_to_tagfile; /* -a: append to tags */ |
289 /* The following three default to TRUE for etags, but to FALSE for ctags. */ | 282 /* The following four default to TRUE for etags, but to FALSE for ctags. */ |
290 logical typedefs; /* -t: create tags for typedefs */ | 283 bool typedefs; /* -t: create tags for C typedefs */ |
291 logical typedefs_and_cplusplus; /* -T: create tags for typedefs, level */ | 284 bool typedefs_and_cplusplus; /* -T: create tags for C typedefs, level */ |
292 /* 0 struct/enum/union decls, and C++ */ | 285 /* 0 struct/enum/union decls, and C++ */ |
293 /* member functions. */ | 286 /* member functions. */ |
294 logical constantypedefs; /* -d: create tags for C #define and enum */ | 287 bool constantypedefs; /* -d: create tags for C #define, enum */ |
295 /* constants. */ | 288 /* constants and variables. */ |
296 /* -D: opposite of -d. Default under ctags. */ | 289 /* -D: opposite of -d. Default under ctags. */ |
297 logical update; /* -u: update tags */ | 290 bool globals; /* create tags for C global variables */ |
298 logical vgrind_style; /* -v: create vgrind style index output */ | 291 bool members; /* create tags for C member variables */ |
299 logical no_warnings; /* -w: suppress warnings */ | 292 bool update; /* -u: update tags */ |
300 logical cxref_style; /* -x: create cxref style output */ | 293 bool vgrind_style; /* -v: create vgrind style index output */ |
301 logical cplusplus; /* .[hc] means C++, not C */ | 294 bool no_warnings; /* -w: suppress warnings */ |
302 logical noindentypedefs; /* -I: ignore indentation in C */ | 295 bool cxref_style; /* -x: create cxref style output */ |
303 | 296 bool cplusplus; /* .[hc] means C++, not C */ |
297 bool noindentypedefs; /* -I: ignore indentation in C */ | |
298 | |
299 #ifdef LONG_OPTIONS | |
304 struct option longopts[] = | 300 struct option longopts[] = |
305 { | 301 { |
306 { "append", no_argument, NULL, 'a' }, | 302 { "append", no_argument, NULL, 'a' }, |
307 { "backward-search", no_argument, NULL, 'B' }, | 303 { "backward-search", no_argument, NULL, 'B' }, |
308 { "c++", no_argument, NULL, 'C' }, | 304 { "c++", no_argument, NULL, 'C' }, |
309 { "cxref", no_argument, NULL, 'x' }, | 305 { "cxref", no_argument, NULL, 'x' }, |
310 { "defines", no_argument, NULL, 'd' }, | 306 { "defines", no_argument, NULL, 'd' }, |
311 { "help", no_argument, NULL, 'h' }, | 307 { "no-defines", no_argument, NULL, 'D' }, |
312 { "help", no_argument, NULL, 'H' }, | 308 { "globals", no_argument, &globals, TRUE }, |
313 { "ignore-indentation", no_argument, NULL, 'I' }, | 309 { "no-globals", no_argument, &globals, FALSE }, |
314 { "include", required_argument, NULL, 'i' }, | 310 { "help", no_argument, NULL, 'h' }, |
315 { "language", required_argument, NULL, 'l' }, | 311 { "help", no_argument, NULL, 'H' }, |
316 { "no-defines", no_argument, NULL, 'D' }, | 312 { "ignore-indentation", no_argument, NULL, 'I' }, |
317 { "no-regex", no_argument, NULL, 'R' }, | 313 { "include", required_argument, NULL, 'i' }, |
318 { "no-warn", no_argument, NULL, 'w' }, | 314 { "language", required_argument, NULL, 'l' }, |
319 { "output", required_argument, NULL, 'o' }, | 315 { "members", no_argument, &members, TRUE }, |
320 { "regex", required_argument, NULL, 'r' }, | 316 { "no-members", no_argument, &members, FALSE }, |
321 { "typedefs", no_argument, NULL, 't' }, | 317 { "no-warn", no_argument, NULL, 'w' }, |
322 { "typedefs-and-c++", no_argument, NULL, 'T' }, | 318 { "output", required_argument, NULL, 'o' }, |
323 { "update", no_argument, NULL, 'u' }, | 319 #ifdef ETAGS_REGEXPS |
324 { "version", no_argument, NULL, 'V' }, | 320 { "regex", required_argument, NULL, 'r' }, |
325 { "vgrind", no_argument, NULL, 'v' }, | 321 { "no-regex", no_argument, NULL, 'R' }, |
322 #endif /* ETAGS_REGEXPS */ | |
323 { "typedefs", no_argument, NULL, 't' }, | |
324 { "typedefs-and-c++", no_argument, NULL, 'T' }, | |
325 { "update", no_argument, NULL, 'u' }, | |
326 { "version", no_argument, NULL, 'V' }, | |
327 { "vgrind", no_argument, NULL, 'v' }, | |
326 { 0 } | 328 { 0 } |
327 }; | 329 }; |
330 #endif /* LONG_OPTIONS */ | |
328 | 331 |
329 #ifdef ETAGS_REGEXPS | 332 #ifdef ETAGS_REGEXPS |
330 /* Structure defining a regular expression. Elements are | 333 /* Structure defining a regular expression. Elements are |
331 the compiled pattern, and the name string. */ | 334 the compiled pattern, and the name string. */ |
332 struct pattern | 335 struct pattern |
333 { | 336 { |
334 struct re_pattern_buffer *pattern; | 337 struct re_pattern_buffer *pattern; |
335 struct re_registers regs; | 338 struct re_registers regs; |
336 char *name_pattern; | 339 char *name_pattern; |
337 logical error_signaled; | 340 bool error_signaled; |
338 }; | 341 }; |
339 | 342 |
340 /* Number of regexps found. */ | 343 /* Number of regexps found. */ |
341 int num_patterns = 0; | 344 int num_patterns = 0; |
342 | 345 |
374 NULL }; | 377 NULL }; |
375 | 378 |
376 char *Cjava_suffixes [] = | 379 char *Cjava_suffixes [] = |
377 { "java", NULL }; | 380 { "java", NULL }; |
378 | 381 |
382 char *Cobol_suffixes [] = | |
383 { "COB", "cob", NULL }; | |
384 | |
379 char *Cstar_suffixes [] = | 385 char *Cstar_suffixes [] = |
380 { "cs", "hs", NULL }; | 386 { "cs", "hs", NULL }; |
381 | 387 |
382 char *Erlang_suffixes [] = | 388 char *Erlang_suffixes [] = |
383 { "erl", "hrl", NULL }; | 389 { "erl", "hrl", NULL }; |
434 { | 440 { |
435 { "asm", Asm_labels, Asm_suffixes, NULL }, | 441 { "asm", Asm_labels, Asm_suffixes, NULL }, |
436 { "c", default_C_entries, default_C_suffixes, NULL }, | 442 { "c", default_C_entries, default_C_suffixes, NULL }, |
437 { "c++", Cplusplus_entries, Cplusplus_suffixes, NULL }, | 443 { "c++", Cplusplus_entries, Cplusplus_suffixes, NULL }, |
438 { "c*", Cstar_entries, Cstar_suffixes, NULL }, | 444 { "c*", Cstar_entries, Cstar_suffixes, NULL }, |
445 { "cobol", Cobol_paragraphs, Cobol_suffixes, NULL }, | |
439 { "erlang", Erlang_functions, Erlang_suffixes, NULL }, | 446 { "erlang", Erlang_functions, Erlang_suffixes, NULL }, |
440 { "fortran", Fortran_functions, Fortran_suffixes, NULL }, | 447 { "fortran", Fortran_functions, Fortran_suffixes, NULL }, |
441 { "java", Cjava_entries, Cjava_suffixes, NULL }, | 448 { "java", Cjava_entries, Cjava_suffixes, NULL }, |
442 { "lisp", Lisp_functions, Lisp_suffixes, NULL }, | 449 { "lisp", Lisp_functions, Lisp_suffixes, NULL }, |
443 { "pascal", Pascal_functions, Pascal_suffixes, NULL }, | 450 { "pascal", Pascal_functions, Pascal_suffixes, NULL }, |
492 } | 499 } |
493 | 500 |
494 void | 501 void |
495 print_help () | 502 print_help () |
496 { | 503 { |
497 printf ("These are the options accepted by %s. You may use unambiguous\n\ | 504 printf ("Usage: %s [options] [[regex-option ...] file-name] ...\n\ |
498 abbreviations for the long option names. A - as file name means read\n\ | 505 \n\ |
499 names from stdin.", progname); | 506 These are the options accepted by %s.\n", progname, progname); |
507 #ifdef LONG_OPTIONS | |
508 puts ("You may use unambiguous abbreviations for the long option names."); | |
509 #else | |
510 puts ("Long option names do not work with this executable, as it is not\n\ | |
511 linked with GNU getopt."); | |
512 #endif /* LONG_OPTIONS */ | |
513 puts ("A - as file name means read names from stdin."); | |
500 if (!CTAGS) | 514 if (!CTAGS) |
501 printf (" Absolute names are stored in the output file as they\n\ | 515 printf (" Absolute names are stored in the output file as they\n\ |
502 are. Relative ones are stored relative to the output file's directory."); | 516 are. Relative ones are stored relative to the output file's directory."); |
503 puts ("\n"); | 517 puts ("\n"); |
504 | 518 |
529 checking the current file."); | 543 checking the current file."); |
530 puts ("-l LANG, --language=LANG\n\ | 544 puts ("-l LANG, --language=LANG\n\ |
531 Force the following files to be considered as written in the\n\ | 545 Force the following files to be considered as written in the\n\ |
532 named language up to the next --language=LANG option."); | 546 named language up to the next --language=LANG option."); |
533 } | 547 } |
548 | |
549 if (CTAGS) | |
550 puts ("--globals\n\ | |
551 Create tag entries for global variables in C and derived languages."); | |
552 else | |
553 puts ("--no-globals\n\ | |
554 Do not create tag entries for global variables in C and\n\ | |
555 derived languages. This makes the tags file smaller."); | |
556 puts ("--members\n\ | |
557 Create tag entries for member variables in C and derived languages."); | |
534 | 558 |
535 #ifdef ETAGS_REGEXPS | 559 #ifdef ETAGS_REGEXPS |
536 puts ("-r /REGEXP/, --regex=/REGEXP/ or --regex=@regexfile\n\ | 560 puts ("-r /REGEXP/, --regex=/REGEXP/ or --regex=@regexfile\n\ |
537 Make a tag for each line matching pattern REGEXP in the\n\ | 561 Make a tag for each line matching pattern REGEXP in the\n\ |
538 following files. regexfile is a file containing one REGEXP\n\ | 562 following files. regexfile is a file containing one REGEXP\n\ |
646 char *in; | 670 char *in; |
647 { | 671 { |
648 static long context = 0; | 672 static long context = 0; |
649 static struct dsc$descriptor_s o; | 673 static struct dsc$descriptor_s o; |
650 static struct dsc$descriptor_s i; | 674 static struct dsc$descriptor_s i; |
651 static logical pass1 = TRUE; | 675 static bool pass1 = TRUE; |
652 long status; | 676 long status; |
653 short retval; | 677 short retval; |
654 | 678 |
655 if (pass1) | 679 if (pass1) |
656 { | 680 { |
686 name of each file specified by the provided arg expanding wildcards. | 710 name of each file specified by the provided arg expanding wildcards. |
687 */ | 711 */ |
688 char * | 712 char * |
689 gfnames (arg, p_error) | 713 gfnames (arg, p_error) |
690 char *arg; | 714 char *arg; |
691 logical *p_error; | 715 bool *p_error; |
692 { | 716 { |
693 static vspec filename = {MAX_FILE_SPEC_LEN, "\0"}; | 717 static vspec filename = {MAX_FILE_SPEC_LEN, "\0"}; |
694 | 718 |
695 switch (fn_exp (&filename, arg)) | 719 switch (fn_exp (&filename, arg)) |
696 { | 720 { |
744 char *this_file; | 768 char *this_file; |
745 argument *argbuffer; | 769 argument *argbuffer; |
746 int current_arg, file_count; | 770 int current_arg, file_count; |
747 struct linebuffer filename_lb; | 771 struct linebuffer filename_lb; |
748 #ifdef VMS | 772 #ifdef VMS |
749 logical got_err; | 773 bool got_err; |
750 #endif | 774 #endif |
751 | 775 |
752 #ifdef DOS_NT | 776 #ifdef DOS_NT |
753 _fmode = O_BINARY; /* all of files are treated as binary files */ | 777 _fmode = O_BINARY; /* all of files are treated as binary files */ |
754 #endif /* DOS_NT */ | 778 #endif /* DOS_NT */ |
768 re_set_syntax (RE_SYNTAX_EMACS); | 792 re_set_syntax (RE_SYNTAX_EMACS); |
769 #endif /* ETAGS_REGEXPS */ | 793 #endif /* ETAGS_REGEXPS */ |
770 | 794 |
771 /* | 795 /* |
772 * If etags, always find typedefs and structure tags. Why not? | 796 * If etags, always find typedefs and structure tags. Why not? |
773 * Also default is to find macro constants and enum constants. | 797 * Also default is to find macro constants, enum constants and |
798 * global variables. | |
774 */ | 799 */ |
775 if (!CTAGS) | 800 if (!CTAGS) |
776 typedefs = typedefs_and_cplusplus = constantypedefs = TRUE; | 801 { |
802 typedefs = typedefs_and_cplusplus = constantypedefs = TRUE; | |
803 globals = TRUE; | |
804 members = FALSE; | |
805 } | |
777 | 806 |
778 while (1) | 807 while (1) |
779 { | 808 { |
780 int opt = getopt_long (argc, argv, | 809 int opt; |
781 "-aCdDf:Il:o:r:RStTi:BuvxwVhH", longopts, 0); | 810 char *optstring; |
782 | 811 |
812 #ifdef ETAGS_REGEXPS | |
813 optstring = "-aCdDf:Il:o:r:RStTi:BuvxwVhH"; | |
814 #else | |
815 optstring = "-aCdDf:Il:o:StTi:BuvxwVhH"; | |
816 #endif /* ETAGS_REGEXPS */ | |
817 | |
818 #ifndef LONG_OPTIONS | |
819 optstring = optstring + 1; | |
820 #endif /* LONG_OPTIONS */ | |
821 | |
822 opt = getopt_long (argc, argv, optstring, longopts, 0); | |
783 if (opt == EOF) | 823 if (opt == EOF) |
784 break; | 824 break; |
785 | 825 |
786 switch (opt) | 826 switch (opt) |
787 { | 827 { |
797 ++current_arg; | 837 ++current_arg; |
798 ++file_count; | 838 ++file_count; |
799 break; | 839 break; |
800 | 840 |
801 /* Common options. */ | 841 /* Common options. */ |
802 case 'a': | 842 case 'a': append_to_tagfile = TRUE; break; |
803 append_to_tagfile = TRUE; | 843 case 'C': cplusplus = TRUE; break; |
804 break; | 844 case 'd': constantypedefs = TRUE; break; |
805 case 'C': | 845 case 'D': constantypedefs = FALSE; break; |
806 cplusplus = TRUE; | |
807 break; | |
808 case 'd': | |
809 constantypedefs = TRUE; | |
810 break; | |
811 case 'D': | |
812 constantypedefs = FALSE; | |
813 break; | |
814 case 'f': /* for compatibility with old makefiles */ | 846 case 'f': /* for compatibility with old makefiles */ |
815 case 'o': | 847 case 'o': |
816 if (tagfile) | 848 if (tagfile) |
817 { | 849 { |
818 error ("-%c option may only be given once.", opt); | 850 error ("-%c option may only be given once.", opt); |
859 case 'i': | 891 case 'i': |
860 included_files[nincluded_files++] = optarg; | 892 included_files[nincluded_files++] = optarg; |
861 break; | 893 break; |
862 #else /* CTAGS */ | 894 #else /* CTAGS */ |
863 /* Ctags options. */ | 895 /* Ctags options. */ |
864 case 'B': | 896 case 'B': searchar = '?'; break; |
865 searchar = '?'; | 897 case 'u': update = TRUE; break; |
866 break; | 898 case 'v': vgrind_style = TRUE; /*FALLTHRU*/ |
867 case 'u': | 899 case 'x': cxref_style = TRUE; break; |
868 update = TRUE; | 900 case 'w': no_warnings = TRUE; break; |
869 break; | |
870 case 'v': | |
871 vgrind_style = TRUE; | |
872 /*FALLTHRU*/ | |
873 case 'x': | |
874 cxref_style = TRUE; | |
875 break; | |
876 case 'w': | |
877 no_warnings = TRUE; | |
878 break; | |
879 #endif /* CTAGS */ | 901 #endif /* CTAGS */ |
880 default: | 902 default: |
881 suggest_asking_for_help (); | 903 suggest_asking_for_help (); |
882 } | 904 } |
883 } | 905 } |
890 ++file_count; | 912 ++file_count; |
891 } | 913 } |
892 | 914 |
893 if (nincluded_files == 0 && file_count == 0) | 915 if (nincluded_files == 0 && file_count == 0) |
894 { | 916 { |
895 error ("%s", "No input files specified."); | 917 error ("no input files specified.", 0); |
896 suggest_asking_for_help (); | 918 suggest_asking_for_help (); |
897 } | 919 } |
898 | 920 |
899 if (tagfile == NULL) | 921 if (tagfile == NULL) |
900 tagfile = CTAGS ? "tags" : "TAGS"; | 922 tagfile = CTAGS ? "tags" : "TAGS"; |
955 #ifdef VMS | 977 #ifdef VMS |
956 while ((this_file = gfnames (argbuffer[i].what, &got_err)) != NULL) | 978 while ((this_file = gfnames (argbuffer[i].what, &got_err)) != NULL) |
957 { | 979 { |
958 if (got_err) | 980 if (got_err) |
959 { | 981 { |
960 error ("Can't find file %s\n", this_file); | 982 error ("can't find file %s\n", this_file); |
961 argc--, argv++; | 983 argc--, argv++; |
962 } | 984 } |
963 else | 985 else |
964 { | 986 { |
965 this_file = massage_name (this_file); | 987 this_file = massage_name (this_file); |
1119 *p = '/'; | 1141 *p = '/'; |
1120 #endif | 1142 #endif |
1121 | 1143 |
1122 if (stat (file, &stat_buf) == 0 && !S_ISREG (stat_buf.st_mode)) | 1144 if (stat (file, &stat_buf) == 0 && !S_ISREG (stat_buf.st_mode)) |
1123 { | 1145 { |
1124 error ("Skipping %s: it is not a regular file.", file); | 1146 error ("skipping %s: it is not a regular file.", file); |
1125 return; | 1147 return; |
1126 } | 1148 } |
1127 if (streq (file, tagfile) && !streq (tagfile, "-")) | 1149 if (streq (file, tagfile) && !streq (tagfile, "-")) |
1128 { | 1150 { |
1129 error ("Skipping inclusion of %s in self.", file); | 1151 error ("skipping inclusion of %s in self.", file); |
1130 return; | 1152 return; |
1131 } | 1153 } |
1132 inf = fopen (file, "r"); | 1154 inf = fopen (file, "r"); |
1133 if (inf == NULL) | 1155 if (inf == NULL) |
1134 { | 1156 { |
1173 init () | 1195 init () |
1174 { | 1196 { |
1175 register char *sp; | 1197 register char *sp; |
1176 register int i; | 1198 register int i; |
1177 | 1199 |
1178 for (i = 0; i < 0177; i++) | 1200 for (i = 0; i < CHARS; i++) |
1179 _wht[i] = _etk[i] = _itk[i] = _btk[i] = FALSE; | 1201 _wht[i] = _nin[i] = _etk[i] = _itk[i] = _btk[i] = FALSE; |
1180 for (sp = white; *sp; sp++) | 1202 for (sp = white; *sp; sp++) _wht[*sp] = TRUE; _wht[0] = _wht['\n']; |
1181 _wht[*sp] = TRUE; | 1203 for (sp = nonam; *sp; sp++) _nin[*sp] = TRUE; _nin[0] = _nin['\n']; |
1182 for (sp = endtk; *sp; sp++) | 1204 for (sp = endtk; *sp; sp++) _etk[*sp] = TRUE; _etk[0] = _etk['\n']; |
1183 _etk[*sp] = TRUE; | 1205 for (sp = midtk; *sp; sp++) _itk[*sp] = TRUE; _btk[0] = _btk['\n']; |
1184 for (sp = intk; *sp; sp++) | 1206 for (sp = begtk; *sp; sp++) _btk[*sp] = TRUE; _itk[0] = _itk['\n']; |
1185 _itk[*sp] = TRUE; | |
1186 for (sp = begtk; *sp; sp++) | |
1187 _btk[*sp] = TRUE; | |
1188 _wht[0] = _wht['\n']; | |
1189 _etk[0] = _etk['\n']; | |
1190 _btk[0] = _btk['\n']; | |
1191 _itk[0] = _itk['\n']; | |
1192 } | 1207 } |
1193 | 1208 |
1194 /* | 1209 /* |
1195 * This routine opens the specified file and calls the function | 1210 * This routine opens the specified file and calls the function |
1196 * which finds the function and type definitions. | 1211 * which finds the function and type definitions. |
1283 | 1298 |
1284 /* Record a tag. */ | 1299 /* Record a tag. */ |
1285 void | 1300 void |
1286 pfnote (name, is_func, linestart, linelen, lno, cno) | 1301 pfnote (name, is_func, linestart, linelen, lno, cno) |
1287 char *name; /* tag name, or NULL if unnamed */ | 1302 char *name; /* tag name, or NULL if unnamed */ |
1288 logical is_func; /* tag is a function */ | 1303 bool is_func; /* tag is a function */ |
1289 char *linestart; /* start of the line where tag is */ | 1304 char *linestart; /* start of the line where tag is */ |
1290 int linelen; /* length of the line where tag is */ | 1305 int linelen; /* length of the line where tag is */ |
1291 int lno; /* line number */ | 1306 int lno; /* line number */ |
1292 long cno; /* character number */ | 1307 long cno; /* character number */ |
1293 { | 1308 { |
1329 } | 1344 } |
1330 else | 1345 else |
1331 np->pat = savenstr (linestart, linelen); | 1346 np->pat = savenstr (linestart, linelen); |
1332 | 1347 |
1333 add_node (np, &head); | 1348 add_node (np, &head); |
1349 } | |
1350 | |
1351 /* Date: Wed, 22 Jan 1997 02:56:31 -0500 | |
1352 * From: Sam Kendall <kendall@cybercom.net> | |
1353 * Subject: Proposal for firming up the TAGS format specification | |
1354 * To: F.Potorti@cnuce.cnr.it | |
1355 * | |
1356 * pfnote should emit the optimized form [unnamed tag] only if: | |
1357 * 1. name does not contain any of the characters " \t\r\n()"; | |
1358 * 2. linestart contains name as either a rightmost, or rightmost but | |
1359 * one character, substring; | |
1360 * 3. the character, if any, immediately before name in linestart must | |
1361 * be one of the characters " \t()"; | |
1362 * 4. the character, if any, immediately after name in linestart must | |
1363 * also be one of the characters " \t()". | |
1364 */ | |
1365 #define traditional_tag_style TRUE | |
1366 void | |
1367 new_pfnote (name, namelen, is_func, linestart, linelen, lno, cno) | |
1368 char *name; /* tag name, or NULL if unnamed */ | |
1369 int namelen; /* tag length */ | |
1370 bool is_func; /* tag is a function */ | |
1371 char *linestart; /* start of the line where tag is */ | |
1372 int linelen; /* length of the line where tag is */ | |
1373 int lno; /* line number */ | |
1374 long cno; /* character number */ | |
1375 { | |
1376 register char *cp; | |
1377 bool named; | |
1378 | |
1379 named = TRUE; | |
1380 if (!CTAGS) | |
1381 { | |
1382 for (cp = name; !notinname (*cp); cp++) | |
1383 continue; | |
1384 if (*cp == '\0') /* rule #1 */ | |
1385 { | |
1386 cp = linestart + linelen - namelen; | |
1387 if (notinname (linestart[linelen-1])) | |
1388 cp -= 1; /* rule #4 */ | |
1389 if (cp >= linestart /* rule #2 */ | |
1390 && (cp == linestart | |
1391 || notinname (cp[-1])) /* rule #3 */ | |
1392 && strneq (name, cp, namelen)) /* rule #2 */ | |
1393 named = FALSE; /* use unnamed tag */ | |
1394 } | |
1395 } | |
1396 | |
1397 if (named) | |
1398 name = savenstr (name, namelen); | |
1399 else | |
1400 name = NULL; | |
1401 pfnote (name, is_func, linestart, linelen, lno, cno); | |
1334 } | 1402 } |
1335 | 1403 |
1336 /* | 1404 /* |
1337 * free_tree () | 1405 * free_tree () |
1338 * recurse on left children, iterate on right children. | 1406 * recurse on left children, iterate on right children. |
1535 /* | 1603 /* |
1536 * The C symbol tables. | 1604 * The C symbol tables. |
1537 */ | 1605 */ |
1538 enum sym_type | 1606 enum sym_type |
1539 { | 1607 { |
1540 st_none, st_C_objprot, st_C_objimpl, st_C_objend, st_C_gnumacro, | 1608 st_none, |
1541 st_C_struct, st_C_enum, st_C_define, st_C_typedef, st_C_typespec, | 1609 st_C_objprot, st_C_objimpl, st_C_objend, |
1542 st_C_javastruct | 1610 st_C_gnumacro, |
1611 st_C_ignore, | |
1612 st_C_javastruct, | |
1613 st_C_struct, st_C_enum, st_C_define, st_C_typedef, st_C_typespec | |
1543 }; | 1614 }; |
1544 | 1615 |
1545 /* Feed stuff between (but not including) %[ and %] lines to: | 1616 /* Feed stuff between (but not including) %[ and %] lines to: |
1546 gperf -c -k 1,3 -o -p -r -t | 1617 gperf -c -k 1,3 -o -p -r -t |
1547 %[ | 1618 %[ |
1549 %% | 1620 %% |
1550 @interface, 0, st_C_objprot | 1621 @interface, 0, st_C_objprot |
1551 @protocol, 0, st_C_objprot | 1622 @protocol, 0, st_C_objprot |
1552 @implementation,0, st_C_objimpl | 1623 @implementation,0, st_C_objimpl |
1553 @end, 0, st_C_objend | 1624 @end, 0, st_C_objend |
1625 import, C_JAVA, st_C_ignore | |
1626 package, C_JAVA, st_C_ignore | |
1627 friend, C_PLPL, st_C_ignore | |
1554 extends, C_JAVA, st_C_javastruct | 1628 extends, C_JAVA, st_C_javastruct |
1555 implements, C_JAVA, st_C_javastruct | 1629 implements, C_JAVA, st_C_javastruct |
1556 class, C_PLPL, st_C_struct | 1630 class, C_PLPL, st_C_struct |
1557 namespace, C_PLPL, st_C_struct | 1631 namespace, C_PLPL, st_C_struct |
1558 domain, C_STAR, st_C_struct | 1632 domain, C_STAR, st_C_struct |
1589 #EXFUN, 0, st_C_gnumacro | 1663 #EXFUN, 0, st_C_gnumacro |
1590 #DEFVAR_, 0, st_C_gnumacro | 1664 #DEFVAR_, 0, st_C_gnumacro |
1591 %] | 1665 %] |
1592 and replace lines between %< and %> with its output. */ | 1666 and replace lines between %< and %> with its output. */ |
1593 /*%<*/ | 1667 /*%<*/ |
1668 /* starting time is 10:31:16 */ | |
1594 /* C code produced by gperf version 2.1 (K&R C version) */ | 1669 /* C code produced by gperf version 2.1 (K&R C version) */ |
1595 /* Command-line: gperf -c -k 1,3 -o -p -r -t */ | 1670 /* Command-line: gperf -c -k 1,3 -o -p -r -t */ |
1596 | 1671 |
1597 | 1672 |
1598 struct C_stab_entry { char *name; int c_ext; enum sym_type type; }; | 1673 struct C_stab_entry { char *name; int c_ext; enum sym_type type; }; |
1599 | 1674 |
1600 #define MIN_WORD_LENGTH 3 | 1675 #define MIN_WORD_LENGTH 3 |
1601 #define MAX_WORD_LENGTH 15 | 1676 #define MAX_WORD_LENGTH 15 |
1602 #define MIN_HASH_VALUE 33 | 1677 #define MIN_HASH_VALUE 15 |
1603 #define MAX_HASH_VALUE 126 | 1678 #define MAX_HASH_VALUE 128 |
1604 /* | 1679 /* |
1605 36 keywords | 1680 39 keywords |
1606 94 is the maximum key range | 1681 114 is the maximum key range |
1607 */ | 1682 */ |
1608 | 1683 |
1609 int | 1684 static int |
1610 hash (str, len) | 1685 hash (str, len) |
1611 register char *str; | 1686 register char *str; |
1612 register unsigned int len; | 1687 register unsigned int len; |
1613 { | 1688 { |
1614 static unsigned char hash_table[] = | 1689 static unsigned char hash_table[] = |
1615 { | 1690 { |
1616 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, | 1691 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
1617 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, | 1692 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
1618 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, | 1693 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
1619 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, | 1694 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
1620 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, | 1695 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
1621 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, | 1696 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
1622 126, 126, 126, 126, 15, 126, 126, 126, 53, 24, | 1697 128, 128, 128, 128, 39, 128, 128, 128, 54, 48, |
1623 41, 126, 126, 126, 126, 126, 126, 126, 126, 126, | 1698 46, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
1624 51, 126, 126, 26, 47, 126, 126, 126, 126, 126, | 1699 28, 128, 128, 40, 32, 128, 128, 128, 128, 128, |
1625 126, 126, 126, 126, 126, 126, 126, 11, 36, 26, | 1700 128, 128, 128, 128, 128, 128, 128, 24, 30, 47, |
1626 35, 13, 22, 39, 126, 34, 126, 126, 43, 21, | 1701 62, 7, 60, 27, 128, 60, 128, 128, 59, 16, |
1627 36, 6, 49, 126, 47, 61, 28, 57, 35, 126, | 1702 31, 23, 45, 128, 4, 14, 2, 55, 5, 128, |
1628 126, 126, 126, 126, 126, 126, 126, 126, | 1703 128, 128, 128, 128, 128, 128, 128, 128, |
1629 }; | 1704 }; |
1630 return len + hash_table[str[2]] + hash_table[str[0]]; | 1705 return len + hash_table[str[2]] + hash_table[str[0]]; |
1631 } | 1706 } |
1632 | 1707 |
1633 struct C_stab_entry * | 1708 struct C_stab_entry * |
1637 { | 1712 { |
1638 | 1713 |
1639 static struct C_stab_entry wordlist[] = | 1714 static struct C_stab_entry wordlist[] = |
1640 { | 1715 { |
1641 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | 1716 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, |
1642 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | |
1643 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | |
1644 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | 1717 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, |
1645 {"float", 0, st_C_typespec}, | |
1646 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | |
1647 {"char", 0, st_C_typespec}, | |
1648 {"class", C_PLPL, st_C_struct}, | |
1649 {"auto", 0, st_C_typespec}, | |
1650 {"",}, {"",}, | |
1651 {"bool", C_PLPL, st_C_typespec}, | |
1652 {"extern", 0, st_C_typespec}, | 1718 {"extern", 0, st_C_typespec}, |
1653 {"extends", C_JAVA, st_C_javastruct}, | 1719 {"extends", C_JAVA, st_C_javastruct}, |
1720 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | |
1721 {"struct", 0, st_C_struct}, | |
1722 {"mutable", C_PLPL, st_C_typespec}, | |
1723 {"",}, {"",}, {"",}, {"",}, | |
1724 {"auto", 0, st_C_typespec}, | |
1725 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | |
1654 {"",}, {"",}, | 1726 {"",}, {"",}, |
1655 {"@implementation", 0, st_C_objimpl}, | |
1656 {"",}, {"",}, {"",}, | |
1657 {"@end", 0, st_C_objend}, | |
1658 {"mutable", C_PLPL, st_C_typespec}, | |
1659 {"",}, {"",}, | |
1660 {"SYSCALL", 0, st_C_gnumacro}, | |
1661 {"",}, | |
1662 {"@interface", 0, st_C_objprot}, | |
1663 {"domain", C_STAR, st_C_struct}, | |
1664 {"define", 0, st_C_define}, | |
1665 {"",}, | |
1666 {"int", 0, st_C_typespec}, | |
1667 {"namespace", C_PLPL, st_C_struct}, | |
1668 {"const", 0, st_C_typespec}, | |
1669 {"",}, {"",}, | |
1670 {"explicit", C_PLPL, st_C_typespec}, | |
1671 {"@protocol", 0, st_C_objprot}, | |
1672 {"short", 0, st_C_typespec}, | 1727 {"short", 0, st_C_typespec}, |
1673 {"void", 0, st_C_typespec}, | |
1674 {"enum", 0, st_C_enum}, | |
1675 {"",}, | |
1676 {"ENTRY", 0, st_C_gnumacro}, | |
1677 {"",}, | 1728 {"",}, |
1678 {"static", 0, st_C_typespec}, | 1729 {"static", 0, st_C_typespec}, |
1679 {"",}, {"",}, | 1730 {"",}, {"",}, |
1680 {"PSEUDO", 0, st_C_gnumacro}, | 1731 {"signed", 0, st_C_typespec}, |
1732 {"",}, {"",}, {"",}, {"",}, | |
1733 {"@protocol", 0, st_C_objprot}, | |
1681 {"",}, | 1734 {"",}, |
1682 {"long", 0, st_C_typespec}, | |
1683 {"typedef", 0, st_C_typedef}, | 1735 {"typedef", 0, st_C_typedef}, |
1684 {"typename", C_PLPL, st_C_typespec}, | 1736 {"typename", C_PLPL, st_C_typespec}, |
1737 {"namespace", C_PLPL, st_C_struct}, | |
1738 {"bool", C_PLPL, st_C_typespec}, | |
1739 {"",}, {"",}, | |
1740 {"explicit", C_PLPL, st_C_typespec}, | |
1741 {"",}, {"",}, {"",}, {"",}, | |
1742 {"int", 0, st_C_typespec}, | |
1743 {"enum", 0, st_C_enum}, | |
1744 {"",}, {"",}, | |
1745 {"void", 0, st_C_typespec}, | |
1746 {"@implementation", 0, st_C_objimpl}, | |
1747 {"",}, | |
1685 {"volatile", 0, st_C_typespec}, | 1748 {"volatile", 0, st_C_typespec}, |
1686 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | 1749 {"",}, |
1750 {"@end", 0, st_C_objend}, | |
1751 {"char", 0, st_C_typespec}, | |
1752 {"class", C_PLPL, st_C_struct}, | |
1753 {"unsigned", 0, st_C_typespec}, | |
1754 {"",}, {"",}, | |
1755 {"@interface", 0, st_C_objprot}, | |
1756 {"",}, | |
1757 {"PSEUDO", 0, st_C_gnumacro}, | |
1758 {"const", 0, st_C_typespec}, | |
1759 {"domain", C_STAR, st_C_struct}, | |
1760 {"ENTRY", 0, st_C_gnumacro}, | |
1761 {"",}, | |
1762 {"SYSCALL", 0, st_C_gnumacro}, | |
1763 {"float", 0, st_C_typespec}, | |
1764 {"",}, {"",}, {"",}, {"",}, {"",}, | |
1765 {"long", 0, st_C_typespec}, | |
1766 {"",}, {"",}, {"",}, {"",}, | |
1767 {"package", C_JAVA, st_C_ignore}, | |
1768 {"",}, {"",}, {"",}, {"",}, {"",}, | |
1769 {"DEFUN", 0, st_C_gnumacro}, | |
1770 {"",}, {"",}, {"",}, {"",}, {"",}, | |
1771 {"import", C_JAVA, st_C_ignore}, | |
1772 {"",}, {"",}, {"",}, | |
1687 {"implements", C_JAVA, st_C_javastruct}, | 1773 {"implements", C_JAVA, st_C_javastruct}, |
1774 {"",}, {"",}, {"",}, {"",}, | |
1775 {"union", 0, st_C_struct}, | |
1688 {"",}, {"",}, | 1776 {"",}, {"",}, |
1689 {"union", 0, st_C_struct}, | 1777 {"double", 0, st_C_typespec}, |
1778 {"",}, {"",}, | |
1779 {"friend", C_PLPL, st_C_ignore}, | |
1690 {"",}, | 1780 {"",}, |
1691 {"double", 0, st_C_typespec}, | 1781 {"define", 0, st_C_define}, |
1692 {"DEFUN", 0, st_C_gnumacro}, | |
1693 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | |
1694 {"signed", 0, st_C_typespec}, | |
1695 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | |
1696 {"struct", 0, st_C_struct}, | |
1697 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, | |
1698 {"",}, {"",}, | |
1699 {"unsigned", 0, st_C_typespec}, | |
1700 }; | 1782 }; |
1701 | 1783 |
1702 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) | 1784 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) |
1703 { | 1785 { |
1704 register int key = hash (str, len); | 1786 register int key = hash (str, len); |
1711 return &wordlist[key]; | 1793 return &wordlist[key]; |
1712 } | 1794 } |
1713 } | 1795 } |
1714 return 0; | 1796 return 0; |
1715 } | 1797 } |
1798 /* ending time is 10:31:16 */ | |
1716 /*%>*/ | 1799 /*%>*/ |
1717 | 1800 |
1718 enum sym_type | 1801 enum sym_type |
1719 C_symtype (str, len, c_ext) | 1802 C_symtype (str, len, c_ext) |
1720 char *str; | 1803 char *str; |
1727 return st_none; | 1810 return st_none; |
1728 return se->type; | 1811 return se->type; |
1729 } | 1812 } |
1730 | 1813 |
1731 /* | 1814 /* |
1732 * C functions are recognized using a simple finite automaton. | 1815 * C functions and variables are recognized using a simple |
1733 * funcdef is its state variable. | 1816 * finite automaton. fvdef is its state variable. |
1734 */ | 1817 */ |
1735 enum | 1818 enum |
1736 { | 1819 { |
1737 fnone, /* nothing seen */ | 1820 fvnone, /* nothing seen */ |
1738 ftagseen, /* function-like tag seen */ | 1821 fvnameseen, /* function or variable name seen */ |
1739 fstartlist, /* just after open parenthesis */ | 1822 fstartlist, /* func: just after open parenthesis */ |
1740 finlist, /* in parameter list */ | 1823 finlist, /* func: in parameter list */ |
1741 flistseen, /* after parameter list */ | 1824 flistseen, /* func: after parameter list */ |
1742 fignore /* before open brace */ | 1825 fignore, /* func: before open brace */ |
1743 } funcdef; | 1826 vignore /* var-like: ignore until ';' */ |
1827 } fvdef; | |
1744 | 1828 |
1745 | 1829 |
1746 /* | 1830 /* |
1747 * typedefs are recognized using a simple finite automaton. | 1831 * typedefs are recognized using a simple finite automaton. |
1748 * typdef is its state variable. | 1832 * typdef is its state variable. |
1813 omethodcolon, /* after method colon */ | 1897 omethodcolon, /* after method colon */ |
1814 omethodparm, /* after method parameter */ | 1898 omethodparm, /* after method parameter */ |
1815 oignore /* wait for @end */ | 1899 oignore /* wait for @end */ |
1816 } objdef; | 1900 } objdef; |
1817 | 1901 |
1902 | |
1903 /* | |
1904 * Use this structure to keep info about the token read, and how it | |
1905 * should be tagged. Used by the make_C_tag function to build a tag. | |
1906 */ | |
1907 typedef struct | |
1908 { | |
1909 bool valid; | |
1910 char *str; | |
1911 bool named; | |
1912 int linelen; | |
1913 int lineno; | |
1914 long linepos; | |
1915 char *buffer; | |
1916 } TOKEN; | |
1917 TOKEN tok; /* latest token read */ | |
1918 | |
1919 | |
1818 /* | 1920 /* |
1819 * Set this to TRUE, and the next token considered is called a function. | 1921 * Set this to TRUE, and the next token considered is called a function. |
1820 * Used only for GNU emacs's function-defining macros. | 1922 * Used only for GNU emacs's function-defining macros. |
1821 */ | 1923 */ |
1822 logical next_token_is_func; | 1924 bool next_token_is_func; |
1823 | 1925 |
1824 /* | 1926 /* |
1825 * TRUE in the rules part of a yacc file, FALSE outside (parse as C). | 1927 * TRUE in the rules part of a yacc file, FALSE outside (parse as C). |
1826 */ | 1928 */ |
1827 logical yacc_rules; | 1929 bool yacc_rules; |
1828 | 1930 |
1829 /* | 1931 /* |
1830 * methodlen is the length of the method name stored in token_name. | 1932 * methodlen is the length of the method name stored in token_name. |
1831 */ | 1933 */ |
1832 int methodlen; | 1934 int methodlen; |
1833 | 1935 |
1834 /* | 1936 /* |
1835 * consider_token () | 1937 * consider_token () |
1836 * checks to see if the current token is at the start of a | 1938 * checks to see if the current token is at the start of a |
1837 * function, or corresponds to a typedef, or is a struct/union/enum | 1939 * function or variable, or corresponds to a typedef, or |
1838 * tag, or #define, or an enum constant. | 1940 * is a struct/union/enum tag, or #define, or an enum constant. |
1839 * | 1941 * |
1840 * *IS_FUNC gets TRUE iff the token is a function or #define macro | 1942 * *IS_FUNC gets TRUE iff the token is a function or #define macro |
1841 * with args. C_EXT is which language we are looking at. | 1943 * with args. C_EXT is which language we are looking at. |
1842 * | 1944 * |
1843 * In the future we will need some way to adjust where the end of | 1945 * In the future we will need some way to adjust where the end of |
1844 * the token is; for instance, implementing the C++ keyword | 1946 * the token is; for instance, implementing the C++ keyword |
1845 * `operator' properly will adjust the end of the token to be after | 1947 * `operator' properly will adjust the end of the token to be after |
1846 * whatever follows `operator'. | 1948 * whatever follows `operator'. |
1847 * | 1949 * |
1848 * Globals | 1950 * Globals |
1849 * funcdef IN OUT | 1951 * fvdef IN OUT |
1850 * structdef IN OUT | 1952 * structdef IN OUT |
1851 * definedef IN OUT | 1953 * definedef IN OUT |
1852 * typdef IN OUT | 1954 * typdef IN OUT |
1853 * objdef IN OUT | 1955 * objdef IN OUT |
1854 * next_token_is_func IN OUT | 1956 * next_token_is_func IN OUT |
1855 */ | 1957 */ |
1856 | 1958 |
1857 logical | 1959 bool |
1858 consider_token (str, len, c, c_ext, cblev, parlev, is_func) | 1960 consider_token (str, len, c, c_ext, cblev, parlev, is_func_or_var) |
1859 register char *str; /* IN: token pointer */ | 1961 register char *str; /* IN: token pointer */ |
1860 register int len; /* IN: token length */ | 1962 register int len; /* IN: token length */ |
1861 register char c; /* IN: first char after the token */ | 1963 register char c; /* IN: first char after the token */ |
1862 int c_ext; /* IN: C extensions mask */ | 1964 int c_ext; /* IN: C extensions mask */ |
1863 int cblev; /* IN: curly brace level */ | 1965 int cblev; /* IN: curly brace level */ |
1864 int parlev; /* IN: parenthesis level */ | 1966 int parlev; /* IN: parenthesis level */ |
1865 logical *is_func; /* OUT: function found */ | 1967 bool *is_func_or_var; /* OUT: function or variable found */ |
1866 { | 1968 { |
1867 enum sym_type toktype = C_symtype (str, len, c_ext); | 1969 enum sym_type toktype = C_symtype (str, len, c_ext); |
1868 | 1970 |
1869 /* | 1971 /* |
1870 * Advance the definedef state machine. | 1972 * Advance the definedef state machine. |
1888 /* | 1990 /* |
1889 * Make a tag for any macro, unless it is a constant | 1991 * Make a tag for any macro, unless it is a constant |
1890 * and constantypedefs is FALSE. | 1992 * and constantypedefs is FALSE. |
1891 */ | 1993 */ |
1892 definedef = dignorerest; | 1994 definedef = dignorerest; |
1893 *is_func = (c == '('); | 1995 *is_func_or_var = (c == '('); |
1894 if (!*is_func && !constantypedefs) | 1996 if (!*is_func_or_var && !constantypedefs) |
1895 return FALSE; | 1997 return FALSE; |
1896 else | 1998 else |
1897 return TRUE; | 1999 return TRUE; |
1898 case dignorerest: | 2000 case dignorerest: |
1899 return FALSE; | 2001 return FALSE; |
1909 case tnone: | 2011 case tnone: |
1910 if (toktype == st_C_typedef) | 2012 if (toktype == st_C_typedef) |
1911 { | 2013 { |
1912 if (typedefs) | 2014 if (typedefs) |
1913 typdef = ttypedseen; | 2015 typdef = ttypedseen; |
1914 funcdef = fnone; | 2016 fvdef = fvnone; |
1915 return FALSE; | 2017 return FALSE; |
1916 } | 2018 } |
1917 break; | 2019 break; |
1918 case ttypedseen: | 2020 case ttypedseen: |
1919 switch (toktype) | 2021 switch (toktype) |
1967 return FALSE; | 2069 return FALSE; |
1968 } | 2070 } |
1969 | 2071 |
1970 if (structdef == skeyseen) | 2072 if (structdef == skeyseen) |
1971 { | 2073 { |
1972 /* Save the tag for struct/union/class, for functions that may be | 2074 /* Save the tag for struct/union/class, for functions and variables |
1973 defined inside. */ | 2075 that may be defined inside. */ |
1974 if (structtype == st_C_struct) | 2076 if (structtype == st_C_struct) |
1975 structtag = savenstr (str, len); | 2077 structtag = savenstr (str, len); |
1976 else | 2078 else |
1977 structtag = "<enum>"; | 2079 structtag = "<enum>"; |
1978 structdef = stagseen; | 2080 structdef = stagseen; |
1979 return TRUE; | 2081 return TRUE; |
1980 } | 2082 } |
1981 | 2083 |
1982 /* Avoid entering funcdef stuff if typdef is going on. */ | 2084 /* Avoid entering fvdef stuff if typdef is going on. */ |
1983 if (typdef != tnone) | 2085 if (typdef != tnone) |
1984 { | 2086 { |
1985 definedef = dnone; | 2087 definedef = dnone; |
1986 return FALSE; | 2088 return FALSE; |
1987 } | 2089 } |
2006 return FALSE; | 2108 return FALSE; |
2007 } | 2109 } |
2008 if (next_token_is_func) | 2110 if (next_token_is_func) |
2009 { | 2111 { |
2010 next_token_is_func = FALSE; | 2112 next_token_is_func = FALSE; |
2011 funcdef = fignore; | 2113 fvdef = fignore; |
2012 *is_func = TRUE; | 2114 *is_func_or_var = TRUE; |
2013 return TRUE; | 2115 return TRUE; |
2014 } | 2116 } |
2015 | 2117 |
2016 /* Detect Objective C constructs. */ | 2118 /* Detect Objective C constructs. */ |
2017 switch (objdef) | 2119 switch (objdef) |
2026 objdef = oimplementation; | 2128 objdef = oimplementation; |
2027 return FALSE; | 2129 return FALSE; |
2028 } | 2130 } |
2029 break; | 2131 break; |
2030 case oimplementation: | 2132 case oimplementation: |
2031 /* Save the class tag for functions that may be defined inside. */ | 2133 /* Save the class tag for functions or variables defined inside. */ |
2032 objtag = savenstr (str, len); | 2134 objtag = savenstr (str, len); |
2033 objdef = oinbody; | 2135 objdef = oinbody; |
2034 return FALSE; | 2136 return FALSE; |
2035 case oprotocol: | 2137 case oprotocol: |
2036 /* Save the class tag for categories. */ | 2138 /* Save the class tag for categories. */ |
2037 objtag = savenstr (str, len); | 2139 objtag = savenstr (str, len); |
2038 objdef = otagseen; | 2140 objdef = otagseen; |
2039 *is_func = TRUE; | 2141 *is_func_or_var = TRUE; |
2040 return TRUE; | 2142 return TRUE; |
2041 case oparenseen: | 2143 case oparenseen: |
2042 objdef = ocatseen; | 2144 objdef = ocatseen; |
2043 *is_func = TRUE; | 2145 *is_func_or_var = TRUE; |
2044 return TRUE; | 2146 return TRUE; |
2045 case oinbody: | 2147 case oinbody: |
2046 break; | 2148 break; |
2047 case omethodsign: | 2149 case omethodsign: |
2048 if (parlev == 0) | 2150 if (parlev == 0) |
2049 { | 2151 { |
2050 objdef = omethodtag; | 2152 objdef = omethodtag; |
2051 methodlen = len; | 2153 methodlen = len; |
2052 grow_linebuffer (&token_name, methodlen+1); | 2154 grow_linebuffer (&token_name, methodlen + 1); |
2053 strncpy (token_name.buffer, str, len); | 2155 strncpy (token_name.buffer, str, len); |
2054 token_name.buffer[methodlen] = '\0'; | 2156 token_name.buffer[methodlen] = '\0'; |
2157 token_name.len = methodlen; | |
2055 return TRUE; | 2158 return TRUE; |
2056 } | 2159 } |
2057 return FALSE; | 2160 return FALSE; |
2058 case omethodcolon: | 2161 case omethodcolon: |
2059 if (parlev == 0) | 2162 if (parlev == 0) |
2062 case omethodparm: | 2165 case omethodparm: |
2063 if (parlev == 0) | 2166 if (parlev == 0) |
2064 { | 2167 { |
2065 objdef = omethodtag; | 2168 objdef = omethodtag; |
2066 methodlen += len; | 2169 methodlen += len; |
2067 grow_linebuffer (&token_name, methodlen+1); | 2170 grow_linebuffer (&token_name, methodlen + 1); |
2068 strncat (token_name.buffer, str, len); | 2171 strncat (token_name.buffer, str, len); |
2172 token_name.len = methodlen; | |
2069 return TRUE; | 2173 return TRUE; |
2070 } | 2174 } |
2071 return FALSE; | 2175 return FALSE; |
2072 case oignore: | 2176 case oignore: |
2073 if (toktype == st_C_objend) | 2177 if (toktype == st_C_objend) |
2081 objdef = onone; | 2185 objdef = onone; |
2082 } | 2186 } |
2083 return FALSE; | 2187 return FALSE; |
2084 } | 2188 } |
2085 | 2189 |
2086 /* A function or enum constant? */ | 2190 /* A function, variable or enum constant? */ |
2087 switch (toktype) | 2191 switch (toktype) |
2088 { | 2192 { |
2089 case st_C_typespec: | 2193 case st_C_typespec: |
2090 if (funcdef != finlist && funcdef != fignore) | 2194 if (fvdef != finlist && fvdef != fignore && fvdef != vignore) |
2091 funcdef = fnone; /* should be useless */ | 2195 fvdef = fvnone; /* should be useless */ |
2196 return FALSE; | |
2197 case st_C_ignore: | |
2198 fvdef = vignore; | |
2092 return FALSE; | 2199 return FALSE; |
2093 case st_none: | 2200 case st_none: |
2094 if (constantypedefs && structdef == sinbody && structtype == st_C_enum) | 2201 if (constantypedefs && structdef == sinbody && structtype == st_C_enum) |
2095 return TRUE; | 2202 return TRUE; |
2096 if (funcdef == fnone) | 2203 if (fvdef == fvnone) |
2097 { | 2204 { |
2098 funcdef = ftagseen; | 2205 fvdef = fvnameseen; /* function or variable */ |
2099 *is_func = TRUE; | 2206 *is_func_or_var = TRUE; |
2100 return TRUE; | 2207 return TRUE; |
2101 } | 2208 } |
2102 } | 2209 } |
2103 | 2210 |
2104 return FALSE; | 2211 return FALSE; |
2105 } | 2212 } |
2106 | 2213 |
2107 /* | 2214 /* |
2108 * C_entries () | 2215 * C_entries () |
2109 * This routine finds functions, typedefs, #define's, enum | 2216 * This routine finds functions, variables, typedefs, |
2110 * constants and struct/union/enum definitions in C syntax | 2217 * #define's, enum constants and struct/union/enum definitions in |
2111 * and adds them to the list. | 2218 * #C syntax and adds them to the list. |
2112 */ | 2219 */ |
2113 typedef struct | |
2114 { | |
2115 logical valid; | |
2116 char *str; | |
2117 logical named; | |
2118 int linelen; | |
2119 int lineno; | |
2120 long linepos; | |
2121 char *buffer; | |
2122 } TOKEN; | |
2123 | |
2124 #define current_lb_is_new (newndx == curndx) | 2220 #define current_lb_is_new (newndx == curndx) |
2125 #define switch_line_buffers() (curndx = 1 - curndx) | 2221 #define switch_line_buffers() (curndx = 1 - curndx) |
2126 | 2222 |
2127 #define curlb (lbs[curndx].lb) | 2223 #define curlb (lbs[curndx].lb) |
2128 #define othlb (lbs[1-curndx].lb) | 2224 #define othlb (lbs[1-curndx].lb) |
2153 definedef = dnone; \ | 2249 definedef = dnone; \ |
2154 } while (0) | 2250 } while (0) |
2155 | 2251 |
2156 | 2252 |
2157 void | 2253 void |
2158 make_C_tag (isfun, tokp) | 2254 make_C_tag (isfun) |
2159 logical isfun; | 2255 bool isfun; |
2160 TOKEN *tokp; | 2256 { |
2161 { | |
2162 char *name = NULL; | |
2163 | |
2164 /* This function should never be called when tok.valid is FALSE, but | 2257 /* This function should never be called when tok.valid is FALSE, but |
2165 we must protect against invalid input or internal errors. */ | 2258 we must protect against invalid input or internal errors. */ |
2166 if (tokp->valid) | 2259 if (tok.valid) |
2167 { | 2260 { |
2168 if (CTAGS || tokp->named) | 2261 if (traditional_tag_style) |
2169 name = savestr (token_name.buffer); | 2262 { |
2170 pfnote (name, isfun, | 2263 /* This was the original code. Now we call new_pfnote instead, |
2171 tokp->buffer, tokp->linelen, tokp->lineno, tokp->linepos); | 2264 which uses the new method for naming tags (see new_pfnote). */ |
2172 tokp->valid = FALSE; | 2265 char *name = NULL; |
2266 | |
2267 if (CTAGS || tok.named) | |
2268 name = savestr (token_name.buffer); | |
2269 pfnote (name, isfun, | |
2270 tok.buffer, tok.linelen, tok.lineno, tok.linepos); | |
2271 } | |
2272 else | |
2273 new_pfnote (token_name.buffer, token_name.len, isfun, | |
2274 tok.buffer, tok.linelen, tok.lineno, tok.linepos); | |
2275 tok.valid = FALSE; | |
2173 } | 2276 } |
2174 else if (DEBUG) | 2277 else if (DEBUG) |
2175 abort (); | 2278 abort (); |
2176 } | 2279 } |
2177 | 2280 |
2182 FILE *inf; /* input file */ | 2285 FILE *inf; /* input file */ |
2183 { | 2286 { |
2184 register char c; /* latest char read; '\0' for end of line */ | 2287 register char c; /* latest char read; '\0' for end of line */ |
2185 register char *lp; /* pointer one beyond the character `c' */ | 2288 register char *lp; /* pointer one beyond the character `c' */ |
2186 int curndx, newndx; /* indices for current and new lb */ | 2289 int curndx, newndx; /* indices for current and new lb */ |
2187 TOKEN tok; /* latest token read */ | |
2188 register int tokoff; /* offset in line of start of current token */ | 2290 register int tokoff; /* offset in line of start of current token */ |
2189 register int toklen; /* length of current token */ | 2291 register int toklen; /* length of current token */ |
2292 char *qualifier; /* string used to qualify names */ | |
2293 int qlen; /* length of qualifier */ | |
2190 int cblev; /* current curly brace level */ | 2294 int cblev; /* current curly brace level */ |
2191 int parlev; /* current parenthesis level */ | 2295 int parlev; /* current parenthesis level */ |
2192 logical incomm, inquote, inchar, quotednl, midtoken; | 2296 bool incomm, inquote, inchar, quotednl, midtoken; |
2193 logical cplpl, cjava; | 2297 bool cplpl, cjava; |
2194 TOKEN savetok; /* token saved during preprocessor handling */ | 2298 TOKEN savetok; /* token saved during preprocessor handling */ |
2195 | 2299 |
2196 | 2300 |
2197 curndx = newndx = 0; | 2301 curndx = newndx = 0; |
2198 lineno = 0; | 2302 lineno = 0; |
2199 charno = 0; | 2303 charno = 0; |
2200 lp = curlb.buffer; | 2304 lp = curlb.buffer; |
2201 *lp = 0; | 2305 *lp = 0; |
2202 | 2306 |
2203 funcdef = fnone; typdef = tnone; structdef = snone; | 2307 fvdef = fvnone; typdef = tnone; structdef = snone; |
2204 definedef = dnone; objdef = onone; | 2308 definedef = dnone; objdef = onone; |
2205 next_token_is_func = yacc_rules = FALSE; | 2309 next_token_is_func = yacc_rules = FALSE; |
2206 midtoken = inquote = inchar = incomm = quotednl = FALSE; | 2310 midtoken = inquote = inchar = incomm = quotednl = FALSE; |
2207 tok.valid = savetok.valid = FALSE; | 2311 tok.valid = savetok.valid = FALSE; |
2208 cblev = 0; | 2312 cblev = 0; |
2209 parlev = 0; | 2313 parlev = 0; |
2210 cplpl = c_ext & C_PLPL; | 2314 cplpl = (c_ext & C_PLPL) == C_PLPL; |
2211 cjava = c_ext & C_JAVA; | 2315 cjava = (c_ext & C_JAVA) == C_JAVA; |
2316 if (cjava) | |
2317 { qualifier = "."; qlen = 1; } | |
2318 else | |
2319 { qualifier = "::"; qlen = 2; } | |
2212 | 2320 |
2213 while (!feof (inf)) | 2321 while (!feof (inf)) |
2214 { | 2322 { |
2215 c = *lp++; | 2323 c = *lp++; |
2216 if (c == '\\') | 2324 if (c == '\\') |
2278 else | 2386 else |
2279 switch (c) | 2387 switch (c) |
2280 { | 2388 { |
2281 case '"': | 2389 case '"': |
2282 inquote = TRUE; | 2390 inquote = TRUE; |
2283 if (funcdef != finlist && funcdef != fignore) | 2391 if (fvdef != finlist && fvdef != fignore && fvdef !=vignore) |
2284 funcdef = fnone; | 2392 fvdef = fvnone; |
2285 continue; | 2393 continue; |
2286 case '\'': | 2394 case '\'': |
2287 inchar = TRUE; | 2395 inchar = TRUE; |
2288 if (funcdef != finlist && funcdef != fignore) | 2396 if (fvdef != finlist && fvdef != fignore && fvdef !=vignore) |
2289 funcdef = fnone; | 2397 fvdef = fvnone; |
2290 continue; | 2398 continue; |
2291 case '/': | 2399 case '/': |
2292 if (*lp == '*') | 2400 if (*lp == '*') |
2293 { | 2401 { |
2294 lp++; | 2402 lp++; |
2305 case '%': | 2413 case '%': |
2306 if ((c_ext & YACC) && *lp == '%') | 2414 if ((c_ext & YACC) && *lp == '%') |
2307 { | 2415 { |
2308 /* entering or exiting rules section in yacc file */ | 2416 /* entering or exiting rules section in yacc file */ |
2309 lp++; | 2417 lp++; |
2310 definedef = dnone; funcdef = fnone; | 2418 definedef = dnone; fvdef = fvnone; |
2311 typdef = tnone; structdef = snone; | 2419 typdef = tnone; structdef = snone; |
2312 next_token_is_func = FALSE; | 2420 next_token_is_func = FALSE; |
2313 midtoken = inquote = inchar = incomm = quotednl = FALSE; | 2421 midtoken = inquote = inchar = incomm = quotednl = FALSE; |
2314 cblev = 0; | 2422 cblev = 0; |
2315 yacc_rules = !yacc_rules; | 2423 yacc_rules = !yacc_rules; |
2319 break; | 2427 break; |
2320 case '#': | 2428 case '#': |
2321 if (definedef == dnone) | 2429 if (definedef == dnone) |
2322 { | 2430 { |
2323 char *cp; | 2431 char *cp; |
2324 logical cpptoken = TRUE; | 2432 bool cpptoken = TRUE; |
2325 | 2433 |
2326 /* Look back on this line. If all blanks, or nonblanks | 2434 /* Look back on this line. If all blanks, or nonblanks |
2327 followed by an end of comment, this is a preprocessor | 2435 followed by an end of comment, this is a preprocessor |
2328 token. */ | 2436 token. */ |
2329 for (cp = newlb.buffer; cp < lp-1; cp++) | 2437 for (cp = newlb.buffer; cp < lp-1; cp++) |
2350 || (cblev == 0 && structdef != scolonseen) | 2458 || (cblev == 0 && structdef != scolonseen) |
2351 || (cblev == 1 && cplpl && structdef == sinbody) | 2459 || (cblev == 1 && cplpl && structdef == sinbody) |
2352 || (structdef == sinbody && structtype == st_C_enum)) | 2460 || (structdef == sinbody && structtype == st_C_enum)) |
2353 && typdef != tignore | 2461 && typdef != tignore |
2354 && definedef != dignorerest | 2462 && definedef != dignorerest |
2355 && funcdef != finlist) | 2463 && fvdef != finlist) |
2356 { | 2464 { |
2357 if (midtoken) | 2465 if (midtoken) |
2358 { | 2466 { |
2359 if (endtoken (c)) | 2467 if (endtoken (c)) |
2360 { | 2468 { |
2367 lp += 2; | 2475 lp += 2; |
2368 toklen += 3; | 2476 toklen += 3; |
2369 } | 2477 } |
2370 else | 2478 else |
2371 { | 2479 { |
2372 logical is_func = FALSE; | 2480 bool funorvar = FALSE; |
2373 | 2481 |
2374 if (yacc_rules | 2482 if (yacc_rules |
2375 || consider_token (newlb.buffer + tokoff, toklen, c, | 2483 || consider_token (newlb.buffer + tokoff, toklen, c, |
2376 c_ext, cblev, parlev, &is_func)) | 2484 c_ext, cblev, parlev, &funorvar)) |
2377 { | 2485 { |
2486 tok.named = FALSE; | |
2378 if (structdef == sinbody | 2487 if (structdef == sinbody |
2379 && definedef == dnone | 2488 && definedef == dnone |
2380 && is_func) | 2489 && funorvar) |
2381 /* function defined in C++ class body */ | 2490 /* function or var defined in C++ class body */ |
2382 { | 2491 { |
2383 grow_linebuffer (&token_name, | 2492 int len = strlen (structtag) + qlen + toklen; |
2384 strlen(structtag)+2+toklen+1); | 2493 grow_linebuffer (&token_name, len + 1); |
2385 strcpy (token_name.buffer, structtag); | 2494 strcpy (token_name.buffer, structtag); |
2386 strcat (token_name.buffer, "::"); | 2495 strcat (token_name.buffer, qualifier); |
2387 strncat (token_name.buffer, | 2496 strncat (token_name.buffer, |
2388 newlb.buffer+tokoff, toklen); | 2497 newlb.buffer + tokoff, toklen); |
2498 token_name.len = len; | |
2389 tok.named = TRUE; | 2499 tok.named = TRUE; |
2390 } | 2500 } |
2391 else if (objdef == ocatseen) | 2501 else if (objdef == ocatseen) |
2392 /* Objective C category */ | 2502 /* Objective C category */ |
2393 { | 2503 { |
2394 grow_linebuffer (&token_name, | 2504 int len = strlen (objtag) + 2 + toklen; |
2395 strlen(objtag)+2+toklen+1); | 2505 grow_linebuffer (&token_name, len + 1); |
2396 strcpy (token_name.buffer, objtag); | 2506 strcpy (token_name.buffer, objtag); |
2397 strcat (token_name.buffer, "("); | 2507 strcat (token_name.buffer, "("); |
2398 strncat (token_name.buffer, | 2508 strncat (token_name.buffer, |
2399 newlb.buffer+tokoff, toklen); | 2509 newlb.buffer + tokoff, toklen); |
2400 strcat (token_name.buffer, ")"); | 2510 strcat (token_name.buffer, ")"); |
2511 token_name.len = len; | |
2401 tok.named = TRUE; | 2512 tok.named = TRUE; |
2402 } | 2513 } |
2403 else if (objdef == omethodtag | 2514 else if (objdef == omethodtag |
2404 || objdef == omethodparm) | 2515 || objdef == omethodparm) |
2405 /* Objective C method */ | 2516 /* Objective C method */ |
2406 { | 2517 { |
2407 tok.named = TRUE; | 2518 tok.named = TRUE; |
2408 } | 2519 } |
2409 else | 2520 else |
2410 { | 2521 { |
2411 grow_linebuffer (&token_name, toklen+1); | 2522 grow_linebuffer (&token_name, toklen + 1); |
2412 strncpy (token_name.buffer, | 2523 strncpy (token_name.buffer, |
2413 newlb.buffer+tokoff, toklen); | 2524 newlb.buffer + tokoff, toklen); |
2414 token_name.buffer[toklen] = '\0'; | 2525 token_name.buffer[toklen] = '\0'; |
2415 if (structdef == stagseen | 2526 token_name.len = toklen; |
2416 || typdef == tend | 2527 /* Name macros. */ |
2417 || (is_func | 2528 tok.named = (structdef == stagseen |
2418 && definedef == dignorerest)) /* macro */ | 2529 || typdef == tend |
2419 tok.named = TRUE; | 2530 || (funorvar |
2420 else | 2531 && definedef == dignorerest)); |
2421 tok.named = FALSE; | |
2422 } | 2532 } |
2423 tok.lineno = lineno; | 2533 tok.lineno = lineno; |
2424 tok.linelen = tokoff + toklen + 1; | 2534 tok.linelen = tokoff + toklen + 1; |
2425 tok.buffer = newlb.buffer; | 2535 tok.buffer = newlb.buffer; |
2426 tok.linepos = newlinepos; | 2536 tok.linepos = newlinepos; |
2427 tok.valid = TRUE; | 2537 tok.valid = TRUE; |
2428 | 2538 |
2429 if (definedef == dnone | 2539 if (definedef == dnone |
2430 && (funcdef == ftagseen | 2540 && (fvdef == fvnameseen |
2431 || structdef == stagseen | 2541 || structdef == stagseen |
2432 || typdef == tend | 2542 || typdef == tend |
2433 || objdef != onone)) | 2543 || objdef != onone)) |
2434 { | 2544 { |
2435 if (current_lb_is_new) | 2545 if (current_lb_is_new) |
2436 switch_line_buffers (); | 2546 switch_line_buffers (); |
2437 } | 2547 } |
2438 else | 2548 else |
2439 make_C_tag (is_func, &tok); | 2549 make_C_tag (funorvar); |
2440 } | 2550 } |
2441 midtoken = FALSE; | 2551 midtoken = FALSE; |
2442 } | 2552 } |
2443 } /* if (endtoken (c)) */ | 2553 } /* if (endtoken (c)) */ |
2444 else if (intoken (c)) | 2554 else if (intoken (c)) |
2450 else if (begtoken (c)) | 2560 else if (begtoken (c)) |
2451 { | 2561 { |
2452 switch (definedef) | 2562 switch (definedef) |
2453 { | 2563 { |
2454 case dnone: | 2564 case dnone: |
2455 switch (funcdef) | 2565 switch (fvdef) |
2456 { | 2566 { |
2457 case fstartlist: | 2567 case fstartlist: |
2458 funcdef = finlist; | 2568 fvdef = finlist; |
2459 continue; | 2569 continue; |
2460 case flistseen: | 2570 case flistseen: |
2461 make_C_tag (TRUE, &tok); | 2571 make_C_tag (TRUE); /* a function */ |
2462 funcdef = fignore; | 2572 fvdef = fignore; |
2463 break; | 2573 break; |
2464 case ftagseen: | 2574 case fvnameseen: |
2465 funcdef = fnone; | 2575 fvdef = fvnone; |
2466 break; | 2576 break; |
2467 } | 2577 } |
2468 if (structdef == stagseen && !cjava) | 2578 if (structdef == stagseen && !cjava) |
2469 structdef = snone; | 2579 structdef = snone; |
2470 break; | 2580 break; |
2491 break; | 2601 break; |
2492 switch (objdef) | 2602 switch (objdef) |
2493 { | 2603 { |
2494 case otagseen: | 2604 case otagseen: |
2495 objdef = oignore; | 2605 objdef = oignore; |
2496 make_C_tag (TRUE, &tok); | 2606 make_C_tag (TRUE); /* an Objective C class */ |
2497 break; | 2607 break; |
2498 case omethodtag: | 2608 case omethodtag: |
2499 case omethodparm: | 2609 case omethodparm: |
2500 objdef = omethodcolon; | 2610 objdef = omethodcolon; |
2501 methodlen += 1; | 2611 methodlen += 1; |
2502 grow_linebuffer (&token_name, methodlen+1); | 2612 grow_linebuffer (&token_name, methodlen + 1); |
2503 strcat (token_name.buffer, ":"); | 2613 strcat (token_name.buffer, ":"); |
2614 token_name.len = methodlen; | |
2504 break; | 2615 break; |
2505 } | 2616 } |
2506 if (structdef == stagseen) | 2617 if (structdef == stagseen) |
2507 structdef = scolonseen; | 2618 structdef = scolonseen; |
2508 else | 2619 else |
2509 switch (funcdef) | 2620 switch (fvdef) |
2510 { | 2621 { |
2511 case ftagseen: | 2622 case fvnameseen: |
2512 if (yacc_rules) | 2623 if (yacc_rules) |
2513 { | 2624 { |
2514 make_C_tag (FALSE, &tok); | 2625 make_C_tag (FALSE); /* a yacc function */ |
2515 funcdef = fignore; | 2626 fvdef = fignore; |
2516 } | 2627 } |
2517 break; | 2628 break; |
2518 case fstartlist: | 2629 case fstartlist: |
2519 funcdef = fnone; | 2630 fvdef = fvnone; |
2520 break; | 2631 break; |
2521 } | 2632 } |
2522 break; | 2633 break; |
2523 case ';': | 2634 case ';': |
2524 if (definedef != dnone) | 2635 if (definedef != dnone) |
2525 break; | 2636 break; |
2526 if (cblev == 0) | 2637 if (cblev == 0) |
2527 switch (typdef) | 2638 switch (typdef) |
2528 { | 2639 { |
2529 case tend: | 2640 case tend: |
2530 make_C_tag (FALSE, &tok); | 2641 make_C_tag (FALSE); /* a typedef */ |
2531 /* FALLTHRU */ | 2642 /* FALLTHRU */ |
2532 default: | 2643 default: |
2533 typdef = tnone; | 2644 typdef = tnone; |
2534 } | 2645 } |
2535 if (funcdef != fignore) | 2646 switch (fvdef) |
2536 { | 2647 { |
2537 funcdef = fnone; | 2648 case fignore: |
2649 break; | |
2650 case fvnameseen: | |
2651 if ((globals && cblev == 0) || (members && cblev == 1)) | |
2652 make_C_tag (FALSE); /* a variable */ | |
2653 /* FALLTHRU */ | |
2654 default: | |
2655 fvdef = fvnone; | |
2538 /* The following instruction invalidates the token. | 2656 /* The following instruction invalidates the token. |
2539 Probably the token should be invalidated in all | 2657 Probably the token should be invalidated in all |
2540 other cases where some state machine is reset. */ | 2658 other cases where some state machine is reset. */ |
2541 tok.valid = FALSE; | 2659 tok.valid = FALSE; |
2542 } | 2660 } |
2548 break; | 2666 break; |
2549 switch (objdef) | 2667 switch (objdef) |
2550 { | 2668 { |
2551 case omethodtag: | 2669 case omethodtag: |
2552 case omethodparm: | 2670 case omethodparm: |
2553 make_C_tag (TRUE, &tok); | 2671 make_C_tag (TRUE); /* an Objective C method */ |
2554 objdef = oinbody; | 2672 objdef = oinbody; |
2555 break; | 2673 break; |
2556 } | 2674 } |
2557 if (funcdef != finlist && funcdef != fignore) | 2675 switch (fvdef) |
2558 funcdef = fnone; | 2676 { |
2677 case finlist: | |
2678 case fignore: | |
2679 case vignore: | |
2680 break; | |
2681 case fvnameseen: | |
2682 if ((globals && cblev == 0) || (members && cblev == 1)) | |
2683 make_C_tag (FALSE); /* a variable */ | |
2684 break; | |
2685 default: | |
2686 fvdef = fvnone; | |
2687 } | |
2559 if (structdef == stagseen) | 2688 if (structdef == stagseen) |
2560 structdef = snone; | 2689 structdef = snone; |
2561 break; | 2690 break; |
2562 case '[': | 2691 case '[': |
2563 if (definedef != dnone) | 2692 if (definedef != dnone) |
2564 break; | 2693 break; |
2565 if (cblev == 0 && typdef == tend) | 2694 if (cblev == 0 && typdef == tend) |
2566 { | 2695 { |
2567 typdef = tignore; | 2696 typdef = tignore; |
2568 make_C_tag (FALSE, &tok); | 2697 make_C_tag (FALSE); /* a typedef */ |
2569 break; | 2698 break; |
2570 } | 2699 } |
2571 if (funcdef != finlist && funcdef != fignore) | 2700 switch (fvdef) |
2572 funcdef = fnone; | 2701 { |
2702 case finlist: | |
2703 case fignore: | |
2704 case vignore: | |
2705 break; | |
2706 case fvnameseen: | |
2707 if ((globals && cblev == 0) || (members && cblev == 1)) | |
2708 make_C_tag (FALSE); /* a variable */ | |
2709 /* FALLTHRU */ | |
2710 default: | |
2711 fvdef = fvnone; | |
2712 } | |
2573 if (structdef == stagseen) | 2713 if (structdef == stagseen) |
2574 structdef = snone; | 2714 structdef = snone; |
2575 break; | 2715 break; |
2576 case '(': | 2716 case '(': |
2577 if (definedef != dnone) | 2717 if (definedef != dnone) |
2578 break; | 2718 break; |
2579 if (objdef == otagseen && parlev == 0) | 2719 if (objdef == otagseen && parlev == 0) |
2580 objdef = oparenseen; | 2720 objdef = oparenseen; |
2581 switch (funcdef) | 2721 switch (fvdef) |
2582 { | 2722 { |
2583 case fnone: | 2723 case fvnone: |
2584 switch (typdef) | 2724 switch (typdef) |
2585 { | 2725 { |
2586 case ttypedseen: | 2726 case ttypedseen: |
2587 case tend: | 2727 case tend: |
2588 /* Make sure that the next char is not a '*'. | |
2589 This handles constructs like: | |
2590 typedef void OperatorFun (int fun); */ | |
2591 if (tok.valid && *lp != '*') | 2728 if (tok.valid && *lp != '*') |
2592 { | 2729 { |
2730 /* This handles constructs like: | |
2731 typedef void OperatorFun (int fun); */ | |
2732 make_C_tag (FALSE); | |
2593 typdef = tignore; | 2733 typdef = tignore; |
2594 make_C_tag (FALSE, &tok); | |
2595 } | 2734 } |
2596 break; | 2735 break; |
2597 } /* switch (typdef) */ | 2736 } /* switch (typdef) */ |
2598 break; | 2737 break; |
2599 case ftagseen: | 2738 case fvnameseen: |
2600 funcdef = fstartlist; | 2739 fvdef = fstartlist; |
2601 break; | 2740 break; |
2602 case flistseen: | 2741 case flistseen: |
2603 funcdef = finlist; | 2742 fvdef = finlist; |
2604 break; | 2743 break; |
2605 } | 2744 } |
2606 parlev++; | 2745 parlev++; |
2607 break; | 2746 break; |
2608 case ')': | 2747 case ')': |
2609 if (definedef != dnone) | 2748 if (definedef != dnone) |
2610 break; | 2749 break; |
2611 if (objdef == ocatseen && parlev == 1) | 2750 if (objdef == ocatseen && parlev == 1) |
2612 { | 2751 { |
2613 make_C_tag (TRUE, &tok); | 2752 make_C_tag (TRUE); /* an Objective C category */ |
2614 objdef = oignore; | 2753 objdef = oignore; |
2615 } | 2754 } |
2616 if (--parlev == 0) | 2755 if (--parlev == 0) |
2617 { | 2756 { |
2618 switch (funcdef) | 2757 switch (fvdef) |
2619 { | 2758 { |
2620 case fstartlist: | 2759 case fstartlist: |
2621 case finlist: | 2760 case finlist: |
2622 funcdef = flistseen; | 2761 fvdef = flistseen; |
2623 break; | 2762 break; |
2624 } | 2763 } |
2625 if (cblev == 0 && typdef == tend) | 2764 if (cblev == 0 && typdef == tend) |
2626 { | 2765 { |
2627 typdef = tignore; | 2766 typdef = tignore; |
2628 make_C_tag (FALSE, &tok); | 2767 make_C_tag (FALSE); /* a typedef */ |
2629 } | 2768 } |
2630 } | 2769 } |
2631 else if (parlev < 0) /* can happen due to ill-conceived #if's. */ | 2770 else if (parlev < 0) /* can happen due to ill-conceived #if's. */ |
2632 parlev = 0; | 2771 parlev = 0; |
2633 break; | 2772 break; |
2643 structtag = "_anonymous_"; | 2782 structtag = "_anonymous_"; |
2644 break; | 2783 break; |
2645 case stagseen: | 2784 case stagseen: |
2646 case scolonseen: /* named struct */ | 2785 case scolonseen: /* named struct */ |
2647 structdef = sinbody; | 2786 structdef = sinbody; |
2648 make_C_tag (FALSE, &tok); | 2787 make_C_tag (FALSE); /* a struct */ |
2649 break; | 2788 break; |
2650 } | 2789 } |
2651 switch (funcdef) | 2790 switch (fvdef) |
2652 { | 2791 { |
2653 case flistseen: | 2792 case flistseen: |
2654 make_C_tag (TRUE, &tok); | 2793 make_C_tag (TRUE); /* a function */ |
2655 /* FALLTHRU */ | 2794 /* FALLTHRU */ |
2656 case fignore: | 2795 case fignore: |
2657 funcdef = fnone; | 2796 fvdef = fvnone; |
2658 break; | 2797 break; |
2659 case fnone: | 2798 case fvnone: |
2660 switch (objdef) | 2799 switch (objdef) |
2661 { | 2800 { |
2662 case otagseen: | 2801 case otagseen: |
2663 make_C_tag (TRUE, &tok); | 2802 make_C_tag (TRUE); /* an Objective C class */ |
2664 objdef = oignore; | 2803 objdef = oignore; |
2665 break; | 2804 break; |
2666 case omethodtag: | 2805 case omethodtag: |
2667 case omethodparm: | 2806 case omethodparm: |
2668 make_C_tag (TRUE, &tok); | 2807 make_C_tag (TRUE); /* an Objective C method */ |
2669 objdef = oinbody; | 2808 objdef = oinbody; |
2670 break; | 2809 break; |
2671 default: | 2810 default: |
2672 /* Neutralize `extern "C" {' grot. */ | 2811 /* Neutralize `extern "C" {' grot. */ |
2673 if (cblev == 0 && structdef == snone && typdef == tnone) | 2812 if (cblev == 0 && structdef == snone && typdef == tnone) |
2677 cblev++; | 2816 cblev++; |
2678 break; | 2817 break; |
2679 case '*': | 2818 case '*': |
2680 if (definedef != dnone) | 2819 if (definedef != dnone) |
2681 break; | 2820 break; |
2682 if (funcdef == fstartlist) | 2821 if (fvdef == fstartlist) |
2683 funcdef = fnone; /* avoid tagging `foo' in `foo (*bar()) ()' */ | 2822 fvdef = fvnone; /* avoid tagging `foo' in `foo (*bar()) ()' */ |
2684 break; | 2823 break; |
2685 case '}': | 2824 case '}': |
2686 if (definedef != dnone) | 2825 if (definedef != dnone) |
2687 break; | 2826 break; |
2688 if (!noindentypedefs && lp == newlb.buffer + 1) | 2827 if (!noindentypedefs && lp == newlb.buffer + 1) |
2706 | 2845 |
2707 structdef = snone; | 2846 structdef = snone; |
2708 structtag = "<error>"; | 2847 structtag = "<error>"; |
2709 } | 2848 } |
2710 break; | 2849 break; |
2850 case '=': | |
2851 if (definedef != dnone) | |
2852 break; | |
2853 switch (fvdef) | |
2854 { | |
2855 case finlist: | |
2856 case fignore: | |
2857 case vignore: | |
2858 break; | |
2859 case fvnameseen: | |
2860 if ((globals && cblev == 0) || (members && cblev == 1)) | |
2861 make_C_tag (FALSE); /* a variable */ | |
2862 /* FALLTHRU */ | |
2863 default: | |
2864 fvdef = vignore; | |
2865 } | |
2866 break; | |
2711 case '+': | 2867 case '+': |
2712 case '-': | 2868 case '-': |
2713 if (objdef == oinbody && cblev == 0) | 2869 if (objdef == oinbody && cblev == 0) |
2714 { | 2870 { |
2715 objdef = omethodsign; | 2871 objdef = omethodsign; |
2716 break; | 2872 break; |
2717 } | 2873 } |
2718 /* FALLTHRU */ | 2874 /* FALLTHRU */ |
2719 case '=': case '#': case '~': case '&': case '%': case '/': | 2875 case '#': case '~': case '&': case '%': case '/': case '|': |
2720 case '|': case '^': case '!': case '<': case '>': case '.': case '?': | 2876 case '^': case '!': case '<': case '>': case '.': case '?': case ']': |
2721 if (definedef != dnone) | 2877 if (definedef != dnone) |
2722 break; | 2878 break; |
2723 /* These surely cannot follow a function tag. */ | 2879 /* These surely cannot follow a function tag. */ |
2724 if (funcdef != finlist && funcdef != fignore) | 2880 if (fvdef != finlist && fvdef != fignore && fvdef != vignore) |
2725 funcdef = fnone; | 2881 fvdef = fvnone; |
2726 break; | 2882 break; |
2727 case '\0': | 2883 case '\0': |
2728 if (objdef == otagseen) | 2884 if (objdef == otagseen) |
2729 { | 2885 { |
2730 make_C_tag (TRUE, &tok); | 2886 make_C_tag (TRUE); /* an Objective C class */ |
2731 objdef = oignore; | 2887 objdef = oignore; |
2732 } | 2888 } |
2733 /* If a macro spans multiple lines don't reset its state. */ | 2889 /* If a macro spans multiple lines don't reset its state. */ |
2734 if (quotednl) | 2890 if (quotednl) |
2735 CNL_SAVE_DEFINEDEF; | 2891 CNL_SAVE_DEFINEDEF; |
2768 C_entries (C_PLPL, inf); | 2924 C_entries (C_PLPL, inf); |
2769 } | 2925 } |
2770 | 2926 |
2771 /* Always do Java. */ | 2927 /* Always do Java. */ |
2772 void | 2928 void |
2773 Cjava_entries (FILE *inf) | 2929 Cjava_entries (inf) |
2930 FILE *inf; | |
2774 { | 2931 { |
2775 C_entries (C_JAVA, inf); | 2932 C_entries (C_JAVA, inf); |
2776 } | 2933 } |
2777 | 2934 |
2778 /* Always do C*. */ | 2935 /* Always do C*. */ |
2793 | 2950 |
2794 /* Fortran parsing */ | 2951 /* Fortran parsing */ |
2795 | 2952 |
2796 char *dbp; | 2953 char *dbp; |
2797 | 2954 |
2798 logical | 2955 bool |
2799 tail (cp) | 2956 tail (cp) |
2800 char *cp; | 2957 char *cp; |
2801 { | 2958 { |
2802 register int len = 0; | 2959 register int len = 0; |
2803 | 2960 |
3007 lineno++; | 3164 lineno++; |
3008 linecharno = charno; | 3165 linecharno = charno; |
3009 charno += readline (&lb, inf); | 3166 charno += readline (&lb, inf); |
3010 cp = lb.buffer; | 3167 cp = lb.buffer; |
3011 | 3168 |
3012 if (*cp++ == 's' && *cp++ == 'u' && *cp++ == 'b' && isspace(*cp++)) | 3169 if (*cp++ == 's' && *cp++ == 'u' && *cp++ == 'b' && isspace (*cp++)) |
3013 { | 3170 { |
3014 while (*cp && isspace(*cp)) | 3171 while (*cp && isspace (*cp)) |
3015 cp++; | 3172 cp++; |
3016 while (*cp && ! isspace(*cp) && *cp != '{') | 3173 while (*cp && ! isspace (*cp) && *cp != '{') |
3017 cp++; | 3174 cp++; |
3018 pfnote ((CTAGS) ? savenstr (lb.buffer, cp-lb.buffer) : NULL, TRUE, | 3175 pfnote ((CTAGS) ? savenstr (lb.buffer, cp-lb.buffer) : NULL, TRUE, |
3019 lb.buffer, cp - lb.buffer + 1, lineno, linecharno); | 3176 lb.buffer, cp - lb.buffer + 1, lineno, linecharno); |
3020 } | 3177 } |
3178 } | |
3179 } | |
3180 | |
3181 /* Idea by Corny de Souza | |
3182 * Cobol tag functions | |
3183 * We could look for anything that could be a paragraph name. | |
3184 * i.e. anything that starts in column 8 is one word and ends in a full stop. | |
3185 */ | |
3186 void | |
3187 Cobol_paragraphs (inf) | |
3188 FILE *inf; | |
3189 { | |
3190 register char *cp; | |
3191 | |
3192 lineno = 0; | |
3193 charno = 0; | |
3194 | |
3195 while (!feof (inf)) | |
3196 { | |
3197 lineno++; | |
3198 linecharno = charno; | |
3199 charno += readline (&lb, inf); | |
3200 | |
3201 if (lb.len < 9) | |
3202 continue; | |
3203 dbp = lb.buffer + 8; | |
3204 | |
3205 /* If eoln, compiler option or comment ignore whole line. */ | |
3206 if (dbp[-1] != ' ' || !isalnum (dbp[0])) | |
3207 continue; | |
3208 | |
3209 for (cp = dbp; isalnum (*cp) || *cp == '-'; cp++) | |
3210 continue; | |
3211 if (*cp++ == '.') | |
3212 pfnote ((CTAGS) ? savenstr (dbp, cp-dbp) : NULL, TRUE, | |
3213 lb.buffer, cp - lb.buffer + 1, lineno, linecharno); | |
3021 } | 3214 } |
3022 } | 3215 } |
3023 | 3216 |
3024 /* Added by Mosur Mohan, 4/22/88 */ | 3217 /* Added by Mosur Mohan, 4/22/88 */ |
3025 /* Pascal parsing */ | 3218 /* Pascal parsing */ |
3037 struct linebuffer tline; /* mostly copied from C_entries */ | 3230 struct linebuffer tline; /* mostly copied from C_entries */ |
3038 long save_lcno; | 3231 long save_lcno; |
3039 int save_lineno, save_len; | 3232 int save_lineno, save_len; |
3040 char c, *cp, *namebuf; | 3233 char c, *cp, *namebuf; |
3041 | 3234 |
3042 logical /* each of these flags is TRUE iff: */ | 3235 bool /* each of these flags is TRUE iff: */ |
3043 incomment, /* point is inside a comment */ | 3236 incomment, /* point is inside a comment */ |
3044 inquote, /* point is inside '..' string */ | 3237 inquote, /* point is inside '..' string */ |
3045 get_tagname, /* point is after PROCEDURE/FUNCTION | 3238 get_tagname, /* point is after PROCEDURE/FUNCTION |
3046 keyword, so next item = potential tag */ | 3239 keyword, so next item = potential tag */ |
3047 found_tag, /* point is after a potential tag */ | 3240 found_tag, /* point is after a potential tag */ |
3169 strcpy (tline.buffer, lb.buffer); | 3362 strcpy (tline.buffer, lb.buffer); |
3170 save_lineno = lineno; | 3363 save_lineno = lineno; |
3171 save_lcno = linecharno; | 3364 save_lcno = linecharno; |
3172 | 3365 |
3173 /* grab block name */ | 3366 /* grab block name */ |
3174 for (cp = dbp + 1; *cp && (!endtoken (*cp)); cp++) | 3367 for (cp = dbp + 1; *cp != '\0' && !endtoken (*cp); cp++) |
3175 continue; | 3368 continue; |
3176 namebuf = (CTAGS) ? savenstr (dbp, cp-dbp) : NULL; | 3369 namebuf = (CTAGS) ? savenstr (dbp, cp-dbp) : NULL; |
3177 dbp = cp; /* set dbp to e-o-token */ | 3370 dbp = cp; /* set dbp to e-o-token */ |
3178 save_len = dbp - lb.buffer + 1; | 3371 save_len = dbp - lb.buffer + 1; |
3179 get_tagname = FALSE; | 3372 get_tagname = FALSE; |
3222 return ((*(++strp) == 'q' || *strp == 'Q') | 3415 return ((*(++strp) == 'q' || *strp == 'Q') |
3223 && (*(++strp) == 'u' || *strp == 'U') | 3416 && (*(++strp) == 'u' || *strp == 'U') |
3224 && (*(++strp) == 'o' || *strp == 'O') | 3417 && (*(++strp) == 'o' || *strp == 'O') |
3225 && (*(++strp) == 't' || *strp == 'T') | 3418 && (*(++strp) == 't' || *strp == 'T') |
3226 && (*(++strp) == 'e' || *strp == 'E') | 3419 && (*(++strp) == 'e' || *strp == 'E') |
3227 && isspace(*(++strp))); | 3420 && isspace (*(++strp))); |
3228 } | 3421 } |
3229 | 3422 |
3230 void | 3423 void |
3231 L_getit () | 3424 L_getit () |
3232 { | 3425 { |
3235 if (*dbp == '\'') /* Skip prefix quote */ | 3428 if (*dbp == '\'') /* Skip prefix quote */ |
3236 dbp++; | 3429 dbp++; |
3237 else if (*dbp == '(' && L_isquote (dbp)) /* Skip "(quote " */ | 3430 else if (*dbp == '(' && L_isquote (dbp)) /* Skip "(quote " */ |
3238 { | 3431 { |
3239 dbp += 7; | 3432 dbp += 7; |
3240 while (isspace(*dbp)) | 3433 while (isspace (*dbp)) |
3241 dbp++; | 3434 dbp++; |
3242 } | 3435 } |
3243 for (cp = dbp /*+1*/; | 3436 for (cp = dbp /*+1*/; |
3244 *cp && *cp != '(' && *cp != ' ' && *cp != ')'; | 3437 *cp != '\0' && *cp != '(' && *cp != ' ' && *cp != ')'; |
3245 cp++) | 3438 cp++) |
3246 continue; | 3439 continue; |
3247 if (cp == dbp) | 3440 if (cp == dbp) |
3248 return; | 3441 return; |
3249 | 3442 |
3310 Postscript_functions (inf) | 3503 Postscript_functions (inf) |
3311 FILE *inf; | 3504 FILE *inf; |
3312 { | 3505 { |
3313 lineno = 0; | 3506 lineno = 0; |
3314 charno = 0; | 3507 charno = 0; |
3508 | |
3315 while (!feof (inf)) | 3509 while (!feof (inf)) |
3316 { | 3510 { |
3317 lineno++; | 3511 lineno++; |
3318 linecharno = charno; | 3512 linecharno = charno; |
3319 charno += readline (&lb, inf); | 3513 charno += readline (&lb, inf); |
3421 :part:appendix:entry:index"; | 3615 :part:appendix:entry:index"; |
3422 | 3616 |
3423 void TEX_mode (); | 3617 void TEX_mode (); |
3424 struct TEX_tabent *TEX_decode_env (); | 3618 struct TEX_tabent *TEX_decode_env (); |
3425 int TEX_Token (); | 3619 int TEX_Token (); |
3426 static void TEX_getit (); | |
3427 | 3620 |
3428 char TEX_esc = '\\'; | 3621 char TEX_esc = '\\'; |
3429 char TEX_opgrp = '{'; | 3622 char TEX_opgrp = '{'; |
3430 char TEX_clgrp = '}'; | 3623 char TEX_clgrp = '}'; |
3431 | 3624 |
3435 void | 3628 void |
3436 TeX_functions (inf) | 3629 TeX_functions (inf) |
3437 FILE *inf; | 3630 FILE *inf; |
3438 { | 3631 { |
3439 char *lasthit; | 3632 char *lasthit; |
3633 register int i; | |
3440 | 3634 |
3441 lineno = 0; | 3635 lineno = 0; |
3442 charno = 0; | 3636 charno = 0; |
3443 | 3637 |
3444 /* Select either \ or ! as escape character. */ | 3638 /* Select either \ or ! as escape character. */ |
3455 charno += readline (&lb, inf); | 3649 charno += readline (&lb, inf); |
3456 dbp = lb.buffer; | 3650 dbp = lb.buffer; |
3457 lasthit = dbp; | 3651 lasthit = dbp; |
3458 while (dbp = etags_strchr (dbp, TEX_esc)) /* Look at each esc in line */ | 3652 while (dbp = etags_strchr (dbp, TEX_esc)) /* Look at each esc in line */ |
3459 { | 3653 { |
3460 register int i; | |
3461 | |
3462 if (!*(++dbp)) | 3654 if (!*(++dbp)) |
3463 break; | 3655 break; |
3464 linecharno += dbp - lasthit; | 3656 linecharno += dbp - lasthit; |
3465 lasthit = dbp; | 3657 lasthit = dbp; |
3466 i = TEX_Token (lasthit); | 3658 i = TEX_Token (lasthit); |
3467 if (0 <= i) | 3659 if (i >= 0) |
3468 { | 3660 { |
3469 pfnote ((char *)NULL, TRUE, | 3661 /* We seem to include the TeX command in the tag name. |
3662 register char *p; | |
3663 for (p = lasthit + TEX_toktab[i].len; | |
3664 *p != '\0' && *p != TEX_clgrp; | |
3665 p++) | |
3666 continue; */ | |
3667 pfnote (/*savenstr (lasthit, p-lasthit)*/ (char *)NULL, TRUE, | |
3470 lb.buffer, lb.len, lineno, linecharno); | 3668 lb.buffer, lb.len, lineno, linecharno); |
3471 if (TeX_named_tokens) | 3669 break; /* We only tag a line once */ |
3472 TEX_getit (lasthit, TEX_toktab[i].len); | |
3473 break; /* We only save a line once */ | |
3474 } | 3670 } |
3475 } | 3671 } |
3476 } | 3672 } |
3477 } | 3673 } |
3478 | 3674 |
3566 } | 3762 } |
3567 } | 3763 } |
3568 return tab; | 3764 return tab; |
3569 } | 3765 } |
3570 | 3766 |
3571 /* Record a tag defined by a TeX command of length LEN and starting at NAME. | |
3572 The name being defined actually starts at (NAME + LEN + 1). | |
3573 But we seem to include the TeX command in the tag name. */ | |
3574 static void | |
3575 TEX_getit (name, len) | |
3576 char *name; | |
3577 int len; | |
3578 { | |
3579 char *p = name + len; | |
3580 | |
3581 if (*name == '\0') | |
3582 return; | |
3583 | |
3584 /* Let tag name extend to next group close (or end of line) */ | |
3585 while (*p && *p != TEX_clgrp) | |
3586 p++; | |
3587 pfnote (savenstr (name, p-name), TRUE, | |
3588 lb.buffer, lb.len, lineno, linecharno); | |
3589 } | |
3590 | |
3591 /* If the text at CP matches one of the tag-defining TeX command names, | 3767 /* If the text at CP matches one of the tag-defining TeX command names, |
3592 return the pointer to the first occurrence of that command in TEX_toktab. | 3768 return the pointer to the first occurrence of that command in TEX_toktab. |
3593 Otherwise return -1. | 3769 Otherwise return -1. |
3594 Keep the capital `T' in `Token' for dumb truncating compilers | 3770 Keep the capital `T' in `Token' for dumb truncating compilers |
3595 (this distinguishes it from `TEX_toktab' */ | 3771 (this distinguishes it from `TEX_toktab' */ |
3609 * Prolog support (rewritten) by Anders Lindgren, Mar. 96 | 3785 * Prolog support (rewritten) by Anders Lindgren, Mar. 96 |
3610 * | 3786 * |
3611 * Assumes that the predicate starts at column 0. | 3787 * Assumes that the predicate starts at column 0. |
3612 * Only the first clause of a predicate is added. | 3788 * Only the first clause of a predicate is added. |
3613 */ | 3789 */ |
3790 int prolog_pred (); | |
3791 void prolog_skip_comment (); | |
3792 int prolog_atom (); | |
3793 int eat_white (); | |
3794 | |
3614 void | 3795 void |
3615 Prolog_functions (inf) | 3796 Prolog_functions (inf) |
3616 FILE *inf; | 3797 FILE *inf; |
3617 { | 3798 { |
3618 int prolog_pred (); | |
3619 void prolog_skip_comment (); | |
3620 | |
3621 char * last; | 3799 char * last; |
3622 int len; | 3800 int len; |
3623 int allocated; | 3801 int allocated; |
3624 | 3802 |
3625 allocated = 0; | 3803 allocated = 0; |
3689 int | 3867 int |
3690 prolog_pred (s, last) | 3868 prolog_pred (s, last) |
3691 char *s; | 3869 char *s; |
3692 char *last; /* Name of last clause. */ | 3870 char *last; /* Name of last clause. */ |
3693 { | 3871 { |
3694 int prolog_atom(); | |
3695 int prolog_white(); | |
3696 | |
3697 int pos; | 3872 int pos; |
3698 int len; | 3873 int len; |
3699 | 3874 |
3700 pos = prolog_atom(s, 0); | 3875 pos = prolog_atom (s, 0); |
3701 if (pos < 1) | 3876 if (pos < 1) |
3702 return 0; | 3877 return 0; |
3703 | 3878 |
3704 len = pos; | 3879 len = pos; |
3705 pos += prolog_white(s, pos); | 3880 pos += eat_white (s, pos); |
3706 | 3881 |
3707 if ((s[pos] == '(') || (s[pos] == '.')) | 3882 if ((s[pos] == '(') || (s[pos] == '.')) |
3708 { | 3883 { |
3709 if (s[pos] == '(') | 3884 if (s[pos] == '(') |
3710 pos++; | 3885 pos++; |
3711 | 3886 |
3712 /* Save only the first clause. */ | 3887 /* Save only the first clause. */ |
3713 if ((last == NULL) || | 3888 if (last == NULL |
3714 (len != strlen(last)) || | 3889 || len != strlen (last) |
3715 (strncmp(s, last, len) != 0)) | 3890 || !strneq (s, last, len)) |
3716 { | 3891 { |
3717 pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE, | 3892 pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE, |
3718 s, pos, lineno, linecharno); | 3893 s, pos, lineno, linecharno); |
3719 return len; | 3894 return len; |
3720 } | 3895 } |
3781 return -1; | 3956 return -1; |
3782 } | 3957 } |
3783 | 3958 |
3784 /* Consume whitespace. Return the number of bytes eaten. */ | 3959 /* Consume whitespace. Return the number of bytes eaten. */ |
3785 int | 3960 int |
3786 prolog_white (s, pos) | 3961 eat_white (s, pos) |
3787 char *s; | 3962 char *s; |
3788 int pos; | 3963 int pos; |
3789 { | 3964 { |
3790 int origpos; | 3965 int origpos = pos; |
3791 | 3966 |
3792 origpos = pos; | 3967 origpos = pos; |
3793 | 3968 |
3794 while (isspace(s[pos])) | 3969 while (isspace (s[pos])) |
3795 pos++; | 3970 pos++; |
3796 | 3971 |
3797 return pos - origpos; | 3972 return pos - origpos; |
3798 } | 3973 } |
3799 | 3974 |
3802 * | 3977 * |
3803 * Generates tags for functions, defines, and records. | 3978 * Generates tags for functions, defines, and records. |
3804 * | 3979 * |
3805 * Assumes that Erlang functions start at column 0. | 3980 * Assumes that Erlang functions start at column 0. |
3806 */ | 3981 */ |
3982 int erlang_func (); | |
3983 void erlang_attribute (); | |
3984 int erlang_atom (); | |
3985 | |
3807 void | 3986 void |
3808 Erlang_functions (inf) | 3987 Erlang_functions (inf) |
3809 FILE *inf; | 3988 FILE *inf; |
3810 { | 3989 { |
3811 int erlang_func (); | |
3812 void erlang_attribute (); | |
3813 | |
3814 char * last; | 3990 char * last; |
3815 int len; | 3991 int len; |
3816 int allocated; | 3992 int allocated; |
3817 | 3993 |
3818 allocated = 0; | 3994 allocated = 0; |
3837 continue; | 4013 continue; |
3838 else if (dbp[0] == '"') /* Sometimes, strings start in column one */ | 4014 else if (dbp[0] == '"') /* Sometimes, strings start in column one */ |
3839 continue; | 4015 continue; |
3840 else if (dbp[0] == '-') /* attribute, e.g. "-define" */ | 4016 else if (dbp[0] == '-') /* attribute, e.g. "-define" */ |
3841 { | 4017 { |
3842 erlang_attribute(dbp); | 4018 erlang_attribute (dbp); |
3843 last = NULL; | 4019 last = NULL; |
3844 } | 4020 } |
3845 else if (len = erlang_func (dbp, last)) | 4021 else if (len = erlang_func (dbp, last)) |
3846 { | 4022 { |
3847 /* | 4023 /* |
3848 * Function. Store the function name so that we only | 4024 * Function. Store the function name so that we only |
3849 * generates a tag for the first clause. | 4025 * generates a tag for the first clause. |
3850 */ | 4026 */ |
3851 if (last == NULL) | 4027 if (last == NULL) |
3852 last = xnew(len + 1, char); | 4028 last = xnew (len + 1, char); |
3853 else if (len + 1 > allocated) | 4029 else if (len + 1 > allocated) |
3854 last = (char *) xrealloc(last, len + 1); | 4030 last = (char *) xrealloc (last, len + 1); |
3855 allocated = len + 1; | 4031 allocated = len + 1; |
3856 strncpy (last, dbp, len); | 4032 strncpy (last, dbp, len); |
3857 last[len] = '\0'; | 4033 last[len] = '\0'; |
3858 } | 4034 } |
3859 } | 4035 } |
3873 int | 4049 int |
3874 erlang_func (s, last) | 4050 erlang_func (s, last) |
3875 char *s; | 4051 char *s; |
3876 char *last; /* Name of last clause. */ | 4052 char *last; /* Name of last clause. */ |
3877 { | 4053 { |
3878 int erlang_atom (); | |
3879 int erlang_white (); | |
3880 | |
3881 int pos; | 4054 int pos; |
3882 int len; | 4055 int len; |
3883 | 4056 |
3884 pos = erlang_atom(s, 0); | 4057 pos = erlang_atom (s, 0); |
3885 if (pos < 1) | 4058 if (pos < 1) |
3886 return 0; | 4059 return 0; |
3887 | 4060 |
3888 len = pos; | 4061 len = pos; |
3889 pos += erlang_white(s, pos); | 4062 pos += eat_white (s, pos); |
3890 | 4063 |
3891 if (s[pos++] == '(') | 4064 /* Save only the first clause. */ |
3892 { | 4065 if (s[pos++] == '(' |
3893 /* Save only the first clause. */ | 4066 && (last == NULL |
3894 if ((last == NULL) || | 4067 || len != strlen (last) |
3895 (len != strlen(last)) || | 4068 || !strneq (s, last, len))) |
3896 (strncmp(s, last, len) != 0)) | |
3897 { | 4069 { |
3898 pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE, | 4070 pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE, |
3899 s, pos, lineno, linecharno); | 4071 s, pos, lineno, linecharno); |
3900 return len; | 4072 return len; |
3901 } | 4073 } |
3902 } | 4074 |
3903 return 0; | 4075 return 0; |
3904 } | 4076 } |
3905 | 4077 |
3906 | 4078 |
3907 /* | 4079 /* |
3915 */ | 4087 */ |
3916 void | 4088 void |
3917 erlang_attribute (s) | 4089 erlang_attribute (s) |
3918 char *s; | 4090 char *s; |
3919 { | 4091 { |
3920 int erlang_atom (); | |
3921 int erlang_white (); | |
3922 | |
3923 int pos; | 4092 int pos; |
3924 int len; | 4093 int len; |
3925 | 4094 |
3926 if ((strncmp(s, "-define", 7) == 0) || | 4095 if (strneq (s, "-define", 7) || strneq (s, "-record", 7)) |
3927 (strncmp(s, "-record", 7) == 0)) | 4096 { |
3928 { | 4097 pos = 7 + eat_white (s, pos); |
3929 pos = 7; | |
3930 pos += erlang_white(s, pos); | |
3931 | |
3932 if (s[pos++] == '(') | 4098 if (s[pos++] == '(') |
3933 { | 4099 { |
3934 pos += erlang_white(s, pos); | 4100 pos += eat_white (s, pos); |
3935 | 4101 if (len = erlang_atom (s, pos)) |
3936 if (len = erlang_atom(s, pos)) | |
3937 { | |
3938 pfnote ((CTAGS) ? savenstr (& s[pos], len) : NULL, TRUE, | 4102 pfnote ((CTAGS) ? savenstr (& s[pos], len) : NULL, TRUE, |
3939 s, pos + len, lineno, linecharno); | 4103 s, pos + len, lineno, linecharno); |
3940 } | |
3941 } | 4104 } |
3942 } | 4105 } |
3943 return; | 4106 return; |
3944 } | 4107 } |
3945 | 4108 |
3991 return pos - origpos; | 4154 return pos - origpos; |
3992 } | 4155 } |
3993 else | 4156 else |
3994 return -1; | 4157 return -1; |
3995 } | 4158 } |
3996 | |
3997 /* Consume whitespace. Return the number of bytes eaten */ | |
3998 int | |
3999 erlang_white (s, pos) | |
4000 char *s; | |
4001 int pos; | |
4002 { | |
4003 int origpos; | |
4004 | |
4005 origpos = pos; | |
4006 | |
4007 while (isspace (s[pos])) | |
4008 pos++; | |
4009 | |
4010 return pos - origpos; | |
4011 } | |
4012 | 4159 |
4013 #ifdef ETAGS_REGEXPS | 4160 #ifdef ETAGS_REGEXPS |
4014 /* Take a string like "/blah/" and turn it into "blah", making sure | 4161 /* Take a string like "/blah/" and turn it into "blah", making sure |
4015 that the first and last characters are the same, and handling | 4162 that the first and last characters are the same, and handling |
4016 quoted separator characters. Actually, stops on the occurrence of | 4163 quoted separator characters. Actually, stops on the occurrence of |
4021 scan_separators (name) | 4168 scan_separators (name) |
4022 char *name; | 4169 char *name; |
4023 { | 4170 { |
4024 char sep = name[0]; | 4171 char sep = name[0]; |
4025 char *copyto = name; | 4172 char *copyto = name; |
4026 logical quoted = FALSE; | 4173 bool quoted = FALSE; |
4027 | 4174 |
4028 for (++name; *name != '\0'; ++name) | 4175 for (++name; *name != '\0'; ++name) |
4029 { | 4176 { |
4030 if (quoted) | 4177 if (quoted) |
4031 { | 4178 { |