mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
conf: add snd_config_is_array() function
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
05a6effd8d
commit
0c99c073d3
2 changed files with 40 additions and 0 deletions
|
|
@ -139,6 +139,7 @@ int snd_config_imake_safe_string(snd_config_t **config, const char *key, const c
|
||||||
int snd_config_imake_pointer(snd_config_t **config, const char *key, const void *ptr);
|
int snd_config_imake_pointer(snd_config_t **config, const char *key, const void *ptr);
|
||||||
|
|
||||||
snd_config_type_t snd_config_get_type(const snd_config_t *config);
|
snd_config_type_t snd_config_get_type(const snd_config_t *config);
|
||||||
|
int snd_config_is_array(const snd_config_t *config);
|
||||||
|
|
||||||
int snd_config_set_id(snd_config_t *config, const char *id);
|
int snd_config_set_id(snd_config_t *config, const char *id);
|
||||||
int snd_config_set_integer(snd_config_t *config, long value);
|
int snd_config_set_integer(snd_config_t *config, long value);
|
||||||
|
|
|
||||||
39
src/conf.c
39
src/conf.c
|
|
@ -1784,6 +1784,45 @@ snd_config_type_t snd_config_get_type(const snd_config_t *config)
|
||||||
return config->type;
|
return config->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int check_array_item(const char *id, int index)
|
||||||
|
{
|
||||||
|
const char *p;
|
||||||
|
long val;
|
||||||
|
|
||||||
|
for (p = id; *p; p++) {
|
||||||
|
if (*p < '0' || *p > '9')
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (safe_strtol(id, &val))
|
||||||
|
return 0;
|
||||||
|
return val == index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Returns if the compound is an array.
|
||||||
|
* \param config Handle to the configuration node.
|
||||||
|
* \return A positive value when true, zero when false, otherwise a negative error code.
|
||||||
|
*/
|
||||||
|
int snd_config_is_array(const snd_config_t *config)
|
||||||
|
{
|
||||||
|
int idx;
|
||||||
|
snd_config_iterator_t i, next;
|
||||||
|
snd_config_t *node;
|
||||||
|
|
||||||
|
assert(config);
|
||||||
|
if (config->type != SND_CONFIG_TYPE_COMPOUND)
|
||||||
|
return -EINVAL;
|
||||||
|
idx = 0;
|
||||||
|
snd_config_for_each(i, next, config) {
|
||||||
|
node = snd_config_iterator_entry(i);
|
||||||
|
if (!check_array_item(node->id, idx))
|
||||||
|
return 0;
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Returns the id of a configuration node.
|
* \brief Returns the id of a configuration node.
|
||||||
* \param[in] config Handle to the configuration node.
|
* \param[in] config Handle to the configuration node.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue