On Wed, 27 Sep 2023 08:37:49 -0300, Crystal Kolipe wrote: > So what do we want? > > 1. Traditional OpenBSD behaviour of breaking input lines at 2047, > (which never actually worked correctly up to now). > 2. Breaking input at 2048. > 3. Support for arbitrary line length with no breaking. > > Presumably nobody is relying on the current behaviour in scripts or other > code, as it's always been broken.
I think we want support for arbitrary line lengths. There is only one place where we need to reallocate the line buffer. - todd Index: usr.bin/deroff/deroff.c =================================================================== RCS file: /cvs/src/usr.bin/deroff/deroff.c,v retrieving revision 1.17 diff -u -p -u -r1.17 deroff.c --- usr.bin/deroff/deroff.c 8 Mar 2023 04:43:10 -0000 1.17 +++ usr.bin/deroff/deroff.c 27 Sep 2023 16:56:54 -0000 @@ -135,7 +135,8 @@ int keepblock; /* keep blocks of text; n char chars[128]; /* SPECIAL, PUNCT, APOS, DIGIT, or LETTER */ -char line[LINE_MAX]; +size_t linesz; +char *line; char *lp; int c; @@ -342,6 +343,10 @@ main(int ac, char **av) files[0] = infile; filesp = &files[0]; + linesz = LINE_MAX; + if ((line = malloc(linesz)) == NULL) + err(1, NULL); + for (i = 'a'; i <= 'z'; ++i) chars[i] = LETTER; for (i = 'A'; i <= 'Z'; ++i) @@ -477,7 +482,15 @@ regline(void (*pfunc)(char *, int), int line[0] = c; lp = line; - while (lp - line < sizeof(line)) { + for (;;) { + if (lp - line == linesz - 2) { + char *newline = reallocarray(line, linesz, 2); + if (newline == NULL) + err(1, NULL); + lp = newline + (lp - line); + line = newline; + linesz *= 2; + } if (c == '\\') { *lp = ' '; backsl();