* Francesco Potorti` reorganised C and C++ based on work by Joe Wells.
* Regexp tags by Tom Tromey.
*
- * 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.53";
+char pot_etags_version[] = "@(#) pot revision number is 11.66";
#define TRUE 1
#define FALSE 0
#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 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
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;
void plain_C_entries ();
void Cplusplus_entries ();
void Cstar_entries ();
+void Erlang_functions ();
void Fortran_functions ();
void Yacc_entries ();
void Lisp_functions ();
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 */
char *Cstar_suffixes [] =
{ "cs", "hs", NULL };
+char *Erlang_suffixes [] =
+ { "erl", "hrl", NULL };
+
char *Fortran_suffixes [] =
{ "F", "f", "f90", "for", 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 },
{
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.");
#endif /* VMS */
\f
-void
+int
main (argc, argv)
int argc;
char *argv[];
}
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)
{
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))
{
enum sym_type
{
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,
+ 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; }
%%
@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
%]
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 15
-#define MIN_HASH_VALUE 7
-#define MAX_HASH_VALUE 63
+#define MIN_HASH_VALUE 34
+#define MAX_HASH_VALUE 121
/*
- 29 keywords
- 57 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[] =
{
- 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 17, 63, 63, 63, 4, 14,
- 4, 63, 63, 63, 63, 63, 63, 63, 63, 63,
- 8, 63, 63, 0, 23, 63, 63, 63, 63, 63,
- 63, 63, 63, 63, 63, 63, 63, 28, 63, 28,
- 10, 31, 27, 18, 63, 6, 63, 63, 26, 1,
- 11, 2, 29, 63, 29, 16, 26, 13, 15, 63,
- 63, 63, 63, 63, 63, 63, 63, 63,
+ 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},
- {"",}, {"",}, {"",}, {"",}, {"",},
- {"DEFUN", 0, st_C_gnumacro},
- {"",}, {"",}, {"",},
- {"domain", C_STAR, st_C_struct},
- {"",}, {"",}, {"",}, {"",}, {"",},
- {"short", 0, st_C_typespec},
- {"union", 0, st_C_struct},
+ {"",}, {"",}, {"",},
+ {"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},
- {"",}, {"",},
- {"PSEUDO", 0, st_C_gnumacro},
- {"double", 0, st_C_typespec},
- {"",}, {"",},
- {"@end", 0, st_C_objend},
- {"@implementation", 0, st_C_objimpl},
+ {"",},
+ {"char", 0, st_C_typespec},
+ {"class", C_PLPL, st_C_struct},
+ {"",}, {"",}, {"",},
{"float", 0, st_C_typespec},
- {"int", 0, st_C_typespec},
- {"",},
- {"unsigned", 0, st_C_typespec},
+ {"",},
+ {"@implementation", 0, st_C_objimpl},
+ {"auto", 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},
+ {"",},
+ {"DEFUN", 0, st_C_gnumacro},
+ {"extern", 0, st_C_typespec},
{"@interface", 0, st_C_objprot},
- {"",},
+ {"",}, {"",}, {"",},
+ {"int", 0, st_C_typespec},
+ {"",}, {"",}, {"",}, {"",},
{"signed", 0, st_C_typespec},
- {"long", 0, st_C_typespec},
- {"ENTRY", 0, st_C_gnumacro},
+ {"short", 0, st_C_typespec},
+ {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
{"define", 0, st_C_define},
- {"const", 0, st_C_typespec},
- {"",}, {"",}, {"",},
+ {"@protocol", 0, st_C_objprot},
{"enum", 0, st_C_enum},
- {"volatile", 0, st_C_typespec},
{"static", 0, st_C_typespec},
+ {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
+ {"union", 0, st_C_struct},
{"struct", 0, st_C_struct},
- {"",}, {"",}, {"",},
- {"@protocol", 0, st_C_objprot},
- {"",}, {"",},
- {"auto", 0, st_C_typespec},
- {"",},
- {"char", 0, st_C_typespec},
- {"class", C_PLPL, st_C_struct},
- {"typedef", 0, st_C_typedef},
- {"extern", 0, st_C_typespec},
+ {"",}, {"",}, {"",}, {"",},
+ {"double", 0, st_C_typespec},
+ {"unsigned", 0, st_C_typespec},
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
omethodtag, /* after method name */
omethodcolon, /* after method colon */
omethodparm, /* after method parameter */
- oignore, /* wait for @end */
+ oignore /* wait for @end */
} objdef;
/*
do { \
curlinepos = charno; \
lineno++; \
+ linecharno = charno; \
charno += readline (&curlb, inf); \
lp = curlb.buffer; \
quotednl = FALSE; \
/* Added by Mosur Mohan, 4/22/88 */
/* Pascal parsing */
-#define GET_NEW_LINE \
-{ \
- linecharno = charno; lineno++; \
- charno += 1 + readline (&lb, inf); \
- dbp = lb.buffer; \
-}
-
/*
* Locates tags for procedures & functions. Doesn't do any type- or
* var-definitions. It does look for the keyword "extern" or
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) ||
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 ((CTAGS) ? savenstr (save_s, s-save_s) : 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
}
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
{
just_read_file (inf)
FILE *inf;
{
+ lineno = 0;
+ charno = 0;
+
while (!feof (inf))
{
++lineno;
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)