Improve the DynamicMeter_search API to make 'key' optional

Thanks to @BenBE for the suggestion.
This commit is contained in:
Nathan Scott 2021-07-12 19:11:39 +10:00
parent 9cbee01877
commit 0daefbe4b4
2 changed files with 4 additions and 3 deletions

View File

@ -52,6 +52,7 @@ bool DynamicMeter_search(Hashtable* dynamics, const char* name, unsigned int* ke
DynamicIterator iter = { .key = 0, .name = name, .found = false };
if (dynamics)
Hashtable_foreach(dynamics, DynamicMeter_compare, &iter);
if (key)
*key = iter.key;
return iter.found;
}

View File

@ -140,8 +140,7 @@ static bool PCPDynamicMeter_validateMeterName(char* key, const char* path, unsig
// Ensure a meter name has not been defined previously
static bool PCPDynamicMeter_uniqueName(char* key, const char* path, unsigned int line, PCPDynamicMeters* meters) {
unsigned int param = 0;
if (DynamicMeter_search(meters->table, key, &param) == false)
if (DynamicMeter_search(meters->table, key, NULL) == false)
return true;
fprintf(stderr, "%s: duplicate name at %s line %u: \"%s\", ignored\n",
@ -199,6 +198,7 @@ static void PCPDynamicMeter_parseFile(PCPDynamicMeters* meters, const char* path
if (caption) {
free_and_xStrdup(&meter->super.caption, caption);
free(caption);
caption = NULL;
}
} else if (value && meter && String_eq(key, "description")) {
free_and_xStrdup(&meter->super.description, value);