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
25 int nextarg, nextchar;
28 struct handle *args_init(int argc, char **argv, char *ctl)
30 /* if ctl is bad, return NULL, else a handle */
33 for (i=0 ; ctl[i]; i+= 2)
34 if (ctl[i+1] != '?' && ctl[i+1] != '-' && ctl[i+1] != '+' && ctl[i+1] != ':')
39 h = (struct handle*)malloc(sizeof(struct handle));
50 int args_next(struct handle *h, int *pos, int *inv, char **opt)
56 if (h->nextarg >= h->argc)
60 if (h->argv[h->nextarg][0] != '-')
62 if (pos) *pos = h->nextarg;
64 if (opt) *opt = h->argv[h->nextarg];
70 a = h->argv[h->nextarg];
71 while (a[h->nextchar] == '~')
77 for (i=0 ; h->ctl[i] ; i+=2)
78 if (h->ctl[i] == a[h->nextchar])
87 if (pos) *pos = h->nextarg;
89 if (a[h->nextchar] == 0)
110 if (h->nextarg >= h->argc)
113 *opt = h->argv[h->nextarg] + h->nextchar;