m4-patches
[Top][All Lists]
Advanced

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

Re: branch-1_4 output flushing


From: Eric Blake
Subject: Re: branch-1_4 output flushing
Date: Tue, 7 Nov 2006 19:13:26 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Eric Blake writes on 2006-08-16 14:28:53 GMT (11 weeks ago):

> 
> $ echo '1errprint(2)3' | m4 2>&1
> 213
> 
> Yuck - we interleaved output to /dev/tty (although Solaris has the same 
bug).  
> It is much nicer to flush all pending stdout before printing to stderr (at 
> least, the gnulib error module thinks so), in case the two FILEs point to the 
> same underlying file:
> 
> $ echo '1errprint(2)3' | src/m4 2>&1
> 123

I have waited too long for porting this one-liner, so as penance I added a 
testcase on head and improved the documentation wording as part of the port.

branch:
2006-11-07  Eric Blake  <address@hidden>

        * doc/m4.texinfo (Esyscmd, Errprint): Minor touchups.

Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.1.1.1.2.97
diff -u -r1.1.1.1.2.97 m4.texinfo
--- doc/m4.texinfo      1 Nov 2006 13:44:53 -0000       1.1.1.1.2.97
+++ doc/m4.texinfo      7 Nov 2006 19:05:35 -0000
@@ -4670,7 +4670,7 @@
 @var{shell-command}.
 
 Prior to executing the command, @code{m4} flushes its buffers.
-The default standard input and error output of @var{shell-command} are
+The default standard input and standard error of @var{shell-command} are
 the same as those of @code{m4}.  The error output of @var{shell-command}
 is not a part of the expansion: it will appear along with the error
 output of @code{m4}.
@@ -4875,8 +4875,9 @@
 You can print error messages using @code{errprint}:
 
 @deffn Builtin errprint (@var{message}, @dots{})
-Prints @var{message} and the rest of the arguments on the
-standard error output, separated by spaces.
+Prints @var{message} and the rest of the arguments to standard error,
+separated by spaces.  Standard error is used, regardless of the
address@hidden option (@pxref{Debugging options, , Invoking m4}).
 
 The expansion of @code{errprint} is void.
 The macro @code{errprint} is recognized only with parameters.
@@ -4887,13 +4888,20 @@
 ')
 @error{}Invalid arguments to forloop
 @result{}
+errprint(`1')errprint(`2',`3
+')
address@hidden 3
address@hidden
 @end example
 
-A trailing newline is @emph{not} printed automatically, so it must be
-supplied as part of the argument, as in the example.  BSD
-implementations of @code{m4} do append a trailing newline on each
address@hidden call, while some other implementations only print the
-first argument.
+A trailing newline is @emph{not} printed automatically, so it should be
+supplied as part of the argument, as in the example.  Unfortunately, the
+exact output of @code{errprint} is not very portable to other @code{m4}
+implementations: @acronym{POSIX} requires that all arguments be printed,
+but some implementations of @code{m4} only print the first.
+Furthermore, some BSD implementations always append a newline for each
address@hidden call, regardless of whether the last argument already
+had one, and @acronym{POSIX} is silent on whether this is acceptable.
 
 @node Location
 @section Printing current location



head:
2006-11-07  Eric Blake  <address@hidden>

        * doc/m4.texinfo (Errprint): Merge another doc node.
        * tests/builtins.at (dumpdef, errprint): New tests.
        * modules/m4.c (errprint): Merge from branch: flush before
        printing to stderr.

Index: doc/m4.texinfo
===================================================================
RCS file: /sources/m4/m4/doc/m4.texinfo,v
retrieving revision 1.75
diff -u -r1.75 m4.texinfo
--- doc/m4.texinfo      31 Oct 2006 14:14:18 -0000      1.75
+++ doc/m4.texinfo      7 Nov 2006 19:05:51 -0000
@@ -5610,13 +5610,15 @@
 @cindex printing error messages
 @cindex error messages, printing
 @cindex messages, printing error
+You can print error messages using @code{errprint}:
+
 @deffn {Builtin (m4)} errprint (@var{message}, @dots{})
-You can print error messages using @code{errprint}, which simply prints
address@hidden and the rest of the arguments on standard error,
-independently of the @option{--debugfile} option (@pxref{Debugging
-options, , Invoking m4}).
+Prints @var{message} and the rest of the arguments to standard error,
+separated by spaces.  Standard error is used, regardless of the
address@hidden option (@pxref{Debugging options, , Invoking m4}).
 
 The expansion of @code{errprint} is void.
+The macro @code{errprint} is recognized only with parameters.
 @end deffn
 
 @example
@@ -5624,11 +5626,20 @@
 ')
 @error{}Illegal arguments to forloop
 @result{}
+errprint(`1')errprint(`2',`3
+')
address@hidden 3
address@hidden
 @end example
 
-A trailing newline is @emph{not} printed automatically, so it must be
-supplied as part of the argument, as in the example.  (BSD flavored
address@hidden's do append a trailing newline on each @code{errprint} call).
+A trailing newline is @emph{not} printed automatically, so it should be
+supplied as part of the argument, as in the example.  Unfortunately, the
+exact output of @code{errprint} is not very portable to other @code{m4}
+implementations: @acronym{POSIX} requires that all arguments be printed,
+but some implementations of @code{m4} only print the first.
+Furthermore, some BSD implementations always append a newline for each
address@hidden call, regardless of whether the last argument already
+had one, and @acronym{POSIX} is silent on whether this is acceptable.
 
 @node Location
 @section Printing current location
Index: modules/m4.c
===================================================================
RCS file: /sources/m4/m4/modules/m4.c,v
retrieving revision 1.90
diff -u -r1.90 m4.c
--- modules/m4.c        31 Oct 2006 14:14:18 -0000      1.90
+++ modules/m4.c        7 Nov 2006 19:05:51 -0000
@@ -557,7 +557,7 @@
   m4_make_diversion (context, i);
 }
 
-/* Expand to the current diversion number, -1 if none.  */
+/* Expand to the current diversion number.  */
 M4BUILTIN_HANDLER (divnum)
 {
   m4_shipout_int (obs, m4_get_current_diversion (context));
@@ -779,6 +779,7 @@
   assert (obstack_object_size (obs) == 0);
   m4_dump_args (context, obs, argc, argv, " ", false);
   obstack_1grow (obs, '\0');
+  m4_sysval_flush (context);
   fputs ((char *) obstack_finish (obs), stderr);
   fflush (stderr);
 }
Index: tests/builtins.at
===================================================================
RCS file: /sources/m4/m4/tests/builtins.at,v
retrieving revision 1.30
diff -u -r1.30 builtins.at
--- tests/builtins.at   31 Oct 2006 14:14:18 -0000      1.30
+++ tests/builtins.at   7 Nov 2006 19:05:51 -0000
@@ -205,6 +205,47 @@
 
 
 ## ------- ##
+## dumpdef ##
+## ------- ##
+
+AT_SETUP([dumpdef])
+
+dnl Make sure that stderr and stdout are properly interleaved when directed
+dnl to the same file.
+AT_DATA([in], [[1dumpdef(`defn')3
+]])
+AT_CHECK_M4([in], [0], [[13
+]], [[defn:    <defn>
+]])
+AT_CHECK_M4([in 2>&1], [0], [[1defn:   <defn>
+3
+]])
+
+AT_CLEANUP
+
+
+## -------- ##
+## errprint ##
+## -------- ##
+
+AT_SETUP([errprint])
+
+dnl Make sure that stderr and stdout are properly interleaved when directed
+dnl to the same file.
+AT_DATA([in], [[1errprint(`2')3errprint(`
+')
+]])
+AT_CHECK_M4([in], [0], [[13
+]], [[2
+]])
+AT_CHECK_M4([in 2>&1], [0], [[123
+
+]])
+
+AT_CLEANUP
+
+
+## ------- ##
 ## esyscmd ##
 ## ------- ##
 







reply via email to

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