testing visibility as the calling user.
.SH OPTIONS
+.TP
+\fB\-b\fR, \fB\-\-basename\fR
+Match only against the file name portion of the path name,
+ie., the directory names will be excluded from the match
+(but still printed). This does not speed up the search,
+but can suppress uninteresting matches.
+
.TP
\fB\-c\fR, \fB\-\-count\fR
Do not print each match. Instead, count them, and print out a total
.I extended
regular expressions.
+.TP
+\fB\-w\fR, \fB\-\-wholename\fR
+Match against the entire path name. This is the default,
+so unless \fB-b\fR is given first (see above), it will not do
+anything. This option thus exists only as compatibility with
+.BR mlocate (1).
+
.TP
.B \-\-help
Print out usage information, then exit successfully.
bool flush_cache = false;
bool patterns_are_regex = false;
bool use_extended_regex = false;
+bool match_basename = false;
int64_t limit_matches = numeric_limits<int64_t>::max();
int64_t limit_left = numeric_limits<int64_t>::max();
for (const char *filename = block.data();
filename != block.data() + block.size();
filename += strlen(filename) + 1) {
+ const char *haystack = filename;
+ if (match_basename) {
+ haystack = strrchr(filename, '/');
+ if (haystack == nullptr) {
+ haystack = filename;
+ } else {
+ ++haystack;
+ }
+ }
+
bool found = true;
for (const Needle &needle : needles) {
- if (!matches(needle, filename)) {
+ if (!matches(needle, haystack)) {
found = false;
break;
}
printf(
"Usage: plocate [OPTION]... PATTERN...\n"
"\n"
+ " -b, --basename search only the file name portion of path names\n"
" -c, --count print number of matches instead of the matches\n"
" -d, --database DBPATH search for files in DBPATH\n"
" (default is " DEFAULT_DBPATH ")\n"
" -0, --null delimit matches by NUL instead of newline\n"
" -r, --regexp interpret patterns as basic regexps (slow)\n"
" --regex interpret patterns as extended regexps (slow)\n"
+ " -w, --wholename search the entire path name (default; see -b)\n"
" --help print this help\n"
" --version print version information\n");
}
static const struct option long_options[] = {
{ "help", no_argument, 0, 'h' },
{ "count", no_argument, 0, 'c' },
+ { "basename", no_argument, 0, 'b' },
{ "database", required_argument, 0, 'd' },
{ "ignore-case", no_argument, 0, 'i' },
{ "limit", required_argument, 0, 'l' },
{ "version", no_argument, 0, 'V' },
{ "regexp", no_argument, 0, 'r' },
{ "regex", no_argument, 0, EXTENDED_REGEX },
+ { "wholename", no_argument, 0, 'w' },
{ "debug", no_argument, 0, 'D' }, // Not documented.
// Enable to test cold-cache behavior (except for access()). Not documented.
{ "flush-cache", no_argument, 0, FLUSH_CACHE },
setlocale(LC_ALL, "");
for (;;) {
int option_index = 0;
- int c = getopt_long(argc, argv, "cd:hil:n:0VD", long_options, &option_index);
+ int c = getopt_long(argc, argv, "bcd:hil:n:0wVD", long_options, &option_index);
if (c == -1) {
break;
}
switch (c) {
+ case 'b':
+ match_basename = true;
+ break;
case 'c':
only_count = true;
break;
patterns_are_regex = true;
use_extended_regex = true;
break;
+ case 'w':
+ match_basename = false; // No-op unless -b is given first.
+ break;
case 'D':
use_debug = true;
break;