mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-04 13:30:08 -05:00
ucm: add ${eval:EXPR} substitution (Syntax 5)
It is useful to do simple integer math in UCM configurations, too.
Use snd_config_evaluate_string() string for this job.
Example:
${eval:1+1}
${eval:100*$var1}
${eval:$[$var2+1]/5}
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
bf528b9066
commit
7b6da9ee6d
3 changed files with 42 additions and 5 deletions
|
|
@ -119,8 +119,8 @@ static int _to_integer(value_type_t *val, snd_config_t *c)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int _eval_string(snd_config_t **dst, const char *s,
|
||||
snd_config_expand_fcn_t fcn, void *private_data)
|
||||
int _snd_eval_string(snd_config_t **dst, const char *s,
|
||||
snd_config_expand_fcn_t fcn, void *private_data)
|
||||
{
|
||||
snd_config_t *tmp;
|
||||
const char *save, *e;
|
||||
|
|
@ -174,7 +174,7 @@ static int _eval_string(snd_config_t **dst, const char *s,
|
|||
return -ENOMEM;
|
||||
memcpy(m, s + 2, e - s - 2);
|
||||
m[e - s - 3] = '\0';
|
||||
err = _eval_string(&tmp, m, fcn, private_data);
|
||||
err = _snd_eval_string(&tmp, m, fcn, private_data);
|
||||
free(m);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
@ -250,7 +250,7 @@ int snd_config_evaluate_string(snd_config_t **dst, const char *s,
|
|||
if (*s != '$')
|
||||
return -EINVAL;
|
||||
if (s[1] == '[') {
|
||||
err = _eval_string(dst, s, fcn, private_data);
|
||||
err = _snd_eval_string(dst, s, fcn, private_data);
|
||||
if (err < 0)
|
||||
SNDERR("wrong expression '%s'", s);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue