X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=parser.c;h=1ff125c69775ca61ce981e10f5216a26ed7fbff3;hb=d2546ae4a3dc3424f9357aea800880b0dd49486f;hp=33466347ed89bb85cd726d4883cf93dc03557619;hpb=f92a7609f7b4a6c72a892b16d371528213eca283;p=smdp.git
diff --git a/parser.c b/parser.c
index 3346634..1ff125c 100644
--- a/parser.c
+++ b/parser.c
@@ -1,3 +1,26 @@
+/*
+ * Functions necessary to parse a file and transform its content into
+ * a deck of slides containing lines. All based on markdown formating
+ * rules.
+ * Copyright (C) 2014 Michael Goehler
+ *
+ * This file is part of mdp.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
#include
#include
#include
@@ -16,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
@@ -29,9 +53,15 @@ deck_t *markdown_load(FILE *input) {
// markdown analyse
bits = markdown_analyse(text);
+ // if first line in file is markdown hr
+ if(!line && CHECK_BIT(bits, IS_HR)) {
+
+ // clear text
+ (text->reset)(text);
+
// if text is markdown hr
- if(CHECK_BIT(bits, IS_HR) &&
- CHECK_BIT(line->bits, IS_EMPTY)) {
+ } else if(CHECK_BIT(bits, IS_HR) &&
+ CHECK_BIT(line->bits, IS_EMPTY)) {
slide->lines = lc;
@@ -110,7 +140,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);
@@ -175,7 +205,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 {
@@ -185,9 +215,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;
}
@@ -212,7 +246,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) {
@@ -357,14 +391,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;