1 /* Tags file maker to go with GNU Emacs -*- coding: latin-1 -*-
3 Copyright (C) 1984 The Regents of the University of California
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the
14 3. Neither the name of the University nor the names of its
15 contributors may be used to endorse or promote products derived
16 from this software without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 Copyright (C) 1984, 1987-1989, 1993-1995, 1998-2011
32 Free Software Foundation, Inc.
34 This file is not considered part of GNU Emacs.
36 This program is free software: you can redistribute it and/or modify
37 it under the terms of the GNU General Public License as published by
38 the Free Software Foundation, either version 3 of the License, or
39 (at your option) any later version.
41 This program is distributed in the hope that it will be useful,
42 but WITHOUT ANY WARRANTY; without even the implied warranty of
43 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 GNU General Public License for more details.
46 You should have received a copy of the GNU General Public License
47 along with this program. If not, see <http://www.gnu.org/licenses/>. */
50 /* NB To comply with the above BSD license, copyright information is
51 reproduced in etc/ETAGS.README. That file should be updated when the
54 To the best of our knowledge, this code was originally based on the
55 ctags.c distributed with BSD4.2, which was copyrighted by the
56 University of California, as described above. */
61 * 1983 Ctags originally by Ken Arnold.
62 * 1984 Fortran added by Jim Kleckner.
63 * 1984 Ed Pelegri-Llopart added C typedefs.
64 * 1985 Emacs TAGS format by Richard Stallman.
65 * 1989 Sam Kendall added C++.
66 * 1992 Joseph B. Wells improved C and C++ parsing.
67 * 1993 Francesco Potortì reorganized C and C++.
68 * 1994 Line-by-line regexp tags by Tom Tromey.
69 * 2001 Nested classes by Francesco Potortì (concept by Mykola Dzyuba).
70 * 2002 #line directives by Francesco Potortì.
72 * Francesco Potortì <pot@gnu.org> has maintained and improved it since 1993.
76 * If you want to add support for a new language, start by looking at the LUA
77 * language, which is the simplest. Alternatively, consider distributing etags
78 * together with a configuration file containing regexp definitions for etags.
81 char pot_etags_version
[] = "@(#) pot revision number is 17.38.1.4";
91 # define NDEBUG /* disable assert */
96 /* On some systems, Emacs defines static as nothing for the sake
97 of unexec. We don't want that here since we don't use unexec. */
99 # ifndef PTR /* for XEmacs */
102 #else /* no config.h */
103 # if defined(__STDC__) && (__STDC__ || defined(__SUNPRO_C))
104 # define PTR void * /* for generic pointers */
105 # else /* not standard C */
106 # define const /* remove const for old compilers' sake */
107 # define PTR long * /* don't use void* */
109 #endif /* !HAVE_CONFIG_H */
112 # define _GNU_SOURCE 1 /* enables some compiler checks on GNU */
115 /* WIN32_NATIVE is for XEmacs.
116 MSDOS, WINDOWSNT, DOS_NT are for Emacs. */
121 #endif /* WIN32_NATIVE */
127 # include <sys/param.h>
129 # ifndef HAVE_CONFIG_H
131 # include <sys/config.h>
143 # define MAXPATHLEN _MAX_PATH
149 # endif /* undef HAVE_GETCWD */
150 #else /* not WINDOWSNT */
154 # else /* no standard C headers */
155 extern char *getenv (const char *);
156 extern char *strcpy (char *, const char *);
157 extern char *strncpy (char *, const char *, unsigned long);
158 extern char *strcat (char *, const char *);
159 extern char *strncat (char *, const char *, unsigned long);
160 extern int strcmp (const char *, const char *);
161 extern int strncmp (const char *, const char *, unsigned long);
162 extern int system (const char *);
163 extern unsigned long strlen (const char *);
164 extern void *malloc (unsigned long);
165 extern void *realloc (void *, unsigned long);
166 extern void exit (int);
167 extern void free (void *);
168 extern void *memmove (void *, const void *, unsigned long);
169 # define EXIT_SUCCESS 0
170 # define EXIT_FAILURE 1
172 #endif /* !WINDOWSNT */
175 #ifndef HAVE_UNISTD_H
176 # if defined (HAVE_GETCWD) && !defined (WINDOWSNT)
177 extern char *getcwd (char *buf
, size_t size
);
179 #endif /* HAVE_UNISTD_H */
184 #include <sys/types.h>
185 #include <sys/stat.h>
189 # undef assert /* some systems have a buggy assert.h */
190 # define assert(x) ((void) 0)
193 #ifdef NO_LONG_OPTIONS /* define this if you don't have GNU getopt */
194 # define NO_LONG_OPTIONS TRUE
195 # define getopt_long(argc,argv,optstr,lopts,lind) getopt (argc, argv, optstr)
197 extern int optind
, opterr
;
199 # define NO_LONG_OPTIONS FALSE
201 #endif /* NO_LONG_OPTIONS */
203 #ifndef HAVE_CONFIG_H /* this is a standalone compilation */
204 # ifdef __CYGWIN__ /* compiling on Cygwin */
206 the regex
.h distributed with Cygwin is
not compatible with etags
, alas
!
207 If you want regular expression support
, you should
delete this notice
and
208 arrange to use the GNU regex
.h
and regex
.c
.
213 /* Define CTAGS to make the program "ctags" compatible with the usual one.
214 Leave it undefined to make the program "etags", which makes emacs-style
215 tag tables and tags typedefs, #defines and struct/union/enum by default. */
223 #define streq(s,t) (assert((s)!=NULL || (t)!=NULL), !strcmp (s, t))
224 #define strcaseeq(s,t) (assert((s)!=NULL && (t)!=NULL), !etags_strcasecmp (s, t))
225 #define strneq(s,t,n) (assert((s)!=NULL || (t)!=NULL), !strncmp (s, t, n))
226 #define strncaseeq(s,t,n) (assert((s)!=NULL && (t)!=NULL), !etags_strncasecmp (s, t, n))
228 #define CHARS 256 /* 2^sizeof(char) */
229 #define CHAR(x) ((unsigned int)(x) & (CHARS - 1))
230 #define iswhite(c) (_wht[CHAR(c)]) /* c is white (see white) */
231 #define notinname(c) (_nin[CHAR(c)]) /* c is not in a name (see nonam) */
232 #define begtoken(c) (_btk[CHAR(c)]) /* c can start token (see begtk) */
233 #define intoken(c) (_itk[CHAR(c)]) /* c can be in token (see midtk) */
234 #define endtoken(c) (_etk[CHAR(c)]) /* c ends tokens (see endtk) */
236 #define ISALNUM(c) isalnum (CHAR(c))
237 #define ISALPHA(c) isalpha (CHAR(c))
238 #define ISDIGIT(c) isdigit (CHAR(c))
239 #define ISLOWER(c) islower (CHAR(c))
241 #define lowcase(c) tolower (CHAR(c))
245 * xnew, xrnew -- allocate, reallocate storage
247 * SYNOPSIS: Type *xnew (int n, Type);
248 * void xrnew (OldPointer, int n, Type);
251 # include "chkmalloc.h"
252 # define xnew(n,Type) ((Type *) trace_malloc (__FILE__, __LINE__, \
253 (n) * sizeof (Type)))
254 # define xrnew(op,n,Type) ((op) = (Type *) trace_realloc (__FILE__, __LINE__, \
255 (char *) (op), (n) * sizeof (Type)))
257 # define xnew(n,Type) ((Type *) xmalloc ((n) * sizeof (Type)))
258 # define xrnew(op,n,Type) ((op) = (Type *) xrealloc ( \
259 (char *) (op), (n) * sizeof (Type)))
264 typedef void Lang_function (FILE *);
268 const char *suffix
; /* file name suffix for this compressor */
269 const char *command
; /* takes one arg and decompresses to stdout */
274 const char *name
; /* language name */
275 const char *help
; /* detailed help for the language */
276 Lang_function
*function
; /* parse function */
277 const char **suffixes
; /* name suffixes of this language's files */
278 const char **filenames
; /* names of this language's files */
279 const char **interpreters
; /* interpreters for this language */
280 bool metasource
; /* source used to generate other sources */
285 struct fdesc
*next
; /* for the linked list */
286 char *infname
; /* uncompressed input file name */
287 char *infabsname
; /* absolute uncompressed input file name */
288 char *infabsdir
; /* absolute dir of input file */
289 char *taggedfname
; /* file name to write in tagfile */
290 language
*lang
; /* language of file */
291 char *prop
; /* file properties to write in tagfile */
292 bool usecharno
; /* etags tags shall contain char number */
293 bool written
; /* entry written in the tags file */
296 typedef struct node_st
297 { /* sorting structure */
298 struct node_st
*left
, *right
; /* left and right sons */
299 fdesc
*fdp
; /* description of file to whom tag belongs */
300 char *name
; /* tag name */
301 char *regex
; /* search regexp */
302 bool valid
; /* write this tag on the tag file */
303 bool is_func
; /* function tag: use regexp in CTAGS mode */
304 bool been_warned
; /* warning already given for duplicated tag */
305 int lno
; /* line number tag is on */
306 long cno
; /* character number line starts on */
310 * A `linebuffer' is a structure which holds a line of text.
311 * `readline_internal' reads a line from a stream into a linebuffer
312 * and works regardless of the length of the line.
313 * SIZE is the size of BUFFER, LEN is the length of the string in
314 * BUFFER after readline reads it.
323 /* Used to support mixing of --lang and file names. */
327 at_language
, /* a language specification */
328 at_regexp
, /* a regular expression */
329 at_filename
, /* a file name */
330 at_stdin
, /* read from stdin here */
331 at_end
/* stop parsing the list */
332 } arg_type
; /* argument type */
333 language
*lang
; /* language associated with the argument */
334 char *what
; /* the argument itself */
337 /* Structure defining a regular expression. */
338 typedef struct regexp
340 struct regexp
*p_next
; /* pointer to next in list */
341 language
*lang
; /* if set, use only for this language */
342 char *pattern
; /* the regexp pattern */
343 char *name
; /* tag name */
344 struct re_pattern_buffer
*pat
; /* the compiled pattern */
345 struct re_registers regs
; /* re registers */
346 bool error_signaled
; /* already signaled for this regexp */
347 bool force_explicit_name
; /* do not allow implict tag name */
348 bool ignore_case
; /* ignore case when matching */
349 bool multi_line
; /* do a multi-line match on the whole file */
353 /* Many compilers barf on this:
354 Lang_function Ada_funcs;
355 so let's write it this way */
356 static void Ada_funcs (FILE *);
357 static void Asm_labels (FILE *);
358 static void C_entries (int c_ext
, FILE *);
359 static void default_C_entries (FILE *);
360 static void plain_C_entries (FILE *);
361 static void Cjava_entries (FILE *);
362 static void Cobol_paragraphs (FILE *);
363 static void Cplusplus_entries (FILE *);
364 static void Cstar_entries (FILE *);
365 static void Erlang_functions (FILE *);
366 static void Forth_words (FILE *);
367 static void Fortran_functions (FILE *);
368 static void HTML_labels (FILE *);
369 static void Lisp_functions (FILE *);
370 static void Lua_functions (FILE *);
371 static void Makefile_targets (FILE *);
372 static void Pascal_functions (FILE *);
373 static void Perl_functions (FILE *);
374 static void PHP_functions (FILE *);
375 static void PS_functions (FILE *);
376 static void Prolog_functions (FILE *);
377 static void Python_functions (FILE *);
378 static void Scheme_functions (FILE *);
379 static void TeX_commands (FILE *);
380 static void Texinfo_nodes (FILE *);
381 static void Yacc_entries (FILE *);
382 static void just_read_file (FILE *);
384 static void print_language_names (void);
385 static void print_version (void);
386 static void print_help (argument
*);
387 int main (int, char **);
389 static compressor
*get_compressor_from_suffix (char *, char **);
390 static language
*get_language_from_langname (const char *);
391 static language
*get_language_from_interpreter (char *);
392 static language
*get_language_from_filename (char *, bool);
393 static void readline (linebuffer
*, FILE *);
394 static long readline_internal (linebuffer
*, FILE *);
395 static bool nocase_tail (const char *);
396 static void get_tag (char *, char **);
398 static void analyse_regex (char *);
399 static void free_regexps (void);
400 static void regex_tag_multiline (void);
401 static void error (const char *, const char *);
402 static void suggest_asking_for_help (void) NO_RETURN
;
403 void fatal (const char *, const char *) NO_RETURN
;
404 static void pfatal (const char *) NO_RETURN
;
405 static void add_node (node
*, node
**);
407 static void init (void);
408 static void process_file_name (char *, language
*);
409 static void process_file (FILE *, char *, language
*);
410 static void find_entries (FILE *);
411 static void free_tree (node
*);
412 static void free_fdesc (fdesc
*);
413 static void pfnote (char *, bool, char *, int, int, long);
414 static void make_tag (const char *, int, bool, char *, int, int, long);
415 static void invalidate_nodes (fdesc
*, node
**);
416 static void put_entries (node
*);
418 static char *concat (const char *, const char *, const char *);
419 static char *skip_spaces (char *);
420 static char *skip_non_spaces (char *);
421 static char *savenstr (const char *, int);
422 static char *savestr (const char *);
423 static char *etags_strchr (const char *, int);
424 static char *etags_strrchr (const char *, int);
425 static int etags_strcasecmp (const char *, const char *);
426 static int etags_strncasecmp (const char *, const char *, int);
427 static char *etags_getcwd (void);
428 static char *relative_filename (char *, char *);
429 static char *absolute_filename (char *, char *);
430 static char *absolute_dirname (char *, char *);
431 static bool filename_is_absolute (char *f
);
432 static void canonicalize_filename (char *);
433 static void linebuffer_init (linebuffer
*);
434 static void linebuffer_setlen (linebuffer
*, int);
435 static PTR
xmalloc (unsigned int);
436 static PTR
xrealloc (char *, unsigned int);
439 static char searchar
= '/'; /* use /.../ searches */
441 static char *tagfile
; /* output file */
442 static char *progname
; /* name this program was invoked with */
443 static char *cwd
; /* current working directory */
444 static char *tagfiledir
; /* directory of tagfile */
445 static FILE *tagf
; /* ioptr for tags file */
447 static fdesc
*fdhead
; /* head of file description list */
448 static fdesc
*curfdp
; /* current file description */
449 static int lineno
; /* line number of current line */
450 static long charno
; /* current character number */
451 static long linecharno
; /* charno of start of current line */
452 static char *dbp
; /* pointer to start of current tag */
454 static const int invalidcharno
= -1;
456 static node
*nodehead
; /* the head of the binary tree of tags */
457 static node
*last_node
; /* the last node created */
459 static linebuffer lb
; /* the current line */
460 static linebuffer filebuf
; /* a buffer containing the whole file */
461 static linebuffer token_name
; /* a buffer containing a tag name */
463 /* boolean "functions" (see init) */
464 static bool _wht
[CHARS
], _nin
[CHARS
], _itk
[CHARS
], _btk
[CHARS
], _etk
[CHARS
];
467 *white
= " \f\t\n\r\v",
469 *nonam
= " \f\t\n\r()=,;", /* look at make_tag before modifying! */
470 /* token ending chars */
471 *endtk
= " \t\n\r\"'#()[]{}=-+%*/&|^~!<>;,.:?",
472 /* token starting chars */
473 *begtk
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~@",
474 /* valid in-token chars */
475 *midtk
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789";
477 static bool append_to_tagfile
; /* -a: append to tags */
478 /* The next five default to TRUE in C and derived languages. */
479 static bool typedefs
; /* -t: create tags for C and Ada typedefs */
480 static bool typedefs_or_cplusplus
; /* -T: create tags for C typedefs, level */
481 /* 0 struct/enum/union decls, and C++ */
482 /* member functions. */
483 static bool constantypedefs
; /* -d: create tags for C #define, enum */
484 /* constants and variables. */
485 /* -D: opposite of -d. Default under ctags. */
486 static bool globals
; /* create tags for global variables */
487 static bool members
; /* create tags for C member variables */
488 static bool declarations
; /* --declarations: tag them and extern in C&Co*/
489 static bool no_line_directive
; /* ignore #line directives (undocumented) */
490 static bool no_duplicates
; /* no duplicate tags for ctags (undocumented) */
491 static bool update
; /* -u: update tags */
492 static bool vgrind_style
; /* -v: create vgrind style index output */
493 static bool no_warnings
; /* -w: suppress warnings (undocumented) */
494 static bool cxref_style
; /* -x: create cxref style output */
495 static bool cplusplus
; /* .[hc] means C++, not C (undocumented) */
496 static bool ignoreindent
; /* -I: ignore indentation in C */
497 static bool packages_only
; /* --packages-only: in Ada, only tag packages*/
499 /* STDIN is defined in LynxOS system headers */
504 #define STDIN 0x1001 /* returned by getopt_long on --parse-stdin */
505 static bool parsing_stdin
; /* --parse-stdin used */
507 static regexp
*p_head
; /* list of all regexps */
508 static bool need_filebuf
; /* some regexes are multi-line */
510 static struct option longopts
[] =
512 { "append", no_argument
, NULL
, 'a' },
513 { "packages-only", no_argument
, &packages_only
, TRUE
},
514 { "c++", no_argument
, NULL
, 'C' },
515 { "declarations", no_argument
, &declarations
, TRUE
},
516 { "no-line-directive", no_argument
, &no_line_directive
, TRUE
},
517 { "no-duplicates", no_argument
, &no_duplicates
, TRUE
},
518 { "help", no_argument
, NULL
, 'h' },
519 { "help", no_argument
, NULL
, 'H' },
520 { "ignore-indentation", no_argument
, NULL
, 'I' },
521 { "language", required_argument
, NULL
, 'l' },
522 { "members", no_argument
, &members
, TRUE
},
523 { "no-members", no_argument
, &members
, FALSE
},
524 { "output", required_argument
, NULL
, 'o' },
525 { "regex", required_argument
, NULL
, 'r' },
526 { "no-regex", no_argument
, NULL
, 'R' },
527 { "ignore-case-regex", required_argument
, NULL
, 'c' },
528 { "parse-stdin", required_argument
, NULL
, STDIN
},
529 { "version", no_argument
, NULL
, 'V' },
531 #if CTAGS /* Ctags options */
532 { "backward-search", no_argument
, NULL
, 'B' },
533 { "cxref", no_argument
, NULL
, 'x' },
534 { "defines", no_argument
, NULL
, 'd' },
535 { "globals", no_argument
, &globals
, TRUE
},
536 { "typedefs", no_argument
, NULL
, 't' },
537 { "typedefs-and-c++", no_argument
, NULL
, 'T' },
538 { "update", no_argument
, NULL
, 'u' },
539 { "vgrind", no_argument
, NULL
, 'v' },
540 { "no-warn", no_argument
, NULL
, 'w' },
542 #else /* Etags options */
543 { "no-defines", no_argument
, NULL
, 'D' },
544 { "no-globals", no_argument
, &globals
, FALSE
},
545 { "include", required_argument
, NULL
, 'i' },
550 static compressor compressors
[] =
552 { "z", "gzip -d -c"},
553 { "Z", "gzip -d -c"},
554 { "gz", "gzip -d -c"},
555 { "GZ", "gzip -d -c"},
556 { "bz2", "bzip2 -d -c" },
557 { "xz", "xz -d -c" },
566 static const char *Ada_suffixes
[] =
567 { "ads", "adb", "ada", NULL
};
568 static const char Ada_help
[] =
569 "In Ada code, functions, procedures, packages, tasks and types are\n\
570 tags. Use the `--packages-only' option to create tags for\n\
572 Ada tag names have suffixes indicating the type of entity:\n\
573 Entity type: Qualifier:\n\
574 ------------ ----------\n\
581 Thus, `M-x find-tag <RET> bidule/b <RET>' will go directly to the\n\
582 body of the package `bidule', while `M-x find-tag <RET> bidule <RET>'\n\
583 will just search for any tag `bidule'.";
586 static const char *Asm_suffixes
[] =
587 { "a", /* Unix assembler */
588 "asm", /* Microcontroller assembly */
589 "def", /* BSO/Tasking definition includes */
590 "inc", /* Microcontroller include files */
591 "ins", /* Microcontroller include files */
592 "s", "sa", /* Unix assembler */
593 "S", /* cpp-processed Unix assembler */
594 "src", /* BSO/Tasking C compiler output */
597 static const char Asm_help
[] =
598 "In assembler code, labels appearing at the beginning of a line,\n\
599 followed by a colon, are tags.";
602 /* Note that .c and .h can be considered C++, if the --c++ flag was
603 given, or if the `class' or `template' keywords are met inside the file.
604 That is why default_C_entries is called for these. */
605 static const char *default_C_suffixes
[] =
607 #if CTAGS /* C help for Ctags */
608 static const char default_C_help
[] =
609 "In C code, any C function is a tag. Use -t to tag typedefs.\n\
610 Use -T to tag definitions of `struct', `union' and `enum'.\n\
611 Use -d to tag `#define' macro definitions and `enum' constants.\n\
612 Use --globals to tag global variables.\n\
613 You can tag function declarations and external variables by\n\
614 using `--declarations', and struct members by using `--members'.";
615 #else /* C help for Etags */
616 static const char default_C_help
[] =
617 "In C code, any C function or typedef is a tag, and so are\n\
618 definitions of `struct', `union' and `enum'. `#define' macro\n\
619 definitions and `enum' constants are tags unless you specify\n\
620 `--no-defines'. Global variables are tags unless you specify\n\
621 `--no-globals' and so are struct members unless you specify\n\
622 `--no-members'. Use of `--no-globals', `--no-defines' and\n\
623 `--no-members' can make the tags table file much smaller.\n\
624 You can tag function declarations and external variables by\n\
625 using `--declarations'.";
626 #endif /* C help for Ctags and Etags */
628 static const char *Cplusplus_suffixes
[] =
629 { "C", "c++", "cc", "cpp", "cxx", "H", "h++", "hh", "hpp", "hxx",
630 "M", /* Objective C++ */
631 "pdb", /* Postscript with C syntax */
633 static const char Cplusplus_help
[] =
634 "In C++ code, all the tag constructs of C code are tagged. (Use\n\
635 --help --lang=c --lang=c++ for full help.)\n\
636 In addition to C tags, member functions are also recognized. Member\n\
637 variables are recognized unless you use the `--no-members' option.\n\
638 Tags for variables and functions in classes are named `CLASS::VARIABLE'\n\
639 and `CLASS::FUNCTION'. `operator' definitions have tag names like\n\
642 static const char *Cjava_suffixes
[] =
644 static char Cjava_help
[] =
645 "In Java code, all the tags constructs of C and C++ code are\n\
646 tagged. (Use --help --lang=c --lang=c++ --lang=java for full help.)";
649 static const char *Cobol_suffixes
[] =
650 { "COB", "cob", NULL
};
651 static char Cobol_help
[] =
652 "In Cobol code, tags are paragraph names; that is, any word\n\
653 starting in column 8 and followed by a period.";
655 static const char *Cstar_suffixes
[] =
656 { "cs", "hs", NULL
};
658 static const char *Erlang_suffixes
[] =
659 { "erl", "hrl", NULL
};
660 static const char Erlang_help
[] =
661 "In Erlang code, the tags are the functions, records and macros\n\
662 defined in the file.";
664 const char *Forth_suffixes
[] =
665 { "fth", "tok", NULL
};
666 static const char Forth_help
[] =
667 "In Forth code, tags are words defined by `:',\n\
668 constant, code, create, defer, value, variable, buffer:, field.";
670 static const char *Fortran_suffixes
[] =
671 { "F", "f", "f90", "for", NULL
};
672 static const char Fortran_help
[] =
673 "In Fortran code, functions, subroutines and block data are tags.";
675 static const char *HTML_suffixes
[] =
676 { "htm", "html", "shtml", NULL
};
677 static const char HTML_help
[] =
678 "In HTML input files, the tags are the `title' and the `h1', `h2',\n\
679 `h3' headers. Also, tags are `name=' in anchors and all\n\
680 occurrences of `id='.";
682 static const char *Lisp_suffixes
[] =
683 { "cl", "clisp", "el", "l", "lisp", "LSP", "lsp", "ml", NULL
};
684 static const char Lisp_help
[] =
685 "In Lisp code, any function defined with `defun', any variable\n\
686 defined with `defvar' or `defconst', and in general the first\n\
687 argument of any expression that starts with `(def' in column zero\n\
690 static const char *Lua_suffixes
[] =
691 { "lua", "LUA", NULL
};
692 static const char Lua_help
[] =
693 "In Lua scripts, all functions are tags.";
695 static const char *Makefile_filenames
[] =
696 { "Makefile", "makefile", "GNUMakefile", "Makefile.in", "Makefile.am", NULL
};
697 static const char Makefile_help
[] =
698 "In makefiles, targets are tags; additionally, variables are tags\n\
699 unless you specify `--no-globals'.";
701 static const char *Objc_suffixes
[] =
702 { "lm", /* Objective lex file */
703 "m", /* Objective C file */
705 static const char Objc_help
[] =
706 "In Objective C code, tags include Objective C definitions for classes,\n\
707 class categories, methods and protocols. Tags for variables and\n\
708 functions in classes are named `CLASS::VARIABLE' and `CLASS::FUNCTION'.\n\
709 (Use --help --lang=c --lang=objc --lang=java for full help.)";
711 static const char *Pascal_suffixes
[] =
712 { "p", "pas", NULL
};
713 static const char Pascal_help
[] =
714 "In Pascal code, the tags are the functions and procedures defined\n\
716 /* " // this is for working around an Emacs highlighting bug... */
718 static const char *Perl_suffixes
[] =
719 { "pl", "pm", NULL
};
720 static const char *Perl_interpreters
[] =
721 { "perl", "@PERL@", NULL
};
722 static const char Perl_help
[] =
723 "In Perl code, the tags are the packages, subroutines and variables\n\
724 defined by the `package', `sub', `my' and `local' keywords. Use\n\
725 `--globals' if you want to tag global variables. Tags for\n\
726 subroutines are named `PACKAGE::SUB'. The name for subroutines\n\
727 defined in the default package is `main::SUB'.";
729 static const char *PHP_suffixes
[] =
730 { "php", "php3", "php4", NULL
};
731 static const char PHP_help
[] =
732 "In PHP code, tags are functions, classes and defines. Unless you use\n\
733 the `--no-members' option, vars are tags too.";
735 static const char *plain_C_suffixes
[] =
736 { "pc", /* Pro*C file */
739 static const char *PS_suffixes
[] =
740 { "ps", "psw", NULL
}; /* .psw is for PSWrap */
741 static const char PS_help
[] =
742 "In PostScript code, the tags are the functions.";
744 static const char *Prolog_suffixes
[] =
746 static const char Prolog_help
[] =
747 "In Prolog code, tags are predicates and rules at the beginning of\n\
750 static const char *Python_suffixes
[] =
752 static const char Python_help
[] =
753 "In Python code, `def' or `class' at the beginning of a line\n\
756 /* Can't do the `SCM' or `scm' prefix with a version number. */
757 static const char *Scheme_suffixes
[] =
758 { "oak", "sch", "scheme", "SCM", "scm", "SM", "sm", "ss", "t", NULL
};
759 static const char Scheme_help
[] =
760 "In Scheme code, tags include anything defined with `def' or with a\n\
761 construct whose name starts with `def'. They also include\n\
762 variables set with `set!' at top level in the file.";
764 static const char *TeX_suffixes
[] =
765 { "bib", "clo", "cls", "ltx", "sty", "TeX", "tex", NULL
};
766 static const char TeX_help
[] =
767 "In LaTeX text, the argument of any of the commands `\\chapter',\n\
768 `\\section', `\\subsection', `\\subsubsection', `\\eqno', `\\label',\n\
769 `\\ref', `\\cite', `\\bibitem', `\\part', `\\appendix', `\\entry',\n\
770 `\\index', `\\def', `\\newcommand', `\\renewcommand',\n\
771 `\\newenvironment' or `\\renewenvironment' is a tag.\n\
773 Other commands can be specified by setting the environment variable\n\
774 `TEXTAGS' to a colon-separated list like, for example,\n\
775 TEXTAGS=\"mycommand:myothercommand\".";
778 static const char *Texinfo_suffixes
[] =
779 { "texi", "texinfo", "txi", NULL
};
780 static const char Texinfo_help
[] =
781 "for texinfo files, lines starting with @node are tagged.";
783 static const char *Yacc_suffixes
[] =
784 { "y", "y++", "ym", "yxx", "yy", NULL
}; /* .ym is Objective yacc file */
785 static const char Yacc_help
[] =
786 "In Bison or Yacc input files, each rule defines as a tag the\n\
787 nonterminal it constructs. The portions of the file that contain\n\
788 C code are parsed as C code (use --help --lang=c --lang=yacc\n\
791 static const char auto_help
[] =
792 "`auto' is not a real language, it indicates to use\n\
793 a default language for files base on file name suffix and file contents.";
795 static const char none_help
[] =
796 "`none' is not a real language, it indicates to only do\n\
797 regexp processing on files.";
799 static const char no_lang_help
[] =
800 "No detailed help available for this language.";
804 * Table of languages.
806 * It is ok for a given function to be listed under more than one
807 * name. I just didn't.
810 static language lang_names
[] =
812 { "ada", Ada_help
, Ada_funcs
, Ada_suffixes
},
813 { "asm", Asm_help
, Asm_labels
, Asm_suffixes
},
814 { "c", default_C_help
, default_C_entries
, default_C_suffixes
},
815 { "c++", Cplusplus_help
, Cplusplus_entries
, Cplusplus_suffixes
},
816 { "c*", no_lang_help
, Cstar_entries
, Cstar_suffixes
},
817 { "cobol", Cobol_help
, Cobol_paragraphs
, Cobol_suffixes
},
818 { "erlang", Erlang_help
, Erlang_functions
, Erlang_suffixes
},
819 { "forth", Forth_help
, Forth_words
, Forth_suffixes
},
820 { "fortran", Fortran_help
, Fortran_functions
, Fortran_suffixes
},
821 { "html", HTML_help
, HTML_labels
, HTML_suffixes
},
822 { "java", Cjava_help
, Cjava_entries
, Cjava_suffixes
},
823 { "lisp", Lisp_help
, Lisp_functions
, Lisp_suffixes
},
824 { "lua", Lua_help
, Lua_functions
, Lua_suffixes
},
825 { "makefile", Makefile_help
,Makefile_targets
,NULL
,Makefile_filenames
},
826 { "objc", Objc_help
, plain_C_entries
, Objc_suffixes
},
827 { "pascal", Pascal_help
, Pascal_functions
, Pascal_suffixes
},
828 { "perl",Perl_help
,Perl_functions
,Perl_suffixes
,NULL
,Perl_interpreters
},
829 { "php", PHP_help
, PHP_functions
, PHP_suffixes
},
830 { "postscript",PS_help
, PS_functions
, PS_suffixes
},
831 { "proc", no_lang_help
, plain_C_entries
, plain_C_suffixes
},
832 { "prolog", Prolog_help
, Prolog_functions
, Prolog_suffixes
},
833 { "python", Python_help
, Python_functions
, Python_suffixes
},
834 { "scheme", Scheme_help
, Scheme_functions
, Scheme_suffixes
},
835 { "tex", TeX_help
, TeX_commands
, TeX_suffixes
},
836 { "texinfo", Texinfo_help
, Texinfo_nodes
, Texinfo_suffixes
},
837 { "yacc", Yacc_help
,Yacc_entries
,Yacc_suffixes
,NULL
,NULL
,TRUE
},
838 { "auto", auto_help
}, /* default guessing scheme */
839 { "none", none_help
, just_read_file
}, /* regexp matching only */
840 { NULL
} /* end of list */
845 print_language_names (void)
848 const char **name
, **ext
;
850 puts ("\nThese are the currently supported languages, along with the\n\
851 default file names and dot suffixes:");
852 for (lang
= lang_names
; lang
->name
!= NULL
; lang
++)
854 printf (" %-*s", 10, lang
->name
);
855 if (lang
->filenames
!= NULL
)
856 for (name
= lang
->filenames
; *name
!= NULL
; name
++)
857 printf (" %s", *name
);
858 if (lang
->suffixes
!= NULL
)
859 for (ext
= lang
->suffixes
; *ext
!= NULL
; ext
++)
860 printf (" .%s", *ext
);
863 puts ("where `auto' means use default language for files based on file\n\
864 name suffix, and `none' means only do regexp processing on files.\n\
865 If no language is specified and no matching suffix is found,\n\
866 the first line of the file is read for a sharp-bang (#!) sequence\n\
867 followed by the name of an interpreter. If no such sequence is found,\n\
868 Fortran is tried first; if no tags are found, C is tried next.\n\
869 When parsing any C file, a \"class\" or \"template\" keyword\n\
871 puts ("Compressed files are supported using gzip, bzip2, and xz.\n\
873 For detailed help on a given language use, for example,\n\
874 etags --help --lang=ada.");
878 # define EMACS_NAME "standalone"
881 # define VERSION "17.38.1.4"
886 /* Makes it easier to update automatically. */
887 char emacs_copyright
[] = "Copyright (C) 2011 Free Software Foundation, Inc.";
889 printf ("%s (%s %s)\n", (CTAGS
) ? "ctags" : "etags", EMACS_NAME
, VERSION
);
890 puts (emacs_copyright
);
891 puts ("This program is distributed under the terms in ETAGS.README");
896 #ifndef PRINT_UNDOCUMENTED_OPTIONS_HELP
897 # define PRINT_UNDOCUMENTED_OPTIONS_HELP FALSE
901 print_help (argument
*argbuffer
)
903 bool help_for_lang
= FALSE
;
905 for (; argbuffer
->arg_type
!= at_end
; argbuffer
++)
906 if (argbuffer
->arg_type
== at_language
)
910 puts (argbuffer
->lang
->help
);
911 help_for_lang
= TRUE
;
917 printf ("Usage: %s [options] [[regex-option ...] file-name] ...\n\
919 These are the options accepted by %s.\n", progname
, progname
);
921 puts ("WARNING: long option names do not work with this executable,\n\
922 as it is not linked with GNU getopt.");
924 puts ("You may use unambiguous abbreviations for the long option names.");
925 puts (" A - as file name means read names from stdin (one per line).\n\
926 Absolute names are stored in the output file as they are.\n\
927 Relative ones are stored relative to the output file's directory.\n");
929 puts ("-a, --append\n\
930 Append tag entries to existing tags file.");
932 puts ("--packages-only\n\
933 For Ada files, only generate tags for packages.");
936 puts ("-B, --backward-search\n\
937 Write the search commands for the tag entries using '?', the\n\
938 backward-search command instead of '/', the forward-search command.");
940 /* This option is mostly obsolete, because etags can now automatically
941 detect C++. Retained for backward compatibility and for debugging and
942 experimentation. In principle, we could want to tag as C++ even
943 before any "class" or "template" keyword.
945 Treat files whose name suffix defaults to C language as C++ files.");
948 puts ("--declarations\n\
949 In C and derived languages, create tags for function declarations,");
951 puts ("\tand create tags for extern variables if --globals is used.");
954 ("\tand create tags for extern variables unless --no-globals is used.");
957 puts ("-d, --defines\n\
958 Create tag entries for C #define constants and enum constants, too.");
960 puts ("-D, --no-defines\n\
961 Don't create tag entries for C #define constants and enum constants.\n\
962 This makes the tags file smaller.");
965 puts ("-i FILE, --include=FILE\n\
966 Include a note in tag file indicating that, when searching for\n\
967 a tag, one should also consult the tags file FILE after\n\
968 checking the current file.");
970 puts ("-l LANG, --language=LANG\n\
971 Force the following files to be considered as written in the\n\
972 named language up to the next --language=LANG option.");
976 Create tag entries for global variables in some languages.");
978 puts ("--no-globals\n\
979 Do not create tag entries for global variables in some\n\
980 languages. This makes the tags file smaller.");
982 if (PRINT_UNDOCUMENTED_OPTIONS_HELP
)
983 puts ("--no-line-directive\n\
984 Ignore #line preprocessor directives in C and derived languages.");
988 Create tag entries for members of structures in some languages.");
990 puts ("--no-members\n\
991 Do not create tag entries for members of structures\n\
992 in some languages.");
994 puts ("-r REGEXP, --regex=REGEXP or --regex=@regexfile\n\
995 Make a tag for each line matching a regular expression pattern\n\
996 in the following files. {LANGUAGE}REGEXP uses REGEXP for LANGUAGE\n\
997 files only. REGEXFILE is a file containing one REGEXP per line.\n\
998 REGEXP takes the form /TAGREGEXP/TAGNAME/MODS, where TAGNAME/ is\n\
999 optional. The TAGREGEXP pattern is anchored (as if preceded by ^).");
1000 puts (" If TAGNAME/ is present, the tags created are named.\n\
1001 For example Tcl named tags can be created with:\n\
1002 --regex=\"/proc[ \\t]+\\([^ \\t]+\\)/\\1/.\".\n\
1003 MODS are optional one-letter modifiers: `i' means to ignore case,\n\
1004 `m' means to allow multi-line matches, `s' implies `m' and\n\
1005 causes dot to match any character, including newline.");
1007 puts ("-R, --no-regex\n\
1008 Don't create tags from regexps for the following files.");
1010 puts ("-I, --ignore-indentation\n\
1011 In C and C++ do not assume that a closing brace in the first\n\
1012 column is the final brace of a function or structure definition.");
1014 puts ("-o FILE, --output=FILE\n\
1015 Write the tags to FILE.");
1017 puts ("--parse-stdin=NAME\n\
1018 Read from standard input and record tags as belonging to file NAME.");
1022 puts ("-t, --typedefs\n\
1023 Generate tag entries for C and Ada typedefs.");
1024 puts ("-T, --typedefs-and-c++\n\
1025 Generate tag entries for C typedefs, C struct/enum/union tags,\n\
1026 and C++ member functions.");
1030 puts ("-u, --update\n\
1031 Update the tag entries for the given files, leaving tag\n\
1032 entries for other files in place. Currently, this is\n\
1033 implemented by deleting the existing entries for the given\n\
1034 files and then rewriting the new entries at the end of the\n\
1035 tags file. It is often faster to simply rebuild the entire\n\
1036 tag file than to use this.");
1040 puts ("-v, --vgrind\n\
1041 Print on the standard output an index of items intended for\n\
1042 human consumption, similar to the output of vgrind. The index\n\
1043 is sorted, and gives the page number of each item.");
1045 if (PRINT_UNDOCUMENTED_OPTIONS_HELP
)
1046 puts ("-w, --no-duplicates\n\
1047 Do not create duplicate tag entries, for compatibility with\n\
1048 traditional ctags.");
1050 if (PRINT_UNDOCUMENTED_OPTIONS_HELP
)
1051 puts ("-w, --no-warn\n\
1052 Suppress warning messages about duplicate tag entries.");
1054 puts ("-x, --cxref\n\
1055 Like --vgrind, but in the style of cxref, rather than vgrind.\n\
1056 The output uses line numbers instead of page numbers, but\n\
1057 beyond that the differences are cosmetic; try both to see\n\
1061 puts ("-V, --version\n\
1062 Print the version of the program.\n\
1064 Print this help message.\n\
1065 Followed by one or more `--language' options prints detailed\n\
1066 help about tag generation for the specified languages.");
1068 print_language_names ();
1071 puts ("Report bugs to bug-gnu-emacs@gnu.org");
1073 exit (EXIT_SUCCESS
);
1078 main (int argc
, char **argv
)
1081 unsigned int nincluded_files
;
1082 char **included_files
;
1083 argument
*argbuffer
;
1084 int current_arg
, file_count
;
1085 linebuffer filename_lb
;
1086 bool help_asked
= FALSE
;
1092 _fmode
= O_BINARY
; /* all of files are treated as binary files */
1096 nincluded_files
= 0;
1097 included_files
= xnew (argc
, char *);
1101 /* Allocate enough no matter what happens. Overkill, but each one
1103 argbuffer
= xnew (argc
, argument
);
1106 * Always find typedefs and structure tags.
1107 * Also default to find macro constants, enum constants, struct
1108 * members and global variables. Do it for both etags and ctags.
1110 typedefs
= typedefs_or_cplusplus
= constantypedefs
= TRUE
;
1111 globals
= members
= TRUE
;
1113 /* When the optstring begins with a '-' getopt_long does not rearrange the
1114 non-options arguments to be at the end, but leaves them alone. */
1115 optstring
= concat (NO_LONG_OPTIONS
? "" : "-",
1116 "ac:Cf:Il:o:r:RSVhH",
1117 (CTAGS
) ? "BxdtTuvw" : "Di:");
1119 while ((opt
= getopt_long (argc
, argv
, optstring
, longopts
, NULL
)) != EOF
)
1123 /* If getopt returns 0, then it has already processed a
1124 long-named option. We should do nothing. */
1128 /* This means that a file name has been seen. Record it. */
1129 argbuffer
[current_arg
].arg_type
= at_filename
;
1130 argbuffer
[current_arg
].what
= optarg
;
1136 /* Parse standard input. Idea by Vivek <vivek@etla.org>. */
1137 argbuffer
[current_arg
].arg_type
= at_stdin
;
1138 argbuffer
[current_arg
].what
= optarg
;
1142 fatal ("cannot parse standard input more than once", (char *)NULL
);
1143 parsing_stdin
= TRUE
;
1146 /* Common options. */
1147 case 'a': append_to_tagfile
= TRUE
; break;
1148 case 'C': cplusplus
= TRUE
; break;
1149 case 'f': /* for compatibility with old makefiles */
1153 error ("-o option may only be given once.", (char *)NULL
);
1154 suggest_asking_for_help ();
1160 case 'S': /* for backward compatibility */
1161 ignoreindent
= TRUE
;
1165 language
*lang
= get_language_from_langname (optarg
);
1168 argbuffer
[current_arg
].lang
= lang
;
1169 argbuffer
[current_arg
].arg_type
= at_language
;
1175 /* Backward compatibility: support obsolete --ignore-case-regexp. */
1176 optarg
= concat (optarg
, "i", ""); /* memory leak here */
1179 argbuffer
[current_arg
].arg_type
= at_regexp
;
1180 argbuffer
[current_arg
].what
= optarg
;
1184 argbuffer
[current_arg
].arg_type
= at_regexp
;
1185 argbuffer
[current_arg
].what
= NULL
;
1197 case 'D': constantypedefs
= FALSE
; break;
1198 case 'i': included_files
[nincluded_files
++] = optarg
; break;
1200 /* Ctags options. */
1201 case 'B': searchar
= '?'; break;
1202 case 'd': constantypedefs
= TRUE
; break;
1203 case 't': typedefs
= TRUE
; break;
1204 case 'T': typedefs
= typedefs_or_cplusplus
= TRUE
; break;
1205 case 'u': update
= TRUE
; break;
1206 case 'v': vgrind_style
= TRUE
; /*FALLTHRU*/
1207 case 'x': cxref_style
= TRUE
; break;
1208 case 'w': no_warnings
= TRUE
; break;
1210 suggest_asking_for_help ();
1214 /* No more options. Store the rest of arguments. */
1215 for (; optind
< argc
; optind
++)
1217 argbuffer
[current_arg
].arg_type
= at_filename
;
1218 argbuffer
[current_arg
].what
= argv
[optind
];
1223 argbuffer
[current_arg
].arg_type
= at_end
;
1226 print_help (argbuffer
);
1229 if (nincluded_files
== 0 && file_count
== 0)
1231 error ("no input files specified.", (char *)NULL
);
1232 suggest_asking_for_help ();
1236 if (tagfile
== NULL
)
1237 tagfile
= savestr (CTAGS
? "tags" : "TAGS");
1238 cwd
= etags_getcwd (); /* the current working directory */
1239 if (cwd
[strlen (cwd
) - 1] != '/')
1242 cwd
= concat (oldcwd
, "/", "");
1246 /* Compute base directory for relative file names. */
1247 if (streq (tagfile
, "-")
1248 || strneq (tagfile
, "/dev/", 5))
1249 tagfiledir
= cwd
; /* relative file names are relative to cwd */
1252 canonicalize_filename (tagfile
);
1253 tagfiledir
= absolute_dirname (tagfile
, cwd
);
1256 init (); /* set up boolean "functions" */
1258 linebuffer_init (&lb
);
1259 linebuffer_init (&filename_lb
);
1260 linebuffer_init (&filebuf
);
1261 linebuffer_init (&token_name
);
1265 if (streq (tagfile
, "-"))
1269 /* Switch redirected `stdout' to binary mode (setting `_fmode'
1270 doesn't take effect until after `stdout' is already open). */
1271 if (!isatty (fileno (stdout
)))
1272 setmode (fileno (stdout
), O_BINARY
);
1276 tagf
= fopen (tagfile
, append_to_tagfile
? "a" : "w");
1282 * Loop through files finding functions.
1284 for (i
= 0; i
< current_arg
; i
++)
1286 static language
*lang
; /* non-NULL if language is forced */
1289 switch (argbuffer
[i
].arg_type
)
1292 lang
= argbuffer
[i
].lang
;
1295 analyse_regex (argbuffer
[i
].what
);
1298 this_file
= argbuffer
[i
].what
;
1299 /* Input file named "-" means read file names from stdin
1300 (one per line) and use them. */
1301 if (streq (this_file
, "-"))
1304 fatal ("cannot parse standard input AND read file names from it",
1306 while (readline_internal (&filename_lb
, stdin
) > 0)
1307 process_file_name (filename_lb
.buffer
, lang
);
1310 process_file_name (this_file
, lang
);
1313 this_file
= argbuffer
[i
].what
;
1314 process_file (stdin
, this_file
, lang
);
1321 free (filebuf
.buffer
);
1322 free (token_name
.buffer
);
1324 if (!CTAGS
|| cxref_style
)
1326 /* Write the remaining tags to tagf (ETAGS) or stdout (CXREF). */
1327 put_entries (nodehead
);
1328 free_tree (nodehead
);
1334 /* Output file entries that have no tags. */
1335 for (fdp
= fdhead
; fdp
!= NULL
; fdp
= fdp
->next
)
1337 fprintf (tagf
, "\f\n%s,0\n", fdp
->taggedfname
);
1339 while (nincluded_files
-- > 0)
1340 fprintf (tagf
, "\f\n%s,include\n", *included_files
++);
1342 if (fclose (tagf
) == EOF
)
1346 exit (EXIT_SUCCESS
);
1349 /* From here on, we are in (CTAGS && !cxref_style) */
1353 for (i
= 0; i
< current_arg
; ++i
)
1355 switch (argbuffer
[i
].arg_type
)
1361 continue; /* the for loop */
1364 "mv %s OTAGS;fgrep -v '\t%s\t' OTAGS >%s;rm OTAGS",
1365 tagfile
, argbuffer
[i
].what
, tagfile
);
1366 if (system (cmd
) != EXIT_SUCCESS
)
1367 fatal ("failed to execute shell command", (char *)NULL
);
1369 append_to_tagfile
= TRUE
;
1372 tagf
= fopen (tagfile
, append_to_tagfile
? "a" : "w");
1375 put_entries (nodehead
); /* write all the tags (CTAGS) */
1376 free_tree (nodehead
);
1378 if (fclose (tagf
) == EOF
)
1382 if (append_to_tagfile
|| update
)
1384 char cmd
[2*BUFSIZ
+20];
1385 /* Maybe these should be used:
1386 setenv ("LC_COLLATE", "C", 1);
1387 setenv ("LC_ALL", "C", 1); */
1388 sprintf (cmd
, "sort -u -o %.*s %.*s", BUFSIZ
, tagfile
, BUFSIZ
, tagfile
);
1389 exit (system (cmd
));
1391 return EXIT_SUCCESS
;
1396 * Return a compressor given the file name. If EXTPTR is non-zero,
1397 * return a pointer into FILE where the compressor-specific
1398 * extension begins. If no compressor is found, NULL is returned
1399 * and EXTPTR is not significant.
1400 * Idea by Vladimir Alexiev <vladimir@cs.ualberta.ca> (1998)
1403 get_compressor_from_suffix (char *file
, char **extptr
)
1406 char *slash
, *suffix
;
1408 /* File has been processed by canonicalize_filename,
1409 so we don't need to consider backslashes on DOS_NT. */
1410 slash
= etags_strrchr (file
, '/');
1411 suffix
= etags_strrchr (file
, '.');
1412 if (suffix
== NULL
|| suffix
< slash
)
1417 /* Let those poor souls who live with DOS 8+3 file name limits get
1418 some solace by treating foo.cgz as if it were foo.c.gz, etc.
1419 Only the first do loop is run if not MSDOS */
1422 for (compr
= compressors
; compr
->suffix
!= NULL
; compr
++)
1423 if (streq (compr
->suffix
, suffix
))
1426 break; /* do it only once: not really a loop */
1429 } while (*suffix
!= '\0');
1436 * Return a language given the name.
1439 get_language_from_langname (const char *name
)
1444 error ("empty language name", (char *)NULL
);
1447 for (lang
= lang_names
; lang
->name
!= NULL
; lang
++)
1448 if (streq (name
, lang
->name
))
1450 error ("unknown language \"%s\"", name
);
1458 * Return a language given the interpreter name.
1461 get_language_from_interpreter (char *interpreter
)
1466 if (interpreter
== NULL
)
1468 for (lang
= lang_names
; lang
->name
!= NULL
; lang
++)
1469 if (lang
->interpreters
!= NULL
)
1470 for (iname
= lang
->interpreters
; *iname
!= NULL
; iname
++)
1471 if (streq (*iname
, interpreter
))
1480 * Return a language given the file name.
1483 get_language_from_filename (char *file
, int case_sensitive
)
1486 const char **name
, **ext
, *suffix
;
1488 /* Try whole file name first. */
1489 for (lang
= lang_names
; lang
->name
!= NULL
; lang
++)
1490 if (lang
->filenames
!= NULL
)
1491 for (name
= lang
->filenames
; *name
!= NULL
; name
++)
1492 if ((case_sensitive
)
1493 ? streq (*name
, file
)
1494 : strcaseeq (*name
, file
))
1497 /* If not found, try suffix after last dot. */
1498 suffix
= etags_strrchr (file
, '.');
1502 for (lang
= lang_names
; lang
->name
!= NULL
; lang
++)
1503 if (lang
->suffixes
!= NULL
)
1504 for (ext
= lang
->suffixes
; *ext
!= NULL
; ext
++)
1505 if ((case_sensitive
)
1506 ? streq (*ext
, suffix
)
1507 : strcaseeq (*ext
, suffix
))
1514 * This routine is called on each file argument.
1517 process_file_name (char *file
, language
*lang
)
1519 struct stat stat_buf
;
1523 char *compressed_name
, *uncompressed_name
;
1524 char *ext
, *real_name
;
1527 canonicalize_filename (file
);
1528 if (streq (file
, tagfile
) && !streq (tagfile
, "-"))
1530 error ("skipping inclusion of %s in self.", file
);
1533 if ((compr
= get_compressor_from_suffix (file
, &ext
)) == NULL
)
1535 compressed_name
= NULL
;
1536 real_name
= uncompressed_name
= savestr (file
);
1540 real_name
= compressed_name
= savestr (file
);
1541 uncompressed_name
= savenstr (file
, ext
- file
);
1544 /* If the canonicalized uncompressed name
1545 has already been dealt with, skip it silently. */
1546 for (fdp
= fdhead
; fdp
!= NULL
; fdp
= fdp
->next
)
1548 assert (fdp
->infname
!= NULL
);
1549 if (streq (uncompressed_name
, fdp
->infname
))
1553 if (stat (real_name
, &stat_buf
) != 0)
1555 /* Reset real_name and try with a different name. */
1557 if (compressed_name
!= NULL
) /* try with the given suffix */
1559 if (stat (uncompressed_name
, &stat_buf
) == 0)
1560 real_name
= uncompressed_name
;
1562 else /* try all possible suffixes */
1564 for (compr
= compressors
; compr
->suffix
!= NULL
; compr
++)
1566 compressed_name
= concat (file
, ".", compr
->suffix
);
1567 if (stat (compressed_name
, &stat_buf
) != 0)
1571 char *suf
= compressed_name
+ strlen (file
);
1572 size_t suflen
= strlen (compr
->suffix
) + 1;
1573 for ( ; suf
[1]; suf
++, suflen
--)
1575 memmove (suf
, suf
+ 1, suflen
);
1576 if (stat (compressed_name
, &stat_buf
) == 0)
1578 real_name
= compressed_name
;
1582 if (real_name
!= NULL
)
1585 free (compressed_name
);
1586 compressed_name
= NULL
;
1590 real_name
= compressed_name
;
1595 if (real_name
== NULL
)
1600 } /* try with a different name */
1602 if (!S_ISREG (stat_buf
.st_mode
))
1604 error ("skipping %s: it is not a regular file.", real_name
);
1607 if (real_name
== compressed_name
)
1609 char *cmd
= concat (compr
->command
, " ", real_name
);
1610 inf
= (FILE *) popen (cmd
, "r");
1614 inf
= fopen (real_name
, "r");
1621 process_file (inf
, uncompressed_name
, lang
);
1623 if (real_name
== compressed_name
)
1624 retval
= pclose (inf
);
1626 retval
= fclose (inf
);
1631 free (compressed_name
);
1632 free (uncompressed_name
);
1639 process_file (FILE *fh
, char *fn
, language
*lang
)
1641 static const fdesc emptyfdesc
;
1644 /* Create a new input file description entry. */
1645 fdp
= xnew (1, fdesc
);
1648 fdp
->infname
= savestr (fn
);
1650 fdp
->infabsname
= absolute_filename (fn
, cwd
);
1651 fdp
->infabsdir
= absolute_dirname (fn
, cwd
);
1652 if (filename_is_absolute (fn
))
1654 /* An absolute file name. Canonicalize it. */
1655 fdp
->taggedfname
= absolute_filename (fn
, NULL
);
1659 /* A file name relative to cwd. Make it relative
1660 to the directory of the tags file. */
1661 fdp
->taggedfname
= relative_filename (fn
, tagfiledir
);
1663 fdp
->usecharno
= TRUE
; /* use char position when making tags */
1665 fdp
->written
= FALSE
; /* not written on tags file yet */
1668 curfdp
= fdhead
; /* the current file description */
1672 /* If not Ctags, and if this is not metasource and if it contained no #line
1673 directives, we can write the tags and free all nodes pointing to
1676 && curfdp
->usecharno
/* no #line directives in this file */
1677 && !curfdp
->lang
->metasource
)
1681 /* Look for the head of the sublist relative to this file. See add_node
1682 for the structure of the node tree. */
1684 for (np
= nodehead
; np
!= NULL
; prev
= np
, np
= np
->left
)
1685 if (np
->fdp
== curfdp
)
1688 /* If we generated tags for this file, write and delete them. */
1691 /* This is the head of the last sublist, if any. The following
1692 instructions depend on this being true. */
1693 assert (np
->left
== NULL
);
1695 assert (fdhead
== curfdp
);
1696 assert (last_node
->fdp
== curfdp
);
1697 put_entries (np
); /* write tags for file curfdp->taggedfname */
1698 free_tree (np
); /* remove the written nodes */
1700 nodehead
= NULL
; /* no nodes left */
1702 prev
->left
= NULL
; /* delete the pointer to the sublist */
1708 * This routine sets up the boolean pseudo-functions which work
1709 * by setting boolean flags dependent upon the corresponding character.
1710 * Every char which is NOT in that string is not a white char. Therefore,
1711 * all of the array "_wht" is set to FALSE, and then the elements
1712 * subscripted by the chars in "white" are set to TRUE. Thus "_wht"
1713 * of a char is TRUE if it is the string "white", else FALSE.
1718 register const char *sp
;
1721 for (i
= 0; i
< CHARS
; i
++)
1722 iswhite(i
) = notinname(i
) = begtoken(i
) = intoken(i
) = endtoken(i
) = FALSE
;
1723 for (sp
= white
; *sp
!= '\0'; sp
++) iswhite (*sp
) = TRUE
;
1724 for (sp
= nonam
; *sp
!= '\0'; sp
++) notinname (*sp
) = TRUE
;
1725 notinname('\0') = notinname('\n');
1726 for (sp
= begtk
; *sp
!= '\0'; sp
++) begtoken (*sp
) = TRUE
;
1727 begtoken('\0') = begtoken('\n');
1728 for (sp
= midtk
; *sp
!= '\0'; sp
++) intoken (*sp
) = TRUE
;
1729 intoken('\0') = intoken('\n');
1730 for (sp
= endtk
; *sp
!= '\0'; sp
++) endtoken (*sp
) = TRUE
;
1731 endtoken('\0') = endtoken('\n');
1735 * This routine opens the specified file and calls the function
1736 * which finds the function and type definitions.
1739 find_entries (FILE *inf
)
1742 language
*lang
= curfdp
->lang
;
1743 Lang_function
*parser
= NULL
;
1745 /* If user specified a language, use it. */
1746 if (lang
!= NULL
&& lang
->function
!= NULL
)
1748 parser
= lang
->function
;
1751 /* Else try to guess the language given the file name. */
1754 lang
= get_language_from_filename (curfdp
->infname
, TRUE
);
1755 if (lang
!= NULL
&& lang
->function
!= NULL
)
1757 curfdp
->lang
= lang
;
1758 parser
= lang
->function
;
1762 /* Else look for sharp-bang as the first two characters. */
1764 && readline_internal (&lb
, inf
) > 0
1766 && lb
.buffer
[0] == '#'
1767 && lb
.buffer
[1] == '!')
1771 /* Set lp to point at the first char after the last slash in the
1772 line or, if no slashes, at the first nonblank. Then set cp to
1773 the first successive blank and terminate the string. */
1774 lp
= etags_strrchr (lb
.buffer
+2, '/');
1778 lp
= skip_spaces (lb
.buffer
+ 2);
1779 cp
= skip_non_spaces (lp
);
1782 if (strlen (lp
) > 0)
1784 lang
= get_language_from_interpreter (lp
);
1785 if (lang
!= NULL
&& lang
->function
!= NULL
)
1787 curfdp
->lang
= lang
;
1788 parser
= lang
->function
;
1793 /* We rewind here, even if inf may be a pipe. We fail if the
1794 length of the first line is longer than the pipe block size,
1795 which is unlikely. */
1798 /* Else try to guess the language given the case insensitive file name. */
1801 lang
= get_language_from_filename (curfdp
->infname
, FALSE
);
1802 if (lang
!= NULL
&& lang
->function
!= NULL
)
1804 curfdp
->lang
= lang
;
1805 parser
= lang
->function
;
1809 /* Else try Fortran or C. */
1812 node
*old_last_node
= last_node
;
1814 curfdp
->lang
= get_language_from_langname ("fortran");
1817 if (old_last_node
== last_node
)
1818 /* No Fortran entries found. Try C. */
1820 /* We do not tag if rewind fails.
1821 Only the file name will be recorded in the tags file. */
1823 curfdp
->lang
= get_language_from_langname (cplusplus
? "c++" : "c");
1829 if (!no_line_directive
1830 && curfdp
->lang
!= NULL
&& curfdp
->lang
->metasource
)
1831 /* It may be that this is a bingo.y file, and we already parsed a bingo.c
1832 file, or anyway we parsed a file that is automatically generated from
1833 this one. If this is the case, the bingo.c file contained #line
1834 directives that generated tags pointing to this file. Let's delete
1835 them all before parsing this file, which is the real source. */
1837 fdesc
**fdpp
= &fdhead
;
1838 while (*fdpp
!= NULL
)
1840 && streq ((*fdpp
)->taggedfname
, curfdp
->taggedfname
))
1841 /* We found one of those! We must delete both the file description
1842 and all tags referring to it. */
1844 fdesc
*badfdp
= *fdpp
;
1846 /* Delete the tags referring to badfdp->taggedfname
1847 that were obtained from badfdp->infname. */
1848 invalidate_nodes (badfdp
, &nodehead
);
1850 *fdpp
= badfdp
->next
; /* remove the bad description from the list */
1851 free_fdesc (badfdp
);
1854 fdpp
= &(*fdpp
)->next
; /* advance the list pointer */
1857 assert (parser
!= NULL
);
1859 /* Generic initialisations before reading from file. */
1860 linebuffer_setlen (&filebuf
, 0); /* reset the file buffer */
1862 /* Generic initialisations before parsing file with readline. */
1863 lineno
= 0; /* reset global line number */
1864 charno
= 0; /* reset global char number */
1865 linecharno
= 0; /* reset global char number of line start */
1869 regex_tag_multiline ();
1874 * Check whether an implicitly named tag should be created,
1875 * then call `pfnote'.
1876 * NAME is a string that is internally copied by this function.
1878 * TAGS format specification
1879 * Idea by Sam Kendall <kendall@mv.mv.com> (1997)
1880 * The following is explained in some more detail in etc/ETAGS.EBNF.
1882 * make_tag creates tags with "implicit tag names" (unnamed tags)
1883 * if the following are all true, assuming NONAM=" \f\t\n\r()=,;":
1884 * 1. NAME does not contain any of the characters in NONAM;
1885 * 2. LINESTART contains name as either a rightmost, or rightmost but
1886 * one character, substring;
1887 * 3. the character, if any, immediately before NAME in LINESTART must
1888 * be a character in NONAM;
1889 * 4. the character, if any, immediately after NAME in LINESTART must
1890 * also be a character in NONAM.
1892 * The implementation uses the notinname() macro, which recognises the
1893 * characters stored in the string `nonam'.
1894 * etags.el needs to use the same characters that are in NONAM.
1897 make_tag (const char *name
, /* tag name, or NULL if unnamed */
1898 int namelen
, /* tag length */
1899 int is_func
, /* tag is a function */
1900 char *linestart
, /* start of the line where tag is */
1901 int linelen
, /* length of the line where tag is */
1902 int lno
, /* line number */
1903 long int cno
) /* character number */
1905 bool named
= (name
!= NULL
&& namelen
> 0);
1908 if (!CTAGS
&& named
) /* maybe set named to false */
1909 /* Let's try to make an implicit tag name, that is, create an unnamed tag
1910 such that etags.el can guess a name from it. */
1913 register const char *cp
= name
;
1915 for (i
= 0; i
< namelen
; i
++)
1916 if (notinname (*cp
++))
1918 if (i
== namelen
) /* rule #1 */
1920 cp
= linestart
+ linelen
- namelen
;
1921 if (notinname (linestart
[linelen
-1]))
1922 cp
-= 1; /* rule #4 */
1923 if (cp
>= linestart
/* rule #2 */
1925 || notinname (cp
[-1])) /* rule #3 */
1926 && strneq (name
, cp
, namelen
)) /* rule #2 */
1927 named
= FALSE
; /* use implicit tag name */
1932 nname
= savenstr (name
, namelen
);
1934 pfnote (nname
, is_func
, linestart
, linelen
, lno
, cno
);
1939 pfnote (char *name
, int is_func
, char *linestart
, int linelen
, int lno
, long int cno
)
1940 /* tag name, or NULL if unnamed */
1941 /* tag is a function */
1942 /* start of the line where tag is */
1943 /* length of the line where tag is */
1945 /* character number */
1949 assert (name
== NULL
|| name
[0] != '\0');
1950 if (CTAGS
&& name
== NULL
)
1953 np
= xnew (1, node
);
1955 /* If ctags mode, change name "main" to M<thisfilename>. */
1956 if (CTAGS
&& !cxref_style
&& streq (name
, "main"))
1958 register char *fp
= etags_strrchr (curfdp
->taggedfname
, '/');
1959 np
->name
= concat ("M", fp
== NULL
? curfdp
->taggedfname
: fp
+ 1, "");
1960 fp
= etags_strrchr (np
->name
, '.');
1961 if (fp
!= NULL
&& fp
[1] != '\0' && fp
[2] == '\0')
1967 np
->been_warned
= FALSE
;
1969 np
->is_func
= is_func
;
1971 if (np
->fdp
->usecharno
)
1972 /* Our char numbers are 0-base, because of C language tradition?
1973 ctags compatibility? old versions compatibility? I don't know.
1974 Anyway, since emacs's are 1-base we expect etags.el to take care
1975 of the difference. If we wanted to have 1-based numbers, we would
1976 uncomment the +1 below. */
1977 np
->cno
= cno
/* + 1 */ ;
1979 np
->cno
= invalidcharno
;
1980 np
->left
= np
->right
= NULL
;
1981 if (CTAGS
&& !cxref_style
)
1983 if (strlen (linestart
) < 50)
1984 np
->regex
= concat (linestart
, "$", "");
1986 np
->regex
= savenstr (linestart
, 50);
1989 np
->regex
= savenstr (linestart
, linelen
);
1991 add_node (np
, &nodehead
);
1996 * recurse on left children, iterate on right children.
1999 free_tree (register node
*np
)
2003 register node
*node_right
= np
->right
;
2004 free_tree (np
->left
);
2014 * delete a file description
2017 free_fdesc (register fdesc
*fdp
)
2019 free (fdp
->infname
);
2020 free (fdp
->infabsname
);
2021 free (fdp
->infabsdir
);
2022 free (fdp
->taggedfname
);
2029 * Adds a node to the tree of nodes. In etags mode, sort by file
2030 * name. In ctags mode, sort by tag name. Make no attempt at
2033 * add_node is the only function allowed to add nodes, so it can
2037 add_node (node
*np
, node
**cur_node_p
)
2040 register node
*cur_node
= *cur_node_p
;
2042 if (cur_node
== NULL
)
2052 /* For each file name, tags are in a linked sublist on the right
2053 pointer. The first tags of different files are a linked list
2054 on the left pointer. last_node points to the end of the last
2056 if (last_node
!= NULL
&& last_node
->fdp
== np
->fdp
)
2058 /* Let's use the same sublist as the last added node. */
2059 assert (last_node
->right
== NULL
);
2060 last_node
->right
= np
;
2063 else if (cur_node
->fdp
== np
->fdp
)
2065 /* Scanning the list we found the head of a sublist which is
2066 good for us. Let's scan this sublist. */
2067 add_node (np
, &cur_node
->right
);
2070 /* The head of this sublist is not good for us. Let's try the
2072 add_node (np
, &cur_node
->left
);
2073 } /* if ETAGS mode */
2078 dif
= strcmp (np
->name
, cur_node
->name
);
2081 * If this tag name matches an existing one, then
2082 * do not add the node, but maybe print a warning.
2084 if (no_duplicates
&& !dif
)
2086 if (np
->fdp
== cur_node
->fdp
)
2090 fprintf (stderr
, "Duplicate entry in file %s, line %d: %s\n",
2091 np
->fdp
->infname
, lineno
, np
->name
);
2092 fprintf (stderr
, "Second entry ignored\n");
2095 else if (!cur_node
->been_warned
&& !no_warnings
)
2099 "Duplicate entry in files %s and %s: %s (Warning only)\n",
2100 np
->fdp
->infname
, cur_node
->fdp
->infname
, np
->name
);
2101 cur_node
->been_warned
= TRUE
;
2106 /* Actually add the node */
2107 add_node (np
, dif
< 0 ? &cur_node
->left
: &cur_node
->right
);
2108 } /* if CTAGS mode */
2112 * invalidate_nodes ()
2113 * Scan the node tree and invalidate all nodes pointing to the
2114 * given file description (CTAGS case) or free them (ETAGS case).
2117 invalidate_nodes (fdesc
*badfdp
, node
**npp
)
2126 if (np
->left
!= NULL
)
2127 invalidate_nodes (badfdp
, &np
->left
);
2128 if (np
->fdp
== badfdp
)
2130 if (np
->right
!= NULL
)
2131 invalidate_nodes (badfdp
, &np
->right
);
2135 assert (np
->fdp
!= NULL
);
2136 if (np
->fdp
== badfdp
)
2138 *npp
= np
->left
; /* detach the sublist from the list */
2139 np
->left
= NULL
; /* isolate it */
2140 free_tree (np
); /* free it */
2141 invalidate_nodes (badfdp
, npp
);
2144 invalidate_nodes (badfdp
, &np
->left
);
2149 static int total_size_of_entries (node
*);
2150 static int number_len (long);
2152 /* Length of a non-negative number's decimal representation. */
2154 number_len (long int num
)
2157 while ((num
/= 10) > 0)
2163 * Return total number of characters that put_entries will output for
2164 * the nodes in the linked list at the right of the specified node.
2165 * This count is irrelevant with etags.el since emacs 19.34 at least,
2166 * but is still supplied for backward compatibility.
2169 total_size_of_entries (register node
*np
)
2171 register int total
= 0;
2173 for (; np
!= NULL
; np
= np
->right
)
2176 total
+= strlen (np
->regex
) + 1; /* pat\177 */
2177 if (np
->name
!= NULL
)
2178 total
+= strlen (np
->name
) + 1; /* name\001 */
2179 total
+= number_len ((long) np
->lno
) + 1; /* lno, */
2180 if (np
->cno
!= invalidcharno
) /* cno */
2181 total
+= number_len (np
->cno
);
2182 total
+= 1; /* newline */
2189 put_entries (register node
*np
)
2192 static fdesc
*fdp
= NULL
;
2197 /* Output subentries that precede this one */
2199 put_entries (np
->left
);
2201 /* Output this entry */
2210 fprintf (tagf
, "\f\n%s,%d\n",
2211 fdp
->taggedfname
, total_size_of_entries (np
));
2212 fdp
->written
= TRUE
;
2214 fputs (np
->regex
, tagf
);
2215 fputc ('\177', tagf
);
2216 if (np
->name
!= NULL
)
2218 fputs (np
->name
, tagf
);
2219 fputc ('\001', tagf
);
2221 fprintf (tagf
, "%d,", np
->lno
);
2222 if (np
->cno
!= invalidcharno
)
2223 fprintf (tagf
, "%ld", np
->cno
);
2229 if (np
->name
== NULL
)
2230 error ("internal error: NULL name in ctags mode.", (char *)NULL
);
2235 fprintf (stdout
, "%s %s %d\n",
2236 np
->name
, np
->fdp
->taggedfname
, (np
->lno
+ 63) / 64);
2238 fprintf (stdout
, "%-16s %3d %-16s %s\n",
2239 np
->name
, np
->lno
, np
->fdp
->taggedfname
, np
->regex
);
2243 fprintf (tagf
, "%s\t%s\t", np
->name
, np
->fdp
->taggedfname
);
2246 { /* function or #define macro with args */
2247 putc (searchar
, tagf
);
2250 for (sp
= np
->regex
; *sp
; sp
++)
2252 if (*sp
== '\\' || *sp
== searchar
)
2256 putc (searchar
, tagf
);
2259 { /* anything else; text pattern inadequate */
2260 fprintf (tagf
, "%d", np
->lno
);
2265 } /* if this node contains a valid tag */
2267 /* Output subentries that follow this one */
2268 put_entries (np
->right
);
2270 put_entries (np
->left
);
2275 #define C_EXT 0x00fff /* C extensions */
2276 #define C_PLAIN 0x00000 /* C */
2277 #define C_PLPL 0x00001 /* C++ */
2278 #define C_STAR 0x00003 /* C* */
2279 #define C_JAVA 0x00005 /* JAVA */
2280 #define C_AUTO 0x01000 /* C, but switch to C++ if `class' is met */
2281 #define YACC 0x10000 /* yacc file */
2284 * The C symbol tables.
2289 st_C_objprot
, st_C_objimpl
, st_C_objend
,
2291 st_C_ignore
, st_C_attribute
,
2294 st_C_class
, st_C_template
,
2295 st_C_struct
, st_C_extern
, st_C_enum
, st_C_define
, st_C_typedef
2298 static unsigned int hash (const char *, unsigned int);
2299 static struct C_stab_entry
* in_word_set (const char *, unsigned int);
2300 static enum sym_type
C_symtype (char *, int, int);
2302 /* Feed stuff between (but not including) %[ and %] lines to:
2308 struct C_stab_entry { char *name; int c_ext; enum sym_type type; }
2312 while, 0, st_C_ignore
2313 switch, 0, st_C_ignore
2314 return, 0, st_C_ignore
2315 __attribute__, 0, st_C_attribute
2316 GTY, 0, st_C_attribute
2317 @interface, 0, st_C_objprot
2318 @protocol, 0, st_C_objprot
2319 @implementation,0, st_C_objimpl
2320 @end, 0, st_C_objend
2321 import, (C_JAVA & ~C_PLPL), st_C_ignore
2322 package, (C_JAVA & ~C_PLPL), st_C_ignore
2323 friend, C_PLPL, st_C_ignore
2324 extends, (C_JAVA & ~C_PLPL), st_C_javastruct
2325 implements, (C_JAVA & ~C_PLPL), st_C_javastruct
2326 interface, (C_JAVA & ~C_PLPL), st_C_struct
2327 class, 0, st_C_class
2328 namespace, C_PLPL, st_C_struct
2329 domain, C_STAR, st_C_struct
2330 union, 0, st_C_struct
2331 struct, 0, st_C_struct
2332 extern, 0, st_C_extern
2334 typedef, 0, st_C_typedef
2335 define, 0, st_C_define
2336 undef, 0, st_C_define
2337 operator, C_PLPL, st_C_operator
2338 template, 0, st_C_template
2339 # DEFUN used in emacs, the next three used in glibc (SYSCALL only for mach).
2340 DEFUN, 0, st_C_gnumacro
2341 SYSCALL, 0, st_C_gnumacro
2342 ENTRY, 0, st_C_gnumacro
2343 PSEUDO, 0, st_C_gnumacro
2344 # These are defined inside C functions, so currently they are not met.
2345 # EXFUN used in glibc, DEFVAR_* in emacs.
2346 #EXFUN, 0, st_C_gnumacro
2347 #DEFVAR_, 0, st_C_gnumacro
2349 and replace lines between %< and %> with its output, then:
2350 - remove the #if characterset check
2351 - make in_word_set static and not inline. */
2353 /* C code produced by gperf version 3.0.1 */
2354 /* Command-line: gperf -m 5 */
2355 /* Computed positions: -k'2-3' */
2357 struct C_stab_entry
{ const char *name
; int c_ext
; enum sym_type type
; };
2358 /* maximum key range = 33, duplicates = 0 */
2368 hash (register const char *str
, register unsigned int len
)
2370 static unsigned char asso_values
[] =
2372 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2373 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2374 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2375 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2376 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2377 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2378 35, 35, 35, 35, 35, 35, 35, 35, 35, 3,
2379 26, 35, 35, 35, 35, 35, 35, 35, 27, 35,
2380 35, 35, 35, 24, 0, 35, 35, 35, 35, 0,
2381 35, 35, 35, 35, 35, 1, 35, 16, 35, 6,
2382 23, 0, 0, 35, 22, 0, 35, 35, 5, 0,
2383 0, 15, 1, 35, 6, 35, 8, 19, 35, 16,
2384 4, 5, 35, 35, 35, 35, 35, 35, 35, 35,
2385 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2386 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2387 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2388 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2389 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2390 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2391 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2392 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2393 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2394 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2395 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2396 35, 35, 35, 35, 35, 35, 35, 35, 35, 35,
2397 35, 35, 35, 35, 35, 35
2399 register int hval
= len
;
2404 hval
+= asso_values
[(unsigned char)str
[2]];
2407 hval
+= asso_values
[(unsigned char)str
[1]];
2413 static struct C_stab_entry
*
2414 in_word_set (register const char *str
, register unsigned int len
)
2418 TOTAL_KEYWORDS
= 33,
2419 MIN_WORD_LENGTH
= 2,
2420 MAX_WORD_LENGTH
= 15,
2425 static struct C_stab_entry wordlist
[] =
2428 {"if", 0, st_C_ignore
},
2429 {"GTY", 0, st_C_attribute
},
2430 {"@end", 0, st_C_objend
},
2431 {"union", 0, st_C_struct
},
2432 {"define", 0, st_C_define
},
2433 {"import", (C_JAVA
& ~C_PLPL
), st_C_ignore
},
2434 {"template", 0, st_C_template
},
2435 {"operator", C_PLPL
, st_C_operator
},
2436 {"@interface", 0, st_C_objprot
},
2437 {"implements", (C_JAVA
& ~C_PLPL
), st_C_javastruct
},
2438 {"friend", C_PLPL
, st_C_ignore
},
2439 {"typedef", 0, st_C_typedef
},
2440 {"return", 0, st_C_ignore
},
2441 {"@implementation",0, st_C_objimpl
},
2442 {"@protocol", 0, st_C_objprot
},
2443 {"interface", (C_JAVA
& ~C_PLPL
), st_C_struct
},
2444 {"extern", 0, st_C_extern
},
2445 {"extends", (C_JAVA
& ~C_PLPL
), st_C_javastruct
},
2446 {"struct", 0, st_C_struct
},
2447 {"domain", C_STAR
, st_C_struct
},
2448 {"switch", 0, st_C_ignore
},
2449 {"enum", 0, st_C_enum
},
2450 {"for", 0, st_C_ignore
},
2451 {"namespace", C_PLPL
, st_C_struct
},
2452 {"class", 0, st_C_class
},
2453 {"while", 0, st_C_ignore
},
2454 {"undef", 0, st_C_define
},
2455 {"package", (C_JAVA
& ~C_PLPL
), st_C_ignore
},
2456 {"__attribute__", 0, st_C_attribute
},
2457 {"SYSCALL", 0, st_C_gnumacro
},
2458 {"ENTRY", 0, st_C_gnumacro
},
2459 {"PSEUDO", 0, st_C_gnumacro
},
2460 {"DEFUN", 0, st_C_gnumacro
}
2463 if (len
<= MAX_WORD_LENGTH
&& len
>= MIN_WORD_LENGTH
)
2465 register int key
= hash (str
, len
);
2467 if (key
<= MAX_HASH_VALUE
&& key
>= 0)
2469 register const char *s
= wordlist
[key
].name
;
2471 if (*str
== *s
&& !strncmp (str
+ 1, s
+ 1, len
- 1) && s
[len
] == '\0')
2472 return &wordlist
[key
];
2479 static enum sym_type
2480 C_symtype (char *str
, int len
, int c_ext
)
2482 register struct C_stab_entry
*se
= in_word_set (str
, len
);
2484 if (se
== NULL
|| (se
->c_ext
&& !(c_ext
& se
->c_ext
)))
2491 * Ignoring __attribute__ ((list))
2493 static bool inattribute
; /* looking at an __attribute__ construct */
2496 * C functions and variables are recognized using a simple
2497 * finite automaton. fvdef is its state variable.
2501 fvnone
, /* nothing seen */
2502 fdefunkey
, /* Emacs DEFUN keyword seen */
2503 fdefunname
, /* Emacs DEFUN name seen */
2504 foperator
, /* func: operator keyword seen (cplpl) */
2505 fvnameseen
, /* function or variable name seen */
2506 fstartlist
, /* func: just after open parenthesis */
2507 finlist
, /* func: in parameter list */
2508 flistseen
, /* func: after parameter list */
2509 fignore
, /* func: before open brace */
2510 vignore
/* var-like: ignore until ';' */
2513 static bool fvextern
; /* func or var: extern keyword seen; */
2516 * typedefs are recognized using a simple finite automaton.
2517 * typdef is its state variable.
2521 tnone
, /* nothing seen */
2522 tkeyseen
, /* typedef keyword seen */
2523 ttypeseen
, /* defined type seen */
2524 tinbody
, /* inside typedef body */
2525 tend
, /* just before typedef tag */
2526 tignore
/* junk after typedef tag */
2530 * struct-like structures (enum, struct and union) are recognized
2531 * using another simple finite automaton. `structdef' is its state
2536 snone
, /* nothing seen yet,
2537 or in struct body if bracelev > 0 */
2538 skeyseen
, /* struct-like keyword seen */
2539 stagseen
, /* struct-like tag seen */
2540 scolonseen
/* colon seen after struct-like tag */
2544 * When objdef is different from onone, objtag is the name of the class.
2546 static const char *objtag
= "<uninited>";
2549 * Yet another little state machine to deal with preprocessor lines.
2553 dnone
, /* nothing seen */
2554 dsharpseen
, /* '#' seen as first char on line */
2555 ddefineseen
, /* '#' and 'define' seen */
2556 dignorerest
/* ignore rest of line */
2560 * State machine for Objective C protocols and implementations.
2561 * Idea by Tom R.Hageman <tom@basil.icce.rug.nl> (1995)
2565 onone
, /* nothing seen */
2566 oprotocol
, /* @interface or @protocol seen */
2567 oimplementation
, /* @implementations seen */
2568 otagseen
, /* class name seen */
2569 oparenseen
, /* parenthesis before category seen */
2570 ocatseen
, /* category name seen */
2571 oinbody
, /* in @implementation body */
2572 omethodsign
, /* in @implementation body, after +/- */
2573 omethodtag
, /* after method name */
2574 omethodcolon
, /* after method colon */
2575 omethodparm
, /* after method parameter */
2576 oignore
/* wait for @end */
2581 * Use this structure to keep info about the token read, and how it
2582 * should be tagged. Used by the make_C_tag function to build a tag.
2586 char *line
; /* string containing the token */
2587 int offset
; /* where the token starts in LINE */
2588 int length
; /* token length */
2590 The previous members can be used to pass strings around for generic
2591 purposes. The following ones specifically refer to creating tags. In this
2592 case the token contained here is the pattern that will be used to create a
2595 bool valid
; /* do not create a tag; the token should be
2596 invalidated whenever a state machine is
2597 reset prematurely */
2598 bool named
; /* create a named tag */
2599 int lineno
; /* source line number of tag */
2600 long linepos
; /* source char number of tag */
2601 } token
; /* latest token read */
2604 * Variables and functions for dealing with nested structures.
2605 * Idea by Mykola Dzyuba <mdzyuba@yahoo.com> (2001)
2607 static void pushclass_above (int, char *, int);
2608 static void popclass_above (int);
2609 static void write_classname (linebuffer
*, const char *qualifier
);
2612 char **cname
; /* nested class names */
2613 int *bracelev
; /* nested class brace level */
2614 int nl
; /* class nesting level (elements used) */
2615 int size
; /* length of the array */
2616 } cstack
; /* stack for nested declaration tags */
2617 /* Current struct nesting depth (namespace, class, struct, union, enum). */
2618 #define nestlev (cstack.nl)
2619 /* After struct keyword or in struct body, not inside a nested function. */
2620 #define instruct (structdef == snone && nestlev > 0 \
2621 && bracelev == cstack.bracelev[nestlev-1] + 1)
2624 pushclass_above (int bracelev
, char *str
, int len
)
2628 popclass_above (bracelev
);
2630 if (nl
>= cstack
.size
)
2632 int size
= cstack
.size
*= 2;
2633 xrnew (cstack
.cname
, size
, char *);
2634 xrnew (cstack
.bracelev
, size
, int);
2636 assert (nl
== 0 || cstack
.bracelev
[nl
-1] < bracelev
);
2637 cstack
.cname
[nl
] = (str
== NULL
) ? NULL
: savenstr (str
, len
);
2638 cstack
.bracelev
[nl
] = bracelev
;
2643 popclass_above (int bracelev
)
2647 for (nl
= cstack
.nl
- 1;
2648 nl
>= 0 && cstack
.bracelev
[nl
] >= bracelev
;
2651 free (cstack
.cname
[nl
]);
2657 write_classname (linebuffer
*cn
, const char *qualifier
)
2660 int qlen
= strlen (qualifier
);
2662 if (cstack
.nl
== 0 || cstack
.cname
[0] == NULL
)
2666 cn
->buffer
[0] = '\0';
2670 len
= strlen (cstack
.cname
[0]);
2671 linebuffer_setlen (cn
, len
);
2672 strcpy (cn
->buffer
, cstack
.cname
[0]);
2674 for (i
= 1; i
< cstack
.nl
; i
++)
2679 s
= cstack
.cname
[i
];
2684 linebuffer_setlen (cn
, len
);
2685 strncat (cn
->buffer
, qualifier
, qlen
);
2686 strncat (cn
->buffer
, s
, slen
);
2691 static bool consider_token (char *, int, int, int *, int, int, bool *);
2692 static void make_C_tag (bool);
2696 * checks to see if the current token is at the start of a
2697 * function or variable, or corresponds to a typedef, or
2698 * is a struct/union/enum tag, or #define, or an enum constant.
2700 * *IS_FUNC gets TRUE if the token is a function or #define macro
2701 * with args. C_EXTP points to which language we are looking at.
2712 consider_token (register char *str
, register int len
, register int c
, int *c_extp
, int bracelev
, int parlev
, int *is_func_or_var
)
2713 /* IN: token pointer */
2714 /* IN: token length */
2715 /* IN: first char after the token */
2716 /* IN, OUT: C extensions mask */
2717 /* IN: brace level */
2718 /* IN: parenthesis level */
2719 /* OUT: function or variable found */
2721 /* When structdef is stagseen, scolonseen, or snone with bracelev > 0,
2722 structtype is the type of the preceding struct-like keyword, and
2723 structbracelev is the brace level where it has been seen. */
2724 static enum sym_type structtype
;
2725 static int structbracelev
;
2726 static enum sym_type toktype
;
2729 toktype
= C_symtype (str
, len
, *c_extp
);
2732 * Skip __attribute__
2734 if (toktype
== st_C_attribute
)
2741 * Advance the definedef state machine.
2746 /* We're not on a preprocessor line. */
2747 if (toktype
== st_C_gnumacro
)
2754 if (toktype
== st_C_define
)
2756 definedef
= ddefineseen
;
2760 definedef
= dignorerest
;
2765 * Make a tag for any macro, unless it is a constant
2766 * and constantypedefs is FALSE.
2768 definedef
= dignorerest
;
2769 *is_func_or_var
= (c
== '(');
2770 if (!*is_func_or_var
&& !constantypedefs
)
2777 error ("internal error: definedef value.", (char *)NULL
);
2786 if (toktype
== st_C_typedef
)
2806 if (structdef
== snone
&& fvdef
== fvnone
)
2825 case st_C_javastruct
:
2826 if (structdef
== stagseen
)
2827 structdef
= scolonseen
;
2831 if ((*c_extp
& C_AUTO
) /* automatic detection of C++ language */
2833 && definedef
== dnone
&& structdef
== snone
2834 && typdef
== tnone
&& fvdef
== fvnone
)
2835 *c_extp
= (*c_extp
| C_PLPL
) & ~C_AUTO
;
2836 if (toktype
== st_C_template
)
2843 && (typdef
== tkeyseen
2844 || (typedefs_or_cplusplus
&& structdef
== snone
)))
2846 structdef
= skeyseen
;
2847 structtype
= toktype
;
2848 structbracelev
= bracelev
;
2849 if (fvdef
== fvnameseen
)
2855 if (structdef
== skeyseen
)
2857 structdef
= stagseen
;
2861 if (typdef
!= tnone
)
2864 /* Detect Objective C constructs. */
2874 objdef
= oimplementation
;
2878 case oimplementation
:
2879 /* Save the class tag for functions or variables defined inside. */
2880 objtag
= savenstr (str
, len
);
2884 /* Save the class tag for categories. */
2885 objtag
= savenstr (str
, len
);
2887 *is_func_or_var
= TRUE
;
2891 *is_func_or_var
= TRUE
;
2899 objdef
= omethodtag
;
2900 linebuffer_setlen (&token_name
, len
);
2901 strncpy (token_name
.buffer
, str
, len
);
2902 token_name
.buffer
[len
] = '\0';
2908 objdef
= omethodparm
;
2914 objdef
= omethodtag
;
2915 linebuffer_setlen (&token_name
, token_name
.len
+ len
);
2916 strncat (token_name
.buffer
, str
, len
);
2921 if (toktype
== st_C_objend
)
2923 /* Memory leakage here: the string pointed by objtag is
2924 never released, because many tests would be needed to
2925 avoid breaking on incorrect input code. The amount of
2926 memory leaked here is the sum of the lengths of the
2934 /* A function, variable or enum constant? */
2956 *is_func_or_var
= TRUE
;
2960 && structdef
== snone
2961 && structtype
== st_C_enum
&& bracelev
> structbracelev
)
2962 return TRUE
; /* enum constant */
2968 fvdef
= fdefunname
; /* GNU macro */
2969 *is_func_or_var
= TRUE
;
2977 if ((strneq (str
, "asm", 3) && endtoken (str
[3]))
2978 || (strneq (str
, "__asm__", 7) && endtoken (str
[7])))
2987 if (len
>= 10 && strneq (str
+len
-10, "::operator", 10))
2989 if (*c_extp
& C_AUTO
) /* automatic detection of C++ */
2990 *c_extp
= (*c_extp
| C_PLPL
) & ~C_AUTO
;
2992 *is_func_or_var
= TRUE
;
2995 if (bracelev
> 0 && !instruct
)
2997 fvdef
= fvnameseen
; /* function or variable */
2998 *is_func_or_var
= TRUE
;
3009 * C_entries often keeps pointers to tokens or lines which are older than
3010 * the line currently read. By keeping two line buffers, and switching
3011 * them at end of line, it is possible to use those pointers.
3019 #define current_lb_is_new (newndx == curndx)
3020 #define switch_line_buffers() (curndx = 1 - curndx)
3022 #define curlb (lbs[curndx].lb)
3023 #define newlb (lbs[newndx].lb)
3024 #define curlinepos (lbs[curndx].linepos)
3025 #define newlinepos (lbs[newndx].linepos)
3027 #define plainc ((c_ext & C_EXT) == C_PLAIN)
3028 #define cplpl (c_ext & C_PLPL)
3029 #define cjava ((c_ext & C_JAVA) == C_JAVA)
3031 #define CNL_SAVE_DEFINEDEF() \
3033 curlinepos = charno; \
3034 readline (&curlb, inf); \
3035 lp = curlb.buffer; \
3042 CNL_SAVE_DEFINEDEF(); \
3043 if (savetoken.valid) \
3045 token = savetoken; \
3046 savetoken.valid = FALSE; \
3048 definedef = dnone; \
3053 make_C_tag (int isfun
)
3055 /* This function is never called when token.valid is FALSE, but
3056 we must protect against invalid input or internal errors. */
3058 make_tag (token_name
.buffer
, token_name
.len
, isfun
, token
.line
,
3059 token
.offset
+token
.length
+1, token
.lineno
, token
.linepos
);
3061 { /* this branch is optimised away if !DEBUG */
3062 make_tag (concat ("INVALID TOKEN:-->", token_name
.buffer
, ""),
3063 token_name
.len
+ 17, isfun
, token
.line
,
3064 token
.offset
+token
.length
+1, token
.lineno
, token
.linepos
);
3065 error ("INVALID TOKEN", NULL
);
3068 token
.valid
= FALSE
;
3074 * This routine finds functions, variables, typedefs,
3075 * #define's, enum constants and struct/union/enum definitions in
3076 * C syntax and adds them to the list.
3079 C_entries (int c_ext
, FILE *inf
)
3080 /* extension of C */
3083 register char c
; /* latest char read; '\0' for end of line */
3084 register char *lp
; /* pointer one beyond the character `c' */
3085 int curndx
, newndx
; /* indices for current and new lb */
3086 register int tokoff
; /* offset in line of start of current token */
3087 register int toklen
; /* length of current token */
3088 const char *qualifier
; /* string used to qualify names */
3089 int qlen
; /* length of qualifier */
3090 int bracelev
; /* current brace level */
3091 int bracketlev
; /* current bracket level */
3092 int parlev
; /* current parenthesis level */
3093 int attrparlev
; /* __attribute__ parenthesis level */
3094 int templatelev
; /* current template level */
3095 int typdefbracelev
; /* bracelev where a typedef struct body begun */
3096 bool incomm
, inquote
, inchar
, quotednl
, midtoken
;
3097 bool yacc_rules
; /* in the rules part of a yacc file */
3098 struct tok savetoken
= {0}; /* token saved during preprocessor handling */
3101 linebuffer_init (&lbs
[0].lb
);
3102 linebuffer_init (&lbs
[1].lb
);
3103 if (cstack
.size
== 0)
3105 cstack
.size
= (DEBUG
) ? 1 : 4;
3107 cstack
.cname
= xnew (cstack
.size
, char *);
3108 cstack
.bracelev
= xnew (cstack
.size
, int);
3111 tokoff
= toklen
= typdefbracelev
= 0; /* keep compiler quiet */
3112 curndx
= newndx
= 0;
3116 fvdef
= fvnone
; fvextern
= FALSE
; typdef
= tnone
;
3117 structdef
= snone
; definedef
= dnone
; objdef
= onone
;
3119 midtoken
= inquote
= inchar
= incomm
= quotednl
= FALSE
;
3120 token
.valid
= savetoken
.valid
= FALSE
;
3121 bracelev
= bracketlev
= parlev
= attrparlev
= templatelev
= 0;
3123 { qualifier
= "."; qlen
= 1; }
3125 { qualifier
= "::"; qlen
= 2; }
3133 /* If we are at the end of the line, the next character is a
3134 '\0'; do not skip it, because it is what tells us
3135 to read the next line. */
3156 /* Newlines inside comments do not end macro definitions in
3158 CNL_SAVE_DEFINEDEF ();
3171 /* Newlines inside strings do not end macro definitions
3172 in traditional cpp, even though compilers don't
3173 usually accept them. */
3174 CNL_SAVE_DEFINEDEF ();
3184 /* Hmmm, something went wrong. */
3193 else if (bracketlev
> 0)
3198 if (--bracketlev
> 0)
3202 CNL_SAVE_DEFINEDEF ();
3230 if (fvdef
!= finlist
&& fvdef
!= fignore
&& fvdef
!=vignore
)
3243 else if (/* cplpl && */ *lp
== '/')
3249 if ((c_ext
& YACC
) && *lp
== '%')
3251 /* Entering or exiting rules section in yacc file. */
3253 definedef
= dnone
; fvdef
= fvnone
; fvextern
= FALSE
;
3254 typdef
= tnone
; structdef
= snone
;
3255 midtoken
= inquote
= inchar
= incomm
= quotednl
= FALSE
;
3257 yacc_rules
= !yacc_rules
;
3263 if (definedef
== dnone
)
3266 bool cpptoken
= TRUE
;
3268 /* Look back on this line. If all blanks, or nonblanks
3269 followed by an end of comment, this is a preprocessor
3271 for (cp
= newlb
.buffer
; cp
< lp
-1; cp
++)
3274 if (*cp
== '*' && *(cp
+1) == '/')
3283 definedef
= dsharpseen
;
3284 } /* if (definedef == dnone) */
3292 /* Consider token only if some involved conditions are satisfied. */
3293 if (typdef
!= tignore
3294 && definedef
!= dignorerest
3297 && (definedef
!= dnone
3298 || structdef
!= scolonseen
)
3305 if (c
== ':' && *lp
== ':' && begtoken (lp
[1]))
3306 /* This handles :: in the middle,
3307 but not at the beginning of an identifier.
3308 Also, space-separated :: is not recognised. */
3310 if (c_ext
& C_AUTO
) /* automatic detection of C++ */
3311 c_ext
= (c_ext
| C_PLPL
) & ~C_AUTO
;
3315 goto still_in_token
;
3319 bool funorvar
= FALSE
;
3322 || consider_token (newlb
.buffer
+ tokoff
, toklen
, c
,
3323 &c_ext
, bracelev
, parlev
,
3326 if (fvdef
== foperator
)
3329 lp
= skip_spaces (lp
-1);
3333 && !iswhite (*lp
) && *lp
!= '(')
3336 toklen
+= lp
- oldlp
;
3338 token
.named
= FALSE
;
3340 && nestlev
> 0 && definedef
== dnone
)
3341 /* in struct body */
3343 write_classname (&token_name
, qualifier
);
3344 linebuffer_setlen (&token_name
,
3345 token_name
.len
+qlen
+toklen
);
3346 strcat (token_name
.buffer
, qualifier
);
3347 strncat (token_name
.buffer
,
3348 newlb
.buffer
+ tokoff
, toklen
);
3351 else if (objdef
== ocatseen
)
3352 /* Objective C category */
3354 int len
= strlen (objtag
) + 2 + toklen
;
3355 linebuffer_setlen (&token_name
, len
);
3356 strcpy (token_name
.buffer
, objtag
);
3357 strcat (token_name
.buffer
, "(");
3358 strncat (token_name
.buffer
,
3359 newlb
.buffer
+ tokoff
, toklen
);
3360 strcat (token_name
.buffer
, ")");
3363 else if (objdef
== omethodtag
3364 || objdef
== omethodparm
)
3365 /* Objective C method */
3369 else if (fvdef
== fdefunname
)
3370 /* GNU DEFUN and similar macros */
3372 bool defun
= (newlb
.buffer
[tokoff
] == 'F');
3376 /* Rewrite the tag so that emacs lisp DEFUNs
3377 can be found by their elisp name */
3383 linebuffer_setlen (&token_name
, len
);
3384 strncpy (token_name
.buffer
,
3385 newlb
.buffer
+ off
, len
);
3386 token_name
.buffer
[len
] = '\0';
3389 if (token_name
.buffer
[len
] == '_')
3390 token_name
.buffer
[len
] = '-';
3391 token
.named
= defun
;
3395 linebuffer_setlen (&token_name
, toklen
);
3396 strncpy (token_name
.buffer
,
3397 newlb
.buffer
+ tokoff
, toklen
);
3398 token_name
.buffer
[toklen
] = '\0';
3399 /* Name macros and members. */
3400 token
.named
= (structdef
== stagseen
3401 || typdef
== ttypeseen
3404 && definedef
== dignorerest
)
3406 && definedef
== dnone
3407 && structdef
== snone
3410 token
.lineno
= lineno
;
3411 token
.offset
= tokoff
;
3412 token
.length
= toklen
;
3413 token
.line
= newlb
.buffer
;
3414 token
.linepos
= newlinepos
;
3417 if (definedef
== dnone
3418 && (fvdef
== fvnameseen
3419 || fvdef
== foperator
3420 || structdef
== stagseen
3422 || typdef
== ttypeseen
3423 || objdef
!= onone
))
3425 if (current_lb_is_new
)
3426 switch_line_buffers ();
3428 else if (definedef
!= dnone
3429 || fvdef
== fdefunname
3431 make_C_tag (funorvar
);
3433 else /* not yacc and consider_token failed */
3435 if (inattribute
&& fvdef
== fignore
)
3437 /* We have just met __attribute__ after a
3438 function parameter list: do not tag the
3445 } /* if (endtoken (c)) */
3446 else if (intoken (c
))
3452 } /* if (midtoken) */
3453 else if (begtoken (c
))
3461 /* This prevents tagging fb in
3462 void (__attribute__((noreturn)) *fb) (void);
3463 Fixing this is not easy and not very important. */
3467 if (plainc
|| declarations
)
3469 make_C_tag (TRUE
); /* a function */
3474 if (structdef
== stagseen
&& !cjava
)
3476 popclass_above (bracelev
);
3484 if (!yacc_rules
|| lp
== newlb
.buffer
+ 1)
3486 tokoff
= lp
- 1 - newlb
.buffer
;
3491 } /* if (begtoken) */
3492 } /* if must look at token */
3495 /* Detect end of line, colon, comma, semicolon and various braces
3496 after having handled a token.*/
3502 if (yacc_rules
&& token
.offset
== 0 && token
.valid
)
3504 make_C_tag (FALSE
); /* a yacc function */
3507 if (definedef
!= dnone
)
3513 make_C_tag (TRUE
); /* an Objective C class */
3517 objdef
= omethodcolon
;
3518 linebuffer_setlen (&token_name
, token_name
.len
+ 1);
3519 strcat (token_name
.buffer
, ":");
3522 if (structdef
== stagseen
)
3524 structdef
= scolonseen
;
3527 /* Should be useless, but may be work as a safety net. */
3528 if (cplpl
&& fvdef
== flistseen
)
3530 make_C_tag (TRUE
); /* a function */
3536 if (definedef
!= dnone
|| inattribute
)
3542 make_C_tag (FALSE
); /* a typedef */
3552 if (typdef
== tignore
|| cplpl
)
3556 if ((globals
&& bracelev
== 0 && (!fvextern
|| declarations
))
3557 || (members
&& instruct
))
3558 make_C_tag (FALSE
); /* a variable */
3561 token
.valid
= FALSE
;
3565 && (cplpl
|| !instruct
)
3566 && (typdef
== tnone
|| (typdef
!= tignore
&& instruct
)))
3568 && plainc
&& instruct
))
3569 make_C_tag (TRUE
); /* a function */
3575 && cplpl
&& structdef
== stagseen
)
3576 make_C_tag (FALSE
); /* forward declaration */
3578 token
.valid
= FALSE
;
3579 } /* switch (fvdef) */
3585 if (structdef
== stagseen
)
3589 if (definedef
!= dnone
|| inattribute
)
3595 make_C_tag (TRUE
); /* an Objective C method */
3616 && (!fvextern
|| declarations
))
3617 || (members
&& instruct
)))
3618 make_C_tag (FALSE
); /* a variable */
3621 if ((declarations
&& typdef
== tnone
&& !instruct
)
3622 || (members
&& typdef
!= tignore
&& instruct
))
3624 make_C_tag (TRUE
); /* a function */
3627 else if (!declarations
)
3629 token
.valid
= FALSE
;
3634 if (structdef
== stagseen
)
3638 if (definedef
!= dnone
|| inattribute
)
3640 if (structdef
== stagseen
)
3647 make_C_tag (FALSE
); /* a typedef */
3659 if ((members
&& bracelev
== 1)
3660 || (globals
&& bracelev
== 0
3661 && (!fvextern
|| declarations
)))
3662 make_C_tag (FALSE
); /* a variable */
3676 if (definedef
!= dnone
)
3678 if (objdef
== otagseen
&& parlev
== 0)
3679 objdef
= oparenseen
;
3683 if (typdef
== ttypeseen
3687 /* This handles constructs like:
3688 typedef void OperatorFun (int fun); */
3707 if (--attrparlev
== 0)
3708 inattribute
= FALSE
;
3711 if (definedef
!= dnone
)
3713 if (objdef
== ocatseen
&& parlev
== 1)
3715 make_C_tag (TRUE
); /* an Objective C category */
3729 || typdef
== ttypeseen
))
3732 make_C_tag (FALSE
); /* a typedef */
3735 else if (parlev
< 0) /* can happen due to ill-conceived #if's. */
3739 if (definedef
!= dnone
)
3741 if (typdef
== ttypeseen
)
3743 /* Whenever typdef is set to tinbody (currently only
3744 here), typdefbracelev should be set to bracelev. */
3746 typdefbracelev
= bracelev
;
3751 make_C_tag (TRUE
); /* a function */
3760 make_C_tag (TRUE
); /* an Objective C class */
3765 make_C_tag (TRUE
); /* an Objective C method */
3769 /* Neutralize `extern "C" {' grot. */
3770 if (bracelev
== 0 && structdef
== snone
&& nestlev
== 0
3778 case skeyseen
: /* unnamed struct */
3779 pushclass_above (bracelev
, NULL
, 0);
3782 case stagseen
: /* named struct or enum */
3783 case scolonseen
: /* a class */
3784 pushclass_above (bracelev
,token
.line
+token
.offset
, token
.length
);
3786 make_C_tag (FALSE
); /* a struct or enum */
3792 if (definedef
!= dnone
)
3794 if (fvdef
== fstartlist
)
3796 fvdef
= fvnone
; /* avoid tagging `foo' in `foo (*bar()) ()' */
3797 token
.valid
= FALSE
;
3801 if (definedef
!= dnone
)
3804 if (!ignoreindent
&& lp
== newlb
.buffer
+ 1)
3807 token
.valid
= FALSE
; /* unexpected value, token unreliable */
3808 bracelev
= 0; /* reset brace level if first column */
3809 parlev
= 0; /* also reset paren level, just in case... */
3811 else if (bracelev
< 0)
3813 token
.valid
= FALSE
; /* something gone amiss, token unreliable */
3816 if (bracelev
== 0 && fvdef
== vignore
)
3817 fvdef
= fvnone
; /* end of function */
3818 popclass_above (bracelev
);
3820 /* Only if typdef == tinbody is typdefbracelev significant. */
3821 if (typdef
== tinbody
&& bracelev
<= typdefbracelev
)
3823 assert (bracelev
== typdefbracelev
);
3828 if (definedef
!= dnone
)
3838 if ((members
&& bracelev
== 1)
3839 || (globals
&& bracelev
== 0 && (!fvextern
|| declarations
)))
3840 make_C_tag (FALSE
); /* a variable */
3848 && (structdef
== stagseen
|| fvdef
== fvnameseen
))
3855 if (templatelev
> 0)
3863 if (objdef
== oinbody
&& bracelev
== 0)
3865 objdef
= omethodsign
;
3870 case '#': case '~': case '&': case '%': case '/':
3871 case '|': case '^': case '!': case '.': case '?':
3872 if (definedef
!= dnone
)
3874 /* These surely cannot follow a function tag in C. */
3887 if (objdef
== otagseen
)
3889 make_C_tag (TRUE
); /* an Objective C class */
3892 /* If a macro spans multiple lines don't reset its state. */
3894 CNL_SAVE_DEFINEDEF ();
3900 } /* while not eof */
3902 free (lbs
[0].lb
.buffer
);
3903 free (lbs
[1].lb
.buffer
);
3907 * Process either a C++ file or a C file depending on the setting
3911 default_C_entries (FILE *inf
)
3913 C_entries (cplusplus
? C_PLPL
: C_AUTO
, inf
);
3916 /* Always do plain C. */
3918 plain_C_entries (FILE *inf
)
3923 /* Always do C++. */
3925 Cplusplus_entries (FILE *inf
)
3927 C_entries (C_PLPL
, inf
);
3930 /* Always do Java. */
3932 Cjava_entries (FILE *inf
)
3934 C_entries (C_JAVA
, inf
);
3939 Cstar_entries (FILE *inf
)
3941 C_entries (C_STAR
, inf
);
3944 /* Always do Yacc. */
3946 Yacc_entries (FILE *inf
)
3948 C_entries (YACC
, inf
);
3952 /* Useful macros. */
3953 #define LOOP_ON_INPUT_LINES(file_pointer, line_buffer, char_pointer) \
3954 for (; /* loop initialization */ \
3955 !feof (file_pointer) /* loop test */ \
3956 && /* instructions at start of loop */ \
3957 (readline (&line_buffer, file_pointer), \
3958 char_pointer = line_buffer.buffer, \
3962 #define LOOKING_AT(cp, kw) /* kw is the keyword, a literal string */ \
3963 ((assert("" kw), TRUE) /* syntax error if not a literal string */ \
3964 && strneq ((cp), kw, sizeof(kw)-1) /* cp points at kw */ \
3965 && notinname ((cp)[sizeof(kw)-1]) /* end of kw */ \
3966 && ((cp) = skip_spaces((cp)+sizeof(kw)-1))) /* skip spaces */
3968 /* Similar to LOOKING_AT but does not use notinname, does not skip */
3969 #define LOOKING_AT_NOCASE(cp, kw) /* the keyword is a literal string */ \
3970 ((assert("" kw), TRUE) /* syntax error if not a literal string */ \
3971 && strncaseeq ((cp), kw, sizeof(kw)-1) /* cp points at kw */ \
3972 && ((cp) += sizeof(kw)-1)) /* skip spaces */
3975 * Read a file, but do no processing. This is used to do regexp
3976 * matching on files that have no language defined.
3979 just_read_file (FILE *inf
)
3982 readline (&lb
, inf
);
3986 /* Fortran parsing */
3988 static void F_takeprec (void);
3989 static void F_getit (FILE *);
3994 dbp
= skip_spaces (dbp
);
3998 dbp
= skip_spaces (dbp
);
3999 if (strneq (dbp
, "(*)", 3))
4004 if (!ISDIGIT (*dbp
))
4006 --dbp
; /* force failure */
4011 while (ISDIGIT (*dbp
));
4019 dbp
= skip_spaces (dbp
);
4022 readline (&lb
, inf
);
4027 dbp
= skip_spaces (dbp
);
4029 if (!ISALPHA (*dbp
) && *dbp
!= '_' && *dbp
!= '$')
4031 for (cp
= dbp
+ 1; *cp
!= '\0' && intoken (*cp
); cp
++)
4033 make_tag (dbp
, cp
-dbp
, TRUE
,
4034 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4039 Fortran_functions (FILE *inf
)
4041 LOOP_ON_INPUT_LINES (inf
, lb
, dbp
)
4044 dbp
++; /* Ratfor escape to fortran */
4045 dbp
= skip_spaces (dbp
);
4049 if (LOOKING_AT_NOCASE (dbp
, "recursive"))
4050 dbp
= skip_spaces (dbp
);
4052 switch (lowcase (*dbp
))
4055 if (nocase_tail ("integer"))
4059 if (nocase_tail ("real"))
4063 if (nocase_tail ("logical"))
4067 if (nocase_tail ("complex") || nocase_tail ("character"))
4071 if (nocase_tail ("double"))
4073 dbp
= skip_spaces (dbp
);
4076 if (nocase_tail ("precision"))
4082 dbp
= skip_spaces (dbp
);
4085 switch (lowcase (*dbp
))
4088 if (nocase_tail ("function"))
4092 if (nocase_tail ("subroutine"))
4096 if (nocase_tail ("entry"))
4100 if (nocase_tail ("blockdata") || nocase_tail ("block data"))
4102 dbp
= skip_spaces (dbp
);
4103 if (*dbp
== '\0') /* assume un-named */
4104 make_tag ("blockdata", 9, TRUE
,
4105 lb
.buffer
, dbp
- lb
.buffer
, lineno
, linecharno
);
4107 F_getit (inf
); /* look for name */
4118 * Philippe Waroquiers (1998)
4121 /* Once we are positioned after an "interesting" keyword, let's get
4122 the real tag value necessary. */
4124 Ada_getit (FILE *inf
, const char *name_qualifier
)
4132 dbp
= skip_spaces (dbp
);
4134 || (dbp
[0] == '-' && dbp
[1] == '-'))
4136 readline (&lb
, inf
);
4139 switch (lowcase(*dbp
))
4142 if (nocase_tail ("body"))
4144 /* Skipping body of procedure body or package body or ....
4145 resetting qualifier to body instead of spec. */
4146 name_qualifier
= "/b";
4151 /* Skipping type of task type or protected type ... */
4152 if (nocase_tail ("type"))
4159 for (cp
= dbp
; *cp
!= '\0' && *cp
!= '"'; cp
++)
4164 dbp
= skip_spaces (dbp
);
4167 && (ISALPHA (*cp
) || ISDIGIT (*cp
) || *cp
== '_' || *cp
== '.'));
4175 name
= concat (dbp
, name_qualifier
, "");
4177 make_tag (name
, strlen (name
), TRUE
,
4178 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4187 Ada_funcs (FILE *inf
)
4189 bool inquote
= FALSE
;
4190 bool skip_till_semicolumn
= FALSE
;
4192 LOOP_ON_INPUT_LINES (inf
, lb
, dbp
)
4194 while (*dbp
!= '\0')
4196 /* Skip a string i.e. "abcd". */
4197 if (inquote
|| (*dbp
== '"'))
4199 dbp
= etags_strchr (dbp
+ !inquote
, '"');
4204 continue; /* advance char */
4209 break; /* advance line */
4213 /* Skip comments. */
4214 if (dbp
[0] == '-' && dbp
[1] == '-')
4215 break; /* advance line */
4217 /* Skip character enclosed in single quote i.e. 'a'
4218 and skip single quote starting an attribute i.e. 'Image. */
4227 if (skip_till_semicolumn
)
4230 skip_till_semicolumn
= FALSE
;
4232 continue; /* advance char */
4235 /* Search for beginning of a token. */
4236 if (!begtoken (*dbp
))
4239 continue; /* advance char */
4242 /* We are at the beginning of a token. */
4243 switch (lowcase(*dbp
))
4246 if (!packages_only
&& nocase_tail ("function"))
4247 Ada_getit (inf
, "/f");
4249 break; /* from switch */
4250 continue; /* advance char */
4252 if (!packages_only
&& nocase_tail ("procedure"))
4253 Ada_getit (inf
, "/p");
4254 else if (nocase_tail ("package"))
4255 Ada_getit (inf
, "/s");
4256 else if (nocase_tail ("protected")) /* protected type */
4257 Ada_getit (inf
, "/t");
4259 break; /* from switch */
4260 continue; /* advance char */
4263 if (typedefs
&& !packages_only
&& nocase_tail ("use"))
4265 /* when tagging types, avoid tagging use type Pack.Typename;
4266 for this, we will skip everything till a ; */
4267 skip_till_semicolumn
= TRUE
;
4268 continue; /* advance char */
4272 if (!packages_only
&& nocase_tail ("task"))
4273 Ada_getit (inf
, "/k");
4274 else if (typedefs
&& !packages_only
&& nocase_tail ("type"))
4276 Ada_getit (inf
, "/t");
4277 while (*dbp
!= '\0')
4281 break; /* from switch */
4282 continue; /* advance char */
4285 /* Look for the end of the token. */
4286 while (!endtoken (*dbp
))
4289 } /* advance char */
4290 } /* advance line */
4295 * Unix and microcontroller assembly tag handling
4296 * Labels: /^[a-zA-Z_.$][a-zA_Z0-9_.$]*[: ^I^J]/
4297 * Idea by Bob Weiner, Motorola Inc. (1994)
4300 Asm_labels (FILE *inf
)
4304 LOOP_ON_INPUT_LINES (inf
, lb
, cp
)
4306 /* If first char is alphabetic or one of [_.$], test for colon
4307 following identifier. */
4308 if (ISALPHA (*cp
) || *cp
== '_' || *cp
== '.' || *cp
== '$')
4310 /* Read past label. */
4312 while (ISALNUM (*cp
) || *cp
== '_' || *cp
== '.' || *cp
== '$')
4314 if (*cp
== ':' || iswhite (*cp
))
4315 /* Found end of label, so copy it and add it to the table. */
4316 make_tag (lb
.buffer
, cp
- lb
.buffer
, TRUE
,
4317 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4325 * Perl sub names: /^sub[ \t\n]+[^ \t\n{]+/
4326 * Perl variable names: /^(my|local).../
4327 * Original code by Bart Robinson <lomew@cs.utah.edu> (1995)
4328 * Additions by Michael Ernst <mernst@alum.mit.edu> (1997)
4329 * Ideas by Kai Großjohann <Kai.Grossjohann@CS.Uni-Dortmund.DE> (2001)
4332 Perl_functions (FILE *inf
)
4334 char *package
= savestr ("main"); /* current package name */
4337 LOOP_ON_INPUT_LINES (inf
, lb
, cp
)
4339 cp
= skip_spaces (cp
);
4341 if (LOOKING_AT (cp
, "package"))
4344 get_tag (cp
, &package
);
4346 else if (LOOKING_AT (cp
, "sub"))
4351 while (!notinname (*cp
))
4354 continue; /* nothing found */
4355 if ((pos
= etags_strchr (sp
, ':')) != NULL
4356 && pos
< cp
&& pos
[1] == ':')
4357 /* The name is already qualified. */
4358 make_tag (sp
, cp
- sp
, TRUE
,
4359 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4363 char savechar
, *name
;
4367 name
= concat (package
, "::", sp
);
4369 make_tag (name
, strlen(name
), TRUE
,
4370 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4374 else if (globals
) /* only if we are tagging global vars */
4376 /* Skip a qualifier, if any. */
4377 bool qual
= LOOKING_AT (cp
, "my") || LOOKING_AT (cp
, "local");
4378 /* After "my" or "local", but before any following paren or space. */
4379 char *varstart
= cp
;
4381 if (qual
/* should this be removed? If yes, how? */
4382 && (*cp
== '$' || *cp
== '@' || *cp
== '%'))
4387 while (ISALNUM (*cp
) || *cp
== '_');
4391 /* Should be examining a variable list at this point;
4392 could insist on seeing an open parenthesis. */
4393 while (*cp
!= '\0' && *cp
!= ';' && *cp
!= '=' && *cp
!= ')')
4399 make_tag (varstart
, cp
- varstart
, FALSE
,
4400 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4409 * Look for /^[\t]*def[ \t\n]+[^ \t\n(:]+/ or /^class[ \t\n]+[^ \t\n(:]+/
4410 * Idea by Eric S. Raymond <esr@thyrsus.com> (1997)
4411 * More ideas by seb bacon <seb@jamkit.com> (2002)
4414 Python_functions (FILE *inf
)
4418 LOOP_ON_INPUT_LINES (inf
, lb
, cp
)
4420 cp
= skip_spaces (cp
);
4421 if (LOOKING_AT (cp
, "def") || LOOKING_AT (cp
, "class"))
4424 while (!notinname (*cp
) && *cp
!= ':')
4426 make_tag (name
, cp
- name
, TRUE
,
4427 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4436 * - /^[ \t]*function[ \t\n]+[^ \t\n(]+/
4437 * - /^[ \t]*class[ \t\n]+[^ \t\n]+/
4438 * - /^[ \t]*define\(\"[^\"]+/
4439 * Only with --members:
4440 * - /^[ \t]*var[ \t\n]+\$[^ \t\n=;]/
4441 * Idea by Diez B. Roggisch (2001)
4444 PHP_functions (FILE *inf
)
4446 register char *cp
, *name
;
4447 bool search_identifier
= FALSE
;
4449 LOOP_ON_INPUT_LINES (inf
, lb
, cp
)
4451 cp
= skip_spaces (cp
);
4453 if (search_identifier
4456 while (!notinname (*cp
))
4458 make_tag (name
, cp
- name
, TRUE
,
4459 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4460 search_identifier
= FALSE
;
4462 else if (LOOKING_AT (cp
, "function"))
4465 cp
= skip_spaces (cp
+1);
4469 while (!notinname (*cp
))
4471 make_tag (name
, cp
- name
, TRUE
,
4472 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4475 search_identifier
= TRUE
;
4477 else if (LOOKING_AT (cp
, "class"))
4482 while (*cp
!= '\0' && !iswhite (*cp
))
4484 make_tag (name
, cp
- name
, FALSE
,
4485 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4488 search_identifier
= TRUE
;
4490 else if (strneq (cp
, "define", 6)
4491 && (cp
= skip_spaces (cp
+6))
4493 && (*cp
== '"' || *cp
== '\''))
4497 while (*cp
!= quote
&& *cp
!= '\0')
4499 make_tag (name
, cp
- name
, FALSE
,
4500 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4503 && LOOKING_AT (cp
, "var")
4507 while (!notinname(*cp
))
4509 make_tag (name
, cp
- name
, FALSE
,
4510 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
4517 * Cobol tag functions
4518 * We could look for anything that could be a paragraph name.
4519 * i.e. anything that starts in column 8 is one word and ends in a full stop.
4520 * Idea by Corny de Souza (1993)
4523 Cobol_paragraphs (FILE *inf
)
4525 register char *bp
, *ep
;
4527 LOOP_ON_INPUT_LINES (inf
, lb
, bp
)
4533 /* If eoln, compiler option or comment ignore whole line. */
4534 if (bp
[-1] != ' ' || !ISALNUM (bp
[0]))
4537 for (ep
= bp
; ISALNUM (*ep
) || *ep
== '-'; ep
++)
4540 make_tag (bp
, ep
- bp
, TRUE
,
4541 lb
.buffer
, ep
- lb
.buffer
+ 1, lineno
, linecharno
);
4548 * Ideas by Assar Westerlund <assar@sics.se> (2001)
4551 Makefile_targets (FILE *inf
)
4555 LOOP_ON_INPUT_LINES (inf
, lb
, bp
)
4557 if (*bp
== '\t' || *bp
== '#')
4559 while (*bp
!= '\0' && *bp
!= '=' && *bp
!= ':')
4561 if (*bp
== ':' || (globals
&& *bp
== '='))
4563 /* We should detect if there is more than one tag, but we do not.
4564 We just skip initial and final spaces. */
4565 char * namestart
= skip_spaces (lb
.buffer
);
4566 while (--bp
> namestart
)
4567 if (!notinname (*bp
))
4569 make_tag (namestart
, bp
- namestart
+ 1, TRUE
,
4570 lb
.buffer
, bp
- lb
.buffer
+ 2, lineno
, linecharno
);
4578 * Original code by Mosur K. Mohan (1989)
4580 * Locates tags for procedures & functions. Doesn't do any type- or
4581 * var-definitions. It does look for the keyword "extern" or
4582 * "forward" immediately following the procedure statement; if found,
4583 * the tag is skipped.
4586 Pascal_functions (FILE *inf
)
4588 linebuffer tline
; /* mostly copied from C_entries */
4590 int save_lineno
, namelen
, taglen
;
4593 bool /* each of these flags is TRUE if: */
4594 incomment
, /* point is inside a comment */
4595 inquote
, /* point is inside '..' string */
4596 get_tagname
, /* point is after PROCEDURE/FUNCTION
4597 keyword, so next item = potential tag */
4598 found_tag
, /* point is after a potential tag */
4599 inparms
, /* point is within parameter-list */
4600 verify_tag
; /* point has passed the parm-list, so the
4601 next token will determine whether this
4602 is a FORWARD/EXTERN to be ignored, or
4603 whether it is a real tag */
4605 save_lcno
= save_lineno
= namelen
= taglen
= 0; /* keep compiler quiet */
4606 name
= NULL
; /* keep compiler quiet */
4609 linebuffer_init (&tline
);
4611 incomment
= inquote
= FALSE
;
4612 found_tag
= FALSE
; /* have a proc name; check if extern */
4613 get_tagname
= FALSE
; /* found "procedure" keyword */
4614 inparms
= FALSE
; /* found '(' after "proc" */
4615 verify_tag
= FALSE
; /* check if "extern" is ahead */
4618 while (!feof (inf
)) /* long main loop to get next char */
4621 if (c
== '\0') /* if end of line */
4623 readline (&lb
, inf
);
4627 if (!((found_tag
&& verify_tag
)
4629 c
= *dbp
++; /* only if don't need *dbp pointing
4630 to the beginning of the name of
4631 the procedure or function */
4635 if (c
== '}') /* within { } comments */
4637 else if (c
== '*' && *dbp
== ')') /* within (* *) comments */
4654 inquote
= TRUE
; /* found first quote */
4656 case '{': /* found open { comment */
4660 if (*dbp
== '*') /* found open (* comment */
4665 else if (found_tag
) /* found '(' after tag, i.e., parm-list */
4668 case ')': /* end of parms list */
4673 if (found_tag
&& !inparms
) /* end of proc or fn stmt */
4680 if (found_tag
&& verify_tag
&& (*dbp
!= ' '))
4682 /* Check if this is an "extern" declaration. */
4685 if (lowcase (*dbp
== 'e'))
4687 if (nocase_tail ("extern")) /* superfluous, really! */
4693 else if (lowcase (*dbp
) == 'f')
4695 if (nocase_tail ("forward")) /* check for forward reference */
4701 if (found_tag
&& verify_tag
) /* not external proc, so make tag */
4705 make_tag (name
, namelen
, TRUE
,
4706 tline
.buffer
, taglen
, save_lineno
, save_lcno
);
4710 if (get_tagname
) /* grab name of proc or fn */
4717 /* Find block name. */
4718 for (cp
= dbp
+ 1; *cp
!= '\0' && !endtoken (*cp
); cp
++)
4721 /* Save all values for later tagging. */
4722 linebuffer_setlen (&tline
, lb
.len
);
4723 strcpy (tline
.buffer
, lb
.buffer
);
4724 save_lineno
= lineno
;
4725 save_lcno
= linecharno
;
4726 name
= tline
.buffer
+ (dbp
- lb
.buffer
);
4728 taglen
= cp
- lb
.buffer
+ 1;
4730 dbp
= cp
; /* set dbp to e-o-token */
4731 get_tagname
= FALSE
;
4735 /* And proceed to check for "extern". */
4737 else if (!incomment
&& !inquote
&& !found_tag
)
4739 /* Check for proc/fn keywords. */
4740 switch (lowcase (c
))
4743 if (nocase_tail ("rocedure")) /* c = 'p', dbp has advanced */
4747 if (nocase_tail ("unction"))
4752 } /* while not eof */
4754 free (tline
.buffer
);
4759 * Lisp tag functions
4760 * look for (def or (DEF, quote or QUOTE
4763 static void L_getit (void);
4768 if (*dbp
== '\'') /* Skip prefix quote */
4770 else if (*dbp
== '(')
4773 /* Try to skip "(quote " */
4774 if (!LOOKING_AT (dbp
, "quote") && !LOOKING_AT (dbp
, "QUOTE"))
4775 /* Ok, then skip "(" before name in (defstruct (foo)) */
4776 dbp
= skip_spaces (dbp
);
4778 get_tag (dbp
, NULL
);
4782 Lisp_functions (FILE *inf
)
4784 LOOP_ON_INPUT_LINES (inf
, lb
, dbp
)
4789 if (strneq (dbp
+1, "def", 3) || strneq (dbp
+1, "DEF", 3))
4791 dbp
= skip_non_spaces (dbp
);
4792 dbp
= skip_spaces (dbp
);
4797 /* Check for (foo::defmumble name-defined ... */
4800 while (!notinname (*dbp
) && *dbp
!= ':');
4805 while (*dbp
== ':');
4807 if (strneq (dbp
, "def", 3) || strneq (dbp
, "DEF", 3))
4809 dbp
= skip_non_spaces (dbp
);
4810 dbp
= skip_spaces (dbp
);
4820 * Lua script language parsing
4821 * Original code by David A. Capello <dacap@users.sourceforge.net> (2004)
4823 * "function" and "local function" are tags if they start at column 1.
4826 Lua_functions (FILE *inf
)
4830 LOOP_ON_INPUT_LINES (inf
, lb
, bp
)
4832 if (bp
[0] != 'f' && bp
[0] != 'l')
4835 (void)LOOKING_AT (bp
, "local"); /* skip possible "local" */
4837 if (LOOKING_AT (bp
, "function"))
4845 * Just look for lines where the first character is '/'
4846 * Also look at "defineps" for PSWrap
4848 * Richard Mlynarik <mly@adoc.xerox.com> (1997)
4849 * Masatake Yamato <masata-y@is.aist-nara.ac.jp> (1999)
4852 PS_functions (FILE *inf
)
4854 register char *bp
, *ep
;
4856 LOOP_ON_INPUT_LINES (inf
, lb
, bp
)
4861 *ep
!= '\0' && *ep
!= ' ' && *ep
!= '{';
4864 make_tag (bp
, ep
- bp
, TRUE
,
4865 lb
.buffer
, ep
- lb
.buffer
+ 1, lineno
, linecharno
);
4867 else if (LOOKING_AT (bp
, "defineps"))
4875 * Ignore anything after \ followed by space or in ( )
4876 * Look for words defined by :
4877 * Look for constant, code, create, defer, value, and variable
4878 * OBP extensions: Look for buffer:, field,
4879 * Ideas by Eduardo Horvath <eeh@netbsd.org> (2004)
4882 Forth_words (FILE *inf
)
4886 LOOP_ON_INPUT_LINES (inf
, lb
, bp
)
4887 while ((bp
= skip_spaces (bp
))[0] != '\0')
4888 if (bp
[0] == '\\' && iswhite(bp
[1]))
4889 break; /* read next line */
4890 else if (bp
[0] == '(' && iswhite(bp
[1]))
4891 do /* skip to ) or eol */
4893 while (*bp
!= ')' && *bp
!= '\0');
4894 else if ((bp
[0] == ':' && iswhite(bp
[1]) && bp
++)
4895 || LOOKING_AT_NOCASE (bp
, "constant")
4896 || LOOKING_AT_NOCASE (bp
, "code")
4897 || LOOKING_AT_NOCASE (bp
, "create")
4898 || LOOKING_AT_NOCASE (bp
, "defer")
4899 || LOOKING_AT_NOCASE (bp
, "value")
4900 || LOOKING_AT_NOCASE (bp
, "variable")
4901 || LOOKING_AT_NOCASE (bp
, "buffer:")
4902 || LOOKING_AT_NOCASE (bp
, "field"))
4903 get_tag (skip_spaces (bp
), NULL
); /* Yay! A definition! */
4905 bp
= skip_non_spaces (bp
);
4910 * Scheme tag functions
4911 * look for (def... xyzzy
4913 * (def ... ((...(xyzzy ....
4915 * Original code by Ken Haase (1985?)
4918 Scheme_functions (FILE *inf
)
4922 LOOP_ON_INPUT_LINES (inf
, lb
, bp
)
4924 if (strneq (bp
, "(def", 4) || strneq (bp
, "(DEF", 4))
4926 bp
= skip_non_spaces (bp
+4);
4927 /* Skip over open parens and white space. Don't continue past
4929 while (*bp
&& notinname (*bp
))
4933 if (LOOKING_AT (bp
, "(SET!") || LOOKING_AT (bp
, "(set!"))
4939 /* Find tags in TeX and LaTeX input files. */
4941 /* TEX_toktab is a table of TeX control sequences that define tags.
4942 * Each entry records one such control sequence.
4944 * Original code from who knows whom.
4946 * Stefan Monnier (2002)
4949 static linebuffer
*TEX_toktab
= NULL
; /* Table with tag tokens */
4951 /* Default set of control sequences to put into TEX_toktab.
4952 The value of environment var TEXTAGS is prepended to this. */
4953 static const char *TEX_defenv
= "\
4954 :chapter:section:subsection:subsubsection:eqno:label:ref:cite:bibitem\
4955 :part:appendix:entry:index:def\
4956 :newcommand:renewcommand:newenvironment:renewenvironment";
4958 static void TEX_mode (FILE *);
4959 static void TEX_decode_env (const char *, const char *);
4961 static char TEX_esc
= '\\';
4962 static char TEX_opgrp
= '{';
4963 static char TEX_clgrp
= '}';
4966 * TeX/LaTeX scanning loop.
4969 TeX_commands (FILE *inf
)
4974 /* Select either \ or ! as escape character. */
4977 /* Initialize token table once from environment. */
4978 if (TEX_toktab
== NULL
)
4979 TEX_decode_env ("TEXTAGS", TEX_defenv
);
4981 LOOP_ON_INPUT_LINES (inf
, lb
, cp
)
4983 /* Look at each TEX keyword in line. */
4986 /* Look for a TEX escape. */
4987 while (*cp
++ != TEX_esc
)
4988 if (cp
[-1] == '\0' || cp
[-1] == '%')
4991 for (key
= TEX_toktab
; key
->buffer
!= NULL
; key
++)
4992 if (strneq (cp
, key
->buffer
, key
->len
))
4995 int namelen
, linelen
;
4998 cp
= skip_spaces (cp
+ key
->len
);
4999 if (*cp
== TEX_opgrp
)
5005 (!iswhite (*p
) && *p
!= '#' &&
5006 *p
!= TEX_opgrp
&& *p
!= TEX_clgrp
);
5011 if (!opgrp
|| *p
== TEX_clgrp
)
5013 while (*p
!= '\0' && *p
!= TEX_opgrp
&& *p
!= TEX_clgrp
)
5015 linelen
= p
- lb
.buffer
+ 1;
5017 make_tag (cp
, namelen
, TRUE
,
5018 lb
.buffer
, linelen
, lineno
, linecharno
);
5019 goto tex_next_line
; /* We only tag a line once */
5027 #define TEX_LESC '\\'
5028 #define TEX_SESC '!'
5030 /* Figure out whether TeX's escapechar is '\\' or '!' and set grouping
5031 chars accordingly. */
5033 TEX_mode (FILE *inf
)
5037 while ((c
= getc (inf
)) != EOF
)
5039 /* Skip to next line if we hit the TeX comment char. */
5041 while (c
!= '\n' && c
!= EOF
)
5043 else if (c
== TEX_LESC
|| c
== TEX_SESC
)
5059 /* If the input file is compressed, inf is a pipe, and rewind may fail.
5060 No attempt is made to correct the situation. */
5064 /* Read environment and prepend it to the default string.
5065 Build token table. */
5067 TEX_decode_env (const char *evarname
, const char *defenv
)
5069 register const char *env
, *p
;
5072 /* Append default string to environment. */
5073 env
= getenv (evarname
);
5077 env
= concat (env
, defenv
, "");
5079 /* Allocate a token table */
5080 for (len
= 1, p
= env
; p
;)
5081 if ((p
= etags_strchr (p
, ':')) && *++p
!= '\0')
5083 TEX_toktab
= xnew (len
, linebuffer
);
5085 /* Unpack environment string into token table. Be careful about */
5086 /* zero-length strings (leading ':', "::" and trailing ':') */
5087 for (i
= 0; *env
!= '\0';)
5089 p
= etags_strchr (env
, ':');
5090 if (!p
) /* End of environment string. */
5091 p
= env
+ strlen (env
);
5093 { /* Only non-zero strings. */
5094 TEX_toktab
[i
].buffer
= savenstr (env
, p
- env
);
5095 TEX_toktab
[i
].len
= p
- env
;
5102 TEX_toktab
[i
].buffer
= NULL
; /* Mark end of table. */
5103 TEX_toktab
[i
].len
= 0;
5110 /* Texinfo support. Dave Love, Mar. 2000. */
5112 Texinfo_nodes (FILE *inf
)
5115 LOOP_ON_INPUT_LINES (inf
, lb
, cp
)
5116 if (LOOKING_AT (cp
, "@node"))
5119 while (*cp
!= '\0' && *cp
!= ',')
5121 make_tag (start
, cp
- start
, TRUE
,
5122 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
5129 * Contents of <title>, <h1>, <h2>, <h3> are tags.
5130 * Contents of <a name=xxx> are tags with name xxx.
5132 * Francesco Potortì, 2002.
5135 HTML_labels (FILE *inf
)
5137 bool getnext
= FALSE
; /* next text outside of HTML tags is a tag */
5138 bool skiptag
= FALSE
; /* skip to the end of the current HTML tag */
5139 bool intag
= FALSE
; /* inside an html tag, looking for ID= */
5140 bool inanchor
= FALSE
; /* when INTAG, is an anchor, look for NAME= */
5144 linebuffer_setlen (&token_name
, 0); /* no name in buffer */
5146 LOOP_ON_INPUT_LINES (inf
, lb
, dbp
)
5147 for (;;) /* loop on the same line */
5149 if (skiptag
) /* skip HTML tag */
5151 while (*dbp
!= '\0' && *dbp
!= '>')
5157 continue; /* look on the same line */
5159 break; /* go to next line */
5162 else if (intag
) /* look for "name=" or "id=" */
5164 while (*dbp
!= '\0' && *dbp
!= '>'
5165 && lowcase (*dbp
) != 'n' && lowcase (*dbp
) != 'i')
5168 break; /* go to next line */
5173 continue; /* look on the same line */
5175 if ((inanchor
&& LOOKING_AT_NOCASE (dbp
, "name="))
5176 || LOOKING_AT_NOCASE (dbp
, "id="))
5178 bool quoted
= (dbp
[0] == '"');
5181 for (end
= ++dbp
; *end
!= '\0' && *end
!= '"'; end
++)
5184 for (end
= dbp
; *end
!= '\0' && intoken (*end
); end
++)
5186 linebuffer_setlen (&token_name
, end
- dbp
);
5187 strncpy (token_name
.buffer
, dbp
, end
- dbp
);
5188 token_name
.buffer
[end
- dbp
] = '\0';
5191 intag
= FALSE
; /* we found what we looked for */
5192 skiptag
= TRUE
; /* skip to the end of the tag */
5193 getnext
= TRUE
; /* then grab the text */
5194 continue; /* look on the same line */
5199 else if (getnext
) /* grab next tokens and tag them */
5201 dbp
= skip_spaces (dbp
);
5203 break; /* go to next line */
5207 inanchor
= (lowcase (dbp
[1]) == 'a' && !intoken (dbp
[2]));
5208 continue; /* look on the same line */
5211 for (end
= dbp
+ 1; *end
!= '\0' && *end
!= '<'; end
++)
5213 make_tag (token_name
.buffer
, token_name
.len
, TRUE
,
5214 dbp
, end
- dbp
, lineno
, linecharno
);
5215 linebuffer_setlen (&token_name
, 0); /* no name in buffer */
5217 break; /* go to next line */
5220 else /* look for an interesting HTML tag */
5222 while (*dbp
!= '\0' && *dbp
!= '<')
5225 break; /* go to next line */
5227 if (lowcase (dbp
[1]) == 'a' && !intoken (dbp
[2]))
5230 continue; /* look on the same line */
5232 else if (LOOKING_AT_NOCASE (dbp
, "<title>")
5233 || LOOKING_AT_NOCASE (dbp
, "<h1>")
5234 || LOOKING_AT_NOCASE (dbp
, "<h2>")
5235 || LOOKING_AT_NOCASE (dbp
, "<h3>"))
5239 continue; /* look on the same line */
5250 * Assumes that the predicate or rule starts at column 0.
5251 * Only the first clause of a predicate or rule is added.
5252 * Original code by Sunichirou Sugou (1989)
5253 * Rewritten by Anders Lindgren (1996)
5255 static size_t prolog_pr (char *, char *);
5256 static void prolog_skip_comment (linebuffer
*, FILE *);
5257 static size_t prolog_atom (char *, size_t);
5260 Prolog_functions (FILE *inf
)
5270 LOOP_ON_INPUT_LINES (inf
, lb
, cp
)
5272 if (cp
[0] == '\0') /* Empty line */
5274 else if (iswhite (cp
[0])) /* Not a predicate */
5276 else if (cp
[0] == '/' && cp
[1] == '*') /* comment. */
5277 prolog_skip_comment (&lb
, inf
);
5278 else if ((len
= prolog_pr (cp
, last
)) > 0)
5280 /* Predicate or rule. Store the function name so that we
5281 only generate a tag for the first clause. */
5283 last
= xnew(len
+ 1, char);
5284 else if (len
+ 1 > allocated
)
5285 xrnew (last
, len
+ 1, char);
5286 allocated
= len
+ 1;
5287 strncpy (last
, cp
, len
);
5296 prolog_skip_comment (linebuffer
*plb
, FILE *inf
)
5302 for (cp
= plb
->buffer
; *cp
!= '\0'; cp
++)
5303 if (cp
[0] == '*' && cp
[1] == '/')
5305 readline (plb
, inf
);
5311 * A predicate or rule definition is added if it matches:
5312 * <beginning of line><Prolog Atom><whitespace>(
5313 * or <beginning of line><Prolog Atom><whitespace>:-
5315 * It is added to the tags database if it doesn't match the
5316 * name of the previous clause header.
5318 * Return the size of the name of the predicate or rule, or 0 if no
5322 prolog_pr (char *s
, char *last
)
5324 /* Name of last clause. */
5329 pos
= prolog_atom (s
, 0);
5334 pos
= skip_spaces (s
+ pos
) - s
;
5337 || (s
[pos
] == '(' && (pos
+= 1))
5338 || (s
[pos
] == ':' && s
[pos
+ 1] == '-' && (pos
+= 2)))
5339 && (last
== NULL
/* save only the first clause */
5340 || len
!= strlen (last
)
5341 || !strneq (s
, last
, len
)))
5343 make_tag (s
, len
, TRUE
, s
, pos
, lineno
, linecharno
);
5351 * Consume a Prolog atom.
5352 * Return the number of bytes consumed, or 0 if there was an error.
5354 * A prolog atom, in this context, could be one of:
5355 * - An alphanumeric sequence, starting with a lower case letter.
5356 * - A quoted arbitrary string. Single quotes can escape themselves.
5357 * Backslash quotes everything.
5360 prolog_atom (char *s
, size_t pos
)
5366 if (ISLOWER(s
[pos
]) || (s
[pos
] == '_'))
5368 /* The atom is unquoted. */
5370 while (ISALNUM(s
[pos
]) || (s
[pos
] == '_'))
5374 return pos
- origpos
;
5376 else if (s
[pos
] == '\'')
5387 pos
++; /* A double quote */
5389 else if (s
[pos
] == '\0')
5390 /* Multiline quoted atoms are ignored. */
5392 else if (s
[pos
] == '\\')
5394 if (s
[pos
+1] == '\0')
5401 return pos
- origpos
;
5409 * Support for Erlang
5411 * Generates tags for functions, defines, and records.
5412 * Assumes that Erlang functions start at column 0.
5413 * Original code by Anders Lindgren (1996)
5415 static int erlang_func (char *, char *);
5416 static void erlang_attribute (char *);
5417 static int erlang_atom (char *);
5420 Erlang_functions (FILE *inf
)
5430 LOOP_ON_INPUT_LINES (inf
, lb
, cp
)
5432 if (cp
[0] == '\0') /* Empty line */
5434 else if (iswhite (cp
[0])) /* Not function nor attribute */
5436 else if (cp
[0] == '%') /* comment */
5438 else if (cp
[0] == '"') /* Sometimes, strings start in column one */
5440 else if (cp
[0] == '-') /* attribute, e.g. "-define" */
5442 erlang_attribute (cp
);
5449 else if ((len
= erlang_func (cp
, last
)) > 0)
5452 * Function. Store the function name so that we only
5453 * generates a tag for the first clause.
5456 last
= xnew (len
+ 1, char);
5457 else if (len
+ 1 > allocated
)
5458 xrnew (last
, len
+ 1, char);
5459 allocated
= len
+ 1;
5460 strncpy (last
, cp
, len
);
5469 * A function definition is added if it matches:
5470 * <beginning of line><Erlang Atom><whitespace>(
5472 * It is added to the tags database if it doesn't match the
5473 * name of the previous clause header.
5475 * Return the size of the name of the function, or 0 if no function
5479 erlang_func (char *s
, char *last
)
5481 /* Name of last clause. */
5486 pos
= erlang_atom (s
);
5491 pos
= skip_spaces (s
+ pos
) - s
;
5493 /* Save only the first clause. */
5496 || len
!= (int)strlen (last
)
5497 || !strneq (s
, last
, len
)))
5499 make_tag (s
, len
, TRUE
, s
, pos
, lineno
, linecharno
);
5508 * Handle attributes. Currently, tags are generated for defines
5511 * They are on the form:
5512 * -define(foo, bar).
5513 * -define(Foo(M, N), M+N).
5514 * -record(graph, {vtab = notable, cyclic = true}).
5517 erlang_attribute (char *s
)
5521 if ((LOOKING_AT (cp
, "-define") || LOOKING_AT (cp
, "-record"))
5524 int len
= erlang_atom (skip_spaces (cp
));
5526 make_tag (cp
, len
, TRUE
, s
, cp
+ len
- s
, lineno
, linecharno
);
5533 * Consume an Erlang atom (or variable).
5534 * Return the number of bytes consumed, or -1 if there was an error.
5537 erlang_atom (char *s
)
5541 if (ISALPHA (s
[pos
]) || s
[pos
] == '_')
5543 /* The atom is unquoted. */
5546 while (ISALNUM (s
[pos
]) || s
[pos
] == '_');
5548 else if (s
[pos
] == '\'')
5550 for (pos
++; s
[pos
] != '\''; pos
++)
5551 if (s
[pos
] == '\0' /* multiline quoted atoms are ignored */
5552 || (s
[pos
] == '\\' && s
[++pos
] == '\0'))
5561 static char *scan_separators (char *);
5562 static void add_regex (char *, language
*);
5563 static char *substitute (char *, char *, struct re_registers
*);
5566 * Take a string like "/blah/" and turn it into "blah", verifying
5567 * that the first and last characters are the same, and handling
5568 * quoted separator characters. Actually, stops on the occurrence of
5569 * an unquoted separator. Also process \t, \n, etc. and turn into
5570 * appropriate characters. Works in place. Null terminates name string.
5571 * Returns pointer to terminating separator, or NULL for
5572 * unterminated regexps.
5575 scan_separators (char *name
)
5578 char *copyto
= name
;
5579 bool quoted
= FALSE
;
5581 for (++name
; *name
!= '\0'; ++name
)
5587 case 'a': *copyto
++ = '\007'; break; /* BEL (bell) */
5588 case 'b': *copyto
++ = '\b'; break; /* BS (back space) */
5589 case 'd': *copyto
++ = 0177; break; /* DEL (delete) */
5590 case 'e': *copyto
++ = 033; break; /* ESC (delete) */
5591 case 'f': *copyto
++ = '\f'; break; /* FF (form feed) */
5592 case 'n': *copyto
++ = '\n'; break; /* NL (new line) */
5593 case 'r': *copyto
++ = '\r'; break; /* CR (carriage return) */
5594 case 't': *copyto
++ = '\t'; break; /* TAB (horizontal tab) */
5595 case 'v': *copyto
++ = '\v'; break; /* VT (vertical tab) */
5601 /* Something else is quoted, so preserve the quote. */
5609 else if (*name
== '\\')
5611 else if (*name
== sep
)
5617 name
= NULL
; /* signal unterminated regexp */
5619 /* Terminate copied string. */
5624 /* Look at the argument of --regex or --no-regex and do the right
5625 thing. Same for each line of a regexp file. */
5627 analyse_regex (char *regex_arg
)
5629 if (regex_arg
== NULL
)
5631 free_regexps (); /* --no-regex: remove existing regexps */
5635 /* A real --regexp option or a line in a regexp file. */
5636 switch (regex_arg
[0])
5638 /* Comments in regexp file or null arg to --regex. */
5644 /* Read a regex file. This is recursive and may result in a
5645 loop, which will stop when the file descriptors are exhausted. */
5649 linebuffer regexbuf
;
5650 char *regexfile
= regex_arg
+ 1;
5652 /* regexfile is a file containing regexps, one per line. */
5653 regexfp
= fopen (regexfile
, "r");
5654 if (regexfp
== NULL
)
5659 linebuffer_init (®exbuf
);
5660 while (readline_internal (®exbuf
, regexfp
) > 0)
5661 analyse_regex (regexbuf
.buffer
);
5662 free (regexbuf
.buffer
);
5667 /* Regexp to be used for a specific language only. */
5671 char *lang_name
= regex_arg
+ 1;
5674 for (cp
= lang_name
; *cp
!= '}'; cp
++)
5677 error ("unterminated language name in regex: %s", regex_arg
);
5681 lang
= get_language_from_langname (lang_name
);
5684 add_regex (cp
, lang
);
5688 /* Regexp to be used for any language. */
5690 add_regex (regex_arg
, NULL
);
5695 /* Separate the regexp pattern, compile it,
5696 and care for optional name and modifiers. */
5698 add_regex (char *regexp_pattern
, language
*lang
)
5700 static struct re_pattern_buffer zeropattern
;
5701 char sep
, *pat
, *name
, *modifiers
;
5704 struct re_pattern_buffer
*patbuf
;
5707 force_explicit_name
= TRUE
, /* do not use implicit tag names */
5708 ignore_case
= FALSE
, /* case is significant */
5709 multi_line
= FALSE
, /* matches are done one line at a time */
5710 single_line
= FALSE
; /* dot does not match newline */
5713 if (strlen(regexp_pattern
) < 3)
5715 error ("null regexp", (char *)NULL
);
5718 sep
= regexp_pattern
[0];
5719 name
= scan_separators (regexp_pattern
);
5722 error ("%s: unterminated regexp", regexp_pattern
);
5727 error ("null name for regexp \"%s\"", regexp_pattern
);
5730 modifiers
= scan_separators (name
);
5731 if (modifiers
== NULL
) /* no terminating separator --> no name */
5737 modifiers
+= 1; /* skip separator */
5739 /* Parse regex modifiers. */
5740 for (; modifiers
[0] != '\0'; modifiers
++)
5741 switch (modifiers
[0])
5744 if (modifiers
== name
)
5745 error ("forcing explicit tag name but no name, ignoring", NULL
);
5746 force_explicit_name
= TRUE
;
5756 need_filebuf
= TRUE
;
5761 wrongmod
[0] = modifiers
[0];
5763 error ("invalid regexp modifier `%s', ignoring", wrongmod
);
5768 patbuf
= xnew (1, struct re_pattern_buffer
);
5769 *patbuf
= zeropattern
;
5772 static char lc_trans
[CHARS
];
5774 for (i
= 0; i
< CHARS
; i
++)
5775 lc_trans
[i
] = lowcase (i
);
5776 patbuf
->translate
= lc_trans
; /* translation table to fold case */
5780 pat
= concat ("^", regexp_pattern
, ""); /* anchor to beginning of line */
5782 pat
= regexp_pattern
;
5785 re_set_syntax (RE_SYNTAX_EMACS
| RE_DOT_NEWLINE
);
5787 re_set_syntax (RE_SYNTAX_EMACS
);
5789 err
= re_compile_pattern (pat
, strlen (pat
), patbuf
);
5794 error ("%s while compiling pattern", err
);
5799 p_head
= xnew (1, regexp
);
5800 p_head
->pattern
= savestr (regexp_pattern
);
5801 p_head
->p_next
= rp
;
5802 p_head
->lang
= lang
;
5803 p_head
->pat
= patbuf
;
5804 p_head
->name
= savestr (name
);
5805 p_head
->error_signaled
= FALSE
;
5806 p_head
->force_explicit_name
= force_explicit_name
;
5807 p_head
->ignore_case
= ignore_case
;
5808 p_head
->multi_line
= multi_line
;
5812 * Do the substitutions indicated by the regular expression and
5816 substitute (char *in
, char *out
, struct re_registers
*regs
)
5819 int size
, dig
, diglen
;
5822 size
= strlen (out
);
5824 /* Pass 1: figure out how much to allocate by finding all \N strings. */
5825 if (out
[size
- 1] == '\\')
5826 fatal ("pattern error in \"%s\"", out
);
5827 for (t
= etags_strchr (out
, '\\');
5829 t
= etags_strchr (t
+ 2, '\\'))
5833 diglen
= regs
->end
[dig
] - regs
->start
[dig
];
5839 /* Allocate space and do the substitutions. */
5841 result
= xnew (size
+ 1, char);
5843 for (t
= result
; *out
!= '\0'; out
++)
5844 if (*out
== '\\' && ISDIGIT (*++out
))
5847 diglen
= regs
->end
[dig
] - regs
->start
[dig
];
5848 strncpy (t
, in
+ regs
->start
[dig
], diglen
);
5855 assert (t
<= result
+ size
);
5856 assert (t
- result
== (int)strlen (result
));
5861 /* Deallocate all regexps. */
5866 while (p_head
!= NULL
)
5868 rp
= p_head
->p_next
;
5869 free (p_head
->pattern
);
5870 free (p_head
->name
);
5878 * Reads the whole file as a single string from `filebuf' and looks for
5879 * multi-line regular expressions, creating tags on matches.
5880 * readline already dealt with normal regexps.
5882 * Idea by Ben Wing <ben@666.com> (2002).
5885 regex_tag_multiline (void)
5887 char *buffer
= filebuf
.buffer
;
5891 for (rp
= p_head
; rp
!= NULL
; rp
= rp
->p_next
)
5895 if (!rp
->multi_line
)
5896 continue; /* skip normal regexps */
5898 /* Generic initialisations before parsing file from memory. */
5899 lineno
= 1; /* reset global line number */
5900 charno
= 0; /* reset global char number */
5901 linecharno
= 0; /* reset global char number of line start */
5903 /* Only use generic regexps or those for the current language. */
5904 if (rp
->lang
!= NULL
&& rp
->lang
!= curfdp
->lang
)
5907 while (match
>= 0 && match
< filebuf
.len
)
5909 match
= re_search (rp
->pat
, buffer
, filebuf
.len
, charno
,
5910 filebuf
.len
- match
, &rp
->regs
);
5915 if (!rp
->error_signaled
)
5917 error ("regexp stack overflow while matching \"%s\"",
5919 rp
->error_signaled
= TRUE
;
5926 if (match
== rp
->regs
.end
[0])
5928 if (!rp
->error_signaled
)
5930 error ("regexp matches the empty string: \"%s\"",
5932 rp
->error_signaled
= TRUE
;
5934 match
= -3; /* exit from while loop */
5938 /* Match occurred. Construct a tag. */
5939 while (charno
< rp
->regs
.end
[0])
5940 if (buffer
[charno
++] == '\n')
5941 lineno
++, linecharno
= charno
;
5943 if (name
[0] == '\0')
5945 else /* make a named tag */
5946 name
= substitute (buffer
, rp
->name
, &rp
->regs
);
5947 if (rp
->force_explicit_name
)
5948 /* Force explicit tag name, if a name is there. */
5949 pfnote (name
, TRUE
, buffer
+ linecharno
,
5950 charno
- linecharno
+ 1, lineno
, linecharno
);
5952 make_tag (name
, strlen (name
), TRUE
, buffer
+ linecharno
,
5953 charno
- linecharno
+ 1, lineno
, linecharno
);
5962 nocase_tail (const char *cp
)
5964 register int len
= 0;
5966 while (*cp
!= '\0' && lowcase (*cp
) == lowcase (dbp
[len
]))
5968 if (*cp
== '\0' && !intoken (dbp
[len
]))
5977 get_tag (register char *bp
, char **namepp
)
5979 register char *cp
= bp
;
5983 /* Go till you get to white space or a syntactic break */
5984 for (cp
= bp
+ 1; !notinname (*cp
); cp
++)
5986 make_tag (bp
, cp
- bp
, TRUE
,
5987 lb
.buffer
, cp
- lb
.buffer
+ 1, lineno
, linecharno
);
5991 *namepp
= savenstr (bp
, cp
- bp
);
5995 * Read a line of text from `stream' into `lbp', excluding the
5996 * newline or CR-NL, if any. Return the number of characters read from
5997 * `stream', which is the length of the line including the newline.
5999 * On DOS or Windows we do not count the CR character, if any before the
6000 * NL, in the returned length; this mirrors the behavior of Emacs on those
6001 * platforms (for text files, it translates CR-NL to NL as it reads in the
6004 * If multi-line regular expressions are requested, each line read is
6005 * appended to `filebuf'.
6008 readline_internal (linebuffer
*lbp
, register FILE *stream
)
6010 char *buffer
= lbp
->buffer
;
6011 register char *p
= lbp
->buffer
;
6012 register char *pend
;
6015 pend
= p
+ lbp
->size
; /* Separate to avoid 386/IX compiler bug. */
6019 register int c
= getc (stream
);
6022 /* We're at the end of linebuffer: expand it. */
6024 xrnew (buffer
, lbp
->size
, char);
6025 p
+= buffer
- lbp
->buffer
;
6026 pend
= buffer
+ lbp
->size
;
6027 lbp
->buffer
= buffer
;
6037 if (p
> buffer
&& p
[-1] == '\r')
6041 /* Assume CRLF->LF translation will be performed by Emacs
6042 when loading this file, so CRs won't appear in the buffer.
6043 It would be cleaner to compensate within Emacs;
6044 however, Emacs does not know how many CRs were deleted
6045 before any given point in the file. */
6060 lbp
->len
= p
- buffer
;
6062 if (need_filebuf
/* we need filebuf for multi-line regexps */
6063 && chars_deleted
> 0) /* not at EOF */
6065 while (filebuf
.size
<= filebuf
.len
+ lbp
->len
+ 1) /* +1 for \n */
6067 /* Expand filebuf. */
6069 xrnew (filebuf
.buffer
, filebuf
.size
, char);
6071 strncpy (filebuf
.buffer
+ filebuf
.len
, lbp
->buffer
, lbp
->len
);
6072 filebuf
.len
+= lbp
->len
;
6073 filebuf
.buffer
[filebuf
.len
++] = '\n';
6074 filebuf
.buffer
[filebuf
.len
] = '\0';
6077 return lbp
->len
+ chars_deleted
;
6081 * Like readline_internal, above, but in addition try to match the
6082 * input line against relevant regular expressions and manage #line
6086 readline (linebuffer
*lbp
, FILE *stream
)
6090 linecharno
= charno
; /* update global char number of line start */
6091 result
= readline_internal (lbp
, stream
); /* read line */
6092 lineno
+= 1; /* increment global line number */
6093 charno
+= result
; /* increment global char number */
6095 /* Honour #line directives. */
6096 if (!no_line_directive
)
6098 static bool discard_until_line_directive
;
6100 /* Check whether this is a #line directive. */
6101 if (result
> 12 && strneq (lbp
->buffer
, "#line ", 6))
6106 if (sscanf (lbp
->buffer
, "#line %u \"%n", &lno
, &start
) >= 1
6107 && start
> 0) /* double quote character found */
6109 char *endp
= lbp
->buffer
+ start
;
6111 while ((endp
= etags_strchr (endp
, '"')) != NULL
6112 && endp
[-1] == '\\')
6115 /* Ok, this is a real #line directive. Let's deal with it. */
6117 char *taggedabsname
; /* absolute name of original file */
6118 char *taggedfname
; /* name of original file as given */
6119 char *name
; /* temp var */
6121 discard_until_line_directive
= FALSE
; /* found it */
6122 name
= lbp
->buffer
+ start
;
6124 canonicalize_filename (name
);
6125 taggedabsname
= absolute_filename (name
, tagfiledir
);
6126 if (filename_is_absolute (name
)
6127 || filename_is_absolute (curfdp
->infname
))
6128 taggedfname
= savestr (taggedabsname
);
6130 taggedfname
= relative_filename (taggedabsname
,tagfiledir
);
6132 if (streq (curfdp
->taggedfname
, taggedfname
))
6133 /* The #line directive is only a line number change. We
6134 deal with this afterwards. */
6137 /* The tags following this #line directive should be
6138 attributed to taggedfname. In order to do this, set
6139 curfdp accordingly. */
6141 fdesc
*fdp
; /* file description pointer */
6143 /* Go look for a file description already set up for the
6144 file indicated in the #line directive. If there is
6145 one, use it from now until the next #line
6147 for (fdp
= fdhead
; fdp
!= NULL
; fdp
= fdp
->next
)
6148 if (streq (fdp
->infname
, curfdp
->infname
)
6149 && streq (fdp
->taggedfname
, taggedfname
))
6150 /* If we remove the second test above (after the &&)
6151 then all entries pertaining to the same file are
6152 coalesced in the tags file. If we use it, then
6153 entries pertaining to the same file but generated
6154 from different files (via #line directives) will
6155 go into separate sections in the tags file. These
6156 alternatives look equivalent. The first one
6157 destroys some apparently useless information. */
6163 /* Else, if we already tagged the real file, skip all
6164 input lines until the next #line directive. */
6165 if (fdp
== NULL
) /* not found */
6166 for (fdp
= fdhead
; fdp
!= NULL
; fdp
= fdp
->next
)
6167 if (streq (fdp
->infabsname
, taggedabsname
))
6169 discard_until_line_directive
= TRUE
;
6173 /* Else create a new file description and use that from
6174 now on, until the next #line directive. */
6175 if (fdp
== NULL
) /* not found */
6178 fdhead
= xnew (1, fdesc
);
6179 *fdhead
= *curfdp
; /* copy curr. file description */
6181 fdhead
->infname
= savestr (curfdp
->infname
);
6182 fdhead
->infabsname
= savestr (curfdp
->infabsname
);
6183 fdhead
->infabsdir
= savestr (curfdp
->infabsdir
);
6184 fdhead
->taggedfname
= taggedfname
;
6185 fdhead
->usecharno
= FALSE
;
6186 fdhead
->prop
= NULL
;
6187 fdhead
->written
= FALSE
;
6191 free (taggedabsname
);
6193 readline (lbp
, stream
);
6195 } /* if a real #line directive */
6196 } /* if #line is followed by a number */
6197 } /* if line begins with "#line " */
6199 /* If we are here, no #line directive was found. */
6200 if (discard_until_line_directive
)
6204 /* Do a tail recursion on ourselves, thus discarding the contents
6205 of the line buffer. */
6206 readline (lbp
, stream
);
6210 discard_until_line_directive
= FALSE
;
6213 } /* if #line directives should be considered */
6220 /* Match against relevant regexps. */
6222 for (rp
= p_head
; rp
!= NULL
; rp
= rp
->p_next
)
6224 /* Only use generic regexps or those for the current language.
6225 Also do not use multiline regexps, which is the job of
6226 regex_tag_multiline. */
6227 if ((rp
->lang
!= NULL
&& rp
->lang
!= fdhead
->lang
)
6231 match
= re_match (rp
->pat
, lbp
->buffer
, lbp
->len
, 0, &rp
->regs
);
6236 if (!rp
->error_signaled
)
6238 error ("regexp stack overflow while matching \"%s\"",
6240 rp
->error_signaled
= TRUE
;
6247 /* Empty string matched. */
6248 if (!rp
->error_signaled
)
6250 error ("regexp matches the empty string: \"%s\"", rp
->pattern
);
6251 rp
->error_signaled
= TRUE
;
6255 /* Match occurred. Construct a tag. */
6257 if (name
[0] == '\0')
6259 else /* make a named tag */
6260 name
= substitute (lbp
->buffer
, rp
->name
, &rp
->regs
);
6261 if (rp
->force_explicit_name
)
6262 /* Force explicit tag name, if a name is there. */
6263 pfnote (name
, TRUE
, lbp
->buffer
, match
, lineno
, linecharno
);
6265 make_tag (name
, strlen (name
), TRUE
,
6266 lbp
->buffer
, match
, lineno
, linecharno
);
6275 * Return a pointer to a space of size strlen(cp)+1 allocated
6276 * with xnew where the string CP has been copied.
6279 savestr (const char *cp
)
6281 return savenstr (cp
, strlen (cp
));
6285 * Return a pointer to a space of size LEN+1 allocated with xnew where
6286 * the string CP has been copied for at most the first LEN characters.
6289 savenstr (const char *cp
, int len
)
6293 dp
= xnew (len
+ 1, char);
6294 strncpy (dp
, cp
, len
);
6300 * Return the ptr in sp at which the character c last
6301 * appears; NULL if not found
6303 * Identical to POSIX strrchr, included for portability.
6306 etags_strrchr (register const char *sp
, register int c
)
6308 register const char *r
;
6320 * Return the ptr in sp at which the character c first
6321 * appears; NULL if not found
6323 * Identical to POSIX strchr, included for portability.
6326 etags_strchr (register const char *sp
, register int c
)
6337 * Compare two strings, ignoring case for alphabetic characters.
6339 * Same as BSD's strcasecmp, included for portability.
6342 etags_strcasecmp (register const char *s1
, register const char *s2
)
6345 && (ISALPHA (*s1
) && ISALPHA (*s2
)
6346 ? lowcase (*s1
) == lowcase (*s2
)
6350 return (ISALPHA (*s1
) && ISALPHA (*s2
)
6351 ? lowcase (*s1
) - lowcase (*s2
)
6356 * Compare two strings, ignoring case for alphabetic characters.
6357 * Stop after a given number of characters
6359 * Same as BSD's strncasecmp, included for portability.
6362 etags_strncasecmp (register const char *s1
, register const char *s2
, register int n
)
6364 while (*s1
!= '\0' && n
-- > 0
6365 && (ISALPHA (*s1
) && ISALPHA (*s2
)
6366 ? lowcase (*s1
) == lowcase (*s2
)
6373 return (ISALPHA (*s1
) && ISALPHA (*s2
)
6374 ? lowcase (*s1
) - lowcase (*s2
)
6378 /* Skip spaces (end of string is not space), return new pointer. */
6380 skip_spaces (char *cp
)
6382 while (iswhite (*cp
))
6387 /* Skip non spaces, except end of string, return new pointer. */
6389 skip_non_spaces (char *cp
)
6391 while (*cp
!= '\0' && !iswhite (*cp
))
6396 /* Print error message and exit. */
6398 fatal (const char *s1
, const char *s2
)
6401 exit (EXIT_FAILURE
);
6405 pfatal (const char *s1
)
6408 exit (EXIT_FAILURE
);
6412 suggest_asking_for_help (void)
6414 fprintf (stderr
, "\tTry `%s %s' for a complete list of options.\n",
6415 progname
, NO_LONG_OPTIONS
? "-h" : "--help");
6416 exit (EXIT_FAILURE
);
6419 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
6421 error (const char *s1
, const char *s2
)
6423 fprintf (stderr
, "%s: ", progname
);
6424 fprintf (stderr
, s1
, s2
);
6425 fprintf (stderr
, "\n");
6428 /* Return a newly-allocated string whose contents
6429 concatenate those of s1, s2, s3. */
6431 concat (const char *s1
, const char *s2
, const char *s3
)
6433 int len1
= strlen (s1
), len2
= strlen (s2
), len3
= strlen (s3
);
6434 char *result
= xnew (len1
+ len2
+ len3
+ 1, char);
6436 strcpy (result
, s1
);
6437 strcpy (result
+ len1
, s2
);
6438 strcpy (result
+ len1
+ len2
, s3
);
6439 result
[len1
+ len2
+ len3
] = '\0';
6445 /* Does the same work as the system V getcwd, but does not need to
6446 guess the buffer size in advance. */
6452 char *path
= xnew (bufsize
, char);
6454 while (getcwd (path
, bufsize
) == NULL
)
6456 if (errno
!= ERANGE
)
6460 path
= xnew (bufsize
, char);
6463 canonicalize_filename (path
);
6466 #else /* not HAVE_GETCWD */
6469 char *p
, path
[MAXPATHLEN
+ 1]; /* Fixed size is safe on MSDOS. */
6473 for (p
= path
; *p
!= '\0'; p
++)
6479 return strdup (path
);
6480 #else /* not MSDOS */
6484 linebuffer_init (&path
);
6485 pipe
= (FILE *) popen ("pwd 2>/dev/null", "r");
6486 if (pipe
== NULL
|| readline_internal (&path
, pipe
) == 0)
6491 #endif /* not MSDOS */
6492 #endif /* not HAVE_GETCWD */
6495 /* Return a newly allocated string containing the file name of FILE
6496 relative to the absolute directory DIR (which should end with a slash). */
6498 relative_filename (char *file
, char *dir
)
6500 char *fp
, *dp
, *afn
, *res
;
6503 /* Find the common root of file and dir (with a trailing slash). */
6504 afn
= absolute_filename (file
, cwd
);
6507 while (*fp
++ == *dp
++)
6509 fp
--, dp
--; /* back to the first differing char */
6511 if (fp
== afn
&& afn
[0] != '/') /* cannot build a relative name */
6514 do /* look at the equal chars until '/' */
6518 /* Build a sequence of "../" strings for the resulting relative file name. */
6520 while ((dp
= etags_strchr (dp
+ 1, '/')) != NULL
)
6522 res
= xnew (3*i
+ strlen (fp
+ 1) + 1, char);
6525 strcat (res
, "../");
6527 /* Add the file name relative to the common root of file and dir. */
6528 strcat (res
, fp
+ 1);
6534 /* Return a newly allocated string containing the absolute file name
6535 of FILE given DIR (which should end with a slash). */
6537 absolute_filename (char *file
, char *dir
)
6539 char *slashp
, *cp
, *res
;
6541 if (filename_is_absolute (file
))
6542 res
= savestr (file
);
6544 /* We don't support non-absolute file names with a drive
6545 letter, like `d:NAME' (it's too much hassle). */
6546 else if (file
[1] == ':')
6547 fatal ("%s: relative file names with drive letters not supported", file
);
6550 res
= concat (dir
, file
, "");
6552 /* Delete the "/dirname/.." and "/." substrings. */
6553 slashp
= etags_strchr (res
, '/');
6554 while (slashp
!= NULL
&& slashp
[0] != '\0')
6556 if (slashp
[1] == '.')
6558 if (slashp
[2] == '.'
6559 && (slashp
[3] == '/' || slashp
[3] == '\0'))
6564 while (cp
>= res
&& !filename_is_absolute (cp
));
6566 cp
= slashp
; /* the absolute name begins with "/.." */
6568 /* Under MSDOS and NT we get `d:/NAME' as absolute
6569 file name, so the luser could say `d:/../NAME'.
6570 We silently treat this as `d:/NAME'. */
6571 else if (cp
[0] != '/')
6575 memmove (cp
, slashp
+ 3, strlen (slashp
+ 2));
6577 /* Overlapping copy isn't really okay */
6578 strcpy (cp
, slashp
+ 3);
6583 else if (slashp
[2] == '/' || slashp
[2] == '\0')
6586 memmove (slashp
, slashp
+ 2, strlen (slashp
+ 1));
6588 strcpy (slashp
, slashp
+ 2);
6594 slashp
= etags_strchr (slashp
+ 1, '/');
6597 if (res
[0] == '\0') /* just a safety net: should never happen */
6600 return savestr ("/");
6606 /* Return a newly allocated string containing the absolute
6607 file name of dir where FILE resides given DIR (which should
6608 end with a slash). */
6610 absolute_dirname (char *file
, char *dir
)
6615 slashp
= etags_strrchr (file
, '/');
6617 return savestr (dir
);
6620 res
= absolute_filename (file
, dir
);
6626 /* Whether the argument string is an absolute file name. The argument
6627 string must have been canonicalized with canonicalize_filename. */
6629 filename_is_absolute (char *fn
)
6631 return (fn
[0] == '/'
6633 || (ISALPHA(fn
[0]) && fn
[1] == ':' && fn
[2] == '/')
6638 /* Downcase DOS drive letter and collapse separators into single slashes.
6641 canonicalize_filename (register char *fn
)
6647 /* Canonicalize drive letter case. */
6648 # define ISUPPER(c) isupper (CHAR(c))
6649 if (fn
[0] != '\0' && fn
[1] == ':' && ISUPPER (fn
[0]))
6650 fn
[0] = lowcase (fn
[0]);
6655 /* Collapse multiple separators into a single slash. */
6656 for (cp
= fn
; *cp
!= '\0'; cp
++, fn
++)
6660 while (cp
[1] == sep
)
6669 /* Initialize a linebuffer for use. */
6671 linebuffer_init (linebuffer
*lbp
)
6673 lbp
->size
= (DEBUG
) ? 3 : 200;
6674 lbp
->buffer
= xnew (lbp
->size
, char);
6675 lbp
->buffer
[0] = '\0';
6679 /* Set the minimum size of a string contained in a linebuffer. */
6681 linebuffer_setlen (linebuffer
*lbp
, int toksize
)
6683 while (lbp
->size
<= toksize
)
6686 xrnew (lbp
->buffer
, lbp
->size
, char);
6691 /* Like malloc but get fatal error if memory is exhausted. */
6693 xmalloc (unsigned int size
)
6695 PTR result
= (PTR
) malloc (size
);
6697 fatal ("virtual memory exhausted", (char *)NULL
);
6702 xrealloc (char *ptr
, unsigned int size
)
6704 PTR result
= (PTR
) realloc (ptr
, size
);
6706 fatal ("virtual memory exhausted", (char *)NULL
);
6712 * indent-tabs-mode: t
6715 * c-font-lock-extra-types: ("FILE" "bool" "language" "linebuffer" "fdesc" "node" "regexp")
6716 * c-file-style: "gnu"
6720 /* etags.c ends here */