diff options
author | Mike Frysinger <vapier@gentoo.org> | 2013-05-24 18:02:35 +1000 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2013-05-24 18:20:53 +1000 |
commit | 03449b84c8f9aee2bf2f438bec2c2ec4606bea48 (patch) | |
tree | 1448207a54fe8f460429fa462291f0cb9c8de783 /fdtget.c | |
parent | fdc7387845420168ee5dd479fbe4391ff93bddab (diff) | |
download | dtc-03449b84c8f9aee2bf2f438bec2c2ec4606bea48.tar.gz |
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>
Diffstat (limited to 'fdtget.c')
-rw-r--r-- | fdtget.c | 60 |
1 files changed, 27 insertions, 33 deletions
@@ -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; |