int main(int argc, char *argv[]) { int notrans = 0; int nofade = 0; int invert = 0; // define command-line options struct option longopts[] = { { "debug", no_argument, 0, 'd' }, { "nofade", no_argument, 0, 'f' }, { "help", no_argument, 0, 'h' }, { "invert", no_argument, 0, 'i' }, { "notrans", no_argument, 0, 't' }, { "version", no_argument, 0, 'v' }, { 0, 0, 0, 0 } }; // parse command-line options int opt, debug = 0; while ((opt = getopt_long(argc, argv, ":dfhitv", longopts, NULL)) != -1) { switch(opt) { case 'd': debug += 1; break; case 'f': nofade = 1; break; case 'h': usage(); break; case 'i': invert = 1; break; case 't': notrans = 1; break; case 'v': version(); break; case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break; case '?': default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break; } } // open file or set input to STDIN char *file; FILE *input; if (optind < argc) { do { file = argv[optind]; } while(++optind < argc); if(!strcmp(file, "-")) { input = stdin; } else { input = fopen(file,"r"); if(!input) { fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno)); exit(EXIT_FAILURE); } } } else { input = stdin; } // load deck object from input deck_t *deck; deck = markdown_load(input); // close file fclose(input); // replace stdin with current tty if input was a pipe if(input == stdin) { input = freopen("/dev/tty", "rw", stdin); if(!input) { fprintf(stderr, "%s: %s: %s\n", argv[0], "/dev/tty", strerror(errno)); exit(EXIT_FAILURE); } } if(debug > 0) { markdown_debug(deck, debug); } ncurses_display(deck, notrans, nofade, invert); return(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int notrans = 0; // disable transparency int nofade = 0; // disable fading int invert = 0; // invert color (black on white) int reload = 0; // reload page N (0 means no reload) int noreload = 1; // reload disabled until we know input is a file int slidenum = 2; // 0:don't show; 1:show #; 2:show #/# // define command-line options struct option longopts[] = { { "debug", no_argument, 0, 'd' }, { "nofade", no_argument, 0, 'f' }, { "help", no_argument, 0, 'h' }, { "invert", no_argument, 0, 'i' }, { "notrans", no_argument, 0, 't' }, { "version", no_argument, 0, 'v' }, { "noslidenum", no_argument, 0, 's' }, { "noslidemax", no_argument, 0, 'x' }, { 0, 0, 0, 0 } }; // parse command-line options int opt, debug = 0; while ((opt = getopt_long(argc, argv, ":dfhitvsx", longopts, NULL)) != -1) { switch(opt) { case 'd': debug += 1; break; case 'f': nofade = 1; break; case 'h': usage(); break; case 'i': invert = 1; break; case 't': notrans = 1; break; case 'v': version(); break; case 's': slidenum = 0; break; case 'x': slidenum = 1; break; case ':': fprintf(stderr, "%s: '%c' requires an argument\n", argv[0], optopt); usage(); break; case '?': default : fprintf(stderr, "%s: option '%c' is invalid\n", argv[0], optopt); usage(); break; } } // set locale to that of the environment, so that ncurses properly renders // UTF-8 characters if the system supports it setlocale(LC_CTYPE, ""); // open file or set input to STDIN char *file = NULL; FILE *input; if (optind < argc) { do { file = argv[optind]; } while(++optind < argc); if(!strcmp(file, "-")) { input = stdin; } else { input = fopen(file,"r"); if(!input) { fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno)); exit(EXIT_FAILURE); } // enable reload because input is a file noreload = 0; } } else { input = stdin; } // reload loop do { // reopen input file on reload if(noreload == 0 && reload > 0) { if(file) { input = fopen(file,"r"); if(!input) { fprintf(stderr, "%s: %s: %s\n", argv[0], file, strerror(errno)); exit(EXIT_FAILURE); } } else { fprintf(stderr, "%s: %s\n", argv[0], "no input file"); exit(EXIT_FAILURE); } } // load deck object from input deck_t *deck; deck = markdown_load(input); // close file fclose(input); // replace stdin with current tty if input was a pipe // if input was a pipe reload is disabled, so we simply check that if(noreload == 1) { input = freopen("/dev/tty", "rw", stdin); if(!input) { fprintf(stderr, "%s: %s: %s\n", argv[0], "/dev/tty", strerror(errno)); exit(EXIT_FAILURE); } } if(debug > 0) { markdown_debug(deck, debug); } reload = ncurses_display(deck, notrans, nofade, invert, reload, noreload, slidenum); free_deck(deck); // reload if supported and requested } while(noreload == 0 && reload > 0); return EXIT_SUCCESS; }