Module Name: src
Committed By: uwe
Date: Thu Jun 25 02:25:53 UTC 2020
Modified Files:
src/usr.bin/m4: extern.h main.c trace.c
Log Message:
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'.
To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/m4/extern.h
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/m4/main.c
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/m4/trace.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/m4/extern.h
diff -u src/usr.bin/m4/extern.h:1.19 src/usr.bin/m4/extern.h:1.20
--- src/usr.bin/m4/extern.h:1.19 Sat Jan 16 18:30:57 2016
+++ src/usr.bin/m4/extern.h Thu Jun 25 02:25:53 2020
@@ -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 @@ extern char *endest;
/* 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 *);
Index: src/usr.bin/m4/main.c
diff -u src/usr.bin/m4/main.c:1.49 src/usr.bin/m4/main.c:1.50
--- src/usr.bin/m4/main.c:1.49 Wed Jun 24 16:49:30 2020
+++ src/usr.bin/m4/main.c Thu Jun 25 02:25:53 2020
@@ -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 @@ onintr(int signo)
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 @@ main(int argc, char *argv[])
{
int c;
int n;
+ int error;
char *p;
- FILE *sfp;
setprogname(argv[0]);
@@ -246,7 +246,7 @@ main(int argc, char *argv[])
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 @@ main(int argc, char *argv[])
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 @@ main(int argc, char *argv[])
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;
Index: src/usr.bin/m4/trace.c
diff -u src/usr.bin/m4/trace.c:1.8 src/usr.bin/m4/trace.c:1.9
--- src/usr.bin/m4/trace.c:1.8 Tue Mar 20 20:34:58 2012
+++ src/usr.bin/m4/trace.c Thu Jun 25 02:25:53 2020
@@ -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 @@ static int frame_level(void);
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