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