+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
} 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++;
}
}
- } else if(isprint(c) || isspace(c)) {
+ } else if(isprint(c) || isspace((unsigned char) c)) {
// add char to line
(text->expand)(text, c);
// 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)) {
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) {
}
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;
}
+int next_word(cstring_t *text, int i) {
+ return next_nonblank(text, next_blank(text, i));
+}
+