Various simple code cleanups.
authorPaul Smith <psmith@gnu.org>
Sun, 25 Oct 2009 00:26:34 +0000 (00:26 +0000)
committerPaul Smith <psmith@gnu.org>
Sun, 25 Oct 2009 00:26:34 +0000 (00:26 +0000)
commands.c
default.c
dep.h
file.c
read.c
variable.c
variable.h

index 19cb7b4..0023ba1 100644 (file)
@@ -43,20 +43,22 @@ int getpid ();
 static unsigned long
 dep_hash_1 (const void *key)
 {
-  return_STRING_HASH_1 (dep_name ((struct dep const *) key));
+  const struct dep *d = key;
+  return_STRING_HASH_1 (dep_name (d));
 }
 
 static unsigned long
 dep_hash_2 (const void *key)
 {
-  return_STRING_HASH_2 (dep_name ((struct dep const *) key));
+  const struct dep *d = key;
+  return_STRING_HASH_2 (dep_name (d));
 }
 
 static int
 dep_hash_cmp (const void *x, const void *y)
 {
-  struct dep *dx = (struct dep *) x;
-  struct dep *dy = (struct dep *) y;
+  const struct dep *dx = x;
+  const struct dep *dy = y;
   return strcmp (dep_name (dx), dep_name (dy));
 }
 
index 2787bf2..fad72ee 100644 (file)
--- a/default.c
+++ b/default.c
@@ -538,14 +538,14 @@ set_default_suffixes (void)
   suffix_file = enter_file (strcache_add (".SUFFIXES"));
 
   if (no_builtin_rules_flag)
-    define_variable ("SUFFIXES", 8, "", o_default, 0);
+    define_variable_cname ("SUFFIXES", "", o_default, 0);
   else
     {
       char *p = default_suffixes;
       suffix_file->deps = enter_prereqs(PARSE_FILE_SEQ (&p, struct dep, '\0',
                                                         NULL, 0),
                                         NULL);
-      define_variable ("SUFFIXES", 8, default_suffixes, o_default, 0);
+      define_variable_cname ("SUFFIXES", default_suffixes, o_default, 0);
     }
 }
 
diff --git a/dep.h b/dep.h
index 1f49313..f25c2d4 100644 (file)
--- a/dep.h
+++ b/dep.h
@@ -88,5 +88,5 @@ struct dep *copy_dep_chain (const struct dep *d);
 void free_dep_chain (struct dep *d);
 void free_ns_chain (struct nameseq *n);
 struct dep *read_all_makefiles (const char **makefiles);
-int eval_buffer (char *buffer);
+void eval_buffer (char *buffer);
 int update_goal_chain (struct dep *goals);
diff --git a/file.c b/file.c
index 9e744b7..e968e40 100644 (file)
--- a/file.c
+++ b/file.c
@@ -758,7 +758,7 @@ snap_deps (void)
   /* If .POSIX was defined, remove OUTPUT_OPTION to comply.  */
   /* This needs more work: what if the user sets this in the makefile?
   if (posix_pedantic)
-    define_variable (STRING_SIZE_TUPLE("OUTPUT_OPTION"), "", o_default, 1);
+    define_variable_cname ("OUTPUT_OPTION", "", o_default, 1);
   */
 #endif
 }
diff --git a/read.c b/read.c
index 669a09c..cda9a28 100644 (file)
--- a/read.c
+++ b/read.c
@@ -134,7 +134,7 @@ const struct floc *reading_file = 0;
 static struct dep *read_makefiles = 0;
 
 static int eval_makefile (const char *filename, int flags);
-static int eval (struct ebuffer *buffer, int flags);
+static void eval (struct ebuffer *buffer, int flags);
 
 static long readline (struct ebuffer *ebuf);
 static void do_undefine (char *name, enum variable_origin origin,
@@ -174,7 +174,7 @@ read_all_makefiles (const char **makefiles)
   /* Create *_LIST variables, to hold the makefiles, targets, and variables
      we will be reading. */
 
-  define_variable ("MAKEFILE_LIST", sizeof ("MAKEFILE_LIST")-1, "", o_file, 0);
+  define_variable_cname ("MAKEFILE_LIST", "", o_file, 0);
 
   DB (DB_BASIC, (_("Reading makefiles...\n")));
 
@@ -323,7 +323,6 @@ eval_makefile (const char *filename, int flags)
   const struct floc *curfile;
   char *expanded = 0;
   int makefile_errno;
-  int r;
 
   filename = strcache_add (filename);
   ebuf.floc.filenm = filename;
@@ -421,7 +420,7 @@ eval_makefile (const char *filename, int flags)
   curfile = reading_file;
   reading_file = &ebuf.floc;
 
-  r = eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL));
+  eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL));
 
   reading_file = curfile;
 
@@ -429,17 +428,17 @@ eval_makefile (const char *filename, int flags)
 
   free (ebuf.bufstart);
   alloca (0);
-  return r;
+
+  return 1;
 }
 
-int
+void
 eval_buffer (char *buffer)
 {
   struct ebuffer ebuf;
   struct conditionals *saved;
   struct conditionals new;
   const struct floc *curfile;
-  int r;
 
   /* Evaluate the buffer */
 
@@ -457,14 +456,13 @@ eval_buffer (char *buffer)
 
   saved = install_conditionals (&new);
 
-  r = eval (&ebuf, 1);
+  eval (&ebuf, 1);
 
   restore_conditionals (saved);
 
   reading_file = curfile;
 
   alloca (0);
-  return r;
 }
 \f
 /* Check LINE to see if it's a variable assignment or undefine.
@@ -540,15 +538,13 @@ parse_var_assignment (const char *line, struct vmodifiers *vmod)
   vmod->assign_v = 1;
   return (char *)p;
 }
-
 \f
 
 /* Read file FILENAME as a makefile and add its contents to the data base.
 
    SET_DEFAULT is true if we are allowed to set the default goal.  */
 
-
-static int
+static void
 eval (struct ebuffer *ebuf, int set_default)
 {
   char *collapsed = 0;
@@ -1301,8 +1297,6 @@ eval (struct ebuffer *ebuf, int set_default)
   if (collapsed)
     free (collapsed);
   free (commands);
-
-  return 1;
 }
 \f
 
index 7cee8bd..e47c896 100644 (file)
@@ -799,7 +799,7 @@ define_automatic_variables (void)
   char buf[200];
 
   sprintf (buf, "%u", makelevel);
-  (void) define_variable (MAKELEVEL_NAME, MAKELEVEL_LENGTH, buf, o_env, 0);
+  define_variable_cname (MAKELEVEL_NAME, buf, o_env, 0);
 
   sprintf (buf, "%s%s%s",
           version_string,
@@ -807,7 +807,7 @@ define_automatic_variables (void)
           ? "" : "-",
           (remote_description == 0 || remote_description[0] == '\0')
           ? "" : remote_description);
-  (void) define_variable ("MAKE_VERSION", 12, buf, o_default, 0);
+  define_variable_cname ("MAKE_VERSION", buf, o_default, 0);
 
 #ifdef  __MSDOS__
   /* Allow to specify a special shell just for Make,
@@ -818,13 +818,13 @@ define_automatic_variables (void)
     struct variable *mshp = lookup_variable ("MAKESHELL", 9);
     struct variable *comp = lookup_variable ("COMSPEC", 7);
 
-    /* Make $MAKESHELL override $SHELL even if -e is in effect.  */
+    /* $(MAKESHELL) overrides $(SHELL) even if -e is in effect.  */
     if (mshp)
       (void) define_variable (shell_str, shlen,
                              mshp->value, o_env_override, 0);
     else if (comp)
       {
-       /* $COMSPEC shouldn't override $SHELL.  */
+       /* $(COMSPEC) shouldn't override $(SHELL).  */
        struct variable *shp = lookup_variable (shell_str, shlen);
 
        if (!shp)
@@ -883,7 +883,7 @@ define_automatic_variables (void)
 
   /* This won't override any definition, but it will provide one if there
      isn't one there.  */
-  v = define_variable ("SHELL", 5, default_shell, o_default, 0);
+  v = define_variable_cname ("SHELL", default_shell, o_default, 0);
 #ifdef __MSDOS__
   v->export = v_export;  /*  Export always SHELL.  */
 #endif
@@ -903,36 +903,36 @@ define_automatic_variables (void)
 #endif
 
   /* Make sure MAKEFILES gets exported if it is set.  */
-  v = define_variable ("MAKEFILES", 9, "", o_default, 0);
+  v = define_variable_cname ("MAKEFILES", "", o_default, 0);
   v->export = v_ifset;
 
   /* Define the magic D and F variables in terms of
      the automatic variables they are variations of.  */
 
 #ifdef VMS
-  define_variable ("@D", 2, "$(dir $@)", o_automatic, 1);
-  define_variable ("%D", 2, "$(dir $%)", o_automatic, 1);
-  define_variable ("*D", 2, "$(dir $*)", o_automatic, 1);
-  define_variable ("<D", 2, "$(dir $<)", o_automatic, 1);
-  define_variable ("?D", 2, "$(dir $?)", o_automatic, 1);
-  define_variable ("^D", 2, "$(dir $^)", o_automatic, 1);
-  define_variable ("+D", 2, "$(dir $+)", o_automatic, 1);
+  define_variable_cname ("@D", "$(dir $@)", o_automatic, 1);
+  define_variable_cname ("%D", "$(dir $%)", o_automatic, 1);
+  define_variable_cname ("*D", "$(dir $*)", o_automatic, 1);
+  define_variable_cname ("<D", "$(dir $<)", o_automatic, 1);
+  define_variable_cname ("?D", "$(dir $?)", o_automatic, 1);
+  define_variable_cname ("^D", "$(dir $^)", o_automatic, 1);
+  define_variable_cname ("+D", "$(dir $+)", o_automatic, 1);
 #else
-  define_variable ("@D", 2, "$(patsubst %/,%,$(dir $@))", o_automatic, 1);
-  define_variable ("%D", 2, "$(patsubst %/,%,$(dir $%))", o_automatic, 1);
-  define_variable ("*D", 2, "$(patsubst %/,%,$(dir $*))", o_automatic, 1);
-  define_variable ("<D", 2, "$(patsubst %/,%,$(dir $<))", o_automatic, 1);
-  define_variable ("?D", 2, "$(patsubst %/,%,$(dir $?))", o_automatic, 1);
-  define_variable ("^D", 2, "$(patsubst %/,%,$(dir $^))", o_automatic, 1);
-  define_variable ("+D", 2, "$(patsubst %/,%,$(dir $+))", o_automatic, 1);
+  define_variable_cname ("@D", "$(patsubst %/,%,$(dir $@))", o_automatic, 1);
+  define_variable_cname ("%D", "$(patsubst %/,%,$(dir $%))", o_automatic, 1);
+  define_variable_cname ("*D", "$(patsubst %/,%,$(dir $*))", o_automatic, 1);
+  define_variable_cname ("<D", "$(patsubst %/,%,$(dir $<))", o_automatic, 1);
+  define_variable_cname ("?D", "$(patsubst %/,%,$(dir $?))", o_automatic, 1);
+  define_variable_cname ("^D", "$(patsubst %/,%,$(dir $^))", o_automatic, 1);
+  define_variable_cname ("+D", "$(patsubst %/,%,$(dir $+))", o_automatic, 1);
 #endif
-  define_variable ("@F", 2, "$(notdir $@)", o_automatic, 1);
-  define_variable ("%F", 2, "$(notdir $%)", o_automatic, 1);
-  define_variable ("*F", 2, "$(notdir $*)", o_automatic, 1);
-  define_variable ("<F", 2, "$(notdir $<)", o_automatic, 1);
-  define_variable ("?F", 2, "$(notdir $?)", o_automatic, 1);
-  define_variable ("^F", 2, "$(notdir $^)", o_automatic, 1);
-  define_variable ("+F", 2, "$(notdir $+)", o_automatic, 1);
+  define_variable_cname ("@F", "$(notdir $@)", o_automatic, 1);
+  define_variable_cname ("%F", "$(notdir $%)", o_automatic, 1);
+  define_variable_cname ("*F", "$(notdir $*)", o_automatic, 1);
+  define_variable_cname ("<F", "$(notdir $<)", o_automatic, 1);
+  define_variable_cname ("?F", "$(notdir $?)", o_automatic, 1);
+  define_variable_cname ("^F", "$(notdir $^)", o_automatic, 1);
+  define_variable_cname ("+F", "$(notdir $+)", o_automatic, 1);
 }
 \f
 int export_all_variables;
index 84ae55e..dbaef67 100644 (file)
@@ -180,6 +180,12 @@ struct variable *define_variable_in_set (const char *name, unsigned int length,
           define_variable_in_set((n),(l),(v),(o),(r),\
                                  current_variable_set_list->set,NILF)
 
+/* Define a variable with a constant name in the current variable set.  */
+
+#define define_variable_cname(n,v,o,r) \
+          define_variable_in_set((n),(sizeof (n) - 1),(v),(o),(r),\
+                                 current_variable_set_list->set,NILF)
+
 /* Define a variable with a location in the current variable set.  */
 
 #define define_variable_loc(n,l,v,o,r,f) \