From 77fa0e926939a87b082f5b56ab15ec64216adc5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sundstr=C3=B6m?= Date: Sat, 26 Mar 2011 20:32:58 +0000 Subject: [PATCH] Add an -l option to 'query' - enabling lookup of path for localized names (or parts thereof). I'm not sure it should be part of 'query', but here it is. Due to using BString it is currently case-sensitive beyond plain ascii names. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41120 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/Jamfile | 6 +++++- src/bin/query.cpp | 42 ++++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/bin/Jamfile b/src/bin/Jamfile index 3c64aa1983..3295e1995b 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -100,7 +100,6 @@ StdBinCommands modifiers.cpp open.cpp play.cpp - query.cpp quit.cpp roster.cpp setdecor.cpp @@ -129,6 +128,11 @@ StdBinCommands urlwrapper.cpp : be $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ; +# commands that need libbe.so and liblocale.so +StdBinCommands + query.cpp + : be $(HAIKU_LOCALE_LIBS) : $(haiku-utils_rsrc) ; + # commands that need libbe.so, libsupc++.so and liblocale.so StdBinCommands dstcheck.cpp diff --git a/src/bin/query.cpp b/src/bin/query.cpp index b50ac683ac..2018746706 100644 --- a/src/bin/query.cpp +++ b/src/bin/query.cpp @@ -13,16 +13,17 @@ */ +#include +#include #include #include -#include +#include #include #include -#include #include -#include #include +#include #include @@ -33,6 +34,7 @@ static const char *kProgramName = __progname; static bool sAllVolumes = false; // Query all volumes? static bool sEscapeMetaChars = true; // Escape metacharacters? static bool sFilesOnly = false; // Show only files? +static bool sLocalizedAppNames = false; // match localized names void @@ -41,6 +43,7 @@ usage(void) printf("usage: %s [ -ef ] [ -a || -v ] expression\n" " -e\t\tdon't escape meta-characters\n" " -f\t\tshow only files (ie. no directories or symbolic links)\n" + " -l\t\tmatch expression with localized application names\n" " -a\t\tperform the query on all volumes\n" " -v \tperform the query on just one volume; can be any\n" "\t\tfile on that volume. Defaults to the current volume.\n" @@ -54,10 +57,12 @@ void perform_query(BVolume &volume, const char *predicate) { BQuery query; - - // Set up the volume and predicate for the query. query.SetVolume(&volume); - query.SetPredicate(predicate); + + if (sLocalizedAppNames) + query.SetPredicate("BEOS:APP_SIG=*"); + else + query.SetPredicate(predicate); status_t status = query.Fetch(); if (status == B_BAD_VALUE) { @@ -84,9 +89,23 @@ perform_query(BVolume &volume, const char *predicate) continue; } - printf("%s\n", sEscapeMetaChars ? - BString().CharacterEscape(path.Path(), " ()?*&\"'[]^\\~|;!<>*$\t", '\\').String() - : path.Path()); + BString string; + if (sLocalizedAppNames && predicate != NULL) { + entry_ref ref; + + if (entry.GetRef(&ref) != B_OK || BLocaleRoster::Default() + ->GetLocalizedFileName(ref, string) != B_OK) + continue; + + if (string.IFindFirst(predicate) < 0) + continue; + } + + string = path.Path(); + if (sEscapeMetaChars) + string.CharacterEscape(" ()?*&\"'[]^\\~|;!<>*$\t", '\\'); + + printf("%s\n", string.String()); } } @@ -105,7 +124,7 @@ main(int argc, char **argv) // Parse command-line arguments. int opt; - while ((opt = getopt(argc, argv, "efav:")) != -1) { + while ((opt = getopt(argc, argv, "efalv:")) != -1) { switch(opt) { case 'e': sEscapeMetaChars = false; @@ -116,6 +135,9 @@ main(int argc, char **argv) case 'a': sAllVolumes = true; break; + case 'l': + sLocalizedAppNames = true; + break; case 'v': strlcpy(volumePath, optarg, B_FILE_NAME_LENGTH); break;