diff --git a/src/fpga.c b/src/fpga.c index e7bce9fe9..4b137f663 100644 --- a/src/fpga.c +++ b/src/fpga.c @@ -26,10 +26,12 @@ int fpga_benchmarks(int argc, char *argv[], struct fpga_card *c); void usage() { - printf("Usage: villas-fpga CONFIGFILE CARD [OPTIONS]\n\n"); - printf(" Options:\n"); - printf(" -d Set log level\n\n"); - + printf("Usage: villas-fpga [OPTIONS] CONFIG CARD\n\n"); + printf(" CONFIG path to a configuration file\n"); + printf(" CARD name of the FPGA card\n"); + printf(" OPTIONS is one or more of the following options:\n"); + printf(" -d Set log level\n"); + printf("\n"); print_copyright(); } @@ -40,28 +42,33 @@ int main(int argc, char *argv[]) struct super_node sn; struct fpga_card *card; - if (argc < 3) { - usage(argv[0]); - exit(EXIT_FAILURE); - } - /* Parse arguments */ char c, *endptr; - while ((c = getopt(argc-1, argv+1, "d:")) != -1) { + while ((c = getopt(argc, argv, "d:")) != -1) { switch (c) { case 'd': sn.log.level = strtoul(optarg, &endptr, 10); - break; + goto check; case '?': default: usage(); exit(EXIT_SUCCESS); } + +check: if (optarg == endptr) + error("Failed to parse parse option argument '-%c %s'", c, optarg); } + + if (argc != optind + 2) { + usage(); + exit(EXIT_FAILURE); + } + + char *configfile = argv[optind]; super_node_init(&sn); - super_node_parse_uri(&sn, argv[1]); + super_node_parse_uri(&sn, configfile); log_init(&sn.log, sn.log.level, sn.log.facilities); rt_init(sn.priority, sn.affinity); diff --git a/src/hook.c b/src/hook.c index 0d1273489..f0c35a273 100644 --- a/src/hook.c +++ b/src/hook.c @@ -75,14 +75,14 @@ static int hook_parse_cli(struct hook *h, char *params[], int paramlen) static void usage() { - printf("Usage: villas-hook [OPTIONS] NAME [PARAM] \n"); - printf(" PARAM a string of configuration settings for the hook\n"); - printf(" OPTIONS are:\n"); + printf("Usage: villas-hook [OPTIONS] NAME [[PARAM1] [PARAM2] ...]\n"); + printf(" NAME the name of the hook function\n"); + printf(" PARAM* a string of configuration settings for the hook\n"); + printf(" OPTIONS is one or more of the following options:\n"); printf(" -h show this help\n"); printf(" -d LVL set debug level to LVL\n"); printf(" -v CNT process CNT samples at once\n"); - printf(" NAME the name of the hook function\n\n"); - + printf("\n"); printf("The following hook functions are supported:\n"); plugin_dump(PLUGIN_TYPE_HOOK); printf("\n"); @@ -103,8 +103,6 @@ int main(int argc, char *argv[]) level = V; cnt = 1; - char *name; - struct log log; struct plugin *p; struct sample *samples[cnt]; @@ -133,6 +131,8 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + char *hookstr = argv[optind]; + if (cnt < 1) error("Vectorize option must be greater than 0"); @@ -145,11 +145,11 @@ int main(int argc, char *argv[]) if (ret) error("Failed to initilize memory pool"); - name = argv[optind]; + - p = plugin_lookup(PLUGIN_TYPE_HOOK, name); + p = plugin_lookup(PLUGIN_TYPE_HOOK, hookstr); if (!p) - error("Unknown hook function '%s'", name); + error("Unknown hook function '%s'", hookstr); config_init(&cfg); diff --git a/src/pipe.c b/src/pipe.c index 043c82476..8403c5051 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -86,7 +86,7 @@ static void quit(int signal, siginfo_t *sinfo, void *ctx) static void usage() { - printf("Usage: villas-pipe CONFIG NODE [OPTIONS]\n"); + printf("Usage: villas-pipe [OPTIONS] CONFIG NODE\n"); printf(" CONFIG path to a configuration file\n"); printf(" NODE the name of the node to which samples are sent and received from\n"); printf(" OPTIONS are:\n"); @@ -220,25 +220,28 @@ int main(int argc, char *argv[]) } } - if (argc < optind + 2) { + if (argc != optind + 2) { usage(); exit(EXIT_FAILURE); } + char *configfile = argv[optind]; + char *nodestr = argv[optind+1]; + log_init(&sn.log, level, LOG_ALL); log_start(&sn.log); super_node_init(&sn); - super_node_parse_uri(&sn, argv[optind]); + super_node_parse_uri(&sn, configfile); memory_init(sn.hugepages); signals_init(quit); rt_init(sn.priority, sn.affinity); /* Initialize node */ - node = list_lookup(&sn.nodes, argv[optind+1]); + node = list_lookup(&sn.nodes, nodestr); if (!node) - error("Node '%s' does not exist!", argv[optind+1]); + error("Node '%s' does not exist!", nodestr); if (node->_vt->start == websocket_start) { web_start(&sn.web); diff --git a/src/signal.c b/src/signal.c index 6ed697d92..573951f99 100644 --- a/src/signal.c +++ b/src/signal.c @@ -46,16 +46,24 @@ enum SIGNAL_TYPE { void usage() { - printf("Usage: villas-signal SIGNAL [OPTIONS]\n"); - printf(" SIGNAL is on of: 'mixed', 'random', 'sine', 'triangle', 'square', 'ramp'\n"); - printf(" -d LVL set debug level\n"); - printf(" -v NUM specifies how many values a message should contain\n"); - printf(" -r HZ how many messages per second\n"); - printf(" -n non real-time mode. do not throttle output.\n"); - printf(" -f HZ the frequency of the signal\n"); - printf(" -a FLT the amplitude\n"); - printf(" -D FLT the standard deviation for 'random' signals\n"); - printf(" -l NUM only send LIMIT messages and stop\n\n"); + printf("Usage: villas-signal [OPTIONS] SIGNAL\n"); + printf(" SIGNAL is on of the following signal types:\n"); + printf(" mixed\n"); + printf(" random\n"); + printf(" sine\n"); + printf(" triangle\n"); + printf(" square\n"); + printf(" ramp\n"); + printf("\n"); + printf(" OPTIONS is one or more of the following options:\n"); + printf(" -d LVL set debug level\n"); + printf(" -v NUM specifies how many values a message should contain\n"); + printf(" -r HZ how many messages per second\n"); + printf(" -n non real-time mode. do not throttle output.\n"); + printf(" -f HZ the frequency of the signal\n"); + printf(" -a FLT the amplitude\n"); + printf(" -D FLT the standard deviation for 'random' signals\n"); + printf(" -l NUM only send LIMIT messages and stop\n\n"); print_copyright(); } @@ -81,28 +89,9 @@ int main(int argc, char *argv[]) int limit = -1; int counter, tfd, steps, level = V; - if (argc < 2) { - usage(); - exit(EXIT_FAILURE); - } - - /* Parse signal type */ - if (!strcmp(argv[1], "random")) - type = TYPE_RANDOM; - else if (!strcmp(argv[1], "sine")) - type = TYPE_SINE; - else if (!strcmp(argv[1], "square")) - type = TYPE_SQUARE; - else if (!strcmp(argv[1], "triangle")) - type = TYPE_TRIANGLE; - else if (!strcmp(argv[1], "ramp")) - type = TYPE_RAMP; - else if (!strcmp(argv[1], "mixed")) - type = TYPE_MIXED; - /* Parse optional command line arguments */ char c, *endptr; - while ((c = getopt(argc-1, argv+1, "hv:r:f:l:a:D:d:n")) != -1) { + while ((c = getopt(argc, argv, "hv:r:f:l:a:D:d:n")) != -1) { switch (c) { case 'd': level = strtoul(optarg, &endptr, 10); @@ -139,6 +128,29 @@ int main(int argc, char *argv[]) check: if (optarg == endptr) error("Failed to parse parse option argument '-%c %s'", c, optarg); } + + if (argc != optind + 1) { + usage(); + exit(EXIT_FAILURE); + } + + char *typestr = argv[optind]; + + /* Parse signal type */ + if (!strcmp(typestr, "random")) + type = TYPE_RANDOM; + else if (!strcmp(typestr, "sine")) + type = TYPE_SINE; + else if (!strcmp(typestr, "square")) + type = TYPE_SQUARE; + else if (!strcmp(typestr, "triangle")) + type = TYPE_TRIANGLE; + else if (!strcmp(typestr, "ramp")) + type = TYPE_RAMP; + else if (!strcmp(typestr, "mixed")) + type = TYPE_MIXED; + else + error("Invalid signal type: %s", typestr); log_init(&log, level, LOG_ALL); diff --git a/src/test-cmp.c b/src/test-cmp.c index d8be78ea8..7c802c8ae 100644 --- a/src/test-cmp.c +++ b/src/test-cmp.c @@ -37,13 +37,21 @@ void usage() { - printf("Usage: villas-test-cmp FILE1 FILE2 [OPTIONS]\n"); + printf("Usage: villas-test-cmp [OPTIONS] FILE1 FILE2\n"); printf(" FILE1 first file to compare\n"); printf(" FILE2 second file to compare against\n"); - printf(" OPTIONS the following optional options:\n"); - printf(" -h print this usage information\n"); - printf(" -d LVL adjust the debug level\n"); - printf(" -e EPS set epsilon for floating point comparisons to EPS\n"); + printf(" OPTIONS is one or more of the following options:\n"); + printf(" -h print this usage information\n"); + printf(" -d LVL adjust the debug level\n"); + printf(" -e EPS set epsilon for floating point comparisons to EPS\n"); + printf("\n"); + printf("Return codes:\n"); + printf(" 0 files are equal\n"); + printf(" 1 file length not equal\n"); + printf(" 2 sequence no not equal\n"); + printf(" 3 timestamp not equal\n"); + printf(" 4 number of values is not equal\n"); + printf(" 5 data is not equal\n"); printf("\n"); print_copyright(); @@ -87,7 +95,7 @@ check: if (optarg == endptr) error("Failed to parse parse option argument '-%c %s'", c, optarg); } - if (argc < optind + 2) { + if (argc != optind + 2) { usage(); exit(EXIT_FAILURE); } diff --git a/src/test-rtt.c b/src/test-rtt.c index 0079f0e9a..f92d8bd9b 100644 --- a/src/test-rtt.c +++ b/src/test-rtt.c @@ -67,16 +67,16 @@ void quit(int signal, siginfo_t *sinfo, void *ctx) void usage() { - printf("Usage: villas-test-rtt CONFIG NODE [ARGS]\n"); + printf("Usage: villas-test-rtt [OPTIONS] CONFIG NODE\n"); printf(" CONFIG path to a configuration file\n"); printf(" NODE name of the node which shoud be used\n"); - printf(" ARGS the following optional options:\n"); - printf(" -c CNT send CNT messages\n"); - printf(" -f FD use file descriptor FD for result output instead of stdout\n"); - printf(" -l LOW smallest value for histogram\n"); - printf(" -H HIGH largest value for histogram\n"); - printf(" -r RES bucket resolution for histogram\n"); - printf(" -h show this usage information\n"); + printf(" OPTIONS is one or more of the following options:\n"); + printf(" -c CNT send CNT messages\n"); + printf(" -f FD use file descriptor FD for result output instead of stdout\n"); + printf(" -l LOW smallest value for histogram\n"); + printf(" -H HIGH largest value for histogram\n"); + printf(" -r RES bucket resolution for histogram\n"); + printf(" -h show this usage information\n"); printf("\n"); print_copyright(); @@ -84,30 +84,9 @@ void usage() int main(int argc, char *argv[]) { - if (argc < 4) { - usage(); - exit(EXIT_FAILURE); - } - - log_init(&sn.log, V, LOG_ALL); - - super_node_init(&sn); - super_node_parse_uri(&sn, argv[1]); - - signals_init(quit); - rt_init(sn.priority, sn.affinity); - memory_init(sn.hugepages); - - node = list_lookup(&sn.nodes, argv[3]); - if (!node) - error("There's no node with the name '%s'", argv[3]); - - node_type_start(node->_vt, &sn); - node_start(node); - /* Parse Arguments */ char c, *endptr; - while ((c = getopt (argc-3, argv+3, "l:hH:r:f:c:")) != -1) { + while ((c = getopt (argc, argv, "l:hH:r:f:c:")) != -1) { switch (c) { case 'c': count = strtoul(optarg, &endptr, 10); @@ -135,6 +114,30 @@ int main(int argc, char *argv[]) check: if (optarg == endptr) error("Failed to parse parse option argument '-%c %s'", c, optarg); } + + if (argc != optind + 2) { + usage(); + exit(EXIT_FAILURE); + } + + char *configfile = argv[optind]; + char *nodestr = argv[optind + 1]; + + log_init(&sn.log, V, LOG_ALL); + + super_node_init(&sn); + super_node_parse_uri(&sn, configfile); + + signals_init(quit); + rt_init(sn.priority, sn.affinity); + memory_init(sn.hugepages); + + node = list_lookup(&sn.nodes, nodestr); + if (!node) + error("There's no node with the name '%s'", nodestr); + + node_type_start(node->_vt, &sn); + node_start(node); test_rtt();