summaryrefslogtreecommitdiff
path: root/usr.bin/m4
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2001-09-18 13:52:59 +0000
committerMarc Espie <espie@cvs.openbsd.org>2001-09-18 13:52:59 +0000
commit7ba378d747ac554e73941549d1771e3956c7ccb6 (patch)
tree4125663a837fd2c3db0e5a637c59c655a57f31fe /usr.bin/m4
parentb8a61704827463b30606d30c7d89c7ae910a770a (diff)
One single point for all macros/builtin expansion.
Diffstat (limited to 'usr.bin/m4')
-rw-r--r--usr.bin/m4/eval.c37
-rw-r--r--usr.bin/m4/extern.h3
-rw-r--r--usr.bin/m4/gnum4.c7
-rw-r--r--usr.bin/m4/main.c16
4 files changed, 37 insertions, 26 deletions
diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c
index 964058f7fdc..c56d1c8bad1 100644
--- a/usr.bin/m4/eval.c
+++ b/usr.bin/m4/eval.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eval.c,v 1.29 2001/06/13 12:20:43 espie Exp $ */
+/* $OpenBSD: eval.c,v 1.30 2001/09/18 13:52:58 espie Exp $ */
/* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */
/*
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95";
#else
-static char rcsid[] = "$OpenBSD: eval.c,v 1.29 2001/06/13 12:20:43 espie Exp $";
+static char rcsid[] = "$OpenBSD: eval.c,v 1.30 2001/09/18 13:52:58 espie Exp $";
#endif
#endif /* not lint */
@@ -78,8 +78,30 @@ static void doundiv __P((const char *[], int));
static void dosub __P((const char *[], int));
static void map __P((char *, const char *, const char *, const char *));
static const char *handledash __P((char *, char *, const char *));
+static void expand_builtin __P((const char *[], int, int));
+static void expand_macro __P((const char *[], int));
+
+
+/*
+ * eval - eval all macros and builtins calls
+ */
+void
+eval(argv, argc, td)
+ const char *argv[];
+ int argc;
+ int td;
+{
+ if (td & RECDEF)
+ errx(1, "%s at line %lu: expanding recursive definition for %s",
+ CURRENT_NAME, CURRENT_LINE, argv[1]);
+ if (td == MACRTYPE)
+ expand_macro(argv, argc);
+ else
+ expand_builtin(argv, argc, td);
+}
+
/*
- * eval - evaluate built-in macros.
+ * expand_builtin - evaluate built-in macros.
* argc - number of elements in argv.
* argv - element vector :
* argv[0] = definition of a user
@@ -98,7 +120,7 @@ static const char *handledash __P((char *, char *, const char *));
*/
void
-eval(argv, argc, td)
+expand_builtin(argv, argc, td)
const char *argv[];
int argc;
int td;
@@ -112,9 +134,6 @@ eval(argv, argc, td)
printf("argv[%d] = %s\n", n, argv[n]);
#endif
- if (td & RECDEF)
- errx(1, "%s at line %lu: expanding recursive definition for %s",
- CURRENT_NAME, CURRENT_LINE, argv[1]);
/*
* if argc == 3 and argv[2] is null, then we
* have macro-or-builtin() type call. We adjust
@@ -446,10 +465,10 @@ eval(argv, argc, td)
char *dumpfmt = "`%s'\t`%s'\n"; /* format string for dumpdef */
/*
- * expand - user-defined macro expansion
+ * expand_macro - user-defined macro expansion
*/
void
-expand(argv, argc)
+expand_macro(argv, argc)
const char *argv[];
int argc;
{
diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h
index 1f4f2a8860d..014b98913be 100644
--- a/usr.bin/m4/extern.h
+++ b/usr.bin/m4/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.21 2000/07/27 17:44:33 espie Exp $ */
+/* $OpenBSD: extern.h,v 1.22 2001/09/18 13:52:58 espie Exp $ */
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
/*-
@@ -41,7 +41,6 @@
/* eval.c */
extern void eval __P((const char *[], int, int));
-extern void expand __P((const char *[], int));
extern void dodefine __P((const char *, const char *));
/* expr.c */
diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c
index 1deb32f1b68..b4c94c6e8e5 100644
--- a/usr.bin/m4/gnum4.c
+++ b/usr.bin/m4/gnum4.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gnum4.c,v 1.11 2001/09/18 13:42:37 espie Exp $ */
+/* $OpenBSD: gnum4.c,v 1.12 2001/09/18 13:52:58 espie Exp $ */
/*
* Copyright (c) 1999 Marc Espie
@@ -173,10 +173,7 @@ doindir(argv, argc)
if (p == NULL)
errx(1, "undefined macro %s", argv[2]);
argv[1] = p->defn;
- if (p->type == MACRTYPE)
- expand(argv+1, argc-1);
- else
- eval(argv+1, argc-1, p->type);
+ eval(argv+1, argc-1, p->type);
}
void
diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c
index 3c61a541839..0fbbf667994 100644
--- a/usr.bin/m4/main.c
+++ b/usr.bin/m4/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.43 2001/09/18 13:44:51 espie Exp $ */
+/* $OpenBSD: main.c,v 1.44 2001/09/18 13:52:58 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.43 2001/09/18 13:44:51 espie Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.44 2001/09/18 13:52:58 espie Exp $";
#endif
#endif /* not lint */
@@ -336,10 +336,8 @@ macro()
if (sp == STACKMAX)
errx(1, "internal stack overflow");
- if (CALTYP == MACRTYPE)
- expand((const char **) mstack+fp+1, 2);
- else
- eval((const char **) mstack+fp+1, 2, CALTYP);
+ eval((const char **) mstack+fp+1, 2,
+ CALTYP);
ep = PREVEP; /* flush strspace */
sp = PREVSP; /* previous sp.. */
@@ -436,10 +434,8 @@ macro()
if (sp == STACKMAX)
errx(1, "internal stack overflow");
- if (CALTYP == MACRTYPE)
- expand((const char **) mstack+fp+1, sp-fp);
- else
- eval((const char **) mstack+fp+1, sp-fp, CALTYP);
+ eval((const char **) mstack+fp+1, sp-fp,
+ CALTYP);
ep = PREVEP; /* flush strspace */
sp = PREVSP; /* previous sp.. */