mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-04 13:30:08 -05:00
conf: snd_config_save() - print arrays as [] not the internal representation
The internal represention of an array is:
{
0 value1
1 value2
2 value2
...
}
which is identicatal to shorter:
[
value1
value2
value3
]
Always print the short format. It's more optimized and readable.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
5766e54fbe
commit
8bd9e7897d
1 changed files with 20 additions and 14 deletions
34
src/conf.c
34
src/conf.c
|
|
@ -1604,12 +1604,13 @@ static void level_print(snd_output_t *out, unsigned int level)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _snd_config_save_children(snd_config_t *config, snd_output_t *out,
|
static int _snd_config_save_children(snd_config_t *config, snd_output_t *out,
|
||||||
unsigned int level, unsigned int joins);
|
unsigned int level, unsigned int joins,
|
||||||
|
int array);
|
||||||
|
|
||||||
static int _snd_config_save_node_value(snd_config_t *n, snd_output_t *out,
|
static int _snd_config_save_node_value(snd_config_t *n, snd_output_t *out,
|
||||||
unsigned int level)
|
unsigned int level)
|
||||||
{
|
{
|
||||||
int err;
|
int err, array;
|
||||||
switch (n->type) {
|
switch (n->type) {
|
||||||
case SND_CONFIG_TYPE_INTEGER:
|
case SND_CONFIG_TYPE_INTEGER:
|
||||||
snd_output_printf(out, "%ld", n->u.integer);
|
snd_output_printf(out, "%ld", n->u.integer);
|
||||||
|
|
@ -1627,13 +1628,14 @@ static int _snd_config_save_node_value(snd_config_t *n, snd_output_t *out,
|
||||||
SNDERR("cannot save runtime pointer type");
|
SNDERR("cannot save runtime pointer type");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
case SND_CONFIG_TYPE_COMPOUND:
|
case SND_CONFIG_TYPE_COMPOUND:
|
||||||
snd_output_putc(out, '{');
|
array = snd_config_is_array(n);
|
||||||
|
snd_output_putc(out, array ? '[' : '{');
|
||||||
snd_output_putc(out, '\n');
|
snd_output_putc(out, '\n');
|
||||||
err = _snd_config_save_children(n, out, level + 1, 0);
|
err = _snd_config_save_children(n, out, level + 1, 0, array);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
level_print(out, level);
|
level_print(out, level);
|
||||||
snd_output_putc(out, '}');
|
snd_output_putc(out, array ? ']' : '}');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -1650,7 +1652,8 @@ static void id_print(snd_config_t *n, snd_output_t *out, unsigned int joins)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _snd_config_save_children(snd_config_t *config, snd_output_t *out,
|
static int _snd_config_save_children(snd_config_t *config, snd_output_t *out,
|
||||||
unsigned int level, unsigned int joins)
|
unsigned int level, unsigned int joins,
|
||||||
|
int array)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
snd_config_iterator_t i, next;
|
snd_config_iterator_t i, next;
|
||||||
|
|
@ -1659,18 +1662,19 @@ static int _snd_config_save_children(snd_config_t *config, snd_output_t *out,
|
||||||
snd_config_t *n = snd_config_iterator_entry(i);
|
snd_config_t *n = snd_config_iterator_entry(i);
|
||||||
if (n->type == SND_CONFIG_TYPE_COMPOUND &&
|
if (n->type == SND_CONFIG_TYPE_COMPOUND &&
|
||||||
n->u.compound.join) {
|
n->u.compound.join) {
|
||||||
err = _snd_config_save_children(n, out, level, joins + 1);
|
err = _snd_config_save_children(n, out, level, joins + 1, 0);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
level_print(out, level);
|
level_print(out, level);
|
||||||
id_print(n, out, joins);
|
if (!array) {
|
||||||
|
id_print(n, out, joins);
|
||||||
|
snd_output_putc(out, ' ');
|
||||||
#if 0
|
#if 0
|
||||||
snd_output_putc(out, ' ');
|
snd_output_putc(out, '=');
|
||||||
snd_output_putc(out, '=');
|
|
||||||
#endif
|
#endif
|
||||||
snd_output_putc(out, ' ');
|
}
|
||||||
err = _snd_config_save_node_value(n, out, level);
|
err = _snd_config_save_node_value(n, out, level);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
|
|
@ -3129,10 +3133,12 @@ int snd_config_test_id(const snd_config_t *config, const char *id)
|
||||||
int snd_config_save(snd_config_t *config, snd_output_t *out)
|
int snd_config_save(snd_config_t *config, snd_output_t *out)
|
||||||
{
|
{
|
||||||
assert(config && out);
|
assert(config && out);
|
||||||
if (config->type == SND_CONFIG_TYPE_COMPOUND)
|
if (config->type == SND_CONFIG_TYPE_COMPOUND) {
|
||||||
return _snd_config_save_children(config, out, 0, 0);
|
int array = snd_config_is_array(config);
|
||||||
else
|
return _snd_config_save_children(config, out, 0, 0, array);
|
||||||
|
} else {
|
||||||
return _snd_config_save_node_value(config, out, 0);
|
return _snd_config_save_node_value(config, out, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue