]> git.alsa-project.org Git - alsa-utils.git/commitdiff
topology: pre-processor: Add a helper function to concat strings
authorRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Fri, 23 Apr 2021 18:15:59 +0000 (11:15 -0700)
committerJaroslav Kysela <perex@perex.cz>
Tue, 25 May 2021 16:26:51 +0000 (18:26 +0200)
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 <ranjani.sridharan@linux.intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
topology/pre-processor.c
topology/pre-processor.h

index 100c9ad22c8a72b511bb1f797f83681675aa2988..3d50d8ce2fca698f90a200b16950a636176312a4 100644 (file)
@@ -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, ...)
 {
index cac464b5576257f1c96704ca8d794a0cf5f6678f..d9f0f3ea8c32029644c173daa6b78a98b59e2992 100644 (file)
@@ -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