From: Michael Göhler Date: Wed, 20 Aug 2014 22:48:55 +0000 (+0200) Subject: move debug function to parser.c X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=3b1d8241131284a13ca059f399d7113075daf351;p=smdp.git move debug function to parser.c --- diff --git a/include/parser.h b/include/parser.h index 091c3d5..14bb232 100644 --- a/include/parser.h +++ b/include/parser.h @@ -5,6 +5,7 @@ document_t *markdown_load(FILE *input); int markdown_analyse(cstring_t *text); +void markdown_debug(document_t *doc, int debug); int is_utf8(char ch); int length_utf8(char ch); int next_nonblank(cstring_t *text, int i); diff --git a/parser.c b/parser.c index fddd8d8..254c084 100644 --- a/parser.c +++ b/parser.c @@ -232,6 +232,49 @@ int markdown_analyse(cstring_t *text) { return bits; } +void markdown_debug(document_t *doc, int debug) { + + // print header to STDERR + int offset; + line_t *header; + if(doc->header) { + header = doc->header; + while(header && + header->length > 0 && + header->text->text[0] == '%') { + + offset = next_blank(header->text, 0) + 1; + fprintf(stderr, "header: %s\n", &header->text->text[offset]); + header = header->next; + } + } + + // print page/line count to STDERR + int cp = 0, cl = 0; + page_t *page = doc->page; + line_t *line; + while(page) { + cp++; + if(debug > 1) { + fprintf(stderr, "page %i:\n", cp); + } + line = page->line; + cl = 0; + while(line) { + cl++; + if(debug > 1) { + fprintf(stderr, " line %i: bits = %i, length = %i\n", cl, line->bits, line->length); + } + line = line->next; + } + if(debug == 1) { + fprintf(stderr, "page %i: %i lines\n", cp, cl); + } + page = page->next; + } +} + + int is_utf8(char ch) { return (ch & 0x80); } diff --git a/tmp.c b/tmp.c index 33b8603..7e8589e 100644 --- a/tmp.c +++ b/tmp.c @@ -63,44 +63,7 @@ int main(int argc, char *argv[]) { doc = markdown_load(input); if(debug > 0) { - // print header to STDERR - int offset; - line_t *header; - if(doc->header) { - header = doc->header; - while(header && - header->length > 0 && - header->text->text[0] == '%') { - - offset = next_blank(header->text, 0) + 1; - fprintf(stderr, "header: %s\n", &header->text->text[offset]); - header = header->next; - } - } - - // print page/line count to STDERR - int cp = 0, cl = 0; - page_t *page = doc->page; - line_t *line; - while(page) { - cp++; - if(debug > 1) { - fprintf(stderr, "page %i:\n", cp); - } - line = page->line; - cl = 0; - while(line) { - cl++; - if(debug > 1) { - fprintf(stderr, " line %i: bits = %i, length = %i\n", cl, line->bits, line->length); - } - line = line->next; - } - if(debug == 1) { - fprintf(stderr, "page %i: %i lines\n", cp, cl); - } - page = page->next; - } + markdown_debug(doc, debug); } }