From b9ad59c4b247708e76a58073c809f85d45d2f3d4 Mon Sep 17 00:00:00 2001
From: Holden Rohrer
Date: Mon, 18 May 2020 23:17:56 -0400
Subject: accumlines now handles multiline
---
badroff.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/badroff.c b/badroff.c
index e73dd99..5324aae 100644
--- a/badroff.c
+++ b/badroff.c
@@ -133,18 +133,33 @@ void multbreak(sb* buffer, size_t start,
}
}
}
+char* breakstr(char* str, size_t* len){
+ char* loc = memchr(str, '\n', *len);
+ if (!loc) return NULL; //essentially truncates "abc\nabc" to "abc\n"
+ *len -= loc-str;
+ *loc = 0; // should always be \n$
+ return loc+1;
+}
llnode* accumlines(size_t* ct){ // returns tail of linked list
llnode *head, *tail; head = tail = appendll(NULL, NULL);
(*ct) = 0;
- while (true){
- tail->next = appendll(tail, line());
- if (endgroup) break;
- (*ct)++;
- tail = tail->next;
+ while (!endgroup){
+ char* ln = line();
+ size_t len = strlen(ln);
+ char* next;
+ while ( (next = breakstr(ln, &len))){
+ printf("line %s\n",ln);
+ tail->next = appendll(tail, ln);
+ tail = tail->next;
+ (*ct)++;
+ printf("added\n");
+ ln = next;
+ };
+ printf("loop\n");
}
- free(tail->next->str); free(tail->next); //.ELS cmd
tail->next = head->next; // loop linked list
free(head);
+ printf("here\n");
endgroup = false; // prevents false positive on next run
return tail;
}
--
cgit