version 1.16, 2000/01/13 17:35:10 |
version 1.17, 2000/01/15 14:26:00 |
|
|
static size_t bufsize = BUFSIZE; |
static size_t bufsize = BUFSIZE; |
static int low_sp = 0; |
static int low_sp = 0; |
|
|
pbent *buf; /* push-back buffer */ |
char *buf; /* push-back buffer */ |
pbent *bufbase; /* the base for current ilevel */ |
char *bufbase; /* the base for current ilevel */ |
pbent *bbase[MAXINP]; /* the base for each ilevel */ |
char *bbase[MAXINP]; /* the base for each ilevel */ |
pbent *bp; /* first available character */ |
char *bp; /* first available character */ |
static pbent *endpbb; /* end of push-back buffer */ |
static char *endpbb; /* end of push-back buffer */ |
|
|
|
|
static void enlarge_bufspace __P((void)); |
static void enlarge_bufspace __P((void)); |
|
|
*/ |
*/ |
void |
void |
putback(c) |
putback(c) |
pbent c; |
int c; |
{ |
{ |
|
if (c == EOF) |
|
return; |
if (bp >= endpbb) |
if (bp >= endpbb) |
enlarge_bufspace(); |
enlarge_bufspace(); |
*bp++ = c; |
*bp++ = c; |
|
|
strspace = xalloc(strsize+1); |
strspace = xalloc(strsize+1); |
ep = strspace; |
ep = strspace; |
endest = strspace+strsize; |
endest = strspace+strsize; |
buf = (pbent *)xalloc(bufsize * sizeof(pbent)); |
buf = (char *)xalloc(bufsize); |
bufbase = buf; |
bufbase = buf; |
bp = buf; |
bp = buf; |
endpbb = buf + bufsize; |
endpbb = buf + bufsize; |
|
|
* duplicate it transparently, and to reclaim the correct |
* duplicate it transparently, and to reclaim the correct |
* space when the stack is unwound. |
* space when the stack is unwound. |
*/ |
*/ |
static |
static void |
void enlarge_strspace() |
enlarge_strspace() |
{ |
{ |
char *newstrspace; |
char *newstrspace; |
|
|
|
|
endest = strspace + strsize; |
endest = strspace + strsize; |
} |
} |
|
|
static |
static void |
void enlarge_bufspace() |
enlarge_bufspace() |
{ |
{ |
pbent *newbuf; |
char *newbuf; |
int i; |
int i; |
|
|
bufsize *= 2; |
bufsize *= 2; |
newbuf = realloc(buf, bufsize*sizeof(pbent)); |
newbuf = realloc(buf, bufsize); |
if (!newbuf) |
if (!newbuf) |
errx(1, "too many characters pushed back"); |
errx(1, "too many characters pushed back"); |
for (i = 0; i < MAXINP; i++) |
for (i = 0; i < MAXINP; i++) |
|
|
obtain_char(f) |
obtain_char(f) |
struct input_file *f; |
struct input_file *f; |
{ |
{ |
if (f->c == '\n') |
if (f->c == EOF) |
|
return EOF; |
|
else if (f->c == '\n') |
f->lineno++; |
f->lineno++; |
|
|
f->c = fgetc(f->file); |
f->c = fgetc(f->file); |
|
|
{ |
{ |
if (f->file != stdin) |
if (f->file != stdin) |
fclose(f->file); |
fclose(f->file); |
|
f->c = EOF; |
/* |
/* |
* XXX can't free filename, as there might still be |
* XXX can't free filename, as there might still be |
* error information pointing to it. |
* error information pointing to it. |