static int argparse_short_opt(struct argparse *this_, const struct argparse_option *options) { for (; options->type != ARGPARSE_OPT_END; options++) { if (options->short_name == *this_->optvalue) { this_->optvalue = this_->optvalue[1] ? this_->optvalue + 1 : NULL; return argparse_getvalue(this_, options, 0); } } return -2; }
static int argparse_long_opt(struct argparse *this_, const struct argparse_option *options) { for (; options->type != ARGPARSE_OPT_END; options++) { const char *rest; int opt_flags = 0; if (!options->long_name) continue; rest = prefix_skip(this_->argv[0] + 2, options->long_name); if (!rest) { // Negation allowed? if (options->flags & OPT_NONEG) { continue; } // Only boolean/bit allow negation. if (options->type != ARGPARSE_OPT_BOOLEAN && options->type != ARGPARSE_OPT_BIT) { continue; } if (!prefix_cmp(this_->argv[0] + 2, "no-")) { rest = prefix_skip(this_->argv[0] + 2 + 3, options->long_name); if (!rest) continue; opt_flags |= OPT_UNSET; } else { continue; } } if (*rest) { if (*rest != '=') continue; this_->optvalue = rest + 1; } return argparse_getvalue(this_, options, opt_flags); } return -2; }
static int argparse_long_opt(struct argparse *self, const struct argparse_option *options) { for (; options->type != ARGPARSE_OPT_END; options++) { const char *rest; int opt_flags = 0; if (!options->long_name) continue; rest = prefix_skip(self->argv[0] + 2, options->long_name); if (!rest) { // negation disabled? if (options->flags & OPT_NONEG) { continue; } // only OPT_BOOLEAN/OPT_BIT supports negation if (options->type != ARGPARSE_OPT_BOOLEAN && options->type != ARGPARSE_OPT_BIT) { continue; } if (prefix_cmp(self->argv[0] + 2, "no-")) { continue; } rest = prefix_skip(self->argv[0] + 2 + 3, options->long_name); if (!rest) continue; opt_flags |= OPT_UNSET; } if (*rest) { if (*rest != '=') continue; self->optvalue = rest + 1; } return argparse_getvalue(self, options, opt_flags | OPT_LONG); } return -2; }