summaryrefslogtreecommitdiffstats
path: root/usr.bin/m4
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2010-03-22 20:40:43 +0000
committerespie <espie@openbsd.org>2010-03-22 20:40:43 +0000
commitddcc7fd65441883f53f400fc8f6d00987df68785 (patch)
treee2a7b8e8dcfc27af8813a8b0d10d1978f7f0ad90 /usr.bin/m4
parentclean up the ProgressMeter code, create a specific class if a Term (diff)
downloadwireguard-openbsd-ddcc7fd65441883f53f400fc8f6d00987df68785.tar.xz
wireguard-openbsd-ddcc7fd65441883f53f400fc8f6d00987df68785.zip
add more gnum4 support: regexps do weird things with empty patterns (this
is required for newer autoconf). fix the tokenizer for gnu extensions, allowing digits out of range is ridiculous. add POSIX2008 mkstemp and document it (also documenting that mktemp is safe, not posix...) tidy the manpage, do extra .Nm m4 -> .Nm. okay otto@, miod@, jmc@
Diffstat (limited to 'usr.bin/m4')
-rw-r--r--usr.bin/m4/gnum4.c13
-rw-r--r--usr.bin/m4/m4.131
-rw-r--r--usr.bin/m4/main.c3
-rw-r--r--usr.bin/m4/tokenizer.l20
4 files changed, 47 insertions, 20 deletions
diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c
index 8d3842f4f7b..8c803fe79fd 100644
--- a/usr.bin/m4/gnum4.c
+++ b/usr.bin/m4/gnum4.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gnum4.c,v 1.39 2008/08/21 21:01:04 espie Exp $ */
+/* $OpenBSD: gnum4.c,v 1.40 2010/03/22 20:40:43 espie Exp $ */
/*
* Copyright (c) 1999 Marc Espie
@@ -444,7 +444,7 @@ dopatsubst(const char *argv[], int argc)
if (argv[3][0] == '\0') {
const char *s;
size_t len;
- if (argv[4] && argc > 4)
+ if (argc > 4 && argv[4])
len = strlen(argv[4]);
else
len = 0;
@@ -489,13 +489,20 @@ doregexp(const char *argv[], int argc)
warnx("Too few arguments to regexp");
return;
}
+ /* special gnu case */
+ if (argv[3][0] == '\0' && mimic_gnu) {
+ if (argc == 4 || argv[4] == NULL)
+ return;
+ else
+ pbstr(argv[4]);
+ }
error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3],
REG_EXTENDED);
if (error != 0)
exit_regerror(error, &re);
pmatch = xalloc(sizeof(regmatch_t) * (re.re_nsub+1), NULL);
- if (argv[4] == NULL || argc == 4)
+ if (argc == 4 || argv[4] == NULL)
do_regexpindex(argv[2], &re, pmatch);
else
do_regexp(argv[2], &re, argv[4], pmatch);
diff --git a/usr.bin/m4/m4.1 b/usr.bin/m4/m4.1
index e191518b983..0d91f6cc00e 100644
--- a/usr.bin/m4/m4.1
+++ b/usr.bin/m4/m4.1
@@ -1,4 +1,4 @@
-.\" @(#) $OpenBSD: m4.1,v 1.56 2009/10/14 17:19:47 sthen Exp $
+.\" @(#) $OpenBSD: m4.1,v 1.57 2010/03/22 20:40:44 espie Exp $
.\"
.\" Copyright (c) 1989, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -30,14 +30,14 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: October 14 2009 $
+.Dd $Mdocdate: March 22 2010 $
.Dt M4 1
.Os
.Sh NAME
.Nm m4
.Nd macro language processor
.Sh SYNOPSIS
-.Nm m4
+.Nm
.Op Fl gPs
.Oo
.Sm off
@@ -54,11 +54,11 @@
.Ek
.Sh DESCRIPTION
The
-.Nm m4
+.Nm
utility is a macro processor that can be used as a front end to any
language (e.g., C, ratfor, fortran, lex, and yacc).
If no input files are given,
-.Nm m4
+.Nm
reads from the standard input,
otherwise files specified on the command line are
processed in the given order.
@@ -66,7 +66,7 @@ Input files can be regular files, files in the m4 include paths, or a
single dash
.Pq Sq - ,
denoting standard input.
-.Nm m4
+.Nm
writes
the processed text to the standard output, unless told otherwise.
.Pp
@@ -168,7 +168,7 @@ Undefine the symbol
.Ar name .
.El
.Sh SYNTAX
-.Nm m4
+.Nm
provides the following built-in macros.
They may be redefined, losing their original meaning.
Return values are null unless otherwise stated.
@@ -239,7 +239,7 @@ macro definitions (even for built-in macros).
.It Fn divert num
There are 10 output queues (numbered 0-9).
At the end of processing
-.Nm m4
+.Nm
concatenates all the queues in numerical order to produce the
final output.
Initially the output queue is 0.
@@ -258,7 +258,7 @@ Prints the first argument on the standard error output stream.
.It Fn esyscmd cmd
Passes its first argument to a shell and returns the shell's standard output.
Note that the shell shares its standard input and standard error with
-.Nm m4 .
+.Nm .
.It Fn eval expr
Computes the first argument as an arithmetic expression using 32-bit
arithmetic.
@@ -347,6 +347,9 @@ Multiple calls to
get inserted in sequence at the final
.Dv EOF .
.It Fn maketemp template
+Like
+.Ic mkstemp .
+.It Fn mkstemp template
Invokes
.Xr mkstemp 3
on the first argument, and returns the modified string.
@@ -433,7 +436,7 @@ Returns the current file's name.
.Sh STANDARDS
The
.Nm
-utility is compliant with the
+utility is mostly compliant with the
.St -p1003.1-2008
specification.
.Pp
@@ -455,6 +458,12 @@ and
.Ic __file__
are extensions to that specification.
.Pp
+.Ic maketemp
+is not supposed to be a synonym for
+.Ic mkstemp ,
+but instead to be an insecure temporary file name creation function.
+The change causes no known compatibility issues.
+.Pp
The output format of tracing and of
.Ic dumpdef
are not specified in any standard,
@@ -479,7 +488,7 @@ replaces the top-most definition only.
Other implementations may erase all definitions on the stack instead.
.Pp
All built-ins do expand without arguments in many other
-.Nm m4 .
+.Nm .
.Pp
Many other
.Nm
diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c
index 8b4017d8d68..b841f47fad4 100644
--- a/usr.bin/m4/main.c
+++ b/usr.bin/m4/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.77 2009/10/14 17:19:47 sthen Exp $ */
+/* $OpenBSD: main.c,v 1.78 2010/03/22 20:40:44 espie Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
@@ -123,6 +123,7 @@ struct keyblk keywrds[] = { /* m4 keywords to be installed */
{ "undivert", UNDVTYPE | NOARGS },
{ "divnum", DIVNTYPE | NOARGS },
{ "maketemp", MKTMTYPE },
+ { "mkstemp", MKTMTYPE },
{ "errprint", ERRPTYPE | NOARGS },
{ "m4wrap", M4WRTYPE | NOARGS },
{ "m4exit", EXITTYPE | NOARGS },
diff --git a/usr.bin/m4/tokenizer.l b/usr.bin/m4/tokenizer.l
index 2d0d169672c..7da63086add 100644
--- a/usr.bin/m4/tokenizer.l
+++ b/usr.bin/m4/tokenizer.l
@@ -1,5 +1,5 @@
%{
-/* $OpenBSD: tokenizer.l,v 1.6 2008/08/21 21:00:14 espie Exp $ */
+/* $OpenBSD: tokenizer.l,v 1.7 2010/03/22 20:40:44 espie Exp $ */
/*
* Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
*
@@ -16,6 +16,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "parser.h"
+#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <stdint.h>
@@ -75,6 +76,7 @@ parse_radix()
long base;
char *next;
long l;
+ int d;
l = 0;
base = strtol(yytext+2, &next, 0);
@@ -84,11 +86,19 @@ parse_radix()
next++;
while (*next != 0) {
if (*next >= '0' && *next <= '9')
- l = base * l + *next - '0';
+ d = *next - '0';
else if (*next >= 'a' && *next <= 'z')
- l = base * l + *next - 'a' + 10;
- else if (*next >= 'A' && *next <= 'Z')
- l = base * l + *next - 'A' + 10;
+ d = *next - 'a' + 10;
+ else {
+ assert(*next >= 'A' && *next <= 'Z');
+ d = *next - 'A' + 10;
+ }
+ if (d >= base) {
+ fprintf(stderr,
+ "m4: error in number %s\n", yytext);
+ return 0;
+ }
+ l = base * l + d;
next++;
}
}