From 6d961236c9a1802de28ed300f7c345cc69a1550f Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Fri, 29 May 2020 01:03:09 -0400 Subject: moved accumlines to make foldlines closer to multbreak --- badroff.c | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/badroff.c b/badroff.c index 7716e85..7814d62 100644 --- a/badroff.c +++ b/badroff.c @@ -158,31 +158,6 @@ static void multbreak(sb* buffer, size_t start, } } } -static llnode* accumlines(size_t* ct){ // returns tail of linked list - llnode *head, *tail; head = tail = appendll(NULL, NULL); - (*ct) = 0; - while (!endgroup){ - char* ln = line(); - if (!ln[0]) { // ln == "" - free(ln); - break; - } - char* next; //greater than nl - while ( (next = strchr(ln, '\n')) ) { - next++; - char sub = *next; - *next = 0; - tail = appendll(tail, ln); - (*ct)++; - *next = sub; - ln = next; - } - } - tail->next = head->next; // loop linked list - free(head); - endgroup = false; // prevents false positive on next run - return tail; -} static char* foldlines(llnode* tail, size_t ct){ sb* buf = newsb(100); @@ -203,16 +178,42 @@ static char* foldlines(llnode* tail, size_t ct){ tail = tail->next; } while (tail != orig); if (valid) brk = i; - if (done || (!valid && i-oldbrk >= width)){ + if (done || (brk != -1 && !valid && i-oldbrk >= width)){ // either all strings are done // or it has hit a non-space column and accum enough space multbreak(buf, oldbrk, brk-oldbrk+1, &tail, &ct); oldbrk = brk+1; // tells offset from previous cut + brk = -1; } } return decompose(buf); } +static llnode* accumlines(size_t* ct){ // returns tail of linked list + llnode *head, *tail; head = tail = appendll(NULL, NULL); + (*ct) = 0; + while (!endgroup){ + char* ln = line(); + if (!ln[0]) { // ln == "" + free(ln); + break; + } + char* next; //greater than nl + while ( (next = strchr(ln, '\n')) ) { + next++; + char sub = *next; + *next = 0; + tail = appendll(tail, ln); + (*ct)++; + *next = sub; + ln = next; + } + } + tail->next = head->next; // loop linked list + free(head); + endgroup = false; // prevents false positive on next run + return tail; +} static char* lineset(char* txt){ size_t ct; llnode* tail = accumlines(&ct); -- cgit