rename objects to deck / slide
[smdp.git] / tmp.c
1 #include <errno.h>
2 #include <getopt.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 #include "include/parser.h"
8
9 void usage() {
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, "                add it multiple times to increases debug level\n\n");
14     fprintf(stderr, "  -h, --help    display this help and exit\n");
15     fprintf(stderr, "\nWith no FILE, or when FILE is -, read standard input.\n\n");
16     exit(EXIT_FAILURE);
17 }
18
19 int main(int argc, char *argv[]) {
20
21     // define command-line options
22     struct option longopts[] = {
23         { "debug", no_argument, 0, 'd' },
24         { "help",  no_argument, 0, 'h' },
25         { 0, 0, 0, 0 }
26     };
27
28     // parse command-line options
29     int opt, debug = 0;
30     while ((opt = getopt_long(argc, argv, ":dh", longopts, NULL)) != -1) {
31         switch(opt) {
32             case 'd': debug += 1; break;
33             case 'h': usage(); break;
34             case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break;
35             case '?':
36             default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break;
37         }
38     }
39
40     // open file or set input to STDIN
41     char *file;
42     FILE *input;
43     if (optind < argc) {
44         do {
45             file = argv[optind];
46         } while(++optind < argc);
47
48         if(!strcmp(file, "-")) {
49             input = stdin;
50         } else {
51             input = fopen(file,"r");
52             if(!input) {
53                 fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno));
54                 exit(EXIT_FAILURE);
55             }
56         }
57     } else {
58         input = stdin;
59     }
60
61     // load deck object from input
62     deck_t *doc;
63     doc = markdown_load(input);
64
65     //TODO close file
66
67     if(debug > 0) {
68         markdown_debug(doc, debug);
69     }
70 }
71