summaryrefslogtreecommitdiff
path: root/usr.bin/m4/eval.c
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2003-06-18 21:08:08 +0000
committerMarc Espie <espie@cvs.openbsd.org>2003-06-18 21:08:08 +0000
commit35eec2cb552641a60db99e8aa2113608d7cc0f78 (patch)
tree979b9af23e6892282e1c2ec48213536677fdc34d /usr.bin/m4/eval.c
parentd6f2c260e4ef7a357be58b961566161e135574b5 (diff)
- store builtin name as definition for builtin macros.
this removes the need for code->name conversion, in exchange for systematically testing the definition type, since we can no longer rely on the defn being NULL. - commonnalize the builtin-detection code, so that we can use it for pushdef as well with define, so that pushdef handles builtins correctly as well. okay fries@, millert@.
Diffstat (limited to 'usr.bin/m4/eval.c')
-rw-r--r--usr.bin/m4/eval.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c
index aafb63f4172..1402529673b 100644
--- a/usr.bin/m4/eval.c
+++ b/usr.bin/m4/eval.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eval.c,v 1.47 2003/06/03 02:56:10 millert Exp $ */
+/* $OpenBSD: eval.c,v 1.48 2003/06/18 21:08:07 espie Exp $ */
/* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */
/*
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95";
#else
-static char rcsid[] = "$OpenBSD: eval.c,v 1.47 2003/06/03 02:56:10 millert Exp $";
+static char rcsid[] = "$OpenBSD: eval.c,v 1.48 2003/06/18 21:08:07 espie Exp $";
#endif
#endif /* not lint */
@@ -63,6 +63,7 @@ static char rcsid[] = "$OpenBSD: eval.c,v 1.47 2003/06/03 02:56:10 millert Exp $
#define BUILTIN_MARKER "__builtin_"
+static void setup_definition(ndptr, const char *);
static void dodefn(const char *);
static void dopushdef(const char *, const char *);
static void dodump(const char *[], int);
@@ -560,29 +561,22 @@ expand_macro(const char *argv[], int argc)
PUTBACK(*p);
}
+
/*
- * dodefine - install definition in the table
+ * common part to dodefine and dopushdef
*/
-void
-dodefine(const char *name, const char *defn)
+static void
+setup_definition(ndptr p, const char *defn)
{
- ndptr p;
int n;
- if (!*name)
- errx(1, "%s at line %lu: null definition.", CURRENT_NAME,
- CURRENT_LINE);
- if ((p = lookup(name)) == nil)
- p = addent(name);
- else if (p->defn != null)
- free((char *) p->defn);
if (strncmp(defn, BUILTIN_MARKER, sizeof(BUILTIN_MARKER)-1) == 0) {
n = builtin_type(defn+sizeof(BUILTIN_MARKER)-1);
if (n != -1) {
p->type = n & TYPEMASK;
if ((n & NOARGS) == 0)
p->type |= NEEDARGS;
- p->defn = null;
+ p->defn = xstrdup(defn+sizeof(BUILTIN_MARKER)-1);
return;
}
}
@@ -591,6 +585,24 @@ dodefine(const char *name, const char *defn)
else
p->defn = xstrdup(defn);
p->type = MACRTYPE;
+}
+
+/*
+ * dodefine - install definition in the table
+ */
+void
+dodefine(const char *name, const char *defn)
+{
+ ndptr p;
+
+ if (!*name)
+ errx(1, "%s at line %lu: null definition.", CURRENT_NAME,
+ CURRENT_LINE);
+ if ((p = lookup(name)) == nil)
+ p = addent(name);
+ else if (p->defn != null)
+ free((char *) p->defn);
+ setup_definition(p, defn);
if (STREQ(name, defn))
p->type |= RECDEF;
}
@@ -606,12 +618,12 @@ dodefn(const char *name)
char *real;
if ((p = lookup(name)) != nil) {
- if (p->defn != null) {
+ if ((p->type & TYPEMASK) == MACRTYPE) {
pbstr(rquote);
pbstr(p->defn);
pbstr(lquote);
- } else if ((real = builtin_realname(p->type)) != NULL) {
- pbstr(real);
+ } else {
+ pbstr(p->defn);
pbstr(BUILTIN_MARKER);
}
}
@@ -633,11 +645,7 @@ dopushdef(const char *name, const char *defn)
errx(1, "%s at line %lu: null definition", CURRENT_NAME,
CURRENT_LINE);
p = addent(name);
- if (!*defn)
- p->defn = null;
- else
- p->defn = xstrdup(defn);
- p->type = MACRTYPE;
+ setup_definition(p, defn);
if (STREQ(name, defn))
p->type |= RECDEF;
}
@@ -648,16 +656,11 @@ dopushdef(const char *name, const char *defn)
static void
dump_one_def(ndptr p)
{
- char *real;
-
if (mimic_gnu) {
if ((p->type & TYPEMASK) == MACRTYPE)
fprintf(traceout, "%s:\t%s\n", p->name, p->defn);
else {
- real = builtin_realname(p->type);
- if (real == NULL)
- real = null;
- fprintf(traceout, "%s:\t<%s>\n", p->name, real);
+ fprintf(traceout, "%s:\t<%s>\n", p->name, p->defn);
}
} else
fprintf(traceout, "`%s'\t`%s'\n", p->name, p->defn);