summaryrefslogtreecommitdiffstats
path: root/usr.bin/m4/main.c
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2005-09-06 15:33:21 +0000
committerespie <espie@openbsd.org>2005-09-06 15:33:21 +0000
commit739ce1244bb934393fb8432151f4a6f43b5e42cc (patch)
treeef76bd8493a9fe4e88d0c89ee41d21f456648246 /usr.bin/m4/main.c
parentMake sure entries do not go away when we run through them in the file code. (diff)
downloadwireguard-openbsd-739ce1244bb934393fb8432151f4a6f43b5e42cc.tar.xz
wireguard-openbsd-739ce1244bb934393fb8432151f4a6f43b5e42cc.zip
finally make our m4 SusV3-compliant.
- changecom and changequote have a simple definition (that matches gnu-m4, coincidentally, so we no longer need two distinct modes for these) - off-by-one bug in -s, this finally works. - reorder main parser loop, so that we can use alphabetic constructs in quotes/comments. - rename putback to pushback, this matches comments, and makes more sense. - more uniform (and updated) description of changequote/changecom. - new, systematic regression tests of comments/quotes. - framework to test -s: one perl script to reconstitute `full' files with all line numbers, so that we can verify the output without needing a complete match. okay otto@, fries@
Diffstat (limited to 'usr.bin/m4/main.c')
-rw-r--r--usr.bin/m4/main.c120
1 files changed, 56 insertions, 64 deletions
diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c
index 3a34f113e0c..d53dd8a0da8 100644
--- a/usr.bin/m4/main.c
+++ b/usr.bin/m4/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.67 2005/08/06 16:22:26 espie Exp $ */
+/* $OpenBSD: main.c,v 1.68 2005/09/06 15:33:21 espie Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
@@ -296,9 +296,9 @@ do_look_ahead(int t, const char *token)
for (i = 1; *++token; i++) {
t = gpbc();
if (t == EOF || (unsigned char)t != (unsigned char)*token) {
- putback(t);
+ pushback(t);
while (--i)
- putback(*--token);
+ pushback(*--token);
return 0;
}
}
@@ -322,10 +322,57 @@ macro(void)
cycle {
t = gpbc();
- if (t == '_' || isalpha(t)) {
+
+ if (LOOK_AHEAD(t,lquote)) { /* strip quotes */
+ nlpar = 0;
+ record(quotes, nlpar++);
+ /*
+ * Opening quote: scan forward until matching
+ * closing quote has been found.
+ */
+ do {
+
+ l = gpbc();
+ if (LOOK_AHEAD(l,rquote)) {
+ if (--nlpar > 0)
+ outputstr(rquote);
+ } else if (LOOK_AHEAD(l,lquote)) {
+ record(quotes, nlpar++);
+ outputstr(lquote);
+ } else if (l == EOF) {
+ if (nlpar == 1)
+ warnx("unclosed quote:");
+ else
+ warnx("%d unclosed quotes:", nlpar);
+ dump_stack(quotes, nlpar);
+ exit(1);
+ } else {
+ if (nlpar > 0) {
+ if (sp < 0)
+ reallyputchar(l);
+ else
+ CHRSAVE(l);
+ }
+ }
+ }
+ while (nlpar != 0);
+ } else if (sp < 0 && LOOK_AHEAD(t, scommt)) {
+ reallyoutputstr(scommt);
+
+ for(;;) {
+ t = gpbc();
+ if (LOOK_AHEAD(t, ecommt)) {
+ reallyoutputstr(ecommt);
+ break;
+ }
+ if (t == EOF)
+ break;
+ reallyputchar(t);
+ }
+ } else if (t == '_' || isalpha(t)) {
p = inspect(t, token);
if (p != NULL)
- putback(l = gpbc());
+ pushback(l = gpbc());
if (p == NULL || (l != LPAREN &&
(macro_getdef(p)->type & NEEDARGS) != 0))
outputstr(token);
@@ -371,62 +418,7 @@ macro(void)
emit_synchline();
bufbase = bbase[ilevel];
continue;
- }
- /*
- * non-alpha token possibly seen..
- * [the order of else if .. stmts is important.]
- */
- else if (LOOK_AHEAD(t,lquote)) { /* strip quotes */
- nlpar = 0;
- record(quotes, nlpar++);
- /*
- * Opening quote: scan forward until matching
- * closing quote has been found.
- */
- do {
-
- l = gpbc();
- if (LOOK_AHEAD(l,rquote)) {
- if (--nlpar > 0)
- outputstr(rquote);
- } else if (LOOK_AHEAD(l,lquote)) {
- record(quotes, nlpar++);
- outputstr(lquote);
- } else if (l == EOF) {
- if (nlpar == 1)
- warnx("unclosed quote:");
- else
- warnx("%d unclosed quotes:", nlpar);
- dump_stack(quotes, nlpar);
- exit(1);
- } else {
- if (nlpar > 0) {
- if (sp < 0)
- reallyputchar(l);
- else
- CHRSAVE(l);
- }
- }
- }
- while (nlpar != 0);
- }
-
- else if (sp < 0 && LOOK_AHEAD(t, scommt)) {
- reallyoutputstr(scommt);
-
- for(;;) {
- t = gpbc();
- if (LOOK_AHEAD(t, ecommt)) {
- reallyoutputstr(ecommt);
- break;
- }
- if (t == EOF)
- break;
- reallyputchar(t);
- }
- }
-
- else if (sp < 0) { /* not in a macro at all */
+ } else if (sp < 0) { /* not in a macro at all */
reallyputchar(t); /* output directly.. */
}
@@ -437,7 +429,7 @@ macro(void)
chrsave(t);
while (isspace(l = gpbc()))
; /* skip blank, tab, nl.. */
- putback(l);
+ pushback(l);
record(paren, PARLEV++);
break;
@@ -464,7 +456,7 @@ macro(void)
chrsave(EOS); /* new argument */
while (isspace(l = gpbc()))
;
- putback(l);
+ pushback(l);
pushs(ep);
} else
chrsave(t);
@@ -550,7 +542,7 @@ inspect(int c, char *tp)
while ((isalnum(c = gpbc()) || c == '_') && tp < etp)
*tp++ = c;
if (c != EOF)
- PUTBACK(c);
+ PUSHBACK(c);
*tp = EOS;
/* token is too long, it won't match anything, but it can still
* be output. */