Make gpd config utility global

Make gpd a global utility macro for reading config/command line parameters.
Add a corresponding function with full name for clarity, keep the short name
for the macro for backward compatibility and ease of use.

The main benefit of gpd/config_get_paramdef_from_name macro/function is that
it does not require maintaining a separate parameter index list.
This commit is contained in:
Bartosz Podrygajlo
2026-01-08 13:57:13 +01:00
parent 9b0bb594f0
commit 11ae7e7993
4 changed files with 16 additions and 21 deletions
+12 -4
View File
@@ -105,13 +105,14 @@ int config_execcheck(configmodule_interface_t *cfg, paramdef_t *params, int nump
return st;
}
int config_paramidx_fromname(paramdef_t *params, int numparams, const char *name) {
for (int i=0; i<numparams ; i++) {
if (strcmp(name,params[i].optname) == 0)
int config_paramidx_fromname(const paramdef_t *params, int numparams, const char *name)
{
for (int i = 0; i < numparams; i++) {
if (strcmp(name, params[i].optname) == 0)
return i;
}
fprintf(stderr,"[CONFIG]config_paramidx_fromname , %s is not a valid parameter name\n",name);
fprintf(stderr, "[CONFIG]config_paramidx_fromname , %s is not a valid parameter name\n", name);
return -1;
}
@@ -290,3 +291,10 @@ void config_set_checkfunctions(paramdef_t *params, checkedparam_t *checkfunction
params[i].chkPptr = &(checkfunctions[i]);
}
}
const paramdef_t *config_get_paramdef_from_name(const paramdef_t *pd, int num, const char *name)
{
int idx = config_paramidx_fromname(pd, num, (char *)name);
AssertFatal(idx >= 0 && idx < num, "Invalid parameter name %s\n", name);
return &pd[idx];
}