m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch-1_4 undivert fixes


From: Eric Blake
Subject: branch-1_4 undivert fixes
Date: Mon, 10 Jul 2006 00:33:18 +0000

This patch fixes undivert to behave sanely with empty or 0 as
its argument.  Without it,  `undivert()' behaved differently
depending on whether you used -I (or M4PATH) or not.

2006-07-09  Eric Blake  <address@hidden>

        * doc/m4.texinfo (Undivert): Fix typo in last commit.
        * src/m4.c (usage): Document M4PATH.
        * src/path.c (path_search): Reject empty string.
        * src/output.c (insert_diversion): Ignore diversion 0.
        * src/builtin.c (m4_undivert): Ignore empty string.
        * NEWS: Document this fix.
Index: NEWS
===================================================================
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.1.1.1.2.30
diff -u -p -r1.1.1.1.2.30 NEWS
--- NEWS        7 Jul 2006 03:37:26 -0000       1.1.1.1.2.30
+++ NEWS        9 Jul 2006 13:22:12 -0000
@@ -29,6 +29,9 @@ Version 1.4.5 - ?? 2006, by ???  (CVS ve
   differently.
 * Fix bug in 1.4.3 patch to use \n line-endings that did not work for
   cygwin.
+* When given the empty string or 0, undivert is now documented as a no-op
+  rather than closing stdout, warning about a non-existent file, or trying
+  to read a directory as a file.
 
 Version 1.4.4b - 17 June 2006, by Eric Blake  (CVS version 1.4.4a)
 
Index: src/builtin.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/builtin.c,v
retrieving revision 1.1.1.1.2.18
diff -u -p -r1.1.1.1.2.18 builtin.c
--- src/builtin.c       7 Jul 2006 20:20:38 -0000       1.1.1.1.2.18
+++ src/builtin.c       9 Jul 2006 13:22:12 -0000
@@ -998,6 +998,8 @@ m4_undivert (struct obstack *obs, int ar
       {
        if (sscanf (ARG (i), "%d", &file) == 1)
          insert_diversion (file);
+       else if (!*ARG (i))
+         /* Ignore empty string.  */;
        else if (no_gnu_extensions)
          M4ERROR ((warning_status, 0,
                    "non-numeric argument to builtin `%s'", ARG (0)));
Index: src/m4.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/m4.c,v
retrieving revision 1.1.1.1.2.13
diff -u -p -r1.1.1.1.2.13 m4.c
--- src/m4.c    7 Jul 2006 20:20:38 -0000       1.1.1.1.2.13
+++ src/m4.c    9 Jul 2006 13:22:12 -0000
@@ -208,6 +208,11 @@ FLAGS is any of:\n\
             stdout);
       fputs ("\
 \n\
+If defined, the environment variable `M4PATH' is a colon-separated list\n\
+of directories included after any specified by `-I'.\n",
+            stdout);
+      fputs ("\
+\n\
 If no FILE or if FILE is `-', standard input is read.\n",
             stdout);
     }
Index: src/output.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/output.c,v
retrieving revision 1.1.1.1.2.6
diff -u -p -r1.1.1.1.2.6 output.c
--- src/output.c        23 Jun 2006 13:06:10 -0000      1.1.1.1.2.6
+++ src/output.c        9 Jul 2006 13:22:12 -0000
@@ -476,9 +476,10 @@ insert_diversion (int divnum)
 {
   struct diversion *diversion;
 
-  /* Do not care about unexisting diversions.  */
+  /* Do not care about unexisting diversions.  Also, diversion 0 is stdout,
+     which is effectively always empty.  */
 
-  if (divnum < 0 || divnum >= diversions)
+  if (divnum <= 0 || divnum >= diversions)
     return;
 
   /* Also avoid undiverting into self.  */
Index: src/path.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/path.c,v
retrieving revision 1.1.1.1.2.4
diff -u -p -r1.1.1.1.2.4 path.c
--- src/path.c  22 Jun 2006 17:43:05 -0000      1.1.1.1.2.4
+++ src/path.c  9 Jul 2006 13:22:12 -0000
@@ -101,40 +101,47 @@ add_include_directory (const char *dir)
 }
 
 FILE *
-path_search (const char *dir)
+path_search (const char *file)
 {
   FILE *fp;
   includes *incl;
   char *name;                  /* buffer for constructed name */
   int e;
 
+  /* Reject empty file.  */
+  if (!*file)
+    {
+      errno = ENOENT;
+      return NULL;
+    }
+
   /* Look in current working directory first.  */
-  fp = fopen (dir, "r");
+  fp = fopen (file, "r");
   if (fp != NULL)
     return fp;
 
   /* If file not found, and filename absolute, fail.  */
-  if (*dir == '/' || no_gnu_extensions)
+  if (*file == '/' || no_gnu_extensions)
     return NULL;
   e = errno;
 
-  name = (char *) xmalloc (dir_max_length + 1 + strlen (dir) + 1);
+  name = (char *) xmalloc (dir_max_length + 1 + strlen (file) + 1);
 
   for (incl = dir_list; incl != NULL; incl = incl->next)
     {
       strncpy (name, incl->dir, incl->len);
       name[incl->len] = '/';
-      strcpy (name + incl->len + 1, dir);
+      strcpy (name + incl->len + 1, file);
 
 #ifdef DEBUG_INCL
-      fprintf (stderr, "path_search (%s) -- trying %s\n", dir, name);
+      fprintf (stderr, "path_search (%s) -- trying %s\n", file, name);
 #endif
 
       fp = fopen (name, "r");
       if (fp != NULL)
        {
          if (debug_level & DEBUG_TRACE_PATH)
-           DEBUG_MESSAGE2 ("path search for `%s' found `%s'", dir, name);
+           DEBUG_MESSAGE2 ("path search for `%s' found `%s'", file, name);
          break;
        }
     }
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.1.1.1.2.33
diff -u -p -r1.1.1.1.2.33 m4.texinfo
--- doc/m4.texinfo      8 Jul 2006 21:20:44 -0000       1.1.1.1.2.33
+++ doc/m4.texinfo      9 Jul 2006 13:22:13 -0000
@@ -2698,6 +2698,7 @@ undivert(`0')
 @result{}
 undivert
 @result{}diverted text
address@hidden
 @end example
 
 When a diversion has been undiverted, the diverted text is discarded,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]