1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

Don't recognize built-ins in contexts where they don't make sense.

Namely, it doesn't help to try and expand include if it's not followed
by parenthesis and a filename.

This should make applications like sendmail m4 scripts more sturdy for
unquoted machine names that happen to collide with built-ins.

The only drawback is that our m4 may now do intelligent things with scripts
that don't work on other systems.
This commit is contained in:
espie 2000-01-11 14:06:11 +00:00
parent 41c6d7ee5d
commit 80cbbe91b6
4 changed files with 57 additions and 41 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: extern.h,v 1.13 1999/11/30 22:19:50 espie Exp $ */
/* $OpenBSD: extern.h,v 1.14 2000/01/11 14:06:11 espie Exp $ */
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
/*-
@ -57,6 +57,9 @@ extern unsigned hash __P((const char *));
extern ndptr lookup __P((const char *));
extern void remhash __P((const char *, int));
/* main.c */
extern void outputstr __P((const char *));
/* misc.c */
extern void chrsave __P((int));
extern char *compute_prevep __P((void));

View File

@ -1,4 +1,4 @@
.\" @(#) $OpenBSD: m4.1,v 1.8 1999/11/17 15:31:53 espie Exp $
.\" @(#) $OpenBSD: m4.1,v 1.9 2000/01/11 14:06:11 espie Exp $
.\"
.\"
.Dd January 26, 1993
@ -30,16 +30,19 @@ parenthesis '('. If the macro name is not followed by an open
parenthesis it is processed with no arguments.
.Pp
Macro names consist of a leading alphabetic or underscore
possibly followed by alphanumeric or underscore characters, therefore
valid macro names match this pattern [a-zA-Z_][a-zA-Z0-9_]*.
possibly followed by alphanumeric or underscore characters, e.g.,
valid macro names match the pattern [a-zA-Z_][a-zA-Z0-9_]*.
.Pp
In arguments to macros, leading unquoted space, tab and newline
characters are ignored. To quote strings use left and right single
characters are ignored. To quote strings, use left and right single
quotes (e.g., ` this is a string with a leading space'). You can change
the quote characters with the
.Ic changequote
built-in macro.
.Pp
Some built-ins don't make any sense without arguments, and hence are not
recognized as special when not followed by an open parenthesis.
.Pp
The options are as follows:
.Bl -tag -width "-Dname[=value]xxx"
.It Fl D Ns Ar name Ns Oo

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.23 2000/01/05 16:06:14 espie Exp $ */
/* $OpenBSD: main.c,v 1.24 2000/01/11 14:06:11 espie Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
@ -47,7 +47,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$OpenBSD: main.c,v 1.23 2000/01/05 16:06:14 espie Exp $";
static char rcsid[] = "$OpenBSD: main.c,v 1.24 2000/01/11 14:06:11 espie Exp $";
#endif
#endif /* not lint */
@ -93,7 +93,7 @@ struct keyblk keywrds[] = { /* m4 keywords to be installed */
{ "sinclude", SINCTYPE },
{ "define", DEFITYPE },
{ "defn", DEFNTYPE },
{ "divert", DIVRTYPE },
{ "divert", DIVRTYPE | NOARGS },
{ "expr", EXPRTYPE },
{ "eval", EXPRTYPE },
{ "substr", SUBSTYPE },
@ -102,9 +102,9 @@ struct keyblk keywrds[] = { /* m4 keywords to be installed */
{ "len", LENGTYPE },
{ "incr", INCRTYPE },
{ "decr", DECRTYPE },
{ "dnl", DNLNTYPE },
{ "changequote", CHNQTYPE },
{ "changecom", CHNCTYPE },
{ "dnl", DNLNTYPE | NOARGS },
{ "changequote", CHNQTYPE | NOARGS },
{ "changecom", CHNCTYPE | NOARGS },
{ "index", INDXTYPE },
#ifdef EXTENDED
{ "paste", PASTTYPE },
@ -112,24 +112,24 @@ struct keyblk keywrds[] = { /* m4 keywords to be installed */
#endif
{ "popdef", POPDTYPE },
{ "pushdef", PUSDTYPE },
{ "dumpdef", DUMPTYPE },
{ "shift", SHIFTYPE },
{ "dumpdef", DUMPTYPE | NOARGS },
{ "shift", SHIFTYPE | NOARGS },
{ "translit", TRNLTYPE },
{ "undefine", UNDFTYPE },
{ "undivert", UNDVTYPE },
{ "divnum", DIVNTYPE },
{ "undivert", UNDVTYPE | NOARGS },
{ "divnum", DIVNTYPE | NOARGS },
{ "maketemp", MKTMTYPE },
{ "errprint", ERRPTYPE },
{ "m4wrap", M4WRTYPE },
{ "m4exit", EXITTYPE },
{ "errprint", ERRPTYPE | NOARGS },
{ "m4wrap", M4WRTYPE | NOARGS },
{ "m4exit", EXITTYPE | NOARGS },
{ "syscmd", SYSCTYPE },
{ "sysval", SYSVTYPE },
{ "sysval", SYSVTYPE | NOARGS },
#if defined(unix) || defined(__unix__)
{ "unix", SELFTYPE },
#if defined(unix) || defined(__unix__)
{ "unix", SELFTYPE | NOARGS },
#else
#ifdef vms
{ "vms", SELFTYPE },
{ "vms", SELFTYPE | NOARGS },
#endif
#endif
};
@ -278,14 +278,12 @@ macro()
if (t == '_' || isalpha(t)) {
putback(t);
s = token;
if ((p = inspect(s)) == nil) {
if (sp < 0)
while (*s)
putc(*s++, active);
else
while (*s)
chrsave(*s++);
}
p = inspect(s);
if (p != nil)
putback(l = gpbc());
if (p == nil || (l != LPAREN &&
(p->type & NEEDARGS) != 0))
outputstr(s);
else {
/*
* real thing.. First build a call frame:
@ -301,7 +299,6 @@ macro()
pushs(p->name); /* macro name */
pushs(ep); /* start next..*/
putback(l = gpbc());
if (l != LPAREN) { /* add bracks */
putback(RPAREN);
putback(LPAREN);
@ -343,14 +340,8 @@ macro()
chars[1] = EOS;
s = chars;
}
if (nlpar > 0) {
if (sp < 0)
while (*s)
putc(*s++, active);
else
while (*s)
chrsave(*s++);
}
if (nlpar > 0)
outputstr(s);
}
while (nlpar != 0);
}
@ -439,6 +430,21 @@ macro()
}
}
/*
* output string directly, without pushing it for reparses.
*/
void
outputstr(s)
const char *s;
{
if (sp < 0)
while (*s)
putc(*s++, active);
else
while (*s)
chrsave(*s++);
}
/*
* build an input token..
* consider only those starting with _ or A-Za-z. This is a
@ -490,7 +496,9 @@ initkwds()
p->name = keywrds[i].knam;
p->defn = null;
p->hv = h;
p->type = keywrds[i].ktyp | STATIC;
p->type = (keywrds[i].ktyp & TYPEMASK) | STATIC;
if ((keywrds[i].ktyp & NOARGS) == 0)
p->type |= NEEDARGS;
}
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mdef.h,v 1.10 2000/01/05 16:06:14 espie Exp $ */
/* $OpenBSD: mdef.h,v 1.11 2000/01/11 14:06:12 espie Exp $ */
/* $NetBSD: mdef.h,v 1.7 1996/01/13 23:25:27 pk Exp $ */
/*
@ -77,6 +77,8 @@
#define TYPEMASK 63 /* Keep bits really corresponding to a type. */
#define STATIC 128 /* Name is statically allocated, don't free. */
#define RECDEF 256 /* Pure recursive def, don't expand it */
#define NOARGS 512 /* builtin needs no args */
#define NEEDARGS 1024 /* mark builtin that need args with this */
/*
* m4 special characters