diff options
author | Warner Losh <imp@FreeBSD.org> | 2014-01-27 06:20:36 +0000 |
---|---|---|
committer | Warner Losh <imp@FreeBSD.org> | 2014-01-27 06:20:36 +0000 |
commit | 939bdb9f6a0dad490702c3009bb8714579e1e765 (patch) | |
tree | 4405597d1484d0e28336fa7f4f113d502f37469f /fdtget.c | |
parent | ab1c86b34d2455fbd8cf2a9a404b0d7fd4ad28b1 (diff) | |
download | src-939bdb9f6a0dad490702c3009bb8714579e1e765.tar.gz src-939bdb9f6a0dad490702c3009bb8714579e1e765.zip |
Import dtc git at 6a15eb2350426d285130e4c9d84c0bdb6575547a (last rev before bison became required)
Notes
Notes:
svn path=/vendor/dtc/dist/; revision=261202
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"); + 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"); + 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"); + usage("must have an even number of arguments"); if (do_fdtget(&disp, filename, argv, argc, args_per_step)) return 1; |