6. Command line parsing

Command line argument parsing is done using the third-party library parg, included in this source distribution.

<<local_variables>>=
struct parg_state ps;
int c;
<<parse_command_flags>>=
parg_init(&ps);
while((c = parg_getopt(&ps, argc, argv, "st:")) != -1) {
    switch(c) {
        case 1:
            filename = (char *)ps.optarg;
            break;
        case 't':
<<generate_toc>>
            break;
        case 's':
<<turn_on_sections>>
            break;
        default:
            fprintf(stderr, "Unknown option -%c\n", c);
            return 1;
    }
}

6.1. Turn on section numbers (-s)

The "-t" flag will turn on section numbers. This will set a global variable use_secno to be 1.

<<turn_on_sections>>=
use_secno = 1;

By default, the use_secno global is 0.

<<global_variables>>=
static int use_secno = 0;

6.2. Generate Table of Contents (-t)

This argument flag will generate a table of contents. The flag has an input parameter, which should be the name of the HTML filename containing the full documentation.

<<generate_toc>>=
mktoc = 1;
indxfile = (char *)ps.optarg;

By default, the filename is set to NULL, and the mktoc variable is set to be false.

<<global_variables>>=
static char *indxfile = NULL;
static int mktoc = 0;



prev | home | next