[alsa-devel] [PATCH RFC 1/2] control: Simplify using snd_config_get_bool()

Takashi Iwai tiwai at suse.de
Fri Oct 12 17:25:23 CEST 2012


snd_config_get_bool() was improved to parse also ASCII strings now,
so we don't have to open-code the boolean parser in
src/control/setup.c any longer.

Signed-off-by: Takashi Iwai <tiwai at suse.de>
---
 src/control/setup.c | 37 ++++++-------------------------------
 1 file changed, 6 insertions(+), 31 deletions(-)

diff --git a/src/control/setup.c b/src/control/setup.c
index eecda45..bd3599d 100644
--- a/src/control/setup.c
+++ b/src/control/setup.c
@@ -400,7 +400,6 @@ static int add_elem(snd_sctl_t *h, snd_config_t *_conf, snd_config_t *private_da
 {
 	snd_config_t *conf;
 	snd_config_iterator_t i, next;
-	char *tmp;
 	int iface = SND_CTL_ELEM_IFACE_MIXER;
 	const char *name = NULL;
 	long index = 0;
@@ -464,33 +463,17 @@ static int add_elem(snd_sctl_t *h, snd_config_t *_conf, snd_config_t *private_da
 			continue;
 		}
 		if (strcmp(id, "lock") == 0) {
-			if ((err = snd_config_get_ascii(n, &tmp)) < 0) {
-				SNDERR("field %s has an invalid type", id);
-				goto _err;
-			}
-			err = snd_config_get_bool_ascii(tmp);
-			if (err < 0) {
-				SNDERR("field %s is not a boolean", id);
-				free(tmp);
+			err = snd_config_get_bool(n);
+			if (err < 0)
 				goto _err;
-			}
 			lock = err;
-			free(tmp);
 			continue;
 		}
 		if (strcmp(id, "preserve") == 0) {
-			if ((err = snd_config_get_ascii(n, &tmp)) < 0) {
-				SNDERR("field %s has an invalid type", id);
-				goto _err;
-			}
-			err = snd_config_get_bool_ascii(tmp);
-			if (err < 0) {
-				SNDERR("field %s is not a boolean", id);
-				free(tmp);
+			err = snd_config_get_bool(n);
+			if (err < 0)
 				goto _err;
-			}
 			preserve = err;
-			free(tmp);
 			continue;
 		}
 		if (strcmp(id, "value") == 0) {
@@ -502,18 +485,10 @@ static int add_elem(snd_sctl_t *h, snd_config_t *_conf, snd_config_t *private_da
 			continue;
 		}
 		if (strcmp(id, "optional") == 0) {
-			if ((err = snd_config_get_ascii(n, &tmp)) < 0) {
-				SNDERR("field %s has an invalid type", id);
-				goto _err;
-			}
-			err = snd_config_get_bool_ascii(tmp);
-			if (err < 0) {
-				SNDERR("field %s is not a boolean", id);
-				free(tmp);
+			err = snd_config_get_bool(n);
+			if (err < 0)
 				goto _err;
-			}
 			optional = err;
-			free(tmp);
 			continue;
 		}
 		SNDERR("Unknown field %s", id);
-- 
1.7.12.2



More information about the Alsa-devel mailing list