Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/m4 Fix --error-output to be more like GNU m4.



details:   https://anonhg.NetBSD.org/src/rev/920c00f5132b
branches:  trunk
changeset: 973244:920c00f5132b
user:      uwe <uwe%NetBSD.org@localhost>
date:      Thu Jun 25 02:25:53 2020 +0000

description:
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'.

diffstat:

 usr.bin/m4/extern.h |   4 ++--
 usr.bin/m4/main.c   |  37 ++++++++-----------------------------
 usr.bin/m4/trace.c  |  24 ++++++++++++++++++------
 3 files changed, 28 insertions(+), 37 deletions(-)

diffs (157 lines):

diff -r 0883f3888afc -r 920c00f5132b usr.bin/m4/extern.h
--- a/usr.bin/m4/extern.h       Wed Jun 24 22:28:07 2020 +0000
+++ b/usr.bin/m4/extern.h       Thu Jun 25 02:25:53 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.20 2020/06/25 02:25:53 uwe 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 0883f3888afc -r 920c00f5132b usr.bin/m4/main.c
--- a/usr.bin/m4/main.c Wed Jun 24 22:28:07 2020 +0000
+++ b/usr.bin/m4/main.c Thu Jun 25 02:25:53 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.49 2020/06/24 16:49:30 uwe Exp $    */
+/*     $NetBSD: main.c,v 1.50 2020/06/25 02:25:53 uwe Exp $    */
 
 /*-
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
 #include "nbtool_config.h"
 #endif
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: main.c,v 1.49 2020/06/24 16:49:30 uwe Exp $");
+__RCSID("$NetBSD: main.c,v 1.50 2020/06/25 02:25:53 uwe 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,29 +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));
-                       /*
-                        * XXX: try to avoid the trap set up by the
-                        * kludge above.  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 output.  This actually
-                        * happens on some hosts, breaking autoconf
-                        * tracing.
-                        */
-                       setvbuf(stderr, (char *)NULL, _IOLBF, 0);
-                       break;
                case 'F':
                        freeze = optarg;
 #ifndef REAL_FREEZE
@@ -310,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 0883f3888afc -r 920c00f5132b usr.bin/m4/trace.c
--- a/usr.bin/m4/trace.c        Wed Jun 24 22:28:07 2020 +0000
+++ b/usr.bin/m4/trace.c        Thu Jun 25 02:25:53 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.9 2020/06/25 02:25:53 uwe 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.9 2020/06/25 02:25:53 uwe 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