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