summaryrefslogtreecommitdiff
path: root/fdtget.c
diff options
context:
space:
mode:
Diffstat (limited to 'fdtget.c')
-rw-r--r--fdtget.c60
1 files changed, 27 insertions, 33 deletions
diff --git a/fdtget.c b/fdtget.c
index c2fbab2..5008cc1 100644
--- a/fdtget.c
+++ b/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;