X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=plocate.cpp;h=3e375449a4ee2b438ff0a9fc68151134d5518e8f;hb=9cae8bc21ec1b18f070ffdd3bdf5864b00916176;hp=ea2ee253e56bf6a2178e3d6ef2cdd886661a7dfc;hpb=09498cce8e0184df78595f7711cc11796629dad7;p=plocate diff --git a/plocate.cpp b/plocate.cpp index ea2ee25..3e37544 100644 --- a/plocate.cpp +++ b/plocate.cpp @@ -24,6 +24,9 @@ using namespace std::chrono; #define dprintf(...) //#define dprintf(...) fprintf(stderr, __VA_ARGS__); +const char *dbpath = "/var/lib/mlocate/plocate.db"; +bool print_nul = false; + class Serializer { public: void do_or_wait(int seq, function cb); @@ -218,7 +221,11 @@ size_t scan_file_block(const vector &needles, string_view compressed, } if (found && has_access(filename, access_rx_cache)) { ++matched; - printf("%s\n", filename); + if (print_nul) { + printf("%s%c", filename, 0); + } else { + printf("%s\n", filename); + } } } return matched; @@ -390,14 +397,13 @@ void do_search_file(const vector &needles, const char *filename) 1e3 * duration(steady_clock::now() - start).count(), matched); } -const char *dbpath = "/var/lib/mlocate/plocate.db"; - void usage() { printf("Usage: slocate [OPTION]... PATTERN...\n"); printf(" -d, --database DBPATH use DBPATH instead of default database (which is\n"); printf(" %s)\n", dbpath); printf(" -h, --help print this help\n"); + printf(" -0, --null separate entries with NUL on output\n"); } int main(int argc, char **argv) @@ -405,12 +411,13 @@ int main(int argc, char **argv) static const struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "database", required_argument, 0, 'd' }, + { "null", no_argument, 0, '0' }, { 0, 0, 0, 0 } }; for (;;) { int option_index = 0; - int c = getopt_long(argc, argv, "d:h:", long_options, &option_index); + int c = getopt_long(argc, argv, "d:h0", long_options, &option_index); if (c == -1) { break; } @@ -421,6 +428,9 @@ int main(int argc, char **argv) case 'h': usage(); exit(0); + case '0': + print_nul = true; + break; } }