diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-05-18 23:17:56 -0400 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-05-18 23:17:56 -0400 |
commit | b9ad59c4b247708e76a58073c809f85d45d2f3d4 (patch) | |
tree | 7220f90fb0b54dede44554a50ef82f3559c34e0d | |
parent | 77638505b32fc938c30b24e87f9dde2d8dc39924 (diff) |
accumlines now handles multiline
-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; } |