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