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