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