7 #include "include/markdown.h"
10 fprintf(stderr, "Usage: tmp [OPTION]... [FILE]\n");
11 fprintf(stderr, "A command-line based markdown presentation tool.\n\n");
12 fprintf(stderr, " -d, --debug enable debug messages on STDERR\n");
13 fprintf(stderr, " -h, --help display this help and exit\n");
14 fprintf(stderr, "\nWith no FILE, or when FILE is -, read standard input.\n\n");
18 int main(int argc, char *argv[]) {
20 // define command-line options
21 struct option longopts[] = {
22 { "debug", no_argument, 0, 'd' },
23 { "help", no_argument, 0, 'h' },
27 // parse command-line options
29 while ((opt = getopt_long(argc, argv, ":dh", longopts, NULL)) != -1) {
31 case 'd': debug = 1; break;
32 case 'h': usage(); break;
33 case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break;
35 default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break;
39 // open file or set input to STDIN
45 } while(++optind < argc);
47 if(!strcmp(file, "-")) {
50 input = fopen(file,"r");
52 fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno));
60 // load document object from input
62 doc = markdown_load(input);
65 // print header to STDERR
71 header->text->size > 0 &&
72 header->text->text[0] == '%') {
74 offset = next_blank(header->text, 0) + 1;
75 printf("header: %s\n", &header->text->text[offset]);
76 header = header->next;
80 // print page/line count to STDERR
82 page_t *page = doc->page;
92 printf("page %i: %i lines\n", cp, cl);