aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-05-25 01:46:43 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-05-25 01:46:46 -0400
commitf3dcedb76e54dc3f07a7ec522fad5a32d8f66110 (patch)
tree8f511ef3f898dfda8d67332bf23820af5ab2393b
parent4e7a7784a4847805077b97cfd1b09cb0595a2507 (diff)
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)
-rw-r--r--badroff.c21
1 files 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);