added header detection + test
[smdp.git] / tmp.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <errno.h>
4
5 #include "include/markdown.h"
6
7 int main(int argc, char *argv[]) {
8
9     FILE *input;
10     document_t *doc;
11
12     if (argc > 1) {
13         if(!strcmp(argv[1], "-")) {
14             input = stdin;
15         } else {
16             input = fopen(argv[1],"r");
17             if(!input) {
18                 fprintf(stderr, "Unable to open '%s': %s\n",
19                     argv[1], strerror(errno));
20                 exit(EXIT_FAILURE);
21             }
22         }
23     } else {
24         input = stdin;
25     }
26
27     doc = markdown_load(input);
28
29     // test line/page load
30     int offset;
31     line_t *header;
32     if(doc->header) {
33         header = doc->header;
34         while(header &&
35               header->text->size > 0 &&
36               header->text->text[0] == '%') {
37
38             offset = next_blank(header->text, 0) + 1;
39             printf("header: %s\n", &header->text->text[offset]);
40             header = header->next;
41         }
42     }
43     int cp = 0, cl = 0;
44     page_t *page = doc->page;
45     line_t *line;
46     while(page) {
47         cp++;
48         line = page->line;
49         cl = 0;
50         while(line) {
51             cl++;
52             line = line->next;
53         }
54         printf("page %i: %i lines\n", cp, cl);
55         page = page->next;
56     }
57 }
58