summaryrefslogtreecommitdiff
path: root/usr.bin/m4
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2000-01-15 14:26:01 +0000
committerMarc Espie <espie@cvs.openbsd.org>2000-01-15 14:26:01 +0000
commit01f3a3293bad0f5c130117d82810c2c14f249640 (patch)
tree52dc3d6be7ab37eaaf62652d9f767ad04e633347 /usr.bin/m4
parentdaf3bbf0fcc9ffc75f8a0d4b2cdee6f647c38906 (diff)
There is no need to waste short for holding EOF in the pushback buffer.
Now that the input_file structure is sufficiently fleshed out, just stop EOF at the putback level, and make sure files at EOF STAY at EOF.
Diffstat (limited to 'usr.bin/m4')
-rw-r--r--usr.bin/m4/extern.h10
-rw-r--r--usr.bin/m4/main.c8
-rw-r--r--usr.bin/m4/mdef.h4
-rw-r--r--usr.bin/m4/misc.c37
4 files changed, 30 insertions, 29 deletions
diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h
index e593793d265..d84f0d55889 100644
--- a/usr.bin/m4/extern.h
+++ b/usr.bin/m4/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.15 2000/01/12 17:49:53 espie Exp $ */
+/* $OpenBSD: extern.h,v 1.16 2000/01/15 14:26:00 espie Exp $ */
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
/*-
@@ -89,10 +89,10 @@ extern int fp; /* m4 call frame pointer */
extern int ilevel; /* input file stack pointer */
extern int oindex; /* diversion index. */
extern int sp; /* current m4 stack pointer */
-extern pbent *bp; /* first available character */
-extern pbent *buf; /* push-back buffer */
-extern pbent *bufbase; /* buffer base for this ilevel */
-extern pbent *bbase[]; /* buffer base per ilevel */
+extern char *bp; /* first available character */
+extern char *buf; /* push-back buffer */
+extern char *bufbase; /* buffer base for this ilevel */
+extern char *bbase[]; /* buffer base per ilevel */
extern char ecommt[MAXCCHARS+1];/* end character for comment */
extern char *ep; /* first free char in strspace */
extern char lquote[MAXCCHARS+1];/* left quote character (`) */
diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c
index b1f80f3a692..309b32e4748 100644
--- a/usr.bin/m4/main.c
+++ b/usr.bin/m4/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.27 2000/01/13 17:35:09 espie Exp $ */
+/* $OpenBSD: main.c,v 1.28 2000/01/15 14:26:00 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.27 2000/01/13 17:35:09 espie Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.28 2000/01/15 14:26:00 espie Exp $";
#endif
#endif /* not lint */
@@ -220,7 +220,6 @@ main(argc,argv)
if (*m4wraps) { /* anything for rundown ?? */
ilevel = 0; /* in case m4wrap includes.. */
bufbase = bp = buf; /* use the entire buffer */
- putback(EOF); /* eof is a must !! */
pbstr(m4wraps); /* user-defined wrapup act */
macro(); /* last will and testament */
}
@@ -257,8 +256,7 @@ do_look_ahead(t, token)
for (i = 1; *++token; i++) {
t = gpbc();
if (t == EOF || t != *token) {
- if (t != EOF)
- putback(t);
+ putback(t);
while (--i)
putback(*--token);
return 0;
diff --git a/usr.bin/m4/mdef.h b/usr.bin/m4/mdef.h
index b88fa5ad0ff..d18fda20f49 100644
--- a/usr.bin/m4/mdef.h
+++ b/usr.bin/m4/mdef.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdef.h,v 1.12 2000/01/12 17:49:53 espie Exp $ */
+/* $OpenBSD: mdef.h,v 1.13 2000/01/15 14:26:00 espie Exp $ */
/* $NetBSD: mdef.h,v 1.7 1996/01/13 23:25:27 pk Exp $ */
/*
@@ -145,8 +145,6 @@ typedef union { /* stack structure */
char *sstr; /* string entry */
} stae;
-typedef short pbent; /* pushback entry; needs to hold chars + EOF */
-
struct input_file {
FILE *file;
char *name;
diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c
index b49dcd96b2b..68bf5b4ae3a 100644
--- a/usr.bin/m4/misc.c
+++ b/usr.bin/m4/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.16 2000/01/13 17:35:10 espie Exp $ */
+/* $OpenBSD: misc.c,v 1.17 2000/01/15 14:26:00 espie Exp $ */
/* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */
/*
@@ -41,7 +41,7 @@
#if 0
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: misc.c,v 1.16 2000/01/13 17:35:10 espie Exp $";
+static char rcsid[] = "$OpenBSD: misc.c,v 1.17 2000/01/15 14:26:00 espie Exp $";
#endif
#endif /* not lint */
@@ -66,11 +66,11 @@ static size_t strsize = STRSPMAX;
static size_t bufsize = BUFSIZE;
static int low_sp = 0;
-pbent *buf; /* push-back buffer */
-pbent *bufbase; /* the base for current ilevel */
-pbent *bbase[MAXINP]; /* the base for each ilevel */
-pbent *bp; /* first available character */
-static pbent *endpbb; /* end of push-back buffer */
+char *buf; /* push-back buffer */
+char *bufbase; /* the base for current ilevel */
+char *bbase[MAXINP]; /* the base for each ilevel */
+char *bp; /* first available character */
+static char *endpbb; /* end of push-back buffer */
static void enlarge_bufspace __P((void));
@@ -96,8 +96,10 @@ indx(s1, s2)
*/
void
putback(c)
- pbent c;
+ int c;
{
+ if (c == EOF)
+ return;
if (bp >= endpbb)
enlarge_bufspace();
*bp++ = c;
@@ -149,7 +151,7 @@ initspaces()
strspace = xalloc(strsize+1);
ep = strspace;
endest = strspace+strsize;
- buf = (pbent *)xalloc(bufsize * sizeof(pbent));
+ buf = (char *)xalloc(bufsize);
bufbase = buf;
bp = buf;
endpbb = buf + bufsize;
@@ -162,8 +164,8 @@ initspaces()
* duplicate it transparently, and to reclaim the correct
* space when the stack is unwound.
*/
-static
-void enlarge_strspace()
+static void
+enlarge_strspace()
{
char *newstrspace;
@@ -182,14 +184,14 @@ void enlarge_strspace()
endest = strspace + strsize;
}
-static
-void enlarge_bufspace()
+static void
+enlarge_bufspace()
{
- pbent *newbuf;
+ char *newbuf;
int i;
bufsize *= 2;
- newbuf = realloc(buf, bufsize*sizeof(pbent));
+ newbuf = realloc(buf, bufsize);
if (!newbuf)
errx(1, "too many characters pushed back");
for (i = 0; i < MAXINP; i++)
@@ -299,7 +301,9 @@ int
obtain_char(f)
struct input_file *f;
{
- if (f->c == '\n')
+ if (f->c == EOF)
+ return EOF;
+ else if (f->c == '\n')
f->lineno++;
f->c = fgetc(f->file);
@@ -324,6 +328,7 @@ release_input(f)
{
if (f->file != stdin)
fclose(f->file);
+ f->c = EOF;
/*
* XXX can't free filename, as there might still be
* error information pointing to it.