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