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