[haiku-commits] r41120 - haiku/trunk/src/bin

  • From: jonas@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 26 Mar 2011 21:32:58 +0100 (CET)

Author: kirilla
Date: 2011-03-26 21:32:58 +0100 (Sat, 26 Mar 2011)
New Revision: 41120
Changeset: https://dev.haiku-os.org/changeset/41120

Modified:
   haiku/trunk/src/bin/Jamfile
   haiku/trunk/src/bin/query.cpp
Log:
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.

Modified: haiku/trunk/src/bin/Jamfile
===================================================================
--- haiku/trunk/src/bin/Jamfile 2011-03-26 20:26:33 UTC (rev 41119)
+++ haiku/trunk/src/bin/Jamfile 2011-03-26 20:32:58 UTC (rev 41120)
@@ -100,7 +100,6 @@
        modifiers.cpp
        open.cpp
        play.cpp
-       query.cpp
        quit.cpp
        roster.cpp
        setdecor.cpp
@@ -129,6 +128,11 @@
        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

Modified: haiku/trunk/src/bin/query.cpp
===================================================================
--- haiku/trunk/src/bin/query.cpp       2011-03-26 20:26:33 UTC (rev 41119)
+++ haiku/trunk/src/bin/query.cpp       2011-03-26 20:32:58 UTC (rev 41120)
@@ -13,16 +13,17 @@
  */
 
 
+#include <Entry.h>
+#include <LocaleRoster.h>
 #include <Path.h>
 #include <Query.h>
-#include <Entry.h>
+#include <String.h>
 #include <Volume.h>
 #include <VolumeRoster.h>
-#include <String.h>
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
-#include <stdlib.h>
 #include <unistd.h>
 
 
@@ -33,6 +34,7 @@
 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 @@
        printf("usage: %s [ -ef ] [ -a || -v <path-to-volume> ] 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 <file>\tperform the query on just one volume; <file> can 
be any\n"
                "\t\tfile on that volume. Defaults to the current volume.\n"
@@ -54,11 +57,13 @@
 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) {
                // the "name=" part may be omitted in our arguments
@@ -84,9 +89,23 @@
                        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 @@
 
        // 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 @@
                        case 'a':
                                sAllVolumes = true;
                                break;
+                       case 'l':
+                               sLocalizedAppNames = true;
+                               break;
                        case 'v':
                                strlcpy(volumePath, optarg, B_FILE_NAME_LENGTH);
                                break;


Other related posts:

  • » [haiku-commits] r41120 - haiku/trunk/src/bin - jonas