* passed to getopt() with the corresponding short options. The caller is
* responsible for freeing the string. */
char *
-long_options_to_short_options(const struct option options[])
+ovs_cmdl_long_options_to_short_options(const struct option options[])
{
char short_options[UCHAR_MAX * 3 + 1];
char *p = short_options;
return xstrdup(short_options);
}
-/* Given the 'struct command' array, prints the usage of all commands. */
+/* Given the 'struct ovs_cmdl_command' array, prints the usage of all commands. */
void
-print_commands(const struct command commands[])
+ovs_cmdl_print_commands(const struct ovs_cmdl_command commands[])
{
struct ds ds = DS_EMPTY_INITIALIZER;
ds_put_cstr(&ds, "The available commands are:\n");
for (; commands->name; commands++) {
- const struct command *c = commands;
+ const struct ovs_cmdl_command *c = commands;
ds_put_format(&ds, " %-23s %s\n", c->name, c->usage ? c->usage : "");
}
printf("%s", ds.string);
/* Given the GNU-style options in 'options', prints all options. */
void
-print_options(const struct option options[])
+ovs_cmdl_print_options(const struct option options[])
{
struct ds ds = DS_EMPTY_INITIALIZER;
* Command-line options should be stripped off, so that a typical invocation
* looks like "run_command(argc - optind, argv + optind, my_commands);". */
void
-run_command(int argc, char *argv[], const struct command commands[])
+ovs_cmdl_run_command(int argc, char *argv[], const struct ovs_cmdl_command commands[])
{
- const struct command *p;
+ const struct ovs_cmdl_command *p;
if (argc < 1) {
ovs_fatal(0, "missing command name; use --help for help");
* before anything else, period, at the very beginning of program
* execution. */
void
-proctitle_init(int argc, char **argv)
+ovs_cmdl_proctitle_init(int argc, char **argv)
{
int i;
/* Changes the name of the process, as shown by "ps", to the program name
* followed by 'format', which is formatted as if by printf(). */
void
-proctitle_set(const char *format, ...)
+ovs_cmdl_proctitle_set(const char *format, ...)
{
va_list args;
int n;
/* Restores the process's original command line, as seen by "ps". */
void
-proctitle_restore(void)
+ovs_cmdl_proctitle_restore(void)
{
ovs_mutex_lock(&proctitle_mutex);
if (saved_proctitle) {
/* Stubs that don't do anything on non-Linux systems. */
void
-proctitle_init(int argc OVS_UNUSED, char **argv OVS_UNUSED)
+ovs_cmdl_proctitle_init(int argc OVS_UNUSED, char **argv OVS_UNUSED)
{
}
#if !(defined(__FreeBSD__) || defined(__NetBSD__))
/* On these platforms we #define this to setproctitle. */
void
-proctitle_set(const char *format OVS_UNUSED, ...)
+ovs_cmdl_proctitle_set(const char *format OVS_UNUSED, ...)
{
}
#endif
void
-proctitle_restore(void)
+ovs_cmdl_proctitle_restore(void)
{
}
#endif /* !__linux__ */
struct option;
-struct command {
+struct ovs_cmdl_command {
const char *name;
const char *usage;
int min_args;
void (*handler)(int argc, char *argv[]);
};
-char *long_options_to_short_options(const struct option *options);
-void print_options(const struct option *options);
-void print_commands(const struct command *commands);
-void run_command(int argc, char *argv[], const struct command[]);
+char *ovs_cmdl_long_options_to_short_options(const struct option *options);
+void ovs_cmdl_print_options(const struct option *options);
+void ovs_cmdl_print_commands(const struct ovs_cmdl_command *commands);
+void ovs_cmdl_run_command(int argc, char *argv[], const struct ovs_cmdl_command[]);
-void proctitle_init(int argc, char **argv);
+void ovs_cmdl_proctitle_init(int argc, char **argv);
#if defined(__FreeBSD__) || defined(__NetBSD__)
-#define proctitle_set setproctitle
+#define ovs_cmdl_proctitle_set setproctitle
#else
-void proctitle_set(const char *, ...)
+void ovs_cmdl_proctitle_set(const char *, ...)
OVS_PRINTF_FORMAT(1, 2);
#endif
-void proctitle_restore(void);
+void ovs_cmdl_proctitle_restore(void);
#endif /* command-line.h */
int retval;
int status;
- proctitle_set("monitoring pid %lu (%s)",
- (unsigned long int) daemon_pid, status_msg);
+ ovs_cmdl_proctitle_set("monitoring pid %lu (%s)",
+ (unsigned long int) daemon_pid, status_msg);
if (child_ready) {
do {
free(status_msg);
/* Running in new daemon process. */
- proctitle_restore();
+ ovs_cmdl_proctitle_restore();
set_subprogram_name("");
}
const char *database;
struct jsonrpc *rpc;
- proctitle_init(argc, argv);
+ ovs_cmdl_proctitle_init(argc, argv);
set_program_name(argv[0]);
parse_options(argc, argv);
fatal_ignore_sigpipe();
TABLE_LONG_OPTIONS,
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
int c;
char *error;
int i;
- proctitle_init(argc, argv);
+ ovs_cmdl_proctitle_init(argc, argv);
set_program_name(argv[0]);
service_start(&argc, &argv);
fatal_ignore_sigpipe();
{"ca-cert", required_argument, NULL, 'C'},
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
int argc = *argcp;
char **argv = *argvp;
/* -m, --more: Verbosity level for "show-log" command output. */
static int show_log_verbosity;
-static const struct command *get_all_commands(void);
+static const struct ovs_cmdl_command *get_all_commands(void);
OVS_NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[]);
set_program_name(argv[0]);
parse_options(argc, argv);
fatal_ignore_sigpipe();
- run_command(argc - optind, argv + optind, get_all_commands());
+ ovs_cmdl_run_command(argc - optind, argv + optind, get_all_commands());
return 0;
}
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
int c;
usage();
case 'o':
- print_options(long_options);
+ ovs_cmdl_print_options(long_options);
exit(EXIT_SUCCESS);
case 'V':
static void
do_list_commands(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
- print_commands(get_all_commands());
+ ovs_cmdl_print_commands(get_all_commands());
}
-static const struct command all_commands[] = {
+static const struct ovs_cmdl_command all_commands[] = {
{ "create", "[db [schema]]", 0, 2, do_create },
{ "compact", "[db [dst]]", 0, 2, do_compact },
{ "convert", "[db [schema [dst]]]", 0, 3, do_convert },
{ NULL, NULL, 0, 0, NULL },
};
-static const struct command *get_all_commands(void)
+static const struct ovs_cmdl_command *get_all_commands(void)
{
return all_commands;
}
#include "ovstest.h"
#include "util.h"
-static struct command *commands = NULL;
+static struct ovs_cmdl_command *commands = NULL;
static size_t n_commands = 0;
static size_t allocated_commands = 0;
static void
-add_command(struct command *cmd)
+add_command(struct ovs_cmdl_command *cmd)
{
- const struct command nil = {NULL, NULL, 0, 0, NULL};
+ const struct ovs_cmdl_command nil = {NULL, NULL, 0, 0, NULL};
while (n_commands + 1 >= allocated_commands) {
commands = x2nrealloc(commands, &allocated_commands,
static void
help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
- const struct command *p;
+ const struct ovs_cmdl_command *p;
struct ds test_names = DS_EMPTY_INITIALIZER;
const int linesize = 70;
static void
add_top_level_commands(void)
{
- struct command help_cmd = {"--help", NULL, 0, 0, help};
+ struct ovs_cmdl_command help_cmd = {"--help", NULL, 0, 0, help};
add_command(&help_cmd);
}
void
ovstest_register(const char *test_name, ovstest_func f)
{
- struct command test_cmd;
+ struct ovs_cmdl_command test_cmd;
test_cmd.name = test_name;
test_cmd.usage = NULL;
add_top_level_commands();
if (argc > 1) {
- run_command(argc - 1, argv + 1, commands);
+ ovs_cmdl_run_command(argc - 1, argv + 1, commands);
}
cleanup();
printf("\n");
}
-static const struct command commands[] = {
+static const struct ovs_cmdl_command commands[] = {
{"check", NULL, 0, 0, run_tests},
{"benchmark", NULL, 1, 1, run_benchmarks},
{NULL, NULL, 0, 0, NULL},
test_bitmap_main(int argc, char *argv[])
{
set_program_name(argv[0]);
- run_command(argc - 1, argv + 1, commands);
+ ovs_cmdl_run_command(argc - 1, argv + 1, commands);
}
OVSTEST_REGISTER("test-bitmap", test_bitmap_main);
minimask_destroy(&minicatchall);
}
\f
-static const struct command commands[] = {
+static const struct ovs_cmdl_command commands[] = {
/* Classifier tests. */
{"empty", NULL, 0, 0, test_empty},
{"destroy-null", NULL, 0, 0, test_destroy_null},
{
set_program_name(argv[0]);
init_values();
- run_command(argc - 1, argv + 1, commands);
+ ovs_cmdl_run_command(argc - 1, argv + 1, commands);
}
OVSTEST_REGISTER("test-classifier", test_classifier_main);
free(elements);
}
\f
-static const struct command commands[] = {
+static const struct ovs_cmdl_command commands[] = {
{"check", NULL, 0, 1, run_tests},
{"benchmark", NULL, 3, 4, run_benchmarks},
{NULL, NULL, 0, 0, NULL},
test_cmap_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
set_program_name(argv[0]);
- run_command(argc - optind, argv + optind, commands);
+ ovs_cmdl_run_command(argc - optind, argv + optind, commands);
}
OVSTEST_REGISTER("test-cmap", test_cmap_main);
}
}
-static const struct command commands[] = {
+static const struct ovs_cmdl_command commands[] = {
{ "insert-delete-same-order", NULL, 0, 0,
test_heap_insert_delete_same_order, },
{ "insert-delete-reverse-order", NULL, 0, 0,
{
set_program_name(argv[0]);
- run_command(argc - 1, argv + 1, commands);
+ ovs_cmdl_run_command(argc - 1, argv + 1, commands);
}
OVSTEST_REGISTER("test-heap", test_heap_main);
OVS_NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[]);
-static struct command *get_all_commands(void);
+static struct ovs_cmdl_command *get_all_commands(void);
static void
test_jsonrpc_main(int argc, char *argv[])
{
- proctitle_init(argc, argv);
+ ovs_cmdl_proctitle_init(argc, argv);
set_program_name(argv[0]);
service_start(&argc, &argv);
parse_options(argc, argv);
- run_command(argc - optind, argv + optind, get_all_commands());
+ ovs_cmdl_run_command(argc - optind, argv + optind, get_all_commands());
}
static void
STREAM_SSL_LONG_OPTIONS,
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
int c = getopt_long(argc, argv, short_options, long_options, NULL);
usage();
}
-static struct command all_commands[] = {
+static struct ovs_cmdl_command all_commands[] = {
{ "listen", NULL, 1, 1, do_listen },
{ "request", NULL, 3, 3, do_request },
{ "notify", NULL, 3, 3, do_notify },
{ NULL, NULL, 0, 0, NULL },
};
-static struct command *
+static struct ovs_cmdl_command *
get_all_commands(void)
{
return all_commands;
int sock;
int n;
- proctitle_init(argc, argv);
+ ovs_cmdl_proctitle_init(argc, argv);
set_program_name(argv[0]);
service_start(&argc, &argv);
parse_options(argc, argv);
VLOG_LONG_OPTIONS,
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
int c = getopt_long(argc, argv, short_options, long_options, NULL);
OVS_NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[]);
-static struct command *get_all_commands(void);
+static struct ovs_cmdl_command *get_all_commands(void);
int
main(int argc, char *argv[])
{
set_program_name(argv[0]);
parse_options(argc, argv);
- run_command(argc - optind, argv + optind, get_all_commands());
+ ovs_cmdl_run_command(argc - optind, argv + optind, get_all_commands());
return 0;
}
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
unsigned long int timeout;
static void
do_transact(int argc, char *argv[])
{
- static const struct command do_transact_commands[] = {
+ static const struct ovs_cmdl_command do_transact_commands[] = {
{ "commit", NULL, 0, 0, do_transact_commit },
{ "abort", NULL, 0, 0, do_transact_abort },
{ "insert", NULL, 2, 3, do_transact_insert },
fputs(args[j], stdout);
}
fputs(":", stdout);
- run_command(n_args, args, do_transact_commands);
+ ovs_cmdl_run_command(n_args, args, do_transact_commands);
putchar('\n');
for (j = 0; j < n_args; j++) {
printf("%03d: done\n", step);
}
-static struct command all_commands[] = {
+static struct ovs_cmdl_command all_commands[] = {
{ "log-io", NULL, 2, INT_MAX, do_log_io },
{ "default-atoms", NULL, 0, 0, do_default_atoms },
{ "default-data", NULL, 0, 0, do_default_data },
{ NULL, NULL, 0, 0, NULL },
};
-static struct command *
+static struct ovs_cmdl_command *
get_all_commands(void)
{
return all_commands;
static void diff_stats(const struct reconnect_stats *old,
const struct reconnect_stats *new,
int delta);
-static const struct command *get_all_commands(void);
+static const struct ovs_cmdl_command *get_all_commands(void);
static void
test_reconnect_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
svec_parse_words(&args, line);
svec_terminate(&args);
if (!svec_is_empty(&args)) {
- run_command(args.n, args.names, get_all_commands());
+ ovs_cmdl_run_command(args.n, args.names, get_all_commands());
}
svec_destroy(&args);
reconnect_listen_error(reconnect, now, atoi(argv[1]));
}
-static const struct command all_commands[] = {
+static const struct ovs_cmdl_command all_commands[] = {
{ "enable", NULL, 0, 0, do_enable },
{ "disable", NULL, 0, 0, do_disable },
{ "force-reconnect", NULL, 0, 0, do_force_reconnect },
{ NULL, NULL, 0, 0, NULL },
};
-static const struct command *
+static const struct ovs_cmdl_command *
get_all_commands(void)
{
return all_commands;
int error;
int sock;
- proctitle_init(argc, argv);
+ ovs_cmdl_proctitle_init(argc, argv);
set_program_name(argv[0]);
service_start(&argc, &argv);
parse_options(argc, argv);
VLOG_LONG_OPTIONS,
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
int c = getopt_long(argc, argv, short_options, long_options, NULL);
}
#endif /* _WIN32 */
\f
-static const struct command commands[] = {
+static const struct ovs_cmdl_command commands[] = {
{"ctz", NULL, 0, 0, test_ctz},
{"clz", NULL, 0, 0, test_clz},
{"round_up_pow2", NULL, 0, 0, test_round_up_pow2},
VLOG_LONG_OPTIONS,
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
int c = getopt_long(argc, argv, short_options, long_options, NULL);
* POSIX doesn't define the circumstances in which stderr is
* fully buffered either. */
setvbuf(stderr, NULL, _IONBF, 0);
- run_command(argc - optind, argv + optind, commands);
+ ovs_cmdl_run_command(argc - optind, argv + optind, commands);
}
OVSTEST_REGISTER("test-util", test_util_main);
ofpbuf_delete(hello);
}
-static const struct command commands[] = {
+static const struct ovs_cmdl_command commands[] = {
{"refuse-connection", NULL, 1, 1, test_refuse_connection},
{"accept-then-close", NULL, 1, 1, test_accept_then_close},
{"read-hello", NULL, 1, 1, test_read_hello},
time_alarm(10);
- run_command(argc - 1, argv + 1, commands);
+ ovs_cmdl_run_command(argc - 1, argv + 1, commands);
}
OVSTEST_REGISTER("test-vconn", test_vconn_main);
VLOG_LONG_OPTIONS,
{NULL, 0, NULL, 0},
};
- char *short_options_ = long_options_to_short_options(long_options);
+ char *short_options_ = ovs_cmdl_long_options_to_short_options(long_options);
char *short_options = xasprintf("+%s", short_options_);
const char *target;
int e_options;
break;
case 'o':
- print_options(long_options);
+ ovs_cmdl_print_options(long_options);
exit(EXIT_SUCCESS);
case 'T':
static double timeout;
-static const struct command *get_all_commands(void);
+static const struct ovs_cmdl_command *get_all_commands(void);
static void parse_options(int argc, char *argv[]);
static void usage(void);
set_program_name(argv[0]);
vlog_set_levels(NULL, VLF_ANY_DESTINATION, VLL_EMER);
parse_options(argc, argv);
- run_command(argc - optind, argv + optind, get_all_commands());
+ ovs_cmdl_run_command(argc - optind, argv + optind, get_all_commands());
return 0;
}
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
local_addr.s_addr = htonl(INADDR_ANY);
local_min_port = local_max_port = 0;
usage();
}
-static const struct command all_commands[] = {
+static const struct ovs_cmdl_command all_commands[] = {
{ "listen", NULL, 0, 0, cmd_listen },
{ "rate", NULL, 0, 0, cmd_rate },
{ "latency", NULL, 0, 0, cmd_latency },
{ NULL, NULL, 0, 0, NULL },
};
-static const struct command *get_all_commands(void)
+static const struct ovs_cmdl_command *get_all_commands(void)
{
return all_commands;
}
VLOG_LONG_OPTIONS,
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
unsigned long int timeout;
usage(NULL);
case 'o':
- print_options(long_options);
+ ovs_cmdl_print_options(long_options);
exit(EXIT_SUCCESS);
case 'V':
static struct sort_criterion *criteria;
static size_t n_criteria, allocated_criteria;
-static const struct command *get_all_commands(void);
+static const struct ovs_cmdl_command *get_all_commands(void);
OVS_NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[]);
service_start(&argc, &argv);
parse_options(argc, argv);
fatal_ignore_sigpipe();
- run_command(argc - optind, argv + optind, get_all_commands());
+ ovs_cmdl_run_command(argc - optind, argv + optind, get_all_commands());
return 0;
}
STREAM_SSL_LONG_OPTIONS,
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
uint32_t versions;
enum ofputil_protocol version_protocols;
usage();
case 'o':
- print_options(long_options);
+ ovs_cmdl_print_options(long_options);
exit(EXIT_SUCCESS);
case OPT_STRICT:
static void
ofctl_list_commands(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
- print_commands(get_all_commands());
+ ovs_cmdl_print_commands(get_all_commands());
}
\f
/* replace-flows and diff-flows commands. */
ofpbuf_delete(hello);
}
-static const struct command all_commands[] = {
+static const struct ovs_cmdl_command all_commands[] = {
{ "show", "switch",
1, 1, ofctl_show },
{ "monitor", "switch [misslen] [invalid_ttl] [watch:[...]]",
{ NULL, NULL, 0, 0, NULL },
};
-static const struct command *get_all_commands(void)
+static const struct ovs_cmdl_command *get_all_commands(void)
{
return all_commands;
}
int retval;
int i;
- proctitle_init(argc, argv);
+ ovs_cmdl_proctitle_init(argc, argv);
set_program_name(argv[0]);
parse_options(argc, argv);
fatal_ignore_sigpipe();
{"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
int indexptr;
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
int option;
size_t n_options;
size_t i;
- tmp = long_options_to_short_options(global_long_options);
+ tmp = ovs_cmdl_long_options_to_short_options(global_long_options);
short_options = xasprintf("+%s", tmp);
free(tmp);
argc -= retval;
argv += retval;
- proctitle_init(argc, argv);
+ ovs_cmdl_proctitle_init(argc, argv);
service_start(&argc, &argv);
remote = parse_options(argc, argv, &unixctl_path);
fatal_ignore_sigpipe();
{"dpdk", required_argument, NULL, OPT_DPDK},
{NULL, 0, NULL, 0},
};
- char *short_options = long_options_to_short_options(long_options);
+ char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
for (;;) {
int c;
size_t n_options;
size_t i;
- tmp = long_options_to_short_options(global_long_options);
+ tmp = ovs_cmdl_long_options_to_short_options(global_long_options);
short_options = xasprintf("+%s", tmp);
free(tmp);