diff options
Diffstat (limited to 'badroff.c')
-rw-r--r-- | badroff.c | 27 |
1 files changed, 21 insertions, 6 deletions
@@ -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; } |