aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-05-29 01:03:09 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-05-29 01:03:09 -0400
commit6d961236c9a1802de28ed300f7c345cc69a1550f (patch)
tree5b64e9894e171d686ec10a8603a234b3c81e06d9
parent7410b071bd7104a911e1b7e813c7677ee72c7cb1 (diff)
moved accumlines to make foldlines closer to multbreak
-rw-r--r--badroff.c53
1 files 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);