Assume freestanding C89 headers, string.h, stdlib.h.
[bpt/emacs.git] / lib-src / etags.c
index 42e4017..522c54e 100644 (file)
@@ -28,8 +28,7 @@ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
-Copyright (C) 1984, 1987, 1988, 1989, 1993, 1994, 1995, 1998, 1999,
-  2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+Copyright (C) 1984, 1987-1989, 1993-1995, 1998-2011
   Free Software Foundation, Inc.
 
 This file is not considered part of GNU Emacs.
@@ -94,8 +93,11 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
 
 #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. */
+  /* This is probably not necessary any more.  On some systems, config.h
+     used to define static as nothing for the sake of unexec.  We don't
+     want that here since we don't use unexec.  None of these systems
+     are supported any more, but the idea is still mentioned in
+     etc/PROBLEMS.  */
 # undef static
 # ifndef PTR                   /* for XEmacs */
 #   define PTR void *
@@ -136,9 +138,7 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
 #endif /* MSDOS */
 
 #ifdef WINDOWSNT
-# include <stdlib.h>
 # include <fcntl.h>
-# include <string.h>
 # include <direct.h>
 # include <io.h>
 # define MAXPATHLEN _MAX_PATH
@@ -149,37 +149,17 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
 #   define HAVE_GETCWD
 # endif /* undef HAVE_GETCWD */
 #else /* not WINDOWSNT */
-# ifdef STDC_HEADERS
-#  include <stdlib.h>
-#  include <string.h>
-# else /* no standard C headers */
-   extern char *getenv (const char *);
-   extern char *strcpy (char *, const char *);
-   extern char *strncpy (char *, const char *, unsigned long);
-   extern char *strcat (char *, const char *);
-   extern char *strncat (char *, const char *, unsigned long);
-   extern int strcmp (const char *, const char *);
-   extern int strncmp (const char *, const char *, unsigned long);
-   extern int system (const char *);
-   extern unsigned long strlen (const char *);
-   extern void *malloc (unsigned long);
-   extern void *realloc (void *, unsigned long);
-   extern void exit (int);
-   extern void free (void *);
-   extern void *memmove (void *, const void *, unsigned long);
-#  define EXIT_SUCCESS 0
-#  define EXIT_FAILURE 1
-# endif
 #endif /* !WINDOWSNT */
 
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#else
+#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 <stdlib.h>
+#include <string.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <errno.h>
@@ -192,10 +172,6 @@ char pot_etags_version[] = "@(#) pot revision number is 17.38.1.4";
 # define assert(x) ((void) 0)
 #endif
 
-#if !defined (S_ISREG) && defined (S_IFREG)
-# define S_ISREG(m)    (((m) & S_IFMT) == S_IFREG)
-#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)
@@ -245,7 +221,6 @@ If you want regular expression support, you should delete this notice and
 #define ISLOWER(c)     islower (CHAR(c))
 
 #define lowcase(c)     tolower (CHAR(c))
-#define upcase(c)      toupper (CHAR(c))
 
 
 /*
@@ -561,6 +536,7 @@ static compressor compressors[] =
   { "gz", "gzip -d -c"},
   { "GZ", "gzip -d -c"},
   { "bz2", "bzip2 -d -c" },
+  { "xz", "xz -d -c" },
   { NULL }
 };
 
@@ -874,7 +850,7 @@ 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.\n\
 When parsing any C file, a \"class\" or \"template\" keyword\n\
 switches to C++.");
-  puts ("Compressed files are supported using gzip and bzip2.\n\
+  puts ("Compressed files are supported using gzip, bzip2, and xz.\n\
 \n\
 For detailed help on a given language use, for example,\n\
 etags --help --lang=ada.");
@@ -890,7 +866,7 @@ static void
 print_version (void)
 {
   /* Makes it easier to update automatically. */
-  char emacs_copyright[] = "Copyright (C) 2010 Free Software Foundation, Inc.";
+  char emacs_copyright[] = "Copyright (C) 2011 Free Software Foundation, Inc.";
 
   printf ("%s (%s %s)\n", (CTAGS) ? "ctags" : "etags", EMACS_NAME, VERSION);
   puts (emacs_copyright);
@@ -2363,14 +2339,7 @@ and replace lines between %< and %> with its output, then:
 struct C_stab_entry { const char *name; int c_ext; enum sym_type type; };
 /* maximum key range = 33, duplicates = 0 */
 
-#ifdef __GNUC__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static unsigned int
+static inline unsigned int
 hash (register const char *str, register unsigned int len)
 {
   static unsigned char asso_values[] =
@@ -3984,10 +3953,8 @@ Yacc_entries (FILE *inf)
 static void
 just_read_file (FILE *inf)
 {
-  register char *dummy;
-
-  LOOP_ON_INPUT_LINES (inf, lb, dummy)
-    continue;
+  while (!feof (inf))
+    readline (&lb, inf);
 }
 
 \f
@@ -4204,7 +4171,7 @@ Ada_funcs (FILE *inf)
          /* Skip a string i.e. "abcd". */
          if (inquote || (*dbp == '"'))
            {
-             dbp = etags_strchr ((inquote) ? dbp : dbp+1, '"');
+             dbp = etags_strchr (dbp + !inquote, '"');
              if (dbp != NULL)
                {
                  inquote = FALSE;
@@ -5260,16 +5227,16 @@ HTML_labels (FILE *inf)
  * Original code by Sunichirou Sugou (1989)
  * Rewritten by Anders Lindgren (1996)
  */
-static int prolog_pr (char *, char *);
+static size_t prolog_pr (char *, char *);
 static void prolog_skip_comment (linebuffer *, FILE *);
-static int prolog_atom (char *, int);
+static size_t prolog_atom (char *, size_t);
 
 static void
 Prolog_functions (FILE *inf)
 {
   char *cp, *last;
-  int len;
-  int allocated;
+  size_t len;
+  size_t allocated;
 
   allocated = 0;
   len = 0;
@@ -5326,16 +5293,16 @@ prolog_skip_comment (linebuffer *plb, FILE *inf)
  * Return the size of the name of the predicate or rule, or 0 if no
  * header was found.
  */
-static int
+static size_t
 prolog_pr (char *s, char *last)
-             
+
                                /* Name of last clause. */
 {
-  int pos;
-  int len;
+  size_t pos;
+  size_t len;
 
   pos = prolog_atom (s, 0);
-  if (pos < 1)
+  if (! pos)
     return 0;
 
   len = pos;
@@ -5345,7 +5312,7 @@ prolog_pr (char *s, char *last)
        || (s[pos] == '(' && (pos += 1))
        || (s[pos] == ':' && s[pos + 1] == '-' && (pos += 2)))
       && (last == NULL         /* save only the first clause */
-         || len != (int)strlen (last)
+         || len != strlen (last)
          || !strneq (s, last, len)))
        {
          make_tag (s, len, TRUE, s, pos, lineno, linecharno);
@@ -5357,17 +5324,17 @@ prolog_pr (char *s, char *last)
 
 /*
  * Consume a Prolog atom.
- * Return the number of bytes consumed, or -1 if there was an error.
+ * Return the number of bytes consumed, or 0 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.
  */
-static int
-prolog_atom (char *s, int pos)
+static size_t
+prolog_atom (char *s, size_t pos)
 {
-  int origpos;
+  size_t origpos;
 
   origpos = pos;
 
@@ -5396,11 +5363,11 @@ prolog_atom (char *s, int pos)
            }
          else if (s[pos] == '\0')
            /* Multiline quoted atoms are ignored. */
-           return -1;
+           return 0;
          else if (s[pos] == '\\')
            {
              if (s[pos+1] == '\0')
-               return -1;
+               return 0;
              pos += 2;
            }
          else
@@ -5409,7 +5376,7 @@ prolog_atom (char *s, int pos)
       return pos - origpos;
     }
   else
-    return -1;
+    return 0;
 }
 
 \f
@@ -5485,7 +5452,7 @@ Erlang_functions (FILE *inf)
  */
 static int
 erlang_func (char *s, char *last)
-             
+
                                /* Name of last clause. */
 {
   int pos;
@@ -6579,22 +6546,13 @@ absolute_filename (char *file, char *dir)
              else if (cp[0] != '/')
                cp = slashp;
 #endif
-#ifdef HAVE_MEMMOVE
               memmove (cp, slashp + 3, strlen (slashp + 2));
-#else
-              /* Overlapping copy isn't really okay */
-             strcpy (cp, slashp + 3);
-#endif
              slashp = cp;
              continue;
            }
          else if (slashp[2] == '/' || slashp[2] == '\0')
            {
-#ifdef HAVE_MEMMOVE
              memmove (slashp, slashp + 2, strlen (slashp + 1));
-#else
-              strcpy (slashp, slashp + 2);
-#endif
              continue;
            }
        }
@@ -6643,7 +6601,7 @@ filename_is_absolute (char *fn)
          );
 }
 
-/* Upcase DOS drive letter and collapse separators into single slashes.
+/* Downcase DOS drive letter and collapse separators into single slashes.
    Works in place. */
 static void
 canonicalize_filename (register char *fn)
@@ -6653,8 +6611,9 @@ canonicalize_filename (register char *fn)
 
 #ifdef DOS_NT
   /* Canonicalize drive letter case.  */
-  if (fn[0] != '\0' && fn[1] == ':' && ISLOWER (fn[0]))
-    fn[0] = upcase (fn[0]);
+# define ISUPPER(c)    isupper (CHAR(c))
+  if (fn[0] != '\0' && fn[1] == ':' && ISUPPER (fn[0]))
+    fn[0] = lowcase (fn[0]);
 
   sep = '\\';
 #endif
@@ -6724,7 +6683,4 @@ xrealloc (char *ptr, unsigned int size)
  * End:
  */
 
-/* arch-tag: 8a9b748d-390c-4922-99db-2eeefa921051
-   (do not change this comment) */
-
 /* etags.c ends here */