* Fix for dir.c from Andreas Schwab. filedef-cleanup-base
authorPaul Smith <psmith@gnu.org>
Mon, 7 Feb 2000 19:54:04 +0000 (19:54 +0000)
committerPaul Smith <psmith@gnu.org>
Mon, 7 Feb 2000 19:54:04 +0000 (19:54 +0000)
* Fix += target-specific variables: if your direct parent doesn't have a
  setting for the variable but his parent does, you'll get recursive
  expansion errors.

ChangeLog
dir.c
expand.c
variable.c
variable.h

index 2988bd47194ac717582977971ceb339b1e32e8cc..3888642bc66d27bd589cb4c16dacede5a6465360 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,31 @@
+2000-02-07  Paul D. Smith  <psmith@gnu.org>
+
+       For += target-specific variables we need to remember which
+       variable set we found the variable in, so we can start looking
+       there in the next iteration (otherwise we'll see it again in
+       recursively_expand and fail!).  This is getting to be a hack; if
+       it gets any worse we'll have to rethink this entire algorithm;
+       probably implementing expansion of these separately from the
+       "normal" expansion, instead of alongside.
+
+       * variable.h (recursively_expand_setlist): Rename
+       recursively_expand to add a struct variable_set_list argument, and
+       make a macro for recursively_expand.
+       (lookup_variable_setlist): Rename lookup_variable to add a struct
+       variable_set_list argument, and make a macro for lookup_variable.
+
+       * expand.c (recursively_expand_setlist): Take an extra struct
+       variable_set_list argument and pass it to
+       allocated_variable_append().
+       (reference_variable): Use lookup_variable_setlist() and pass the
+       returned variable_set_list to recursively_expand_setlist.
+       (allocated_variable_append): Take an extra setlist argument and
+       use this as the starting place when searching for the appended
+       expansion.  If it's null, use current_variable_set_list as before.
+
+       * variable.c (lookup_variable_setlist): If the LISTP argument is
+       not nil, return the list where we found the variable in it.
+
 2000-02-04  Paul D. Smith  <psmith@gnu.org>
 
        * variable.c (print_variable): Write out filename/linenumber
        * variable.c, vmsdir.h, vmsfunctions.c, vmsify.c, glob/glob.c:
        * glob/glob.h: Installed patches.  See readme.vms for details.
 
+2000-01-14  Andreas Schwab  <schwab@suse.de>
+
+       * dir.c (read_dirstream): Initialize d_type if it exists.
+
 2000-01-11  Paul D. Smith  <psmith@gnu.org>
 
        Resolve PR/xxxx: don't automatically evaluate the $(call ...)
        protocol to always use simple nul-terminated strings, instead of
        sometimes using offset pointers to mark the end of arguments.
        This change also fixes PR/1517.
-       Both PR's by Damien GIBOU <damien.gibou@st.com>.
+       Reported by Damien GIBOU <damien.gibou@st.com>.
 
        * function.c (struct function_table_entry): Remove the negative
        required_args hack; put in explicit min and max # of arguments.
        * implicit.c (pattern_search): Remove the extra check of the
        implicit flag added on 8/24/1998.  This causes problems and the
        reason for the change was better resolved by the change made to
-       check_deps() on 8/26/1998.  This fixes PR/1423.
+       check_deps() on 1998-08-26.  This fixes PR/1423.
 
 1999-12-08  Paul D. Smith  <psmith@gnu.org>
 
diff --git a/dir.c b/dir.c
index caa80426e7635940a19f86aef94a06b2634c16bd..9221c4428e725d3c9a7afb0e7b646f03021ad80f 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -1058,6 +1058,9 @@ read_dirstream (stream)
              FAKE_DIR_ENTRY (d);
 #ifdef _DIRENT_HAVE_D_NAMLEN
              d->d_namlen = len - 1;
+#endif
+#ifdef _DIRENT_HAVE_D_TYPE
+             d->d_type = DT_UNKNOWN;
 #endif
              memcpy (d->d_name, df->name, len);
              return d;
@@ -1079,19 +1082,33 @@ ansi_free(p)
       free(p);
 }
 
+/* On 64 bit ReliantUNIX (5.44 and above) in LFS mode, stat() is actually a
+ * macro for stat64().  If stat is a macro, make a local wrapper function to
+ * invoke it.
+ */
+#ifndef stat
+# ifndef VMS
+extern int stat ();
+# endif
+# define local_stat stat
+#else
+static int local_stat (path, buf)
+    char *path;
+    struct stat *buf;
+{
+  return stat (path, buf);
+}
+#endif
+
 void
 dir_setup_glob (gl)
      glob_t *gl;
 {
-#ifndef VMS
-  extern int stat ();
-#endif
-
   /* Bogus sunos4 compiler complains (!) about & before functions.  */
   gl->gl_opendir = open_dirstream;
   gl->gl_readdir = read_dirstream;
   gl->gl_closedir = ansi_free;
-  gl->gl_stat = stat;
+  gl->gl_stat = local_stat;
   /* We don't bother setting gl_lstat, since glob never calls it.
      The slot is only there for compatibility with 4.4 BSD.  */
 }
index f15da026413a29ddcf70e656be0a5a719ee683ee..070b8933269a18c24676a7d1569be7813497806f 100644 (file)
--- a/expand.c
+++ b/expand.c
@@ -91,11 +91,13 @@ initialize_variable_output ()
 \f
 /* Recursively expand V.  The returned string is malloc'd.  */
 
-static char *allocated_variable_append PARAMS ((struct variable *v));
+static char *allocated_variable_append PARAMS ((struct variable *v,
+                                                struct variable_set_list *l));
 
 char *
-recursively_expand (v)
+recursively_expand_setlist (v, list)
      register struct variable *v;
+     struct variable_set_list *list;
 {
   char *value;
 
@@ -107,7 +109,7 @@ recursively_expand (v)
 
   v->expanding = 1;
   if (v->append)
-    value = allocated_variable_append (v);
+    value = allocated_variable_append (v, list);
   else
     value = allocated_variable_expand (v->value);
   v->expanding = 0;
@@ -141,16 +143,19 @@ reference_variable (o, name, length)
      char *name;
      unsigned int length;
 {
-  register struct variable *v = lookup_variable (name, length);
+  register struct variable *v;
+  struct variable_set_list *setlist;
   char *value;
 
+  v = lookup_variable_setlist (name, length, &setlist);
+
   if (v == 0)
     warn_undefined (name, length);
 
   if (v == 0 || *v->value == '\0')
     return o;
 
-  value = (v->recursive ? recursively_expand (v) : v->value);
+  value = (v->recursive ? recursively_expand_setlist (v, setlist) : v->value);
 
   o = variable_buffer_output (o, value, strlen (value));
 
@@ -467,8 +472,9 @@ variable_expand_for_file (line, file)
     context of the next variable set, then we append the expanded value.  */
 
 static char *
-allocated_variable_append (v)
+allocated_variable_append (v, list)
      struct variable *v;
+     struct variable_set_list *list;
 {
   struct variable_set_list *save;
   int len = strlen (v->name);
@@ -480,9 +486,12 @@ allocated_variable_append (v)
 
   variable_buffer = 0;
 
-  assert(current_variable_set_list->next != 0);
+  if (!list)
+    list = current_variable_set_list;
+
+  assert(list->next != 0);
   save = current_variable_set_list;
-  current_variable_set_list = current_variable_set_list->next;
+  current_variable_set_list = list->next;
 
   var[0] = '$';
   var[1] = '(';
index 58af1219cfb9428d867da769576f35df9f4fa44d..508965756e36a29da6d5f4633248f8b58b9eee9a 100644 (file)
@@ -134,12 +134,17 @@ define_variable_in_set (name, length, value, origin, recursive, set, flocp)
 /* Lookup a variable whose name is a string starting at NAME
    and with LENGTH chars.  NAME need not be null-terminated.
    Returns address of the `struct variable' containing all info
-   on the variable, or nil if no such variable is defined.  */
+   on the variable, or nil if no such variable is defined.
+
+   If LISTP is not nil, return a pointer to the setlist where
+   the variable was found.  If the variable wasn't found, the
+   value of LISTP is unchanged.  */
 
 struct variable *
-lookup_variable (name, length)
+lookup_variable_setlist (name, length, listp)
      char *name;
      unsigned int length;
+     struct variable_set_list **listp;
 {
   register struct variable_set_list *setlist;
 
@@ -160,7 +165,11 @@ lookup_variable (name, length)
        if (*v->name == *name
            && strneq (v->name + 1, name + 1, length - 1)
            && v->name[length] == 0)
-         return v;
+          {
+            if (listp)
+              *listp = setlist;
+            return v;
+          }
     }
 
 #ifdef VMS
@@ -181,6 +190,9 @@ lookup_variable (name, length)
          sptr = value;
          scnt = 0;
 
+          if (listp)
+            *listp = current_variable_set_list;
+
          while ((sptr = strchr (sptr, '$')))
            {
              scnt++;
index d449ef82d97c7fbc8d4af060051d8983886bff44..4c707dcfc823a8335e5e47f48cf4165745e8e68d 100644 (file)
@@ -95,7 +95,10 @@ extern char *patsubst_expand PARAMS ((char *o, char *text, char *pattern, char *
                char *pattern_percent, char *replace_percent));
 
 /* expand.c */
-extern char *recursively_expand PARAMS ((struct variable *v));
+extern char *recursively_expand_setlist PARAMS ((struct variable *v,
+                                                 struct variable_set_list *l));
+
+#define recursively_expand(v) recursively_expand_setlist((v),(struct variable_set_list *)0)
 
 /* variable.c */
 extern struct variable_set_list *create_new_variable_set PARAMS ((void));
@@ -108,7 +111,12 @@ extern void print_variable_set PARAMS ((struct variable_set *set, char *prefix))
 extern void merge_variable_set_lists PARAMS ((struct variable_set_list **setlist0, struct variable_set_list *setlist1));
 extern struct variable *try_variable_definition PARAMS ((const struct floc *flocp, char *line, enum variable_origin origin, int target_var));
 
-extern struct variable *lookup_variable PARAMS ((char *name, unsigned int length));
+extern struct variable *lookup_variable_setlist
+    PARAMS ((char *name, unsigned int length,
+             struct variable_set_list **lisp));
+
+#define lookup_variable(n,l) lookup_variable_setlist((n),(l),\
+                                                (struct variable_set_list **)0)
 
 extern struct variable *define_variable_in_set
     PARAMS ((char *name, unsigned int length, char *value,