Fix a new bug introduced by the previous bug fix
This commit is contained in:
parent
290e3eed11
commit
c56690ef7b
@ -40,7 +40,7 @@
|
||||
static char sccsid[] = "@(#)compile.c 8.1 (Berkeley) 6/6/93";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id: compile.c,v 1.10 1998/09/22 18:39:47 brian Exp $";
|
||||
"$Id: compile.c,v 1.11 1998/12/07 05:35:54 archie Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -160,7 +160,7 @@ compile_stream(link)
|
||||
|
||||
stack = 0;
|
||||
for (;;) {
|
||||
if ((p = cu_fgets(lbuf, sizeof(lbuf))) == NULL) {
|
||||
if ((p = cu_fgets(lbuf, sizeof(lbuf), NULL)) == NULL) {
|
||||
if (stack != 0)
|
||||
errx(1, "%lu: %s: unexpected EOF (pending }'s)",
|
||||
linenum, fname);
|
||||
@ -456,6 +456,7 @@ compile_subst(p, s)
|
||||
static char lbuf[_POSIX2_LINE_MAX + 1];
|
||||
int asize, ref, size;
|
||||
char c, *text, *op, *sp;
|
||||
int more = 0;
|
||||
|
||||
c = *p++; /* Terminator character */
|
||||
if (c == '\0')
|
||||
@ -483,8 +484,8 @@ compile_subst(p, s)
|
||||
} else if (*p == '&' || *p == '\\')
|
||||
*sp++ = '\\';
|
||||
} else if (*p == c) {
|
||||
if (*++p == '\0') {
|
||||
if (cu_fgets(lbuf, sizeof(lbuf)))
|
||||
if (*++p == '\0' && more) {
|
||||
if (cu_fgets(lbuf, sizeof(lbuf), &more))
|
||||
p = lbuf;
|
||||
}
|
||||
*sp++ = '\0';
|
||||
@ -503,7 +504,7 @@ compile_subst(p, s)
|
||||
asize *= 2;
|
||||
text = xrealloc(text, asize);
|
||||
}
|
||||
} while (cu_fgets(p = lbuf, sizeof(lbuf)));
|
||||
} while (cu_fgets(p = lbuf, sizeof(lbuf), &more));
|
||||
errx(1, "%lu: %s: unterminated substitute in regular expression",
|
||||
linenum, fname);
|
||||
/* NOTREACHED */
|
||||
@ -636,7 +637,7 @@ compile_text()
|
||||
asize = 2 * _POSIX2_LINE_MAX + 1;
|
||||
text = xmalloc(asize);
|
||||
size = 0;
|
||||
while (cu_fgets(lbuf, sizeof(lbuf))) {
|
||||
while (cu_fgets(lbuf, sizeof(lbuf), NULL)) {
|
||||
op = s = text + size;
|
||||
p = lbuf;
|
||||
EATSPACE();
|
||||
|
@ -50,7 +50,7 @@ extern char *fname;
|
||||
void cfclose __P((struct s_command *, struct s_command *));
|
||||
void compile __P((void));
|
||||
void cspace __P((SPACE *, char *, size_t, enum e_spflag));
|
||||
char *cu_fgets __P((char *, int));
|
||||
char *cu_fgets __P((char *, int, int *));
|
||||
int mf_fgets __P((SPACE *, enum e_spflag));
|
||||
void process __P((void));
|
||||
char *strregerror __P((int, regex_t *));
|
||||
|
@ -46,7 +46,7 @@ static const char copyright[] =
|
||||
static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/3/94";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
"$Id: main.c,v 1.7 1997/08/11 07:21:03 charnier Exp $";
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -176,9 +176,10 @@ usage()
|
||||
* together. Empty strings and files are ignored.
|
||||
*/
|
||||
char *
|
||||
cu_fgets(buf, n)
|
||||
cu_fgets(buf, n, more)
|
||||
char *buf;
|
||||
int n;
|
||||
int *more;
|
||||
{
|
||||
static enum {ST_EOF, ST_FILE, ST_STRING} state = ST_EOF;
|
||||
static FILE *f; /* Current open file */
|
||||
@ -189,8 +190,11 @@ cu_fgets(buf, n)
|
||||
again:
|
||||
switch (state) {
|
||||
case ST_EOF:
|
||||
if (script == NULL)
|
||||
if (script == NULL) {
|
||||
if (more != NULL)
|
||||
*more = 0;
|
||||
return (NULL);
|
||||
}
|
||||
linenum = 0;
|
||||
switch (script->type) {
|
||||
case CU_FILE:
|
||||
@ -215,6 +219,8 @@ cu_fgets(buf, n)
|
||||
linenum++;
|
||||
if (linenum == 1 && buf[0] == '#' && buf[1] == 'n')
|
||||
nflag = 1;
|
||||
if (more != NULL)
|
||||
*more = !feof(f);
|
||||
return (p);
|
||||
}
|
||||
script = script->next;
|
||||
@ -229,6 +235,8 @@ cu_fgets(buf, n)
|
||||
if (n-- <= 1) {
|
||||
*p = '\0';
|
||||
linenum++;
|
||||
if (more != NULL)
|
||||
*more = 1;
|
||||
return (buf);
|
||||
}
|
||||
switch (*s) {
|
||||
@ -241,6 +249,8 @@ cu_fgets(buf, n)
|
||||
script = script->next;
|
||||
*p = '\0';
|
||||
linenum++;
|
||||
if (more != NULL)
|
||||
*more = 0;
|
||||
return (buf);
|
||||
}
|
||||
case '\n':
|
||||
@ -248,6 +258,8 @@ cu_fgets(buf, n)
|
||||
*p = '\0';
|
||||
s++;
|
||||
linenum++;
|
||||
if (more != NULL)
|
||||
*more = 0;
|
||||
return (buf);
|
||||
default:
|
||||
*p++ = *s++;
|
||||
|
Loading…
Reference in New Issue
Block a user