3 * args - a getopt link argument processor
5 * void *handle = args_init(argc, argv, "argctl");
7 * args_next(handle, &pos, &inv, &optarg) -> BAD_FLAG/END_ARGS/NO_FLAG/opt
9 * argctl = {<optchar><typechar>}*
10 * typechar == ? -f or -~f
26 int nextarg, nextchar;
28 #define NULLH ((struct handle *)0)
30 struct handle *args_init(int argc, char **argv, char *ctl)
32 /* if ctl is bad, return NULL, else a handle */
35 for (i=0 ; ctl[i]; i+= 2)
36 if (ctl[i+1] != '?' && ctl[i+1] != '-' && ctl[i+1] != '+' && ctl[i+1] != ':')
41 h = (struct handle*)malloc(sizeof(struct handle));
52 int args_next(struct handle *h, int *pos, int *inv, char **opt)
58 if (h->nextarg >= h->argc)
62 if (h->argv[h->nextarg][0] != '-')
64 if (pos) *pos = h->nextarg;
66 if (opt) *opt = h->argv[h->nextarg];
72 a = h->argv[h->nextarg];
73 while (a[h->nextchar] == '~')
79 for (i=0 ; h->ctl[i] ; i+=2)
80 if (h->ctl[i] == a[h->nextchar])
89 if (pos) *pos = h->nextarg;
91 if (a[h->nextchar] == 0)
112 if (h->nextarg >= h->argc)
115 *opt = h->argv[h->nextarg] + h->nextchar;