aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-05-18 23:17:56 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-05-18 23:17:56 -0400
commitb9ad59c4b247708e76a58073c809f85d45d2f3d4 (patch)
tree7220f90fb0b54dede44554a50ef82f3559c34e0d
parent77638505b32fc938c30b24e87f9dde2d8dc39924 (diff)
accumlines now handles multiline
-rw-r--r--badroff.c27
1 files 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;
}