]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
whereis: reset search mask more carefully
authorKarel Zak <kzak@redhat.com>
Thu, 23 Oct 2014 12:29:45 +0000 (14:29 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Oct 2014 12:29:45 +0000 (14:29 +0200)
 # whereis -m cal -M /usr/share/man/man1/ -f ls
 cal: /usr/share/man/man1/cal.1.gz /usr/share/man/man1p/cal.1p.gz
 ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

the -M also resets the search mask, so for 'ls' it returns also
binaries. That's bug. Expected result is:

 # ./whereis -m cal -M /usr/share/man/man1/ -f ls
 cal: /usr/share/man/man1/cal.1.gz /usr/share/man/man1p/cal.1p.gz
 ls: /usr/share/man/man1/ls.1.gz

the search mask has to be sensitive only to -b -m -s options,
otherwise the semantic is pretty messy.

Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/whereis.1
misc-utils/whereis.c

index fde0dd779a4370c89ff628e0884d436d56842170..e8e43272268762fe325c1f5a79d8efa8de80803b 100644 (file)
@@ -56,14 +56,35 @@ in the places specified by
 .B $PATH
 and
 .BR $MANPATH .
+
+The search restrinctions (options \fB\-b\fP, \fB\-m\fP and \fB\-s\fP) are
+cumulative and always applied for the next \fIname\fP patterns specified on
+command line. The first search restrinction resets the search mask. For example
+.RS
+.sp
+.B "whereis -bm ls tr -m gcc"
+.sp
+.RE
+searchs for "ls" and "tr" binaries and man pages, and "gcc" man pages only.
+
+The options \fB\-B\fP, \fB\-M\fP and \fB\-S\fP resets search paths for the next
+\fIname\fP patterns. For example
+.RS
+.sp
+.B "whereis -m ls -M /usr/share/man/man1 -f cal"
+.sp
+.RE
+searchs for "ls" man pages in all default paths, but for "cal" in
+/usr/share/man/man1 directory only.
+
 .SH OPTIONS
 .TP
 .IP \fB\-b\fP
-Search only for binaries.
+Search for binaries.
 .IP \fB\-m\fP
-Search only for manuals.
+Search for manuals.
 .IP \fB\-s\fP
-Search only for sources.
+Search for sources.
 .IP \fB\-u\fP
 Only show the command names that have unusual entries.  A command is said to be
 unusual if it does not have just one entry of each explicitly requested type.
index 9c0127e1b8c50d7ab3ba6cfc7c99733b2816579f..944e83bf07b52433c620ac76e5e328e40e46d4fa 100644 (file)
@@ -491,7 +491,7 @@ int main(int argc, char **argv)
 {
        struct wh_dirlist *ls = NULL;
        int want = ALL_DIRS;
-       int i;
+       int i, want_resetable = 0;
 
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
@@ -519,21 +519,16 @@ int main(int argc, char **argv)
 
                if (*arg != '-') {
                        lookup(arg, ls, want);
-                       continue;
-               }
-
-               if (i > 1 && *argv[i - 1] != '-') {
-                       /* the list of search patterns has been interupted by
-                        * any non-pattern option, then reset the mask for
-                        * wanted directories. For example:
-                        *
-                        *    whereis -m ls -b tr
+                       /*
+                        * The lookup mask ("want") is cumulative and it's
+                        * resetable only when it has been already used.
                         *
-                        * search for "ls" in mandirs and "tr" in bindirs
+                        *  whereis -b -m foo     :'foo' mask=BIN|MAN
+                        *  whereis -b foo bar    :'foo' and 'bar' mask=BIN|MAN
+                        *  whereis -b foo -m bar :'foo' mask=BIN; 'bar' mask=MAN
                         */
-                       DBG(ARGV, ul_debug("list of search patterns interupted "
-                                          "by non-pattern"));
-                       want = ALL_DIRS;
+                       want_resetable = 1;
+                       continue;
                }
 
                for (++arg; arg && *arg; arg++) {
@@ -570,12 +565,24 @@ int main(int argc, char **argv)
                                        &ls, &i, argc, argv, SRC_DIR);
                                break;
                        case 'b':
+                               if (want_resetable) {
+                                       want = ALL_DIRS;
+                                       want_resetable = 0;
+                               }
                                want = want == ALL_DIRS ? BIN_DIR : want | BIN_DIR;
                                break;
                        case 'm':
+                               if (want_resetable) {
+                                       want = ALL_DIRS;
+                                       want_resetable = 0;
+                               }
                                want = want == ALL_DIRS ? MAN_DIR : want | MAN_DIR;
                                break;
                        case 's':
+                               if (want_resetable) {
+                                       want = ALL_DIRS;
+                                       want_resetable = 0;
+                               }
                                want = want == ALL_DIRS ? SRC_DIR : want | SRC_DIR;
                                break;
                        case 'l':