summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed
diff options
context:
space:
mode:
authorarchie <archie@FreeBSD.org>1998-12-08 21:29:22 +0000
committerarchie <archie@FreeBSD.org>1998-12-08 21:29:22 +0000
commite11c48f4b11b75b26ff4f5bd1a3a16a9a0934561 (patch)
treed1e77bd59cef6652d070bd1547a2ad21c6b3c287 /usr.bin/sed
parent80e25474dbac23ca21683a91ee989a5db243b32b (diff)
downloadFreeBSD-src-e11c48f4b11b75b26ff4f5bd1a3a16a9a0934561.zip
FreeBSD-src-e11c48f4b11b75b26ff4f5bd1a3a16a9a0934561.tar.gz
Fix a new bug introduced by the previous bug fix
Diffstat (limited to 'usr.bin/sed')
-rw-r--r--usr.bin/sed/compile.c13
-rw-r--r--usr.bin/sed/extern.h2
-rw-r--r--usr.bin/sed/main.c18
3 files changed, 23 insertions, 10 deletions
diff --git a/usr.bin/sed/compile.c b/usr.bin/sed/compile.c
index bf0b56f..1313fca 100644
--- a/usr.bin/sed/compile.c
+++ b/usr.bin/sed/compile.c
@@ -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();
diff --git a/usr.bin/sed/extern.h b/usr.bin/sed/extern.h
index a80f7c9..584ac6f 100644
--- a/usr.bin/sed/extern.h
+++ b/usr.bin/sed/extern.h
@@ -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 *));
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index 6e1ef35..353dedb 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -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 @@ again:
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 @@ again:
if (n-- <= 1) {
*p = '\0';
linenum++;
+ if (more != NULL)
+ *more = 1;
return (buf);
}
switch (*s) {
@@ -241,6 +249,8 @@ again:
script = script->next;
*p = '\0';
linenum++;
+ if (more != NULL)
+ *more = 0;
return (buf);
}
case '\n':
@@ -248,6 +258,8 @@ again:
*p = '\0';
s++;
linenum++;
+ if (more != NULL)
+ *more = 0;
return (buf);
default:
*p++ = *s++;
OpenPOWER on IntegriCloud