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