7 #include "include/parser.h"
8 #include "include/viewer.h"
11 fprintf(stderr, "Usage: mdp [OPTION]... [FILE]\n");
12 fprintf(stderr, "A command-line based markdown presentation tool.\n\n");
13 fprintf(stderr, " -d, --debug enable debug messages on STDERR\n");
14 fprintf(stderr, " add it multiple times to increases debug level\n\n");
15 fprintf(stderr, " -h, --help display this help and exit\n");
16 fprintf(stderr, "\nWith no FILE, or when FILE is -, read standard input.\n\n");
20 int main(int argc, char *argv[]) {
22 // define command-line options
23 struct option longopts[] = {
24 { "debug", no_argument, 0, 'd' },
25 { "help", no_argument, 0, 'h' },
29 // parse command-line options
31 while ((opt = getopt_long(argc, argv, ":dh", longopts, NULL)) != -1) {
33 case 'd': debug += 1; break;
34 case 'h': usage(); break;
35 case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break;
37 default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break;
41 // open file or set input to STDIN
47 } while(++optind < argc);
49 if(!strcmp(file, "-")) {
52 input = fopen(file,"r");
54 fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno));
62 // load deck object from input
64 deck = markdown_load(input);
69 markdown_debug(deck, debug);
72 ncurses_display(deck, 0, 0);