diff options
-rw-r--r-- | badroff.c | 53 |
1 files changed, 27 insertions, 26 deletions
@@ -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); |