X-Git-Url: https://git.danieliu.xyz/?p=smdp.git;a=blobdiff_plain;f=src%2Fmain.c;h=37af9bc13b87a6041225d3074e3898af60f431e5;hp=e1829a8281b3dfc6f3d4a5825b407da7a86d8eae;hb=8689da8fc361118b05e33f3d19b269e9463040d0;hpb=aaef0d22541650ed73e094363e1886943ca035d3 diff --git a/src/main.c b/src/main.c index e1829a8..37af9bc 100644 --- a/src/main.c +++ b/src/main.c @@ -49,9 +49,11 @@ void version() { } int main(int argc, char *argv[]) { - int notrans = 0; - int nofade = 0; - int invert = 0; + 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 // define command-line options struct option longopts[] = { @@ -81,7 +83,7 @@ int main(int argc, char *argv[]) { } // open file or set input to STDIN - char *file; + char *file = NULL; FILE *input; if (optind < argc) { do { @@ -96,34 +98,57 @@ int main(int argc, char *argv[]) { 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; } - // load deck object from input - deck_t *deck; - deck = markdown_load(input); + // 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); + } + } - // close file - fclose(input); + // load deck object from input + deck_t *deck; + deck = markdown_load(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); + // 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); - } + if(debug > 0) { + markdown_debug(deck, debug); + } + + reload = ncurses_display(deck, notrans, nofade, invert, reload, noreload); - ncurses_display(deck, notrans, nofade, invert); + free_deck(deck); - free_deck(deck); + // reload if supported and requested + } while(noreload == 0 && reload > 0); return EXIT_SUCCESS; }