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