diff options
author | Karel Zak <kzak@redhat.com> | 2014-10-23 14:29:45 +0200 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2014-10-24 11:29:07 +0200 |
commit | f17942e77f690e126f08ea7e12e6d5fbe9954e1e (patch) | |
tree | a6a7475ed6e6f55157a3a0b4dc049ac6a97a048c | |
parent | 0d21f36ff3643ad2ea708f3596d64042331b037a (diff) | |
download | util-linux-f17942e77f690e126f08ea7e12e6d5fbe9954e1e.tar.gz |
whereis: reset search mask more carefully
# 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>
-rw-r--r-- | misc-utils/whereis.1 | 27 | ||||
-rw-r--r-- | misc-utils/whereis.c | 35 |
2 files changed, 45 insertions, 17 deletions
diff --git a/misc-utils/whereis.1 b/misc-utils/whereis.1 index fde0dd779..e8e432722 100644 --- a/misc-utils/whereis.1 +++ b/misc-utils/whereis.1 @@ -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. diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c index 1def37dfc..d5dd06ded 100644 --- a/misc-utils/whereis.c +++ b/misc-utils/whereis.c @@ -490,7 +490,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); @@ -518,21 +518,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++) { @@ -569,12 +564,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': |