]> code.delx.au - gnu-emacs/blobdiff - lib-src/etags.c
Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[gnu-emacs] / lib-src / etags.c
index 73462c83ad7839b0004b3a3302cc06a928df507d..ec96f45fc949e885bd339a77750911a624983853 100644 (file)
@@ -123,19 +123,9 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
 # undef HAVE_NTGUI
 # undef  DOS_NT
 # define DOS_NT
-# ifndef HAVE_GETCWD
-#   define HAVE_GETCWD
-# endif /* undef HAVE_GETCWD */
-#else /* not WINDOWSNT */
-#endif /* !WINDOWSNT */
+#endif /* WINDOWSNT */
 
 #include <unistd.h>
-#ifndef HAVE_UNISTD_H
-# if defined (HAVE_GETCWD) && !defined (WINDOWSNT)
-    extern char *getcwd (char *buf, size_t size);
-# endif
-#endif /* HAVE_UNISTD_H */
-
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
@@ -152,16 +142,7 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
 # define assert(x) ((void) 0)
 #endif
 
-#ifdef NO_LONG_OPTIONS         /* define this if you don't have GNU getopt */
-# define NO_LONG_OPTIONS TRUE
-# define getopt_long(argc,argv,optstr,lopts,lind) getopt (argc, argv, optstr)
-  extern char *optarg;
-  extern int optind, opterr;
-#else
-# define NO_LONG_OPTIONS FALSE
-# include <getopt.h>
-#endif /* NO_LONG_OPTIONS */
-
+#include <getopt.h>
 #include <regex.h>
 
 /* Define CTAGS to make the program "ctags" compatible with the usual one.
@@ -372,6 +353,7 @@ static void put_entries (node *);
 static char *concat (const char *, const char *, const char *);
 static char *skip_spaces (char *);
 static char *skip_non_spaces (char *);
+static char *skip_name (char *);
 static char *savenstr (const char *, int);
 static char *savestr (const char *);
 static char *etags_strchr (const char *, int);
@@ -638,7 +620,8 @@ static const char Lisp_help [] =
 "In Lisp code, any function defined with `defun', any variable\n\
 defined with `defvar' or `defconst', and in general the first\n\
 argument of any expression that starts with `(def' in column zero\n\
-is a tag.";
+is a tag.\n\
+The `--declarations' option tags \"(defvar foo)\" constructs too.";
 
 static const char *Lua_suffixes [] =
   { "lua", "LUA", NULL };
@@ -869,11 +852,7 @@ print_help (argument *argbuffer)
   printf ("Usage: %s [options] [[regex-option ...] file-name] ...\n\
 \n\
 These are the options accepted by %s.\n", progname, progname);
-  if (NO_LONG_OPTIONS)
-    puts ("WARNING: long option names do not work with this executable,\n\
-as it is not linked with GNU getopt.");
-  else
-    puts ("You may use unambiguous abbreviations for the long option names.");
+  puts ("You may use unambiguous abbreviations for the long option names.");
   puts ("  A - as file name means read names from stdin (one per line).\n\
 Absolute names are stored in the output file as they are.\n\
 Relative ones are stored relative to the output file's directory.\n");
@@ -1065,9 +1044,9 @@ main (int argc, char **argv)
 
   /* When the optstring begins with a '-' getopt_long does not rearrange the
      non-options arguments to be at the end, but leaves them alone. */
-  optstring = concat (NO_LONG_OPTIONS ? "" : "-",
-                     "ac:Cf:Il:o:r:RSVhH",
-                     (CTAGS) ? "BxdtTuvw" : "Di:");
+  optstring = concat ("-ac:Cf:Il:o:r:RSVhH",
+                     (CTAGS) ? "BxdtTuvw" : "Di:",
+                     "");
 
   while ((opt = getopt_long (argc, argv, optstring, longopts, NULL)) != EOF)
     switch (opt)
@@ -4292,6 +4271,7 @@ Asm_labels (FILE *inf)
 /*
  * Perl support
  * Perl sub names: /^sub[ \t\n]+[^ \t\n{]+/
+ *                 /^use constant[ \t\n]+[^ \t\n{=,;]+/
  * Perl variable names: /^(my|local).../
  * Original code by Bart Robinson <lomew@cs.utah.edu> (1995)
  * Additions by Michael Ernst <mernst@alum.mit.edu> (1997)
@@ -4314,9 +4294,10 @@ Perl_functions (FILE *inf)
        }
       else if (LOOKING_AT (cp, "sub"))
        {
-         char *pos;
-         char *sp = cp;
+         char *pos, *sp;
 
+       subr:
+         sp = cp;
          while (!notinname (*cp))
            cp++;
          if (cp == sp)
@@ -4339,8 +4320,21 @@ Perl_functions (FILE *inf)
                        lb.buffer, cp - lb.buffer + 1, lineno, linecharno);
              free (name);
            }
+       }
+      else if (LOOKING_AT (cp, "use constant")
+              || LOOKING_AT (cp, "use constant::defer"))
+       {
+         /* For hash style multi-constant like
+               use constant { FOO => 123,
+                              BAR => 456 };
+            only the first FOO is picked up.  Parsing across the value
+            expressions would be difficult in general, due to possible nested
+            hashes, here-documents, etc.  */
+         if (*cp == '{')
+           cp = skip_spaces (cp+1);
+         goto subr;
        }
-       else if (globals)       /* only if we are tagging global vars */
+      else if (globals)        /* only if we are tagging global vars */
        {
          /* Skip a qualifier, if any. */
          bool qual = LOOKING_AT (cp, "my") || LOOKING_AT (cp, "local");
@@ -4755,6 +4749,19 @@ Lisp_functions (FILE *inf)
       if (dbp[0] != '(')
        continue;
 
+      /* "(defvar foo)" is a declaration rather than a definition.  */
+      if (! declarations)
+       {
+         char *p = dbp + 1;
+         if (LOOKING_AT (p, "defvar"))
+           {
+             p = skip_name (p); /* past var name */
+             p = skip_spaces (p);
+             if (*p == ')')
+               continue;
+           }
+       }
+
       if (strneq (dbp+1, "def", 3) || strneq (dbp+1, "DEF", 3))
        {
          dbp = skip_non_spaces (dbp);
@@ -6315,6 +6322,16 @@ skip_non_spaces (char *cp)
   return cp;
 }
 
+/* Skip any chars in the "name" class.*/
+static char *
+skip_name (char *cp)
+{
+  /* '\0' is a notinname() so loop stops there too */
+  while (! notinname (*cp))
+    cp++;
+  return cp;
+}
+
 /* Print error message and exit.  */
 void
 fatal (const char *s1, const char *s2)
@@ -6333,8 +6350,8 @@ pfatal (const char *s1)
 static void
 suggest_asking_for_help (void)
 {
-  fprintf (stderr, "\tTry `%s %s' for a complete list of options.\n",
-          progname, NO_LONG_OPTIONS ? "-h" : "--help");
+  fprintf (stderr, "\tTry `%s --help' for a complete list of options.\n",
+          progname);
   exit (EXIT_FAILURE);
 }
 
@@ -6372,7 +6389,6 @@ concat (const char *s1, const char *s2, const char *s3)
 static char *
 etags_getcwd (void)
 {
-#ifdef HAVE_GETCWD
   int bufsize = 200;
   char *path = xnew (bufsize, char);
 
@@ -6387,34 +6403,6 @@ etags_getcwd (void)
 
   canonicalize_filename (path);
   return path;
-
-#else /* not HAVE_GETCWD */
-#if 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 */
-  linebuffer path;
-  FILE *pipe;
-
-  linebuffer_init (&path);
-  pipe = (FILE *) popen ("pwd 2>/dev/null", "r");
-  if (pipe == NULL || readline_internal (&path, pipe) == 0)
-    pfatal ("pwd");
-  pclose (pipe);
-
-  return path.buffer;
-#endif /* not MSDOS */
-#endif /* not HAVE_GETCWD */
 }
 
 /* Return a newly allocated string containing the file name of FILE