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
This commit is contained in:
Jonas Sundström
2011-03-26 20:32:58 +00:00
parent ea8749b6b5
commit 77fa0e9269
2 changed files with 37 additions and 11 deletions
+5 -1
View File
@@ -100,7 +100,6 @@ StdBinCommands
modifiers.cpp modifiers.cpp
open.cpp open.cpp
play.cpp play.cpp
query.cpp
quit.cpp quit.cpp
roster.cpp roster.cpp
setdecor.cpp setdecor.cpp
@@ -129,6 +128,11 @@ StdBinCommands
urlwrapper.cpp urlwrapper.cpp
: be $(TARGET_LIBSUPC++) : $(haiku-utils_rsrc) ; : 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 # commands that need libbe.so, libsupc++.so and liblocale.so
StdBinCommands StdBinCommands
dstcheck.cpp dstcheck.cpp
+32 -10
View File
@@ -13,16 +13,17 @@
*/ */
#include <Entry.h>
#include <LocaleRoster.h>
#include <Path.h> #include <Path.h>
#include <Query.h> #include <Query.h>
#include <Entry.h> #include <String.h>
#include <Volume.h> #include <Volume.h>
#include <VolumeRoster.h> #include <VolumeRoster.h>
#include <String.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
@@ -33,6 +34,7 @@ static const char *kProgramName = __progname;
static bool sAllVolumes = false; // Query all volumes? static bool sAllVolumes = false; // Query all volumes?
static bool sEscapeMetaChars = true; // Escape metacharacters? static bool sEscapeMetaChars = true; // Escape metacharacters?
static bool sFilesOnly = false; // Show only files? static bool sFilesOnly = false; // Show only files?
static bool sLocalizedAppNames = false; // match localized names
void void
@@ -41,6 +43,7 @@ usage(void)
printf("usage: %s [ -ef ] [ -a || -v <path-to-volume> ] expression\n" printf("usage: %s [ -ef ] [ -a || -v <path-to-volume> ] expression\n"
" -e\t\tdon't escape meta-characters\n" " -e\t\tdon't escape meta-characters\n"
" -f\t\tshow only files (ie. no directories or symbolic links)\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" " -a\t\tperform the query on all volumes\n"
" -v <file>\tperform the query on just one volume; <file> can be any\n" " -v <file>\tperform the query on just one volume; <file> can be any\n"
"\t\tfile on that volume. Defaults to the current volume.\n" "\t\tfile on that volume. Defaults to the current volume.\n"
@@ -54,10 +57,12 @@ void
perform_query(BVolume &volume, const char *predicate) perform_query(BVolume &volume, const char *predicate)
{ {
BQuery query; BQuery query;
// Set up the volume and predicate for the query.
query.SetVolume(&volume); query.SetVolume(&volume);
query.SetPredicate(predicate);
if (sLocalizedAppNames)
query.SetPredicate("BEOS:APP_SIG=*");
else
query.SetPredicate(predicate);
status_t status = query.Fetch(); status_t status = query.Fetch();
if (status == B_BAD_VALUE) { if (status == B_BAD_VALUE) {
@@ -84,9 +89,23 @@ perform_query(BVolume &volume, const char *predicate)
continue; continue;
} }
printf("%s\n", sEscapeMetaChars ? BString string;
BString().CharacterEscape(path.Path(), " ()?*&\"'[]^\\~|;!<>*$\t", '\\').String() if (sLocalizedAppNames && predicate != NULL) {
: path.Path()); 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. // Parse command-line arguments.
int opt; int opt;
while ((opt = getopt(argc, argv, "efav:")) != -1) { while ((opt = getopt(argc, argv, "efalv:")) != -1) {
switch(opt) { switch(opt) {
case 'e': case 'e':
sEscapeMetaChars = false; sEscapeMetaChars = false;
@@ -116,6 +135,9 @@ main(int argc, char **argv)
case 'a': case 'a':
sAllVolumes = true; sAllVolumes = true;
break; break;
case 'l':
sLocalizedAppNames = true;
break;
case 'v': case 'v':
strlcpy(volumePath, optarg, B_FILE_NAME_LENGTH); strlcpy(volumePath, optarg, B_FILE_NAME_LENGTH);
break; break;