]> git.alsa-project.org Git - alsa-lib.git/commitdiff
ucm: add show_err parameter to uc_mgr_get_variable
authorJaroslav Kysela <perex@perex.cz>
Wed, 18 Feb 2026 12:23:26 +0000 (13:23 +0100)
committerJaroslav Kysela <perex@perex.cz>
Wed, 18 Feb 2026 12:30:29 +0000 (13:30 +0100)
Add bool show_err parameter to uc_mgr_get_variable() to control whether
an error message is displayed when a variable is not defined. This
centralizes error reporting and eliminates redundant error messages
in callers.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
src/ucm/main.c
src/ucm/parser.c
src/ucm/ucm_local.h
src/ucm/ucm_subs.c
src/ucm/utils.c

index 26b0ea2043ccd58ba33cbcefeb652eec29be74f4..72315d282e4f3d615a1ef9e9be984e04fe42636b 100644 (file)
@@ -1781,7 +1781,7 @@ int snd_use_case_mgr_open(snd_use_case_mgr_t **uc_mgr,
                card_name = parse_open_variables(mgr, card_name);
 
        /* Application developers: This argument is not supposed to be set for standard applications. */
-       if (uc_mgr_get_variable(mgr, "@InBoot"))
+       if (uc_mgr_get_variable(mgr, "@InBoot", false))
                mgr->in_boot = true;
 
        err = uc_mgr_card_open(mgr);
index 8d5428c2443dc9a50078e324e0f44cddaf565659..2d7833e9657ec87d5d2509531e56ebd308e37e38 100644 (file)
@@ -527,7 +527,7 @@ static int evaluate_macro1(snd_use_case_mgr_t *uc_mgr,
                if (err < 0)
                        goto __err_path;
                snprintf(name, sizeof(name), "__%s", id);
-               if (uc_mgr_get_variable(uc_mgr, name)) {
+               if (uc_mgr_get_variable(uc_mgr, name, false)) {
                        snd_error(UCM, "Macro argument '%s' is already defined", name);
                        goto __err_path;
                }
index 5ac4d3c4d753d4cd1c0cf4fb4724b0424725cac1..3015cca59f10fa796dbabcb9fc204fedc4f5ce5a 100644 (file)
@@ -352,7 +352,8 @@ int uc_mgr_add_value(struct list_head *base, const char *key, char *val);
 int uc_mgr_check_value(struct list_head *value_list, const char *identifier);
 
 const char *uc_mgr_get_variable(snd_use_case_mgr_t *uc_mgr,
-                               const char *name);
+                               const char *name,
+                               bool show_err);
 
 int uc_mgr_set_variable(snd_use_case_mgr_t *uc_mgr,
                        const char *name,
index 5ee386ac850b02e3aaa39ebddf4fa0fb3b252124..eb46ffcf5b602bf2e3a33eb81182bd0465ba94dd 100644 (file)
@@ -234,11 +234,9 @@ static char *rval_card_info(snd_use_case_mgr_t *uc_mgr, const char *query)
 
        if (card_str[0] == '$') {
                tmp = card_str + 1;
-               card_str = uc_mgr_get_variable(uc_mgr, tmp);
-               if (card_str == NULL) {
-                       snd_error(UCM, "info-card: variable '%s' not found", tmp);
+               card_str = uc_mgr_get_variable(uc_mgr, tmp, true);
+               if (card_str == NULL)
                        goto __error;
-               }
        }
 
        if (snd_config_search(config, "field", &d)) {
@@ -250,11 +248,9 @@ static char *rval_card_info(snd_use_case_mgr_t *uc_mgr, const char *query)
 
        if (field_str[0] == '$') {
                tmp = field_str + 1;
-               field_str = uc_mgr_get_variable(uc_mgr, tmp);
-               if (field_str == NULL) {
-                       snd_error(UCM, "info-card: variable '%s' not found", tmp);
+               field_str = uc_mgr_get_variable(uc_mgr, tmp, true);
+               if (field_str == NULL)
                        goto __error;
-               }
        }
 
        if (safe_strtol(card_str, &card_num) == 0)
@@ -351,9 +347,9 @@ static char *rval_lookup_main(snd_use_case_mgr_t *uc_mgr,
                goto null;
        if (s[0] == '$' && uc_mgr->conf_format >= 9) {
                tmp = s + 1;
-               s = uc_mgr_get_variable(uc_mgr, tmp);
+               s = uc_mgr_get_variable(uc_mgr, tmp, true);
                if (s == NULL)
-                       goto var_not_found;
+                       goto null;
        }
        for (fcn = iter->fcns ; fcn; fcn++) {
                if (strcasecmp(fcn->name, s) == 0) {
@@ -373,9 +369,9 @@ static char *rval_lookup_main(snd_use_case_mgr_t *uc_mgr,
                goto null;
        if (s[0] == '$' && uc_mgr->conf_format >= 9) {
                tmp = s + 1;
-               s = uc_mgr_get_variable(uc_mgr, tmp);
+               s = uc_mgr_get_variable(uc_mgr, tmp, true);
                if (s == NULL)
-                       goto var_not_found;
+                       goto null;
        }
        err = regcomp(&re, s, REG_EXTENDED | REG_ICASE);
        if (err) {
@@ -399,8 +395,6 @@ fin:
        if (iter->done)
                iter->done(iter);
        return result;
-var_not_found:
-       snd_error(UCM, "lookup: variable '%s' not found", tmp);
 null:
        result = NULL;
        goto fin;
@@ -533,11 +527,9 @@ static int rval_pcm_lookup_init(snd_use_case_mgr_t *uc_mgr,
            snd_config_get_string(d, &s) == 0) {
                if (s[0] == '$' && uc_mgr->conf_format >= 9) {
                        tmp = s + 1;
-                       s = uc_mgr_get_variable(uc_mgr, tmp);
-                       if (s == NULL) {
-                               snd_error(UCM, "pcm lookup: variable '%s' not found", tmp);
+                       s = uc_mgr_get_variable(uc_mgr, tmp, true);
+                       if (s == NULL)
                                return -EINVAL;
-                       }
                }
                if (strcasecmp(s, "playback") == 0)
                        stream = SND_PCM_STREAM_PLAYBACK;
@@ -596,11 +588,9 @@ static int rval_device_lookup_init(snd_use_case_mgr_t *uc_mgr,
        }
        if (s[0] == '$' && uc_mgr->conf_format >= 9) {
                tmp = s + 1;
-               s = uc_mgr_get_variable(uc_mgr, tmp);
-               if (s == NULL) {
-                       snd_error(UCM, "device lookup: variable '%s' not found", tmp);
+               s = uc_mgr_get_variable(uc_mgr, tmp, true);
+               if (s == NULL)
                        return -EINVAL;
-               }
        }
        for (t = types; t->name; t++)
                if (strcasecmp(t->name, s) == 0)
@@ -848,7 +838,7 @@ static char *rval_var(snd_use_case_mgr_t *uc_mgr, const char *id)
        } else if (id[0] == '@') {
                ignore_not_found = true;
        }
-       v = uc_mgr_get_variable(uc_mgr, id);
+       v = uc_mgr_get_variable(uc_mgr, id, false);
        if (v == NULL && ignore_not_found)
                v = "";
        if (v)
@@ -864,7 +854,7 @@ static int rval_eval_var_cb(snd_config_t **dst, const char *s, void *private_dat
        snd_use_case_mgr_t *uc_mgr = private_data;
        const char *v;
 
-       v = uc_mgr_get_variable(uc_mgr, s);
+       v = uc_mgr_get_variable(uc_mgr, s, false);
        if (v == NULL)
                return -ENOENT;
        return snd_config_imake_string(dst, NULL, v);
@@ -1062,7 +1052,7 @@ __match2:
                        if (*v2 == '$' && uc_mgr->conf_format >= 3) {
                                if (strncmp(value, "${eval:", 7) == 0)
                                        goto __direct_fcn2;
-                               tmp = uc_mgr_get_variable(uc_mgr, v2 + 1);
+                               tmp = uc_mgr_get_variable(uc_mgr, v2 + 1, false);
                                if (tmp == NULL) {
                                        snd_error(UCM, "define '%s' is not reachable in this context!", v2 + 1);
                                        rval = NULL;
index dcb5c6e178dd8a09a9e0210c5b51596a6397f9de..eb6bb4abdc575bc82dda5ffd7cf7ca2102c5404d 100644 (file)
@@ -672,7 +672,7 @@ int uc_mgr_remove_device(struct use_case_verb *verb, const char *name)
        return found == 0 ? -ENODEV : 0;
 }
 
-const char *uc_mgr_get_variable(snd_use_case_mgr_t *uc_mgr, const char *name)
+const char *uc_mgr_get_variable(snd_use_case_mgr_t *uc_mgr, const char *name, bool show_err)
 {
        struct list_head *pos;
        struct ucm_value *value;
@@ -682,6 +682,8 @@ const char *uc_mgr_get_variable(snd_use_case_mgr_t *uc_mgr, const char *name)
                if (strcmp(value->name, name) == 0)
                        return value->data;
        }
+       if (show_err)
+               snd_error(UCM, "variable '%s' is not defined", name);
        return NULL;
 }