diff options
author | Mike Frysinger <vapier@gentoo.org> | 2007-04-13 15:09:37 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2007-04-13 15:09:37 +0000 |
commit | 6dde29a0c940a16b2228233fc5d2336eca2f6d2f (patch) | |
tree | c9a7c99915e412ba22d86aa9b719ba7d8994b644 /src | |
parent | bc91e51d435b118a05ee23e80b227aca88f55125 (diff) |
add basic --help
Diffstat (limited to 'src')
-rw-r--r-- | src/mountinfo.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/mountinfo.c b/src/mountinfo.c index 33f1869b..85d4ecc3 100644 --- a/src/mountinfo.c +++ b/src/mountinfo.c @@ -128,6 +128,28 @@ static char **find_mounts (regex_t *node_regex, regex_t *fstype_regex, # error "Operating system not supported!" #endif +#define getoptstring "F:N:S:fnrhV" +static struct option longopts[] = { + { "fstype-regex", 1, NULL, 'F'}, + { "node-regex", 1, NULL, 'N'}, + { "skip-regex", 1, NULL, 'S'}, + { "fstype", 0, NULL, 'f'}, + { "node", 0, NULL, 'n'}, + { "reverse", 0, NULL, 'r'}, + { "help", 0, NULL, 'h'}, + { NULL, 0, NULL, 0} +}; + +static void usage (int exit_status) +{ + int i; + printf ("Usage: mountinfo [options]\n\n"); + printf ("Options:\n"); + for (i = 0; longopts[i].name; ++i) + printf (" -%c, --%s\n", longopts[i].val, longopts[i].name); + exit (exit_status); +} + int main (int argc, char **argv) { int i; @@ -144,17 +166,7 @@ int main (int argc, char **argv) char **mounts = NULL; char c; - static struct option longopts[] = { - { "fstype-regex", 1, NULL, 'F'}, - { "node-regex", 1, NULL, 'N'}, - { "skip-regex", 1, NULL, 'S'}, - { "fstype", 0, NULL, 'f'}, - { "node", 0, NULL, 'n'}, - { "reverse", 0, NULL, 'r'}, - { NULL, 0, NULL, 0} - }; - - while ((c = getopt_long (argc, argv, "F:N:S:fnr", + while ((c = getopt_long (argc, argv, getoptstring, longopts, (int *) 0)) != -1) switch (c) { case 'F': @@ -207,8 +219,11 @@ int main (int argc, char **argv) reverse = true; break; + case 'h': + usage (EXIT_SUCCESS); + default: - exit (EXIT_FAILURE); + usage (EXIT_FAILURE); } while (optind < argc) { @@ -241,4 +256,3 @@ int main (int argc, char **argv) exit (result); } - |