m4-patches
[Top][All Lists]
Advanced

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

Re: Interactive behaviour


From: Eric Blake
Subject: Re: Interactive behaviour
Date: Wed, 20 Sep 2006 06:56:26 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Stepan Kasal on 9/20/2006 5:21 AM:
> Hello,
>   current CVS version of m4 sets interactive mode iff the stdin is a
> tty.  I think it would be better to set interactive mode iff the
> stdin, the stdout, and the stderr are a tty.  (Something like the
> patch below.)

How about something like what POSIX requires of sh (where, of course, m4's
- -e takes the place of sh's -i)?

"If the -i option is present, or if there are no operands and the shell's
standard input and standard error are attached to a terminal, the shell is
considered to be interactive."

As far as I can see, the only reason --interactive is -e instead of -i is
due to command-line compatibility with SysV implementations such as
Solaris m4.  But should I add -i as a synonym for -e as a followon patch?

It didn't help that NEWS didn't mention when -b was added.  Fortunately,
CVS sleuthing isn't too hard, and I found it in version 1.10 of main.c in
Aug 2001, the same month as the mythical 1.4q release (and since I haven't
seen a 1.4q tarball, I just documented it for the upcoming 1.9b).

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

        Change the default of interactive sessions to match sh.
        * src/main.c (usage): Document this.
        (enum interactive_choice): New enum.
        (main): Use it to defer decision of interactive until after
        argument processing.
        * doc/m4.texinfo (Invoking m4): Document this.
        * NEWS: Likewise, plus add missing mention of -b.
        Reported by Stepan Kasal.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFETp584KuGfSFAYARAuUOAJ9fzLHgnSB67qeDhpuqlGuIOeGj3ACfUO9w
z/d5GK7yAxOcGdKS6HTsMvs=
=9ES4
-----END PGP SIGNATURE-----
Index: NEWS
===================================================================
RCS file: /sources/m4/m4/NEWS,v
retrieving revision 1.17
diff -u -p -r1.17 NEWS
--- NEWS        20 Sep 2006 04:04:29 -0000      1.17
+++ NEWS        20 Sep 2006 12:54:09 -0000
@@ -52,6 +52,12 @@ promoted to 2.0.
 * New `--safer' command-line option cripples the potentially unsafe
   macros `debugfile', `syscmd', `esyscmd', and `maketemp'.
 
+* New `-b'/`--batch' command line option to force non-interactive mode.
+  Also, in addition to `-e'/`--interactive' requesting interactive mode, m4
+  now follows the lead of sh, and automatically enters interactive mode
+  when there are no files specified, and when both standard input and
+  standard error are terminals.
+
 * New `m' flag to `-d'/`--debug' option or `debugmode' macro traces
   actions related to module loading and unloading.  Also, the `--debug'
   option now understands `-' and `+' modifiers, the way `debugmode' has
Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.48
diff -u -p -r1.48 m4.texinfo
--- doc/m4.texinfo      20 Sep 2006 04:04:29 -0000      1.48
+++ doc/m4.texinfo      20 Sep 2006 12:54:10 -0000
@@ -420,8 +420,9 @@ immediately exit @code{m4} without readi
 Makes this invocation of @code{m4} non-interactive.  This means that
 output will be buffered, and interrupts will halt execution.  If neither
 @option{-b} nor @option{-e} are specified, this is activated by default
-if standard input is not a terminal.  If both @option{-b} and
address@hidden are specified, only the last one takes effect.
+when any input files are specified, or when either standard input or
+standard error is not a terminal.  If both @option{-b} and @option{-e}
+are specified, only the last one takes effect.
 
 @item -c
 @itemx --discard-comments
@@ -437,8 +438,10 @@ issued, considering all of them to be fa
 Makes this invocation of @code{m4} interactive.  This means that all
 output will be unbuffered, and interrupts will be ignored.  If neither
 @option{-b} nor @option{-e} are specified, this is activated by default
-if standard input is a terminal.  If both @option{-b} and @option{-e}
-are specified, only the last one takes effect.
+when no input files are specified, and when both standard input and
+standard error are terminals (similar to the way that /bin/sh determines
+when to be interactive).  If both @option{-b} and @option{-e} are
+specified, only the last one takes effect.
 
 @item -P
 @itemx --prefix-builtins
Index: src/main.c
===================================================================
RCS file: /sources/m4/m4/src/main.c,v
retrieving revision 1.85
diff -u -p -r1.85 main.c
--- src/main.c  20 Sep 2006 04:04:29 -0000      1.85
+++ src/main.c  20 Sep 2006 12:54:10 -0000
@@ -69,7 +69,8 @@ usage (int status)
       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 @@ static const struct option long_options[
 
 #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 @@ main (int argc, char *const *argv, char 
   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 @@ main (int argc, char *const *argv, char 
   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 @@ main (int argc, char *const *argv, char 
        break;
 
       case 'b':
-       m4_set_interactive_opt (context, false);
+       interactive = INTERACTIVE_NO;
        break;
 
       case 'c':
@@ -410,7 +417,7 @@ main (int argc, char *const *argv, char 
        break;
 
       case 'e':
-       m4_set_interactive_opt (context, true);
+       interactive = INTERACTIVE_YES;
        break;
 
       case 'l':
@@ -457,6 +464,15 @@ main (int argc, char *const *argv, char 
        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]