Mercurial > hg > toybox
comparison 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 |
comparison
equal
deleted
inserted
replaced
25:eb46bb5626cb | 26:75b80e55bcfc |
---|---|
128 int len; | 128 int len; |
129 } *longopts = NULL; | 129 } *longopts = NULL; |
130 long *nextarg = (long *)&toy; | 130 long *nextarg = (long *)&toy; |
131 char *options = toys.which->options; | 131 char *options = toys.which->options; |
132 | 132 |
133 // Parse leading special behavior indicators | 133 if (options) { |
134 for (;;) { | 134 // Parse leading special behavior indicators |
135 if (*options == '+') stopearly++; | 135 for (;;) { |
136 else if (*options == '<') minargs=*(++options)-'0'; | 136 if (*options == '+') stopearly++; |
137 else if (*options == '>') maxargs=*(++options)-'0'; | 137 else if (*options == '<') minargs=*(++options)-'0'; |
138 else if (*options == '#') gof.noerror++; | 138 else if (*options == '>') maxargs=*(++options)-'0'; |
139 else if (*options == '&') nodash++; | 139 else if (*options == '#') gof.noerror++; |
140 else break; | 140 else if (*options == '&') nodash++; |
141 options++; | 141 else break; |
142 } | 142 options++; |
143 | 143 } |
144 // Parse rest of opts into array | 144 |
145 while (*options) { | 145 // Parse rest of opts into array |
146 | 146 while (*options) { |
147 // Allocate a new option entry when necessary | 147 |
148 if (!gof.this) { | 148 // Allocate a new option entry when necessary |
149 gof.this = xzalloc(sizeof(struct opts)); | 149 if (!gof.this) { |
150 gof.this->next = gof.opts; | 150 gof.this = xzalloc(sizeof(struct opts)); |
151 gof.opts = gof.this; | 151 gof.this->next = gof.opts; |
152 } | 152 gof.opts = gof.this; |
153 // Each option must start with (or an option character. (Bare | 153 } |
154 // longopts only come at the start of the string.) | 154 // Each option must start with (or an option character. (Bare |
155 if (*options == '(') { | 155 // longopts only come at the start of the string.) |
156 char *end; | 156 if (*options == '(') { |
157 struct longopts *lo = xmalloc(sizeof(struct longopts)); | 157 char *end; |
158 | 158 struct longopts *lo = xmalloc(sizeof(struct longopts)); |
159 // Find the end of the longopt | 159 |
160 for (end = ++options; *end && *end != ')'; end++); | 160 // Find the end of the longopt |
161 if (CFG_DEBUG && !*end) error_exit("Unterminated optstring"); | 161 for (end = ++options; *end && *end != ')'; end++); |
162 | 162 if (CFG_DEBUG && !*end) error_exit("Unterminated optstring"); |
163 // Allocate and init a new struct longopts | 163 |
164 lo = xmalloc(sizeof(struct longopts)); | 164 // Allocate and init a new struct longopts |
165 lo->next = longopts; | 165 lo = xmalloc(sizeof(struct longopts)); |
166 lo->opt = gof.this; | 166 lo->next = longopts; |
167 lo->str = options; | 167 lo->opt = gof.this; |
168 lo->len = end-options; | 168 lo->str = options; |
169 longopts = lo; | 169 lo->len = end-options; |
170 options = end; | 170 longopts = lo; |
171 | 171 options = end; |
172 // For leading longopts (with no corresponding short opt), note | 172 |
173 // that this option struct has been used. | 173 // For leading longopts (with no corresponding short opt), note |
174 gof.this->shift++; | 174 // that this option struct has been used. |
175 | 175 gof.this->shift++; |
176 // If this is the start of a new option that wasn't a longopt, | 176 |
177 | 177 // If this is the start of a new option that wasn't a longopt, |
178 } else if (index(":*?@", *options)) { | 178 |
179 gof.this->type |= *options; | 179 } else if (index(":*?@", *options)) { |
180 // Pointer and long guaranteed to be the same size by LP64. | 180 gof.this->type |= *options; |
181 *(++nextarg) = 0; | 181 // Pointer and long guaranteed to be the same size by LP64. |
182 gof.this->arg = (void *)nextarg; | 182 *(++nextarg) = 0; |
183 } else if (*options == '|') { | 183 gof.this->arg = (void *)nextarg; |
184 } else if (*options == '+') { | 184 } else if (*options == '|') { |
185 } else if (*options == '~') { | 185 } else if (*options == '+') { |
186 } else if (*options == '!') { | 186 } else if (*options == '~') { |
187 } else if (*options == '[') { | 187 } else if (*options == '!') { |
188 | 188 } else if (*options == '[') { |
189 // At this point, we've hit the end of the previous option. The | 189 |
190 // current character is the start of a new option. If we've already | 190 // At this point, we've hit the end of the previous option. The |
191 // assigned an option to this struct, loop to allocate a new one. | 191 // current character is the start of a new option. If we've already |
192 // (It'll get back here afterwards.) | 192 // assigned an option to this struct, loop to allocate a new one. |
193 } else if(gof.this->shift || gof.this->c) { | 193 // (It'll get back here afterwards.) |
194 gof.this = NULL; | 194 } else if(gof.this->shift || gof.this->c) { |
195 continue; | 195 gof.this = NULL; |
196 | 196 continue; |
197 // Claim this option, loop to see what's after it. | 197 |
198 } else gof.this->c = *options; | 198 // Claim this option, loop to see what's after it. |
199 | 199 } else gof.this->c = *options; |
200 options++; | 200 |
201 options++; | |
202 } | |
201 } | 203 } |
202 | 204 |
203 // Initialize shift bits (have to calculate this ahead of time because | 205 // Initialize shift bits (have to calculate this ahead of time because |
204 // longopts jump into the middle of the list), and allocate space to | 206 // longopts jump into the middle of the list), and allocate space to |
205 // store optargs. | 207 // store optargs. |