(main): Pass the -u option to sort in ctags mode.
[bpt/emacs.git] / lib-src / etags.c
index c3578a4..00c4d0c 100644 (file)
@@ -41,7 +41,7 @@
  * configuration file containing regexp definitions for etags.
  */
 
-char pot_etags_version[] = "@(#) pot revision number is $Revision: 17.22 $";
+char pot_etags_version[] = "@(#) pot revision number is 17.26";
 
 #define        TRUE    1
 #define        FALSE   0
@@ -456,9 +456,10 @@ static bool globals;               /* create tags for global variables */
 static bool declarations;      /* --declarations: tag them and extern in C&Co*/
 static bool members;           /* create tags for C member variables */
 static bool no_line_directive; /* ignore #line directives (undocumented) */
+static bool no_duplicates;     /* no duplicate tags for ctags (undocumented) */
 static bool update;            /* -u: update tags */
 static bool vgrind_style;      /* -v: create vgrind style index output */
-static bool no_warnings;       /* -w: suppress warnings */
+static bool no_warnings;       /* -w: suppress warnings (undocumented) */
 static bool cxref_style;       /* -x: create cxref style output */
 static bool cplusplus;         /* .[hc] means C++, not C */
 static bool ignoreindent;      /* -I: ignore indentation in C */
@@ -477,39 +478,40 @@ static bool need_filebuf; /* some regexes are multi-line */
 
 static struct option longopts[] =
 {
-  { "append",            no_argument,       NULL,               'a'   },
-  { "packages-only",      no_argument,      &packages_only,     TRUE  },
-  { "c++",               no_argument,       NULL,               'C'   },
-  { "declarations",      no_argument,       &declarations,      TRUE  },
-  { "no-line-directive",  no_argument,      &no_line_directive, TRUE  },
-  { "help",              no_argument,       NULL,               'h'   },
-  { "help",              no_argument,       NULL,               'H'   },
-  { "ignore-indentation", no_argument,      NULL,               'I'   },
-  { "language",           required_argument, NULL,                      'l'   },
-  { "members",           no_argument,       &members,           TRUE  },
-  { "no-members",        no_argument,       &members,           FALSE },
-  { "output",            required_argument, NULL,               'o'   },
-  { "regex",             required_argument, NULL,               'r'   },
-  { "no-regex",                  no_argument,       NULL,               'R'   },
-  { "ignore-case-regex",  required_argument, NULL,              'c'   },
+  { "append",             no_argument,       NULL,               'a'   },
+  { "packages-only",      no_argument,       &packages_only,     TRUE  },
+  { "c++",                no_argument,       NULL,               'C'   },
+  { "declarations",       no_argument,       &declarations,      TRUE  },
+  { "no-line-directive",  no_argument,       &no_line_directive, TRUE  },
+  { "no-duplicates",      no_argument,       &no_duplicates,     TRUE  },
+  { "help",               no_argument,       NULL,               'h'   },
+  { "help",               no_argument,       NULL,               'H'   },
+  { "ignore-indentation", no_argument,       NULL,               'I'   },
+  { "language",           required_argument, NULL,               'l'   },
+  { "members",            no_argument,       &members,           TRUE  },
+  { "no-members",         no_argument,       &members,           FALSE },
+  { "output",             required_argument, NULL,               'o'   },
+  { "regex",              required_argument, NULL,               'r'   },
+  { "no-regex",           no_argument,       NULL,               'R'   },
+  { "ignore-case-regex",  required_argument, NULL,               'c'   },
   { "parse-stdin",        required_argument, NULL,               STDIN },
-  { "version",           no_argument,       NULL,               'V'   },
+  { "version",            no_argument,       NULL,               'V'   },
 
 #if CTAGS /* Ctags options */
-  { "backward-search",   no_argument,       NULL,               'B'   },
-  { "cxref",             no_argument,       NULL,               'x'   },
-  { "defines",           no_argument,       NULL,               'd'   },
-  { "globals",           no_argument,       &globals,           TRUE  },
-  { "typedefs",                  no_argument,       NULL,               't'   },
-  { "typedefs-and-c++",          no_argument,       NULL,               'T'   },
-  { "update",            no_argument,       NULL,               'u'   },
-  { "vgrind",            no_argument,       NULL,               'v'   },
-  { "no-warn",           no_argument,       NULL,               'w'   },
+  { "backward-search",    no_argument,       NULL,               'B'   },
+  { "cxref",              no_argument,       NULL,               'x'   },
+  { "defines",            no_argument,       NULL,               'd'   },
+  { "globals",            no_argument,       &globals,           TRUE  },
+  { "typedefs",           no_argument,       NULL,               't'   },
+  { "typedefs-and-c++",   no_argument,       NULL,               'T'   },
+  { "update",             no_argument,       NULL,               'u'   },
+  { "vgrind",             no_argument,       NULL,               'v'   },
+  { "no-warn",            no_argument,       NULL,               'w'   },
 
 #else /* Etags options */
-  { "no-defines",        no_argument,       NULL,               'D'   },
-  { "no-globals",        no_argument,       &globals,           FALSE },
-  { "include",           required_argument, NULL,               'i'   },
+  { "no-defines",         no_argument,       NULL,               'D'   },
+  { "no-globals",         no_argument,       &globals,           FALSE },
+  { "include",            required_argument, NULL,               'i'   },
 #endif
   { NULL }
 };
@@ -976,9 +978,13 @@ Relative ones are stored relative to the output file's directory.\n");
         Print on the standard output an index of items intended for\n\
         human consumption, similar to the output of vgrind.  The index\n\
         is sorted, and gives the page number of each item.");
+# if PRINT_UNDOCUMENTED_OPTIONS_HELP
+      puts ("-w, --no-duplicates\n\
+        Do not create duplicate tag entries, for compatibility with\n\
+       traditional ctags.");
       puts ("-w, --no-warn\n\
-        Suppress warning messages about entries defined in multiple\n\
-        files.");
+        Suppress warning messages about duplicate tag entries.");
+# endif /* PRINT_UNDOCUMENTED_OPTIONS_HELP */
       puts ("-x, --cxref\n\
         Like --vgrind, but in the style of cxref, rather than vgrind.\n\
         The output uses line numbers instead of page numbers, but\n\
@@ -1454,8 +1460,11 @@ main (argc, argv)
   if (CTAGS)
     if (append_to_tagfile || update)
       {
-       char cmd[2*BUFSIZ+10];
-       sprintf (cmd, "sort -o %.*s %.*s", BUFSIZ, tagfile, BUFSIZ, tagfile);
+       char cmd[2*BUFSIZ+20];
+       /* Maybe these should be used:
+          setenv ("LC_COLLATE", "C", 1);
+          setenv ("LC_ALL", "C", 1); */
+       sprintf (cmd, "sort -u -o %.*s %.*s", BUFSIZ, tagfile, BUFSIZ, tagfile);
        exit (system (cmd));
       }
   return EXIT_SUCCESS;
@@ -2168,7 +2177,7 @@ add_node (np, cur_node_p)
        * If this tag name matches an existing one, then
        * do not add the node, but maybe print a warning.
        */
-      if (!dif)
+      if (no_duplicates && !dif)
        {
          if (np->fdp == cur_node->fdp)
            {
@@ -3163,7 +3172,7 @@ static void
 make_C_tag (isfun)
      bool isfun;
 {
-  /* This function should never be called when token.valid is FALSE, but
+  /* This function is never called when token.valid is FALSE, but
      we must protect against invalid input or internal errors. */
   if (!DEBUG && !token.valid)
     return;
@@ -3493,7 +3502,6 @@ C_entries (c_ext, inf)
                                  off += 1;
                                  len -= 1;
                                }
-                             len = toklen;
                              linebuffer_setlen (&token_name, len);
                              strncpy (token_name.buffer,
                                       newlb.buffer + off, len);
@@ -4687,8 +4695,16 @@ Makefile_targets (inf)
       while (*bp != '\0' && *bp != '=' && *bp != ':')
        bp++;
       if (*bp == ':' || (globals && *bp == '='))
-       make_tag (lb.buffer, bp - lb.buffer, TRUE,
-                 lb.buffer, bp - lb.buffer + 1, lineno, linecharno);
+       {
+         /* We should detect if there is more than one tag, but we do not.
+            We just skip initial and final spaces. */
+         char * namestart = skip_spaces (lb.buffer);
+         while (--bp > namestart)
+           if (!notinname (*bp))
+             break;
+         make_tag (namestart, bp - namestart + 1, TRUE,
+                   lb.buffer, bp - lb.buffer + 2, lineno, linecharno);
+       }
     }
 }
 
@@ -6278,7 +6294,7 @@ readline (lbp, stream)
                  name = lbp->buffer + start;
                  *endp = '\0';
                  canonicalize_filename (name); /* for DOS */
-                 taggedabsname = absolute_filename (name, curfdp->infabsdir);
+                 taggedabsname = absolute_filename (name, tagfiledir);
                  if (filename_is_absolute (name)
                      || filename_is_absolute (curfdp->infname))
                    taggedfname = savestr (taggedabsname);