From: Ranjani Sridharan Date: Fri, 23 Apr 2021 18:15:59 +0000 (-0700) Subject: topology: pre-processor: Add a helper function to concat strings X-Git-Tag: v1.2.5~30 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=eb514c6bd7ff669ecad6548885be2545fc02fea5;p=alsa-utils.git topology: pre-processor: Add a helper function to concat strings The pre-processor needs to concatinate strings separated by '.' for building object names from constructor attribute values and searching for configs with ID's containing strings separate by '.'. Add a helper function to concat strings in the specified input format. Signed-off-by: Ranjani Sridharan Signed-off-by: Jaroslav Kysela --- diff --git a/topology/pre-processor.c b/topology/pre-processor.c index 100c9ad..3d50d8c 100644 --- a/topology/pre-processor.c +++ b/topology/pre-processor.c @@ -71,6 +71,33 @@ int tplg_config_make_add(snd_config_t **config, const char *id, snd_config_type_ return ret; } +/* + * The pre-processor will need to concat multiple strings separate by '.' to construct the object + * name and search for configs with ID's separated by '.'. + * This function helps concat input strings in the specified input format + */ +char *tplg_snprintf(char *fmt, ...) +{ + char *string; + int len = 1; + + va_list va; + + va_start(va, fmt); + len += vsnprintf(NULL, 0, fmt, va); + va_end(va); + + string = calloc(1, len); + if (!string) + return NULL; + + va_start(va, fmt); + vsnprintf(string, len, fmt, va); + va_end(va); + + return string; +} + #ifdef TPLG_DEBUG void tplg_pp_debug(char *fmt, ...) { diff --git a/topology/pre-processor.h b/topology/pre-processor.h index cac464b..d9f0f3e 100644 --- a/topology/pre-processor.h +++ b/topology/pre-processor.h @@ -30,4 +30,6 @@ void tplg_pp_config_debug(struct tplg_pre_processor *tplg_pp, snd_config_t *cfg) snd_config_t *tplg_find_config(snd_config_t *config, const char *name); int tplg_config_make_add(snd_config_t **config, const char *id, snd_config_type_t type, snd_config_t *parent); + +char *tplg_snprintf(char *fmt, ...); #endif