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