(describe-current-display-table):
[bpt/emacs.git] / lib-src / etags.c
index bca7a1e..3057800 100644 (file)
@@ -25,11 +25,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  *     Gnu Emacs TAGS format and modifications by RMS?
  *     Sam Kendall added C++.
  *
- *     Francesco Potorti` is the current maintainer.   7.5
+ *     Francesco Potorti` (pot@cnuce.cnr.it) is the current maintainer. 9.7
  */
 
 #ifdef HAVE_CONFIG_H
-#include "../src/config.h"
+#include <../src/config.h>
 #endif
 
 #include <stdio.h>
@@ -37,6 +37,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#if !defined (S_ISREG) && defined (S_IFREG)
+# define S_ISREG(m)    (((m) & S_IFMT) == S_IFREG)
+#endif
+
 #include "getopt.h"
 
 extern char *malloc (), *realloc ();
@@ -138,7 +142,7 @@ struct nd_st
   char *name;                  /* function or type name        */
   char *file;                  /* file name                    */
   logical is_func;             /* use pattern or line no       */
-  logical rewritten;           /* list name separately         */
+  logical named;               /* list name separately         */
   logical been_warned;         /* set if noticed dup           */
   int lno;                     /* line number tag is on        */
   long cno;                    /* character number line starts on */
@@ -326,7 +330,7 @@ typedef struct
   char *p;
   int len;
   LINENO lineno;
-  logical rewritten;
+  logical named;
 } TOKEN;
 
 /* C extensions.
@@ -432,7 +436,7 @@ print_version ()
 #ifdef ETAGS
   printf ("ETAGS ");
 #endif
-  printf ("for Emacs version 19.0.\n");
+  printf ("for Emacs version 19.\n");
 
   exit (0);
 }
@@ -784,12 +788,7 @@ process_file (file)
 {
   struct stat stat_buf;
 
-  stat (file, &stat_buf);
-  if (!(stat_buf.st_mode & S_IFREG)
-#ifdef S_IFLNK
-      || !(stat_buf.st_mode & S_IFLNK)
-#endif
-      )
+  if (stat (file, &stat_buf) || !S_ISREG (stat_buf.st_mode))
     {
       fprintf (stderr, "Skipping %s: it is not a regular file.\n", file);
       return;
@@ -800,19 +799,10 @@ process_file (file)
       fprintf (stderr, "Skipping inclusion of %s in self.\n", file);
       return;
     }
-  if (emacs_tags_format)
-    {
-      char *cp = etags_rindex (file, '/');
-      if (cp)
-       ++cp;
-      else
-       cp = file;
-    }
   find_entries (file);
   if (emacs_tags_format)
     {
-      fprintf (outf, "\f\n%s,%d\n",
-              file, total_size_of_entries (head));
+      fprintf (outf, "\f\n%s,%d\n", file, total_size_of_entries (head));
       put_entries (head);
       free_tree (head);
       head = NULL;
@@ -993,10 +983,10 @@ string_numeric_p (str)
 /* Record a tag. */
 /* Should take a TOKEN* instead!! */
 void
-pfnote (name, is_func, rewritten, linestart, linelen, lno, cno)
+pfnote (name, is_func, named, linestart, linelen, lno, cno)
      char *name;               /* tag name */
      logical is_func;          /* function or type name? */
-     logical rewritten;                /* tag different from text of definition? */
+     logical named;            /* tag different from text of definition? */
      char *linestart;
      int linelen;
      int lno;
@@ -1031,12 +1021,12 @@ pfnote (name, is_func, rewritten, linestart, linelen, lno, cno)
       fp = etags_rindex (name, '.');
       if (fp && fp[1] != '\0' && fp[2] == '\0')
        *fp = 0;
-      rewritten = TRUE;
+      named = TRUE;
     }
   np->name = savestr (name);
   np->file = curfile;
   np->is_func = is_func;
-  np->rewritten = rewritten;
+  np->named = named;
   np->lno = lno;
   /* UNCOMMENT THE +1 HERE: */
   np->cno = cno /* + 1 */ ;    /* our char numbers are 0-base; emacs's are 1-base */
@@ -1174,7 +1164,7 @@ put_entries (node)
 
   if (emacs_tags_format)
     {
-      if (node->rewritten)
+      if (node->named)
        {
          fprintf (outf, "%s\177%s\001%d,%d\n",
                   node->pat, node->name,
@@ -1259,7 +1249,7 @@ total_size_of_entries (node)
       /* Count this entry */
       total += strlen (node->pat) + 1;
       total += number_len ((long) node->lno) + 1 + number_len (node->cno) + 1;
-      if (node->rewritten)
+      if (node->named)
        total += 1 + strlen (node->name);       /* \001name */
     }
 
@@ -1436,9 +1426,9 @@ do {                                                                      \
   definedef = dnone;                                                   \
 } while (FALSE)
 
-#define MAKE_TAG_FROM_NEW_LB(isfun)  pfnote (tokb, isfun, tok.rewritten, \
+#define MAKE_TAG_FROM_NEW_LB(isfun)  pfnote (nameb, isfun, tok.named,  \
   newlb.buffer, tokoff + toklen + 1, tok.lineno, GET_CHARNO (newlinepos))
-#define MAKE_TAG_FROM_OTH_LB(isfun)  pfnote (tokb, isfun, tok.rewritten, \
+#define MAKE_TAG_FROM_OTH_LB(isfun)  pfnote (nameb, isfun, tok.named,  \
   othlb.buffer, tokoff + toklen + 1, tok.lineno, GET_CHARNO (othlinepos))
 
 void
@@ -1449,7 +1439,7 @@ C_entries (c_ext)
   register char *lp;           /* pointer one beyond the character `c' */
   int curndx, newndx;          /* indices for current and new lb */
   TOKEN tok;                   /* latest token read for funcdef & structdef */
-  char tokb[BUFSIZ];           /* latest token name for funcdef & structdef */
+  char nameb[BUFSIZ];          /* latest token name for funcdef & structdef */
   register int tokoff;         /* offset in line of start of latest token */
   register int toklen;         /* length of latest token */
   int cblev;                   /* current curly brace level */
@@ -1590,30 +1580,36 @@ C_entries (c_ext)
                    }
                  else
                    {
-                     logical is_func;
+                     logical is_func = FALSE;
 
                      tok.lineno = lineno;
                      tok.p = newlb.buffer + tokoff;
                      tok.len = toklen;
-                     tok.rewritten = FALSE;
+                     tok.named = FALSE;
                      if (yacc_rules
                          || consider_token (c, lp, &tok,
                                             c_ext, cblev, &is_func))
                        {
                          if (structdef == sinbody
-                             && definedef == dnone && is_func)
-                           {   /* function defined in C++ class body */
-                             sprintf (tokb, "%s::%.*s",
+                             && definedef == dnone
+                             && is_func)
+                           /* function defined in C++ class body */
+                           {
+                             tok.named = TRUE;
+                             sprintf (nameb, "%s::%.*s",
                                       ((structtag[0] == '\0')
                                        ? "_anonymous_" : structtag),
                                       tok.len, tok.p);
-                             tok.rewritten = TRUE;
                            }
                          else
                            {
-                             sprintf (tokb, "%.*s", tok.len, tok.p);
+                             sprintf (nameb, "%.*s", tok.len, tok.p);
                            }
 
+                         if (structdef == stagseen
+                             || typdef == tend)
+                           tok.named = TRUE;
+
                          if (funcdef == ftagseen
                              || structdef == stagseen
                              || typdef == tend)
@@ -1792,12 +1788,9 @@ consider_token (c, lp, tokp, c_ext, cblev, is_func)
      int cblev;                        /* IN: curly brace level */
      logical *is_func;         /* OUT */
 {
-  logical firsttok;            /* TRUE if have seen first token in ()'s */
   Stab_entry *tokse = stab_find (get_C_stab (c_ext), tokp->p, tokp->len);
   enum sym_type toktype = stab_type (tokse);
 
-  *is_func = FALSE;            /* not a function */
-
   /*
    * Advance the definedef state machine.
    */
@@ -2782,7 +2775,7 @@ prolog_getit (s, lineno, linecharno)
   *s = '\0';
   strcpy (nambuf, save_s);
   *s = tmpc;
-  pfnote (nambuf, TRUE, save_s, strlen (nambuf), lineno, linecharno);
+  pfnote (nambuf, TRUE, FALSE, save_s, strlen (nambuf), lineno, linecharno);
 }
 
 /* It is assumed that prolog predicate starts from column 0. */