From: Michael Göhler Date: Mon, 25 Aug 2014 07:34:54 +0000 (+0200) Subject: rename objects to deck / slide X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=9dec35aae55c1d122523458b0c92ec1eea16fbdc;p=smdp.git rename objects to deck / slide --- diff --git a/include/markdown.h b/include/markdown.h index dc759e0..d1d05f2 100644 --- a/include/markdown.h +++ b/include/markdown.h @@ -27,21 +27,21 @@ typedef struct _line_t { int offset; } line_t; -typedef struct _page_t { +typedef struct _slide_t { line_t *line; - struct _page_t *prev; - struct _page_t *next; -} page_t; + struct _slide_t *prev; + struct _slide_t *next; +} slide_t; -typedef struct _document_t { +typedef struct _deck_t { line_t *header; - page_t *page; -} document_t; + slide_t *slide; +} deck_t; line_t *new_line(); line_t *next_line(line_t *prev); -page_t *new_page(); -page_t *next_page(page_t *prev); -document_t *new_document(); +slide_t *new_slide(); +slide_t *next_slide(slide_t *prev); +deck_t *new_deck(); #endif // !defined( MARKDOWN_H ) diff --git a/include/parser.h b/include/parser.h index 14bb232..89e1a5d 100644 --- a/include/parser.h +++ b/include/parser.h @@ -3,9 +3,9 @@ #include "markdown.h" -document_t *markdown_load(FILE *input); +deck_t *markdown_load(FILE *input); int markdown_analyse(cstring_t *text); -void markdown_debug(document_t *doc, int debug); +void markdown_debug(deck_t *deck, int debug); int is_utf8(char ch); int length_utf8(char ch); int next_nonblank(cstring_t *text, int i); diff --git a/markdown.c b/markdown.c index 0d42005..aaa1554 100644 --- a/markdown.c +++ b/markdown.c @@ -19,24 +19,24 @@ line_t *next_line(line_t *prev) { return x; } -page_t *new_page() { - page_t *x = malloc(sizeof(page_t)); +slide_t *new_slide() { + slide_t *x = malloc(sizeof(slide_t)); x->line = (void*)0; x->prev = x->next = (void*)0; return x; } -page_t *next_page(page_t *prev) { - page_t *x = new_page(); +slide_t *next_slide(slide_t *prev) { + slide_t *x = new_slide(); x->prev = prev; prev->next = x; return x; } -document_t *new_document() { - document_t *x = malloc(sizeof(document_t)); +deck_t *new_deck() { + deck_t *x = malloc(sizeof(deck_t)); x->header = (void*)0; - x->page = (void*)0; + x->slide = (void*)0; return x; } diff --git a/parser.c b/parser.c index 254c084..552a453 100644 --- a/parser.c +++ b/parser.c @@ -3,18 +3,18 @@ #include "include/parser.h" -document_t *markdown_load(FILE *input) { +deck_t *markdown_load(FILE *input) { int c = 0, i = 0, l = 0, bits = 0; - document_t *doc; - page_t *page; + deck_t *deck; + slide_t *slide; line_t *line; cstring_t *text; - doc = new_document(); - page = new_page(); - doc->page = page; + deck = new_deck(); + slide = new_slide(); + deck->slide = slide; text = cstring_init(); while ((c = fgetc(input)) != EOF) { @@ -33,17 +33,17 @@ document_t *markdown_load(FILE *input) { // reset line length l = 0; - // create next page - page = next_page(page); + // create next slide + slide = next_slide(slide); } else { - // if page ! has line - if(!page->line) { + // if slide ! has line + if(!slide->line) { // create new line line = new_line(); - page->line = line; + slide->line = line; } else { @@ -104,11 +104,11 @@ document_t *markdown_load(FILE *input) { } // detect header - line = doc->page->line; + line = deck->slide->line; if(line && line->text->size > 0 && line->text->text[0] == '%') { - // assign header to document - doc->header = line; + // assign header to deck + deck->header = line; // find first non-header line while(line->text->size > 0 && line->text->text[0] == '%') { @@ -119,14 +119,14 @@ document_t *markdown_load(FILE *input) { line->prev->next = (void*)0; line->prev = (void*)0; - // remove header lines from page - doc->page->line = line; + // remove header lines from slide + deck->slide->line = line; } // combine underlined H1/H2 in single line - page = doc->page; - while(page) { - line = page->line; + slide = deck->slide; + while(slide) { + line = slide->line; while(line) { if((CHECK_BIT(line->bits, IS_H1) || CHECK_BIT(line->bits, IS_H2)) && @@ -151,10 +151,10 @@ document_t *markdown_load(FILE *input) { } line = line->next; } - page = page->next; + slide = slide->next; } - return doc; + return deck; } int markdown_analyse(cstring_t *text) { @@ -232,13 +232,13 @@ int markdown_analyse(cstring_t *text) { return bits; } -void markdown_debug(document_t *doc, int debug) { +void markdown_debug(deck_t *deck, int debug) { // print header to STDERR int offset; line_t *header; - if(doc->header) { - header = doc->header; + if(deck->header) { + header = deck->header; while(header && header->length > 0 && header->text->text[0] == '%') { @@ -249,16 +249,16 @@ void markdown_debug(document_t *doc, int debug) { } } - // print page/line count to STDERR - int cp = 0, cl = 0; - page_t *page = doc->page; + // print slide/line count to STDERR + int cs = 0, cl = 0; + slide_t *slide = deck->slide; line_t *line; - while(page) { - cp++; + while(slide) { + cs++; if(debug > 1) { - fprintf(stderr, "page %i:\n", cp); + fprintf(stderr, "slide %i:\n", cs); } - line = page->line; + line = slide->line; cl = 0; while(line) { cl++; @@ -268,9 +268,9 @@ void markdown_debug(document_t *doc, int debug) { line = line->next; } if(debug == 1) { - fprintf(stderr, "page %i: %i lines\n", cp, cl); + fprintf(stderr, "slide %i: %i lines\n", cs, cl); } - page = page->next; + slide = slide->next; } } diff --git a/tmp.c b/tmp.c index 7e8589e..fef4fef 100644 --- a/tmp.c +++ b/tmp.c @@ -58,10 +58,12 @@ int main(int argc, char *argv[]) { input = stdin; } - // load document object from input - document_t *doc; + // load deck object from input + deck_t *doc; doc = markdown_load(input); + //TODO close file + if(debug > 0) { markdown_debug(doc, debug); }