X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utilities%2Fovs-dpctl.c;h=08713eb0777ea49344bdd1383967d859a5948da0;hb=675febfa2f31372e45e2a6a28ce19256b22106d7;hp=5a0da820c2fbe8a06c8f3b091fa23550ea542d32;hpb=e8b52a913a8fc3d2ef0dae82eda5905668ebfae1;p=openvswitch diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index 5a0da820..08713eb0 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -43,56 +43,20 @@ #include "vlog.h" #define THIS_MODULE VLM_dpctl -struct command { - const char *name; - int min_args; - int max_args; - void (*handler)(int argc, char *argv[]); -}; - -static struct command all_commands[]; +static const struct command all_commands[]; static void usage(void) NO_RETURN; static void parse_options(int argc, char *argv[]); -int main(int argc, char *argv[]) +int +main(int argc, char *argv[]) { - struct command *p; - set_program_name(argv[0]); time_init(); vlog_init(); parse_options(argc, argv); signal(SIGPIPE, SIG_IGN); - - argc -= optind; - argv += optind; - if (argc < 1) - ovs_fatal(0, "missing command name; use --help for help"); - - for (p = all_commands; p->name != NULL; p++) { - if (!strcmp(p->name, argv[0])) { - int n_arg = argc - 1; - if (n_arg < p->min_args) - ovs_fatal(0, "'%s' command requires at least %d arguments", - p->name, p->min_args); - else if (n_arg > p->max_args) - ovs_fatal(0, "'%s' command takes at most %d arguments", - p->name, p->max_args); - else { - p->handler(argc, argv); - if (ferror(stdout)) { - ovs_fatal(0, "write to stdout failed"); - } - if (ferror(stderr)) { - ovs_fatal(0, "write to stderr failed"); - } - exit(0); - } - } - } - ovs_fatal(0, "unknown command '%s'; use --help for help", argv[0]); - + run_command(argc - optind, argv + optind, all_commands); return 0; } @@ -527,7 +491,7 @@ do_help(int argc UNUSED, char *argv[] UNUSED) usage(); } -static struct command all_commands[] = { +static const struct command all_commands[] = { { "add-dp", 1, INT_MAX, do_add_dp }, { "del-dp", 1, 1, do_del_dp }, { "add-if", 2, INT_MAX, do_add_if },