Fixed bug where long lines (>1023 characters in current implementation)

were viewed as multiple lines by both standard input and ~<file.
Closes PR 3463.
This commit is contained in:
phil 1997-07-07 22:57:52 +00:00
parent 5c2a76b304
commit a8316bbccd
3 changed files with 30 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: collect.c,v 1.7 1997/05/17 19:55:12 pk Exp $ */
/* $NetBSD: collect.c,v 1.8 1997/07/07 22:57:52 phil Exp $ */
/*
* Copyright (c) 1980, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)collect.c 8.2 (Berkeley) 4/19/94";
#else
static char rcsid[] = "$NetBSD: collect.c,v 1.7 1997/05/17 19:55:12 pk Exp $";
static char rcsid[] = "$NetBSD: collect.c,v 1.8 1997/07/07 22:57:52 phil Exp $";
#endif
#endif /* not lint */
@ -86,6 +86,8 @@ collect(hp, printheaders)
extern char *tempMail;
char getsub;
sigset_t oset, nset;
int longline, lastlong, rc; /* So we don't make 2 or more lines
out of a long input line. */
#if __GNUC__
/* Avoid longjmp clobbering */
(void) &escape;
@ -142,6 +144,8 @@ collect(hp, printheaders)
escape = ESCAPE;
eofcount = 0;
hadintr = 0;
lastlong = 0;
longline = 0;
if (!setjmp(colljmp)) {
if (getsub)
@ -174,14 +178,17 @@ cont:
}
break;
}
lastlong = longline;
longline = c == LINESIZE-1;
eofcount = 0;
hadintr = 0;
if (linebuf[0] == '.' && linebuf[1] == '\0' &&
value("interactive") != NOSTR &&
value("interactive") != NOSTR && !lastlong &&
(value("dot") != NOSTR || value("ignoreeof") != NOSTR))
break;
if (linebuf[0] != escape || value("interactive") == NOSTR) {
if (putline(collf, linebuf) < 0)
if (linebuf[0] != escape || value("interactive") == NOSTR ||
lastlong) {
if (putline(collf, linebuf, !longline) < 0)
goto err;
continue;
}
@ -193,7 +200,7 @@ cont:
* Otherwise, it's an error.
*/
if (c == escape) {
if (putline(collf, &linebuf[1]) < 0)
if (putline(collf, &linebuf[1], !longline) < 0)
goto err;
else
break;
@ -298,9 +305,10 @@ cont:
fflush(stdout);
lc = 0;
cc = 0;
while (readline(fbuf, linebuf, LINESIZE) >= 0) {
lc++;
if ((t = putline(collf, linebuf)) < 0) {
while ((rc = readline(fbuf, linebuf, LINESIZE)) >= 0) {
if (rc != LINESIZE-1) lc++;
if ((t = putline(collf, linebuf,
rc != LINESIZE-1)) < 0) {
Fclose(fbuf);
goto err;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.5 1996/12/28 07:11:01 tls Exp $ */
/* $NetBSD: extern.h,v 1.6 1997/07/07 22:57:53 phil Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -33,7 +33,7 @@
* SUCH DAMAGE.
*
* @(#)extern.h 8.2 (Berkeley) 4/20/95
* $NetBSD: extern.h,v 1.5 1996/12/28 07:11:01 tls Exp $
* $NetBSD: extern.h,v 1.6 1997/07/07 22:57:53 phil Exp $
*/
struct name;
@ -200,7 +200,7 @@ void prettyprint __P((struct name *));
void printgroup __P((char []));
void printhead __P((int));
int puthead __P((struct header *, FILE *, int));
int putline __P((FILE *, char *));
int putline __P((FILE *, char *, int));
int pversion __P((void *));
void quit __P((void));
int quitcmd __P((void *));

View File

@ -1,4 +1,4 @@
/* $NetBSD: fio.c,v 1.7 1997/05/13 06:15:54 mikel Exp $ */
/* $NetBSD: fio.c,v 1.8 1997/07/07 22:57:55 phil Exp $ */
/*
* Copyright (c) 1980, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)fio.c 8.2 (Berkeley) 4/20/95";
#else
static char rcsid[] = "$NetBSD: fio.c,v 1.7 1997/05/13 06:15:54 mikel Exp $";
static char rcsid[] = "$NetBSD: fio.c,v 1.8 1997/07/07 22:57:55 phil Exp $";
#endif
#endif /* not lint */
@ -163,21 +163,25 @@ setptr(ibuf, offset)
/*
* Drop the passed line onto the passed output buffer.
* If a write error occurs, return -1, else the count of
* characters written, including the newline.
* characters written, including the newline if requested.
*/
int
putline(obuf, linebuf)
putline(obuf, linebuf, outlf)
FILE *obuf;
char *linebuf;
int outlf;
{
register int c;
c = strlen(linebuf);
(void) fwrite(linebuf, sizeof *linebuf, c, obuf);
(void) putc('\n', obuf);
if (outlf) {
(void) putc('\n', obuf);
c++;
}
if (ferror(obuf))
return (-1);
return (c + 1);
return (c);
}
/*