static int parse_options(int argc, char **argv) { int ch; getopt_reset(); while ((ch = getopt_long(argc, argv, SHORT_OPTS, opts, NULL)) != -1) { if (general_parse_opt(ch, &buzzy_raw_pkg)) { continue; } if (package_env_parse_opt(ch, &buzzy_raw_pkg)) { continue; } switch (ch) { case 'f': force = true; break; default: cork_command_show_help(&buzzy_raw_pkg, NULL); exit(EXIT_FAILURE); } } return optind; }
int execute_command(int argc, char **argv) { struct command *cmdtp; int ret; getopt_reset(); /* Look up command in command table */ if ((cmdtp = find_cmd(argv[0]))) { /* OK - call function to do the command */ ret = cmdtp->cmd(cmdtp, argc, argv); if (ret == COMMAND_ERROR_USAGE) { barebox_cmd_usage(cmdtp); return COMMAND_ERROR; } return ret; } else { #ifdef CONFIG_CMD_HELP printf ("Unknown command '%s' - try 'help'\n", argv[0]); #else printf ("Unknown command '%s'\n", argv[0]); #endif return -1; /* give up after bad command */ } }
static int get_options(struct options *options, int argc, char *argv[]) { getopt_reset(); int ch; int long_option_index; while (-1 != (ch = getopt_long(argc, argv, short_options, long_options, &long_option_index))) { switch (ch) { case option_value_debug: options->debug = true; break; case option_value_format: get_format(options, optarg); break; case option_value_help: options->help = true; return optind; case option_value_jrand48: get_jrand48(options, optarg); break; case option_value_verbose: options->verbose = true; break; default: options->error = true; break; } } return optind; }