summaryrefslogtreecommitdiff
path: root/gen-manpage-opts.c
blob: d49576aba5b840cfb34fa4957c6aea0075d39522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * Prints the option help in a form that is suitable to include in the manpage.
 */
#include <stdio.h>
#include <ctype.h>

#include "nvidia-installer.h"
#include "option_table.h"

static void print_option(const NVOption *o)
{
    printf(".TP\n.BI ");
    /* Print the name of the option */
    /* XXX We should backslashify the '-' characters in o->name. */
    if (o->flags & NVOPT_IS_BOOLEAN) {
        /* "\-\-name, \-\-no\-name */
        printf("\"\\-\\-%s, \\-\\-no\\-%s", o->name, o->name);
    } else if (isalnum(o->val)) {
        /* "\-c, \-\-name */
        printf("\"\\-%c, \\-\\-%s", o->val, o->name);
    } else {
        /* "\-\-name */
        printf("\"\\-\\-%s", o->name);
    }

    if (o->flags & NVOPT_HAS_ARGUMENT) {
        printf("=\" \"%s", o->name);
    }

    printf("\"\n");

    /* Print the option description */
    /* XXX Each sentence should be on its own line! */
    /* XXX We need to backslashify the '-' characters here. */
    printf("%s\n", o->description);
}

int main(int argc, char* argv[])
{
    int i;
    const NVOption *o;

    /* Print the "simple" options, i.e. the ones you get by running
     * nvidia-installer --help.
     */
    printf(".SH OPTIONS\n");
    for (i = 0; __options[i].name; i++) {
        o = &__options[i];

        if (!(o->flags & OPTION_HELP_ALWAYS))
            continue;

        if (!o->description)
            continue;

        print_option(o);
    }

    /* Print the advanced options. */
    printf(".SH \"ADVANCED OPTIONS\"\n");
    for (i = 0; __options[i].name; i++) {
        o = &__options[i];

        if (o->flags & OPTION_HELP_ALWAYS)
            continue;

        if (!o->description)
            continue;

        print_option(o);
    }

    return 0;
}