MCPcopy Create free account
hub / github.com/cppla/ServerStatus / argparse_parse

Function argparse_parse

server/src/argparse.c:180–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178}
179
180int
181argparse_parse(struct argparse *this_, int argc, const char **argv)
182{
183 this_->argc = argc - 1;
184 this_->argv = argv + 1;
185 this_->out = argv;
186
187 argparse_options_check(this_->options);
188
189 for (; this_->argc; this_->argc--, this_->argv++) {
190 const char *arg = this_->argv[0];
191 if (arg[0] != '-' || !arg[1]) {
192 if (this_->flags & ARGPARSE_STOP_AT_NON_OPTION) {
193 goto end;
194 }
195 // if it's not option or is a single char '-', copy verbatimly
196 this_->out[this_->cpidx++] = this_->argv[0];
197 continue;
198 }
199 // short option
200 if (arg[1] != '-') {
201 this_->optvalue = arg + 1;
202 switch (argparse_short_opt(this_, this_->options)) {
203 case -1:
204 break;
205 case -2:
206 goto unknown;
207 }
208 while (this_->optvalue) {
209 switch (argparse_short_opt(this_, this_->options)) {
210 case -1:
211 break;
212 case -2:
213 goto unknown;
214 }
215 }
216 continue;
217 }
218 // if '--' presents
219 if (!arg[2]) {
220 this_->argc--;
221 this_->argv++;
222 break;
223 }
224 // long option
225 switch (argparse_long_opt(this_, this_->options)) {
226 case -1:
227 break;
228 case -2:
229 goto unknown;
230 }
231 continue;
232
233unknown:
234 fprintf(stderr, "error: unknown option `%s`\n", this_->argv[0]);
235 argparse_usage(this_);
236 exit(0);
237 }

Callers 1

mainFunction · 0.85

Calls 4

argparse_options_checkFunction · 0.85
argparse_short_optFunction · 0.85
argparse_long_optFunction · 0.85
argparse_usageFunction · 0.85

Tested by

no test coverage detected