From patchwork Wed Jul 1 13:44:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Girdwood X-Patchwork-Id: 6703751 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8255B9F2F0 for ; Wed, 1 Jul 2015 13:48:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8EE2A2041F for ; Wed, 1 Jul 2015 13:48:43 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 4A6D220254 for ; Wed, 1 Jul 2015 13:48:42 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 65338265342; Wed, 1 Jul 2015 15:48:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 3AF232614A4; Wed, 1 Jul 2015 15:46:16 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id E53092606D4; Wed, 1 Jul 2015 15:46:13 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by alsa0.perex.cz (Postfix) with ESMTP id CF2EE26069D for ; Wed, 1 Jul 2015 15:45:45 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 01 Jul 2015 06:45:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,386,1432623600"; d="scan'208";a="756533965" Received: from twhit3x-mobl1.ger.corp.intel.com (HELO loki.ger.corp.intel.com) ([10.252.31.19]) by orsmga002.jf.intel.com with ESMTP; 01 Jul 2015 06:45:43 -0700 From: Liam Girdwood To: Date: Wed, 1 Jul 2015 14:44:26 +0100 Message-Id: <1435758275-4047-4-git-send-email-liam.r.girdwood@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435758275-4047-1-git-send-email-liam.r.girdwood@linux.intel.com> References: <1435758275-4047-1-git-send-email-liam.r.girdwood@linux.intel.com> Cc: Takashi Iwai , Vinod Koul , Mark Brown , Liam Girdwood Subject: [alsa-devel] [PATCH v2 04/13] topology: Add text section parser. X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Parse text lists (like enum values) and store for later attachment to other objects. Signed-off-by: Liam Girdwood --- src/topology/text.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/topology/text.c diff --git a/src/topology/text.c b/src/topology/text.c new file mode 100644 index 0000000..d24d027 --- /dev/null +++ b/src/topology/text.c @@ -0,0 +1,99 @@ +/* + Copyright(c) 2014-2015 Intel Corporation + All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + Authors: Mengdong Lin + Yao Jin + Liam Girdwood + +*/ + +#include "list.h" +#include "tplg_local.h" + +#define TEXT_SIZE_MAX \ + (SND_SOC_TPLG_NUM_TEXTS * SNDRV_CTL_ELEM_ID_NAME_MAXLEN) + +static int parse_text_values(snd_config_t *cfg, struct tplg_elem *elem) +{ + snd_config_iterator_t i, next; + snd_config_t *n; + const char *value = NULL; + int j = 0; + + tplg_dbg(" Text Values: %s\n", elem->id); + + snd_config_for_each(i, next, cfg) { + n = snd_config_iterator_entry(i); + + if (j == SND_SOC_TPLG_NUM_TEXTS) { + tplg_dbg("error: text string number exceeds %d\n", j); + return -ENOMEM; + } + + /* get value */ + if (snd_config_get_string(n, &value) < 0) + continue; + + strncpy(&elem->texts[j][0], value, + SNDRV_CTL_ELEM_ID_NAME_MAXLEN); + elem->texts[j][SNDRV_CTL_ELEM_ID_NAME_MAXLEN - 1] = 0; + tplg_dbg("\t%s\n", &elem->texts[j][0]); + + j++; + } + + return 0; +} + +/* Parse Text data. + * + * Object text strings. + * + * SectionText."text name" { + * + * Values [ + * + * ] + * } + */ +int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg, + void *private ATTRIBUTE_UNUSED) +{ + snd_config_iterator_t i, next; + snd_config_t *n; + const char *id; + int err = 0; + struct tplg_elem *elem; + + elem = tplg_elem_new_common(tplg, cfg, PARSER_TYPE_TEXT); + if (!elem) + return -ENOMEM; + + snd_config_for_each(i, next, cfg) { + + n = snd_config_iterator_entry(i); + if (snd_config_get_id(n, &id) < 0) + continue; + + if (strcmp(id, "values") == 0) { + err = parse_text_values(n, elem); + if (err < 0) { + fprintf(stderr, "error: failed to parse text values"); + return err; + } + continue; + } + } + + return err; +}