X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=parser.c;h=33466347ed89bb85cd726d4883cf93dc03557619;hb=f92a7609f7b4a6c72a892b16d371528213eca283;hp=9931b02e5ef15b94f7f33b3680843da96a9f443d;hpb=32639324a5ed0b1678d1066680ed6d2e469ae271;p=smdp.git diff --git a/parser.c b/parser.c index 9931b02..3346634 100644 --- a/parser.c +++ b/parser.c @@ -1,3 +1,4 @@ +#include #include #include @@ -80,7 +81,7 @@ deck_t *markdown_load(FILE *input) { } else if(c == '\t') { // expand tab to spaces - for (i = 0; i <= EXPAND_TABS; i++) { + for (i = 0; i < EXPAND_TABS; i++) { (text->expand)(text, ' '); l++; } @@ -171,7 +172,8 @@ deck_t *markdown_load(FILE *input) { // remove line from linked list line->prev->next = line->next; - line->next->prev = line->prev; + if(line->next) + line->next->prev = line->prev; // set bits on revious line if(CHECK_BIT(line->bits, IS_H1)) { @@ -359,12 +361,16 @@ int next_nonblank(cstring_t *text, int i) { ++i; return i; -}; +} int next_blank(cstring_t *text, int i) { while ((i < text->size) && !isspace((text->text)[i])) ++i; return i; -}; +} + +int next_word(cstring_t *text, int i) { + return next_nonblank(text, next_blank(text, i)); +}