From f3dcedb76e54dc3f07a7ec522fad5a32d8f66110 Mon Sep 17 00:00:00 2001
From: Holden Rohrer
Date: Mon, 25 May 2020 01:46:43 -0400
Subject: fixed accumlines multiline handling
the splitting of a string by lines isn't done by replacing \n with \0
but by replacing the char after (with a bit of restructuring)
---
badroff.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/badroff.c b/badroff.c
index e9346c3..385cd3c 100644
--- a/badroff.c
+++ b/badroff.c
@@ -137,13 +137,6 @@ 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;
@@ -153,14 +146,16 @@ llnode* accumlines(size_t* ct){ // returns tail of linked list
free(ln);
break;
}
- size_t len = strlen(ln);
- char* next;
- while ( (next = breakstr(ln, &len))){
- tail->next = appendll(tail, ln);
- tail = tail->next;
+ 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);
--
cgit