int argparse_help_cb(struct argparse *this_, const struct argparse_option *option) { (void)option; argparse_usage(this_); exit(0); return 0; }
int argparse_help_cb(struct argparse *self, const struct argparse_option *option) { (void)option; argparse_usage(self); exit(0); return 0; }
int argparse_parse(struct argparse *this_, int argc, const char **argv) { this_->argc = argc - 1; this_->argv = argv + 1; this_->out = argv; argparse_options_check(this_->options); for (; this_->argc; this_->argc--, this_->argv++) { const char *arg = this_->argv[0]; if (arg[0] != '-' || !arg[1]) { if (this_->flags & ARGPARSE_STOP_AT_NON_OPTION) { goto end; } // if it's not option or is a single char '-', copy verbatimly this_->out[this_->cpidx++] = this_->argv[0]; continue; } // short option if (arg[1] != '-') { this_->optvalue = arg + 1; switch (argparse_short_opt(this_, this_->options)) { case -1: break; case -2: goto unknown; } while (this_->optvalue) { switch (argparse_short_opt(this_, this_->options)) { case -1: break; case -2: goto unknown; } } continue; } // if '--' presents if (!arg[2]) { this_->argc--; this_->argv++; break; } // long option switch (argparse_long_opt(this_, this_->options)) { case -1: break; case -2: goto unknown; } continue; unknown: fprintf(stderr, "error: unknown option `%s`\n", this_->argv[0]); argparse_usage(this_); exit(0); } end: memmove(this_->out + this_->cpidx, this_->argv, this_->argc * sizeof(*this_->out)); this_->out[this_->cpidx + this_->argc] = NULL; return this_->cpidx + this_->argc; }