From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: [PATCH] ucm: Allow cset commands to have values with spaces. Date: Thu, 09 Aug 2012 16:07:51 +0200 Message-ID: References: <1344519811-29520-1-git-send-email-tanu.kaskinen@digia.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 53D02266366 for ; Thu, 9 Aug 2012 15:38:05 +0200 (CEST) In-Reply-To: <1344519811-29520-1-git-send-email-tanu.kaskinen@digia.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Tanu Kaskinen Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org At Thu, 9 Aug 2012 16:43:31 +0300, Tanu Kaskinen wrote: > > An example: > cset "name='Input Select' Digital Mic" > > The old parsing code interpreted "name='Input Select' Digital" > as the element id, which of course didn't work. > > Signed-off-by: Tanu Kaskinen > --- > src/ucm/main.c | 19 +++++++++++++++++-- > 1 file changed, 17 insertions(+), 2 deletions(-) > > diff --git a/src/ucm/main.c b/src/ucm/main.c > index 4b37776..05a7b0a 100644 > --- a/src/ucm/main.c > +++ b/src/ucm/main.c > @@ -170,8 +170,23 @@ static int execute_cset(snd_ctl_t *ctl, char *cset) > snd_ctl_elem_value_malloc(&value); > snd_ctl_elem_info_malloc(&info); > > - pos = strrchr(cset, ' '); > - if (pos == NULL) { > + /* Find the space after the element id, taking quoting with > + single-quotes into account. */ > + for (pos = cset; *pos != '\0'; pos += strcspn(pos, "' ")) { > + if (*pos == ' ') > + break; > + if (*pos == '\'') { A double-quote can be supported easily here... Takashi > + pos++; > + pos += strcspn(pos, "'"); > + if (*pos == '\0') { > + uc_error("invalid element id (closing single-quote not found): %s", cset); > + err = -EINVAL; > + goto __fail; > + } > + pos++; > + } > + } > + if (*pos == '\0') { > uc_error("undefined value for cset >%s<", cset); > err = -EINVAL; > goto __fail; > -- > 1.7.9.5 >