annotate lib/args.c @ 26:75b80e55bcfc

Add one if() that has lots of whitespace fallout.
author Rob Landley <rob@landley.net>
date Sun, 19 Nov 2006 17:29:35 -0500
parents eb46bb5626cb
children be59ed005902
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4 :
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
2 * args.c - Command line argument parsing.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
3 *
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
4 * Copyright 2006 Rob Landley <rob@landley.net>
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
5 */
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
6
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
7 #include "toys.h"
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
8
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
9 // Design goals:
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
10 // Don't use getopt()
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
11 // Don't permute original arguments.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
12 // handle --long gracefully "(noshort)a(along)b(blong1)(blong2)"
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
13 // After each argument:
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
14 // Note that pointer and long are always the same size, even on 64 bit.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
15 // : plus a string argument, keep most recent if more than one
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
16 // * plus a string argument, appended to a list
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
17 // ? plus a signed long argument (TODO: Bounds checking?)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
18 // @ plus an occurrence counter (which is a long)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
19 // | this is required. If more than one marked, only one required.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
20 // (longopt)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
21 // +X enabling this enables X (switch on)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
22 // ~X enabling this disables X (switch off)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
23 // x~x means toggle x, I.E. specifying it again switches it off.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
24 // !X die with error if X already set (x!x die if x supplied twice)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
25 // [yz] needs at least one of y or z.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
26 // at the beginning:
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
27 // + stop at first nonoption argument
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
28 // ? return array of remaining arguments in first vararg
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
29 // <0 at least # leftover arguments needed (default 0)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
30 // >9 at most # leftover arguments needed (default MAX_INT)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
31 // # don't show_usage() on unknown argument.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
32 // & first argument has imaginary dash (ala tar/ps)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
33 // If given twice, all arguments have imaginary dash
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
34
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
35 // Notes from getopt man page
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
36 // - and -- cannot be arguments.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
37 // -- force end of arguments
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
38 // - is a synonym for stdin in file arguments
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
39 // -abc means -a -b -c
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
40
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
41 /* This uses a getopt-like option string, but not getopt() itself.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
42 *
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
43 * Each option in options corresponds to a bit position in the return
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
44 * value (last argument is (1<<0), the next to last is (1<<1) and so on.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
45 * If the option isn't seen in argv its bit is 0. Options which have an
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
46 * argument use the next vararg. (So varargs used by options go from left to
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
47 * right, but bits set by arguments go from right to left.)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
48 *
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
49 * Example:
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
50 * get_optflags("ab:c:d", NULL, &bstring, &cstring);
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
51 * argv = ["command", "-b", "fruit", "-d"]
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
52 * flags = 5, bstring="fruit", cstring=NULL;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
53 */
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
54
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
55 struct opts {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
56 struct opts *next;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
57 char c;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
58 int type;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
59 int shift;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
60 void *arg;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
61 };
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
62
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
63 struct getoptflagstate
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
64 {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
65 int argc;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
66 char *arg;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
67 struct opts *opts, *this;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
68 int noerror, nodash_now;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
69 };
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
70
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
71 static struct getoptflagstate gof;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
72
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
73 // Returns zero if it didn't consume the rest of the current -abcdef
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
74 static int gotflag(void)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
75 {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
76 char *arg = NULL;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
77 int type;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
78 int ret = 0;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
79
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
80 // Did we recognize this option?
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
81 if (!gof.this && !gof.noerror) error_exit("Unknown option %s\n", gof.arg);
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
82 else toys.optflags |= 1 << gof.this->shift;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
83
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
84 // Does this option take an argument?
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
85 gof.arg++;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
86 if (gof.this->type & 255) {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
87 // Make "tar xCjfv blah1 blah2 thingy" work like
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
88 // "tar -x -C blah1 -j -f blah2 -v thingy"
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
89 if (!gof.nodash_now && !*gof.arg) {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
90 gof.arg = toys.argv[++gof.argc];
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
91 if (!gof.arg) error_exit("Missing argument");
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
92 } else {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
93 arg = gof.arg;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
94 ret++;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
95 }
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
96 } else gof.this = NULL;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
97
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
98 // If the last option had an argument, grab it.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
99 if (!gof.this) return 0;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
100 type = gof.this->type & 255;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
101 if (!gof.arg && !(gof.arg = toys.argv[++gof.argc]))
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
102 error_exit("Missing argument");
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
103 if (type == ':') gof.this->arg = arg;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
104 else if (type == '*') {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
105 struct arg_list *temp, **list;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
106 list = (struct arg_list **)gof.this->arg;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
107 temp = xmalloc(sizeof(struct arg_list));
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
108 temp->arg = arg;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
109 temp->next = *list;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
110 *list = temp;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
111 } else if (type == '?') {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
112 } else if (type == '@') {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
113 }
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
114
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
115 return ret;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
116 }
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
117
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
118 // Fill out toys.optflags and toys.optargs. This isn't reentrant because
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
119 // we don't bzero(&gof, sizeof(gof));
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
120
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
121 void get_optflags(void)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
122 {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
123 int stopearly = 0, optarg = 0, nodash = 0, minargs = 0, maxargs = INT_MAX;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
124 struct longopts {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
125 struct longopts *next;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
126 struct opts *opt;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
127 char *str;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
128 int len;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
129 } *longopts = NULL;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
130 long *nextarg = (long *)&toy;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
131 char *options = toys.which->options;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
132
26
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
133 if (options) {
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
134 // Parse leading special behavior indicators
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
135 for (;;) {
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
136 if (*options == '+') stopearly++;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
137 else if (*options == '<') minargs=*(++options)-'0';
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
138 else if (*options == '>') maxargs=*(++options)-'0';
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
139 else if (*options == '#') gof.noerror++;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
140 else if (*options == '&') nodash++;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
141 else break;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
142 options++;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
143 }
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
144
26
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
145 // Parse rest of opts into array
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
146 while (*options) {
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
147
26
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
148 // Allocate a new option entry when necessary
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
149 if (!gof.this) {
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
150 gof.this = xzalloc(sizeof(struct opts));
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
151 gof.this->next = gof.opts;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
152 gof.opts = gof.this;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
153 }
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
154 // Each option must start with (or an option character. (Bare
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
155 // longopts only come at the start of the string.)
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
156 if (*options == '(') {
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
157 char *end;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
158 struct longopts *lo = xmalloc(sizeof(struct longopts));
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
159
26
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
160 // Find the end of the longopt
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
161 for (end = ++options; *end && *end != ')'; end++);
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
162 if (CFG_DEBUG && !*end) error_exit("Unterminated optstring");
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
163
26
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
164 // Allocate and init a new struct longopts
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
165 lo = xmalloc(sizeof(struct longopts));
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
166 lo->next = longopts;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
167 lo->opt = gof.this;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
168 lo->str = options;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
169 lo->len = end-options;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
170 longopts = lo;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
171 options = end;
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
172
26
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
173 // For leading longopts (with no corresponding short opt), note
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
174 // that this option struct has been used.
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
175 gof.this->shift++;
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
176
26
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
177 // If this is the start of a new option that wasn't a longopt,
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
178
26
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
179 } else if (index(":*?@", *options)) {
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
180 gof.this->type |= *options;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
181 // Pointer and long guaranteed to be the same size by LP64.
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
182 *(++nextarg) = 0;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
183 gof.this->arg = (void *)nextarg;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
184 } else if (*options == '|') {
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
185 } else if (*options == '+') {
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
186 } else if (*options == '~') {
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
187 } else if (*options == '!') {
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
188 } else if (*options == '[') {
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
189
26
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
190 // At this point, we've hit the end of the previous option. The
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
191 // current character is the start of a new option. If we've already
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
192 // assigned an option to this struct, loop to allocate a new one.
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
193 // (It'll get back here afterwards.)
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
194 } else if(gof.this->shift || gof.this->c) {
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
195 gof.this = NULL;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
196 continue;
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
197
26
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
198 // Claim this option, loop to see what's after it.
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
199 } else gof.this->c = *options;
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
200
26
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
201 options++;
75b80e55bcfc Add one if() that has lots of whitespace fallout.
Rob Landley <rob@landley.net>
parents: 25
diff changeset
202 }
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
203 }
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
204
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
205 // Initialize shift bits (have to calculate this ahead of time because
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
206 // longopts jump into the middle of the list), and allocate space to
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
207 // store optargs.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
208 gof.argc = 0;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
209 for (gof.this = gof.opts; gof.this; gof.this = gof.this->next)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
210 gof.this->shift = gof.argc++;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
211 toys.optargs = xzalloc(sizeof(char *)*(++gof.argc));
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
212
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
213 // Iterate through command line arguments, skipping argv[0]
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
214 for (gof.argc=1; toys.argv[gof.argc]; gof.argc++) {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
215 char *arg = toys.argv[gof.argc];
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
216
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
217 // Parse this argument
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
218 if (stopearly>1) goto notflag;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
219
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
220 gof.nodash_now = 0;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
221
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
222 // Various things with dashes
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
223 if (*arg == '-') {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
224
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
225 // Handle -
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
226 if (!arg[1]) goto notflag;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
227 arg++;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
228 if (*arg=='-') {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
229 struct longopts *lo;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
230
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
231 arg++;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
232 // Handle --
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
233 if (!*arg) {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
234 stopearly += 2;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
235 goto notflag;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
236 }
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
237 // Handle --longopt
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
238
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
239 for (lo = longopts; lo; lo = lo->next) {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
240 if (!strncmp(arg, lo->str, lo->len)) {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
241 if (arg[lo->len]) {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
242 if (arg[lo->len]=='='
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
243 && (lo->opt->type & 255))
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
244 {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
245 arg += lo->len;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
246 } else continue;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
247
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
248 // *options should be nul, this makes sure
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
249 // that the while (*arg) loop terminates;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
250 } arg = options-1;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
251 gof.this = lo->opt;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
252 break;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
253 }
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
254 }
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
255 // Long option parsed, jump to option handling.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
256 gotflag();
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
257 continue;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
258 }
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
259
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
260 // Handle things that don't start with a dash.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
261 } else {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
262 if (nodash && (nodash>1 || gof.argc == 1)) gof.nodash_now = 1;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
263 else goto notflag;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
264 }
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
265
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
266 // At this point, we have the args part of -args. Loop through
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
267 // each entry (could be -abc meaning -a -b -c)
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
268 while (*arg) {
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
269 // Identify next option char.
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
270 for (gof.this = gof.opts; gof.this && *arg != gof.this->c;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
271 gof.this = gof.this->next);
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
272 if (gotflag()) break;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
273 arg++;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
274 }
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
275 continue;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
276
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
277 // Not a flag, save value in toys.optargs[]
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
278 notflag:
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
279 if (stopearly) stopearly++;
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
280 toys.optargs[optarg++] = toys.argv[gof.argc];
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
281 }
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
282
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
283 // Sanity check
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
284 if (optarg<minargs) error_exit("Need %d arguments", minargs);
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
285 if (optarg>maxargs) error_exit("Max %d arguments", maxargs);
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
diff changeset
286 }