4
* option arguments parser
10
static CONST opt_t *NEAR getoption __P_((int, CONST opt_t *));
13
static CONST opt_t *NEAR getoption(c, optlist)
19
if (!optlist) return(NULL);
20
for (n = 0; optlist[n].opt; n++)
21
if (c == optlist[n].opt) return(&(optlist[n]));
32
for (n = 0; optlist[n].opt; n++)
33
if (optlist[n].var) *(optlist[n].var) = 0;
36
VOID optusage(arg0, args, optlist)
37
CONST char *arg0, *args;
42
fprintf(stderr, "Usage: %s", arg0);
44
if (optlist) while (optlist[n].opt) n++;
47
for (n = 0; optlist[n].opt; n++) {
48
fputc(optlist[n].opt, stderr);
50
if (!(optlist[n].argval)) continue;
51
fprintf(stderr, " <%s>", optlist[n].argval);
52
if (optlist[n + 1].opt) fputs(" [-", stderr);
56
fprintf(stderr, " %s\n", args);
59
int evalopt(argc, argv, optlist)
68
for (n = 1; n < argc; n++) {
69
if (argv[n][0] != '-' || !argv[n][1]) break;
70
if (argv[n][1] == '=' && !argv[n][2]) {
75
for (i = 1; argv[n][i]; i++) {
76
if (!(optp = getoption(argv[n][i], optlist)))
79
if (!(optp -> argval)) {
80
if (optp -> var) *(optp -> var) = optp -> val;
84
if (!*cp) cp = argv[++n];
85
if (!cp || (val = atoi(cp)) <= 0) return(-1);
86
if (optp -> var) *(optp -> var) = val;