MCPcopy Create free account
hub / github.com/F-Stack/f-stack / xo_parse_args

Function xo_parse_args

tools/libxo/libxo/libxo.c:8139–8225  ·  view source on GitHub ↗

* Parse any libxo-specific options from the command line, removing them * so the main() argument parsing won't see them. We return the new value * for argc or -1 for error. If an error occurred, the program should * exit. A suitable error message has already been displayed. */

Source from the content-addressed store, hash-verified

8137 * exit. A suitable error message has already been displayed.
8138 */
8139int
8140xo_parse_args (int argc, char **argv)
8141{
8142 static char libxo_opt[] = "--libxo";
8143 char *cp;
8144 int i, save;
8145
8146 /*
8147 * If xo_set_program has always been called, we honor that value
8148 */
8149 if (xo_program == NULL) {
8150 /* Save our program name for xo_err and friends */
8151 xo_program = argv[0];
8152 cp = strrchr(xo_program, '/');
8153 if (cp)
8154 xo_program = ++cp;
8155 else
8156 cp = argv[0]; /* Reset to front of string */
8157
8158 /*
8159 * GNU libtool add an annoying ".test" as the program
8160 * extension; we remove it. libtool also adds a "lt-" prefix
8161 * that we cannot remove.
8162 */
8163 size_t len = strlen(xo_program);
8164 static const char gnu_ext[] = ".test";
8165 if (len >= sizeof(gnu_ext)) {
8166 cp += len + 1 - sizeof(gnu_ext);
8167 if (xo_streq(cp, gnu_ext))
8168 *cp = '\0';
8169 }
8170 }
8171
8172 xo_handle_t *xop = xo_default(NULL);
8173
8174 for (save = i = 1; i < argc; i++) {
8175 if (argv[i] == NULL
8176 || strncmp(argv[i], libxo_opt, sizeof(libxo_opt) - 1) != 0) {
8177 if (save != i)
8178 argv[save] = argv[i];
8179 save += 1;
8180 continue;
8181 }
8182
8183 cp = argv[i] + sizeof(libxo_opt) - 1;
8184 if (*cp == '\0') {
8185 cp = argv[++i];
8186 if (cp == NULL) {
8187 xo_warnx("missing libxo option");
8188 return -1;
8189 }
8190
8191 if (xo_set_options(xop, cp) < 0)
8192 return -1;
8193 } else if (*cp == ':') {
8194 if (xo_set_options(xop, cp) < 0)
8195 return -1;
8196

Callers 15

main.cFile · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 6

strrchrFunction · 0.85
xo_streqFunction · 0.85
xo_defaultFunction · 0.85
strncmpFunction · 0.85
xo_warnxFunction · 0.85
xo_set_optionsFunction · 0.85

Tested by 13

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68