diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-12-20 15:39:15 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-12-20 15:39:15 +0000 |
commit | 653ace9d3ec27cdd8e4aa1baa633902ecab5c0c0 (patch) | |
tree | 27692c4bcc0d95028b54782c586053a9cf1432c3 | |
parent | d1e240e9a356c75fe1356e44b8ee69e787ba8412 (diff) |
Simplify some push-back code (e.g. for left and right quotes) so that
it uses pbstr() instead of doing the characters individually (in
reverse order) with putback(); cgd
-rw-r--r-- | usr.bin/m4/eval.c | 28 | ||||
-rw-r--r-- | usr.bin/m4/main.c | 30 |
2 files changed, 28 insertions, 30 deletions
diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index d5abbbaa76c..1681f36fe50 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.9 1997/08/31 21:34:18 deraadt Exp $ */ +/* $OpenBSD: eval.c,v 1.10 1997/12/20 15:39:13 deraadt 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.9 1997/08/31 21:34:18 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: eval.c,v 1.10 1997/12/20 15:39:13 deraadt Exp $"; #endif #endif /* not lint */ @@ -240,22 +240,14 @@ register int td; if (argc > 3) { int k; for (n = argc - 1; n > 3; n--) { - k = strlen(rquote); - while (k--) - putback(rquote[k]); + pbstr(rquote); pbstr(argv[n]); - k = strlen(lquote); - while (k--) - putback(lquote[k]); + pbstr(lquote); putback(COMMA); } - k = strlen(rquote); - while (k--) - putback(rquote[k]); + pbstr(rquote); pbstr(argv[3]); - k = strlen(lquote); - while (k--) - putback(lquote[k]); + pbstr(lquote); } break; @@ -494,13 +486,9 @@ char *name; register ndptr p; if ((p = lookup(name)) != nil && p->defn != null) { - int n = strlen(rquote); - while (n--) - putback(rquote[n]); + pbstr(rquote); pbstr(p->defn); - n = strlen(lquote); - while (n--) - putback(lquote[n]); + pbstr(lquote); } } diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index d1f3b08ce9e..28ba8f8724c 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -1,5 +1,5 @@ -/* $OpenBSD: main.c,v 1.6 1997/12/10 20:24:15 deraadt Exp $ */ -/* $NetBSD: main.c,v 1.11 1996/01/13 23:25:26 pk Exp $ */ +/* $OpenBSD: main.c,v 1.7 1997/12/20 15:39:14 deraadt Exp $ */ +/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -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.6 1997/12/10 20:24:15 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.7 1997/12/20 15:39:14 deraadt Exp $"; #endif #endif /* not lint */ @@ -280,7 +280,7 @@ do_look_ahead(t, token) */ void macro() { - char token[MAXTOK]; + char token[MAXTOK], chars[2]; register char *s; register int t, l; register ndptr p; @@ -331,24 +331,34 @@ macro() { continue; } /* - * non-alpha single-char token seen.. + * non-alpha token possibly seen.. * [the order of else if .. stmts is important.] */ else if (LOOK_AHEAD(t,lquote)) { /* strip quotes */ nlpar = 1; do { + l = gpbc(); - if (LOOK_AHEAD(l,rquote)) + if (LOOK_AHEAD(l,rquote)) { nlpar--; - else if (LOOK_AHEAD(l,lquote)) + s = rquote; + } else if (LOOK_AHEAD(l,lquote)) { nlpar++; - else if (l == EOF) + s = lquote; + } else if (l == EOF) oops("missing right quote", ""); + else { + chars[0] = l; + chars[1] = '\0'; + s = chars; + } if (nlpar > 0) { if (sp < 0) - putc(l, active); + while (*s) + putc(*s++, active); else - chrsave(l); + while (*s) + chrsave(*s++); } } while (nlpar != 0); |