mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
dtc/fdt{get, put}/convert-dtsv0-lexer: convert to new usage helpers
This helps standardize the flag processing and the usage screens. Only lightly tested; would be great if someone who uses these utils could double check. Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
fdc7387845
commit
03449b84c8
5 changed files with 131 additions and 127 deletions
60
fdtget.c
60
fdtget.c
|
@ -277,33 +277,33 @@ static int do_fdtget(struct display_info *disp, const char *filename,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const char *usage_msg =
|
||||
"fdtget - read values from device tree\n"
|
||||
"\n"
|
||||
"Each value is printed on a new line.\n\n"
|
||||
"Usage:\n"
|
||||
/* Usage related data. */
|
||||
static const char usage_synopsis[] =
|
||||
"read values from device tree\n"
|
||||
" fdtget <options> <dt file> [<node> <property>]...\n"
|
||||
" fdtget -p <options> <dt file> [<node> ]...\n"
|
||||
"Options:\n"
|
||||
"\t-t <type>\tType of data\n"
|
||||
"\t-p\t\tList properties for each node\n"
|
||||
"\t-l\t\tList subnodes for each node\n"
|
||||
"\t-d\t\tDefault value to display when the property is "
|
||||
"missing\n"
|
||||
"\t-h\t\tPrint this help\n\n"
|
||||
"\n"
|
||||
"Each value is printed on a new line.\n"
|
||||
USAGE_TYPE_MSG;
|
||||
|
||||
static void usage(const char *msg)
|
||||
{
|
||||
if (msg)
|
||||
fprintf(stderr, "Error: %s\n\n", msg);
|
||||
|
||||
fprintf(stderr, "%s", usage_msg);
|
||||
exit(2);
|
||||
}
|
||||
static const char usage_short_opts[] = "t:pld:" USAGE_COMMON_SHORT_OPTS;
|
||||
static struct option const usage_long_opts[] = {
|
||||
{"type", a_argument, NULL, 't'},
|
||||
{"properties", no_argument, NULL, 'p'},
|
||||
{"list", no_argument, NULL, 'l'},
|
||||
{"default", a_argument, NULL, 'd'},
|
||||
USAGE_COMMON_LONG_OPTS,
|
||||
};
|
||||
static const char * const usage_opts_help[] = {
|
||||
"Type of data",
|
||||
"List properties for each node",
|
||||
"List subnodes for each node",
|
||||
"Default value to display when the property is missing",
|
||||
USAGE_COMMON_OPTS_HELP
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
char *filename = NULL;
|
||||
struct display_info disp;
|
||||
int args_per_step = 2;
|
||||
|
@ -312,20 +312,14 @@ int main(int argc, char *argv[])
|
|||
memset(&disp, '\0', sizeof(disp));
|
||||
disp.size = -1;
|
||||
disp.mode = MODE_SHOW_VALUE;
|
||||
for (;;) {
|
||||
int c = getopt(argc, argv, "d:hlpt:");
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
case '?':
|
||||
usage(NULL);
|
||||
while ((opt = util_getopt_long()) != EOF) {
|
||||
switch (opt) {
|
||||
case_USAGE_COMMON_FLAGS
|
||||
|
||||
case 't':
|
||||
if (utilfdt_decode_type(optarg, &disp.type,
|
||||
&disp.size))
|
||||
usage("Invalid type string");
|
||||
long_usage("invalid type string");
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
|
@ -347,7 +341,7 @@ int main(int argc, char *argv[])
|
|||
if (optind < argc)
|
||||
filename = argv[optind++];
|
||||
if (!filename)
|
||||
usage("Missing filename");
|
||||
long_usage("missing filename");
|
||||
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
@ -358,7 +352,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Check for node, property arguments */
|
||||
if (args_per_step == 2 && (argc % 2))
|
||||
usage("Must have an even number of arguments");
|
||||
long_usage("must have an even number of arguments");
|
||||
|
||||
if (do_fdtget(&disp, filename, argv, argc, args_per_step))
|
||||
return 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue