/* Tags file maker to go with GNU Emacs
Copyright (C) 1984, 87, 88, 89, 93, 94, 95
Free Software Foundation, Inc. and Ken Arnold
+
This file is not considered part of GNU Emacs.
This program is free software; you can redistribute it and/or modify
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+along with this program; if not, write to the Free Software Foundation,
+Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*
* Authors:
* Gnu Emacs TAGS format and modifications by RMS?
* Sam Kendall added C++.
* Francesco Potorti` reorganised C and C++ based on work by Joe Wells.
-#ifdef ETAGS_REGEXPS
* Regexp tags by Tom Tromey.
-#endif
*
- * Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer.
+ * Francesco Potorti` (F.Potorti@cnuce.cnr.it) is the current maintainer.
*/
-char pot_etags_version[] = "@(#) pot revision number is 11.42";
+char pot_etags_version[] = "@(#) pot revision number is 11.66";
#define TRUE 1
#define FALSE 0
+
#ifndef DEBUG
# define DEBUG FALSE
#endif
#ifdef MSDOS
-#include <fcntl.h>
-#include <sys/param.h>
+# include <string.h>
+# include <fcntl.h>
+# include <sys/param.h>
#endif /* MSDOS */
#ifdef WINDOWSNT
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h>
-#define MAXPATHLEN _MAX_PATH
+# include <stdlib.h>
+# include <fcntl.h>
+# include <string.h>
+# include <io.h>
+# define MAXPATHLEN _MAX_PATH
#endif
#ifdef HAVE_CONFIG_H
-#include <config.h>
-/* On some systems, Emacs defines static as nothing for the sake
- of unexec. We don't want that here since we don't use unexec. */
-#undef static
+# include <config.h>
+ /* On some systems, Emacs defines static as nothing for the sake
+ of unexec. We don't want that here since we don't use unexec. */
+# undef static
#endif
#include <stdio.h>
#include <getopt.h>
#ifdef ETAGS_REGEXPS
-#include <regex.h>
+# include <regex.h>
#endif /* ETAGS_REGEXPS */
/* Define CTAGS to make the program "ctags" compatible with the usual one.
/* Exit codes for success and failure. */
#ifdef VMS
-#define GOOD 1
-#define BAD 0
+# define GOOD 1
+# define BAD 0
#else
-#define GOOD 0
-#define BAD 1
+# define GOOD 0
+# define BAD 1
#endif
/* C extensions. */
#define C_STAR 0x00003 /* C* */
#define YACC 0x10000 /* yacc file */
-#define streq(s,t) (strcmp (s, t) == 0)
-#define strneq(s,t,n) (strncmp (s, t, n) == 0)
+#define streq(s,t) ((DEBUG &&!(s)&&!(t)&&(abort(),1)) || !strcmp(s,t))
+#define strneq(s,t,n) ((DEBUG &&!(s)&&!(t)&&(abort(),1)) || !strncmp(s,t,n))
#define lowcase(c) tolower ((unsigned char)c)
#define endtoken(arg) (_etk[arg]) /* T if char ends tokens */
#ifdef DOS_NT
-# define absolutefn(fn) (fn[0] == '/' || (isalpha (fn[0]) && fn[1] == ':'))
+# define absolutefn(fn) (fn[0] == '/' \
+ || (fn[1] == ':' && fn[2] == '/'))
#else
# define absolutefn(fn) (fn[0] == '/')
#endif
typedef int logical;
typedef struct nd_st
-{ /* sorting structure */
+{ /* sorting structure */
char *name; /* function or type name */
char *file; /* file name */
logical is_func; /* use pattern or line no */
Lang_function C_entries;
Lang_function Cplusplus_entries;
Lang_function Cstar_entries;
+Lang_function Erlang_functions;
Lang_function Fortran_functions;
Lang_function Yacc_entries;
Lang_function Lisp_functions;
Lang_function Pascal_functions;
+Lang_function Perl_functions;
Lang_function Prolog_functions;
Lang_function Scheme_functions;
Lang_function TeX_functions;
void plain_C_entries ();
void Cplusplus_entries ();
void Cstar_entries ();
+void Erlang_functions ();
void Fortran_functions ();
void Yacc_entries ();
void Lisp_functions ();
void Pascal_functions ();
+void Perl_functions ();
void Prolog_functions ();
void Scheme_functions ();
void TeX_functions ();
void just_read_file ();
#endif
-logical get_language ();
+Lang_function *get_language_from_name ();
+Lang_function *get_language_from_interpreter ();
+Lang_function *get_language_from_suffix ();
int total_size_of_entries ();
long readline ();
long readline_internal ();
#endif
void add_node ();
void error ();
+void suggest_asking_for_help ();
void fatal (), pfatal ();
void find_entries ();
void free_tree ();
int lineno; /* line number of current line */
long charno; /* current character number */
-
-long linecharno; /* charno of start of line; not used by C,
- but by every other language. */
+long linecharno; /* charno of start of line */
char *curfile; /* current input file name */
char *tagfile; /* output file */
* `readline' reads a line from a stream into a linebuffer and works
* regardless of the length of the line.
*/
+#define GROW_LINEBUFFER(buf,toksize) \
+while (buf.size < toksize) \
+ buf.buffer = (char *) xrealloc (buf.buffer, buf.size *= 2)
struct linebuffer
{
long size;
};
struct linebuffer lb; /* the current line */
-struct linebuffer token_name; /* used by C_entries as temporary area */
+struct linebuffer token_name; /* used by C_entries as a temporary area */
struct
{
long linepos;
/* boolean "functions" (see init) */
logical _wht[0177], _etk[0177], _itk[0177], _btk[0177];
char
- *white = " \f\t\n\013", /* white chars */
- *endtk = " \t\n\013\"'#()[]{}=-+%*/&|^~!<>;,.:?", /* token ending chars */
- /* token starting chars */
- *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~",
- /* valid in-token chars */
- *intk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789";
+ /* white chars */
+ *white = " \f\t\n\013",
+ /* token ending chars */
+ *endtk = " \t\n\013\"'#()[]{}=-+%*/&|^~!<>;,.:?",
+ /* token starting chars */
+ *begtk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$~@",
+ /* valid in-token chars */
+ *intk = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz$0123456789";
logical append_to_tagfile; /* -a: append to tags */
/* The following three default to TRUE for etags, but to FALSE for ctags. */
struct pattern *patterns = NULL;
#endif /* ETAGS_REGEXPS */
-/* Language stuff. */
+/*
+ * Language stuff.
+ */
+
+/* Non-NULL if language fixed. */
+Lang_function *lang_func = NULL;
+
+/* Assembly code */
+char *Asm_suffixes [] = { "a", /* Unix assembler */
+ "asm", /* Microcontroller assembly */
+ "def", /* BSO/Tasking definition includes */
+ "inc", /* Microcontroller include files */
+ "ins", /* Microcontroller include files */
+ "s", "sa", /* Unix assembler */
+ "src", /* BSO/Tasking C compiler output */
+ NULL
+ };
+
+/* Note that .c and .h can be considered C++, if the --c++ flag was
+ given. That is why default_C_entries is called here. */
+char *default_C_suffixes [] =
+ { "c", "h", NULL };
+
+/* .M is for Objective C++ files. */
+char *Cplusplus_suffixes [] =
+ { "C", "H", "c++", "cc", "cpp", "cxx", "h++", "hh", "hpp", "hxx", "M", NULL};
+
+char *Cstar_suffixes [] =
+ { "cs", "hs", NULL };
+
+char *Erlang_suffixes [] =
+ { "erl", "hrl", NULL };
+
+char *Fortran_suffixes [] =
+ { "F", "f", "f90", "for", NULL };
+
+char *Lisp_suffixes [] =
+ { "cl", "clisp", "el", "l", "lisp", "lsp", "ml", NULL };
+
+char *Pascal_suffixes [] =
+ { "p", "pas", NULL };
+
+char *Perl_suffixes [] =
+ { "pl", "pm", NULL };
+char *Perl_interpreters [] =
+ { "perl", "@PERL@", NULL };
+
+char *plain_C_suffixes [] =
+ { "pc", /* Pro*C file */
+ "m", /* Objective C file */
+ "lm", /* Objective lex file */
+ NULL };
+
+char *Prolog_suffixes [] =
+ { "prolog", NULL };
+
+/* Can't do the `SCM' or `scm' prefix with a version number. */
+char *Scheme_suffixes [] =
+ { "SCM", "SM", "oak", "sch", "scheme", "scm", "sm", "t", NULL };
+
+char *TeX_suffixes [] =
+ { "TeX", "bib", "clo", "cls", "ltx", "sty", "tex", NULL };
+
+char *Yacc_suffixes [] =
+ { "y", "ym", NULL }; /* .ym is Objective yacc file */
+
+/* Table of language names and corresponding functions, file suffixes
+ and interpreter names.
+ It is ok for a given function to be listed under more than one
+ name. I just didn't. */
struct lang_entry
{
- char *suffix;
+ char *name;
Lang_function *function;
+ char **suffixes;
+ char **interpreters;
};
-/* Table of language names and corresponding functions. */
-/* It is ok for a given function to be listed under more than one
- name. I just didn't. */
-/* "auto" language reverts to default behavior. */
-struct lang_entry lang_names[] =
-{
- { "asm", Asm_labels },
- { "c", default_C_entries },
- { "c++", Cplusplus_entries },
- { "c*", Cstar_entries },
- { "fortran", Fortran_functions },
- { "lisp", Lisp_functions },
- { "none", just_read_file },
- { "pascal", Pascal_functions },
- { "scheme" , Scheme_functions },
- { "tex", TeX_functions },
- { "auto", NULL },
- { NULL, NULL }
-};
-
-/* Table of file name suffixes and corresponding language functions. */
-struct lang_entry lang_suffixes[] =
-{
- /* Assembly code */
- { "a", Asm_labels }, /* Unix assembler */
- { "asm", Asm_labels }, /* Microcontroller assembly */
- { "def", Asm_labels }, /* BSO/Tasking definition includes */
- { "inc", Asm_labels }, /* Microcontroller include files */
- { "ins", Asm_labels }, /* Microcontroller include files */
- { "s", Asm_labels },
- { "sa", Asm_labels }, /* Unix assembler */
- { "src", Asm_labels }, /* BSO/Tasking C compiler output */
-
- /* LaTeX source code */
- { "bib", TeX_functions },
- { "clo", TeX_functions },
- { "cls", TeX_functions },
- { "ltx", TeX_functions },
- { "sty", TeX_functions },
- { "TeX", TeX_functions },
- { "tex", TeX_functions },
-
- /* Lisp source code */
- { "cl", Lisp_functions },
- { "clisp", Lisp_functions },
- { "el", Lisp_functions },
- { "l", Lisp_functions },
- { "lisp", Lisp_functions },
- { "lsp", Lisp_functions },
- { "ml", Lisp_functions },
-
- /* Scheme source code */
- { "SCM", Scheme_functions },
- { "SM", Scheme_functions },
- { "oak", Scheme_functions },
- { "sch", Scheme_functions },
- { "scheme", Scheme_functions },
- { "scm", Scheme_functions },
- { "sm", Scheme_functions },
- { "t", Scheme_functions },
- /* FIXME Can't do the `SCM' or `scm' prefix with a version number */
-
- /* Note that .c and .h can be considered C++, if the --c++ flag was
- given. That is why default_C_entries is called here. */
- { "c", default_C_entries },
- { "h", default_C_entries },
-
- /* Pro*C file. */
- { "pc", plain_C_entries },
-
- /* C++ file */
- { "C", Cplusplus_entries },
- { "H", Cplusplus_entries },
- { "c++", Cplusplus_entries },
- { "cc", Cplusplus_entries },
- { "cpp", Cplusplus_entries },
- { "cxx", Cplusplus_entries },
- { "h++", Cplusplus_entries },
- { "hh", Cplusplus_entries },
- { "hpp", Cplusplus_entries },
- { "hxx", Cplusplus_entries },
-
- /* Yacc file */
- { "y", Yacc_entries },
-
- /* C* file */
- { "cs", Cstar_entries },
- { "hs", Cstar_entries },
-
- /* Fortran */
- { "F", Fortran_functions },
- { "f", Fortran_functions },
- { "f90", Fortran_functions },
- { "for", Fortran_functions },
-
- /* Prolog source code */
- { "prolog", Prolog_functions },
-
- /* Pascal file */
- { "p", Pascal_functions },
- { "pas", Pascal_functions },
-
- { NULL, NULL }
+struct lang_entry lang_names [] =
+{
+ { "asm", Asm_labels, Asm_suffixes, NULL },
+ { "c", default_C_entries, default_C_suffixes, NULL },
+ { "c++", Cplusplus_entries, Cplusplus_suffixes, NULL },
+ { "c*", Cstar_entries, Cstar_suffixes, NULL },
+ { "erlang", Erlang_functions, Erlang_suffixes, NULL },
+ { "fortran", Fortran_functions, Fortran_suffixes, NULL },
+ { "lisp", Lisp_functions, Lisp_suffixes, NULL },
+ { "pascal", Pascal_functions, Pascal_suffixes, NULL },
+ { "perl", Perl_functions, Perl_suffixes, Perl_interpreters },
+ { "proc", plain_C_entries, plain_C_suffixes, NULL },
+ { "prolog", Prolog_functions, Prolog_suffixes, NULL },
+ { "scheme", Scheme_functions, Scheme_suffixes, NULL },
+ { "tex", TeX_functions, TeX_suffixes, NULL },
+ { "yacc", Yacc_entries, Yacc_suffixes, NULL },
+ { "auto", NULL }, /* default guessing scheme */
+ { "none", just_read_file }, /* regexp matching only */
+ { NULL, NULL } /* end of list */
};
-/* Non-NULL if language fixed. */
-Lang_function *lang_func = NULL;
-
\f
void
print_language_names ()
{
- struct lang_entry *name, *ext;
+ struct lang_entry *lang;
+ char **ext;
puts ("\nThese are the currently supported languages, along with the\n\
default file name suffixes:");
- for (name = lang_names; name->suffix; ++name)
+ for (lang = lang_names; lang->name != NULL; lang++)
{
- printf ("\t%s\t", name->suffix);
- for (ext = lang_suffixes; ext->suffix; ++ext)
- if (name->function == ext->function)
- printf (" .%s", ext->suffix);
+ printf ("\t%s\t", lang->name);
+ if (lang->suffixes != NULL)
+ for (ext = lang->suffixes; *ext != NULL; ext++)
+ printf (" .%s", *ext);
puts ("");
}
puts ("Where `auto' means use default language for files based on file\n\
name suffix, and `none' means only do regexp processing on files.\n\
If no language is specified and no matching suffix is found,\n\
+the first line of the file is read for a sharp-bang (#!) sequence\n\
+followed by the name of an interpreter. If no such sequence is found,\n\
Fortran is tried first; if no tags are found, C is tried next.");
}
{
printf ("These are the options accepted by %s. You may use unambiguous\n\
abbreviations for the long option names. A - as file name means read\n\
-names from stdin.\n\n", progname);
+names from stdin.", progname);
+ if (!CTAGS)
+ printf (" Absolute names are stored in the output file as they\n\
+are. Relative ones are stored relative to the output file's directory.");
+ puts ("\n");
puts ("-a, --append\n\
Append tag entries to existing tags file.");
enum argument_type arg_type;
char *what;
Lang_function *function;
-} ARGUMENT;
+} argument;
#ifdef VMS /* VMS specific functions */
#endif /* VMS */
\f
-void
+int
main (argc, argv)
int argc;
char *argv[];
unsigned int nincluded_files = 0;
char **included_files = xnew (argc, char *);
char *this_file;
- ARGUMENT *argbuffer;
+ argument *argbuffer;
int current_arg = 0, file_count = 0;
struct linebuffer filename_lb;
#ifdef VMS
/* Allocate enough no matter what happens. Overkill, but each one
is small. */
- argbuffer = xnew (argc, ARGUMENT);
+ argbuffer = xnew (argc, argument);
#ifdef ETAGS_REGEXPS
/* Set syntax for regular expression routines. */
{
fprintf (stderr, "%s: -%c option may only be given once.\n",
progname, opt);
- goto usage;
+ suggest_asking_for_help ();
}
tagfile = optarg;
break;
noindentypedefs = TRUE;
break;
case 'l':
- if (!get_language (optarg, &argbuffer[current_arg].function))
- {
- fprintf (stderr, "%s: language \"%s\" not recognized.\n",
- progname, optarg);
- goto usage;
- }
+ argbuffer[current_arg].function = get_language_from_name (optarg);
argbuffer[current_arg].arg_type = at_language;
++current_arg;
break;
break;
#endif /* CTAGS */
default:
- goto usage;
+ suggest_asking_for_help ();
}
}
if (nincluded_files == 0 && file_count == 0)
{
fprintf (stderr, "%s: No input files specified.\n", progname);
-
- usage:
- fprintf (stderr, "\tTry `%s --help' for a complete list of options.\n",
- progname);
- exit (BAD);
+ suggest_asking_for_help ();
}
if (tagfile == NULL)
- {
- tagfile = CTAGS ? "tags" : "TAGS";
- }
+ tagfile = CTAGS ? "tags" : "TAGS";
cwd = etags_getcwd (); /* the current working directory */
- strcat (cwd, "/");
+ if (cwd[strlen (cwd) - 1] != '/')
+ cwd = concat (cwd, "/", "");
if (streq (tagfile, "-"))
- {
- tagfiledir = cwd;
- }
+ tagfiledir = cwd;
else
- {
- tagfiledir = absolute_dirname (tagfile, cwd);
- }
+ tagfiledir = absolute_dirname (tagfile, cwd);
init (); /* set up boolean "functions" */
if (!CTAGS)
{
if (streq (tagfile, "-"))
- tagf = stdout;
+ {
+ tagf = stdout;
+#ifdef DOS_NT
+ /* Switch redirected `stdout' to binary mode (setting `_fmode'
+ doesn't take effect until after `stdout' is already open). */
+ if (!isatty (fileno (stdout)))
+ setmode (fileno (stdout), O_BINARY);
+#endif /* DOS_NT */
+ }
else
tagf = fopen (tagfile, append_to_tagfile ? "a" : "w");
if (tagf == NULL)
/*
- * Set the language, given the name.
+ * Return a Lang_function given the name.
*/
-logical
-get_language (language, func)
- char *language;
- Lang_function **func;
+Lang_function *
+get_language_from_name (name)
+ char *name;
{
struct lang_entry *lang;
- for (lang = lang_names; lang->suffix; ++lang)
- {
- if (streq (language, lang->suffix))
- {
- *func = lang->function;
- return TRUE;
- }
- }
+ if (name != NULL)
+ for (lang = lang_names; lang->name != NULL; lang++)
+ {
+ if (streq (name, lang->name))
+ return lang->function;
+ }
- return FALSE;
+ fprintf (stderr, "%s: language \"%s\" not recognized.\n",
+ progname, optarg);
+ suggest_asking_for_help ();
+
+ /* This point should never be reached. The function should either
+ return a function pointer or never return. Note that a NULL
+ pointer cannot be considered as an error, as it means that the
+ language has not been explicitely imposed by the user ("auto"). */
+ return NULL; /* avoid warnings from compiler */
+}
+
+
+/*
+ * Return a Lang_function given the interpreter name.
+ */
+Lang_function *
+get_language_from_interpreter (interpreter)
+ char *interpreter;
+{
+ struct lang_entry *lang;
+ char **iname;
+
+ if (interpreter == NULL)
+ return NULL;
+ for (lang = lang_names; lang->name != NULL; lang++)
+ if (lang->interpreters != NULL)
+ for (iname = lang->interpreters; *iname != NULL; iname++)
+ if (streq (*iname, interpreter))
+ return lang->function;
+
+ return NULL;
+}
+
+
+
+/*
+ * Return a Lang_function given the file suffix.
+ */
+Lang_function *
+get_language_from_suffix (suffix)
+ char *suffix;
+{
+ struct lang_entry *lang;
+ char **ext;
+
+ if (suffix == NULL)
+ return NULL;
+ for (lang = lang_names; lang->name != NULL; lang++)
+ if (lang->suffixes != NULL)
+ for (ext = lang->suffixes; *ext != NULL; ext++)
+ if (streq (*ext, suffix))
+ return lang->function;
+
+ return NULL;
}
{
struct stat stat_buf;
FILE *inf;
+#ifdef DOS_NT
+ char *p;
+
+ for (p = file; *p != '\0'; p++)
+ if (*p == '\\')
+ *p = '/';
+#endif
if (stat (file, &stat_buf) == 0 && !S_ISREG (stat_buf.st_mode))
{
FILE *inf;
{
char *cp;
- struct lang_entry *lang;
+ Lang_function *function;
NODE *old_last_node;
extern NODE *last_node;
+
/* Memory leakage here: the memory block pointed by curfile is never
released. The amount of memory leaked here is the sum of the
lengths of the input file names. */
curfile = savestr (file);
- cp = etags_strrchr (file, '.');
/* If user specified a language, use it. */
- if (lang_func != NULL)
+ function = lang_func;
+ if (function != NULL)
{
- lang_func (inf);
+ function (inf);
fclose (inf);
return;
}
- if (cp)
+ cp = etags_strrchr (file, '.');
+ if (cp != NULL)
{
- ++cp;
- for (lang = lang_suffixes; lang->suffix; ++lang)
+ cp += 1;
+ function = get_language_from_suffix (cp);
+ if (function != NULL)
{
- if (streq (cp, lang->suffix))
+ function (inf);
+ fclose (inf);
+ return;
+ }
+ }
+
+ /* Look for sharp-bang as the first two characters. */
+ if (readline_internal (&lb, inf) > 2
+ && lb.buffer[0] == '#'
+ && lb.buffer[1] == '!')
+ {
+ char *lp;
+
+ /* Set lp to point at the first char after the last slash in the
+ line or, if no slashes, at the first nonblank. Then set cp to
+ the first successive blank and terminate the string. */
+ lp = etags_strrchr (lb.buffer+2, '/');
+ if (lp != NULL)
+ lp += 1;
+ else
+ for (lp = lb.buffer+2; *lp != '\0' && isspace (*lp); lp++)
+ continue;
+ for (cp = lp; *cp != '\0' && !isspace (*cp); cp++)
+ continue;
+ *cp = '\0';
+
+ if (strlen (lp) > 0)
+ {
+ function = get_language_from_interpreter (lp);
+ if (function != NULL)
{
- lang->function (inf);
+ function (inf);
fclose (inf);
return;
}
}
}
+ rewind (inf);
/* Try Fortran. */
old_last_node = last_node;
default_C_entries (inf);
}
fclose (inf);
+ return;
}
\f
/* Record a tag. */
void
pfnote (name, is_func, linestart, linelen, lno, cno)
- char *name; /* tag name, if different from definition */
+ char *name; /* tag name, or NULL if unnamed */
logical is_func; /* tag is a function */
char *linestart; /* start of the line where tag is */
int linelen; /* length of the line where tag is */
int lno; /* line number */
long cno; /* character number */
{
- register NODE *np = xnew (1, NODE);
+ register NODE *np;
+
+ if (CTAGS && name == NULL)
+ return;
+
+ np = xnew (1, NODE);
/* If ctags mode, change name "main" to M<thisfilename>. */
if (CTAGS && !cxref_style && streq (name, "main"))
np->lno = lno;
/* Our char numbers are 0-base, because of C language tradition?
ctags compatibility? old versions compatibility? I don't know.
- Anyway, since emacs's are 1-base we espect etags.el to take care
+ Anyway, since emacs's are 1-base we expect etags.el to take care
of the difference. If we wanted to have 1-based numbers, we would
uncomment the +1 below. */
np->cno = cno /* + 1 */ ;
np->left = np->right = NULL;
- np->pat = savenstr (linestart, ((CTAGS && !cxref_style) ? 50 : linelen));
+ if (CTAGS && !cxref_style)
+ {
+ if (strlen (linestart) < 50)
+ np->pat = concat (linestart, "$", "");
+ else
+ np->pat = savenstr (linestart, 50);
+ }
+ else
+ np->pat = savenstr (linestart, linelen);
add_node (np, &head);
}
fprintf (tagf, "%s\177%d,%d\n",
node->pat, node->lno, node->cno);
}
- else if (!cxref_style)
+ else
{
- fprintf (tagf, "%s\t%s\t",
- node->name, node->file);
-
- if (node->is_func)
- { /* a function */
- putc (searchar, tagf);
- putc ('^', tagf);
+ if (node->name == NULL)
+ error ("internal error: NULL name in ctags mode.", 0);
- for (sp = node->pat; *sp; sp++)
- {
- if (*sp == '\\' || *sp == searchar)
- putc ('\\', tagf);
- putc (*sp, tagf);
- }
- putc (searchar, tagf);
+ if (cxref_style)
+ {
+ if (vgrind_style)
+ fprintf (stdout, "%s %s %d\n",
+ node->name, node->file, (node->lno + 63) / 64);
+ else
+ fprintf (stdout, "%-16s %3d %-16s %s\n",
+ node->name, node->lno, node->file, node->pat);
}
else
- { /* a typedef; text pattern inadequate */
- fprintf (tagf, "%d", node->lno);
+ {
+ fprintf (tagf, "%s\t%s\t", node->name, node->file);
+
+ if (node->is_func)
+ { /* a function */
+ putc (searchar, tagf);
+ putc ('^', tagf);
+
+ for (sp = node->pat; *sp; sp++)
+ {
+ if (*sp == '\\' || *sp == searchar)
+ putc ('\\', tagf);
+ putc (*sp, tagf);
+ }
+ putc (searchar, tagf);
+ }
+ else
+ { /* a typedef; text pattern inadequate */
+ fprintf (tagf, "%d", node->lno);
+ }
+ putc ('\n', tagf);
}
- putc ('\n', tagf);
}
- else if (vgrind_style)
- fprintf (stdout, "%s %s %d\n",
- node->name, node->file, (node->lno + 63) / 64);
- else
- fprintf (stdout, "%-16s %3d %-16s %s\n",
- node->name, node->lno, node->file, node->pat);
/* Output subentries that follow this one */
put_entries (node->right);
*/
enum sym_type
{
- st_none, st_C_struct, st_C_enum, st_C_define, st_C_typedef, st_C_typespec
+ st_none, st_C_objprot, st_C_objimpl, st_C_objend, st_C_gnumacro,
+ st_C_struct, st_C_enum, st_C_define, st_C_typedef, st_C_typespec
};
/* Feed stuff between (but not including) %[ and %] lines to:
- gperf -c -k1,3 -o -p -r -t
+ gperf -c -k 1,3 -o -p -r -t
%[
struct C_stab_entry { char *name; int c_ext; enum sym_type type; }
%%
+@interface, 0, st_C_objprot
+@protocol, 0, st_C_objprot
+@implementation,0, st_C_objimpl
+@end, 0, st_C_objend
class, C_PLPL, st_C_struct
+namespace, C_PLPL, st_C_struct
domain, C_STAR, st_C_struct
union, 0, st_C_struct
struct, 0, st_C_struct
enum, 0, st_C_enum
typedef, 0, st_C_typedef
define, 0, st_C_define
+bool, C_PLPL, st_C_typespec
long, 0, st_C_typespec
short, 0, st_C_typespec
int, 0, st_C_typespec
static, 0, st_C_typespec
const, 0, st_C_typespec
volatile, 0, st_C_typespec
+explicit, C_PLPL, st_C_typespec
+mutable, C_PLPL, st_C_typespec
+typename, C_PLPL, st_C_typespec
+# DEFUN used in emacs, the next three used in glibc (SYSCALL only for mach).
+DEFUN, 0, st_C_gnumacro
+SYSCALL, 0, st_C_gnumacro
+ENTRY, 0, st_C_gnumacro
+PSEUDO, 0, st_C_gnumacro
+# These are defined inside C functions, so currently they are not met.
+# EXFUN used in glibc, DEFVAR_* in emacs.
+#EXFUN, 0, st_C_gnumacro
+#DEFVAR_, 0, st_C_gnumacro
%]
and replace lines between %< and %> with its output. */
/*%<*/
-/* C code produced by gperf version 1.8.1 (K&R C version) */
-/* Command-line: gperf -c -k1,3 -o -p -r -t */
+/* C code produced by gperf version 2.1 (K&R C version) */
+/* Command-line: gperf -c -k 1,3 -o -p -r -t */
struct C_stab_entry { char *name; int c_ext; enum sym_type type; };
#define MIN_WORD_LENGTH 3
-#define MAX_WORD_LENGTH 8
-#define MIN_HASH_VALUE 10
-#define MAX_HASH_VALUE 62
+#define MAX_WORD_LENGTH 15
+#define MIN_HASH_VALUE 34
+#define MAX_HASH_VALUE 121
/*
- 21 keywords
- 53 is the maximum key range
+ 34 keywords
+ 88 is the maximum key range
*/
static int
hash (str, len)
- register char *str;
- register int len;
+ register char *str;
+ register unsigned int len;
{
static unsigned char hash_table[] =
{
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
- 62, 62, 62, 62, 62, 62, 62, 2, 62, 7,
- 6, 9, 15, 30, 62, 24, 62, 62, 1, 24,
- 7, 27, 13, 62, 19, 26, 18, 27, 1, 62,
- 62, 62, 62, 62, 62, 62, 62, 62,
+ 121, 121, 121, 121, 121, 121, 121, 121, 121, 121,
+ 121, 121, 121, 121, 121, 121, 121, 121, 121, 121,
+ 121, 121, 121, 121, 121, 121, 121, 121, 121, 121,
+ 121, 121, 121, 121, 121, 121, 121, 121, 121, 121,
+ 121, 121, 121, 121, 121, 121, 121, 121, 121, 121,
+ 121, 121, 121, 121, 121, 121, 121, 121, 121, 121,
+ 121, 121, 121, 121, 45, 121, 121, 121, 16, 19,
+ 61, 121, 121, 121, 121, 121, 121, 121, 121, 121,
+ 10, 121, 121, 20, 53, 121, 121, 121, 121, 121,
+ 121, 121, 121, 121, 121, 121, 121, 41, 45, 22,
+ 60, 47, 37, 28, 121, 55, 121, 121, 20, 14,
+ 29, 30, 5, 121, 50, 59, 30, 54, 6, 121,
+ 121, 121, 121, 121, 121, 121, 121, 121,
};
return len + hash_table[str[2]] + hash_table[str[0]];
}
struct C_stab_entry *
-in_word_set (str, len)
+in_word_set (str, len)
register char *str;
- register int len;
+ register unsigned int len;
{
static struct C_stab_entry wordlist[] =
{
- {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
- {"",},
+ {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
+ {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
+ {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
+ {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
{"volatile", 0, st_C_typespec},
- {"",},
+ {"PSEUDO", 0, st_C_gnumacro},
+ {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
+ {"typedef", 0, st_C_typedef},
+ {"typename", C_PLPL, st_C_typespec},
+ {"",}, {"",}, {"",},
+ {"SYSCALL", 0, st_C_gnumacro},
+ {"",}, {"",}, {"",},
+ {"mutable", C_PLPL, st_C_typespec},
+ {"namespace", C_PLPL, st_C_struct},
{"long", 0, st_C_typespec},
+ {"",}, {"",},
+ {"const", 0, st_C_typespec},
+ {"",}, {"",}, {"",},
+ {"explicit", C_PLPL, st_C_typespec},
+ {"",}, {"",}, {"",}, {"",},
+ {"void", 0, st_C_typespec},
+ {"",},
{"char", 0, st_C_typespec},
{"class", C_PLPL, st_C_struct},
- {"",}, {"",}, {"",}, {"",},
- {"const", 0, st_C_typespec},
- {"",}, {"",}, {"",}, {"",},
+ {"",}, {"",}, {"",},
+ {"float", 0, st_C_typespec},
+ {"",},
+ {"@implementation", 0, st_C_objimpl},
{"auto", 0, st_C_typespec},
- {"",}, {"",},
- {"define", 0, st_C_define},
- {"",},
- {"void", 0, st_C_typespec},
- {"",}, {"",}, {"",},
- {"extern", 0, st_C_typespec},
- {"static", 0, st_C_typespec},
- {"",},
+ {"",},
+ {"ENTRY", 0, st_C_gnumacro},
+ {"@end", 0, st_C_objend},
+ {"bool", C_PLPL, st_C_typespec},
{"domain", C_STAR, st_C_struct},
- {"",},
- {"typedef", 0, st_C_typedef},
- {"double", 0, st_C_typespec},
- {"enum", 0, st_C_enum},
- {"",}, {"",}, {"",}, {"",},
+ {"",},
+ {"DEFUN", 0, st_C_gnumacro},
+ {"extern", 0, st_C_typespec},
+ {"@interface", 0, st_C_objprot},
+ {"",}, {"",}, {"",},
{"int", 0, st_C_typespec},
- {"",},
- {"float", 0, st_C_typespec},
- {"",}, {"",}, {"",},
- {"struct", 0, st_C_struct},
- {"",}, {"",}, {"",}, {"",},
- {"union", 0, st_C_struct},
- {"",},
+ {"",}, {"",}, {"",}, {"",},
+ {"signed", 0, st_C_typespec},
{"short", 0, st_C_typespec},
- {"",}, {"",},
+ {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
+ {"define", 0, st_C_define},
+ {"@protocol", 0, st_C_objprot},
+ {"enum", 0, st_C_enum},
+ {"static", 0, st_C_typespec},
+ {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
+ {"union", 0, st_C_struct},
+ {"struct", 0, st_C_struct},
+ {"",}, {"",}, {"",}, {"",},
+ {"double", 0, st_C_typespec},
{"unsigned", 0, st_C_typespec},
- {"signed", 0, st_C_typespec},
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register char *s = wordlist[key].name;
- if (*s == *str && strneq (str + 1, s + 1, len - 1))
+ if (*s == *str && !strncmp (str + 1, s + 1, len - 1))
return &wordlist[key];
}
}
* C functions are recognized using a simple finite automaton.
* funcdef is its state variable.
*/
-typedef enum
+enum
{
fnone, /* nothing seen */
ftagseen, /* function-like tag seen */
finlist, /* in parameter list */
flistseen, /* after parameter list */
fignore /* before open brace */
-} FUNCST;
-FUNCST funcdef;
+} funcdef;
/*
* typedefs are recognized using a simple finite automaton.
- * typeddef is its state variable.
+ * typdef is its state variable.
*/
-typedef enum
+enum
{
tnone, /* nothing seen */
ttypedseen, /* typedef keyword seen */
tinbody, /* inside typedef body */
tend, /* just before typedef tag */
tignore /* junk after typedef tag */
-} TYPEDST;
-TYPEDST typdef;
+} typdef;
/*
* using another simple finite automaton. `structdef' is its state
* variable.
*/
-typedef enum
+enum
{
snone, /* nothing seen yet */
skeyseen, /* struct-like keyword seen */
stagseen, /* struct-like tag seen */
scolonseen, /* colon seen after struct-like tag */
sinbody /* in struct body: recognize member func defs*/
-} STRUCTST;
-STRUCTST structdef;
+} structdef;
/*
* When structdef is stagseen, scolonseen, or sinbody, structtag is the
char *structtag = "<uninited>";
enum sym_type structtype;
+/*
+ * When objdef is different from onone, objtag is the name of the class.
+ */
+char *objtag = "<uninited>";
+
/*
* Yet another little state machine to deal with preprocessor lines.
*/
-typedef enum
+enum
{
dnone, /* nothing seen */
dsharpseen, /* '#' seen as first char on line */
ddefineseen, /* '#' and 'define' seen */
dignorerest /* ignore rest of line */
-} DEFINEST;
-DEFINEST definedef;
+} definedef;
+
+/*
+ * State machine for Objective C protocols and implementations.
+ */
+enum
+{
+ onone, /* nothing seen */
+ oprotocol, /* @interface or @protocol seen */
+ oimplementation, /* @implementations seen */
+ otagseen, /* class name seen */
+ oparenseen, /* parenthesis before category seen */
+ ocatseen, /* category name seen */
+ oinbody, /* in @implementation body */
+ omethodsign, /* in @implementation body, after +/- */
+ omethodtag, /* after method name */
+ omethodcolon, /* after method colon */
+ omethodparm, /* after method parameter */
+ oignore /* wait for @end */
+} objdef;
/*
* Set this to TRUE, and the next token considered is called a function.
*/
logical yacc_rules;
+/*
+ * methodlen is the length of the method name stored in token_name.
+ */
+int methodlen;
+
/*
* consider_token ()
* checks to see if the current token is at the start of a
* structdef IN OUT
* definedef IN OUT
* typdef IN OUT
+ * objdef IN OUT
* next_token_is_func IN OUT
*/
logical
-consider_token (str, len, c, c_ext, cblev, is_func)
+consider_token (str, len, c, c_ext, cblev, parlev, is_func)
register char *str; /* IN: token pointer */
register int len; /* IN: token length */
register char c; /* IN: first char after the token */
int c_ext; /* IN: C extensions mask */
int cblev; /* IN: curly brace level */
+ int parlev; /* IN: parenthesis level */
logical *is_func; /* OUT: function found */
{
enum sym_type toktype = C_symtype (str, len, c_ext);
}
/* Detect GNU macros. */
- if (definedef == dnone)
- if (strneq (str, "DEFUN", len) /* Used in emacs */
-#if FALSE
- These are defined inside C functions, so currently they
- are not met anyway.
- || strneq (str, "EXFUN", len) /* Used in glibc */
- || strneq (str, "DEFVAR_", 7) /* Used in emacs */
-#endif
- || strneq (str, "SYSCALL", len) /* Used in glibc (mach) */
- || strneq (str, "ENTRY", len) /* Used in glibc */
- || strneq (str, "PSEUDO", len)) /* Used in glibc */
-
- {
- next_token_is_func = TRUE;
- return FALSE;
- }
+ if (definedef == dnone && toktype == st_C_gnumacro)
+ {
+ next_token_is_func = TRUE;
+ return FALSE;
+ }
if (next_token_is_func)
{
next_token_is_func = FALSE;
return TRUE;
}
+ /*
+ * Detecting Objective C constructs.
+ */
+ switch (objdef)
+ {
+ case onone:
+ switch (toktype)
+ {
+ case st_C_objprot:
+ objdef = oprotocol;
+ return FALSE;
+ case st_C_objimpl:
+ objdef = oimplementation;
+ return FALSE;
+ }
+ break;
+ case oimplementation:
+ /* Save the class tag for functions that may be defined inside. */
+ objtag = savenstr (str, len);
+ objdef = oinbody;
+ return FALSE;
+ case oprotocol:
+ /* Save the class tag for categories. */
+ objtag = savenstr (str, len);
+ objdef = otagseen;
+ *is_func = TRUE;
+ return TRUE;
+ case oparenseen:
+ objdef = ocatseen;
+ *is_func = TRUE;
+ return TRUE;
+ case oinbody:
+ break;
+ case omethodsign:
+ if (parlev == 0)
+ {
+ objdef = omethodtag;
+ methodlen = len;
+ GROW_LINEBUFFER (token_name, methodlen+1);
+ strncpy (token_name.buffer, str, len);
+ token_name.buffer[methodlen] = '\0';
+ return TRUE;
+ }
+ return FALSE;
+ case omethodcolon:
+ if (parlev == 0)
+ objdef = omethodparm;
+ return FALSE;
+ case omethodparm:
+ if (parlev == 0)
+ {
+ objdef = omethodtag;
+ methodlen += len;
+ GROW_LINEBUFFER (token_name, methodlen+1);
+ strncat (token_name.buffer, str, len);
+ return TRUE;
+ }
+ return FALSE;
+ case oignore:
+ if (toktype == st_C_objend)
+ {
+ /* Memory leakage here: the string pointed by objtag is
+ never released, because many tests would be needed to
+ avoid breaking on incorrect input code. The amount of
+ memory leaked here is the sum of the lengths of the
+ class tags.
+ free (objtag); */
+ objdef = onone;
+ }
+ return FALSE;
+ }
+
/* A function? */
switch (toktype)
{
do { \
curlinepos = charno; \
lineno++; \
+ linecharno = charno; \
charno += readline (&curlb, inf); \
lp = curlb.buffer; \
quotednl = FALSE; \
definedef = dnone; \
} while (0)
+/* Ideally this macro should never be called wihen tok.valid is FALSE,
+ but this would mean that the state machines always guess right. */
#define make_tag(isfun) do \
-{ \
- if (tok.valid) \
- { \
- char *name = NULL; \
- if (tok.named) \
- name = savestr (token_name.buffer); \
- pfnote (name, isfun, tok.buffer, tok.linelen, tok.lineno, tok.linepos); \
- } \
- else if (DEBUG) abort (); \
+if (tok.valid) { \
+ char *name = NULL; \
+ if (CTAGS || tok.named) \
+ name = savestr (token_name.buffer); \
+ pfnote (name, isfun, tok.buffer, tok.linelen, tok.lineno, tok.linepos); \
tok.valid = FALSE; \
} while (0)
lp = curlb.buffer;
*lp = 0;
- definedef = dnone; funcdef = fnone; typdef = tnone; structdef = snone;
+ funcdef = fnone; typdef = tnone; structdef = snone;
+ definedef = dnone; objdef = onone;
next_token_is_func = yacc_rules = FALSE;
midtoken = inquote = inchar = incomm = quotednl = FALSE;
tok.valid = savetok.valid = FALSE;
incomm = TRUE;
continue;
}
- else if (cplpl && *lp == '/')
+ else if (/* cplpl && */ *lp == '/')
{
- c = 0;
+ c = '\0';
break;
}
else
{
if (endtoken (c))
{
- if (cplpl && c == ':' && *lp == ':' && begtoken(*(lp + 1)))
+ if (c == ':' && cplpl && *lp == ':' && begtoken(*(lp + 1)))
{
/*
* This handles :: in the middle, but not at the
logical is_func = FALSE;
if (yacc_rules
- || consider_token (newlb.buffer + tokoff, toklen,
- c, c_ext, cblev, &is_func))
+ || consider_token (newlb.buffer + tokoff, toklen, c,
+ c_ext, cblev, parlev, &is_func))
{
if (structdef == sinbody
&& definedef == dnone
&& is_func)
/* function defined in C++ class body */
{
- int strsize = strlen(structtag) + 2 + toklen + 1;
- while (token_name.size < strsize)
- {
- token_name.size *= 2;
- token_name.buffer
- = (char *) xrealloc (token_name.buffer,
- token_name.size);
- }
+ GROW_LINEBUFFER (token_name,
+ strlen(structtag)+2+toklen+1);
strcpy (token_name.buffer, structtag);
strcat (token_name.buffer, "::");
strncat (token_name.buffer,
newlb.buffer+tokoff, toklen);
tok.named = TRUE;
}
+ else if (objdef == ocatseen)
+ /* Objective C category */
+ {
+ GROW_LINEBUFFER (token_name,
+ strlen(objtag)+2+toklen+1);
+ strcpy (token_name.buffer, objtag);
+ strcat (token_name.buffer, "(");
+ strncat (token_name.buffer,
+ newlb.buffer+tokoff, toklen);
+ strcat (token_name.buffer, ")");
+ tok.named = TRUE;
+ }
+ else if (objdef == omethodtag
+ || objdef == omethodparm)
+ /* Objective C method */
+ {
+ tok.named = TRUE;
+ }
else
{
- while (token_name.size < toklen + 1)
- {
- token_name.size *= 2;
- token_name.buffer
- = (char *) xrealloc (token_name.buffer,
- token_name.size);
- }
+ GROW_LINEBUFFER (token_name, toklen+1);
strncpy (token_name.buffer,
newlb.buffer+tokoff, toklen);
token_name.buffer[toklen] = '\0';
if (definedef == dnone
&& (funcdef == ftagseen
|| structdef == stagseen
- || typdef == tend))
+ || typdef == tend
+ || objdef != onone))
{
if (current_lb_is_new)
switch_line_buffers ();
case ':':
if (definedef != dnone)
break;
+ switch (objdef)
+ {
+ case otagseen:
+ objdef = oignore;
+ make_tag (TRUE);
+ break;
+ case omethodtag:
+ case omethodparm:
+ objdef = omethodcolon;
+ methodlen += 1;
+ GROW_LINEBUFFER (token_name, methodlen+1);
+ strcat (token_name.buffer, ":");
+ break;
+ }
if (structdef == stagseen)
structdef = scolonseen;
else
typdef = tnone;
}
if (funcdef != fignore)
- funcdef = fnone;
+ {
+ funcdef = fnone;
+ /* The following instruction invalidates the token.
+ Probably the token should be invalidated in all
+ other cases where some state machine is reset. */
+ tok.valid = FALSE;
+ }
if (structdef == stagseen)
structdef = snone;
break;
case ',':
if (definedef != dnone)
break;
+ switch (objdef)
+ {
+ case omethodtag:
+ case omethodparm:
+ make_tag (TRUE);
+ objdef = oinbody;
+ break;
+ }
if (funcdef != finlist && funcdef != fignore)
funcdef = fnone;
if (structdef == stagseen)
case '(':
if (definedef != dnone)
break;
+ if (objdef == otagseen && parlev == 0)
+ objdef = oparenseen;
switch (funcdef)
{
case fnone:
case ')':
if (definedef != dnone)
break;
+ if (objdef == ocatseen && parlev == 1)
+ {
+ make_tag (TRUE);
+ objdef = oignore;
+ }
if (--parlev == 0)
{
switch (funcdef)
funcdef = fnone;
break;
case fnone:
- /* Neutralize `extern "C" {' grot and look inside structs. */
- if (cblev == 0 && structdef == snone && typdef == tnone)
- cblev = -1;
+ switch (objdef)
+ {
+ case otagseen:
+ make_tag (TRUE);
+ objdef = oignore;
+ break;
+ case omethodtag:
+ case omethodparm:
+ make_tag (TRUE);
+ objdef = oinbody;
+ break;
+ default:
+ /* Neutralize `extern "C" {' grot and look inside structs. */
+ if (cblev == 0 && structdef == snone && typdef == tnone)
+ cblev = -1;
+ }
}
cblev++;
break;
/* Memory leakage here: the string pointed by structtag is
never released, because I fear to miss something and
break things while freeing the area. The amount of
- memory leaked here is the sum of the lenghts of the
+ memory leaked here is the sum of the lengths of the
struct tags.
if (structdef == sinbody)
free (structtag); */
structtag = "<error>";
}
break;
- case '=':
- case '#': case '+': case '-': case '~': case '&': case '%': case '/':
+ case '+':
+ case '-':
+ if (objdef == oinbody && cblev == 0)
+ {
+ objdef = omethodsign;
+ break;
+ }
+ /* FALLTHRU */
+ case '=': case '#': case '~': case '&': case '%': case '/':
case '|': case '^': case '!': case '<': case '>': case '.': case '?':
if (definedef != dnone)
break;
funcdef = fnone;
break;
case '\0':
+ if (objdef == otagseen)
+ {
+ make_tag (TRUE);
+ objdef = oignore;
+ }
/* If a macro spans multiple lines don't reset its state. */
if (quotednl)
CNL_SAVE_DEFINEDEF;
&& (isalpha (*cp) || isdigit (*cp) || (*cp == '_') || (*cp == '$')));
cp++)
continue;
- pfnote (NULL, TRUE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
+ pfnote ((CTAGS) ? savenstr (dbp, cp-dbp) : NULL, TRUE,
+ lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
}
void
if (*cp == ':' || isspace (*cp))
{
/* Found end of label, so copy it and add it to the table. */
- pfnote (NULL, TRUE,
+ pfnote ((CTAGS) ? savenstr(lb.buffer, cp-lb.buffer) : NULL, TRUE,
lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
}
}
}
}
\f
-/* Added by Mosur Mohan, 4/22/88 */
-/* Pascal parsing */
+/*
+ * Perl support by Bart Robinson <lomew@cs.utah.edu>
+ * Perl sub names: look for /^sub[ \t\n]+[^ \t\n{]+/
+ */
+void
+Perl_functions (inf)
+ FILE *inf;
+{
+ register char *cp;
-#define GET_NEW_LINE \
-{ \
- linecharno = charno; lineno++; \
- charno += 1 + readline (&lb, inf); \
- dbp = lb.buffer; \
+ lineno = 0;
+ charno = 0;
+
+ while (!feof (inf))
+ {
+ lineno++;
+ linecharno = charno;
+ charno += readline (&lb, inf);
+ cp = lb.buffer;
+
+ if (*cp++ == 's' && *cp++ == 'u' && *cp++ == 'b' && isspace(*cp++))
+ {
+ while (*cp && isspace(*cp))
+ cp++;
+ while (*cp && ! isspace(*cp) && *cp != '{')
+ cp++;
+ pfnote ((CTAGS) ? savenstr (lb.buffer, cp-lb.buffer) : NULL, TRUE,
+ lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
+ }
+ }
}
+\f
+/* Added by Mosur Mohan, 4/22/88 */
+/* Pascal parsing */
/*
* Locates tags for procedures & functions. Doesn't do any type- or
struct linebuffer tline; /* mostly copied from C_entries */
long save_lcno;
int save_lineno, save_len;
- char c;
+ char c, *cp, *namebuf;
logical /* each of these flags is TRUE iff: */
incomment, /* point is inside a comment */
c = *dbp++;
if (c == '\0') /* if end of line */
{
- GET_NEW_LINE;
+ lineno++;
+ linecharno = charno;
+ charno += readline (&lb, inf);
+ dbp = lb.buffer;
if (*dbp == '\0')
continue;
if (!((found_tag && verify_tag) ||
{
found_tag = FALSE;
verify_tag = FALSE;
- pfnote (NULL, TRUE,
+ pfnote (namebuf, TRUE,
tline.buffer, save_len, save_lineno, save_lcno);
continue;
}
}
if (get_tagname) /* grab name of proc or fn */
{
- int size;
-
if (*dbp == '\0')
continue;
/* save all values for later tagging */
- size = strlen (lb.buffer) + 1;
- while (size > tline.size)
- {
- tline.size *= 2;
- tline.buffer = (char *) xrealloc (tline.buffer, tline.size);
- }
+ GROW_LINEBUFFER (tline, strlen (lb.buffer) + 1);
strcpy (tline.buffer, lb.buffer);
save_lineno = lineno;
save_lcno = linecharno;
/* grab block name */
- for (dbp++; *dbp && (!endtoken (*dbp)); dbp++)
+ for (cp = dbp + 1; *cp && (!endtoken (*cp)); cp++)
continue;
+ namebuf = (CTAGS) ? savenstr (dbp, cp-dbp) : NULL;
+ dbp = cp; /* set dbp to e-o-token */
save_len = dbp - lb.buffer + 1;
get_tagname = FALSE;
found_tag = TRUE;
if (cp == dbp)
return;
- pfnote (NULL, TRUE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
+ pfnote ((CTAGS) ? savenstr (dbp, cp-dbp) : NULL, TRUE,
+ lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
}
void
*cp && *cp != '(' && *cp != ')' && !isspace (*cp);
cp++)
continue;
- pfnote (NULL, TRUE, lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
+ pfnote ((CTAGS) ? savenstr (dbp, cp-dbp) : NULL, TRUE,
+ lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
}
\f
/* Find tags in TeX and LaTeX input files. */
return -1;
}
\f
-/* Support for Prolog. */
+/*
+ * Prolog support (rewritten) by Anders Lindgren, Mar. 96
+ *
+ * Assumes that the predicate starts at column 0.
+ * Only the first clause of a predicate is added.
+ */
+void
+Prolog_functions (inf)
+ FILE *inf;
+{
+ int prolog_pred ();
+ void prolog_skip_comment ();
+
+ char * last;
+ int len;
+ int allocated;
+
+ allocated = 0;
+ len = 0;
+ last = NULL;
+
+ lineno = 0;
+ linecharno = 0;
+ charno = 0;
+
+ while (!feof (inf))
+ {
+ lineno++;
+ linecharno += charno;
+ charno = readline (&lb, inf);
+ dbp = lb.buffer;
+ if (dbp[0] == '\0') /* Empty line */
+ continue;
+ else if (isspace (dbp[0])) /* Not a predicate */
+ continue;
+ else if (dbp[0] == '/' && dbp[1] == '*') /* comment. */
+ prolog_skip_comment (&lb, inf, &lineno, &linecharno);
+ else if (len = prolog_pred (dbp, last))
+ {
+ /* Predicate. Store the function name so that we only
+ * generates a tag for the first clause. */
+ if (last == NULL)
+ last = xnew(len + 1, char);
+ else if (len + 1 > allocated)
+ last = (char *) xrealloc(last, len + 1);
+ allocated = len + 1;
+ strncpy (last, dbp, len);
+ last[len] = '\0';
+ }
+ }
+}
+
-/* Whole head (not only functor, but also arguments)
- is gotten in compound term. */
void
-prolog_getit (s)
+prolog_skip_comment (plb, inf)
+ struct linebuffer *plb;
+ FILE *inf;
+{
+ char *cp;
+
+ do
+ {
+ for (cp = plb->buffer; *cp != '\0'; cp++)
+ if (cp[0] == '*' && cp[1] == '/')
+ return;
+ lineno++;
+ linecharno += readline (plb, inf);
+ }
+ while (!feof(inf));
+}
+
+/*
+ * A predicate definition is added if it matches:
+ * <beginning of line><Prolog Atom><whitespace>(
+ *
+ * It is added to the tags database if it doesn't match the
+ * name of the previous clause header.
+ *
+ * Return the size of the name of the predicate, or 0 if no header
+ * was found.
+ */
+int
+prolog_pred (s, last)
char *s;
+ char *last; /* Name of last clause. */
{
- char *save_s;
- int insquote, npar;
+ int prolog_atom();
+ int prolog_white();
- save_s = s;
- insquote = FALSE;
- npar = 0;
- while (1)
+ int pos;
+ int len;
+
+ pos = prolog_atom(s, 0);
+ if (pos < 1)
+ return 0;
+
+ len = pos;
+ pos += prolog_white(s, pos);
+
+ if ((s[pos] == '(') || (s[pos] == '.'))
{
- if (s[0] == '\0') /* syntax error. */
- return;
- else if (insquote && s[0] == '\'' && s[1] == '\'')
- s += 2;
- else if (s[0] == '\'')
+ if (s[pos] == '(')
+ pos++;
+
+ /* Save only the first clause. */
+ if ((last == NULL) ||
+ (len != strlen(last)) ||
+ (strncmp(s, last, len) != 0))
{
- insquote = !insquote;
- s++;
+ pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE,
+ s, pos, lineno, linecharno);
+ return len;
}
- else if (!insquote && s[0] == '(')
+ }
+ return 0;
+}
+
+/*
+ * Consume a Prolog atom.
+ * Return the number of bytes consumed, or -1 if there was an error.
+ *
+ * A prolog atom, in this context, could be one of:
+ * - An alphanumeric sequence, starting with a lower case letter.
+ * - A quoted arbitrary string. Single quotes can escape themselves.
+ * Backslash quotes everything.
+ */
+int
+prolog_atom (s, pos)
+ char *s;
+ int pos;
+{
+ int origpos;
+
+ origpos = pos;
+
+ if (islower(s[pos]) || (s[pos] == '_'))
+ {
+ /* The atom is unquoted. */
+ pos++;
+ while (isalnum(s[pos]) || (s[pos] == '_'))
{
- npar++;
- s++;
+ pos++;
}
- else if (!insquote && s[0] == ')')
+ return pos - origpos;
+ }
+ else if (s[pos] == '\'')
+ {
+ pos++;
+
+ while (1)
{
- npar--;
- s++;
- if (npar == 0)
- break;
- else if (npar < 0) /* syntax error. */
- return;
- }
- else if (!insquote && s[0] == '.'
- && (isspace (s[1]) || s[1] == '\0'))
- { /* fullstop. */
- if (npar != 0) /* syntax error. */
- return;
- s++;
- break;
+ if (s[pos] == '\'')
+ {
+ pos++;
+ if (s[pos] != '\'')
+ break;
+ pos++; /* A double quote */
+ }
+ else if (s[pos] == '\0')
+ /* Multiline quoted atoms are ignored. */
+ return -1;
+ else if (s[pos] == '\\')
+ {
+ if (s[pos+1] == '\0')
+ return -1;
+ pos += 2;
+ }
+ else
+ pos++;
}
- else
- s++;
+ return pos - origpos;
}
- pfnote (NULL, TRUE, save_s, s-save_s, lineno, linecharno);
+ else
+ return -1;
}
-/* It is assumed that prolog predicate starts from column 0. */
+/* Consume whitespace. Return the number of bytes eaten. */
+int
+prolog_white (s, pos)
+ char *s;
+ int pos;
+{
+ int origpos;
+
+ origpos = pos;
+
+ while (isspace(s[pos]))
+ pos++;
+
+ return pos - origpos;
+}
+\f
+/*
+ * Support for Erlang -- Anders Lindgren, Feb 1996.
+ *
+ * Generates tags for functions, defines, and records.
+ *
+ * Assumes that Erlang functions start at column 0.
+ */
void
-Prolog_functions (inf)
+Erlang_functions (inf)
FILE *inf;
{
- void skip_comment (), prolog_getit ();
+ int erlang_func ();
+ void erlang_attribute ();
+
+ char * last;
+ int len;
+ int allocated;
+
+ allocated = 0;
+ len = 0;
+ last = NULL;
+
+ lineno = 0;
+ linecharno = 0;
+ charno = 0;
- lineno = linecharno = charno = 0;
while (!feof (inf))
{
lineno++;
linecharno += charno;
- charno = readline (&lb, inf) + 1; /* 1 for newline. */
+ charno = readline (&lb, inf);
dbp = lb.buffer;
- if (isspace (dbp[0])) /* not predicate header. */
+ if (dbp[0] == '\0') /* Empty line */
continue;
- else if (dbp[0] == '%') /* comment. */
+ else if (isspace (dbp[0])) /* Not function nor attribute */
continue;
- else if (dbp[0] == '/' && dbp[1] == '*') /* comment. */
- skip_comment (&lb, inf, &lineno, &linecharno);
- else /* found. */
- prolog_getit (dbp);
+ else if (dbp[0] == '%') /* comment */
+ continue;
+ else if (dbp[0] == '"') /* Sometimes, strings start in column one */
+ continue;
+ else if (dbp[0] == '-') /* attribute, e.g. "-define" */
+ {
+ erlang_attribute(dbp);
+ last = NULL;
+ }
+ else if (len = erlang_func (dbp, last))
+ {
+ /*
+ * Function. Store the function name so that we only
+ * generates a tag for the first clause.
+ */
+ if (last == NULL)
+ last = xnew(len + 1, char);
+ else if (len + 1 > allocated)
+ last = (char *) xrealloc(last, len + 1);
+ allocated = len + 1;
+ strncpy (last, dbp, len);
+ last[len] = '\0';
+ }
+ }
+}
+
+
+/*
+ * A function definition is added if it matches:
+ * <beginning of line><Erlang Atom><whitespace>(
+ *
+ * It is added to the tags database if it doesn't match the
+ * name of the previous clause header.
+ *
+ * Return the size of the name of the function, or 0 if no function
+ * was found.
+ */
+int
+erlang_func (s, last)
+ char *s;
+ char *last; /* Name of last clause. */
+{
+ int erlang_atom ();
+ int erlang_white ();
+
+ int pos;
+ int len;
+
+ pos = erlang_atom(s, 0);
+ if (pos < 1)
+ return 0;
+
+ len = pos;
+ pos += erlang_white(s, pos);
+
+ if (s[pos++] == '(')
+ {
+ /* Save only the first clause. */
+ if ((last == NULL) ||
+ (len != strlen(last)) ||
+ (strncmp(s, last, len) != 0))
+ {
+ pfnote ((CTAGS) ? savenstr (s, len) : NULL, TRUE,
+ s, pos, lineno, linecharno);
+ return len;
+ }
}
+ return 0;
}
+
+/*
+ * Handle attributes. Currently, tags are generated for defines
+ * and records.
+ *
+ * They are on the form:
+ * -define(foo, bar).
+ * -define(Foo(M, N), M+N).
+ * -record(graph, {vtab = notable, cyclic = true}).
+ */
void
-skip_comment (plb, inf, plineno, plinecharno)
- struct linebuffer *plb;
- FILE *inf;
- int *plineno; /* result */
- long *plinecharno; /* result */
+erlang_attribute (s)
+ char *s;
{
- char *cp;
+ int erlang_atom ();
+ int erlang_white ();
- do
+ int pos;
+ int len;
+
+ if ((strncmp(s, "-define", 7) == 0) ||
+ (strncmp(s, "-record", 7) == 0))
{
- for (cp = plb->buffer; *cp != '\0'; cp++)
- if (cp[0] == '*' && cp[1] == '/')
- return;
- (*plineno)++;
- *plinecharno += readline (plb, inf) + 1; /* 1 for newline. */
+ pos = 7;
+ pos += erlang_white(s, pos);
+
+ if (s[pos++] == '(')
+ {
+ pos += erlang_white(s, pos);
+
+ if (len = erlang_atom(s, pos))
+ {
+ pfnote ((CTAGS) ? savenstr (& s[pos], len) : NULL, TRUE,
+ s, pos + len, lineno, linecharno);
+ }
+ }
}
- while (!feof(inf));
+ return;
+}
+
+
+/*
+ * Consume an Erlang atom (or variable).
+ * Return the number of bytes consumed, or -1 if there was an error.
+ */
+int
+erlang_atom (s, pos)
+ char *s;
+ int pos;
+{
+ int origpos;
+
+ origpos = pos;
+
+ if (isalpha (s[pos]) || s[pos] == '_')
+ {
+ /* The atom is unquoted. */
+ pos++;
+ while (isalnum (s[pos]) || s[pos] == '_')
+ pos++;
+ return pos - origpos;
+ }
+ else if (s[pos] == '\'')
+ {
+ pos++;
+
+ while (1)
+ {
+ if (s[pos] == '\'')
+ {
+ pos++;
+ break;
+ }
+ else if (s[pos] == '\0')
+ /* Multiline quoted atoms are ignored. */
+ return -1;
+ else if (s[pos] == '\\')
+ {
+ if (s[pos+1] == '\0')
+ return -1;
+ pos += 2;
+ }
+ else
+ pos++;
+ }
+ return pos - origpos;
+ }
+ else
+ return -1;
+}
+
+/* Consume whitespace. Return the number of bytes eaten */
+int
+erlang_white (s, pos)
+ char *s;
+ int pos;
+{
+ int origpos;
+
+ origpos = pos;
+
+ while (isspace (s[pos]))
+ pos++;
+
+ return pos - origpos;
}
\f
#ifdef ETAGS_REGEXPS
/* Take a string like "/blah/" and turn it into "blah", making sure
that the first and last characters are the same, and handling
- quoted separator characters. Actually, stops on the occurence of
+ quoted separator characters. Actually, stops on the occurrence of
an unquoted separator. Also turns "\t" into a Tab character.
Returns pointer to terminating separator. Works in place. Null
terminates name string. */
++t;
if (!*t)
{
- fprintf (stderr, "%s: pattern subtitution ends prematurely\n",
+ fprintf (stderr, "%s: pattern substitution ends prematurely\n",
progname);
return NULL;
}
}
if (c == EOF)
{
+ *p = '\0';
chars_deleted = 0;
break;
}
if (p > buffer && p[-1] == '\r')
{
*--p = '\0';
+#ifdef DOS_NT
+ /* Assume CRLF->LF translation will be performed by Emacs
+ when loading this file, so CRs won't appear in the buffer.
+ It would be cleaner to compensate within Emacs;
+ however, Emacs does not know how many CRs were deleted
+ before any given point in the file. */
+ chars_deleted = 1;
+#else
chars_deleted = 2;
+#endif
}
else
{
FILE *stream;
{
/* Read new line. */
- int i;
long result = readline_internal (linebuffer, stream);
-
#ifdef ETAGS_REGEXPS
+ int i;
+
/* Match against all listed patterns. */
for (i = 0; i < num_patterns; ++i)
{
just_read_file (inf)
FILE *inf;
{
+ lineno = 0;
+ charno = 0;
+
while (!feof (inf))
{
++lineno;
exit (BAD);
}
+void
+suggest_asking_for_help ()
+{
+ fprintf (stderr, "\tTry `%s --help' for a complete list of options.\n",
+ progname);
+ exit (BAD);
+}
+
/* Print error message. `s1' is printf control string, `s2' is arg for it. */
void
error (s1, s2)
char *
etags_getcwd ()
{
-#ifdef DOS_NT
- char *p, path[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */
-
- getwd (path);
- p = path;
- while (*p)
- if (*p == '\\')
- *p++ = '/';
- else
- *p++ = lowcase (*p);
-
- return strdup (path);
-#else /* not DOS_NT */
-#if HAVE_GETCWD
+#ifdef HAVE_GETCWD
int bufsize = 200;
char *path = xnew (bufsize, char);
}
return path;
-#else /* not DOS_NT and not HAVE_GETCWD */
+#else /* not HAVE_GETCWD */
+#ifdef MSDOS
+ char *p, path[MAXPATHLEN + 1]; /* Fixed size is safe on MSDOS. */
+
+ getwd (path);
+
+ for (p = path; *p != '\0'; p++)
+ if (*p == '\\')
+ *p = '/';
+ else
+ *p = lowcase (*p);
+
+ return strdup (path);
+#else /* not MSDOS */
struct linebuffer path;
FILE *pipe;
pclose (pipe);
return path.buffer;
+#endif /* not MSDOS */
#endif /* not HAVE_GETCWD */
-#endif /* not DOS_NT */
}
/* Return a newly allocated string containing the filename
if (absolutefn (file))
res = concat (file, "", "");
+#ifdef DOS_NT
+ /* We don't support non-absolute filenames with a drive
+ letter, like `d:NAME' (it's too much hassle). */
+ else if (file[1] == ':')
+ fatal ("%s: relative filenames with drive letters not supported", file);
+#endif
else
res = concat (cwd, file, "");
cp = slashp;
do
cp--;
- while (cp >= res && *cp != '/');
+ while (cp >= res && !absolutefn (cp));
if (*cp == '/')
{
strcpy (cp, slashp + 3);
}
+#ifdef DOS_NT
+ /* Under MSDOS and NT we get `d:/NAME' as absolute
+ filename, so the luser could say `d:/../NAME'.
+ We silently treat this as `d:/NAME'. */
+ else if (cp[1] == ':')
+ strcpy (cp + 3, slashp + 4);
+#endif
else /* else (cp == res) */
{
if (slashp[3] != '\0')
{
char *slashp, *res;
char save;
+#ifdef DOS_NT
+ char *p;
+
+ for (p = file; *p != '\0'; p++)
+ if (*p == '\\')
+ *p = '/';
+#endif
slashp = etags_strrchr (file, '/');
if (slashp == NULL)