diff options
-rw-r--r-- | usr.bin/m4/eval.c | 59 | ||||
-rw-r--r-- | usr.bin/m4/extern.h | 3 | ||||
-rw-r--r-- | usr.bin/m4/main.c | 17 |
3 files changed, 35 insertions, 44 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); diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h index 57275a7f89d..29022fd922d 100644 --- a/usr.bin/m4/extern.h +++ b/usr.bin/m4/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.32 2003/06/12 14:36:43 espie Exp $ */ +/* $OpenBSD: extern.h,v 1.33 2003/06/18 21:08:07 espie Exp $ */ /* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */ /*- @@ -66,7 +66,6 @@ extern void remhash(const char *, int); /* main.c */ extern void outputstr(const char *); extern int builtin_type(const char *); -extern char *builtin_realname(int); extern void do_emit_synchline(void); #define emit_synchline() do { if (synch_lines) do_emit_synchline(); } while(0) diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index c60b9b8c66b..a07ebbfd477 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.57 2003/06/12 14:36:43 espie Exp $ */ +/* $OpenBSD: main.c,v 1.58 2003/06/18 21:08:07 espie Exp $ */ /* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ /*- @@ -43,7 +43,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.57 2003/06/12 14:36:43 espie Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.58 2003/06/18 21:08:07 espie Exp $"; #endif #endif /* not lint */ @@ -586,7 +586,7 @@ initkwds(void) p->nxtptr = hashtab[h % HASHSIZE]; hashtab[h % HASHSIZE] = p; p->name = xstrdup(keywrds[i].knam); - p->defn = null; + p->defn = xstrdup(keywrds[i].knam); p->hv = h; p->type = keywrds[i].ktyp & TYPEMASK; if ((keywrds[i].ktyp & NOARGS) == 0) @@ -606,17 +606,6 @@ builtin_type(const char *key) return -1; } -char * -builtin_realname(int n) -{ - int i; - - for (i = 0; i != MAXKEYS; i++) - if (((keywrds[i].ktyp ^ n) & TYPEMASK) == 0) - return keywrds[i].knam; - return NULL; -} - static void record(struct position *t, int lev) { |