2323#include <stdio.h>
2424#include <stdlib.h>
2525#include <string.h>
26+ #include <ctype.h>
2627
2728#include "main.h"
2829
30+ int is_number (const char * str ) {
31+ while (* str ) {
32+ if (!isdigit (* str )) return 0 ;
33+ str ++ ;
34+ }
35+ return 1 ;
36+ }
37+
2938void usage () {
3039 fprintf (stderr , "%s" , "Usage: mdp [OPTION]... [FILE]\n" );
3140 fprintf (stderr , "%s" , "A command-line based markdown presentation tool.\n\n" );
41+ fprintf (stderr , "%s" , " -c, --nocodebg don't change the background color of code blocks\n" );
3242 fprintf (stderr , "%s" , " -d, --debug enable debug messages on STDERR\n" );
3343 fprintf (stderr , "%s" , " add it multiple times to increases debug level\n" );
3444 fprintf (stderr , "%s" , " -e, --expand enable character entity expansion\n" );
3545 fprintf (stderr , "%s" , " -f, --nofade disable color fading in 256 color mode\n" );
3646 fprintf (stderr , "%s" , " -h, --help display this help and exit\n" );
3747 fprintf (stderr , "%s" , " -i, --invert swap black and white color\n" );
48+ fprintf (stderr , "%s" , " -j N, --jump N jump to slide N\n" );
3849 fprintf (stderr , "%s" , " -t, --notrans disable transparency in transparent terminal\n" );
3950 fprintf (stderr , "%s" , " -s, --noslidenum do not show slide number at the bottom\n" );
4051 fprintf (stderr , "%s" , " -v, --version display the version number and license\n" );
4152 fprintf (stderr , "%s" , " -x, --noslidemax show slide number, but not total number of slides\n" );
42- fprintf (stderr , "%s" , " -c, --nocodebg don't change the background color of code blocks\n" );
4353 fprintf (stderr , "%s" , "\nWith no FILE, or when FILE is -, read standard input.\n\n" );
4454 exit (EXIT_FAILURE );
4555}
@@ -66,33 +76,43 @@ int main(int argc, char *argv[]) {
6676
6777 // define command-line options
6878 struct option longopts [] = {
69- { "debug" , no_argument , 0 , 'd' },
70- { "expand" , no_argument , 0 , 'e' },
71- { "nofade" , no_argument , 0 , 'f' },
72- { "help" , no_argument , 0 , 'h' },
73- { "invert" , no_argument , 0 , 'i' },
74- { "notrans" , no_argument , 0 , 't' },
75- { "version" , no_argument , 0 , 'v' },
76- { "noslidenum" , no_argument , 0 , 's' },
77- { "noslidemax" , no_argument , 0 , 'x' },
78- { "nocodebg" , no_argument , 0 , 'c' },
79+ { "nocodebg" , no_argument , 0 , 'c' },
80+ { "debug" , no_argument , 0 , 'd' },
81+ { "expand" , no_argument , 0 , 'e' },
82+ { "nofade" , no_argument , 0 , 'f' },
83+ { "help" , no_argument , 0 , 'h' },
84+ { "invert" , no_argument , 0 , 'i' },
85+ { "jump" , required_argument , 0 , 'j' },
86+ { "notrans" , no_argument , 0 , 't' },
87+ { "version" , no_argument , 0 , 'v' },
88+ { "noslidenum" , no_argument , 0 , 's' },
89+ { "noslidemax" , no_argument , 0 , 'x' },
7990 { 0 , 0 , 0 , 0 }
8091 };
8192
8293 // parse command-line options
8394 int opt , debug = 0 ;
84- while ((opt = getopt_long (argc , argv , ":defhitvsxc " , longopts , NULL )) != -1 ) {
95+ while ((opt = getopt_long (argc , argv , ":cdefhij:tvsx " , longopts , NULL )) != -1 ) {
8596 switch (opt ) {
97+ case 'c' : nocodebg = 1 ; break ;
8698 case 'd' : debug += 1 ; break ;
8799 case 'e' : noexpand = 0 ; break ;
88100 case 'f' : nofade = 1 ; break ;
89101 case 'h' : usage (); break ;
90102 case 'i' : invert = 1 ; break ;
103+ case 'j' :
104+ if (!is_number (optarg )) {
105+ fprintf (stderr , "%s: '%s' is not a valid number\n" , argv [0 ], optarg );
106+ usage ();
107+ break ;
108+ }
109+ reload = atoi (optarg );
110+ noreload = 0 ;
111+ break ;
91112 case 't' : notrans = 1 ; break ;
92113 case 'v' : version (); break ;
93114 case 's' : slidenum = 0 ; break ;
94115 case 'x' : slidenum = 1 ; break ;
95- case 'c' : nocodebg = 1 ; break ;
96116 case ':' : fprintf (stderr , "%s: '%c' requires an argument\n" , argv [0 ], optopt ); usage (); break ;
97117 case '?' :
98118 default : fprintf (stderr , "%s: option '%c' is invalid\n" , argv [0 ], optopt ); usage (); break ;
0 commit comments