m4-commit
[Top][All Lists]
Advanced

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

Changes to m4/src/main.c,v


From: Eric Blake
Subject: Changes to m4/src/main.c,v
Date: Wed, 20 Sep 2006 13:05:52 +0000

CVSROOT:        /sources/m4
Module name:    m4
Changes by:     Eric Blake <ericb>      06/09/20 13:05:51

Index: src/main.c
===================================================================
RCS file: /sources/m4/m4/src/main.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -b -r1.85 -r1.86
--- src/main.c  20 Sep 2006 04:04:29 -0000      1.85
+++ src/main.c  20 Sep 2006 13:05:51 -0000      1.86
@@ -69,7 +69,8 @@
       printf (_("Usage: %s [OPTION]... [FILE]...\n"), program_name);
       fputs (_("\
 Process macros in FILEs.\n\
-If no FILE or if FILE is `-', standard input is read.\n\
+If no FILE or if FILE is `-', standard input is read.  With no FILE and both\n\
+standard input and standard output are terminals, -e is implied.\n\
 "), stdout);
       fputs (_("\
 \n\
@@ -225,6 +226,14 @@
 
 #define OPTSTRING "B:D:EF:GH:I:L:M:N:PQR:S:T:U:bcd::el:m:o:r:st:"
 
+/* For determining whether to be interactive.  */
+enum interactive_choice
+{
+  INTERACTIVE_UNKNOWN, /* Still processing arguments, no -b or -e yet */
+  INTERACTIVE_YES,     /* -e specified last */
+  INTERACTIVE_NO       /* -b specified last */
+};
+
 int
 main (int argc, char *const *argv, char *const *envp)
 {
@@ -240,6 +249,7 @@
   bool import_environment = false; /* true to import environment */
   const char *frozen_file_to_read = NULL;
   const char *frozen_file_to_write = NULL;
+  enum interactive_choice interactive = INTERACTIVE_UNKNOWN;
 
   m4 *context;
 
@@ -263,9 +273,6 @@
   setup_stackovf_trap (argv, envp, stackovf_handler);
 #endif
 
-  if (isatty (STDIN_FILENO))
-    m4_set_interactive_opt (context, true);
-
   if (getenv ("POSIXLY_CORRECT"))
     m4_set_posixly_correct_opt (context, true);
 
@@ -389,7 +396,7 @@
        break;
 
       case 'b':
-       m4_set_interactive_opt (context, false);
+       interactive = INTERACTIVE_NO;
        break;
 
       case 'c':
@@ -410,7 +417,7 @@
        break;
 
       case 'e':
-       m4_set_interactive_opt (context, true);
+       interactive = INTERACTIVE_YES;
        break;
 
       case 'l':
@@ -457,6 +464,15 @@
        break;
       }
 
+  /* Interactive if specified, or if no input files and stdin and
+     stderr are terminals, to match sh behavior.  */
+
+  m4_set_interactive_opt (context, (interactive == INTERACTIVE_YES
+                                   || (interactive == INTERACTIVE_UNKNOWN
+                                       && optind == argc
+                                       && isatty (STDIN_FILENO)
+                                       && isatty (STDERR_FILENO))));
+
   /* Do the basic initializations.  */
 
   m4_input_init (context);




reply via email to

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