m4-commit
[Top][All Lists]
Advanced

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

Changes to m4/src/Attic/m4.c,v [branch-1_4]


From: Eric Blake
Subject: Changes to m4/src/Attic/m4.c,v [branch-1_4]
Date: Thu, 07 Sep 2006 22:48:17 +0000

CVSROOT:        /sources/m4
Module name:    m4
Branch:         branch-1_4
Changes by:     Eric Blake <ericb>      06/09/07 22:48:15

Index: src/m4.c
===================================================================
RCS file: /sources/m4/m4/src/Attic/m4.c,v
retrieving revision 1.1.1.1.2.27
retrieving revision 1.1.1.1.2.28
diff -u -b -r1.1.1.1.2.27 -r1.1.1.1.2.28
--- src/m4.c    8 Aug 2006 23:17:44 -0000       1.1.1.1.2.27
+++ src/m4.c    7 Sep 2006 22:48:15 -0000       1.1.1.1.2.28
@@ -279,6 +279,7 @@
 
   macro_definition *defines;
   FILE *fp;
+  boolean read_stdin = FALSE;
 
   program_name = argv[0];
   retcode = EXIT_SUCCESS;
@@ -488,14 +489,24 @@
 
   if (optind == argc)
     {
-      push_file (stdin, "stdin");
+      /* No point closing stdin until after wrapped text is
+        processed.  */
+      push_file (stdin, "stdin", FALSE);
+      read_stdin = TRUE;
       expand_input ();
     }
   else
     for (; optind < argc; optind++)
       {
        if (strcmp (argv[optind], "-") == 0)
-         push_file (stdin, "stdin");
+         {
+           /* If stdin is a terminal, we want to allow 'm4 - file -'
+              to read input from stdin twice, like GNU cat.  Besides,
+              there is no point closing stdin before wrapped text, to
+              minimize bugs in syscmd called from wrapped text.  */
+           push_file (stdin, "stdin", FALSE);
+           read_stdin = TRUE;
+         }
        else
          {
            const char *name;
@@ -508,7 +519,7 @@
                retcode = EXIT_FAILURE;
                continue;
              }
-           push_file (fp, name);
+           push_file (fp, name, TRUE);
            free ((char *) name);
          }
        expand_input ();
@@ -520,9 +531,15 @@
   while (pop_wrapup ())
     expand_input ();
 
-  /* Change debug stream back to stderr, to force flushing debug stream and
-     detect any errors it might have encountered.  */
+  /* Change debug stream back to stderr, to force flushing the debug
+     stream and detect any errors it might have encountered.  Close
+     stdin if we read from it, to detect any errors.  */
   debug_set_output (NULL);
+  if (read_stdin && fclose (stdin) == EOF)
+    {
+      M4ERROR ((warning_status, errno, "error reading file"));
+      retcode = EXIT_FAILURE;
+    }
 
   if (frozen_file_to_write)
     produce_frozen_state (frozen_file_to_write);




reply via email to

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