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