summaryrefslogtreecommitdiffstats
path: root/misc-utils/whereis.c
diff options
context:
space:
mode:
authorKarel Zak2014-10-23 14:29:45 +0200
committerKarel Zak2014-10-23 14:29:45 +0200
commitf4802c901134c56718e0c47308536c7eb2d552ae (patch)
treed0be6912218daf934a2644a24050d9c97c168d0a /misc-utils/whereis.c
parentwhereis: cleanup debug stuff, fix argv[] usage (diff)
downloadkernel-qcow2-util-linux-f4802c901134c56718e0c47308536c7eb2d552ae.tar.gz
kernel-qcow2-util-linux-f4802c901134c56718e0c47308536c7eb2d552ae.tar.xz
kernel-qcow2-util-linux-f4802c901134c56718e0c47308536c7eb2d552ae.zip
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>
Diffstat (limited to 'misc-utils/whereis.c')
-rw-r--r--misc-utils/whereis.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index 9c0127e1b..944e83bf0 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -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':