2 * mdp -- A command-line based markdown presentation tool.
3 * Copyright (C) 2014 Michael Goehler
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "include/mdp.h"
29 fprintf(stderr, "%s", "Usage: mdp [OPTION]... [FILE]\n");
30 fprintf(stderr, "%s", "A command-line based markdown presentation tool.\n\n");
31 fprintf(stderr, "%s", " -d, --debug enable debug messages on STDERR\n");
32 fprintf(stderr, "%s", " add it multiple times to increases debug level\n");
33 fprintf(stderr, "%s", " -f, --nofade disable color fading in 256 color mode\n");
34 fprintf(stderr, "%s", " -h, --help display this help and exit\n");
35 fprintf(stderr, "%s", " -t, --notrans disable transparency in transparent terminal\n");
36 fprintf(stderr, "%s", "\nWith no FILE, or when FILE is -, read standard input.\n\n");
41 printf("mdp %d.%d\n", MAJOR_VERSION, MINOR_VERSION);
42 printf("Copyright (C) 2014 Michael Goehler\n");
43 printf("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n");
44 printf("This is free software: you are free to change and redistribute it.\n");
45 printf("There is NO WARRANTY, to the extent permitted by law.\n");
46 printf("\nWritten by Michael Goehler and others, see <https://github.com/visit1985/mdp/blob/master/AUTHORS>.\n");
50 int main(int argc, char *argv[]) {
54 // define command-line options
55 struct option longopts[] = {
56 { "debug", no_argument, 0, 'd' },
57 { "nofade", no_argument, 0, 'f' },
58 { "help", no_argument, 0, 'h' },
59 { "notrans", no_argument, 0, 't' },
60 { "version", no_argument, 0, 'v' },
64 // parse command-line options
66 while ((opt = getopt_long(argc, argv, ":dfhtv", longopts, NULL)) != -1) {
68 case 'd': debug += 1; break;
69 case 'f': nofade = 1; break;
70 case 'h': usage(); break;
71 case 't': notrans = 1; break;
72 case 'v': version(); break;
73 case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break;
75 default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break;
79 // open file or set input to STDIN
85 } while(++optind < argc);
87 if(!strcmp(file, "-")) {
90 input = fopen(file,"r");
92 fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno));
100 // load deck object from input
102 deck = markdown_load(input);
107 // replace stdin with current tty if input was a pipe
109 freopen("/dev/tty", "rw", stdin);
112 markdown_debug(deck, debug);
115 ncurses_display(deck, notrans, nofade);
117 return(EXIT_SUCCESS);