summaryrefslogtreecommitdiff
path: root/usr.bin/m4
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2000-01-11 14:06:13 +0000
committerMarc Espie <espie@cvs.openbsd.org>2000-01-11 14:06:13 +0000
commit23672b016e655ac72332ce1d7258b102c47affc4 (patch)
tree6eb96ecee200b2dd25c7d5bb073bfc00598e3788 /usr.bin/m4
parente9c732393983baaa370e71df06a0ea002b54c413 (diff)
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.
Diffstat (limited to 'usr.bin/m4')
-rw-r--r--usr.bin/m4/extern.h5
-rw-r--r--usr.bin/m4/m4.111
-rw-r--r--usr.bin/m4/main.c78
-rw-r--r--usr.bin/m4/mdef.h4
4 files changed, 57 insertions, 41 deletions
diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h
index aae0fabde18..5d44b105031 100644
--- a/usr.bin/m4/extern.h
+++ b/usr.bin/m4/extern.h
@@ -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));
diff --git a/usr.bin/m4/m4.1 b/usr.bin/m4/m4.1
index 646e9820f6e..25f4db51b4d 100644
--- a/usr.bin/m4/m4.1
+++ b/usr.bin/m4/m4.1
@@ -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
diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c
index b906b8ec873..13c8395a7ba 100644
--- a/usr.bin/m4/main.c
+++ b/usr.bin/m4/main.c
@@ -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;
}
}
diff --git a/usr.bin/m4/mdef.h b/usr.bin/m4/mdef.h
index d06da732c90..77bbaa3ab28 100644
--- a/usr.bin/m4/mdef.h
+++ b/usr.bin/m4/mdef.h
@@ -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