MCPcopy Create free account
hub / github.com/cofyc/argparse / argparse_long_opt

Function argparse_long_opt

argparse.c:161–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161static int
162argparse_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
200int
201argparse_init(struct argparse *self, struct argparse_option *options,

Callers 1

argparse_parseFunction · 0.85

Calls 3

prefix_skipFunction · 0.85
prefix_cmpFunction · 0.85
argparse_getvalueFunction · 0.85

Tested by

no test coverage detected