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.diff -r1.19 -r1.19.18.1 src/usr.bin/m4/extern.h
(martin)
--- src/usr.bin/m4/extern.h 2016/01/16 18:30:57 1.19
+++ src/usr.bin/m4/extern.h 2020/07/07 10:40:46 1.19.18.1
@@ -1,15 +1,15 @@ | @@ -1,15 +1,15 @@ | |||
1 | /* $OpenBSD: extern.h,v 1.49 2009/10/14 17:19:47 sthen Exp $ */ | 1 | /* $OpenBSD: extern.h,v 1.49 2009/10/14 17:19:47 sthen Exp $ */ | |
2 | /* $NetBSD: extern.h,v 1.19 2016/01/16 18:30:57 christos Exp $ */ | 2 | /* $NetBSD: extern.h,v 1.19.18.1 2020/07/07 10:40:46 martin Exp $ */ | |
3 | 3 | |||
4 | /*- | 4 | /*- | |
5 | * Copyright (c) 1991, 1993 | 5 | * Copyright (c) 1991, 1993 | |
6 | * The Regents of the University of California. All rights reserved. | 6 | * The Regents of the University of California. All rights reserved. | |
7 | * | 7 | * | |
8 | * This code is derived from software contributed to Berkeley by | 8 | * This code is derived from software contributed to Berkeley by | |
9 | * Ozan Yigit at York University. | 9 | * Ozan Yigit at York University. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions and the following disclaimer. | 15 | * notice, this list of conditions and the following disclaimer. | |
@@ -136,27 +136,27 @@ extern void release_input(struct input_f | @@ -136,27 +136,27 @@ extern void release_input(struct input_f | |||
136 | enlarge_strspace(); \ | 136 | enlarge_strspace(); \ | |
137 | *ep++ = (c); \ | 137 | *ep++ = (c); \ | |
138 | } while(0) | 138 | } while(0) | |
139 | 139 | |||
140 | /* and corresponding exposure for local symbols */ | 140 | /* and corresponding exposure for local symbols */ | |
141 | extern void enlarge_bufspace(void); | 141 | extern void enlarge_bufspace(void); | |
142 | extern void enlarge_strspace(void); | 142 | extern void enlarge_strspace(void); | |
143 | extern unsigned char *endpbb; | 143 | extern unsigned char *endpbb; | |
144 | extern char *endest; | 144 | extern char *endest; | |
145 | 145 | |||
146 | /* trace.c */ | 146 | /* trace.c */ | |
147 | extern unsigned int trace_flags; | 147 | extern unsigned int trace_flags; | |
148 | #define TRACE_ALL 512 | 148 | #define TRACE_ALL 512 | |
149 | extern void trace_file(const char *); | 149 | extern int trace_file(const char *); | |
150 | extern size_t trace(const char **, int, struct input_file *); | 150 | extern size_t trace(const char **, int, struct input_file *); | |
151 | extern void finish_trace(size_t); | 151 | extern void finish_trace(size_t); | |
152 | extern void set_trace_flags(const char *); | 152 | extern void set_trace_flags(const char *); | |
153 | extern FILE *traceout; | 153 | extern FILE *traceout; | |
154 | 154 | |||
155 | extern ndptr hashtab[]; /* hash table for macros etc. */ | 155 | extern ndptr hashtab[]; /* hash table for macros etc. */ | |
156 | extern stae *mstack; /* stack of m4 machine */ | 156 | extern stae *mstack; /* stack of m4 machine */ | |
157 | extern char *sstack; /* shadow stack, for string space extension */ | 157 | extern char *sstack; /* shadow stack, for string space extension */ | |
158 | extern FILE *active; /* active output file pointer */ | 158 | extern FILE *active; /* active output file pointer */ | |
159 | extern struct input_file infile[];/* input file stack (0=stdin) */ | 159 | extern struct input_file infile[];/* input file stack (0=stdin) */ | |
160 | extern FILE **outfile; /* diversion array(0=bitbucket) */ | 160 | extern FILE **outfile; /* diversion array(0=bitbucket) */ | |
161 | extern int maxout; /* maximum number of diversions */ | 161 | extern int maxout; /* maximum number of diversions */ | |
162 | extern int fp; /* m4 call frame pointer */ | 162 | extern int fp; /* m4 call frame pointer */ |
--- src/usr.bin/m4/m4.1 2016/01/17 11:24:28 1.27
+++ src/usr.bin/m4/m4.1 2020/07/07 10:40:46 1.27.18.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | .\" $NetBSD: m4.1,v 1.27 2016/01/17 11:24:28 wiz Exp $ | 1 | .\" $NetBSD: m4.1,v 1.27.18.1 2020/07/07 10:40:46 martin Exp $ | |
2 | .\" @(#) $OpenBSD: m4.1,v 1.56 2009/10/14 17:19:47 sthen Exp $ | 2 | .\" @(#) $OpenBSD: m4.1,v 1.56 2009/10/14 17:19:47 sthen Exp $ | |
3 | .\" | 3 | .\" | |
4 | .\" Copyright (c) 1989, 1993 | 4 | .\" Copyright (c) 1989, 1993 | |
5 | .\" The Regents of the University of California. All rights reserved. | 5 | .\" The Regents of the University of California. All rights reserved. | |
6 | .\" | 6 | .\" | |
7 | .\" This code is derived from software contributed to Berkeley by | 7 | .\" This code is derived from software contributed to Berkeley by | |
8 | .\" Ozan Yigit at York University. | 8 | .\" Ozan Yigit at York University. | |
9 | .\" | 9 | .\" | |
10 | .\" Redistribution and use in source and binary forms, with or without | 10 | .\" Redistribution and use in source and binary forms, with or without | |
11 | .\" modification, are permitted provided that the following conditions | 11 | .\" modification, are permitted provided that the following conditions | |
12 | .\" are met: | 12 | .\" are met: | |
13 | .\" 1. Redistributions of source code must retain the above copyright | 13 | .\" 1. Redistributions of source code must retain the above copyright | |
14 | .\" notice, this list of conditions and the following disclaimer. | 14 | .\" notice, this list of conditions and the following disclaimer. | |
@@ -21,42 +21,41 @@ | @@ -21,42 +21,41 @@ | |||
21 | .\" | 21 | .\" | |
22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 22 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 23 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 24 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 25 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 26 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 27 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 28 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 29 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 30 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. | |
33 | .\" | 33 | .\" | |
34 | .Dd January 16, 2015 | 34 | .Dd June 25, 2020 | |
35 | .Dt M4 1 | 35 | .Dt M4 1 | |
36 | .Os | 36 | .Os | |
37 | .Sh NAME | 37 | .Sh NAME | |
38 | .Nm m4 | 38 | .Nm m4 | |
39 | .Nd macro language processor | 39 | .Nd macro language processor | |
40 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS | |
41 | .Nm m4 | 41 | .Nm m4 | |
42 | .Op Fl EGgiPQsv | 42 | .Op Fl EGgiPQsv | |
43 | .Oo | 43 | .Oo | |
44 | .Sm off | 44 | .Sm off | |
45 | .Fl D Ar name Op No = Ar value | 45 | .Fl D Ar name Op No = Ar value | |
46 | .Sm on | 46 | .Sm on | |
47 | .Oc | 47 | .Oc | |
48 | .Op Fl d Ar flags | 48 | .Op Fl d Ar flags | |
49 | .Op Fl e Ar filename | |||
50 | .Op Fl F Ar filename | 49 | .Op Fl F Ar filename | |
51 | .Op Fl I Ar dirname | 50 | .Op Fl I Ar dirname | |
52 | .Op Fl L Ar number | 51 | .Op Fl L Ar number | |
53 | .Op Fl o Ar filename | 52 | .Op Fl o Ar filename | |
54 | .Op Fl R Ar filename | 53 | .Op Fl R Ar filename | |
55 | .Op Fl t Ar macro | 54 | .Op Fl t Ar macro | |
56 | .Op Fl U Ns Ar name | 55 | .Op Fl U Ns Ar name | |
57 | .Op Ar | 56 | .Op Ar | |
58 | .Sh DESCRIPTION | 57 | .Sh DESCRIPTION | |
59 | The | 58 | The | |
60 | .Nm m4 | 59 | .Nm m4 | |
61 | utility is a macro processor that can be used as a front end to any | 60 | utility is a macro processor that can be used as a front end to any | |
62 | language (e.g., C, ratfor, fortran, lex, and yacc). | 61 | language (e.g., C, ratfor, fortran, lex, and yacc). | |
@@ -128,55 +127,53 @@ quote arguments and expansion with the c | @@ -128,55 +127,53 @@ quote arguments and expansion with the c | |||
128 | start with all macros traced. | 127 | start with all macros traced. | |
129 | .It Ar x | 128 | .It Ar x | |
130 | number macro expansions. | 129 | number macro expansions. | |
131 | .It Ar V | 130 | .It Ar V | |
132 | turn on all options. | 131 | turn on all options. | |
133 | .El | 132 | .El | |
134 | .Pp | 133 | .Pp | |
135 | By default, trace is set to | 134 | By default, trace is set to | |
136 | .Qq eq . | 135 | .Qq eq . | |
137 | .It Fl E , Fl Fl fatal-warnings | 136 | .It Fl E , Fl Fl fatal-warnings | |
138 | Warnings make | 137 | Warnings make | |
139 | .Nm | 138 | .Nm | |
140 | exit. | 139 | exit. | |
141 | .It Fl e , Fl Fl error-output Ar filename | |||
142 | Redirect error output to filename. | |||
143 | .It Fl F , Fl Fl freeze-state Ar filename | 140 | .It Fl F , Fl Fl freeze-state Ar filename | |
144 | Save the input state to | 141 | Save the input state to | |
145 | .Ar filename . | 142 | .Ar filename . | |
146 | .It Fl G , Fl Fl traditional | 143 | .It Fl G , Fl Fl traditional | |
147 | Disable GNU-m4 extensions. | 144 | Disable GNU-m4 extensions. | |
148 | .It Fl g , Fl Fl gnu | 145 | .It Fl g , Fl Fl gnu | |
149 | Activate GNU-m4 compatibility mode. | 146 | Activate GNU-m4 compatibility mode. | |
150 | In this mode, translit handles simple character | 147 | In this mode, translit handles simple character | |
151 | ranges (e.g., a-z), regular expressions mimic emacs behavior, | 148 | ranges (e.g., a-z), regular expressions mimic emacs behavior, | |
152 | multiple m4wrap calls are handled as a stack, | 149 | multiple m4wrap calls are handled as a stack, | |
153 | the number of diversions is unlimited, | 150 | the number of diversions is unlimited, | |
154 | empty names for macro definitions are allowed, | 151 | empty names for macro definitions are allowed, | |
155 | and eval understands | 152 | and eval understands | |
156 | .Sq 0rbase:value | 153 | .Sq 0rbase:value | |
157 | numbers. | 154 | numbers. | |
158 | .It Fl Fl help | 155 | .It Fl Fl help | |
159 | Print help message and exit. | 156 | Print help message and exit. | |
160 | .It Fl I , Fl Fl include Ar "dirname" | 157 | .It Fl I , Fl Fl include Ar "dirname" | |
161 | Add directory | 158 | Add directory | |
162 | .Ar dirname | 159 | .Ar dirname | |
163 | to the include path. | 160 | to the include path. | |
164 | .It Fl i , Fl Fl interactive | 161 | .It Fl i , Fl Fl interactive | |
165 | Set unbuffered output, disable tty signals. | 162 | Set unbuffered output, disable tty signals. | |
166 | .It Fl L , Fl Fl nesting-limit | 163 | .It Fl L , Fl Fl nesting-limit | |
167 | Set the nesting limit in macro expansions. | 164 | Set the nesting limit in macro expansions. | |
168 | This is unimplemented and unlimited. | 165 | This is unimplemented and unlimited. | |
169 | .It Fl o Ar filename | 166 | .It Fl o , Fl Fl error-output Ar filename | |
170 | Send trace output to | 167 | Send trace output to | |
171 | .Ar filename . | 168 | .Ar filename . | |
172 | .It Fl P , Fl Fl prefix-builtins | 169 | .It Fl P , Fl Fl prefix-builtins | |
173 | Prefix all built-in macros with | 170 | Prefix all built-in macros with | |
174 | .Sq m4_ . | 171 | .Sq m4_ . | |
175 | For example, instead of writing | 172 | For example, instead of writing | |
176 | .Ic define , | 173 | .Ic define , | |
177 | use | 174 | use | |
178 | .Ic m4_define . | 175 | .Ic m4_define . | |
179 | .It Fl Q , Fl Fl quiet , Fl Fl silent | 176 | .It Fl Q , Fl Fl quiet , Fl Fl silent | |
180 | Don't print warnings. | 177 | Don't print warnings. | |
181 | .It Fl R , Fl Fl reload-state Ar filename | 178 | .It Fl R , Fl Fl reload-state Ar filename | |
182 | Reload a previously saved state from | 179 | Reload a previously saved state from |
--- src/usr.bin/m4/main.c 2019/03/26 16:41:06 1.48
+++ src/usr.bin/m4/main.c 2020/07/07 10:40:46 1.48.2.1
@@ -1,15 +1,15 @@ | @@ -1,15 +1,15 @@ | |||
1 | /* $OpenBSD: main.c,v 1.77 2009/10/14 17:19:47 sthen Exp $ */ | 1 | /* $OpenBSD: main.c,v 1.77 2009/10/14 17:19:47 sthen Exp $ */ | |
2 | /* $NetBSD: main.c,v 1.48 2019/03/26 16:41:06 christos Exp $ */ | 2 | /* $NetBSD: main.c,v 1.48.2.1 2020/07/07 10:40:46 martin Exp $ */ | |
3 | 3 | |||
4 | /*- | 4 | /*- | |
5 | * Copyright (c) 1989, 1993 | 5 | * Copyright (c) 1989, 1993 | |
6 | * The Regents of the University of California. All rights reserved. | 6 | * The Regents of the University of California. All rights reserved. | |
7 | * | 7 | * | |
8 | * This code is derived from software contributed to Berkeley by | 8 | * This code is derived from software contributed to Berkeley by | |
9 | * Ozan Yigit at York University. | 9 | * Ozan Yigit at York University. | |
10 | * | 10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | 11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | 12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | 13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | 14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions and the following disclaimer. | 15 | * notice, this list of conditions and the following disclaimer. | |
@@ -32,27 +32,27 @@ | @@ -32,27 +32,27 @@ | |||
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
33 | * SUCH DAMAGE. | 33 | * SUCH DAMAGE. | |
34 | */ | 34 | */ | |
35 | 35 | |||
36 | /* | 36 | /* | |
37 | * main.c | 37 | * main.c | |
38 | * Facility: m4 macro processor | 38 | * Facility: m4 macro processor | |
39 | * by: oz | 39 | * by: oz | |
40 | */ | 40 | */ | |
41 | #if HAVE_NBTOOL_CONFIG_H | 41 | #if HAVE_NBTOOL_CONFIG_H | |
42 | #include "nbtool_config.h" | 42 | #include "nbtool_config.h" | |
43 | #endif | 43 | #endif | |
44 | #include <sys/cdefs.h> | 44 | #include <sys/cdefs.h> | |
45 | __RCSID("$NetBSD: main.c,v 1.48 2019/03/26 16:41:06 christos Exp $"); | 45 | __RCSID("$NetBSD: main.c,v 1.48.2.1 2020/07/07 10:40:46 martin Exp $"); | |
46 | #include <assert.h> | 46 | #include <assert.h> | |
47 | #include <signal.h> | 47 | #include <signal.h> | |
48 | #include <getopt.h> | 48 | #include <getopt.h> | |
49 | #include <err.h> | 49 | #include <err.h> | |
50 | #include <errno.h> | 50 | #include <errno.h> | |
51 | #include <unistd.h> | 51 | #include <unistd.h> | |
52 | #include <stdio.h> | 52 | #include <stdio.h> | |
53 | #include <ctype.h> | 53 | #include <ctype.h> | |
54 | #include <string.h> | 54 | #include <string.h> | |
55 | #include <stddef.h> | 55 | #include <stddef.h> | |
56 | #include <stdint.h> | 56 | #include <stdint.h> | |
57 | #include <stdlib.h> | 57 | #include <stdlib.h> | |
58 | #include <ohash.h> | 58 | #include <ohash.h> | |
@@ -186,27 +186,27 @@ usage(FILE *f) | @@ -186,27 +186,27 @@ usage(FILE *f) | |||
186 | __dead static void | 186 | __dead static void | |
187 | onintr(int signo) | 187 | onintr(int signo) | |
188 | { | 188 | { | |
189 | char intrmessage[] = "m4: interrupted.\n"; | 189 | char intrmessage[] = "m4: interrupted.\n"; | |
190 | write(STDERR_FILENO, intrmessage, sizeof(intrmessage)-1); | 190 | write(STDERR_FILENO, intrmessage, sizeof(intrmessage)-1); | |
191 | _exit(1); | 191 | _exit(1); | |
192 | } | 192 | } | |
193 | 193 | |||
194 | #define OPT_HELP 1 | 194 | #define OPT_HELP 1 | |
195 | 195 | |||
196 | struct option longopts[] = { | 196 | struct option longopts[] = { | |
197 | { "debug", optional_argument, 0, 'd' }, | 197 | { "debug", optional_argument, 0, 'd' }, | |
198 | { "define", required_argument, 0, 'D' }, | 198 | { "define", required_argument, 0, 'D' }, | |
199 | { "error-output", required_argument, 0, 'e' }, | 199 | { "error-output", required_argument, 0, 'o' }, /* sic */ | |
200 | { "fatal-warnings", no_argument, 0, 'E' }, | 200 | { "fatal-warnings", no_argument, 0, 'E' }, | |
201 | { "freeze-state", required_argument, 0, 'F' }, | 201 | { "freeze-state", required_argument, 0, 'F' }, | |
202 | { "gnu", no_argument, 0, 'g' }, | 202 | { "gnu", no_argument, 0, 'g' }, | |
203 | { "help", no_argument, 0, OPT_HELP }, | 203 | { "help", no_argument, 0, OPT_HELP }, | |
204 | { "include", required_argument, 0, 'I' }, | 204 | { "include", required_argument, 0, 'I' }, | |
205 | { "interactive", no_argument, 0, 'i' }, | 205 | { "interactive", no_argument, 0, 'i' }, | |
206 | { "nesting-limit", required_argument, 0, 'L' }, | 206 | { "nesting-limit", required_argument, 0, 'L' }, | |
207 | { "prefix-builtins", no_argument, 0, 'P' }, | 207 | { "prefix-builtins", no_argument, 0, 'P' }, | |
208 | { "quiet", no_argument, 0, 'Q' }, | 208 | { "quiet", no_argument, 0, 'Q' }, | |
209 | { "reload-state", required_argument, 0, 'R' }, | 209 | { "reload-state", required_argument, 0, 'R' }, | |
210 | { "silent", no_argument, 0, 'Q' }, | 210 | { "silent", no_argument, 0, 'Q' }, | |
211 | { "synclines", no_argument, 0, 's' }, | 211 | { "synclines", no_argument, 0, 's' }, | |
212 | { "trace", required_argument, 0, 't' }, | 212 | { "trace", required_argument, 0, 't' }, | |
@@ -217,99 +217,89 @@ struct option longopts[] = { | @@ -217,99 +217,89 @@ struct option longopts[] = { | |||
217 | { "arglength", required_argument, 0, 'l' }, | 217 | { "arglength", required_argument, 0, 'l' }, | |
218 | { "debugfile", optional_argument, 0, OPT_DEBUGFILE }, | 218 | { "debugfile", optional_argument, 0, OPT_DEBUGFILE }, | |
219 | { "hashsize", required_argument, 0, 'H' }, | 219 | { "hashsize", required_argument, 0, 'H' }, | |
220 | { "warn-macro-sequence",optional_argument, 0, OPT_WARN_SEQUENCE }, | 220 | { "warn-macro-sequence",optional_argument, 0, OPT_WARN_SEQUENCE }, | |
221 | #endif | 221 | #endif | |
222 | { 0, 0, 0, 0 }, | 222 | { 0, 0, 0, 0 }, | |
223 | }; | 223 | }; | |
224 | 224 | |||
225 | int | 225 | int | |
226 | main(int argc, char *argv[]) | 226 | main(int argc, char *argv[]) | |
227 | { | 227 | { | |
228 | int c; | 228 | int c; | |
229 | int n; | 229 | int n; | |
230 | int error; | |||
230 | char *p; | 231 | char *p; | |
231 | FILE *sfp; | |||
232 | 232 | |||
233 | setprogname(argv[0]); | 233 | setprogname(argv[0]); | |
234 | 234 | |||
235 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) | 235 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) | |
236 | signal(SIGINT, onintr); | 236 | signal(SIGINT, onintr); | |
237 | 237 | |||
238 | init_macros(); | 238 | init_macros(); | |
239 | initspaces(); | 239 | initspaces(); | |
240 | STACKMAX = INITSTACKMAX; | 240 | STACKMAX = INITSTACKMAX; | |
241 | 241 | |||
242 | mstack = (stae *)xalloc(sizeof(stae) * STACKMAX, NULL); | 242 | mstack = (stae *)xalloc(sizeof(stae) * STACKMAX, NULL); | |
243 | sstack = (char *)xalloc(STACKMAX, NULL); | 243 | sstack = (char *)xalloc(STACKMAX, NULL); | |
244 | 244 | |||
245 | maxout = 0; | 245 | maxout = 0; | |
246 | outfile = NULL; | 246 | outfile = NULL; | |
247 | resizedivs(MAXOUT); | 247 | resizedivs(MAXOUT); | |
248 | 248 | |||
249 | while ((c = getopt_long(argc, argv, "D:d:e:EF:GgI:iL:o:PR:Qst:U:v", | 249 | while ((c = getopt_long(argc, argv, "D:d:EF:GgI:iL:o:PR:Qst:U:v", | |
250 | longopts, NULL)) != -1) | 250 | longopts, NULL)) != -1) | |
251 | switch(c) { | 251 | switch(c) { | |
252 | case 'D': /* define something..*/ | 252 | case 'D': /* define something..*/ | |
253 | for (p = optarg; *p; p++) | 253 | for (p = optarg; *p; p++) | |
254 | if (*p == '=') | 254 | if (*p == '=') | |
255 | break; | 255 | break; | |
256 | if (*p) | 256 | if (*p) | |
257 | *p++ = EOS; | 257 | *p++ = EOS; | |
258 | dodefine(optarg, p); | 258 | dodefine(optarg, p); | |
259 | break; | 259 | break; | |
260 | case 'd': | 260 | case 'd': | |
261 | set_trace_flags(optarg); | 261 | set_trace_flags(optarg); | |
262 | break; | 262 | break; | |
263 | case 'E': | 263 | case 'E': | |
264 | fatal_warnings++; | 264 | fatal_warnings++; | |
265 | break; | 265 | break; | |
266 | case 'e': | |||
267 | /* | |||
268 | * Don't use freopen here because if it fails | |||
269 | * we lose stderr, instead trash it. | |||
270 | */ | |||
271 | if ((sfp = fopen(optarg, "w+")) == NULL) { | |||
272 | warn("Can't redirect errors to `%s'", optarg); | |||
273 | break; | |||
274 | } | |||
275 | fclose(stderr); | |||
276 | memcpy(stderr, sfp, sizeof(*sfp)); | |||
277 | break; | |||
278 | case 'F': | 266 | case 'F': | |
279 | freeze = optarg; | 267 | freeze = optarg; | |
280 | #ifndef REAL_FREEZE | 268 | #ifndef REAL_FREEZE | |
281 | if ((freezef = fopen(freeze, "w")) == NULL) | 269 | if ((freezef = fopen(freeze, "w")) == NULL) | |
282 | err(EXIT_FAILURE, "Can't open `%s'", freeze); | 270 | err(EXIT_FAILURE, "Can't open `%s'", freeze); | |
283 | #endif | 271 | #endif | |
284 | break; | 272 | break; | |
285 | case 'I': | 273 | case 'I': | |
286 | addtoincludepath(optarg); | 274 | addtoincludepath(optarg); | |
287 | break; | 275 | break; | |
288 | case 'i': | 276 | case 'i': | |
289 | setvbuf(stdout, NULL, _IONBF, 0); | 277 | setvbuf(stdout, NULL, _IONBF, 0); | |
290 | signal(SIGINT, SIG_IGN); | 278 | signal(SIGINT, SIG_IGN); | |
291 | break; | 279 | break; | |
292 | case 'G': | 280 | case 'G': | |
293 | mimic_gnu = 0; | 281 | mimic_gnu = 0; | |
294 | break; | 282 | break; | |
295 | case 'g': | 283 | case 'g': | |
296 | mimic_gnu = 1; | 284 | mimic_gnu = 1; | |
297 | break; | 285 | break; | |
298 | case 'L': | 286 | case 'L': | |
299 | nesting_limit = atoi(optarg); | 287 | nesting_limit = atoi(optarg); | |
300 | break; | 288 | break; | |
301 | case 'o': | 289 | case 'o': | |
302 | trace_file(optarg); | 290 | error = trace_file(optarg); | |
291 | if (error) | |||
292 | warn("%s", optarg); | |||
303 | break; | 293 | break; | |
304 | case 'P': | 294 | case 'P': | |
305 | prefix_builtins = 1; | 295 | prefix_builtins = 1; | |
306 | break; | 296 | break; | |
307 | case 'Q': | 297 | case 'Q': | |
308 | quiet++; | 298 | quiet++; | |
309 | break; | 299 | break; | |
310 | case 'R': | 300 | case 'R': | |
311 | reload = optarg; | 301 | reload = optarg; | |
312 | break; | 302 | break; | |
313 | case 's': | 303 | case 's': | |
314 | synch_lines = 1; | 304 | synch_lines = 1; | |
315 | break; | 305 | break; |
--- src/usr.bin/m4/trace.c 2012/03/20 20:34:58 1.8
+++ src/usr.bin/m4/trace.c 2020/07/07 10:40:46 1.8.34.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: trace.c,v 1.8 2012/03/20 20:34:58 matt Exp $ */ | 1 | /* $NetBSD: trace.c,v 1.8.34.1 2020/07/07 10:40:46 martin Exp $ */ | |
2 | /* $OpenBSD: trace.c,v 1.15 2006/03/24 08:03:44 espie Exp $ */ | 2 | /* $OpenBSD: trace.c,v 1.15 2006/03/24 08:03:44 espie Exp $ */ | |
3 | /* | 3 | /* | |
4 | * Copyright (c) 2001 Marc Espie. | 4 | * Copyright (c) 2001 Marc Espie. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * | 14 | * | |
@@ -18,27 +18,27 @@ | @@ -18,27 +18,27 @@ | |||
18 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD | 18 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD | |
19 | * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 | * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
21 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 21 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 | */ | 26 | */ | |
27 | #if HAVE_NBTOOL_CONFIG_H | 27 | #if HAVE_NBTOOL_CONFIG_H | |
28 | #include "nbtool_config.h" | 28 | #include "nbtool_config.h" | |
29 | #endif | 29 | #endif | |
30 | #include <sys/cdefs.h> | 30 | #include <sys/cdefs.h> | |
31 | __RCSID("$NetBSD: trace.c,v 1.8 2012/03/20 20:34:58 matt Exp $"); | 31 | __RCSID("$NetBSD: trace.c,v 1.8.34.1 2020/07/07 10:40:46 martin Exp $"); | |
32 | 32 | |||
33 | #include <sys/types.h> | 33 | #include <sys/types.h> | |
34 | #include <err.h> | 34 | #include <err.h> | |
35 | #include <stddef.h> | 35 | #include <stddef.h> | |
36 | #include <stdint.h> | 36 | #include <stdint.h> | |
37 | #include <stdio.h> | 37 | #include <stdio.h> | |
38 | #include <stdlib.h> | 38 | #include <stdlib.h> | |
39 | #include "mdef.h" | 39 | #include "mdef.h" | |
40 | #include "stdd.h" | 40 | #include "stdd.h" | |
41 | #include "extern.h" | 41 | #include "extern.h" | |
42 | 42 | |||
43 | FILE *traceout; | 43 | FILE *traceout; | |
44 | 44 | |||
@@ -49,35 +49,47 @@ FILE *traceout; | @@ -49,35 +49,47 @@ FILE *traceout; | |||
49 | #define TRACE_LINENO 16 | 49 | #define TRACE_LINENO 16 | |
50 | #define TRACE_CONT 32 | 50 | #define TRACE_CONT 32 | |
51 | #define TRACE_ID 64 | 51 | #define TRACE_ID 64 | |
52 | #define TRACE_NEWFILE 128 /* not implemented yet */ | 52 | #define TRACE_NEWFILE 128 /* not implemented yet */ | |
53 | #define TRACE_INPUT 256 /* not implemented yet */ | 53 | #define TRACE_INPUT 256 /* not implemented yet */ | |
54 | 54 | |||
55 | static unsigned int letter_to_flag(int); | 55 | static unsigned int letter_to_flag(int); | |
56 | static void print_header(struct input_file *); | 56 | static void print_header(struct input_file *); | |
57 | static int frame_level(void); | 57 | static int frame_level(void); | |
58 | 58 | |||
59 | 59 | |||
60 | unsigned int trace_flags = TRACE_QUOTE | TRACE_EXPANSION; | 60 | unsigned int trace_flags = TRACE_QUOTE | TRACE_EXPANSION; | |
61 | 61 | |||
62 | void | 62 | int | |
63 | trace_file(const char *name) | 63 | trace_file(const char *name) | |
64 | { | 64 | { | |
65 | FILE *newfp; | |||
66 | ||||
67 | if (name == NULL) | |||
68 | newfp = stderr; | |||
69 | #if 0 /* not yet */ | |||
70 | else if (*name == '\0') | |||
71 | newfp = NULL; | |||
72 | #endif | |||
73 | else { | |||
74 | newfp = fopen(name, "a"); | |||
75 | if (newfp == NULL) | |||
76 | return -1; | |||
77 | } | |||
65 | 78 | |||
66 | if (traceout && traceout != stderr) | 79 | if (traceout && traceout != stderr) | |
67 | fclose(traceout); | 80 | fclose(traceout); | |
68 | traceout = fopen(name, "w"); | 81 | traceout = newfp; | |
69 | if (!traceout) | 82 | return 0; | |
70 | err(1, "can't open %s", name); | |||
71 | } | 83 | } | |
72 | 84 | |||
73 | static unsigned int | 85 | static unsigned int | |
74 | letter_to_flag(int c) | 86 | letter_to_flag(int c) | |
75 | { | 87 | { | |
76 | switch(c) { | 88 | switch(c) { | |
77 | case 'a': | 89 | case 'a': | |
78 | return TRACE_ARGS; | 90 | return TRACE_ARGS; | |
79 | case 'e': | 91 | case 'e': | |
80 | return TRACE_EXPANSION; | 92 | return TRACE_EXPANSION; | |
81 | case 'q': | 93 | case 'q': | |
82 | return TRACE_QUOTE; | 94 | return TRACE_QUOTE; | |
83 | case 'c': | 95 | case 'c': |