]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
whereis: new usage output & version printing
authorSami Kerola <kerolasa@iki.fi>
Sat, 25 Jun 2011 10:48:26 +0000 (12:48 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sat, 25 Jun 2011 11:20:01 +0000 (13:20 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
misc-utils/whereis.c

index 931ff77b5d8801fad10d6ff0cb299478db14f6b9..b6204ddd7192d96884fa6382f1a6fe403e034327 100644 (file)
@@ -46,6 +46,7 @@
 #include <string.h>
 #include <ctype.h>
 #include "nls.h"
+#include "c.h"
 
 void zerof(void);
 void getlist(int *, char ***, char ***, int *);
@@ -143,6 +144,27 @@ int        Bcnt;
 char   **Mflag;
 int    Mcnt;
 char   uflag;
+
+static void __attribute__ ((__noreturn__)) usage(FILE * out)
+{
+       fprintf(out, _("Usage: %s [options] file\n"),
+               program_invocation_short_name);
+
+       fprintf(out, _("\nOptions:\n"
+                      " -f file    define search scope\n"
+                      " -b         search only binaries\n"
+                      " -B dirs    define binaries lookup path\n"
+                      " -m         search only manual paths\n"
+                      " -M dirs    define man lookup path\n"
+                      " -s         search only sources path\n"
+                      " -S dirs    define sources lookup path\n"
+                      " -u         search from unusual enties\n"
+                      " -V         output version information and exit\n"
+                      " -h         display this help and exit\n\n"
+                      "See how to use file and dirs arguments from whereis(1) manual.\n\n"));
+       exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
 /*
  * whereis name
  * look for source, documentation and binaries
@@ -155,9 +177,7 @@ main(int argc, char **argv) {
 
        argc--, argv++;
        if (argc == 0) {
-usage:
-               fprintf(stderr, _("whereis [ -sbmu ] [ -SBM dir ... -f ] name...\n"));
-               exit(1);
+               usage(stderr);
        }
        do
                if (argv[0][0] == '-') {
@@ -197,9 +217,15 @@ usage:
                                zerof();
                                mflag++;
                                continue;
-
+                       case 'V':
+                               printf(_("%s from %s\n"),
+                                       program_invocation_short_name,
+                                       PACKAGE_STRING);
+                               return EXIT_SUCCESS;
+                       case 'h':
+                               usage(stdout);
                        default:
-                               goto usage;
+                               usage(stderr);
                        }
                        argv++;
                } else