Source-Changes-HG archive

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

[src/netbsd-9]: src/usr.bin/m4 Pull up following revision(s) (requested by uw...



details:   https://anonhg.NetBSD.org/src/rev/e5ecd28d2347
branches:  netbsd-9
changeset: 963974:e5ecd28d2347
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Jul 07 10:40:46 2020 +0000

description:
Pull up following revision(s) (requested by uwe in ticket #981):

        usr.bin/m4/m4.1: revision 1.28
        usr.bin/m4/m4.1: revision 1.29
        usr.bin/m4/extern.h: revision 1.20
        usr.bin/m4/main.c: revision 1.49
        usr.bin/m4/m4.1: revision 1.30
        usr.bin/m4/trace.c: revision 1.9
        usr.bin/m4/main.c: revision 1.50

Try not to lose error output with --error-output.

Try to avoid the trap we set up ourselves while avoiding freopen(3).
When exit flushes and closes open streams it may close sfp first and
when it comes about to flush and close stderr, the descriptor is
already gone and we lose any buffered error output.  This actually
happens on some hosts, breaking --trace output used by autoconf.

Fix --error-output to be more like GNU m4.

GNU m4 --error-output is the same as -o despite the name.  It does NOT
affect warnings, error messages, and 'errprint' output so drop the
misguided bit of code that tried to freopen stderr without closing it
on failure.  Drop -e (which was our local invention) and make merge
--error-output with -o so that both set traceout.  Make trace_file()
preserve the old traceout on error and return error status so that the
caller can emit appropriate warning.

Do not yet support disabling tracing with an empty name, the rest of
the code is not ready, we don't do -o positionally and we don't have
`debugfile'.

Fix --error-output to be more like GNU m4.  It's a long version of -o.

Bump date for previous.

Use a date that is actually a real date.

diffstat:

 usr.bin/m4/extern.h |   4 ++--
 usr.bin/m4/m4.1     |   9 +++------
 usr.bin/m4/main.c   |  26 ++++++++------------------
 usr.bin/m4/trace.c  |  24 ++++++++++++++++++------
 4 files changed, 31 insertions(+), 32 deletions(-)

diffs (190 lines):

diff -r efb46f8da5bf -r e5ecd28d2347 usr.bin/m4/extern.h
--- a/usr.bin/m4/extern.h       Tue Jul 07 10:30:52 2020 +0000
+++ b/usr.bin/m4/extern.h       Tue Jul 07 10:40:46 2020 +0000
@@ -1,5 +1,5 @@
 /*     $OpenBSD: extern.h,v 1.49 2009/10/14 17:19:47 sthen Exp $       */
-/*     $NetBSD: extern.h,v 1.19 2016/01/16 18:30:57 christos Exp $     */
+/*     $NetBSD: extern.h,v 1.19.18.1 2020/07/07 10:40:46 martin Exp $  */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -146,7 +146,7 @@
 /* trace.c */
 extern unsigned int trace_flags;
 #define TRACE_ALL      512
-extern void trace_file(const char *);
+extern int trace_file(const char *);
 extern size_t trace(const char **, int, struct input_file *);
 extern void finish_trace(size_t);
 extern void set_trace_flags(const char *);
diff -r efb46f8da5bf -r e5ecd28d2347 usr.bin/m4/m4.1
--- a/usr.bin/m4/m4.1   Tue Jul 07 10:30:52 2020 +0000
+++ b/usr.bin/m4/m4.1   Tue Jul 07 10:40:46 2020 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: m4.1,v 1.27 2016/01/17 11:24:28 wiz Exp $
+.\"    $NetBSD: m4.1,v 1.27.18.1 2020/07/07 10:40:46 martin Exp $
 .\"    @(#) $OpenBSD: m4.1,v 1.56 2009/10/14 17:19:47 sthen Exp $
 .\"
 .\" Copyright (c) 1989, 1993
@@ -31,7 +31,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd January 16, 2015
+.Dd June 25, 2020
 .Dt M4 1
 .Os
 .Sh NAME
@@ -46,7 +46,6 @@
 .Sm on
 .Oc
 .Op Fl d Ar flags
-.Op Fl e Ar filename
 .Op Fl F Ar filename
 .Op Fl I Ar dirname
 .Op Fl L Ar number
@@ -138,8 +137,6 @@
 Warnings make
 .Nm
 exit.
-.It Fl e , Fl Fl error-output Ar filename
-Redirect error output to filename.
 .It Fl F , Fl Fl freeze-state Ar filename
 Save the input state to
 .Ar filename .
@@ -166,7 +163,7 @@
 .It Fl L , Fl Fl nesting-limit
 Set the nesting limit in macro expansions.
 This is unimplemented and unlimited.
-.It Fl o Ar filename
+.It Fl o , Fl Fl error-output Ar filename
 Send trace output to
 .Ar filename .
 .It Fl P , Fl Fl prefix-builtins
diff -r efb46f8da5bf -r e5ecd28d2347 usr.bin/m4/main.c
--- a/usr.bin/m4/main.c Tue Jul 07 10:30:52 2020 +0000
+++ b/usr.bin/m4/main.c Tue Jul 07 10:40:46 2020 +0000
@@ -1,5 +1,5 @@
 /*     $OpenBSD: main.c,v 1.77 2009/10/14 17:19:47 sthen Exp $ */
-/*     $NetBSD: main.c,v 1.48 2019/03/26 16:41:06 christos Exp $       */
+/*     $NetBSD: main.c,v 1.48.2.1 2020/07/07 10:40:46 martin Exp $     */
 
 /*-
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
 #include "nbtool_config.h"
 #endif
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: main.c,v 1.48 2019/03/26 16:41:06 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.48.2.1 2020/07/07 10:40:46 martin Exp $");
 #include <assert.h>
 #include <signal.h>
 #include <getopt.h>
@@ -196,7 +196,7 @@
 struct option longopts[] = {
        { "debug",              optional_argument,      0, 'd' },
        { "define",             required_argument,      0, 'D' },
-       { "error-output",       required_argument,      0, 'e' },
+       { "error-output",       required_argument,      0, 'o' }, /* sic */
        { "fatal-warnings",     no_argument,            0, 'E' },
        { "freeze-state",       required_argument,      0, 'F' },
        { "gnu",                no_argument,            0, 'g' },
@@ -227,8 +227,8 @@
 {
        int c;
        int n;
+       int error;
        char *p;
-       FILE *sfp;
 
        setprogname(argv[0]);
 
@@ -246,7 +246,7 @@
        outfile = NULL;
        resizedivs(MAXOUT);
 
-       while ((c = getopt_long(argc, argv, "D:d:e:EF:GgI:iL:o:PR:Qst:U:v",
+       while ((c = getopt_long(argc, argv, "D:d:EF:GgI:iL:o:PR:Qst:U:v",
            longopts, NULL)) != -1)
                switch(c) {
                case 'D':               /* define something..*/
@@ -263,18 +263,6 @@
                case 'E':
                        fatal_warnings++;
                        break;
-               case 'e':
-                       /*
-                        * Don't use freopen here because if it fails
-                        * we lose stderr, instead trash it.
-                        */
-                       if ((sfp = fopen(optarg, "w+")) == NULL) {
-                               warn("Can't redirect errors to `%s'", optarg);
-                               break;
-                       }
-                       fclose(stderr);
-                       memcpy(stderr, sfp, sizeof(*sfp));
-                       break;
                case 'F':
                        freeze = optarg;
 #ifndef REAL_FREEZE
@@ -299,7 +287,9 @@
                        nesting_limit = atoi(optarg);
                        break;
                case 'o':
-                       trace_file(optarg);
+                       error = trace_file(optarg);
+                       if (error)
+                               warn("%s", optarg);
                         break;
                case 'P':
                        prefix_builtins = 1;
diff -r efb46f8da5bf -r e5ecd28d2347 usr.bin/m4/trace.c
--- a/usr.bin/m4/trace.c        Tue Jul 07 10:30:52 2020 +0000
+++ b/usr.bin/m4/trace.c        Tue Jul 07 10:40:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trace.c,v 1.8 2012/03/20 20:34:58 matt Exp $   */
+/*     $NetBSD: trace.c,v 1.8.34.1 2020/07/07 10:40:46 martin Exp $    */
 /* $OpenBSD: trace.c,v 1.15 2006/03/24 08:03:44 espie Exp $ */
 /*
  * Copyright (c) 2001 Marc Espie.
@@ -28,7 +28,7 @@
 #include "nbtool_config.h"
 #endif
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: trace.c,v 1.8 2012/03/20 20:34:58 matt Exp $");
+__RCSID("$NetBSD: trace.c,v 1.8.34.1 2020/07/07 10:40:46 martin Exp $");
 
 #include <sys/types.h>
 #include <err.h>
@@ -59,15 +59,27 @@
 
 unsigned int trace_flags = TRACE_QUOTE | TRACE_EXPANSION;
 
-void
+int
 trace_file(const char *name)
 {
+       FILE *newfp;
+
+       if (name == NULL)
+               newfp = stderr;
+#if 0 /* not yet */
+       else if (*name == '\0')
+               newfp = NULL;
+#endif
+       else {
+               newfp = fopen(name, "a");
+               if (newfp == NULL)
+                       return -1;
+       }
 
        if (traceout && traceout != stderr)
                fclose(traceout);
-       traceout = fopen(name, "w");
-       if (!traceout)
-               err(1, "can't open %s", name);
+       traceout = newfp;
+       return 0;
 }
 
 static unsigned int



Home | Main Index | Thread Index | Old Index