Commit 4d77a253 authored by Alessandro Rubini's avatar Alessandro Rubini

tools: all tools get '-h' and '--help'

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 45a401c8
......@@ -8,6 +8,15 @@
#include "tools-common.h"
static void help(char *name)
{
fprintf(stderr, "%s: Use \"%s [-i <index>] [-d <dev>] <cmd>\"\n",
name, name);
fprintf(stderr, " cmd is one of \"get\", \"host\", "
"\"local\", \"wr\" or a floating point time in secs\n");
exit(1);
}
int main(int argc, char **argv)
{
struct fdelay_board *b;
......@@ -18,6 +27,9 @@ int main(int argc, char **argv)
/* Standard part of the file (repeated code) */
if (tools_need_help(argc, argv))
help(argv[0]);
nboards = fdelay_init();
if (nboards < 0) {
......@@ -41,13 +53,8 @@ int main(int argc, char **argv)
}
/* Parse the mandatory extra argument */
if (optind != argc - 1) {
fprintf(stderr, "%s: Use \"%s [-i <index>] [-d <dev>] <cmd>\"\n",
argv[0], argv[0]);
fprintf(stderr, " cmd is one of \"get\", \"host\", "
"\"local\", \"wr\" or a floating point time in secs\n");
exit(1);
}
if (optind != argc - 1)
help(argv[0]);
s = argv[optind];
/* Crappy parser */
if (!strcmp(s, "get"))
......
......@@ -7,12 +7,23 @@
#define FDELAY_INTERNAL /* hack... */
#include "fdelay-lib.h"
#include "tools-common.h"
static void help(char *name)
{
fprintf(stderr, "%s: Lists boards, takes no arguments\n", name);
exit(1);
}
int main(int argc, char **argv)
{
int i, j;
struct __fdelay_board *b;
struct fdelay_board *ub;
if (tools_need_help(argc, argv))
help(argv[0]);
if (argc > 1) {
fprintf(stderr, "%s: too many arguments (none expected)\n",
argv[0]);
......
......@@ -8,6 +8,13 @@
#include "tools-common.h"
static void help(char *name)
{
fprintf(stderr, "%s: Use \"%s [-i <index>] [-d <dev>] 1|0\n",
name, name);
exit(1);
}
int main(int argc, char **argv)
{
struct fdelay_board *b;
......@@ -16,6 +23,9 @@ int main(int argc, char **argv)
/* Standard part of the file (repeated code) */
if (tools_need_help(argc, argv))
help(argv[0]);
nboards = fdelay_init();
if (nboards < 0) {
......@@ -39,11 +49,8 @@ int main(int argc, char **argv)
}
/* Parse the mandatory extra argument */
if (optind != argc - 1) {
fprintf(stderr, "%s: Use \"%s [-i <index>] [-d <dev>] 1|0\n",
argv[0], argv[0]);
exit(1);
}
if (optind != argc - 1)
help(argv[0]);
newval = -1;
if (!strcmp(argv[optind], "0"))
newval = 0;
......
/*
* Simple code that is repeated over several tools
*/
/* Simple code that is repeated over several tools */
static void help(char *name); /* This is mandatory in all tools */
static inline void tools_getopt_d_i(int argc, char **argv,
int *dev, int *index)
......@@ -7,7 +10,7 @@ static inline void tools_getopt_d_i(int argc, char **argv,
char *rest;
int opt;
while ((opt = getopt(argc, argv, "d:i:")) != -1) {
while ((opt = getopt(argc, argv, "d:i:h")) != -1) {
switch (opt) {
case 'i':
*index = strtol(optarg, &rest, 0);
......@@ -25,6 +28,17 @@ static inline void tools_getopt_d_i(int argc, char **argv,
exit(1);
}
break;
case 'h':
help(argv[0]);
}
}
}
static inline int tools_need_help(int argc, char **argv)
{
if (argc != 2)
return 0;
if (!strcmp(argv[1], "--help"))
return 1;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment