diff --git a/src/bin/filteredquery/FilteredQuery.cpp b/src/bin/filteredquery/FilteredQuery.cpp index 03cf8a8be6..f3466e27ce 100644 --- a/src/bin/filteredquery/FilteredQuery.cpp +++ b/src/bin/filteredquery/FilteredQuery.cpp @@ -12,16 +12,16 @@ static void CopyQuery(const BQuery &query, BQuery *dest) { ASSERT(dest); - + BQuery &nonConst = const_cast(query); - + // BQuery doesn't have a copy constructor, - // so we have to do the work ourselves... + // so we have to do the work ourselves... // Copy the predicate BString buffer; nonConst.GetPredicate(&buffer); dest->SetPredicate(buffer.String()); - + // Copy the targetted volume BVolume volume(nonConst.TargetDevice()); dest->SetVolume(&volume); @@ -37,7 +37,7 @@ TFilteredQuery::TFilteredQuery(const BQuery &query) : BQuery() { - CopyQuery(query, this); + CopyQuery(query, this); } @@ -46,7 +46,7 @@ TFilteredQuery::TFilteredQuery(const TFilteredQuery &query) BQuery() { CopyQuery(query, this); - + // copy filters fFilters = query.fFilters; } @@ -62,7 +62,7 @@ bool TFilteredQuery::AddFilter(filter_function filter, void *arg) { filter_pair *filterPair = new filter_pair(filter, arg); - + return fFilters.AddItem(filterPair); } @@ -86,8 +86,8 @@ TFilteredQuery::GetNextRef(entry_ref *ref) { entry_ref tmpRef; status_t result; - - int32 filterCount = fFilters.CountItems(); + + int32 filterCount = fFilters.CountItems(); while ((result = BQuery::GetNextRef(&tmpRef)) == B_OK) { bool accepted = true; // We have a match, so let the entry_ref go through the filters @@ -99,14 +99,14 @@ TFilteredQuery::GetNextRef(entry_ref *ref) if (!accepted) break; } - + if (accepted) { // Ok, this entry_ref passed all tests *ref = tmpRef; break; } } - + return result; } @@ -116,12 +116,12 @@ TFilteredQuery::GetNextEntry(BEntry *entry, bool traverse) { // This code is almost a full copy/paste from Haiku's // BQuery::GetNextEntry(BEntry *entry, bool traverse) - + entry_ref ref; status_t error = GetNextRef(&ref); if (error == B_OK) error = entry->SetTo(&ref, traverse); - + return error; } @@ -132,6 +132,6 @@ TFilteredQuery::Clear() int32 filtersCount = fFilters.CountItems(); for (int32 i = 0; i < filtersCount; i++) delete fFilters.RemoveItemAt(i); - + return BQuery::Clear(); } diff --git a/src/bin/filteredquery/FilteredQuery.h b/src/bin/filteredquery/FilteredQuery.h index e5c59c3a5a..aea3b634da 100644 --- a/src/bin/filteredquery/FilteredQuery.h +++ b/src/bin/filteredquery/FilteredQuery.h @@ -10,7 +10,7 @@ typedef bool (*filter_function)(const entry_ref *ref, void *arg); struct filter_pair { filter_function filter; void *args; - + filter_pair(filter_function function, void *arguments) { filter = function; @@ -22,21 +22,21 @@ struct filter_pair { class TFilteredQuery : public BQuery { public: TFilteredQuery(); - + // BQuery doesn't have a copy constructor. We supply // this method to workaround this problem TFilteredQuery(const BQuery &query); TFilteredQuery(const TFilteredQuery &query); virtual ~TFilteredQuery(); - + bool AddFilter(filter_function function, void *arg); void RemoveFilter(filter_function function); - + virtual status_t GetNextRef(entry_ref *ref); virtual status_t GetNextEntry(BEntry *entry, bool traverse = false); - - status_t Clear(); - + + status_t Clear(); + private: BObjectList fFilters; }; diff --git a/src/bin/filteredquery/query.cpp b/src/bin/filteredquery/query.cpp index 681337dbec..ebe4e65eb0 100644 --- a/src/bin/filteredquery/query.cpp +++ b/src/bin/filteredquery/query.cpp @@ -32,7 +32,7 @@ struct folder_params BPath path; bool includeSubFolders; }; - + static bool FilterByFolder(const entry_ref *ref, void *arg) @@ -40,7 +40,7 @@ FilterByFolder(const entry_ref *ref, void *arg) folder_params* params = static_cast(arg); BPath& wantedPath = params->path; bool includeSub = params->includeSubFolders; - + BPath path(ref); if (includeSub) { if (!strncmp(path.Path(), wantedPath.Path(), @@ -90,7 +90,7 @@ perform_query(BVolume &volume, const char *predicate, const char *filterpath) options.includeSubFolders = o_subfolders; query.AddFilter(FilterByFolder, &options); } - + status_t status = query.Fetch(); if (status == B_BAD_VALUE) { // the "name=" part may be omitted in our arguments @@ -125,16 +125,16 @@ main(int32 argc, const char **argv) { // Make sure we have the minimum number of arguments. if (argc < 2) - usage(); + usage(); // Which volume do we make the query on? // Default to the current volume. char volumePath[B_FILE_NAME_LENGTH]; char directoryPath[B_PATH_NAME_LENGTH]; - + strcpy(volumePath, "."); strcpy(directoryPath, "."); - + // Parse command-line arguments. int opt; while ((opt = getopt(argc, (char **)argv, "easv:p:")) != -1) { @@ -146,19 +146,19 @@ main(int32 argc, const char **argv) case 'e': o_escaping = false; break; - + case 'v': strncpy(volumePath, optarg, B_FILE_NAME_LENGTH); break; - + case 'p': strncpy(directoryPath, optarg, B_PATH_NAME_LENGTH); break; - + case 's': o_subfolders = true; break; - + default: usage(); break; @@ -175,7 +175,7 @@ main(int32 argc, const char **argv) printf("query: %s is not a valid file\n", volumePath); exit(1); } - + status_t status = entry.GetVolume(&volume); if (status != B_OK) { fprintf(stderr, "%s: could not get volume: %s\n", __progname, strerror(status)); @@ -186,7 +186,7 @@ main(int32 argc, const char **argv) printf("query: volume containing %s is not query-enabled\n", volumePath); else perform_query(volume, argv[optind], directoryPath); - } else { + } else { // Okay, we want to query all the disks -- so iterate over // them, one by one, running the query. BVolumeRoster volumeRoster;