]> git.alsa-project.org Git - alsa-utils.git/commitdiff
alsactl init - allow enum specification by name strings
authorJaroslav Kysela <perex@perex.cz>
Thu, 14 Aug 2008 09:21:59 +0000 (11:21 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 14 Aug 2008 09:21:59 +0000 (11:21 +0200)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
alsactl/init/hda
alsactl/init_parse.c

index 9c33123f6d030b8585e37397e4912c22178998d6..a104959b91b91c94586ccf05cecf30dcb201f9bc 100644 (file)
@@ -16,7 +16,7 @@ CTL{name}="Front Playback Volume", CTL{value}="35,35"
 CTL{name}="Front Playback Switch", CTL{value}="on,on"
 CTL{name}="PCM Playback Volume", CTL{value}="150,150"
 # capture
-CTL{name}="Input Source", CTL{value}="0"
+CTL{name}="Input Source", CTL{value}="Mic"
 CTL{name}="Capture Volume", CTL{value}="65,65"
 CTL{name}="Capture Switch", CTL{value}="on,on"
 RESULT="true", EXIT="return"
@@ -26,8 +26,8 @@ LABEL="Lenovo T61"
 CTL{reset}="mixer"
 CTL{name}="Headphone Playback Switch", CTL{value}="on,on"
 CTL{name}="PCM Playback Volume", CTL{value}="30,30"
-# capture (Internal Mic)
-CTL{name}="Input Source", CTL{value}="1"
+# capture
+CTL{name}="Input Source", CTL{value}="Internal Mic"
 CTL{name}="Internal Mic Boost", CTL{value}="1"
 CTL{name}="Capture Volume", CTL{value}="45,45"
 CTL{name}="Capture Switch", CTL{value}="on,on"
index 96caf46bc5c93cd07fcacc4d88f4e4e697ef2857..c96cc9a93042ca1e4fde9f27e87f03b5c4112dcf 100644 (file)
@@ -333,8 +333,9 @@ static const char *get_ctl_value(struct space *space)
 static int set_ctl_value(struct space *space, const char *value)
 {
        snd_ctl_elem_type_t type;
-       unsigned int idx, count;
+       unsigned int idx, idx2, count, items;
        const char *pos;
+       snd_hctl_elem_t *elem;
        int val;
 
        type = snd_ctl_elem_info_get_type(space->ctl_info);
@@ -377,8 +378,32 @@ static int set_ctl_value(struct space *space, const char *value)
                for (idx = 0; idx < count; idx++) {
                        while (*value == ' ')
                                value++;
-                       snd_ctl_elem_value_set_enumerated(space->ctl_value, idx, strtol(value, NULL, 0));
                        pos = strchr(value, ',');
+                       if (isdigit(value[0]) || value[0] == '-') {
+                               snd_ctl_elem_value_set_enumerated(space->ctl_value, idx, strtol(value, NULL, 0));
+                       } else {
+                               if (pos)
+                                       *(char *)pos = '\0';
+                               remove_trailing_chars((char *)value, ' ');
+                               items = snd_ctl_elem_info_get_items(space->ctl_info);
+                               for (idx2 = 0; idx2 < items; idx2++) {
+                                       snd_ctl_elem_info_set_item(space->ctl_info, idx);
+                                       elem = snd_hctl_find_elem(space->ctl_handle, space->ctl_id);
+                                       if (elem == NULL)
+                                               return -ENOENT;
+                                       val = snd_hctl_elem_info(elem, space->ctl_info);
+                                       if (val < 0)
+                                               return val;
+                                       if (strcasecmp(snd_ctl_elem_info_get_item_name(space->ctl_info), value) == 0) {
+                                               snd_ctl_elem_value_set_enumerated(space->ctl_value, idx, idx2);
+                                               break;
+                                       }
+                               }
+                               if (idx2 >= items) {
+                                       Perror(space, "wrong enum identifier '%s'", value);
+                                       return -EINVAL;
+                               }
+                       }
                        value = pos ? pos + 1 : value + strlen(value) - 1;
                }
                break;
@@ -389,14 +414,14 @@ static int set_ctl_value(struct space *space, const char *value)
                while (*value == ' ')
                        value++;
                if (strlen(value) != count * 2) {
-                       Perror(space, "bad ctl value hexa length (should be %u bytes, line %i)", count, space->linenum);
+                       Perror(space, "bad ctl value hexa length (should be %u bytes)", count);
                        return -EINVAL;
                }
                for (idx = 0; idx < count; idx += 2) {
                        val = hextodigit(*(value++)) << 4;
                        val |= hextodigit(*(value++));
                        if (val > 255) {
-                               Perror(space, "bad ctl hexa value (line %i)", space->linenum);
+                               Perror(space, "bad ctl hexa value");
                                return -EINVAL;
                        }
                        snd_ctl_elem_value_set_byte(space->ctl_value, idx, val);
@@ -1371,6 +1396,8 @@ static int parse_line(struct space *space, char *line, size_t linesize)
                                                Perror(space, "unterminated GOTO '%s'", space->go_to);
                                                free(space->go_to);
                                        }
+                                       if (err)
+                                               break;
                                }
                                closedir(dir);
                        } else {
@@ -1392,6 +1419,8 @@ static int parse_line(struct space *space, char *line, size_t linesize)
                        space->linenum = linenum;
                        if (space->quit)
                                break;
+                       if (err)
+                               break;
                        continue;
                }
                if (strncasecmp(key, "ACCESS", 6) == 0) {