diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c index 0e77c6b6653d..59fde31138b4 100644 --- a/usr.bin/m4/eval.c +++ b/usr.bin/m4/eval.c @@ -378,8 +378,8 @@ expand(argv, argc) register char *argv[]; register int argc; { - register char *t; - register char *p; + register unsigned char *t; + register unsigned char *p; register int n; register int argno; @@ -688,7 +688,7 @@ dosub(argv, argc) register char *argv[]; register int argc; { - register char *ap, *fc, *k; + register unsigned char *ap, *fc, *k; register int nc; if (argc < 5) diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h index b54a9b975a9c..a8df3ebbab83 100644 --- a/usr.bin/m4/extern.h +++ b/usr.bin/m4/extern.h @@ -65,7 +65,7 @@ void map __P((char *, char *, char *, char *)); void onintr __P((int)); void oops __P((const char *, ...)); void pbnum __P((int)); -void pbstr __P((char *)); +void pbstr __P((unsigned char *)); void putback __P((int)); void remhash __P((char *, int)); void usage __P((void)); @@ -79,13 +79,13 @@ 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 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 unsigned char *bp; /* first available character */ +extern unsigned char buf[]; /* push-back buffer */ +extern unsigned char *bufbase; /* buffer base for this ilevel */ +extern unsigned char *bbase[]; /* buffer base per ilevel */ extern char ecommt; /* end character for comment */ extern char *endest; /* end of string space */ -extern char *endpbb; /* end of push-back buffer */ +extern unsigned char *endpbb; /* end of push-back buffer */ extern char *ep; /* first free char in strspace */ extern char lquote; /* left quote character (`) */ extern char *m4temp; /* filename for diversions */ diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c index 221b865a9b64..d16bbf15655c 100644 --- a/usr.bin/m4/main.c +++ b/usr.bin/m4/main.c @@ -63,11 +63,11 @@ static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #include "pathnames.h" ndptr hashtab[HASHSIZE]; /* hash table for macros etc. */ -char buf[BUFSIZE]; /* push-back buffer */ -char *bufbase = buf; /* the base for current ilevel */ -char *bbase[MAXINP]; /* the base for each ilevel */ -char *bp = buf; /* first available character */ -char *endpbb = buf+BUFSIZE; /* end of push-back buffer */ +unsigned char buf[BUFSIZE]; /* push-back buffer */ +unsigned char *bufbase = buf; /* the base for current ilevel */ +unsigned char *bbase[MAXINP]; /* the base for each ilevel */ +unsigned char *bp = buf; /* first available character */ +unsigned char *endpbb = buf+BUFSIZE; /* end of push-back buffer */ stae mstack[STACKMAX+1]; /* stack of m4 machine */ char strspace[STRSPMAX+1]; /* string space for evaluation */ char *ep = strspace; /* first free char in strspace */ @@ -248,7 +248,7 @@ macro() { register int nlpar; cycle { - if ((t = gpbc()) == '_' || isalpha(t)) { + if ((t = gpbc()) == '_' || (t != EOF && isalpha(t))) { putback(t); if ((p = inspect(s = token)) == nil) { if (sp < 0) @@ -327,7 +327,7 @@ macro() { case LPAREN: if (PARLEV > 0) chrsave(t); - while (isspace(l = gpbc())) + while ((l = gpbc()) != EOF && isspace(l)) ; /* skip blank, tab, nl.. */ putback(l); PARLEV++; @@ -356,7 +356,7 @@ macro() { case COMMA: if (PARLEV == 1) { chrsave(EOS); /* new argument */ - while (isspace(l = gpbc())) + while ((l = gpbc()) != EOF && isspace(l)) ; putback(l); pushs(ep); @@ -380,13 +380,13 @@ ndptr inspect(tp) register char *tp; { - register char c; + register int c; register char *name = tp; register char *etp = tp+MAXTOK; register ndptr p; register unsigned long h = 0; - while ((isalnum(c = gpbc()) || c == '_') && tp < etp) + while ((c = gpbc()) != EOF && (isalnum(c) || c == '_') && tp < etp) h = (h << 5) + h + (*tp++ = c); putback(c); if (tp == etp) diff --git a/usr.bin/m4/mdef.h b/usr.bin/m4/mdef.h index cc256b012b3e..239993a44ade 100644 --- a/usr.bin/m4/mdef.h +++ b/usr.bin/m4/mdef.h @@ -142,7 +142,7 @@ typedef union { /* stack structure */ * pushf() - push a call frame entry onto stack * pushs() - push a string pointer onto stack */ -#define gpbc() (bp > bufbase) ? *--bp : getc(infile[ilevel]) +#define gpbc() (bp > bufbase) ? (*--bp ? *bp : EOF) : getc(infile[ilevel]) #define pushf(x) if (sp < STACKMAX) mstack[++sp].sfra = (x) #define pushs(x) if (sp < STACKMAX) mstack[++sp].sstr = (x) diff --git a/usr.bin/m4/misc.c b/usr.bin/m4/misc.c index 2ed115bac4c6..916edbac41e4 100644 --- a/usr.bin/m4/misc.c +++ b/usr.bin/m4/misc.c @@ -73,8 +73,10 @@ char *s2; */ void putback(c) -char c; +int c; { + if (c == EOF) + c = 0; if (bp < endpbb) *bp++ = c; else @@ -88,10 +90,10 @@ char c; */ void pbstr(s) -register char *s; +register unsigned char *s; { - register char *es; - register char *zp; + register unsigned char *es; + register unsigned char *zp; es = s; zp = bp;