From eb514c6bd7ff669ecad6548885be2545fc02fea5 Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Fri, 23 Apr 2021 11:15:59 -0700 Subject: [PATCH] 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 --- topology/pre-processor.c | 27 +++++++++++++++++++++++++++ topology/pre-processor.h | 2 ++ 2 files changed, 29 insertions(+) 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