mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	mixer: simple - add snd_mixer_selem_id_parse() from amixer
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
		
							parent
							
								
									1b14643384
								
							
						
					
					
						commit
						4ce38a5ff4
					
				
					 2 changed files with 54 additions and 0 deletions
				
			
		| 
						 | 
					@ -304,6 +304,7 @@ const char *snd_mixer_selem_id_get_name(const snd_mixer_selem_id_t *obj);
 | 
				
			||||||
unsigned int snd_mixer_selem_id_get_index(const snd_mixer_selem_id_t *obj);
 | 
					unsigned int snd_mixer_selem_id_get_index(const snd_mixer_selem_id_t *obj);
 | 
				
			||||||
void snd_mixer_selem_id_set_name(snd_mixer_selem_id_t *obj, const char *val);
 | 
					void snd_mixer_selem_id_set_name(snd_mixer_selem_id_t *obj, const char *val);
 | 
				
			||||||
void snd_mixer_selem_id_set_index(snd_mixer_selem_id_t *obj, unsigned int val);
 | 
					void snd_mixer_selem_id_set_index(snd_mixer_selem_id_t *obj, unsigned int val);
 | 
				
			||||||
 | 
					int snd_mixer_selem_id_parse(snd_mixer_selem_id_t *dst, const char *str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** \} */
 | 
					/** \} */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1052,3 +1052,56 @@ void snd_mixer_selem_id_set_index(snd_mixer_selem_id_t *obj, unsigned int val)
 | 
				
			||||||
	assert(obj);
 | 
						assert(obj);
 | 
				
			||||||
	obj->index = val;
 | 
						obj->index = val;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * \brief Parse ASCII simple mixer element identifier
 | 
				
			||||||
 | 
					 * \param dst Parsed simple mixer element identifier
 | 
				
			||||||
 | 
					 * \param str Mixer simple element ASCII representation
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int snd_mixer_selem_id_parse(snd_mixer_selem_id_t *dst, const char *str)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int c, size;
 | 
				
			||||||
 | 
						char buf[128];
 | 
				
			||||||
 | 
						char *ptr = buf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memset(dst, 0, sizeof(*dst));
 | 
				
			||||||
 | 
						while (*str == ' ' || *str == '\t')
 | 
				
			||||||
 | 
							str++;
 | 
				
			||||||
 | 
						if (!(*str))
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						size = 1;	/* for '\0' */
 | 
				
			||||||
 | 
						if (*str != '"' && *str != '\'') {
 | 
				
			||||||
 | 
							while (*str && *str != ',') {
 | 
				
			||||||
 | 
								if (size < (int)sizeof(buf)) {
 | 
				
			||||||
 | 
									*ptr++ = *str;
 | 
				
			||||||
 | 
									size++;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								str++;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							c = *str++;
 | 
				
			||||||
 | 
							while (*str && *str != c) {
 | 
				
			||||||
 | 
								if (size < (int)sizeof(buf)) {
 | 
				
			||||||
 | 
									*ptr++ = *str;
 | 
				
			||||||
 | 
									size++;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								str++;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (*str == c)
 | 
				
			||||||
 | 
								str++;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (*str == '\0') {
 | 
				
			||||||
 | 
							*ptr = 0;
 | 
				
			||||||
 | 
							goto _set;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (*str != ',')
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						*ptr = 0;	/* terminate the string */
 | 
				
			||||||
 | 
						str++;
 | 
				
			||||||
 | 
						if (str[0] < '0' || str[1] > '9')
 | 
				
			||||||
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
						dst->index = atoi(str);
 | 
				
			||||||
 | 
					       _set:
 | 
				
			||||||
 | 
						snd_strlcpy(dst->name, buf, sizeof(dst->name));
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue