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