aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);