| 159 | } |
| 160 | |
| 161 | static int |
| 162 | argparse_long_opt(struct argparse *self, const struct argparse_option *options) |
| 163 | { |
| 164 | for (; options->type != ARGPARSE_OPT_END; options++) { |
| 165 | const char *rest; |
| 166 | int opt_flags = 0; |
| 167 | if (!options->long_name) |
| 168 | continue; |
| 169 | |
| 170 | rest = prefix_skip(self->argv[0] + 2, options->long_name); |
| 171 | if (!rest) { |
| 172 | // negation disabled? |
| 173 | if (options->flags & OPT_NONEG) { |
| 174 | continue; |
| 175 | } |
| 176 | // only OPT_BOOLEAN/OPT_BIT supports negation |
| 177 | if (options->type != ARGPARSE_OPT_BOOLEAN && options->type != |
| 178 | ARGPARSE_OPT_BIT) { |
| 179 | continue; |
| 180 | } |
| 181 | |
| 182 | if (prefix_cmp(self->argv[0] + 2, "no-")) { |
| 183 | continue; |
| 184 | } |
| 185 | rest = prefix_skip(self->argv[0] + 2 + 3, options->long_name); |
| 186 | if (!rest) |
| 187 | continue; |
| 188 | opt_flags |= OPT_UNSET; |
| 189 | } |
| 190 | if (*rest) { |
| 191 | if (*rest != '=') |
| 192 | continue; |
| 193 | self->optvalue = rest + 1; |
| 194 | } |
| 195 | return argparse_getvalue(self, options, opt_flags | OPT_LONG); |
| 196 | } |
| 197 | return -2; |
| 198 | } |
| 199 | |
| 200 | int |
| 201 | argparse_init(struct argparse *self, struct argparse_option *options, |
no test coverage detected