From 11f1bb5ab42571fae5cc607d42b8d918c9e170ab Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sun, 3 Sep 2006 04:05:20 +0200 Subject: udevinfo: use long options --- udevinfo.8 | 26 +++++++++++++------------- udevinfo.c | 53 ++++++++++++++++++++++++++++++----------------------- udevinfo.xml | 53 ++++++++++++++++++++++++----------------------------- 3 files changed, 67 insertions(+), 65 deletions(-) diff --git a/udevinfo.8 b/udevinfo.8 index 4430f5d9d3..01c9090031 100644 --- a/udevinfo.8 +++ b/udevinfo.8 @@ -14,17 +14,17 @@ udevinfo \- query device information from the udev database .SH "SYNOPSIS" .HP 9 -\fBudevinfo\fR [\fB\-q\ \fR\fB\fIquery\-type\fR\fR] [\fB\-a\ \fR] [\fB\-p\ \fR\fB\fIdevpath\fR\fR] [\fB\-n\ \fR\fB\fInode\fR\fR] [\fB\-r\fR] [\fB\-e\fR] [\fB\-V\fR] [\fB\-h\fR] +\fBudevinfo\fR [\fB\-\-query=\fR\fB\fIquery\-type\fR\fR] [\fB\-\-attribute\-walk\fR] [\fB\-\-path=\fR\fB\fIdevpath\fR\fR] [\fB\-\-name=\fR\fB\fInode\fR\fR] [\fB\-\-root\fR] [\fB\-\-export\-db\fR] [\fB\-\-version\fR] [\fB\-\-help\fR] .SH "DESCRIPTION" .PP udevinfo queries the udev database for device information stored in the udev database. It can also query the properties of a device from its sysfs representation to help creating udev rules that match this device. .SH "OPTIONS" .TP 3n -\fB\-q\fR +\fB\-\-query=\fR\fB\fItype\fR\fR Query the database for specified type of device data. It needs the -\fB\-p\fR +\fB\-\-path\fR or -\fB\-n\fR +\fB\-\-name\fR to identify the specified device. Valid queries are: \fBname\fR, \fBsymlink\fR, @@ -32,27 +32,27 @@ to identify the specified device. Valid queries are: \fBenv\fR, \fBall\fR. .TP 3n -\fB\-a\fR -Print all sysfs properties of the specified device that can be used in udev rules to match the specified device. It prints all devices along the chain, up to the root of sysfs that can be used in udev rules. -.TP 3n -\fB\-p \fR\fB\fIdevpath\fR\fR +\fB\-\-path=\fR\fB\fIdevpath\fR\fR The devpath of the device to query. .TP 3n -\fB\-n \fR\fB\fInode\fR\fR +\fB\-\-name=\fR\fB\fInode\fR\fR The name of the device node or a symlink to query .TP 3n -\fB\-r\fR +\fB\-\-root\fR The udev root directory: \fI/dev\fR. If used in conjunction with a \fBname\fR or \fBsymlink\fR -query, the query returns the absolute path. +query, the query returns the absolute path including the root directory. +.TP 3n +\fB\-\-attribute\-walk\fR +Print all sysfs properties of the specified device that can be used in udev rules to match the specified device. It prints all devices along the chain, up to the root of sysfs that can be used in udev rules. .TP 3n -\fB\-e\fR +\fB\-\-export\fR Export the content of the udev database. .TP 3n -\fB\-h\fR +\fB\-\-help\fR Print help text. .SH "AUTHOR" .PP diff --git a/udevinfo.c b/udevinfo.c index 3146a96119..d1d77152c3 100644 --- a/udevinfo.c +++ b/udevinfo.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "udev.h" @@ -167,6 +168,18 @@ int main(int argc, char *argv[], char *envp[]) struct udevice *udev; int root = 0; + struct option options[] = { + { "name", 1, NULL, 'n' }, + { "path", 1, NULL, 'p' }, + { "query", 1, NULL, 'q' }, + { "attribute-walk", 0, NULL, 'a' }, + { "export-db", 0, NULL, 'e' }, + { "root", 0, NULL, 'r' }, + { "version", 0, NULL, 'V' }, + { "help", 0, NULL, 'h' }, + {} + }; + enum action_type { ACTION_NONE, ACTION_QUERY, @@ -199,9 +212,8 @@ int main(int argc, char *argv[], char *envp[]) } /* get command line options */ - opterr = 0; while (1) { - option = getopt(argc, argv, ":aden:p:q:rVh"); + option = getopt_long(argc, argv, "aden:p:q:rVh", options, NULL); if (option == -1) break; @@ -267,30 +279,25 @@ int main(int argc, char *argv[], char *envp[]) printf("udevinfo, version %s\n", UDEV_VERSION); goto exit; case 'h': - printf("Usage: udevinfo [-anpqrVh]\n" - " -q TYPE query database for the specified value:\n" - " 'name' name of device node\n" - " 'symlink' pointing to node\n" - " 'path' sysfs device path\n" - " 'env' the device related imported environment\n" - " 'all' all values\n" + printf("Usage: udevinfo OPTIONS\n" + " --query= query database for the specified value:\n" + " name name of device node\n" + " symlink pointing to node\n" + " path sysfs device path\n" + " env the device related imported environment\n" + " all all values\n" "\n" - " -p PATH sysfs device path used for query or chain\n" - " -n NAME node/symlink name used for query\n" + " --path= sysfs device path used for query or chain\n" + " --name= node or symlink name used for query\n" "\n" - " -r prepend to query result or print udev_root\n" - " -a print all SYSFS_attributes along the device chain\n" - " -e export the content of the udev database\n" - " -V print udev version\n" - " -h print this help text\n" + " --root prepend to query result or print udev_root\n" + " --attribute-walk print all SYSFS_attributes along the device chain\n" + " --export-db export the content of the udev database\n" + " --verision print udev version\n" + " --help print this text\n" "\n"); goto exit; - case ':': - fprintf(stderr, "missing argument for '%c'\n", optopt); - goto exit; - case '?': default: - fprintf(stderr, "unrecognized option '%c'\n", optopt); goto exit; } } @@ -315,7 +322,7 @@ int main(int argc, char *argv[], char *envp[]) } udev_db_get_device(udev, devpath); } else { - fprintf(stderr, "query needs device path(-p) or node name(-n) specified\n"); + fprintf(stderr, "query needs --path or node --name specified\n"); rc = 4; goto exit; } @@ -366,7 +373,7 @@ int main(int argc, char *argv[], char *envp[]) } print_device_chain(devpath); } else { - fprintf(stderr, "attribute walk needs device path(-p) or node name(-n) specified\n"); + fprintf(stderr, "attribute walk needs --path or node --name specified\n"); rc = 5; goto exit; } diff --git a/udevinfo.xml b/udevinfo.xml index 9bd0b8dc17..6c08eee58f 100644 --- a/udevinfo.xml +++ b/udevinfo.xml @@ -25,14 +25,14 @@ udevinfo - - - - - - - - + + + + + + + + @@ -46,57 +46,52 @@ OPTIONS - + Query the database for specified type of device data. It needs the - or to identify the specified + or to identify the specified device. Valid queries are: name, symlink, path, env, all. - - - - - Print all sysfs properties of the specified device that can be used - in udev rules to match the specified device. It prints all devices - along the chain, up to the root of sysfs that can be used in udev rules. - - - - + The devpath of the device to query. - - + The name of the device node or a symlink to query - - + The udev root directory: /dev. If used in conjunction with a name or symlink query, the - query returns the absolute path. + query returns the absolute path including the root directory. + + + + + + Print all sysfs properties of the specified device that can be used + in udev rules to match the specified device. It prints all devices + along the chain, up to the root of sysfs that can be used in udev rules. - - + Export the content of the udev database. - + Print help text. -- cgit v1.2.3-54-g00ecf