diff options
author | Takashi Iwai <tiwai@suse.de> | 2007-07-31 17:29:45 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2007-07-31 17:29:45 +0200 |
commit | 4b16370c01c2352eb00375e80d15897212045607 (patch) | |
tree | 043ee764d7e3ea233b8f22a155383eee50764fbe /amixer | |
parent | fea8dbf0209130259bb9a3248d16a995e96369d8 (diff) |
amixer - Allow to pass enum item string for cset, too
cset accepts only integer values as indices, so far, but it's a bit
unfriendly. Now it accepts the item name as a string argument, too.
The index can be given using numbers as fallback.
Diffstat (limited to 'amixer')
-rw-r--r-- | amixer/amixer.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/amixer/amixer.c b/amixer/amixer.c index 7da0ebe..87d93a5 100644 --- a/amixer/amixer.c +++ b/amixer/amixer.c @@ -1154,6 +1154,34 @@ static int parse_simple_id(const char *str, snd_mixer_selem_id_t *sid) return 0; } +static int get_ctl_enum_item_index(snd_ctl_t *handle, snd_ctl_elem_info_t *info, + char **ptrp) +{ + char *ptr = *ptrp; + int items, i, len; + const char *name; + + items = snd_ctl_elem_info_get_items(info); + if (items <= 0) + return -1; + + for (i = 0; i < items; i++) { + snd_ctl_elem_info_set_item(info, i); + if (snd_ctl_elem_info(handle, info) < 0) + return -1; + name = snd_ctl_elem_info_get_item_name(info); + len = strlen(name); + if (! strncmp(name, ptr, len)) { + if (! ptr[len] || ptr[len] == ',' || ptr[len] == '\n') { + ptr += len; + *ptrp = ptr; + return i; + } + } + } + return -1; +} + static int cset(int argc, char *argv[], int roflag, int keep_handle) { int err; @@ -1242,7 +1270,9 @@ static int cset(int argc, char *argv[], int roflag, int keep_handle) snd_ctl_elem_value_set_integer64(control, idx, tmp); break; case SND_CTL_ELEM_TYPE_ENUMERATED: - tmp = get_integer(&ptr, 0, snd_ctl_elem_info_get_items(info) - 1); + tmp = get_ctl_enum_item_index(handle, info, &ptr); + if (tmp < 0) + tmp = get_integer(&ptr, 0, snd_ctl_elem_info_get_items(info) - 1); snd_ctl_elem_value_set_enumerated(control, idx, tmp); break; case SND_CTL_ELEM_TYPE_BYTES: |