0
|
1 /* Tags file maker to go with GNU Emacs
|
|
2 Copyright (C) 1984, 87, 88, 89, 93, 94, 95
|
|
3 Free Software Foundation, Inc. and Ken Arnold
|
|
4 This file is not considered part of GNU Emacs.
|
|
5
|
|
6 This program is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 2 of the License, or
|
|
9 (at your option) any later version.
|
|
10
|
|
11 This program is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with this program; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: FSF 19.30. */
|
|
22
|
|
23 /*
|
|
24 * Authors:
|
|
25 * Ctags originally by Ken Arnold.
|
|
26 * Fortran added by Jim Kleckner.
|
|
27 * Ed Pelegri-Llopart added C typedefs.
|
|
28 * Gnu Emacs TAGS format and modifications by RMS?
|
|
29 * Sam Kendall added C++.
|
|
30 * Francesco Potorti` reorganised C and C++ based on work by Joe Wells.
|
|
31 #ifdef ETAGS_REGEXPS
|
|
32 * Regexp tags by Tom Tromey.
|
|
33 #endif
|
|
34 *
|
|
35 * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer.
|
|
36 */
|
|
37
|
|
38 char pot_etags_version[] = "@(#) pot revision number is 11.45";
|
|
39
|
|
40 #define TRUE 1
|
|
41 #define FALSE 0
|
|
42 #ifndef DEBUG
|
|
43 # define DEBUG FALSE
|
|
44 #endif
|
|
45
|
|
46 #ifdef MSDOS
|
|
47 #include <fcntl.h>
|
|
48 #include <sys/param.h>
|
|
49 #endif /* MSDOS */
|
|
50
|
|
51 #ifdef WINDOWSNT
|
|
52 #include <stdlib.h>
|
|
53 #include <fcntl.h>
|
|
54 #include <string.h>
|
|
55 #define MAXPATHLEN _MAX_PATH
|
|
56 #endif
|
|
57
|
|
58 #ifdef HAVE_CONFIG_H
|
|
59 #include <../src/config.h>
|
|
60 /* On some systems, Emacs defines static as nothing for the sake
|
|
61 of unexec. We don't want that here since we don't use unexec. */
|
|
62 #undef static
|
|
63 #endif
|
|
64
|
|
65 #if __STDC__ || defined(STDC_HEADERS)
|
|
66 #include <stdlib.h>
|
|
67 #include <unistd.h>
|
|
68 #include <string.h>
|
|
69 #else
|
|
70 extern char *getenv ();
|
|
71 #endif
|
|
72
|
|
73 #include <stdio.h>
|
|
74 #include <ctype.h>
|
|
75 #include <errno.h>
|
|
76 #ifndef errno
|
|
77 extern int errno;
|
|
78 #endif
|
|
79 #include <sys/types.h>
|
|
80 #include <sys/stat.h>
|
|
81
|
|
82 #if !defined (S_ISREG) && defined (S_IFREG)
|
|
83 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
|
84 #endif
|
|
85
|
|
86 #include <getopt.h>
|
|
87
|
|
88 #ifdef ETAGS_REGEXPS
|
|
89 #include <regex.h>
|
|
90 #endif /* ETAGS_REGEXPS */
|
|
91
|
|
92 /* Define CTAGS to make the program "ctags" compatible with the usual one.
|
|
93 Let it undefined to make the program "etags", which makes emacs-style
|
|
94 tag tables and tags typedefs, #defines and struct/union/enum by default. */
|
|
95 #ifdef CTAGS
|
|
96 # undef CTAGS
|
|
97 # define CTAGS TRUE
|
|
98 #else
|
|
99 # define CTAGS FALSE
|
|
100 #endif
|
|
101
|
|
102 /* Exit codes for success and failure. */
|
|
103 #ifdef VMS
|
|
104 #define GOOD 1
|
|
105 #define BAD 0
|
|
106 #else
|
|
107 #define GOOD 0
|
|
108 #define BAD 1
|
|
109 #endif
|
|
110
|
|
111 /* C extensions. */
|
|
112 #define C_PLPL 0x00001 /* C++ */
|
|
113 #define C_STAR 0x00003 /* C* */
|
|
114 #define YACC 0x10000 /* yacc file */
|
|
115
|
|
116 #define streq(s,t) (strcmp (s, t) == 0)
|
|
117 #define strneq(s,t,n) (strncmp (s, t, n) == 0)
|
|
118
|
|
119 #define lowcase(c) tolower ((unsigned char)c)
|
|
120
|
|
121 #define iswhite(arg) (_wht[(unsigned int) arg]) /* T if char is white */
|
|
122 #define begtoken(arg) (_btk[(unsigned int) arg]) /* T if char can start token */
|
|
123 #define intoken(arg) (_itk[(unsigned int) arg]) /* T if char can be in token */
|
|
124 #define endtoken(arg) (_etk[(unsigned int) arg]) /* T if char ends tokens */
|
|
125
|
|
126 /* typedefs from down below, moved up for prototypes */
|
|
127
|
|
128 /*
|
|
129 * A `struct linebuffer' is a structure which holds a line of text.
|
|
130 * `readline' reads a line from a stream into a linebuffer and works
|
|
131 * regardless of the length of the line.
|
|
132 */
|
|
133 struct linebuffer
|
|
134 {
|
|
135 long size;
|
|
136 char *buffer;
|
|
137 };
|
|
138
|
|
139 #ifdef DOS_NT
|
|
140 # define absolutefn(fn) (fn[0] == '/' || (isalpha (fn[0]) && fn[1] == ':'))
|
|
141 #else
|
|
142 # define absolutefn(fn) (fn[0] == '/')
|
|
143 #endif
|
|
144
|
|
145
|
|
146 /*
|
|
147 * xnew -- allocate storage
|
|
148 *
|
|
149 * SYNOPSIS: Type *xnew (int n, Type);
|
|
150 */
|
|
151 #define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type)))
|
|
152
|
|
153 typedef int logical;
|
|
154
|
|
155 typedef struct nd_st
|
|
156 { /* sorting structure */
|
|
157 char *name; /* function or type name */
|
|
158 char *file; /* file name */
|
|
159 logical is_func; /* use pattern or line no */
|
|
160 logical been_warned; /* set if noticed dup */
|
|
161 long lno; /* line number tag is on */
|
|
162 long cno; /* character number line starts on */
|
|
163 char *pat; /* search pattern */
|
|
164 struct nd_st *left, *right; /* left and right sons */
|
|
165 } NODE;
|
|
166
|
|
167 extern char *getenv ();
|
|
168
|
|
169 char *concat (CONST char *s1, CONST char *s2, CONST char *s3);
|
|
170 char *savenstr (CONST char *cp, int len);
|
|
171 char *savestr (CONST char *cp);
|
|
172 char *etags_strchr (CONST char *sp, char c);
|
|
173 char *etags_strrchr (CONST char *sp, char c);
|
|
174 char *etags_getcwd (void);
|
|
175 char *relative_filename (CONST char *file, CONST char *dir);
|
|
176 char *absolute_filename (CONST char *file, CONST char *cwd);
|
|
177 char *absolute_dirname (char *file, CONST char *cwd);
|
|
178 void *xmalloc (unsigned int size);
|
|
179 void *xrealloc (void *ptr, unsigned int size);
|
|
180
|
|
181 typedef void Lang_function ();
|
|
182 #if FALSE /* many compilers barf on this */
|
|
183 Lang_function Asm_labels;
|
|
184 Lang_function default_C_entries;
|
|
185 Lang_function C_entries;
|
|
186 Lang_function Cplusplus_entries;
|
|
187 Lang_function Cstar_entries;
|
|
188 Lang_function Fortran_functions;
|
|
189 Lang_function Yacc_entries;
|
|
190 Lang_function Lisp_functions;
|
|
191 Lang_function Pascal_functions;
|
|
192 Lang_function Perl_functions;
|
|
193 Lang_function Postscript_functions;
|
|
194 Lang_function Prolog_functions;
|
|
195 Lang_function Scheme_functions;
|
|
196 Lang_function TeX_functions;
|
|
197 Lang_function just_read_file;
|
|
198 #else /* so let's write it this way */
|
|
199 void Asm_labels (FILE *inf);
|
|
200 void C_entries (int c_ext, FILE *inf);
|
|
201 void default_C_entries (FILE *inf);
|
|
202 void plain_C_entries (FILE *inf);
|
|
203 void Cplusplus_entries (FILE *inf);
|
|
204 void Cstar_entries (FILE *inf);
|
|
205 void Fortran_functions (FILE *inf);
|
|
206 void Yacc_entries (FILE *inf);
|
|
207 void Lisp_functions (FILE *inf);
|
|
208 void Pascal_functions (FILE *inf);
|
|
209 void Perl_functions (FILE *inf);
|
|
210 void Postscript_functions (FILE *inf);
|
|
211 void Prolog_functions (FILE *inf);
|
|
212 void Scheme_functions (FILE *inf);
|
|
213 void TeX_functions (FILE *inf);
|
|
214 void just_read_file (FILE *inf);
|
|
215 #endif
|
|
216
|
|
217 Lang_function *get_language_from_name (char *name);
|
|
218 Lang_function *get_language_from_interpreter (char *interpreter);
|
|
219 Lang_function *get_language_from_suffix (CONST char *suffix);
|
|
220 int total_size_of_entries (NODE *node);
|
|
221 long readline (struct linebuffer *linebuffer, FILE *stream);
|
|
222 long readline_internal (struct linebuffer *linebuffer, FILE *stream);
|
|
223 #ifdef ETAGS_REGEXPS
|
|
224 void add_regex (char *regexp_pattern);
|
|
225 #endif
|
|
226 void add_node (NODE *node, NODE **cur_node_p);
|
|
227 void error (CONST char *s1, CONST void *s2);
|
|
228 void fatal (CONST char *s1, CONST char *s2);
|
|
229 void pfatal (CONST char *s1);
|
|
230 void find_entries (CONST char *file, FILE *inf);
|
|
231 void free_tree (NODE *);
|
|
232 void getit (FILE *inf);
|
|
233 void init (void);
|
|
234 void initbuffer (struct linebuffer *linebuffer);
|
|
235 void pfnote (char *name, logical is_func, char *linestart,
|
|
236 int linelen, int lno, long cno);
|
|
237 void process_file (CONST char *file);
|
|
238 void put_entries (NODE *node);
|
|
239 void takeprec (void);
|
|
240
|
|
241
|
|
242 char searchar = '/'; /* use /.../ searches */
|
|
243
|
|
244 int lineno; /* line number of current line */
|
|
245 long charno; /* current character number */
|
|
246
|
|
247 long linecharno; /* charno of start of line; not used by C,
|
|
248 but by every other language. */
|
|
249
|
|
250 char *curfile; /* current input file name */
|
|
251 char *tagfile; /* output file */
|
|
252 CONST char *progname; /* name this program was invoked with */
|
|
253 char *cwd; /* current working directory */
|
|
254 char *tagfiledir; /* directory of tagfile */
|
|
255
|
|
256 FILE *tagf; /* ioptr for tags file */
|
|
257 NODE *head; /* the head of the binary tree of tags */
|
|
258
|
|
259 struct linebuffer lb; /* the current line */
|
|
260 struct linebuffer token_name; /* used by C_entries as temporary area */
|
|
261 struct
|
|
262 {
|
|
263 long linepos;
|
|
264 struct linebuffer lb; /* used by C_entries instead of lb */
|
|
265 } lbs[2];
|
|
266
|
|
267 /* boolean "functions" (see init) */
|
|
268 logical _wht[0177], _etk[0177], _itk[0177], _btk[0177];
|
|
269 CONST char
|
|
270 *white = " \f\t\n\013", /* white chars */
|
|
271 *endtk = " \t\n\013\"'#()[]{}=-+%*/&|^~!<>;,.:?", /* token ending chars */
|
|
272 /* token starting chars */
|
|
273 *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~",
|
|
274 /* valid in-token chars */
|
|
275 *intk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789";
|
|
276
|
|
277 logical append_to_tagfile; /* -a: append to tags */
|
|
278 /* The following three default to TRUE for etags, but to FALSE for ctags. */
|
|
279 logical typedefs; /* -t: create tags for typedefs */
|
|
280 logical typedefs_and_cplusplus; /* -T: create tags for typedefs, level */
|
|
281 /* 0 struct/enum/union decls, and C++ */
|
|
282 /* member functions. */
|
|
283 logical constantypedefs; /* -d: create tags for C #define and enum */
|
|
284 /* constants. Enum consts not implemented. */
|
|
285 /* -D: opposite of -d. Default under ctags. */
|
|
286 logical update; /* -u: update tags */
|
|
287 logical vgrind_style; /* -v: create vgrind style index output */
|
|
288 logical no_warnings; /* -w: suppress warnings */
|
|
289 logical cxref_style; /* -x: create cxref style output */
|
|
290 logical cplusplus; /* .[hc] means C++, not C */
|
|
291 logical noindentypedefs; /* -I: ignore indentation in C */
|
|
292
|
|
293 struct option longopts[] =
|
|
294 {
|
|
295 { "append", no_argument, NULL, 'a' },
|
|
296 { "backward-search", no_argument, NULL, 'B' },
|
|
297 { "c++", no_argument, NULL, 'C' },
|
|
298 { "cxref", no_argument, NULL, 'x' },
|
|
299 { "defines", no_argument, NULL, 'd' },
|
|
300 { "help", no_argument, NULL, 'h' },
|
|
301 { "help", no_argument, NULL, 'H' },
|
|
302 { "ignore-indentation", no_argument, NULL, 'I' },
|
|
303 { "include", required_argument, NULL, 'i' },
|
|
304 { "language", required_argument, NULL, 'l' },
|
|
305 { "no-defines", no_argument, NULL, 'D' },
|
|
306 { "no-regex", no_argument, NULL, 'R' },
|
|
307 { "no-warn", no_argument, NULL, 'w' },
|
|
308 { "output", required_argument, NULL, 'o' },
|
|
309 { "regex", required_argument, NULL, 'r' },
|
|
310 { "typedefs", no_argument, NULL, 't' },
|
|
311 { "typedefs-and-c++", no_argument, NULL, 'T' },
|
|
312 { "update", no_argument, NULL, 'u' },
|
|
313 { "version", no_argument, NULL, 'V' },
|
|
314 { "vgrind", no_argument, NULL, 'v' },
|
|
315 { 0 }
|
|
316 };
|
|
317
|
|
318 #ifdef ETAGS_REGEXPS
|
|
319 /* Structure defining a regular expression. Elements are
|
|
320 the compiled pattern, and the name string. */
|
|
321 struct pattern
|
|
322 {
|
|
323 struct re_pattern_buffer *pattern;
|
|
324 struct re_registers regs;
|
|
325 char *name_pattern;
|
|
326 logical error_signaled;
|
|
327 };
|
|
328
|
|
329 /* Number of regexps found. */
|
|
330 int num_patterns = 0;
|
|
331
|
|
332 /* Array of all regexps. */
|
|
333 struct pattern *patterns = NULL;
|
|
334 #endif /* ETAGS_REGEXPS */
|
|
335
|
|
336 /*
|
|
337 * Language stuff.
|
|
338 */
|
|
339
|
|
340 /* Non-NULL if language fixed. */
|
|
341 Lang_function *lang_func = NULL;
|
|
342
|
|
343 /* Assembly code */
|
|
344 CONST char *Asm_suffixes [] = { "a", /* Unix assembler */
|
|
345 "asm", /* Microcontroller assembly */
|
|
346 "def", /* BSO/Tasking definition includes */
|
|
347 "inc", /* Microcontroller include files */
|
|
348 "ins", /* Microcontroller include files */
|
|
349 "s", "sa", /* Unix assembler */
|
|
350 "src", /* BSO/Tasking C compiler output */
|
|
351 NULL
|
|
352 };
|
|
353
|
|
354 /* Note that .c and .h can be considered C++, if the --c++ flag was
|
|
355 given. That is why default_C_entries is called here. */
|
|
356 CONST char *default_C_suffixes [] =
|
|
357 { "c", "h", NULL };
|
|
358
|
|
359 /* C++ file */
|
|
360 CONST char *Cplusplus_suffixes [] =
|
|
361 { "C", "H", "c++", "cc", "cpp", "cxx", "h++", "hh", "hpp", "hxx",
|
|
362 /* XEmacs addition: Postscript with C syntax */
|
|
363 "pdb", NULL };
|
|
364
|
|
365 /* C* file */
|
|
366 CONST char *Cstar_suffixes [] =
|
|
367 { "cs", "hs", NULL };
|
|
368
|
|
369 /* Fortran */
|
|
370 CONST char *Fortran_suffixes [] =
|
|
371 { "F", "f", "f90", "for", NULL };
|
|
372
|
|
373 /* Lisp source code */
|
|
374 CONST char *Lisp_suffixes [] =
|
|
375 { "cl", "clisp", "el", "l", "lisp", "lsp", "ml", NULL };
|
|
376
|
|
377 /* Pascal file */
|
|
378 CONST char *Pascal_suffixes [] =
|
|
379 { "p", "pas", NULL };
|
|
380
|
|
381 /* Perl file */
|
|
382 CONST char *Perl_suffixes [] =
|
|
383 { "pl", "pm", NULL };
|
|
384 CONST char *Perl_interpreters [] =
|
|
385 { "perl", NULL };
|
|
386
|
|
387 /* Pro*C file. */
|
|
388 CONST char *plain_C_suffixes [] =
|
|
389 { "pc", NULL };
|
|
390
|
|
391 /* XEmacs addition */
|
|
392 /* Postscript source code */
|
|
393 CONST char *Postscript_suffixes [] =
|
|
394 { "ps", NULL };
|
|
395
|
|
396 /* Prolog source code */
|
|
397 CONST char *Prolog_suffixes [] =
|
|
398 { "prolog", NULL };
|
|
399
|
|
400 /* Scheme source code */
|
|
401 /* FIXME Can't do the `SCM' or `scm' prefix with a version number */
|
|
402 CONST char *Scheme_suffixes [] =
|
|
403 { "SCM", "SM", "oak", "sch", "scheme", "scm", "sm", "t", NULL };
|
|
404
|
|
405 /* TeX/LaTeX source code */
|
|
406 CONST char *TeX_suffixes [] =
|
|
407 { "bib", "clo", "cls", "ltx", "sty", "TeX", "tex", NULL };
|
|
408
|
|
409 /* Yacc file */
|
|
410 CONST char *Yacc_suffixes [] =
|
|
411 { "y", NULL };
|
|
412
|
|
413 /* Table of language names and corresponding functions, file suffixes
|
|
414 and interpreter names.
|
|
415 It is ok for a given function to be listed under more than one
|
|
416 name. I just didn't. */
|
|
417 struct lang_entry
|
|
418 {
|
|
419 CONST char *name;
|
|
420 Lang_function *function;
|
|
421 CONST char **suffixes;
|
|
422 CONST char **interpreters;
|
|
423 };
|
|
424
|
|
425 CONST struct lang_entry lang_names [] =
|
|
426 {
|
|
427 { "asm", Asm_labels, Asm_suffixes },
|
|
428 { "c", default_C_entries, default_C_suffixes },
|
|
429 { "c++", Cplusplus_entries, Cplusplus_suffixes },
|
|
430 { "c*", Cstar_entries, Cstar_suffixes },
|
|
431 { "fortran", Fortran_functions, Fortran_suffixes },
|
|
432 { "lisp", Lisp_functions, Lisp_suffixes },
|
|
433 { "pascal", Pascal_functions, Pascal_suffixes },
|
|
434 { "perl", Perl_functions, Perl_suffixes, Perl_interpreters },
|
|
435 { "proc", plain_C_entries, plain_C_suffixes },
|
|
436 { "prolog", Prolog_functions, Prolog_suffixes },
|
|
437 { "postscript", Postscript_functions, Postscript_suffixes },
|
|
438 { "scheme" , Scheme_functions, Scheme_suffixes },
|
|
439 { "tex", TeX_functions, TeX_suffixes },
|
|
440 { "yacc", Yacc_entries, Yacc_suffixes },
|
|
441 { "auto", NULL }, /* default guessing scheme */
|
|
442 { "none", just_read_file }, /* regexp matching only */
|
|
443 { NULL, NULL } /* end of list */
|
|
444 };
|
|
445
|
|
446
|
|
447 static void
|
|
448 print_language_names (void)
|
|
449 {
|
|
450 CONST struct lang_entry *lang;
|
|
451 CONST char **ext;
|
|
452
|
|
453 puts ("\nThese are the currently supported languages, along with the\n\
|
|
454 default file name suffixes:");
|
|
455 for (lang = lang_names; lang->name != NULL; lang++)
|
|
456 {
|
|
457 printf ("\t%s\t", lang->name);
|
|
458 if (lang->suffixes != NULL)
|
|
459 for (ext = lang->suffixes; *ext != NULL; ext++)
|
|
460 printf (" .%s", *ext);
|
|
461 puts ("");
|
|
462 }
|
|
463 puts ("Where `auto' means use default language for files based on file\n\
|
|
464 name suffix, and `none' means only do regexp processing on files.\n\
|
|
465 If no language is specified and no matching suffix is found,\n\
|
|
466 the first line of the file is read for a sharp-bang (#!) sequence\n\
|
|
467 followed by the name of an interpreter. If no such sequence is found,\n\
|
|
468 Fortran is tried first; if no tags are found, C is tried next.");
|
|
469 }
|
|
470
|
|
471 #ifndef VERSION
|
|
472 # define VERSION "19"
|
|
473 #endif
|
|
474 static void
|
|
475 print_version (void)
|
|
476 {
|
|
477 printf ("%s for Emacs version %s\n", (CTAGS) ? "ctags" : "etags", VERSION);
|
|
478
|
|
479 exit (GOOD);
|
|
480 }
|
|
481
|
|
482 static void
|
|
483 print_help (void)
|
|
484 {
|
|
485 printf ("These are the options accepted by %s. You may use unambiguous\n\
|
|
486 abbreviations for the long option names. A - as file name means read\n\
|
|
487 names from stdin.\n\n", progname);
|
|
488
|
|
489 puts ("-a, --append\n\
|
|
490 Append tag entries to existing tags file.");
|
|
491
|
|
492 if (CTAGS)
|
|
493 puts ("-B, --backward-search\n\
|
|
494 Write the search commands for the tag entries using '?', the\n\
|
|
495 backward-search command instead of '/', the forward-search command.");
|
|
496
|
|
497 puts ("-C, --c++\n\
|
|
498 Treat files whose name suffix defaults to C language as C++ files.");
|
|
499
|
|
500 if (CTAGS)
|
|
501 puts ("-d, --defines\n\
|
|
502 Create tag entries for constant C #defines, too.");
|
|
503 else
|
|
504 puts ("-D, --no-defines\n\
|
|
505 Don't create tag entries for constant C #defines. This makes\n\
|
|
506 the tags file smaller.");
|
|
507
|
|
508 if (!CTAGS)
|
|
509 {
|
|
510 puts ("-i FILE, --include=FILE\n\
|
|
511 Include a note in tag file indicating that, when searching for\n\
|
|
512 a tag, one should also consult the tags file FILE after\n\
|
|
513 checking the current file.");
|
|
514 puts ("-l LANG, --language=LANG\n\
|
|
515 Force the following files to be considered as written in the\n\
|
|
516 named language up to the next --language=LANG option.");
|
|
517 }
|
|
518
|
|
519 #ifdef ETAGS_REGEXPS
|
|
520 puts ("-r /REGEXP/, --regex=/REGEXP/\n\
|
|
521 Make a tag for each line matching pattern REGEXP in the\n\
|
|
522 following files. REGEXP is anchored (as if preceded by ^).\n\
|
|
523 The form /REGEXP/NAME/ creates a named tag. For example Tcl\n\
|
|
524 named tags can be created with:\n\
|
|
525 --regex=/proc[ \\t]+\\([^ \\t]+\\)/\\1/.");
|
|
526 puts ("-R, --no-regex\n\
|
|
527 Don't create tags from regexps for the following files.");
|
|
528 #endif /* ETAGS_REGEXPS */
|
|
529 puts ("-o FILE, --output=FILE\n\
|
|
530 Write the tags to FILE.");
|
|
531 puts ("-I, --ignore-indentation\n\
|
|
532 Don't rely on indentation quite as much as normal. Currently,\n\
|
|
533 this means not to assume that a closing brace in the first\n\
|
|
534 column is the final brace of a function or structure\n\
|
|
535 definition in C and C++.");
|
|
536
|
|
537 if (CTAGS)
|
|
538 {
|
|
539 puts ("-t, --typedefs\n\
|
|
540 Generate tag entries for C typedefs.");
|
|
541 puts ("-T, --typedefs-and-c++\n\
|
|
542 Generate tag entries for C typedefs, C struct/enum/union tags,\n\
|
|
543 and C++ member functions.");
|
|
544 puts ("-u, --update\n\
|
|
545 Update the tag entries for the given files, leaving tag\n\
|
|
546 entries for other files in place. Currently, this is\n\
|
|
547 implemented by deleting the existing entries for the given\n\
|
|
548 files and then rewriting the new entries at the end of the\n\
|
|
549 tags file. It is often faster to simply rebuild the entire\n\
|
|
550 tag file than to use this.");
|
|
551 puts ("-v, --vgrind\n\
|
|
552 Generates an index of items intended for human consumption,\n\
|
|
553 similar to the output of vgrind. The index is sorted, and\n\
|
|
554 gives the page number of each item.");
|
|
555 puts ("-w, --no-warn\n\
|
|
556 Suppress warning messages about entries defined in multiple\n\
|
|
557 files.");
|
|
558 puts ("-x, --cxref\n\
|
|
559 Like --vgrind, but in the style of cxref, rather than vgrind.\n\
|
|
560 The output uses line numbers instead of page numbers, but\n\
|
|
561 beyond that the differences are cosmetic; try both to see\n\
|
|
562 which you like.");
|
|
563 }
|
|
564
|
|
565 puts ("-V, --version\n\
|
|
566 Print the version of the program.\n\
|
|
567 -h, --help\n\
|
|
568 Print this help message.");
|
|
569
|
|
570 print_language_names ();
|
|
571
|
|
572 exit (GOOD);
|
|
573 }
|
|
574
|
|
575
|
|
576 #ifdef ETAGS_REGEXPS
|
|
577 enum argument_type
|
|
578 {
|
|
579 at_language,
|
|
580 at_regexp,
|
|
581 at_filename
|
|
582 };
|
|
583 #else /* !ETAGS_REGEXPS */
|
|
584 enum argument_type
|
|
585 {
|
|
586 at_language,
|
|
587 at_filename
|
|
588 };
|
|
589 #endif /* !ETAGS_REGEXPS */
|
|
590
|
|
591 /* This structure helps us allow mixing of --lang and filenames. */
|
|
592 typedef struct
|
|
593 {
|
|
594 enum argument_type arg_type;
|
|
595 char *what;
|
|
596 Lang_function *function;
|
|
597 } argument;
|
|
598
|
|
599 #ifdef VMS /* VMS specific functions */
|
|
600
|
|
601 #define EOS '\0'
|
|
602
|
|
603 /* This is a BUG! ANY arbitrary limit is a BUG!
|
|
604 Won't someone please fix this? */
|
|
605 #define MAX_FILE_SPEC_LEN 255
|
|
606 typedef struct {
|
|
607 short curlen;
|
|
608 char body[MAX_FILE_SPEC_LEN + 1];
|
|
609 } vspec;
|
|
610
|
|
611 /*
|
|
612 v1.05 nmm 26-Jun-86 fn_exp - expand specification of list of file names
|
|
613 returning in each successive call the next filename matching the input
|
|
614 spec. The function expects that each in_spec passed
|
|
615 to it will be processed to completion; in particular, up to and
|
|
616 including the call following that in which the last matching name
|
|
617 is returned, the function ignores the value of in_spec, and will
|
|
618 only start processing a new spec with the following call.
|
|
619 If an error occurs, on return out_spec contains the value
|
|
620 of in_spec when the error occurred.
|
|
621
|
|
622 With each successive filename returned in out_spec, the
|
|
623 function's return value is one. When there are no more matching
|
|
624 names the function returns zero. If on the first call no file
|
|
625 matches in_spec, or there is any other error, -1 is returned.
|
|
626 */
|
|
627
|
|
628 #include <rmsdef.h>
|
|
629 #include <descrip.h>
|
|
630 #define OUTSIZE MAX_FILE_SPEC_LEN
|
|
631 short
|
|
632 fn_exp (vspec *out, char *in)
|
|
633 {
|
|
634 static long context = 0;
|
|
635 static struct dsc$descriptor_s o;
|
|
636 static struct dsc$descriptor_s i;
|
|
637 static logical pass1 = TRUE;
|
|
638 long status;
|
|
639 short retval;
|
|
640
|
|
641 if (pass1)
|
|
642 {
|
|
643 pass1 = FALSE;
|
|
644 o.dsc$a_pointer = (char *) out;
|
|
645 o.dsc$w_length = (short)OUTSIZE;
|
|
646 i.dsc$a_pointer = in;
|
|
647 i.dsc$w_length = (short)strlen(in);
|
|
648 i.dsc$b_dtype = DSC$K_DTYPE_T;
|
|
649 i.dsc$b_class = DSC$K_CLASS_S;
|
|
650 o.dsc$b_dtype = DSC$K_DTYPE_VT;
|
|
651 o.dsc$b_class = DSC$K_CLASS_VS;
|
|
652 }
|
|
653 if ((status = lib$find_file(&i, &o, &context, 0, 0)) == RMS$_NORMAL)
|
|
654 {
|
|
655 out->body[out->curlen] = EOS;
|
|
656 return 1;
|
|
657 }
|
|
658 else if (status == RMS$_NMF)
|
|
659 retval = 0;
|
|
660 else
|
|
661 {
|
|
662 strcpy(out->body, in);
|
|
663 retval = -1;
|
|
664 }
|
|
665 lib$find_file_end(&context);
|
|
666 pass1 = TRUE;
|
|
667 return retval;
|
|
668 }
|
|
669
|
|
670 /*
|
|
671 v1.01 nmm 19-Aug-85 gfnames - return in successive calls the
|
|
672 name of each file specified by the provided arg expanding wildcards.
|
|
673 */
|
|
674 char *
|
|
675 gfnames (char *arg, logical *p_error)
|
|
676 {
|
|
677 static vspec filename = {MAX_FILE_SPEC_LEN, "\0"};
|
|
678
|
|
679 switch (fn_exp (&filename, arg))
|
|
680 {
|
|
681 case 1:
|
|
682 *p_error = FALSE;
|
|
683 return filename.body;
|
|
684 case 0:
|
|
685 *p_error = FALSE;
|
|
686 return NULL;
|
|
687 default:
|
|
688 *p_error = TRUE;
|
|
689 return filename.body;
|
|
690 }
|
|
691 }
|
|
692
|
|
693 #ifndef OLD /* Newer versions of VMS do provide `system'. */
|
|
694 void
|
|
695 system (char *cmd)
|
|
696 {
|
|
697 fprintf (stderr, "system() function not implemented under VMS\n");
|
|
698 }
|
|
699 #endif
|
|
700
|
|
701 #define VERSION_DELIM ';'
|
|
702 char *
|
|
703 massage_name (char *s)
|
|
704 {
|
|
705 char *start = s;
|
|
706
|
|
707 for ( ; *s; s++)
|
|
708 if (*s == VERSION_DELIM)
|
|
709 {
|
|
710 *s = EOS;
|
|
711 break;
|
|
712 }
|
|
713 else
|
|
714 *s = lowcase (*s);
|
|
715 return start;
|
|
716 }
|
|
717 #endif /* VMS */
|
|
718
|
|
719
|
|
720 void
|
|
721 main (int argc, char *argv[])
|
|
722 {
|
|
723 int i;
|
|
724 unsigned int nincluded_files = 0;
|
|
725 char **included_files = xnew (argc, char *);
|
|
726 char *this_file;
|
|
727 argument *argbuffer;
|
|
728 int current_arg = 0, file_count = 0;
|
|
729 struct linebuffer filename_lb;
|
|
730 #ifdef VMS
|
|
731 logical got_err;
|
|
732 #endif
|
|
733
|
|
734 #ifdef DOS_NT
|
|
735 _fmode = O_BINARY; /* all of files are treated as binary files */
|
|
736 #endif /* DOS_NT */
|
|
737
|
|
738 progname = argv[0];
|
|
739
|
|
740 /* Allocate enough no matter what happens. Overkill, but each one
|
|
741 is small. */
|
|
742 argbuffer = xnew (argc, argument);
|
|
743
|
|
744 #ifdef ETAGS_REGEXPS
|
|
745 /* Set syntax for regular expression routines. */
|
|
746 re_set_syntax (RE_SYNTAX_EMACS);
|
|
747 #endif /* ETAGS_REGEXPS */
|
|
748
|
|
749 /*
|
|
750 * If etags, always find typedefs and structure tags. Why not?
|
|
751 * Also default is to find macro constants.
|
|
752 */
|
|
753 if (!CTAGS)
|
|
754 typedefs = typedefs_and_cplusplus = constantypedefs = TRUE;
|
|
755
|
|
756 while (1)
|
|
757 {
|
|
758 int opt = getopt_long (argc, argv,
|
|
759 "-aCdDf:Il:o:r:RStTi:BuvxwVhH", longopts, 0);
|
|
760
|
|
761 if (opt == EOF)
|
|
762 break;
|
|
763
|
|
764 switch (opt)
|
|
765 {
|
|
766 case 0:
|
|
767 /* If getopt returns 0, then it has already processed a
|
|
768 long-named option. We should do nothing. */
|
|
769 break;
|
|
770
|
|
771 case 1:
|
|
772 /* This means that a filename has been seen. Record it. */
|
|
773 argbuffer[current_arg].arg_type = at_filename;
|
|
774 argbuffer[current_arg].what = optarg;
|
|
775 ++current_arg;
|
|
776 ++file_count;
|
|
777 break;
|
|
778
|
|
779 /* Common options. */
|
|
780 case 'a':
|
|
781 append_to_tagfile = TRUE;
|
|
782 break;
|
|
783 case 'C':
|
|
784 cplusplus = TRUE;
|
|
785 break;
|
|
786 case 'd':
|
|
787 constantypedefs = TRUE;
|
|
788 break;
|
|
789 case 'D':
|
|
790 constantypedefs = FALSE;
|
|
791 break;
|
|
792 case 'f': /* for compatibility with old makefiles */
|
|
793 case 'o':
|
|
794 if (tagfile)
|
|
795 {
|
|
796 fprintf (stderr, "%s: -%c option may only be given once.\n",
|
|
797 progname, opt);
|
|
798 goto usage;
|
|
799 }
|
|
800 tagfile = optarg;
|
|
801 break;
|
|
802 case 'I':
|
|
803 case 'S': /* for backward compatibility */
|
|
804 noindentypedefs = TRUE;
|
|
805 break;
|
|
806 case 'l':
|
|
807 argbuffer[current_arg].function = get_language_from_name (optarg);
|
|
808 if (argbuffer[current_arg].function == NULL)
|
|
809 {
|
|
810 fprintf (stderr, "%s: language \"%s\" not recognized.\n",
|
|
811 progname, optarg);
|
|
812 goto usage;
|
|
813 }
|
|
814 argbuffer[current_arg].arg_type = at_language;
|
|
815 ++current_arg;
|
|
816 break;
|
|
817 #ifdef ETAGS_REGEXPS
|
|
818 case 'r':
|
|
819 argbuffer[current_arg].arg_type = at_regexp;
|
|
820 argbuffer[current_arg].what = optarg;
|
|
821 ++current_arg;
|
|
822 break;
|
|
823 case 'R':
|
|
824 argbuffer[current_arg].arg_type = at_regexp;
|
|
825 argbuffer[current_arg].what = NULL;
|
|
826 ++current_arg;
|
|
827 break;
|
|
828 #endif /* ETAGS_REGEXPS */
|
|
829 case 'V':
|
|
830 print_version ();
|
|
831 break;
|
|
832 case 'h':
|
|
833 case 'H':
|
|
834 print_help ();
|
|
835 break;
|
|
836 case 't':
|
|
837 typedefs = TRUE;
|
|
838 break;
|
|
839 case 'T':
|
|
840 typedefs = typedefs_and_cplusplus = TRUE;
|
|
841 break;
|
|
842 #if (!CTAGS)
|
|
843 /* Etags options */
|
|
844 case 'i':
|
|
845 included_files[nincluded_files++] = optarg;
|
|
846 break;
|
|
847 #else /* CTAGS */
|
|
848 /* Ctags options. */
|
|
849 case 'B':
|
|
850 searchar = '?';
|
|
851 break;
|
|
852 case 'u':
|
|
853 update = TRUE;
|
|
854 break;
|
|
855 case 'v':
|
|
856 vgrind_style = TRUE;
|
|
857 /*FALLTHRU*/
|
|
858 case 'x':
|
|
859 cxref_style = TRUE;
|
|
860 break;
|
|
861 case 'w':
|
|
862 no_warnings = TRUE;
|
|
863 break;
|
|
864 #endif /* CTAGS */
|
|
865 default:
|
|
866 goto usage;
|
|
867 }
|
|
868 }
|
|
869
|
|
870 for (; optind < argc; ++optind)
|
|
871 {
|
|
872 argbuffer[current_arg].arg_type = at_filename;
|
|
873 argbuffer[current_arg].what = argv[optind];
|
|
874 ++current_arg;
|
|
875 ++file_count;
|
|
876 }
|
|
877
|
|
878 if (nincluded_files == 0 && file_count == 0)
|
|
879 {
|
|
880 fprintf (stderr, "%s: No input files specified.\n", progname);
|
|
881
|
|
882 usage:
|
|
883 fprintf (stderr, "\tTry `%s --help' for a complete list of options.\n",
|
|
884 progname);
|
|
885 exit (BAD);
|
|
886 }
|
|
887
|
|
888 if (tagfile == NULL)
|
|
889 {
|
|
890 tagfile = CTAGS ? (char *) "tags" : (char *) "TAGS";
|
|
891 }
|
|
892 cwd = etags_getcwd (); /* the current working directory */
|
|
893 strcat (cwd, "/");
|
|
894 if (streq (tagfile, "-"))
|
|
895 {
|
|
896 tagfiledir = cwd;
|
|
897 }
|
|
898 else
|
|
899 {
|
|
900 tagfiledir = absolute_dirname (tagfile, cwd);
|
|
901 }
|
|
902
|
|
903 init (); /* set up boolean "functions" */
|
|
904
|
|
905 initbuffer (&lb);
|
|
906 initbuffer (&token_name);
|
|
907 initbuffer (&lbs[0].lb);
|
|
908 initbuffer (&lbs[1].lb);
|
|
909 initbuffer (&filename_lb);
|
|
910
|
|
911 if (!CTAGS)
|
|
912 {
|
|
913 if (streq (tagfile, "-"))
|
|
914 tagf = stdout;
|
|
915 else
|
|
916 tagf = fopen (tagfile, append_to_tagfile ? "a" : "w");
|
|
917 if (tagf == NULL)
|
|
918 pfatal (tagfile);
|
|
919 }
|
|
920
|
|
921 /*
|
|
922 * Loop through files finding functions.
|
|
923 */
|
|
924 for (i = 0; i < current_arg; ++i)
|
|
925 {
|
|
926 switch (argbuffer[i].arg_type)
|
|
927 {
|
|
928 case at_language:
|
|
929 lang_func = argbuffer[i].function;
|
|
930 break;
|
|
931 #ifdef ETAGS_REGEXPS
|
|
932 case at_regexp:
|
|
933 add_regex (argbuffer[i].what);
|
|
934 break;
|
|
935 #endif
|
|
936 case at_filename:
|
|
937 #ifdef VMS
|
|
938 while ((this_file = gfnames (argbuffer[i].what, &got_err)) != NULL)
|
|
939 {
|
|
940 if (got_err)
|
|
941 {
|
|
942 error ("Can't find file %s\n", this_file);
|
|
943 argc--, argv++;
|
|
944 }
|
|
945 else
|
|
946 {
|
|
947 this_file = massage_name (this_file);
|
|
948 }
|
|
949 #else
|
|
950 this_file = argbuffer[i].what;
|
|
951 #endif
|
|
952 /* Input file named "-" means read file names from stdin
|
|
953 and use them. */
|
|
954 if (streq (this_file, "-"))
|
|
955 while (readline_internal (&filename_lb, stdin) > 0)
|
|
956 process_file (filename_lb.buffer);
|
|
957 else
|
|
958 process_file (this_file);
|
|
959 #ifdef VMS
|
|
960 }
|
|
961 #endif
|
|
962 break;
|
|
963 }
|
|
964 }
|
|
965
|
|
966 if (!CTAGS)
|
|
967 {
|
|
968 while (nincluded_files-- > 0)
|
|
969 fprintf (tagf, "\f\n%s,include\n", *included_files++);
|
|
970
|
|
971 fclose (tagf);
|
|
972 exit (GOOD);
|
|
973 }
|
|
974
|
|
975 /* If CTAGS, we are here. process_file did not write the tags yet,
|
|
976 because we want them ordered. Let's do it now. */
|
|
977 if (cxref_style)
|
|
978 {
|
|
979 tagf = fopen (tagfile, append_to_tagfile ? "a" : "w");
|
|
980 if (tagf == NULL)
|
|
981 pfatal (tagfile);
|
|
982 put_entries (head);
|
|
983 exit (GOOD);
|
|
984 }
|
|
985
|
|
986 if (update)
|
|
987 {
|
|
988 char cmd[BUFSIZ];
|
|
989 for (i = 0; i < current_arg; ++i)
|
|
990 {
|
|
991 if (argbuffer[i].arg_type != at_filename)
|
|
992 continue;
|
|
993 sprintf (cmd,
|
|
994 "mv %s OTAGS;fgrep -v '\t%s\t' OTAGS >%s;rm OTAGS",
|
|
995 tagfile, argbuffer[i].what, tagfile);
|
|
996 if (system (cmd) != GOOD)
|
|
997 fatal ("failed to execute shell command", 0);
|
|
998 }
|
|
999 append_to_tagfile = TRUE;
|
|
1000 }
|
|
1001
|
|
1002 tagf = fopen (tagfile, append_to_tagfile ? "a" : "w");
|
|
1003 if (tagf == NULL)
|
|
1004 pfatal (tagfile);
|
|
1005 put_entries (head);
|
|
1006 fclose (tagf);
|
|
1007
|
|
1008 if (update)
|
|
1009 {
|
|
1010 char cmd[BUFSIZ];
|
|
1011 sprintf (cmd, "sort %s -o %s", tagfile, tagfile);
|
|
1012 exit (system (cmd));
|
|
1013 }
|
|
1014 exit (GOOD);
|
|
1015 }
|
|
1016
|
|
1017
|
|
1018 /*
|
|
1019 * Return a Lang_function given the name.
|
|
1020 */
|
|
1021 Lang_function *
|
|
1022 get_language_from_name (char *name)
|
|
1023 {
|
|
1024 CONST struct lang_entry *lang;
|
|
1025
|
|
1026 if (name == NULL)
|
|
1027 return NULL;
|
|
1028 for (lang = lang_names; lang->name != NULL; lang++)
|
|
1029 {
|
|
1030 if (streq (name, lang->name))
|
|
1031 return lang->function;
|
|
1032 }
|
|
1033
|
|
1034 return NULL;
|
|
1035 }
|
|
1036
|
|
1037
|
|
1038 /*
|
|
1039 * Return a Lang_function given the interpreter name.
|
|
1040 */
|
|
1041 Lang_function *
|
|
1042 get_language_from_interpreter (char *interpreter)
|
|
1043 {
|
|
1044 CONST struct lang_entry *lang;
|
|
1045 CONST char **iname;
|
|
1046
|
|
1047 if (interpreter == NULL)
|
|
1048 return NULL;
|
|
1049 for (lang = lang_names; lang->name != NULL; lang++)
|
|
1050 if (lang->interpreters != NULL)
|
|
1051 for (iname = lang->interpreters; *iname != NULL; iname++)
|
|
1052 if (streq (*iname, interpreter))
|
|
1053 return lang->function;
|
|
1054
|
|
1055 return NULL;
|
|
1056 }
|
|
1057
|
|
1058
|
|
1059
|
|
1060 /*
|
|
1061 * Return a Lang_function given the file suffix.
|
|
1062 */
|
|
1063 Lang_function *
|
|
1064 get_language_from_suffix (CONST char *suffix)
|
|
1065 {
|
|
1066 CONST struct lang_entry *lang;
|
|
1067 CONST char **ext;
|
|
1068
|
|
1069 if (suffix == NULL)
|
|
1070 return NULL;
|
|
1071 for (lang = lang_names; lang->name != NULL; lang++)
|
|
1072 if (lang->suffixes != NULL)
|
|
1073 for (ext = lang->suffixes; *ext != NULL; ext++)
|
|
1074 if (streq (*ext, suffix))
|
|
1075 return lang->function;
|
|
1076
|
|
1077 return NULL;
|
|
1078 }
|
|
1079
|
|
1080
|
|
1081 /*
|
|
1082 * This routine is called on each file argument.
|
|
1083 */
|
|
1084 void
|
|
1085 process_file (CONST char *file)
|
|
1086 {
|
|
1087 struct stat stat_buf;
|
|
1088 FILE *inf;
|
|
1089
|
|
1090 if (stat (file, &stat_buf) == 0 && !S_ISREG (stat_buf.st_mode))
|
|
1091 {
|
|
1092 fprintf (stderr, "Skipping %s: it is not a regular file.\n", file);
|
|
1093 return;
|
|
1094 }
|
|
1095 if (streq (file, tagfile) && !streq (tagfile, "-"))
|
|
1096 {
|
|
1097 fprintf (stderr, "Skipping inclusion of %s in self.\n", file);
|
|
1098 return;
|
|
1099 }
|
|
1100 inf = fopen (file, "r");
|
|
1101 if (inf == NULL)
|
|
1102 {
|
|
1103 perror (file);
|
|
1104 return;
|
|
1105 }
|
|
1106
|
|
1107 find_entries (file, inf);
|
|
1108
|
|
1109 if (!CTAGS)
|
|
1110 {
|
|
1111 char *filename;
|
|
1112
|
|
1113 if (absolutefn (file))
|
|
1114 {
|
|
1115 /* file is an absolute filename. Canonicalise it. */
|
|
1116 filename = absolute_filename (file, cwd);
|
|
1117 }
|
|
1118 else
|
|
1119 {
|
|
1120 /* file is a filename relative to cwd. Make it relative
|
|
1121 to the directory of the tags file. */
|
|
1122 filename = relative_filename (file, tagfiledir);
|
|
1123 }
|
|
1124 fprintf (tagf, "\f\n%s,%d\n", filename, total_size_of_entries (head));
|
|
1125 free (filename);
|
|
1126 put_entries (head);
|
|
1127 free_tree (head);
|
|
1128 head = NULL;
|
|
1129 }
|
|
1130 }
|
|
1131
|
|
1132 /*
|
|
1133 * This routine sets up the boolean pseudo-functions which work
|
|
1134 * by setting boolean flags dependent upon the corresponding character
|
|
1135 * Every char which is NOT in that string is not a white char. Therefore,
|
|
1136 * all of the array "_wht" is set to FALSE, and then the elements
|
|
1137 * subscripted by the chars in "white" are set to TRUE. Thus "_wht"
|
|
1138 * of a char is TRUE if it is the string "white", else FALSE.
|
|
1139 */
|
|
1140 void
|
|
1141 init (void)
|
|
1142 {
|
|
1143 register CONST char *sp;
|
|
1144 register int i;
|
|
1145
|
|
1146 for (i = 0; i < 0177; i++)
|
|
1147 _wht[i] = _etk[i] = _itk[i] = _btk[i] = FALSE;
|
|
1148 for (sp = white; *sp; sp++)
|
|
1149 _wht[(unsigned int) *sp] = TRUE;
|
|
1150 for (sp = endtk; *sp; sp++)
|
|
1151 _etk[(unsigned int) *sp] = TRUE;
|
|
1152 for (sp = intk; *sp; sp++)
|
|
1153 _itk[(unsigned int) *sp] = TRUE;
|
|
1154 for (sp = begtk; *sp; sp++)
|
|
1155 _btk[(unsigned int) *sp] = TRUE;
|
|
1156 _wht[0] = _wht['\n'];
|
|
1157 _etk[0] = _etk['\n'];
|
|
1158 _btk[0] = _btk['\n'];
|
|
1159 _itk[0] = _itk['\n'];
|
|
1160 }
|
|
1161
|
|
1162 /*
|
|
1163 * This routine opens the specified file and calls the function
|
|
1164 * which finds the function and type definitions.
|
|
1165 */
|
|
1166 void
|
|
1167 find_entries (CONST char *file, FILE *inf)
|
|
1168 {
|
|
1169 char *cp;
|
|
1170 Lang_function *function;
|
|
1171 NODE *old_last_node;
|
|
1172 extern NODE *last_node;
|
|
1173
|
|
1174 /* Memory leakage here: the memory block pointed by curfile is never
|
|
1175 released. The amount of memory leaked here is the sum of the
|
|
1176 lengths of the input file names. */
|
|
1177 curfile = savestr (file);
|
|
1178
|
|
1179 /* If user specified a language, use it. */
|
|
1180 function = lang_func;
|
|
1181 if (function != NULL)
|
|
1182 {
|
|
1183 function (inf);
|
|
1184 fclose (inf);
|
|
1185 return;
|
|
1186 }
|
|
1187
|
|
1188 cp = etags_strrchr (file, '.');
|
|
1189 if (cp != NULL)
|
|
1190 {
|
|
1191 cp += 1;
|
|
1192 function = get_language_from_suffix (cp);
|
|
1193 if (function != NULL)
|
|
1194 {
|
|
1195 function (inf);
|
|
1196 fclose (inf);
|
|
1197 return;
|
|
1198 }
|
|
1199 }
|
|
1200
|
|
1201 /* Look for sharp-bang as the first two characters. */
|
|
1202 if (readline_internal (&lb, inf) > 2
|
|
1203 && lb.buffer[0] == '#'
|
|
1204 && lb.buffer[1] == '!')
|
|
1205 {
|
|
1206 char *lp;
|
|
1207
|
|
1208 /* Set lp to point at the first char after the last slash in the
|
|
1209 line or, if no slashes, at the first nonblank. Then set cp to
|
|
1210 the first successive blank and terminate the string. */
|
|
1211 lp = etags_strrchr (lb.buffer+2, '/');
|
|
1212 if (lp != NULL)
|
|
1213 lp += 1;
|
|
1214 else
|
|
1215 for (lp = lb.buffer+2; *lp != '\0' && isspace (*lp); lp++)
|
|
1216 continue;
|
|
1217 for (cp = lp; *cp != '\0' && !isspace (*cp); cp++)
|
|
1218 continue;
|
|
1219 *cp = '\0';
|
|
1220
|
|
1221 if (strlen (lp) > 0)
|
|
1222 {
|
|
1223 function = get_language_from_interpreter (lp);
|
|
1224 if (function != NULL)
|
|
1225 {
|
|
1226 function (inf);
|
|
1227 fclose (inf);
|
|
1228 return;
|
|
1229 }
|
|
1230 }
|
|
1231 }
|
|
1232 rewind (inf);
|
|
1233
|
|
1234 /* Try Fortran. */
|
|
1235 old_last_node = last_node;
|
|
1236 Fortran_functions (inf);
|
|
1237
|
|
1238 /* No Fortran entries found. Try C. */
|
|
1239 if (old_last_node == last_node)
|
|
1240 {
|
|
1241 rewind (inf);
|
|
1242 default_C_entries (inf);
|
|
1243 }
|
|
1244 fclose (inf);
|
|
1245 return;
|
|
1246 }
|
|
1247
|
|
1248 /* Record a tag. */
|
|
1249 #if 0
|
|
1250 char *name; /* tag name, if different from definition */
|
|
1251 logical is_func; /* tag is a function */
|
|
1252 char *linestart; /* start of the line where tag is */
|
|
1253 int linelen; /* length of the line where tag is */
|
|
1254 int lno; /* line number */
|
|
1255 long cno; /* character number */
|
|
1256 #endif
|
|
1257 void
|
|
1258 pfnote (char *name, logical is_func, char *linestart,
|
|
1259 int linelen, int lno, long cno)
|
|
1260 {
|
|
1261 register NODE *np = xnew (1, NODE);
|
|
1262
|
|
1263 /* If ctags mode, change name "main" to M<thisfilename>. */
|
|
1264 if (CTAGS && !cxref_style && streq (name, "main"))
|
|
1265 {
|
|
1266 register char *fp = etags_strrchr (curfile, '/');
|
|
1267 np->name = concat ("M", fp == 0 ? curfile : fp + 1, "");
|
|
1268 fp = etags_strrchr (np->name, '.');
|
|
1269 if (fp && fp[1] != '\0' && fp[2] == '\0')
|
|
1270 fp[0] = 0;
|
|
1271 }
|
|
1272 else
|
|
1273 np->name = name;
|
|
1274 np->been_warned = FALSE;
|
|
1275 np->file = curfile;
|
|
1276 np->is_func = is_func;
|
|
1277 np->lno = lno;
|
|
1278 /* Our char numbers are 0-base, because of C language tradition?
|
|
1279 ctags compatibility? old versions compatibility? I don't know.
|
|
1280 Anyway, since emacs's are 1-base we espect etags.el to take care
|
|
1281 of the difference. If we wanted to have 1-based numbers, we would
|
|
1282 uncomment the +1 below. */
|
|
1283 np->cno = cno /* + 1 */ ;
|
|
1284 np->left = np->right = NULL;
|
|
1285 np->pat = savenstr (linestart, ((CTAGS && !cxref_style) ? 50 : linelen));
|
|
1286
|
|
1287 add_node (np, &head);
|
|
1288 }
|
|
1289
|
|
1290 /*
|
|
1291 * free_tree ()
|
|
1292 * recurse on left children, iterate on right children.
|
|
1293 */
|
|
1294 void
|
|
1295 free_tree (NODE *node)
|
|
1296 {
|
|
1297 while (node)
|
|
1298 {
|
|
1299 register NODE *node_right = node->right;
|
|
1300 free_tree (node->left);
|
|
1301 if (node->name != NULL)
|
|
1302 free (node->name);
|
|
1303 free (node->pat);
|
|
1304 free ((char *) node);
|
|
1305 node = node_right;
|
|
1306 }
|
|
1307 }
|
|
1308
|
|
1309 /*
|
|
1310 * add_node ()
|
|
1311 * Adds a node to the tree of nodes. In etags mode, we don't keep
|
|
1312 * it sorted; we just keep a linear list. In ctags mode, maintain
|
|
1313 * an ordered tree, with no attempt at balancing.
|
|
1314 *
|
|
1315 * add_node is the only function allowed to add nodes, so it can
|
|
1316 * maintain state.
|
|
1317 */
|
|
1318 NODE *last_node = NULL;
|
|
1319 void
|
|
1320 add_node (NODE *node, NODE **cur_node_p)
|
|
1321 {
|
|
1322 register int dif;
|
|
1323 register NODE *cur_node = *cur_node_p;
|
|
1324
|
|
1325 if (cur_node == NULL)
|
|
1326 {
|
|
1327 *cur_node_p = node;
|
|
1328 last_node = node;
|
|
1329 return;
|
|
1330 }
|
|
1331
|
|
1332 if (!CTAGS)
|
|
1333 {
|
|
1334 /* Etags Mode */
|
|
1335 if (last_node == NULL)
|
|
1336 fatal ("internal error in add_node", 0);
|
|
1337 last_node->right = node;
|
|
1338 last_node = node;
|
|
1339 }
|
|
1340 else
|
|
1341 {
|
|
1342 /* Ctags Mode */
|
|
1343 dif = strcmp (node->name, cur_node->name);
|
|
1344
|
|
1345 /*
|
|
1346 * If this tag name matches an existing one, then
|
|
1347 * do not add the node, but maybe print a warning.
|
|
1348 */
|
|
1349 if (!dif)
|
|
1350 {
|
|
1351 if (streq (node->file, cur_node->file))
|
|
1352 {
|
|
1353 if (!no_warnings)
|
|
1354 {
|
|
1355 fprintf (stderr, "Duplicate entry in file %s, line %d: %s\n",
|
|
1356 node->file, lineno, node->name);
|
|
1357 fprintf (stderr, "Second entry ignored\n");
|
|
1358 }
|
|
1359 }
|
|
1360 else if (!cur_node->been_warned && !no_warnings)
|
|
1361 {
|
|
1362 fprintf
|
|
1363 (stderr,
|
|
1364 "Duplicate entry in files %s and %s: %s (Warning only)\n",
|
|
1365 node->file, cur_node->file, node->name);
|
|
1366 cur_node->been_warned = TRUE;
|
|
1367 }
|
|
1368 return;
|
|
1369 }
|
|
1370
|
|
1371 /* Actually add the node */
|
|
1372 add_node (node, dif < 0 ? &cur_node->left : &cur_node->right);
|
|
1373 }
|
|
1374 }
|
|
1375
|
|
1376 void
|
|
1377 put_entries (NODE *node)
|
|
1378 {
|
|
1379 register char *sp;
|
|
1380
|
|
1381 if (node == NULL)
|
|
1382 return;
|
|
1383
|
|
1384 /* Output subentries that precede this one */
|
|
1385 put_entries (node->left);
|
|
1386
|
|
1387 /* Output this entry */
|
|
1388
|
|
1389 if (!CTAGS)
|
|
1390 {
|
|
1391 if (node->name != NULL)
|
|
1392 fprintf (tagf, "%s\177%s\001%ld,%ld\n",
|
|
1393 node->pat, node->name, node->lno, node->cno);
|
|
1394 else
|
|
1395 fprintf (tagf, "%s\177%ld,%ld\n",
|
|
1396 node->pat, node->lno, node->cno);
|
|
1397 }
|
|
1398 else if (!cxref_style)
|
|
1399 {
|
|
1400 fprintf (tagf, "%s\t%s\t",
|
|
1401 node->name, node->file);
|
|
1402
|
|
1403 if (node->is_func)
|
|
1404 { /* a function */
|
|
1405 putc (searchar, tagf);
|
|
1406 putc ('^', tagf);
|
|
1407
|
|
1408 for (sp = node->pat; *sp; sp++)
|
|
1409 {
|
|
1410 if (*sp == '\\' || *sp == searchar)
|
|
1411 putc ('\\', tagf);
|
|
1412 putc (*sp, tagf);
|
|
1413 }
|
|
1414 putc (searchar, tagf);
|
|
1415 }
|
|
1416 else
|
|
1417 { /* a typedef; text pattern inadequate */
|
|
1418 fprintf (tagf, "%ld", node->lno);
|
|
1419 }
|
|
1420 putc ('\n', tagf);
|
|
1421 }
|
|
1422 else if (vgrind_style)
|
|
1423 fprintf (stdout, "%s %s %ld\n",
|
|
1424 node->name, node->file, (node->lno + 63) / 64);
|
|
1425 else
|
|
1426 fprintf (stdout, "%-16s %3ld %-16s %s\n",
|
|
1427 node->name, node->lno, node->file, node->pat);
|
|
1428
|
|
1429 /* Output subentries that follow this one */
|
|
1430 put_entries (node->right);
|
|
1431 }
|
|
1432
|
|
1433 /* Length of a number's decimal representation. */
|
|
1434 static int
|
|
1435 number_len (long num)
|
|
1436 {
|
|
1437 int len = 0;
|
|
1438 if (!num)
|
|
1439 return 1;
|
|
1440 for (; num; num /= 10)
|
|
1441 ++len;
|
|
1442 return len;
|
|
1443 }
|
|
1444
|
|
1445 /*
|
|
1446 * Return total number of characters that put_entries will output for
|
|
1447 * the nodes in the subtree of the specified node. Works only if
|
|
1448 * we are not ctags, but called only in that case. This count
|
|
1449 * is irrelevant with the new tags.el, but is still supplied for
|
|
1450 * backward compatibility.
|
|
1451 */
|
|
1452 int
|
|
1453 total_size_of_entries (NODE *node)
|
|
1454 {
|
|
1455 register int total;
|
|
1456
|
|
1457 if (node == NULL)
|
|
1458 return 0;
|
|
1459
|
|
1460 total = 0;
|
|
1461 for (; node; node = node->right)
|
|
1462 {
|
|
1463 /* Count left subentries. */
|
|
1464 total += total_size_of_entries (node->left);
|
|
1465
|
|
1466 /* Count this entry */
|
|
1467 total += strlen (node->pat) + 1;
|
|
1468 total += number_len ((long) node->lno) + 1 + number_len (node->cno) + 1;
|
|
1469 if (node->name != NULL)
|
|
1470 total += 1 + strlen (node->name); /* \001name */
|
|
1471 }
|
|
1472
|
|
1473 return total;
|
|
1474 }
|
|
1475
|
|
1476 /*
|
|
1477 * The C symbol tables.
|
|
1478 */
|
|
1479 enum sym_type
|
|
1480 {
|
|
1481 st_none, st_C_struct, st_C_enum, st_C_define, st_C_typedef, st_C_typespec
|
|
1482 };
|
|
1483
|
|
1484 /* Feed stuff between (but not including) %[ and %] lines to:
|
|
1485 gperf -c -k1,3 -o -p -r -t
|
|
1486 %[
|
|
1487 struct C_stab_entry { CONST char *name; int c_ext; enum sym_type type; }
|
|
1488 %%
|
|
1489 class, C_PLPL, st_C_struct
|
|
1490 domain, C_STAR, st_C_struct
|
|
1491 union, 0, st_C_struct
|
|
1492 struct, 0, st_C_struct
|
|
1493 enum, 0, st_C_enum
|
|
1494 typedef, 0, st_C_typedef
|
|
1495 define, 0, st_C_define
|
|
1496 long, 0, st_C_typespec
|
|
1497 short, 0, st_C_typespec
|
|
1498 int, 0, st_C_typespec
|
|
1499 char, 0, st_C_typespec
|
|
1500 float, 0, st_C_typespec
|
|
1501 double, 0, st_C_typespec
|
|
1502 signed, 0, st_C_typespec
|
|
1503 unsigned, 0, st_C_typespec
|
|
1504 auto, 0, st_C_typespec
|
|
1505 void, 0, st_C_typespec
|
|
1506 extern, 0, st_C_typespec
|
|
1507 static, 0, st_C_typespec
|
|
1508 const, 0, st_C_typespec
|
|
1509 volatile, 0, st_C_typespec
|
|
1510 %]
|
|
1511 and replace lines between %< and %> with its output. */
|
|
1512 /*%<*/
|
|
1513 /* C code produced by gperf version 1.8.1 (K&R C version) */
|
|
1514 /* Command-line: gperf -c -k1,3 -o -p -r -t */
|
|
1515
|
|
1516
|
|
1517 struct C_stab_entry { CONST char *name; int c_ext; enum sym_type type; };
|
|
1518
|
|
1519 #define MIN_WORD_LENGTH 3
|
|
1520 #define MAX_WORD_LENGTH 8
|
|
1521 #define MIN_HASH_VALUE 10
|
|
1522 #define MAX_HASH_VALUE 62
|
|
1523 /*
|
|
1524 21 keywords
|
|
1525 53 is the maximum key range
|
|
1526 */
|
|
1527
|
|
1528 static int
|
|
1529 hash (CONST char *str, int len)
|
|
1530 {
|
|
1531 static unsigned char hash_table[] =
|
|
1532 {
|
|
1533 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
|
1534 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
|
1535 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
|
1536 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
|
1537 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
|
1538 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
|
1539 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
|
1540 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
|
1541 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
|
|
1542 62, 62, 62, 62, 62, 62, 62, 2, 62, 7,
|
|
1543 6, 9, 15, 30, 62, 24, 62, 62, 1, 24,
|
|
1544 7, 27, 13, 62, 19, 26, 18, 27, 1, 62,
|
|
1545 62, 62, 62, 62, 62, 62, 62, 62,
|
|
1546 };
|
|
1547 return len + hash_table[(int) str[2]] + hash_table[(int) str[0]];
|
|
1548 }
|
|
1549
|
|
1550 static struct C_stab_entry *
|
|
1551 in_word_set (CONST char *str, int len)
|
|
1552 {
|
|
1553
|
|
1554 static struct C_stab_entry wordlist[] =
|
|
1555 {
|
|
1556 {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
|
1557 {"",},
|
|
1558 {"volatile", 0, st_C_typespec},
|
|
1559 {"",},
|
|
1560 {"long", 0, st_C_typespec},
|
|
1561 {"char", 0, st_C_typespec},
|
|
1562 {"class", C_PLPL, st_C_struct},
|
|
1563 {"",}, {"",}, {"",}, {"",},
|
|
1564 {"const", 0, st_C_typespec},
|
|
1565 {"",}, {"",}, {"",}, {"",},
|
|
1566 {"auto", 0, st_C_typespec},
|
|
1567 {"",}, {"",},
|
|
1568 {"define", 0, st_C_define},
|
|
1569 {"",},
|
|
1570 {"void", 0, st_C_typespec},
|
|
1571 {"",}, {"",}, {"",},
|
|
1572 {"extern", 0, st_C_typespec},
|
|
1573 {"static", 0, st_C_typespec},
|
|
1574 {"",},
|
|
1575 {"domain", C_STAR, st_C_struct},
|
|
1576 {"",},
|
|
1577 {"typedef", 0, st_C_typedef},
|
|
1578 {"double", 0, st_C_typespec},
|
|
1579 {"enum", 0, st_C_enum},
|
|
1580 {"",}, {"",}, {"",}, {"",},
|
|
1581 {"int", 0, st_C_typespec},
|
|
1582 {"",},
|
|
1583 {"float", 0, st_C_typespec},
|
|
1584 {"",}, {"",}, {"",},
|
|
1585 {"struct", 0, st_C_struct},
|
|
1586 {"",}, {"",}, {"",}, {"",},
|
|
1587 {"union", 0, st_C_struct},
|
|
1588 {"",},
|
|
1589 {"short", 0, st_C_typespec},
|
|
1590 {"",}, {"",},
|
|
1591 {"unsigned", 0, st_C_typespec},
|
|
1592 {"signed", 0, st_C_typespec},
|
|
1593 };
|
|
1594
|
|
1595 if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
|
|
1596 {
|
|
1597 register int key = hash (str, len);
|
|
1598
|
|
1599 if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)
|
|
1600 {
|
|
1601 register CONST char *s = wordlist[key].name;
|
|
1602
|
|
1603 if (*s == *str && strneq (str + 1, s + 1, len - 1))
|
|
1604 return &wordlist[key];
|
|
1605 }
|
|
1606 }
|
|
1607 return 0;
|
|
1608 }
|
|
1609 /*%>*/
|
|
1610
|
|
1611 static enum sym_type
|
|
1612 C_symtype (char *str, int len, int c_ext)
|
|
1613 {
|
|
1614 register struct C_stab_entry *se = in_word_set(str, len);
|
|
1615
|
|
1616 if (se == NULL || (se->c_ext && !(c_ext & se->c_ext)))
|
|
1617 return st_none;
|
|
1618 return se->type;
|
|
1619 }
|
|
1620
|
|
1621 /*
|
|
1622 * C functions are recognized using a simple finite automaton.
|
|
1623 * funcdef is its state variable.
|
|
1624 */
|
|
1625 typedef enum
|
|
1626 {
|
|
1627 fnone, /* nothing seen */
|
|
1628 ftagseen, /* function-like tag seen */
|
|
1629 fstartlist, /* just after open parenthesis */
|
|
1630 finlist, /* in parameter list */
|
|
1631 flistseen, /* after parameter list */
|
|
1632 fignore /* before open brace */
|
|
1633 } FUNCST;
|
|
1634 FUNCST funcdef;
|
|
1635
|
|
1636
|
|
1637 /*
|
|
1638 * typedefs are recognized using a simple finite automaton.
|
|
1639 * typeddef is its state variable.
|
|
1640 */
|
|
1641 typedef enum
|
|
1642 {
|
|
1643 tnone, /* nothing seen */
|
|
1644 ttypedseen, /* typedef keyword seen */
|
|
1645 tinbody, /* inside typedef body */
|
|
1646 tend, /* just before typedef tag */
|
|
1647 tignore /* junk after typedef tag */
|
|
1648 } TYPEDST;
|
|
1649 TYPEDST typdef;
|
|
1650
|
|
1651
|
|
1652 /*
|
|
1653 * struct-like structures (enum, struct and union) are recognized
|
|
1654 * using another simple finite automaton. `structdef' is its state
|
|
1655 * variable.
|
|
1656 */
|
|
1657 typedef enum
|
|
1658 {
|
|
1659 snone, /* nothing seen yet */
|
|
1660 skeyseen, /* struct-like keyword seen */
|
|
1661 stagseen, /* struct-like tag seen */
|
|
1662 scolonseen, /* colon seen after struct-like tag */
|
|
1663 sinbody /* in struct body: recognize member func defs*/
|
|
1664 } STRUCTST;
|
|
1665 STRUCTST structdef;
|
|
1666
|
|
1667 /*
|
|
1668 * When structdef is stagseen, scolonseen, or sinbody, structtag is the
|
|
1669 * struct tag, and structtype is the type of the preceding struct-like
|
|
1670 * keyword.
|
|
1671 */
|
|
1672 CONST char *structtag = "<uninited>";
|
|
1673 enum sym_type structtype;
|
|
1674
|
|
1675 /*
|
|
1676 * Yet another little state machine to deal with preprocessor lines.
|
|
1677 */
|
|
1678 typedef enum
|
|
1679 {
|
|
1680 dnone, /* nothing seen */
|
|
1681 dsharpseen, /* '#' seen as first char on line */
|
|
1682 ddefineseen, /* '#' and 'define' seen */
|
|
1683 dignorerest /* ignore rest of line */
|
|
1684 } DEFINEST;
|
|
1685 DEFINEST definedef;
|
|
1686
|
|
1687 /*
|
|
1688 * Set this to TRUE, and the next token considered is called a function.
|
|
1689 * Used only for GNU emacs's function-defining macros.
|
|
1690 */
|
|
1691 logical next_token_is_func;
|
|
1692
|
|
1693 /*
|
|
1694 * TRUE in the rules part of a yacc file, FALSE outside (parse as C).
|
|
1695 */
|
|
1696 logical yacc_rules;
|
|
1697
|
|
1698 /*
|
|
1699 * consider_token ()
|
|
1700 * checks to see if the current token is at the start of a
|
|
1701 * function, or corresponds to a typedef, or is a struct/union/enum
|
|
1702 * tag.
|
|
1703 *
|
|
1704 * *IS_FUNC gets TRUE iff the token is a function or macro with args.
|
|
1705 * C_EXT is which language we are looking at.
|
|
1706 *
|
|
1707 * In the future we will need some way to adjust where the end of
|
|
1708 * the token is; for instance, implementing the C++ keyword
|
|
1709 * `operator' properly will adjust the end of the token to be after
|
|
1710 * whatever follows `operator'.
|
|
1711 *
|
|
1712 * Globals
|
|
1713 * funcdef IN OUT
|
|
1714 * structdef IN OUT
|
|
1715 * definedef IN OUT
|
|
1716 * typdef IN OUT
|
|
1717 * next_token_is_func IN OUT
|
|
1718 */
|
|
1719
|
|
1720 #if 0
|
|
1721 register char *str; /* IN: token pointer */
|
|
1722 register int len; /* IN: token length */
|
|
1723 register char c; /* IN: first char after the token */
|
|
1724 int c_ext; /* IN: C extensions mask */
|
|
1725 int cblev; /* IN: curly brace level */
|
|
1726 logical *is_func; /* OUT: function found */
|
|
1727 #endif
|
|
1728 static logical
|
|
1729 consider_token (char *str, int len, char c, int c_ext, int cblev,
|
|
1730 logical *is_func)
|
|
1731 {
|
|
1732 enum sym_type toktype = C_symtype (str, len, c_ext);
|
|
1733
|
|
1734 /*
|
|
1735 * Advance the definedef state machine.
|
|
1736 */
|
|
1737 switch (definedef)
|
|
1738 {
|
|
1739 case dnone:
|
|
1740 /* We're not on a preprocessor line. */
|
|
1741 break;
|
|
1742 case dsharpseen:
|
|
1743 if (toktype == st_C_define)
|
|
1744 {
|
|
1745 definedef = ddefineseen;
|
|
1746 }
|
|
1747 else
|
|
1748 {
|
|
1749 definedef = dignorerest;
|
|
1750 }
|
|
1751 return FALSE;
|
|
1752 case ddefineseen:
|
|
1753 /*
|
|
1754 * Make a tag for any macro, unless it is a constant
|
|
1755 * and constantypedefs is FALSE.
|
|
1756 */
|
|
1757 definedef = dignorerest;
|
|
1758 *is_func = (c == '(');
|
|
1759 if (!*is_func && !constantypedefs)
|
|
1760 return FALSE;
|
|
1761 else
|
|
1762 return TRUE;
|
|
1763 case dignorerest:
|
|
1764 return FALSE;
|
|
1765 default:
|
|
1766 error ("internal error: definedef value.", 0);
|
|
1767 }
|
|
1768
|
|
1769 /*
|
|
1770 * Now typedefs
|
|
1771 */
|
|
1772 switch (typdef)
|
|
1773 {
|
|
1774 case tnone:
|
|
1775 if (toktype == st_C_typedef)
|
|
1776 {
|
|
1777 if (typedefs)
|
|
1778 typdef = ttypedseen;
|
|
1779 funcdef = fnone;
|
|
1780 return FALSE;
|
|
1781 }
|
|
1782 break;
|
|
1783 case ttypedseen:
|
|
1784 switch (toktype)
|
|
1785 {
|
|
1786 case st_none:
|
|
1787 case st_C_typespec:
|
|
1788 typdef = tend;
|
|
1789 break;
|
|
1790 case st_C_struct:
|
|
1791 case st_C_enum:
|
|
1792 break;
|
|
1793 default:
|
|
1794 break;
|
|
1795 }
|
|
1796 /* Do not return here, so the structdef stuff has a chance. */
|
|
1797 break;
|
|
1798 case tend:
|
|
1799 switch (toktype)
|
|
1800 {
|
|
1801 case st_C_typespec:
|
|
1802 case st_C_struct:
|
|
1803 case st_C_enum:
|
|
1804 return FALSE;
|
|
1805 default:
|
|
1806 break;
|
|
1807 }
|
|
1808 return TRUE;
|
|
1809 default:
|
|
1810 break;
|
|
1811 }
|
|
1812
|
|
1813 /*
|
|
1814 * This structdef business is currently only invoked when cblev==0.
|
|
1815 * It should be recursively invoked whatever the curly brace level,
|
|
1816 * and a stack of states kept, to allow for definitions of structs
|
|
1817 * within structs.
|
|
1818 *
|
|
1819 * This structdef business is NOT invoked when we are ctags and the
|
|
1820 * file is plain C. This is because a struct tag may have the same
|
|
1821 * name as another tag, and this loses with ctags.
|
|
1822 *
|
|
1823 * This if statement deals with the typdef state machine as
|
|
1824 * follows: if typdef==ttypedseen and token is struct/union/class/enum,
|
|
1825 * return FALSE. All the other code here is for the structdef
|
|
1826 * state machine.
|
|
1827 */
|
|
1828 switch (toktype)
|
|
1829 {
|
|
1830 case st_C_struct:
|
|
1831 case st_C_enum:
|
|
1832 if (typdef == ttypedseen
|
|
1833 || (typedefs_and_cplusplus && cblev == 0 && structdef == snone))
|
|
1834 {
|
|
1835 structdef = skeyseen;
|
|
1836 structtype = toktype;
|
|
1837 }
|
|
1838 return FALSE;
|
|
1839 default:
|
|
1840 break;
|
|
1841 }
|
|
1842 if (structdef == skeyseen)
|
|
1843 {
|
|
1844 /* Save the tag for struct/union/class, for functions that may be
|
|
1845 defined inside. */
|
|
1846 if (structtype == st_C_struct)
|
|
1847 structtag = savenstr (str, len);
|
|
1848 else
|
|
1849 structtag = "<enum>";
|
|
1850 structdef = stagseen;
|
|
1851 return TRUE;
|
|
1852 }
|
|
1853
|
|
1854 /* Avoid entering funcdef stuff if typdef is going on. */
|
|
1855 if (typdef != tnone)
|
|
1856 {
|
|
1857 definedef = dnone;
|
|
1858 return FALSE;
|
|
1859 }
|
|
1860
|
|
1861 /* Detect GNU macros. */
|
|
1862 if (definedef == dnone)
|
|
1863 if (strneq (str, "DEFUN", len) /* Used in emacs */
|
|
1864 #if FALSE
|
|
1865 These are defined inside C functions, so currently they
|
|
1866 are not met anyway.
|
|
1867 || strneq (str, "EXFUN", len) /* Used in glibc */
|
|
1868 || strneq (str, "DEFVAR_", 7) /* Used in emacs */
|
|
1869 #endif
|
|
1870 || strneq (str, "SYSCALL", len) /* Used in glibc (mach) */
|
|
1871 || strneq (str, "ENTRY", len) /* Used in glibc */
|
|
1872 || strneq (str, "PSEUDO", len)) /* Used in glibc */
|
|
1873
|
|
1874 {
|
|
1875 next_token_is_func = TRUE;
|
|
1876 return FALSE;
|
|
1877 }
|
|
1878 if (next_token_is_func)
|
|
1879 {
|
|
1880 next_token_is_func = FALSE;
|
|
1881 funcdef = fignore;
|
|
1882 *is_func = TRUE;
|
|
1883 return TRUE;
|
|
1884 }
|
|
1885
|
|
1886 /* A function? */
|
|
1887 switch (toktype)
|
|
1888 {
|
|
1889 case st_C_typespec:
|
|
1890 if (funcdef != finlist && funcdef != fignore)
|
|
1891 funcdef = fnone; /* should be useless */
|
|
1892 return FALSE;
|
|
1893 default:
|
|
1894 if (funcdef == fnone)
|
|
1895 {
|
|
1896 funcdef = ftagseen;
|
|
1897 *is_func = TRUE;
|
|
1898 return TRUE;
|
|
1899 }
|
|
1900 }
|
|
1901
|
|
1902 return FALSE;
|
|
1903 }
|
|
1904
|
|
1905 /*
|
|
1906 * C_entries ()
|
|
1907 * This routine finds functions, typedefs, #define's and
|
|
1908 * struct/union/enum definitions in C syntax and adds them
|
|
1909 * to the list.
|
|
1910 */
|
|
1911 typedef struct
|
|
1912 {
|
|
1913 logical valid;
|
|
1914 char *str;
|
|
1915 logical named;
|
|
1916 int linelen;
|
|
1917 int lineno;
|
|
1918 long linepos;
|
|
1919 char *buffer;
|
|
1920 } TOKEN;
|
|
1921
|
|
1922 #define current_lb_is_new (newndx == curndx)
|
|
1923 #define switch_line_buffers() (curndx = 1 - curndx)
|
|
1924
|
|
1925 #define curlb (lbs[curndx].lb)
|
|
1926 #define othlb (lbs[1-curndx].lb)
|
|
1927 #define newlb (lbs[newndx].lb)
|
|
1928 #define curlinepos (lbs[curndx].linepos)
|
|
1929 #define othlinepos (lbs[1-curndx].linepos)
|
|
1930 #define newlinepos (lbs[newndx].linepos)
|
|
1931
|
|
1932 #define CNL_SAVE_DEFINEDEF \
|
|
1933 do { \
|
|
1934 curlinepos = charno; \
|
|
1935 lineno++; \
|
|
1936 charno += readline (&curlb, inf); \
|
|
1937 lp = curlb.buffer; \
|
|
1938 quotednl = FALSE; \
|
|
1939 newndx = curndx; \
|
|
1940 } while (0)
|
|
1941
|
|
1942 #define CNL \
|
|
1943 do { \
|
|
1944 CNL_SAVE_DEFINEDEF; \
|
|
1945 if (savetok.valid) \
|
|
1946 { \
|
|
1947 tok = savetok; \
|
|
1948 savetok.valid = FALSE; \
|
|
1949 } \
|
|
1950 definedef = dnone; \
|
|
1951 } while (0)
|
|
1952
|
|
1953 #define make_tag(isfun) do \
|
|
1954 { \
|
|
1955 if (tok.valid) \
|
|
1956 { \
|
|
1957 char *name = NULL; \
|
|
1958 if (tok.named) \
|
|
1959 name = savestr (token_name.buffer); \
|
|
1960 pfnote (name, isfun, tok.buffer, tok.linelen, tok.lineno, tok.linepos); \
|
|
1961 } \
|
|
1962 else if (DEBUG) abort (); \
|
|
1963 tok.valid = FALSE; \
|
|
1964 } while (0)
|
|
1965
|
|
1966 #if 0
|
|
1967 int c_ext; /* extension of C */
|
|
1968 FILE *inf; /* input file */
|
|
1969 #endif
|
|
1970 void
|
|
1971 C_entries (int c_ext, FILE *inf)
|
|
1972 {
|
|
1973 register char c; /* latest char read; '\0' for end of line */
|
|
1974 register char *lp; /* pointer one beyond the character `c' */
|
|
1975 int curndx, newndx; /* indices for current and new lb */
|
|
1976 TOKEN tok; /* latest token read */
|
|
1977 register int tokoff = 0; /* offset in line of start of current token */
|
|
1978 register int toklen = 0; /* length of current token */
|
|
1979 int cblev; /* current curly brace level */
|
|
1980 int parlev; /* current parenthesis level */
|
|
1981 logical incomm, inquote, inchar, quotednl, midtoken;
|
|
1982 logical cplpl;
|
|
1983 TOKEN savetok; /* token saved during preprocessor handling */
|
|
1984
|
|
1985
|
|
1986 curndx = newndx = 0;
|
|
1987 lineno = 0;
|
|
1988 charno = 0;
|
|
1989 lp = curlb.buffer;
|
|
1990 *lp = 0;
|
|
1991
|
|
1992 definedef = dnone; funcdef = fnone; typdef = tnone; structdef = snone;
|
|
1993 next_token_is_func = yacc_rules = FALSE;
|
|
1994 midtoken = inquote = inchar = incomm = quotednl = FALSE;
|
|
1995 tok.valid = savetok.valid = FALSE;
|
|
1996 cblev = 0;
|
|
1997 parlev = 0;
|
|
1998 cplpl = c_ext & C_PLPL;
|
|
1999
|
|
2000 while (!feof (inf))
|
|
2001 {
|
|
2002 c = *lp++;
|
|
2003 if (c == '\\')
|
|
2004 {
|
|
2005 /* If we're at the end of the line, the next character is a
|
|
2006 '\0'; don't skip it, because it's the thing that tells us
|
|
2007 to read the next line. */
|
|
2008 if (*lp == '\0')
|
|
2009 {
|
|
2010 quotednl = TRUE;
|
|
2011 continue;
|
|
2012 }
|
|
2013 lp++;
|
|
2014 c = ' ';
|
|
2015 }
|
|
2016 else if (incomm)
|
|
2017 {
|
|
2018 switch (c)
|
|
2019 {
|
|
2020 case '*':
|
|
2021 if (*lp == '/')
|
|
2022 {
|
|
2023 c = *lp++;
|
|
2024 incomm = FALSE;
|
|
2025 }
|
|
2026 break;
|
|
2027 case '\0':
|
|
2028 /* Newlines inside comments do not end macro definitions in
|
|
2029 traditional cpp. */
|
|
2030 CNL_SAVE_DEFINEDEF;
|
|
2031 break;
|
|
2032 }
|
|
2033 continue;
|
|
2034 }
|
|
2035 else if (inquote)
|
|
2036 {
|
|
2037 switch (c)
|
|
2038 {
|
|
2039 case '"':
|
|
2040 inquote = FALSE;
|
|
2041 break;
|
|
2042 case '\0':
|
|
2043 /* Newlines inside strings do not end macro definitions
|
|
2044 in traditional cpp, even though compilers don't
|
|
2045 usually accept them. */
|
|
2046 CNL_SAVE_DEFINEDEF;
|
|
2047 break;
|
|
2048 }
|
|
2049 continue;
|
|
2050 }
|
|
2051 else if (inchar)
|
|
2052 {
|
|
2053 switch (c)
|
|
2054 {
|
|
2055 case '\0':
|
|
2056 /* Hmmm, something went wrong. */
|
|
2057 CNL;
|
|
2058 /* FALLTHRU */
|
|
2059 case '\'':
|
|
2060 inchar = FALSE;
|
|
2061 break;
|
|
2062 }
|
|
2063 continue;
|
|
2064 }
|
|
2065 else
|
|
2066 switch (c)
|
|
2067 {
|
|
2068 case '"':
|
|
2069 inquote = TRUE;
|
|
2070 if (funcdef != finlist && funcdef != fignore)
|
|
2071 funcdef = fnone;
|
|
2072 continue;
|
|
2073 case '\'':
|
|
2074 inchar = TRUE;
|
|
2075 if (funcdef != finlist && funcdef != fignore)
|
|
2076 funcdef = fnone;
|
|
2077 continue;
|
|
2078 case '/':
|
|
2079 if (*lp == '*')
|
|
2080 {
|
|
2081 lp++;
|
|
2082 incomm = TRUE;
|
|
2083 continue;
|
|
2084 }
|
|
2085 else if (cplpl && *lp == '/')
|
|
2086 {
|
|
2087 c = 0;
|
|
2088 break;
|
|
2089 }
|
|
2090 else
|
|
2091 break;
|
|
2092 case '%':
|
|
2093 if ((c_ext & YACC) && *lp == '%')
|
|
2094 {
|
|
2095 /* entering or exiting rules section in yacc file */
|
|
2096 lp++;
|
|
2097 definedef = dnone; funcdef = fnone;
|
|
2098 typdef = tnone; structdef = snone;
|
|
2099 next_token_is_func = FALSE;
|
|
2100 midtoken = inquote = inchar = incomm = quotednl = FALSE;
|
|
2101 cblev = 0;
|
|
2102 yacc_rules = !yacc_rules;
|
|
2103 continue;
|
|
2104 }
|
|
2105 else
|
|
2106 break;
|
|
2107 case '#':
|
|
2108 if (definedef == dnone)
|
|
2109 {
|
|
2110 char *cp;
|
|
2111 logical cpptoken = TRUE;
|
|
2112
|
|
2113 /* Look back on this line. If all blanks, or nonblanks
|
|
2114 followed by an end of comment, this is a preprocessor
|
|
2115 token. */
|
|
2116 for (cp = newlb.buffer; cp < lp-1; cp++)
|
|
2117 if (!iswhite (*cp))
|
|
2118 {
|
|
2119 if (*cp == '*' && *(cp+1) == '/')
|
|
2120 {
|
|
2121 cp++;
|
|
2122 cpptoken = TRUE;
|
|
2123 }
|
|
2124 else
|
|
2125 cpptoken = FALSE;
|
|
2126 }
|
|
2127 if (cpptoken)
|
|
2128 definedef = dsharpseen;
|
|
2129 } /* if (definedef == dnone) */
|
|
2130
|
|
2131 continue;
|
|
2132 } /* switch (c) */
|
|
2133
|
|
2134
|
|
2135 /* Consider token only if some complicated conditions are satisfied. */
|
|
2136 if ((definedef != dnone
|
|
2137 || (cblev == 0 && structdef != scolonseen)
|
|
2138 || (cblev == 1 && cplpl && structdef == sinbody))
|
|
2139 && typdef != tignore
|
|
2140 && definedef != dignorerest
|
|
2141 && funcdef != finlist)
|
|
2142 {
|
|
2143 if (midtoken)
|
|
2144 {
|
|
2145 if (endtoken (c))
|
|
2146 {
|
|
2147 if (cplpl && c == ':' && *lp == ':' && begtoken(*(lp + 1)))
|
|
2148 {
|
|
2149 /*
|
|
2150 * This handles :: in the middle, but not at the
|
|
2151 * beginning of an identifier.
|
|
2152 */
|
|
2153 lp += 2;
|
|
2154 toklen += 3;
|
|
2155 }
|
|
2156 else
|
|
2157 {
|
|
2158 logical is_func = FALSE;
|
|
2159
|
|
2160 if (yacc_rules
|
|
2161 || consider_token (newlb.buffer + tokoff, toklen,
|
|
2162 c, c_ext, cblev, &is_func))
|
|
2163 {
|
|
2164 if (structdef == sinbody
|
|
2165 && definedef == dnone
|
|
2166 && is_func)
|
|
2167 /* function defined in C++ class body */
|
|
2168 {
|
|
2169 int strsize = strlen(structtag) + 2 + toklen + 1;
|
|
2170 while (token_name.size < strsize)
|
|
2171 {
|
|
2172 token_name.size *= 2;
|
|
2173 token_name.buffer
|
|
2174 = (char *) xrealloc (token_name.buffer,
|
|
2175 token_name.size);
|
|
2176 }
|
|
2177 strcpy (token_name.buffer, structtag);
|
|
2178 strcat (token_name.buffer, "::");
|
|
2179 strncat (token_name.buffer,
|
|
2180 newlb.buffer+tokoff, toklen);
|
|
2181 tok.named = TRUE;
|
|
2182 }
|
|
2183 else
|
|
2184 {
|
|
2185 while (token_name.size < toklen + 1)
|
|
2186 {
|
|
2187 token_name.size *= 2;
|
|
2188 token_name.buffer
|
|
2189 = (char *) xrealloc (token_name.buffer,
|
|
2190 token_name.size);
|
|
2191 }
|
|
2192 strncpy (token_name.buffer,
|
|
2193 newlb.buffer+tokoff, toklen);
|
|
2194 token_name.buffer[toklen] = '\0';
|
|
2195 if (structdef == stagseen
|
|
2196 || typdef == tend
|
|
2197 || (is_func
|
|
2198 && definedef == dignorerest)) /* macro */
|
|
2199 tok.named = TRUE;
|
|
2200 else
|
|
2201 tok.named = FALSE;
|
|
2202 }
|
|
2203 tok.lineno = lineno;
|
|
2204 tok.linelen = tokoff + toklen + 1;
|
|
2205 tok.buffer = newlb.buffer;
|
|
2206 tok.linepos = newlinepos;
|
|
2207 tok.valid = TRUE;
|
|
2208
|
|
2209 if (definedef == dnone
|
|
2210 && (funcdef == ftagseen
|
|
2211 || structdef == stagseen
|
|
2212 || typdef == tend))
|
|
2213 {
|
|
2214 if (current_lb_is_new)
|
|
2215 switch_line_buffers ();
|
|
2216 }
|
|
2217 else
|
|
2218 make_tag (is_func);
|
|
2219 }
|
|
2220 midtoken = FALSE;
|
|
2221 }
|
|
2222 } /* if (endtoken (c)) */
|
|
2223 else if (intoken (c))
|
|
2224 {
|
|
2225 toklen++;
|
|
2226 continue;
|
|
2227 }
|
|
2228 } /* if (midtoken) */
|
|
2229 else if (begtoken (c))
|
|
2230 {
|
|
2231 switch (definedef)
|
|
2232 {
|
|
2233 case dnone:
|
|
2234 switch (funcdef)
|
|
2235 {
|
|
2236 case fstartlist:
|
|
2237 funcdef = finlist;
|
|
2238 continue;
|
|
2239 case flistseen:
|
|
2240 make_tag (TRUE);
|
|
2241 funcdef = fignore;
|
|
2242 break;
|
|
2243 case ftagseen:
|
|
2244 funcdef = fnone;
|
|
2245 break;
|
|
2246 default:
|
|
2247 break;
|
|
2248 }
|
|
2249 if (structdef == stagseen)
|
|
2250 structdef = snone;
|
|
2251 break;
|
|
2252 case dsharpseen:
|
|
2253 savetok = tok;
|
|
2254 default:
|
|
2255 break;
|
|
2256 }
|
|
2257 if (!yacc_rules || lp == newlb.buffer + 1)
|
|
2258 {
|
|
2259 tokoff = lp - 1 - newlb.buffer;
|
|
2260 toklen = 1;
|
|
2261 midtoken = TRUE;
|
|
2262 }
|
|
2263 continue;
|
|
2264 } /* if (begtoken) */
|
|
2265 } /* if must look at token */
|
|
2266
|
|
2267
|
|
2268 /* Detect end of line, colon, comma, semicolon and various braces
|
|
2269 after having handled a token.*/
|
|
2270 switch (c)
|
|
2271 {
|
|
2272 case ':':
|
|
2273 if (definedef != dnone)
|
|
2274 break;
|
|
2275 if (structdef == stagseen)
|
|
2276 structdef = scolonseen;
|
|
2277 else
|
|
2278 switch (funcdef)
|
|
2279 {
|
|
2280 case ftagseen:
|
|
2281 if (yacc_rules)
|
|
2282 {
|
|
2283 make_tag (FALSE);
|
|
2284 funcdef = fignore;
|
|
2285 }
|
|
2286 break;
|
|
2287 case fstartlist:
|
|
2288 funcdef = fnone;
|
|
2289 break;
|
|
2290 default:
|
|
2291 break;
|
|
2292 }
|
|
2293 break;
|
|
2294 case ';':
|
|
2295 if (definedef != dnone)
|
|
2296 break;
|
|
2297 if (cblev == 0)
|
|
2298 switch (typdef)
|
|
2299 {
|
|
2300 case tend:
|
|
2301 make_tag (FALSE);
|
|
2302 /* FALLTHRU */
|
|
2303 default:
|
|
2304 typdef = tnone;
|
|
2305 }
|
|
2306 if (funcdef != fignore)
|
|
2307 {
|
|
2308 funcdef = fnone;
|
|
2309 /* The following instruction invalidates the token.
|
|
2310 Probably the token should be invalidated in all
|
|
2311 other cases where some state machine is reset. */
|
|
2312 tok.valid = FALSE;
|
|
2313 }
|
|
2314 if (structdef == stagseen)
|
|
2315 structdef = snone;
|
|
2316 break;
|
|
2317 case ',':
|
|
2318 if (definedef != dnone)
|
|
2319 break;
|
|
2320 if (funcdef != finlist && funcdef != fignore)
|
|
2321 funcdef = fnone;
|
|
2322 if (structdef == stagseen)
|
|
2323 structdef = snone;
|
|
2324 break;
|
|
2325 case '[':
|
|
2326 if (definedef != dnone)
|
|
2327 break;
|
|
2328 if (cblev == 0 && typdef == tend)
|
|
2329 {
|
|
2330 typdef = tignore;
|
|
2331 make_tag (FALSE);
|
|
2332 break;
|
|
2333 }
|
|
2334 if (funcdef != finlist && funcdef != fignore)
|
|
2335 funcdef = fnone;
|
|
2336 if (structdef == stagseen)
|
|
2337 structdef = snone;
|
|
2338 break;
|
|
2339 case '(':
|
|
2340 if (definedef != dnone)
|
|
2341 break;
|
|
2342 switch (funcdef)
|
|
2343 {
|
|
2344 case fnone:
|
|
2345 switch (typdef)
|
|
2346 {
|
|
2347 case ttypedseen:
|
|
2348 case tend:
|
|
2349 /* Make sure that the next char is not a '*'.
|
|
2350 This handles constructs like:
|
|
2351 typedef void OperatorFun (int fun); */
|
|
2352 if (*lp != '*')
|
|
2353 {
|
|
2354 typdef = tignore;
|
|
2355 make_tag (FALSE);
|
|
2356 }
|
|
2357 break;
|
|
2358 default:
|
|
2359 break;
|
|
2360 } /* switch (typdef) */
|
|
2361 break;
|
|
2362 case ftagseen:
|
|
2363 funcdef = fstartlist;
|
|
2364 break;
|
|
2365 case flistseen:
|
|
2366 funcdef = finlist;
|
|
2367 break;
|
|
2368 default:
|
|
2369 break;
|
|
2370 }
|
|
2371 parlev++;
|
|
2372 break;
|
|
2373 case ')':
|
|
2374 if (definedef != dnone)
|
|
2375 break;
|
|
2376 if (--parlev == 0)
|
|
2377 {
|
|
2378 switch (funcdef)
|
|
2379 {
|
|
2380 case fstartlist:
|
|
2381 case finlist:
|
|
2382 funcdef = flistseen;
|
|
2383 break;
|
|
2384 default:
|
|
2385 break;
|
|
2386 }
|
|
2387 if (cblev == 0 && typdef == tend)
|
|
2388 {
|
|
2389 typdef = tignore;
|
|
2390 make_tag (FALSE);
|
|
2391 }
|
|
2392 }
|
|
2393 else if (parlev < 0) /* can happen due to ill-conceived #if's. */
|
|
2394 parlev = 0;
|
|
2395 break;
|
|
2396 case '{':
|
|
2397 if (definedef != dnone)
|
|
2398 break;
|
|
2399 if (typdef == ttypedseen)
|
|
2400 typdef = tinbody;
|
|
2401 switch (structdef)
|
|
2402 {
|
|
2403 case skeyseen: /* unnamed struct */
|
|
2404 structtag = "_anonymous_";
|
|
2405 structdef = sinbody;
|
|
2406 break;
|
|
2407 case stagseen:
|
|
2408 case scolonseen: /* named struct */
|
|
2409 structdef = sinbody;
|
|
2410 make_tag (FALSE);
|
|
2411 break;
|
|
2412 default:
|
|
2413 break;
|
|
2414 }
|
|
2415 switch (funcdef)
|
|
2416 {
|
|
2417 case flistseen:
|
|
2418 make_tag (TRUE);
|
|
2419 /* FALLTHRU */
|
|
2420 case fignore:
|
|
2421 funcdef = fnone;
|
|
2422 break;
|
|
2423 case fnone:
|
|
2424 /* Neutralize `extern "C" {' grot and look inside structs. */
|
|
2425 if (cblev == 0 && structdef == snone && typdef == tnone)
|
|
2426 cblev = -1;
|
|
2427 default:
|
|
2428 break;
|
|
2429 }
|
|
2430 cblev++;
|
|
2431 break;
|
|
2432 case '*':
|
|
2433 if (definedef != dnone)
|
|
2434 break;
|
|
2435 if (funcdef == fstartlist)
|
|
2436 funcdef = fnone; /* avoid tagging `foo' in `foo (*bar()) ()' */
|
|
2437 break;
|
|
2438 case '}':
|
|
2439 if (definedef != dnone)
|
|
2440 break;
|
|
2441 if (!noindentypedefs && lp == newlb.buffer + 1)
|
|
2442 {
|
|
2443 cblev = 0; /* reset curly brace level if first column */
|
|
2444 parlev = 0; /* also reset paren level, just in case... */
|
|
2445 }
|
|
2446 else if (cblev > 0)
|
|
2447 cblev--;
|
|
2448 if (cblev == 0)
|
|
2449 {
|
|
2450 if (typdef == tinbody)
|
|
2451 typdef = tend;
|
|
2452 /* Memory leakage here: the string pointed by structtag is
|
|
2453 never released, because I fear to miss something and
|
|
2454 break things while freeing the area. The amount of
|
|
2455 memory leaked here is the sum of the lenghts of the
|
|
2456 struct tags.
|
|
2457 if (structdef == sinbody)
|
|
2458 free (structtag); */
|
|
2459
|
|
2460 structdef = snone;
|
|
2461 structtag = "<error>";
|
|
2462 }
|
|
2463 break;
|
|
2464 case '=':
|
|
2465 case '#': case '+': case '-': case '~': case '&': case '%': case '/':
|
|
2466 case '|': case '^': case '!': case '<': case '>': case '.': case '?':
|
|
2467 if (definedef != dnone)
|
|
2468 break;
|
|
2469 /* These surely cannot follow a function tag. */
|
|
2470 if (funcdef != finlist && funcdef != fignore)
|
|
2471 funcdef = fnone;
|
|
2472 break;
|
|
2473 case '\0':
|
|
2474 /* If a macro spans multiple lines don't reset its state. */
|
|
2475 if (quotednl)
|
|
2476 CNL_SAVE_DEFINEDEF;
|
|
2477 else
|
|
2478 CNL;
|
|
2479 break;
|
|
2480 } /* switch (c) */
|
|
2481
|
|
2482 } /* while not eof */
|
|
2483 }
|
|
2484
|
|
2485 /*
|
|
2486 * Process either a C++ file or a C file depending on the setting
|
|
2487 * of a global flag.
|
|
2488 */
|
|
2489 void
|
|
2490 default_C_entries (FILE *inf)
|
|
2491 {
|
|
2492 C_entries (cplusplus ? C_PLPL : 0, inf);
|
|
2493 }
|
|
2494
|
|
2495 /* Always do plain ANSI C. */
|
|
2496 void
|
|
2497 plain_C_entries (inf)
|
|
2498 FILE *inf;
|
|
2499 {
|
|
2500 C_entries (0, inf);
|
|
2501 }
|
|
2502
|
|
2503 /* Always do C++. */
|
|
2504 void
|
|
2505 Cplusplus_entries (FILE *inf)
|
|
2506 {
|
|
2507 C_entries (C_PLPL, inf);
|
|
2508 }
|
|
2509
|
|
2510 /* Always do C*. */
|
|
2511 void
|
|
2512 Cstar_entries (FILE *inf)
|
|
2513 {
|
|
2514 C_entries (C_STAR, inf);
|
|
2515 }
|
|
2516
|
|
2517 /* Always do Yacc. */
|
|
2518 void
|
|
2519 Yacc_entries (FILE *inf)
|
|
2520 {
|
|
2521 C_entries (YACC, inf);
|
|
2522 }
|
|
2523
|
|
2524 /* Fortran parsing */
|
|
2525
|
|
2526 char *dbp;
|
|
2527
|
|
2528 static logical
|
|
2529 tail (CONST char *cp)
|
|
2530 {
|
|
2531 register int len = 0;
|
|
2532
|
|
2533 while (*cp && lowcase(*cp) == lowcase(dbp[len]))
|
|
2534 cp++, len++;
|
|
2535 if (*cp == '\0' && !intoken(dbp[len]))
|
|
2536 {
|
|
2537 dbp += len;
|
|
2538 return TRUE;
|
|
2539 }
|
|
2540 return FALSE;
|
|
2541 }
|
|
2542
|
|
2543 void
|
|
2544 takeprec (void)
|
|
2545 {
|
|
2546 while (isspace (*dbp))
|
|
2547 dbp++;
|
|
2548 if (*dbp != '*')
|
|
2549 return;
|
|
2550 dbp++;
|
|
2551 while (isspace (*dbp))
|
|
2552 dbp++;
|
|
2553 if (strneq (dbp, "(*)", 3))
|
|
2554 {
|
|
2555 dbp += 3;
|
|
2556 return;
|
|
2557 }
|
|
2558 if (!isdigit (*dbp))
|
|
2559 {
|
|
2560 --dbp; /* force failure */
|
|
2561 return;
|
|
2562 }
|
|
2563 do
|
|
2564 dbp++;
|
|
2565 while (isdigit (*dbp));
|
|
2566 }
|
|
2567
|
|
2568 void
|
|
2569 getit (FILE *inf)
|
|
2570 {
|
|
2571 register char *cp;
|
|
2572
|
|
2573 while (isspace (*dbp))
|
|
2574 dbp++;
|
|
2575 if (*dbp == '\0')
|
|
2576 {
|
|
2577 lineno++;
|
|
2578 linecharno = charno;
|
|
2579 charno += readline (&lb, inf);
|
|
2580 dbp = lb.buffer;
|
|
2581 if (dbp[5] != '&')
|
|
2582 return;
|
|
2583 dbp += 6;
|
|
2584 while (isspace (*dbp))
|
|
2585 dbp++;
|
|
2586 }
|
|
2587 if (!isalpha (*dbp)
|
|
2588 && *dbp != '_'
|
|
2589 && *dbp != '$')
|
|
2590 return;
|
|
2591 for (cp = dbp + 1;
|
|
2592 (*cp
|
|
2593 && (isalpha (*cp) || isdigit (*cp) || (*cp == '_') || (*cp == '$')));
|
|
2594 cp++)
|
|
2595 continue;
|
|
2596 pfnote (NULL, TRUE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
|
|
2597 }
|
|
2598
|
|
2599 void
|
|
2600 Fortran_functions (FILE *inf)
|
|
2601 {
|
|
2602 lineno = 0;
|
|
2603 charno = 0;
|
|
2604
|
|
2605 while (!feof (inf))
|
|
2606 {
|
|
2607 lineno++;
|
|
2608 linecharno = charno;
|
|
2609 charno += readline (&lb, inf);
|
|
2610 dbp = lb.buffer;
|
|
2611 if (*dbp == '%')
|
|
2612 dbp++; /* Ratfor escape to fortran */
|
|
2613 while (isspace (*dbp))
|
|
2614 dbp++;
|
|
2615 if (*dbp == '\0')
|
|
2616 continue;
|
|
2617 switch (lowcase (*dbp))
|
|
2618 {
|
|
2619 case 'i':
|
|
2620 if (tail ("integer"))
|
|
2621 takeprec ();
|
|
2622 break;
|
|
2623 case 'r':
|
|
2624 if (tail ("real"))
|
|
2625 takeprec ();
|
|
2626 break;
|
|
2627 case 'l':
|
|
2628 if (tail ("logical"))
|
|
2629 takeprec ();
|
|
2630 break;
|
|
2631 case 'c':
|
|
2632 if (tail ("complex") || tail ("character"))
|
|
2633 takeprec ();
|
|
2634 break;
|
|
2635 case 'd':
|
|
2636 if (tail ("double"))
|
|
2637 {
|
|
2638 while (isspace (*dbp))
|
|
2639 dbp++;
|
|
2640 if (*dbp == '\0')
|
|
2641 continue;
|
|
2642 if (tail ("precision"))
|
|
2643 break;
|
|
2644 continue;
|
|
2645 }
|
|
2646 break;
|
|
2647 }
|
|
2648 while (isspace (*dbp))
|
|
2649 dbp++;
|
|
2650 if (*dbp == '\0')
|
|
2651 continue;
|
|
2652 switch (lowcase (*dbp))
|
|
2653 {
|
|
2654 case 'f':
|
|
2655 if (tail ("function"))
|
|
2656 getit (inf);
|
|
2657 continue;
|
|
2658 case 's':
|
|
2659 if (tail ("subroutine"))
|
|
2660 getit (inf);
|
|
2661 continue;
|
|
2662 case 'e':
|
|
2663 if (tail ("entry"))
|
|
2664 getit (inf);
|
|
2665 continue;
|
|
2666 case 'p':
|
|
2667 if (tail ("program"))
|
|
2668 {
|
|
2669 getit (inf);
|
|
2670 continue;
|
|
2671 }
|
|
2672 if (tail ("procedure"))
|
|
2673 getit (inf);
|
|
2674 continue;
|
|
2675 }
|
|
2676 }
|
|
2677 }
|
|
2678
|
|
2679 /*
|
|
2680 * Bob Weiner, Motorola Inc., 4/3/94
|
|
2681 * Unix and microcontroller assembly tag handling
|
|
2682 * look for '^[a-zA-Z_.$][a-zA_Z0-9_.$]*[: ^I^J]'
|
|
2683 */
|
|
2684 void
|
|
2685 Asm_labels (FILE *inf)
|
|
2686 {
|
|
2687 register char *cp;
|
|
2688
|
|
2689 lineno = 0;
|
|
2690 charno = 0;
|
|
2691
|
|
2692 while (!feof (inf))
|
|
2693 {
|
|
2694 lineno++;
|
|
2695 linecharno = charno;
|
|
2696 charno += readline (&lb, inf);
|
|
2697 cp = lb.buffer;
|
|
2698
|
|
2699 /* If first char is alphabetic or one of [_.$], test for colon
|
|
2700 following identifier. */
|
|
2701 if (isalpha (*cp) || *cp == '_' || *cp == '.' || *cp == '$')
|
|
2702 {
|
|
2703 /* Read past label. */
|
|
2704 cp++;
|
|
2705 while (isalnum (*cp) || *cp == '_' || *cp == '.' || *cp == '$')
|
|
2706 cp++;
|
|
2707 if (*cp == ':' || isspace (*cp))
|
|
2708 {
|
|
2709 /* Found end of label, so copy it and add it to the table. */
|
|
2710 pfnote (NULL, TRUE,
|
|
2711 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
|
|
2712 }
|
|
2713 }
|
|
2714 }
|
|
2715 }
|
|
2716
|
|
2717 /*
|
|
2718 * Perl support by Bart Robinson <lomew@cs.utah.edu>
|
|
2719 * Perl sub names: look for /^sub[ \t\n]+[^ \t\n{]+/
|
|
2720 */
|
|
2721 void
|
|
2722 Perl_functions (inf)
|
|
2723 FILE *inf;
|
|
2724 {
|
|
2725 register char *cp;
|
|
2726
|
|
2727 lineno = 0;
|
|
2728 charno = 0;
|
|
2729
|
|
2730 while (!feof (inf))
|
|
2731 {
|
|
2732 lineno++;
|
|
2733 linecharno = charno;
|
|
2734 charno += readline (&lb, inf);
|
|
2735 cp = lb.buffer;
|
|
2736
|
|
2737 if (*cp++ == 's' && *cp++ == 'u' && *cp++ == 'b' && isspace(*cp++))
|
|
2738 {
|
|
2739 while (*cp && isspace(*cp))
|
|
2740 cp++;
|
|
2741 while (*cp && ! isspace(*cp) && *cp != '{')
|
|
2742 cp++;
|
|
2743 pfnote (NULL, TRUE,
|
|
2744 lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
|
|
2745 }
|
|
2746 }
|
|
2747 }
|
|
2748
|
|
2749 /* Added by Mosur Mohan, 4/22/88 */
|
|
2750 /* Pascal parsing */
|
|
2751
|
|
2752 #define GET_NEW_LINE \
|
|
2753 { \
|
|
2754 linecharno = charno; lineno++; \
|
|
2755 charno += 1 + readline (&lb, inf); \
|
|
2756 dbp = lb.buffer; \
|
|
2757 }
|
|
2758
|
|
2759 /*
|
|
2760 * Locates tags for procedures & functions. Doesn't do any type- or
|
|
2761 * var-definitions. It does look for the keyword "extern" or
|
|
2762 * "forward" immediately following the procedure statement; if found,
|
|
2763 * the tag is skipped.
|
|
2764 */
|
|
2765 void
|
|
2766 Pascal_functions (FILE *inf)
|
|
2767 {
|
|
2768 struct linebuffer tline; /* mostly copied from C_entries */
|
|
2769 long save_lcno = 0;
|
|
2770 int save_lineno = 0, save_len = 0;
|
|
2771 char c;
|
|
2772
|
|
2773 logical /* each of these flags is TRUE iff: */
|
|
2774 incomment, /* point is inside a comment */
|
|
2775 inquote, /* point is inside '..' string */
|
|
2776 get_tagname, /* point is after PROCEDURE/FUNCTION
|
|
2777 keyword, so next item = potential tag */
|
|
2778 found_tag, /* point is after a potential tag */
|
|
2779 inparms, /* point is within parameter-list */
|
|
2780 verify_tag; /* point has passed the parm-list, so the
|
|
2781 next token will determine whether this
|
|
2782 is a FORWARD/EXTERN to be ignored, or
|
|
2783 whether it is a real tag */
|
|
2784
|
|
2785 lineno = 0;
|
|
2786 charno = 0;
|
|
2787 dbp = lb.buffer;
|
|
2788 *dbp = '\0';
|
|
2789 save_len = 0;
|
|
2790 initbuffer (&tline);
|
|
2791
|
|
2792 incomment = inquote = FALSE;
|
|
2793 found_tag = FALSE; /* have a proc name; check if extern */
|
|
2794 get_tagname = FALSE; /* have found "procedure" keyword */
|
|
2795 inparms = FALSE; /* found '(' after "proc" */
|
|
2796 verify_tag = FALSE; /* check if "extern" is ahead */
|
|
2797
|
|
2798 /* long main loop to get next char */
|
|
2799 while (!feof (inf))
|
|
2800 {
|
|
2801 c = *dbp++;
|
|
2802 if (c == '\0') /* if end of line */
|
|
2803 {
|
|
2804 GET_NEW_LINE;
|
|
2805 if (*dbp == '\0')
|
|
2806 continue;
|
|
2807 if (!((found_tag && verify_tag) ||
|
|
2808 get_tagname))
|
|
2809 c = *dbp++; /* only if don't need *dbp pointing
|
|
2810 to the beginning of the name of
|
|
2811 the procedure or function */
|
|
2812 }
|
|
2813 if (incomment)
|
|
2814 {
|
|
2815 if (c == '}') /* within { } comments */
|
|
2816 incomment = FALSE;
|
|
2817 else if (c == '*' && *dbp == ')') /* within (* *) comments */
|
|
2818 {
|
|
2819 dbp++;
|
|
2820 incomment = FALSE;
|
|
2821 }
|
|
2822 continue;
|
|
2823 }
|
|
2824 else if (inquote)
|
|
2825 {
|
|
2826 if (c == '\'')
|
|
2827 inquote = FALSE;
|
|
2828 continue;
|
|
2829 }
|
|
2830 else
|
|
2831 switch (c)
|
|
2832 {
|
|
2833 case '\'':
|
|
2834 inquote = TRUE; /* found first quote */
|
|
2835 continue;
|
|
2836 case '{': /* found open { comment */
|
|
2837 incomment = TRUE;
|
|
2838 continue;
|
|
2839 case '(':
|
|
2840 if (*dbp == '*') /* found open (* comment */
|
|
2841 {
|
|
2842 incomment = TRUE;
|
|
2843 dbp++;
|
|
2844 }
|
|
2845 else if (found_tag) /* found '(' after tag, i.e., parm-list */
|
|
2846 inparms = TRUE;
|
|
2847 continue;
|
|
2848 case ')': /* end of parms list */
|
|
2849 if (inparms)
|
|
2850 inparms = FALSE;
|
|
2851 continue;
|
|
2852 case ';':
|
|
2853 if (found_tag && !inparms) /* end of proc or fn stmt */
|
|
2854 {
|
|
2855 verify_tag = TRUE;
|
|
2856 break;
|
|
2857 }
|
|
2858 continue;
|
|
2859 }
|
|
2860 if (found_tag && verify_tag && (*dbp != ' '))
|
|
2861 {
|
|
2862 /* check if this is an "extern" declaration */
|
|
2863 if (*dbp == '\0')
|
|
2864 continue;
|
|
2865 if (lowcase (*dbp == 'e'))
|
|
2866 {
|
|
2867 if (tail ("extern")) /* superfluous, really! */
|
|
2868 {
|
|
2869 found_tag = FALSE;
|
|
2870 verify_tag = FALSE;
|
|
2871 }
|
|
2872 }
|
|
2873 else if (lowcase (*dbp) == 'f')
|
|
2874 {
|
|
2875 if (tail ("forward")) /* check for forward reference */
|
|
2876 {
|
|
2877 found_tag = FALSE;
|
|
2878 verify_tag = FALSE;
|
|
2879 }
|
|
2880 }
|
|
2881 if (found_tag && verify_tag) /* not external proc, so make tag */
|
|
2882 {
|
|
2883 found_tag = FALSE;
|
|
2884 verify_tag = FALSE;
|
|
2885 pfnote (NULL, TRUE,
|
|
2886 tline.buffer, save_len, save_lineno, save_lcno);
|
|
2887 continue;
|
|
2888 }
|
|
2889 }
|
|
2890 if (get_tagname) /* grab name of proc or fn */
|
|
2891 {
|
|
2892 int size;
|
|
2893
|
|
2894 if (*dbp == '\0')
|
|
2895 continue;
|
|
2896
|
|
2897 /* save all values for later tagging */
|
|
2898 size = strlen (lb.buffer) + 1;
|
|
2899 while (size > tline.size)
|
|
2900 {
|
|
2901 tline.size *= 2;
|
|
2902 tline.buffer = (char *) xrealloc (tline.buffer, tline.size);
|
|
2903 }
|
|
2904 strcpy (tline.buffer, lb.buffer);
|
|
2905 save_lineno = lineno;
|
|
2906 save_lcno = linecharno;
|
|
2907
|
|
2908 /* grab block name */
|
|
2909 for (dbp++; *dbp && (!endtoken (*dbp)); dbp++)
|
|
2910 continue;
|
|
2911 save_len = dbp - lb.buffer + 1;
|
|
2912 get_tagname = FALSE;
|
|
2913 found_tag = TRUE;
|
|
2914 continue;
|
|
2915
|
|
2916 /* and proceed to check for "extern" */
|
|
2917 }
|
|
2918 else if (!incomment && !inquote && !found_tag)
|
|
2919 {
|
|
2920 /* check for proc/fn keywords */
|
|
2921 switch (lowcase (c))
|
|
2922 {
|
|
2923 case 'p':
|
|
2924 if (tail ("rocedure")) /* c = 'p', dbp has advanced */
|
|
2925 get_tagname = TRUE;
|
|
2926 continue;
|
|
2927 case 'f':
|
|
2928 if (tail ("unction"))
|
|
2929 get_tagname = TRUE;
|
|
2930 continue;
|
|
2931 }
|
|
2932 }
|
|
2933 } /* while not eof */
|
|
2934
|
|
2935 free (tline.buffer);
|
|
2936 }
|
|
2937
|
|
2938 /*
|
|
2939 * lisp tag functions
|
|
2940 * look for (def or (DEF, quote or QUOTE
|
|
2941 */
|
|
2942 static int
|
|
2943 L_isdef (char *strp)
|
|
2944 {
|
|
2945 return ((strp[1] == 'd' || strp[1] == 'D')
|
|
2946 && (strp[2] == 'e' || strp[2] == 'E')
|
|
2947 && (strp[3] == 'f' || strp[3] == 'F'));
|
|
2948 }
|
|
2949
|
|
2950 static int
|
|
2951 L_isquote (char *strp)
|
|
2952 {
|
|
2953 return ((*(++strp) == 'q' || *strp == 'Q')
|
|
2954 && (*(++strp) == 'u' || *strp == 'U')
|
|
2955 && (*(++strp) == 'o' || *strp == 'O')
|
|
2956 && (*(++strp) == 't' || *strp == 'T')
|
|
2957 && (*(++strp) == 'e' || *strp == 'E')
|
|
2958 && isspace(*(++strp)));
|
|
2959 }
|
|
2960
|
|
2961 static void
|
|
2962 L_getit (void)
|
|
2963 {
|
|
2964 register char *cp;
|
|
2965
|
|
2966 if (*dbp == '\'') /* Skip prefix quote */
|
|
2967 dbp++;
|
|
2968 else if (*dbp == '(' && L_isquote (dbp)) /* Skip "(quote " */
|
|
2969 {
|
|
2970 dbp += 7;
|
|
2971 while (isspace(*dbp))
|
|
2972 dbp++;
|
|
2973 }
|
|
2974 for (cp = dbp /*+1*/;
|
|
2975 *cp && *cp != '(' && *cp != ' ' && *cp != ')';
|
|
2976 cp++)
|
|
2977 continue;
|
|
2978 if (cp == dbp)
|
|
2979 return;
|
|
2980
|
|
2981 pfnote (NULL, TRUE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
|
|
2982 }
|
|
2983
|
|
2984 void
|
|
2985 Lisp_functions (FILE *inf)
|
|
2986 {
|
|
2987 lineno = 0;
|
|
2988 charno = 0;
|
|
2989
|
|
2990 while (!feof (inf))
|
|
2991 {
|
|
2992 lineno++;
|
|
2993 linecharno = charno;
|
|
2994 charno += readline (&lb, inf);
|
|
2995 dbp = lb.buffer;
|
|
2996 if (dbp[0] == '(')
|
|
2997 {
|
|
2998 if (L_isdef (dbp))
|
|
2999 {
|
|
3000 while (!isspace (*dbp))
|
|
3001 dbp++;
|
|
3002 while (isspace (*dbp))
|
|
3003 dbp++;
|
|
3004 L_getit ();
|
|
3005 }
|
|
3006 else
|
|
3007 {
|
|
3008 /* Check for (foo::defmumble name-defined ... */
|
|
3009 do
|
|
3010 dbp++;
|
|
3011 while (*dbp && !isspace (*dbp)
|
|
3012 && *dbp != ':' && *dbp != '(' && *dbp != ')');
|
|
3013 if (*dbp == ':')
|
|
3014 {
|
|
3015 do
|
|
3016 dbp++;
|
|
3017 while (*dbp == ':');
|
|
3018
|
|
3019 if (L_isdef (dbp - 1))
|
|
3020 {
|
|
3021 while (!isspace (*dbp))
|
|
3022 dbp++;
|
|
3023 while (isspace (*dbp))
|
|
3024 dbp++;
|
|
3025 L_getit ();
|
|
3026 }
|
|
3027 }
|
|
3028 }
|
|
3029 }
|
|
3030 }
|
|
3031 }
|
|
3032
|
|
3033 /* XEmacs addition: */
|
|
3034
|
|
3035 /*
|
|
3036 * Postscript tag functions
|
|
3037 * Just look for lines where the first character is '/'
|
|
3038 */
|
|
3039
|
|
3040 static void
|
|
3041 PS_getit (void)
|
|
3042 {
|
|
3043 register char *cp;
|
|
3044 char c;
|
|
3045 char nambuf[BUFSIZ];
|
|
3046
|
|
3047 if (*dbp == 0) return;
|
|
3048 for (cp = dbp+1; *cp && *cp != ' ' && *cp != '{'; cp++)
|
|
3049 continue;
|
|
3050 c = cp[0];
|
|
3051 cp[0] = 0;
|
|
3052 strcpy(nambuf, dbp);
|
|
3053 cp[0] = c;
|
|
3054 pfnote (nambuf, TRUE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
|
|
3055 }
|
|
3056
|
|
3057 void
|
|
3058 Postscript_functions (FILE *fi)
|
|
3059 {
|
|
3060 lineno = 0;
|
|
3061 charno = 0;
|
|
3062
|
|
3063 while (!feof (fi))
|
|
3064 {
|
|
3065 lineno++;
|
|
3066 linecharno = charno;
|
|
3067 charno += readline (&lb, fi) + 1;
|
|
3068 dbp = lb.buffer;
|
|
3069 if (dbp[0] == '/')
|
|
3070 {
|
|
3071 PS_getit();
|
|
3072 }
|
|
3073 }
|
|
3074 }
|
|
3075
|
|
3076
|
|
3077 /*
|
|
3078 * Scheme tag functions
|
|
3079 * look for (def... xyzzy
|
|
3080 * look for (def... (xyzzy
|
|
3081 * look for (def ... ((...(xyzzy ....
|
|
3082 * look for (set! xyzzy
|
|
3083 */
|
|
3084
|
|
3085 void get_scheme (void);
|
|
3086
|
|
3087 void
|
|
3088 Scheme_functions (FILE *inf)
|
|
3089 {
|
|
3090 lineno = 0;
|
|
3091 charno = 0;
|
|
3092
|
|
3093 while (!feof (inf))
|
|
3094 {
|
|
3095 lineno++;
|
|
3096 linecharno = charno;
|
|
3097 charno += readline (&lb, inf);
|
|
3098 dbp = lb.buffer;
|
|
3099 if (dbp[0] == '(' &&
|
|
3100 (dbp[1] == 'D' || dbp[1] == 'd') &&
|
|
3101 (dbp[2] == 'E' || dbp[2] == 'e') &&
|
|
3102 (dbp[3] == 'F' || dbp[3] == 'f'))
|
|
3103 {
|
|
3104 while (!isspace (*dbp))
|
|
3105 dbp++;
|
|
3106 /* Skip over open parens and white space */
|
|
3107 while (*dbp && (isspace (*dbp) || *dbp == '('))
|
|
3108 dbp++;
|
|
3109 get_scheme ();
|
|
3110 }
|
|
3111 if (dbp[0] == '(' &&
|
|
3112 (dbp[1] == 'S' || dbp[1] == 's') &&
|
|
3113 (dbp[2] == 'E' || dbp[2] == 'e') &&
|
|
3114 (dbp[3] == 'T' || dbp[3] == 't') &&
|
|
3115 (dbp[4] == '!' || dbp[4] == '!') &&
|
|
3116 (isspace (dbp[5])))
|
|
3117 {
|
|
3118 while (!isspace (*dbp))
|
|
3119 dbp++;
|
|
3120 /* Skip over white space */
|
|
3121 while (isspace (*dbp))
|
|
3122 dbp++;
|
|
3123 get_scheme ();
|
|
3124 }
|
|
3125 }
|
|
3126 }
|
|
3127
|
|
3128 void
|
|
3129 get_scheme (void)
|
|
3130 {
|
|
3131 register char *cp;
|
|
3132
|
|
3133 if (*dbp == '\0')
|
|
3134 return;
|
|
3135 /* Go till you get to white space or a syntactic break */
|
|
3136 for (cp = dbp + 1;
|
|
3137 *cp && *cp != '(' && *cp != ')' && !isspace (*cp);
|
|
3138 cp++)
|
|
3139 continue;
|
|
3140 pfnote (NULL, TRUE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
|
|
3141 }
|
|
3142
|
|
3143 /* Find tags in TeX and LaTeX input files. */
|
|
3144
|
|
3145 /* TEX_toktab is a table of TeX control sequences that define tags.
|
|
3146 Each TEX_tabent records one such control sequence.
|
|
3147 CONVERT THIS TO USE THE Stab TYPE!! */
|
|
3148 struct TEX_tabent
|
|
3149 {
|
|
3150 CONST char *name;
|
|
3151 int len;
|
|
3152 };
|
|
3153
|
|
3154 struct TEX_tabent *TEX_toktab = NULL; /* Table with tag tokens */
|
|
3155
|
|
3156 /* Default set of control sequences to put into TEX_toktab.
|
|
3157 The value of environment var TEXTAGS is prepended to this. */
|
|
3158
|
|
3159 CONST char *TEX_defenv = "\
|
|
3160 :chapter:section:subsection:subsubsection:eqno:label:ref:cite:bibitem\
|
|
3161 :part:appendix:entry:index";
|
|
3162
|
|
3163 void TEX_mode (FILE *inf);
|
|
3164 struct TEX_tabent *TEX_decode_env (CONST char *evarname, CONST char *defenv);
|
|
3165 int TEX_Token (char *cp);
|
|
3166 #if TeX_named_tokens
|
|
3167 void TEX_getit (char *name, int len);
|
|
3168 #endif
|
|
3169
|
|
3170 char TEX_esc = '\\';
|
|
3171 char TEX_opgrp = '{';
|
|
3172 char TEX_clgrp = '}';
|
|
3173
|
|
3174 /*
|
|
3175 * TeX/LaTeX scanning loop.
|
|
3176 */
|
|
3177 void
|
|
3178 TeX_functions (FILE *inf)
|
|
3179 {
|
|
3180 char *lasthit;
|
|
3181
|
|
3182 lineno = 0;
|
|
3183 charno = 0;
|
|
3184
|
|
3185 /* Select either \ or ! as escape character. */
|
|
3186 TEX_mode (inf);
|
|
3187
|
|
3188 /* Initialize token table once from environment. */
|
|
3189 if (!TEX_toktab)
|
|
3190 TEX_toktab = TEX_decode_env ("TEXTAGS", TEX_defenv);
|
|
3191
|
|
3192 while (!feof (inf))
|
|
3193 { /* Scan each line in file */
|
|
3194 lineno++;
|
|
3195 linecharno = charno;
|
|
3196 charno += readline (&lb, inf);
|
|
3197 dbp = lb.buffer;
|
|
3198 lasthit = dbp;
|
|
3199 while ((dbp = etags_strchr (dbp, TEX_esc)))/* Look at each esc in line */
|
|
3200 {
|
|
3201 register int i;
|
|
3202
|
|
3203 if (!*(++dbp))
|
|
3204 break;
|
|
3205 linecharno += dbp - lasthit;
|
|
3206 lasthit = dbp;
|
|
3207 i = TEX_Token (lasthit);
|
|
3208 if (0 <= i)
|
|
3209 {
|
|
3210 pfnote (NULL, TRUE,
|
|
3211 lb.buffer, strlen (lb.buffer), lineno, linecharno);
|
|
3212 #if TeX_named_tokens
|
|
3213 TEX_getit (lasthit, TEX_toktab[i].len);
|
|
3214 #endif
|
|
3215 break; /* We only save a line once */
|
|
3216 }
|
|
3217 }
|
|
3218 }
|
|
3219 }
|
|
3220
|
|
3221 #define TEX_LESC '\\'
|
|
3222 #define TEX_SESC '!'
|
|
3223 #define TEX_cmt '%'
|
|
3224
|
|
3225 /* Figure out whether TeX's escapechar is '\\' or '!' and set grouping
|
|
3226 chars accordingly. */
|
|
3227 void
|
|
3228 TEX_mode (FILE *inf)
|
|
3229 {
|
|
3230 int c;
|
|
3231
|
|
3232 while ((c = getc (inf)) != EOF)
|
|
3233 {
|
|
3234 /* Skip to next line if we hit the TeX comment char. */
|
|
3235 if (c == TEX_cmt)
|
|
3236 while (c != '\n')
|
|
3237 c = getc (inf);
|
|
3238 else if (c == TEX_LESC || c == TEX_SESC )
|
|
3239 break;
|
|
3240 }
|
|
3241
|
|
3242 if (c == TEX_LESC)
|
|
3243 {
|
|
3244 TEX_esc = TEX_LESC;
|
|
3245 TEX_opgrp = '{';
|
|
3246 TEX_clgrp = '}';
|
|
3247 }
|
|
3248 else
|
|
3249 {
|
|
3250 TEX_esc = TEX_SESC;
|
|
3251 TEX_opgrp = '<';
|
|
3252 TEX_clgrp = '>';
|
|
3253 }
|
|
3254 rewind (inf);
|
|
3255 }
|
|
3256
|
|
3257 /* Read environment and prepend it to the default string.
|
|
3258 Build token table. */
|
|
3259 struct TEX_tabent *
|
|
3260 TEX_decode_env (CONST char *evarname, CONST char *defenv)
|
|
3261 {
|
|
3262 register CONST char *env, *p;
|
|
3263
|
|
3264 struct TEX_tabent *tab;
|
|
3265 int size, i;
|
|
3266
|
|
3267 /* Append default string to environment. */
|
|
3268 env = getenv (evarname);
|
|
3269 if (!env)
|
|
3270 env = defenv;
|
|
3271 else
|
|
3272 env = concat (env, defenv, ""); /* never freed! */
|
|
3273
|
|
3274 /* Allocate a token table */
|
|
3275 for (size = 1, p = env; p;)
|
|
3276 if ((p = etags_strchr (p, ':')) && *(++p))
|
|
3277 size++;
|
|
3278 /* Add 1 to leave room for null terminator. */
|
|
3279 tab = xnew (size + 1, struct TEX_tabent);
|
|
3280
|
|
3281 /* Unpack environment string into token table. Be careful about */
|
|
3282 /* zero-length strings (leading ':', "::" and trailing ':') */
|
|
3283 for (i = 0; *env;)
|
|
3284 {
|
|
3285 p = etags_strchr (env, ':');
|
|
3286 if (!p) /* End of environment string. */
|
|
3287 p = env + strlen (env);
|
|
3288 if (p - env > 0)
|
|
3289 { /* Only non-zero strings. */
|
|
3290 tab[i].name = savenstr (env, p - env);
|
|
3291 tab[i].len = strlen (tab[i].name);
|
|
3292 i++;
|
|
3293 }
|
|
3294 if (*p)
|
|
3295 env = p + 1;
|
|
3296 else
|
|
3297 {
|
|
3298 tab[i].name = NULL; /* Mark end of table. */
|
|
3299 tab[i].len = 0;
|
|
3300 break;
|
|
3301 }
|
|
3302 }
|
|
3303 return tab;
|
|
3304 }
|
|
3305
|
|
3306 #if TeX_named_tokens
|
|
3307 /* Record a tag defined by a TeX command of length LEN and starting at NAME.
|
|
3308 The name being defined actually starts at (NAME + LEN + 1).
|
|
3309 But we seem to include the TeX command in the tag name. */
|
|
3310 void
|
|
3311 TEX_getit (char *name, int len)
|
|
3312 {
|
|
3313 char *p = name + len;
|
|
3314
|
|
3315 if (*name == '\0')
|
|
3316 return;
|
|
3317
|
|
3318 /* Let tag name extend to next group close (or end of line) */
|
|
3319 while (*p && *p != TEX_clgrp)
|
|
3320 p++;
|
|
3321 pfnote (savenstr (name, p-name), TRUE,
|
|
3322 lb.buffer, strlen (lb.buffer), lineno, linecharno);
|
|
3323 }
|
|
3324 #endif
|
|
3325
|
|
3326 /* If the text at CP matches one of the tag-defining TeX command names,
|
|
3327 return the pointer to the first occurrence of that command in TEX_toktab.
|
|
3328 Otherwise return -1.
|
|
3329 Keep the capital `T' in `Token' for dumb truncating compilers
|
|
3330 (this distinguishes it from `TEX_toktab' */
|
|
3331 int
|
|
3332 TEX_Token (char *cp)
|
|
3333 {
|
|
3334 int i;
|
|
3335
|
|
3336 for (i = 0; TEX_toktab[i].len > 0; i++)
|
|
3337 if (strneq (TEX_toktab[i].name, cp, TEX_toktab[i].len))
|
|
3338 return i;
|
|
3339 return -1;
|
|
3340 }
|
|
3341
|
|
3342 /* Support for Prolog. */
|
|
3343
|
|
3344 /* Whole head (not only functor, but also arguments)
|
|
3345 is gotten in compound term. */
|
|
3346 static void
|
|
3347 prolog_getit (char *s)
|
|
3348 {
|
|
3349 char *save_s;
|
|
3350 int insquote, npar;
|
|
3351
|
|
3352 save_s = s;
|
|
3353 insquote = FALSE;
|
|
3354 npar = 0;
|
|
3355 while (1)
|
|
3356 {
|
|
3357 if (s[0] == '\0') /* syntax error. */
|
|
3358 return;
|
|
3359 else if (insquote && s[0] == '\'' && s[1] == '\'')
|
|
3360 s += 2;
|
|
3361 else if (s[0] == '\'')
|
|
3362 {
|
|
3363 insquote = !insquote;
|
|
3364 s++;
|
|
3365 }
|
|
3366 else if (!insquote && s[0] == '(')
|
|
3367 {
|
|
3368 npar++;
|
|
3369 s++;
|
|
3370 }
|
|
3371 else if (!insquote && s[0] == ')')
|
|
3372 {
|
|
3373 npar--;
|
|
3374 s++;
|
|
3375 if (npar == 0)
|
|
3376 break;
|
|
3377 else if (npar < 0) /* syntax error. */
|
|
3378 return;
|
|
3379 }
|
|
3380 else if (!insquote && s[0] == '.'
|
|
3381 && (isspace (s[1]) || s[1] == '\0'))
|
|
3382 { /* fullstop. */
|
|
3383 if (npar != 0) /* syntax error. */
|
|
3384 return;
|
|
3385 s++;
|
|
3386 break;
|
|
3387 }
|
|
3388 else
|
|
3389 s++;
|
|
3390 }
|
|
3391 pfnote (NULL, TRUE, save_s, s-save_s, lineno, linecharno);
|
|
3392 }
|
|
3393
|
|
3394 void skip_comment (struct linebuffer *plb, FILE *inf, int *plineno,
|
|
3395 long *plinecharno);
|
|
3396
|
|
3397 /* It is assumed that prolog predicate starts from column 0. */
|
|
3398 void
|
|
3399 Prolog_functions (FILE *inf)
|
|
3400 {
|
|
3401 lineno = linecharno = charno = 0;
|
|
3402 while (!feof (inf))
|
|
3403 {
|
|
3404 lineno++;
|
|
3405 linecharno += charno;
|
|
3406 charno = readline (&lb, inf) + 1; /* 1 for newline. */
|
|
3407 dbp = lb.buffer;
|
|
3408 if (isspace (dbp[0])) /* not predicate header. */
|
|
3409 continue;
|
|
3410 else if (dbp[0] == '%') /* comment. */
|
|
3411 continue;
|
|
3412 else if (dbp[0] == '/' && dbp[1] == '*') /* comment. */
|
|
3413 skip_comment (&lb, inf, &lineno, &linecharno);
|
|
3414 else /* found. */
|
|
3415 prolog_getit (dbp);
|
|
3416 }
|
|
3417 }
|
|
3418
|
|
3419 void
|
|
3420 skip_comment (struct linebuffer *plb, FILE *inf, int *plineno,
|
|
3421 long *plinecharno)
|
|
3422 {
|
|
3423 char *cp;
|
|
3424
|
|
3425 do
|
|
3426 {
|
|
3427 for (cp = plb->buffer; *cp != '\0'; cp++)
|
|
3428 if (cp[0] == '*' && cp[1] == '/')
|
|
3429 return;
|
|
3430 (*plineno)++;
|
|
3431 *plinecharno += readline (plb, inf) + 1; /* 1 for newline. */
|
|
3432 }
|
|
3433 while (!feof(inf));
|
|
3434 }
|
|
3435
|
|
3436 #ifdef ETAGS_REGEXPS
|
|
3437 /* Take a string like "/blah/" and turn it into "blah", making sure
|
|
3438 that the first and last characters are the same, and handling
|
|
3439 quoted separator characters. Actually, stops on the occurence of
|
|
3440 an unquoted separator. Also turns "\t" into a Tab character.
|
|
3441 Returns pointer to terminating separator. Works in place. Null
|
|
3442 terminates name string. */
|
|
3443 static char *
|
|
3444 scan_separators (char *name)
|
|
3445 {
|
|
3446 char sep = name[0];
|
|
3447 char *copyto = name;
|
|
3448 logical quoted = FALSE;
|
|
3449
|
|
3450 for (++name; *name != '\0'; ++name)
|
|
3451 {
|
|
3452 if (quoted)
|
|
3453 {
|
|
3454 if (*name == 't')
|
|
3455 *copyto++ = '\t';
|
|
3456 else if (*name == sep)
|
|
3457 *copyto++ = sep;
|
|
3458 else
|
|
3459 {
|
|
3460 /* Something else is quoted, so preserve the quote. */
|
|
3461 *copyto++ = '\\';
|
|
3462 *copyto++ = *name;
|
|
3463 }
|
|
3464 quoted = FALSE;
|
|
3465 }
|
|
3466 else if (*name == '\\')
|
|
3467 quoted = TRUE;
|
|
3468 else if (*name == sep)
|
|
3469 break;
|
|
3470 else
|
|
3471 *copyto++ = *name;
|
|
3472 }
|
|
3473
|
|
3474 /* Terminate copied string. */
|
|
3475 *copyto = '\0';
|
|
3476 return name;
|
|
3477 }
|
|
3478
|
|
3479 /* Turn a name, which is an ed-style (but Emacs syntax) regular
|
|
3480 expression, into a real regular expression by compiling it. */
|
|
3481 void
|
|
3482 add_regex (char *regexp_pattern)
|
|
3483 {
|
|
3484 char *name;
|
|
3485 const char *err;
|
|
3486 struct re_pattern_buffer *patbuf;
|
|
3487
|
|
3488 if (regexp_pattern == NULL)
|
|
3489 {
|
|
3490 /* Remove existing regexps. */
|
|
3491 num_patterns = 0;
|
|
3492 patterns = NULL;
|
|
3493 return;
|
|
3494 }
|
|
3495
|
|
3496 if (regexp_pattern[0] == '\0')
|
|
3497 {
|
|
3498 error ("missing regexp", 0);
|
|
3499 return;
|
|
3500 }
|
|
3501 if (regexp_pattern[strlen(regexp_pattern)-1] != regexp_pattern[0])
|
|
3502 {
|
|
3503 error ("%s: unterminated regexp", regexp_pattern);
|
|
3504 return;
|
|
3505 }
|
|
3506 name = scan_separators (regexp_pattern);
|
|
3507 if (regexp_pattern[0] == '\0')
|
|
3508 {
|
|
3509 error ("null regexp", 0);
|
|
3510 return;
|
|
3511 }
|
|
3512 (void) scan_separators (name);
|
|
3513
|
|
3514 patbuf = xnew (1, struct re_pattern_buffer);
|
|
3515 patbuf->translate = NULL;
|
|
3516 patbuf->fastmap = NULL;
|
|
3517 patbuf->buffer = NULL;
|
|
3518 patbuf->allocated = 0;
|
|
3519
|
|
3520 err = re_compile_pattern (regexp_pattern, strlen (regexp_pattern), patbuf);
|
|
3521 if (err != NULL)
|
|
3522 {
|
|
3523 error ("%s while compiling pattern", (void *) err);
|
|
3524 return;
|
|
3525 }
|
|
3526
|
|
3527 num_patterns += 1;
|
|
3528 if (num_patterns == 1)
|
|
3529 patterns = xnew (1, struct pattern);
|
|
3530 else
|
|
3531 patterns = ((struct pattern *)
|
|
3532 xrealloc (patterns,
|
|
3533 (num_patterns * sizeof (struct pattern))));
|
|
3534 patterns[num_patterns - 1].pattern = patbuf;
|
|
3535 patterns[num_patterns - 1].name_pattern = savestr (name);
|
|
3536 patterns[num_patterns - 1].error_signaled = FALSE;
|
|
3537 }
|
|
3538
|
|
3539 /*
|
|
3540 * Do the substitutions indicated by the regular expression and
|
|
3541 * arguments.
|
|
3542 */
|
|
3543 static char *
|
|
3544 substitute (char *in, char *out, struct re_registers *regs)
|
|
3545 {
|
|
3546 char *result = NULL, *t;
|
|
3547 int size = 0;
|
|
3548
|
|
3549 /* Pass 1: figure out how much size to allocate. */
|
|
3550 for (t = out; *t; ++t)
|
|
3551 {
|
|
3552 if (*t == '\\')
|
|
3553 {
|
|
3554 ++t;
|
|
3555 if (!*t)
|
|
3556 {
|
|
3557 fprintf (stderr, "%s: pattern subtitution ends prematurely\n",
|
|
3558 progname);
|
|
3559 return NULL;
|
|
3560 }
|
|
3561 if (isdigit (*t))
|
|
3562 {
|
|
3563 int dig = *t - '0';
|
|
3564 size += regs->end[dig] - regs->start[dig];
|
|
3565 }
|
|
3566 }
|
|
3567 }
|
|
3568
|
|
3569 /* Allocate space and do the substitutions. */
|
|
3570 result = xnew (size + 1, char);
|
|
3571 size = 0;
|
|
3572 for (; *out; ++out)
|
|
3573 {
|
|
3574 if (*out == '\\')
|
|
3575 {
|
|
3576 ++out;
|
|
3577 if (isdigit (*out))
|
|
3578 {
|
|
3579 /* Using "dig2" satisfies my debugger. Bleah. */
|
|
3580 int dig2 = *out - '0';
|
|
3581 strncpy (result + size, in + regs->start[dig2],
|
|
3582 regs->end[dig2] - regs->start[dig2]);
|
|
3583 size += regs->end[dig2] - regs->start[dig2];
|
|
3584 }
|
|
3585 else
|
|
3586 result[size++] = *out;
|
|
3587 }
|
|
3588 else
|
|
3589 result[size++] = *out;
|
|
3590 }
|
|
3591 result[size] = '\0';
|
|
3592
|
|
3593 return result;
|
|
3594 }
|
|
3595
|
|
3596 #endif /* ETAGS_REGEXPS */
|
|
3597 /* Initialize a linebuffer for use */
|
|
3598 void
|
|
3599 initbuffer (struct linebuffer *linebuffer)
|
|
3600 {
|
|
3601 linebuffer->size = 200;
|
|
3602 linebuffer->buffer = xnew (200, char);
|
|
3603 }
|
|
3604
|
|
3605 /*
|
|
3606 * Read a line of text from `stream' into `linebuffer'.
|
|
3607 * Return the number of characters read from `stream',
|
|
3608 * which is the length of the line including the newline, if any.
|
|
3609 */
|
|
3610 long
|
|
3611 readline_internal (struct linebuffer *linebuffer, FILE *stream)
|
|
3612 {
|
|
3613 char *buffer = linebuffer->buffer;
|
|
3614 register char *p = linebuffer->buffer;
|
|
3615 register char *pend;
|
|
3616 int chars_deleted;
|
|
3617
|
|
3618 pend = p + linebuffer->size; /* Separate to avoid 386/IX compiler bug. */
|
|
3619
|
|
3620 while (1)
|
|
3621 {
|
|
3622 register int c = getc (stream);
|
|
3623 if (p == pend)
|
|
3624 {
|
|
3625 linebuffer->size *= 2;
|
|
3626 buffer = (char *) xrealloc (buffer, linebuffer->size);
|
|
3627 p += buffer - linebuffer->buffer;
|
|
3628 pend = buffer + linebuffer->size;
|
|
3629 linebuffer->buffer = buffer;
|
|
3630 }
|
|
3631 if (c == EOF)
|
|
3632 {
|
|
3633 chars_deleted = 0;
|
|
3634 break;
|
|
3635 }
|
|
3636 if (c == '\n')
|
|
3637 {
|
|
3638 if (p > buffer && p[-1] == '\r')
|
|
3639 {
|
|
3640 *--p = '\0';
|
|
3641 chars_deleted = 2;
|
|
3642 }
|
|
3643 else
|
|
3644 {
|
|
3645 *p = '\0';
|
|
3646 chars_deleted = 1;
|
|
3647 }
|
|
3648 break;
|
|
3649 }
|
|
3650 *p++ = c;
|
|
3651 }
|
|
3652
|
|
3653 return p - buffer + chars_deleted;
|
|
3654 }
|
|
3655
|
|
3656 /*
|
|
3657 * Like readline_internal, above, but try to match the input
|
|
3658 * line against any existing regular expressions.
|
|
3659 */
|
|
3660 long
|
|
3661 readline (struct linebuffer *linebuffer, FILE *stream)
|
|
3662 {
|
|
3663 /* Read new line. */
|
|
3664 #ifdef ETAGS_REGEXPS
|
|
3665 int i;
|
|
3666 #endif
|
|
3667 long result = readline_internal (linebuffer, stream);
|
|
3668
|
|
3669 #ifdef ETAGS_REGEXPS
|
|
3670 /* Match against all listed patterns. */
|
|
3671 for (i = 0; i < num_patterns; ++i)
|
|
3672 {
|
|
3673 int match = re_match (patterns[i].pattern, linebuffer->buffer,
|
|
3674 (int)result, 0, &patterns[i].regs);
|
|
3675 switch (match)
|
|
3676 {
|
|
3677 case -2:
|
|
3678 /* Some error. */
|
|
3679 if (!patterns[i].error_signaled)
|
|
3680 {
|
|
3681 /* To avoid casting an int to a pointer, format the string
|
|
3682 * here, and pass the address of the string to `error'. */
|
|
3683 char int_string[12];
|
|
3684
|
|
3685 sprintf(int_string, "%d", i);
|
|
3686 error ("error while matching pattern %s", int_string);
|
|
3687 patterns[i].error_signaled = TRUE;
|
|
3688 }
|
|
3689 break;
|
|
3690 case -1:
|
|
3691 /* No match. */
|
|
3692 break;
|
|
3693 default:
|
|
3694 /* Match occurred. Construct a tag. */
|
|
3695 if (patterns[i].name_pattern[0] != '\0')
|
|
3696 {
|
|
3697 /* Make a named tag. */
|
|
3698 char *name = substitute (linebuffer->buffer,
|
|
3699 patterns[i].name_pattern,
|
|
3700 &patterns[i].regs);
|
|
3701 if (name != NULL)
|
|
3702 pfnote (name, TRUE,
|
|
3703 linebuffer->buffer, match, lineno, linecharno);
|
|
3704 }
|
|
3705 else
|
|
3706 {
|
|
3707 /* Make an unnamed tag. */
|
|
3708 pfnote (NULL, TRUE,
|
|
3709 linebuffer->buffer, match, lineno, linecharno);
|
|
3710 }
|
|
3711 break;
|
|
3712 }
|
|
3713 }
|
|
3714 #endif /* ETAGS_REGEXPS */
|
|
3715
|
|
3716 return result;
|
|
3717 }
|
|
3718
|
|
3719 /*
|
|
3720 * Read a file, but do no processing. This is used to do regexp
|
|
3721 * matching on files that have no language defined.
|
|
3722 */
|
|
3723 void
|
|
3724 just_read_file (FILE *inf)
|
|
3725 {
|
|
3726 while (!feof (inf))
|
|
3727 {
|
|
3728 ++lineno;
|
|
3729 linecharno = charno;
|
|
3730 charno += readline (&lb, inf) + 1;
|
|
3731 }
|
|
3732 }
|
|
3733
|
|
3734
|
|
3735 /*
|
|
3736 * Return a pointer to a space of size strlen(cp)+1 allocated
|
|
3737 * with xnew where the string CP has been copied.
|
|
3738 */
|
|
3739 char *
|
|
3740 savestr (CONST char *cp)
|
|
3741 {
|
|
3742 return savenstr (cp, strlen (cp));
|
|
3743 }
|
|
3744
|
|
3745 /*
|
|
3746 * Return a pointer to a space of size LEN+1 allocated with xnew where
|
|
3747 * the string CP has been copied for at most the first LEN characters.
|
|
3748 */
|
|
3749 char *
|
|
3750 savenstr (CONST char *cp, int len)
|
|
3751 {
|
|
3752 register char *dp;
|
|
3753
|
|
3754 dp = xnew (len + 1, char);
|
|
3755 strncpy (dp, cp, len);
|
|
3756 dp[len] = '\0';
|
|
3757 return dp;
|
|
3758 }
|
|
3759
|
|
3760 /*
|
|
3761 * Return the ptr in sp at which the character c last
|
|
3762 * appears; NULL if not found
|
|
3763 *
|
|
3764 * Identical to System V strrchr, included for portability.
|
|
3765 */
|
|
3766 char *
|
|
3767 etags_strrchr (CONST char *sp, char c)
|
|
3768 {
|
|
3769 register CONST char *r;
|
|
3770
|
|
3771 r = NULL;
|
|
3772 do
|
|
3773 {
|
|
3774 if (*sp == c)
|
|
3775 r = sp;
|
|
3776 } while (*sp++);
|
|
3777 return (char *)r;
|
|
3778 }
|
|
3779
|
|
3780
|
|
3781 /*
|
|
3782 * Return the ptr in sp at which the character c first
|
|
3783 * appears; NULL if not found
|
|
3784 *
|
|
3785 * Identical to System V strchr, included for portability.
|
|
3786 */
|
|
3787 char *
|
|
3788 etags_strchr (CONST char *sp, char c)
|
|
3789 {
|
|
3790 do
|
|
3791 {
|
|
3792 if (*sp == c)
|
|
3793 return (char *)sp;
|
|
3794 } while (*sp++);
|
|
3795 return NULL;
|
|
3796 }
|
|
3797
|
|
3798 /* Print error message and exit. */
|
|
3799 void
|
|
3800 fatal (CONST char *s1, CONST char *s2)
|
|
3801 {
|
|
3802 error (s1, s2);
|
|
3803 exit (BAD);
|
|
3804 }
|
|
3805
|
|
3806 void
|
|
3807 pfatal (CONST char *s1)
|
|
3808 {
|
|
3809 perror (s1);
|
|
3810 exit (BAD);
|
|
3811 }
|
|
3812
|
|
3813 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
|
|
3814 void
|
|
3815 error (CONST char *s1, CONST void *s2)
|
|
3816 {
|
|
3817 fprintf (stderr, "%s: ", progname);
|
|
3818 fprintf (stderr, s1, s2);
|
|
3819 fprintf (stderr, "\n");
|
|
3820 }
|
|
3821
|
|
3822 /* Return a newly-allocated string whose contents
|
|
3823 concatenate those of s1, s2, s3. */
|
|
3824 char *
|
|
3825 concat (CONST char *s1, CONST char *s2, CONST char *s3)
|
|
3826 {
|
|
3827 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
|
|
3828 char *result = xnew (len1 + len2 + len3 + 1, char);
|
|
3829
|
|
3830 strcpy (result, s1);
|
|
3831 strcpy (result + len1, s2);
|
|
3832 strcpy (result + len1 + len2, s3);
|
|
3833 result[len1 + len2 + len3] = '\0';
|
|
3834
|
|
3835 return result;
|
|
3836 }
|
|
3837
|
|
3838 /* Does the same work as the system V getcwd, but does not need to
|
|
3839 guess the buffer size in advance. */
|
|
3840 /* Does the same work as the system V getcwd, but does not need to
|
|
3841 guess the buffer size in advance. */
|
|
3842 char *
|
|
3843 etags_getcwd (void)
|
|
3844 {
|
|
3845 #ifdef DOS_NT
|
|
3846 char *p, path[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */
|
|
3847
|
|
3848 getwd (path);
|
|
3849 p = path;
|
|
3850 while (*p)
|
|
3851 if (*p == '\\')
|
|
3852 *p++ = '/';
|
|
3853 else
|
|
3854 *p++ = lowcase (*p);
|
|
3855
|
|
3856 return strdup (path);
|
|
3857 #else /* not DOS_NT */
|
|
3858 #if HAVE_GETCWD
|
|
3859 int bufsize = 200;
|
|
3860 char *path = xnew (bufsize, char);
|
|
3861
|
|
3862 while (getcwd (path, bufsize) == NULL)
|
|
3863 {
|
|
3864 if (errno != ERANGE)
|
|
3865 pfatal ("getcwd");
|
|
3866 bufsize *= 2;
|
|
3867 path = xnew (bufsize, char);
|
|
3868 }
|
|
3869
|
|
3870 return path;
|
|
3871 #else /* not DOS_NT and not HAVE_GETCWD */
|
|
3872 struct linebuffer path;
|
|
3873 FILE *paype;
|
|
3874
|
|
3875 initbuffer (&path);
|
|
3876 paype = (FILE *) popen ("pwd 2>/dev/null", "r");
|
|
3877 if (paype == NULL || readline_internal (&path, paype) == 0)
|
|
3878 pfatal ("pwd");
|
|
3879 pclose (paype);
|
|
3880
|
|
3881 return path.buffer;
|
|
3882 #endif /* not HAVE_GETCWD */
|
|
3883 #endif /* not DOS_NT */
|
|
3884 }
|
|
3885
|
|
3886 /* Return a newly allocated string containing the filename
|
|
3887 of FILE relative to the absolute directory DIR (which
|
|
3888 should end with a slash). */
|
|
3889 char *
|
|
3890 relative_filename (CONST char *file, CONST char *dir)
|
|
3891 {
|
|
3892 char *fp;
|
|
3893 CONST char *dp;
|
|
3894 char *abbs, *res;
|
|
3895
|
|
3896 /* Find the common root of file and dir. */
|
|
3897 abbs = absolute_filename (file, cwd);
|
|
3898 fp = abbs;
|
|
3899 dp = dir;
|
|
3900 while (*fp++ == *dp++)
|
|
3901 continue;
|
|
3902 do
|
|
3903 {
|
|
3904 fp--;
|
|
3905 dp--;
|
|
3906 }
|
|
3907 while (*fp != '/');
|
|
3908
|
|
3909 /* Build a sequence of "../" strings for the resulting relative filename. */
|
|
3910 for (dp = etags_strchr (dp + 1, '/'), res = (char *) "";
|
|
3911 dp != NULL;
|
|
3912 dp = etags_strchr (dp + 1, '/'))
|
|
3913 {
|
|
3914 res = concat (res, "../", "");
|
|
3915 }
|
|
3916
|
|
3917 /* Add the filename relative to the common root of file and dir. */
|
|
3918 res = concat (res, fp + 1, "");
|
|
3919 free (abbs);
|
|
3920
|
|
3921 return res;
|
|
3922 }
|
|
3923
|
|
3924 /* Return a newly allocated string containing the
|
|
3925 absolute filename of FILE given CWD (which should
|
|
3926 end with a slash). */
|
|
3927 char *
|
|
3928 absolute_filename (CONST char *file, CONST char *cwwd)
|
|
3929 {
|
|
3930 char *slashp, *cp, *res;
|
|
3931
|
|
3932 if (absolutefn (file))
|
|
3933 res = concat (file, "", "");
|
|
3934 else
|
|
3935 res = concat (cwwd, file, "");
|
|
3936
|
|
3937 /* Delete the "/dirname/.." and "/." substrings. */
|
|
3938 slashp = etags_strchr (res, '/');
|
|
3939 while (slashp != NULL && slashp[0] != '\0')
|
|
3940 {
|
|
3941 if (slashp[1] == '.')
|
|
3942 {
|
|
3943 if (slashp[2] == '.'
|
|
3944 && (slashp[3] == '/' || slashp[3] == '\0'))
|
|
3945 {
|
|
3946 cp = slashp;
|
|
3947 do
|
|
3948 cp--;
|
|
3949 while (cp >= res && *cp != '/');
|
|
3950 if (*cp == '/')
|
|
3951 {
|
|
3952 strcpy (cp, slashp + 3);
|
|
3953 }
|
|
3954 else /* else (cp == res) */
|
|
3955 {
|
|
3956 if (slashp[3] != '\0')
|
|
3957 strcpy (cp, slashp + 4);
|
|
3958 else
|
|
3959 return (char *) ".";
|
|
3960 }
|
|
3961 slashp = cp;
|
|
3962 continue;
|
|
3963 }
|
|
3964 else if (slashp[2] == '/' || slashp[2] == '\0')
|
|
3965 {
|
|
3966 strcpy (slashp, slashp + 2);
|
|
3967 continue;
|
|
3968 }
|
|
3969 }
|
|
3970
|
|
3971 slashp = etags_strchr (slashp + 1, '/');
|
|
3972 }
|
|
3973
|
|
3974 return res;
|
|
3975 }
|
|
3976
|
|
3977 /* Return a newly allocated string containing the absolute
|
|
3978 filename of dir where FILE resides given CWD (which should
|
|
3979 end with a slash). */
|
|
3980 char *
|
|
3981 absolute_dirname (char *file, CONST char *cwwd)
|
|
3982 {
|
|
3983 char *slashp, *res;
|
|
3984 char save;
|
|
3985
|
|
3986 slashp = etags_strrchr (file, '/');
|
|
3987 if (slashp == NULL)
|
|
3988 return (char *) cwwd;
|
|
3989 save = slashp[1];
|
|
3990 slashp[1] = '\0';
|
|
3991 res = absolute_filename (file, cwwd);
|
|
3992 slashp[1] = save;
|
|
3993
|
|
3994 return res;
|
|
3995 }
|
|
3996
|
|
3997 /* Like malloc but get fatal error if memory is exhausted. */
|
|
3998 void *
|
|
3999 xmalloc (unsigned int size)
|
|
4000 {
|
|
4001 void *result = malloc (size);
|
|
4002 if (result == NULL)
|
|
4003 fatal ("virtual memory exhausted", 0);
|
|
4004 return result;
|
|
4005 }
|
|
4006
|
|
4007 void *
|
|
4008 xrealloc (void *ptr, unsigned int size)
|
|
4009 {
|
|
4010 void *result = realloc (ptr, size);
|
|
4011 if (result == NULL)
|
|
4012 fatal ("virtual memory exhausted", 0);
|
|
4013 return result;
|
|
4014 }
|