X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=parser.c;h=8489ab03372e16c387846d3d6947a585e2b4823f;hb=2c77b5e6e665dcce85cc22d7673573c46137593d;hp=dc2677d1d33e59ce63d5ad7edfd54aa8b152bd56;hpb=d4843ea375360f37e965709e73c0fbd68e302dca;p=smdp.git diff --git a/parser.c b/parser.c index dc2677d..8489ab0 100644 --- a/parser.c +++ b/parser.c @@ -39,7 +39,8 @@ deck_t *markdown_load(FILE *input) { deck_t *deck = new_deck(); slide_t *slide = new_slide(); - line_t *line; + line_t *line = NULL; + line_t *tmp = NULL; cstring_t *text = cstring_init(); // assign first slide to deck @@ -133,7 +134,7 @@ deck_t *markdown_load(FILE *input) { } - } else if(isprint(c) || isspace(c)) { + } else if(isprint(c) || isspace((unsigned char) c)) { // add char to line (text->expand)(text, c); @@ -198,7 +199,7 @@ deck_t *markdown_load(FILE *input) { if(line->next) line->next->prev = line->prev; - // set bits on revious line + // set bits on previous line if(CHECK_BIT(line->bits, IS_H1)) { SET_BIT(line->prev->bits, IS_H1); } else { @@ -208,9 +209,13 @@ deck_t *markdown_load(FILE *input) { // adjust line count slide->lines -= 1; + // maintain loop condition + tmp = line; + line = line->prev; + // delete line - (line->text->delete)(line->text); - free(line); + (tmp->text->delete)(tmp->text); + free(tmp); } line = line->next; } @@ -235,7 +240,7 @@ int markdown_analyse(cstring_t *text) { offset = next_nonblank(text, 0); // strip trailing spaces - for(eol = text->size; eol > offset && isspace(text->text[eol - 1]); eol--); + for(eol = text->size; eol > offset && isspace((unsigned char) text->text[eol - 1]); eol--); // IS_CODE if(offset >= CODE_INDENT) { @@ -380,14 +385,14 @@ int length_utf8(char ch) { } int next_nonblank(cstring_t *text, int i) { - while ((i < text->size) && isspace((text->text)[i])) + while ((i < text->size) && isspace((unsigned char) (text->text)[i])) ++i; return i; } int next_blank(cstring_t *text, int i) { - while ((i < text->size) && !isspace((text->text)[i])) + while ((i < text->size) && !isspace((unsigned char) (text->text)[i])) ++i; return i;