int snd_config_delete(snd_config_t *config);
int snd_config_delete_compound_members(const snd_config_t *config);
int snd_config_copy(snd_config_t **dst, snd_config_t *src);
+int snd_config_substitute(snd_config_t *dst, snd_config_t *src);
int snd_config_merge(snd_config_t *dst, snd_config_t *src, int override);
int snd_config_make(snd_config_t **config, const char *key,
${find-card:<str>} | Find a card - see _Find card substitution_ section
${find-device:<str>} | Find a device - see _Find device substitution_ section
+#### Special whole string substitution
+
+Substituted string | Value
+---------------------|---------------------
+${evali:<str>} | Evaluate expression like *($var+2)/3* [**Syntax 5**]; target node will be integer; substituted only in the LibraryConfig subtree
+
#### Find card substitution
This substitutions finds the ALSA card and returns the appropriate identifier or
int err;
if (uc_mgr->conf_format < 5) {
- uc_error("variable substitution is supported in v5+ syntax");
+ uc_error("variable evaluation is supported in v5+ syntax");
return NULL;
}
err = _snd_eval_string(&dst, e, rval_eval_var_cb, uc_mgr);
return r;
}
+static int rval_evali(snd_use_case_mgr_t *uc_mgr, snd_config_t *node, const char *e)
+{
+ snd_config_t *dst;
+ const char *id;
+ char *s;
+ size_t l;
+ int err;
+
+ if (uc_mgr->conf_format < 5) {
+ uc_error("variable evaluation is supported in v5+ syntax");
+ return -EINVAL;
+ }
+ err = snd_config_get_id(node, &id);
+ if (err < 0)
+ return err;
+ l = strlen(e);
+ if (e[l-1] != '}')
+ return -EINVAL;
+ s = malloc(l + 1);
+ if (s == NULL)
+ return -ENOMEM;
+ strcpy(s, e);
+ s[l-1] = '\0';
+ err = _snd_eval_string(&dst, s + 8, rval_eval_var_cb, uc_mgr);
+ free(s);
+ if (err < 0) {
+ uc_error("unable to evaluate '%s'", e);
+ return err;
+ }
+ err = snd_config_set_id(dst, id);
+ if (err < 0)
+ return err;
+ return snd_config_substitute(node, dst);
+}
+
#define MATCH_VARIABLE(name, id, fcn, empty_ok) \
if (strncmp((name), (id), sizeof(id) - 1) == 0) { \
rval = fcn(uc_mgr); \
return err;
if (!uc_mgr_substitute_check(s2))
return 0;
+ if (strncmp(s2, "${evali:", 8) == 0)
+ return rval_evali(uc_mgr, node, s2);
err = uc_mgr_get_substituted_value(uc_mgr, &s, s2);
if (err < 0)
return err;