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