]> code.delx.au - gnu-emacs/blobdiff - lib-src/ebrowse.c
Update copyright year to 2015
[gnu-emacs] / lib-src / ebrowse.c
index a1fe10b863a20fb923723204a2766aa14611b6e7..d16c9ae54af12f44cd994df05e3ae81ddc6491ea 100644 (file)
@@ -1,6 +1,6 @@
 /* ebrowse.c --- parsing files for the ebrowse C++ browser
 
-Copyright (C) 1992-201 Free Software Foundation, Inc.
+Copyright (C) 1992-2015 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -19,6 +19,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
 #include <config.h>
+#include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -43,17 +44,12 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #define READ_CHUNK_SIZE (100 * 1024)
 
-/* The character used as a separator in path lists (like $PATH).  */
-
 #if defined (__MSDOS__)
-#define PATH_LIST_SEPARATOR ';'
 #define FILENAME_EQ(X,Y)    (strcasecmp (X,Y) == 0)
 #else
 #if defined (WINDOWSNT)
-#define PATH_LIST_SEPARATOR ';'
 #define FILENAME_EQ(X,Y)    (stricmp (X,Y) == 0)
 #else
-#define PATH_LIST_SEPARATOR ':'
 #define FILENAME_EQ(X,Y)    (streq (X,Y))
 #endif
 #endif
@@ -242,7 +238,7 @@ struct member
   char *def_regexp;            /* Regular expression matching definition.  */
   const char *def_filename;    /* File name of definition.  */
   int def_pos;                 /* Buffer position of definition.  */
-  char name[1];                        /* Member name.  */
+  char name[FLEXIBLE_ARRAY_MEMBER]; /* Member name.  */
 };
 
 /* Structures of this type are used to connect class structures with
@@ -261,7 +257,7 @@ struct alias
   struct alias *next;          /* Next in list.  */
   struct sym *namesp;          /* Namespace in which defined.  */
   struct link *aliasee;                /* List of aliased namespaces (A::B::C...).  */
-  char name[1];                        /* Alias name.  */
+  char name[FLEXIBLE_ARRAY_MEMBER]; /* Alias name.  */
 };
 
 /* The structure used to describe a class in the symbol table,
@@ -285,7 +281,7 @@ struct sym
   const char *filename;                /* File in which it can be found.  */
   const char *sfilename;       /* File in which members can be found.  */
   struct sym *namesp;          /* Namespace in which defined. .  */
-  char name[1];                 /* Name of the class.  */
+  char name[FLEXIBLE_ARRAY_MEMBER]; /* Name of the class.  */
 };
 
 /* Experimental: Print info for `--position-info'.  We print
@@ -463,10 +459,6 @@ static struct member *add_member (struct sym *, char *, int, int, unsigned);
 static void class_definition (struct sym *, int, int, int);
 static char *operator_name (int *);
 static void parse_qualified_param_ident_or_type (char **);
-static void usage (int) NO_RETURN;
-static void version (void) NO_RETURN;
-
-
 \f
 /***********************************************************************
                              Utilities
@@ -522,7 +514,7 @@ static char *
 xstrdup (char *s)
 {
   if (s)
-    s = strcpy (xmalloc (strlen (s) + 1), s);
+    return strcpy (xmalloc (strlen (s) + 1), s);
   return s;
 }
 
@@ -576,8 +568,8 @@ add_sym (const char *name, struct sym *nested_in_class)
          puts (name);
        }
 
-      sym = (struct sym *) xmalloc (sizeof *sym + strlen (name));
-      memset (sym, 0, sizeof *sym);
+      sym = xmalloc (offsetof (struct sym, name) + strlen (name) + 1);
+      memset (sym, 0, offsetof (struct sym, name));
       strcpy (sym->name, name);
       sym->namesp = scope;
       sym->next = class_table[h];
@@ -861,7 +853,8 @@ add_global_decl (char *name, char *regexp, int pos, unsigned int hash, int var,
 static struct member *
 add_member (struct sym *cls, char *name, int var, int sc, unsigned int hash)
 {
-  struct member *m = (struct member *) xmalloc (sizeof *m + strlen (name));
+  struct member *m = xmalloc (offsetof (struct member, name)
+                             + strlen (name) + 1);
   struct member **list;
   struct member *p;
   struct member *prev;
@@ -971,8 +964,8 @@ mark_inherited_virtual (void)
 static struct sym *
 make_namespace (char *name, struct sym *context)
 {
-  struct sym *s = (struct sym *) xmalloc (sizeof *s + strlen (name));
-  memset (s, 0, sizeof *s);
+  struct sym *s = xmalloc (offsetof (struct sym, name) + strlen (name) + 1);
+  memset (s, 0, offsetof (struct sym, name));
   strcpy (s->name, name);
   s->next = all_namespaces;
   s->namesp = context;
@@ -1055,7 +1048,7 @@ register_namespace_alias (char *new_name, struct link *old_name)
     if (streq (new_name, al->name) && (al->namesp == current_namespace))
       return;
 
-  al = (struct alias *) xmalloc (sizeof *al + strlen (new_name));
+  al = xmalloc (offsetof (struct alias, name) + strlen (new_name) + 1);
   strcpy (al->name, new_name);
   al->next = namespace_alias_table[h];
   al->namesp = current_namespace;
@@ -1103,7 +1096,7 @@ leave_namespace (void)
 /* Write string S to the output file FP in a Lisp-readable form.
    If S is null, write out `()'.  */
 
-static inline void
+static void
 putstr (const char *s, FILE *fp)
 {
   if (!s)
@@ -1157,19 +1150,19 @@ sym_scope_1 (struct sym *p)
   if (*scope_buffer)
     {
       ensure_scope_buffer_room (3);
-      strcat (scope_buffer, "::");
+      strcpy (scope_buffer + scope_buffer_len, "::");
       scope_buffer_len += 2;
     }
 
   len = strlen (p->name);
   ensure_scope_buffer_room (len + 1);
-  strcat (scope_buffer, p->name);
+  strcpy (scope_buffer + scope_buffer_len, p->name);
   scope_buffer_len += len;
 
   if (HAS_FLAG (p->flags, F_TEMPLATE))
     {
       ensure_scope_buffer_room (3);
-      strcat (scope_buffer, "<>");
+      strcpy (scope_buffer + scope_buffer_len, "<>");
       scope_buffer_len += 2;
     }
 
@@ -2804,24 +2797,25 @@ operator_name (int *sc)
       s = token_string (LA1);
       MATCH ();
 
-      len = strlen (s) + 10;
+      ptrdiff_t slen = strlen (s);
+      len = slen + 10;
       if (len > id_size)
        {
          size_t new_size = max (len, 2 * id_size);
          id = (char *) xrealloc (id, new_size);
          id_size = new_size;
        }
-      strcpy (id, s);
+      char *z = stpcpy (id, s);
 
       /* Vector new or delete?  */
       if (LOOKING_AT ('['))
        {
-         strcat (id, "[");
+         z = stpcpy (z, "[");
          MATCH ();
 
          if (LOOKING_AT (']'))
            {
-             strcat (id, "]");
+             strcpy (z, "]");
              MATCH ();
            }
        }
@@ -2837,7 +2831,7 @@ operator_name (int *sc)
          id = (char *) xrealloc (id, new_size);
          id_size = new_size;
        }
-      strcpy (id, "operator");
+      char *z = stpcpy (id, "operator");
 
       /* Beware access declarations of the form "X::f;" Beware of
         `operator () ()'.  Yet another difficulty is found in
@@ -2849,14 +2843,16 @@ operator_name (int *sc)
          len += strlen (s) + 2;
          if (len > id_size)
            {
+             ptrdiff_t idlen = z - id;
              size_t new_size = max (len, 2 * id_size);
              id = (char *) xrealloc (id, new_size);
              id_size = new_size;
+             z = id + idlen;
            }
 
          if (*s != ')' && *s != ']')
-           strcat (id, " ");
-          strcat (id, s);
+           *z++ = ' ';
+          z = stpcpy (z, s);
           MATCH ();
 
          /* If this is a simple operator like `+', stop now.  */
@@ -3421,7 +3417,7 @@ add_search_path (char *path_list)
       char *start = path_list;
       struct search_path *p;
 
-      while (*path_list && *path_list != PATH_LIST_SEPARATOR)
+      while (*path_list && *path_list != SEPCHAR)
         ++path_list;
 
       p = (struct search_path *) xmalloc (sizeof *p);
@@ -3438,7 +3434,7 @@ add_search_path (char *path_list)
       else
         search_path = search_path_tail = p;
 
-      while (*path_list == PATH_LIST_SEPARATOR)
+      while (*path_list == SEPCHAR)
         ++path_list;
     }
 }
@@ -3469,9 +3465,9 @@ open_file (char *file)
          buffer = (char *) xrealloc (buffer, buffer_size);
        }
 
-      strcpy (buffer, path->path);
-      strcat (buffer, "/");
-      strcat (buffer, file);
+      char *z = stpcpy (buffer, path->path);
+      *z++ = '/';
+      strcpy (z, file);
       fp = fopen (buffer, "r");
     }
 
@@ -3488,7 +3484,9 @@ open_file (char *file)
 
 /* Display usage information and exit program.  */
 
-#define USAGE "\
+static char const *const usage_message[] =
+  {
+    "\
 Usage: ebrowse [options] {files}\n\
 \n\
   -a, --append                  append output to existing file\n\
@@ -3496,6 +3494,8 @@ Usage: ebrowse [options] {files}\n\
   -I, --search-path=LIST        set search path for input files\n\
   -m, --min-regexp-length=N     set minimum regexp length to N\n\
   -M, --max-regexp-length=N     set maximum regexp length to N\n\
+",
+    "\
   -n, --no-nested-classes       exclude nested classes\n\
   -o, --output-file=FILE        set output file name to FILE\n\
   -p, --position-info           print info about position in file\n\
@@ -3505,12 +3505,16 @@ Usage: ebrowse [options] {files}\n\
   -x, --no-regexps             don't record regular expressions\n\
       --help                    display this help\n\
       --version                        display version info\n\
+\n\
 "
+  };
 
-static void
+static _Noreturn void
 usage (int error)
 {
-  puts (USAGE);
+  int i;
+  for (i = 0; i < sizeof usage_message / sizeof *usage_message; i++)
+    fputs (usage_message[i], stdout);
   exit (error ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
@@ -3522,11 +3526,10 @@ usage (int error)
 # define VERSION "21"
 #endif
 
-static void
+static _Noreturn void
 version (void)
 {
-  /* Makes it easier to update automatically. */
-  char emacs_copyright[] = "Copyright (C) 2012 Free Software Foundation, Inc.";
+  char emacs_copyright[] = COPYRIGHT;
 
   printf ("ebrowse %s\n", VERSION);
   puts (emacs_copyright);