1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-02 12:20:51 +00:00

Do not truncate lines longer than 512 chars.

PR:		210344
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D6881
This commit is contained in:
Pietro Cerutti 2016-07-11 08:05:46 +00:00
parent 3e1c325e63
commit 5a4d1cc66f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=302558

View File

@ -78,7 +78,9 @@ struct CHAR {
int c_width; /* width or -1 if multi-column char. filler */
} ;
static struct CHAR obuf[MAXBUF];
static struct CHAR sobuf[MAXBUF]; /* static output buffer */
static struct CHAR *obuf = sobuf;
static int buflen = MAXBUF;
static int col, maxcol;
static int mode;
static int halfpos;
@ -151,6 +153,9 @@ main(int argc, char **argv)
else
filter(f);
}
if (obuf != sobuf) {
free(obuf);
}
exit(0);
}
@ -166,128 +171,148 @@ filter(FILE *f)
{
wint_t c;
int i, w;
int copy;
copy = 0;
while ((c = getwc(f)) != WEOF && col < MAXBUF) switch(c) {
while ((c = getwc(f)) != WEOF) {
if (col == buflen) {
if (obuf == sobuf) {
obuf = NULL;
copy = 1;
}
obuf = realloc(obuf, sizeof(*obuf) * 2 * buflen);
if (obuf == NULL) {
obuf = sobuf;
break;
} else if (copy) {
memcpy(obuf, sobuf, sizeof(*obuf) * buflen);
copy = 0;
}
bzero((char *)(obuf + buflen), sizeof(*obuf) * buflen);
buflen *= 2;
}
switch(c) {
case '\b':
if (col > 0)
col--;
continue;
case '\b':
if (col > 0)
col--;
continue;
case '\t':
col = (col+8) & ~07;
if (col > maxcol)
maxcol = col;
continue;
case '\t':
col = (col+8) & ~07;
if (col > maxcol)
maxcol = col;
continue;
case '\r':
col = 0;
continue;
case '\r':
col = 0;
continue;
case SO:
mode |= ALTSET;
continue;
case SO:
mode |= ALTSET;
continue;
case SI:
mode &= ~ALTSET;
continue;
case SI:
mode &= ~ALTSET;
continue;
case IESC:
switch (c = getwc(f)) {
case IESC:
switch (c = getwc(f)) {
case HREV:
if (halfpos == 0) {
mode |= SUPERSC;
halfpos--;
} else if (halfpos > 0) {
mode &= ~SUBSC;
halfpos--;
} else {
halfpos = 0;
reverse();
}
continue;
case HREV:
if (halfpos == 0) {
mode |= SUPERSC;
halfpos--;
} else if (halfpos > 0) {
mode &= ~SUBSC;
halfpos--;
} else {
halfpos = 0;
case HFWD:
if (halfpos == 0) {
mode |= SUBSC;
halfpos++;
} else if (halfpos < 0) {
mode &= ~SUPERSC;
halfpos++;
} else {
halfpos = 0;
fwd();
}
continue;
case FREV:
reverse();
continue;
default:
errx(1, "unknown escape sequence in input: %o, %o", IESC, c);
}
continue;
case HFWD:
if (halfpos == 0) {
mode |= SUBSC;
halfpos++;
} else if (halfpos < 0) {
mode &= ~SUPERSC;
halfpos++;
} else {
halfpos = 0;
fwd();
case '_':
if (obuf[col].c_char || obuf[col].c_width < 0) {
while (col > 0 && obuf[col].c_width < 0)
col--;
w = obuf[col].c_width;
for (i = 0; i < w; i++)
obuf[col++].c_mode |= UNDERL | mode;
if (col > maxcol)
maxcol = col;
continue;
}
obuf[col].c_char = '_';
obuf[col].c_width = 1;
/* FALLTHROUGH */
case ' ':
col++;
if (col > maxcol)
maxcol = col;
continue;
case FREV:
reverse();
case '\n':
flushln();
continue;
case '\f':
flushln();
putwchar('\f');
continue;
default:
errx(1, "unknown escape sequence in input: %o, %o", IESC, c);
}
continue;
case '_':
if (obuf[col].c_char || obuf[col].c_width < 0) {
while (col > 0 && obuf[col].c_width < 0)
col--;
w = obuf[col].c_width;
for (i = 0; i < w; i++)
obuf[col++].c_mode |= UNDERL | mode;
if ((w = wcwidth(c)) <= 0) /* non printing */
continue;
if (obuf[col].c_char == '\0') {
obuf[col].c_char = c;
for (i = 0; i < w; i++)
obuf[col + i].c_mode = mode;
obuf[col].c_width = w;
for (i = 1; i < w; i++)
obuf[col + i].c_width = -1;
} else if (obuf[col].c_char == '_') {
obuf[col].c_char = c;
for (i = 0; i < w; i++)
obuf[col + i].c_mode |= UNDERL|mode;
obuf[col].c_width = w;
for (i = 1; i < w; i++)
obuf[col + i].c_width = -1;
} else if ((wint_t)obuf[col].c_char == c) {
for (i = 0; i < w; i++)
obuf[col + i].c_mode |= BOLD|mode;
} else {
w = obuf[col].c_width;
for (i = 0; i < w; i++)
obuf[col + i].c_mode = mode;
}
col += w;
if (col > maxcol)
maxcol = col;
continue;
}
obuf[col].c_char = '_';
obuf[col].c_width = 1;
/* FALLTHROUGH */
case ' ':
col++;
if (col > maxcol)
maxcol = col;
continue;
case '\n':
flushln();
continue;
case '\f':
flushln();
putwchar('\f');
continue;
default:
if ((w = wcwidth(c)) <= 0) /* non printing */
continue;
if (obuf[col].c_char == '\0') {
obuf[col].c_char = c;
for (i = 0; i < w; i++)
obuf[col + i].c_mode = mode;
obuf[col].c_width = w;
for (i = 1; i < w; i++)
obuf[col + i].c_width = -1;
} else if (obuf[col].c_char == '_') {
obuf[col].c_char = c;
for (i = 0; i < w; i++)
obuf[col + i].c_mode |= UNDERL|mode;
obuf[col].c_width = w;
for (i = 1; i < w; i++)
obuf[col + i].c_width = -1;
} else if ((wint_t)obuf[col].c_char == c) {
for (i = 0; i < w; i++)
obuf[col + i].c_mode |= BOLD|mode;
} else {
w = obuf[col].c_width;
for (i = 0; i < w; i++)
obuf[col + i].c_mode = mode;
}
col += w;
if (col > maxcol)
maxcol = col;
continue;
}
if (ferror(f))
err(1, NULL);
@ -405,7 +430,7 @@ static void
initbuf(void)
{
bzero((char *)obuf, sizeof (obuf)); /* depends on NORMAL == 0 */
bzero((char *)obuf, buflen * sizeof(*obuf)); /* depends on NORMAL == 0 */
col = 0;
maxcol = 0;
mode &= ALTSET;