}
static int pre_process_includes(struct tplg_pre_processor *tplg_pp, snd_config_t *top,
- const char *pre_processor_defs);
+ const char *pre_processor_defs, const char *inc_path);
static int pre_process_include_conf(struct tplg_pre_processor *tplg_pp, snd_config_t *config,
const char *pre_processor_defs, snd_config_t **new,
- snd_config_t *variable)
+ snd_config_t *variable, const char *inc_path)
{
snd_config_iterator_t i, next;
const char *variable_name;
regex_t regex;
const char *filename;
const char *id;
- char *full_path, *alsa_dir = getenv("ALSA_CONFIG_DIR");
+ char *full_path;
n = snd_config_iterator_entry(i);
if (snd_config_get_id(n, &id) < 0)
continue;
/* regex matched. now include the conf file */
- snd_config_get_string(n, &filename);
+ ret = snd_config_get_string(n, &filename);
+ if (ret < 0)
+ goto err;
- if (alsa_dir)
- full_path = tplg_snprintf("%s/%s", alsa_dir, filename);
+ if (filename && filename[0] != '/')
+ full_path = tplg_snprintf("%s/%s", inc_path, filename);
else
- full_path = tplg_snprintf("%s", alsa_dir);
+ full_path = tplg_snprintf("%s", filename);
ret = snd_input_stdio_open(&in, full_path, "r");
- free(full_path);
if (ret < 0) {
- fprintf(stderr, "Unable to open included conf file %s\n", filename);
+ fprintf(stderr, "Unable to open included conf file %s\n", full_path);
+ free(full_path);
goto err;
}
+ free(full_path);
/* load config */
ret = snd_config_load(*new, in);
+ snd_input_close(in);
if (ret < 0) {
fprintf(stderr, "Unable to load included configuration\n");
goto err;
}
/* recursively process any nested includes */
- return pre_process_includes(tplg_pp, *new, pre_processor_defs);
+ return pre_process_includes(tplg_pp, *new, pre_processor_defs, inc_path);
}
err:
}
static int pre_process_includes(struct tplg_pre_processor *tplg_pp, snd_config_t *top,
- const char *pre_processor_defs)
+ const char *pre_processor_defs, const char *inc_path)
{
snd_config_iterator_t i, next;
snd_config_t *includes, *conf_defines;
}
/* create conf node from included file */
- ret = pre_process_include_conf(tplg_pp, n, pre_processor_defs, &new, define);
+ ret = pre_process_include_conf(tplg_pp, n, pre_processor_defs, &new, define, inc_path);
if (ret < 0) {
fprintf(stderr, "Unable to process include file \n");
return ret;
}
static int pre_process_includes_all(struct tplg_pre_processor *tplg_pp, snd_config_t *top,
- const char *pre_processor_defs)
+ const char *pre_processor_defs, const char *inc_path)
{
snd_config_iterator_t i, next;
int ret;
return 0;
/* process includes at this node */
- ret = pre_process_includes(tplg_pp, top, pre_processor_defs);
+ ret = pre_process_includes(tplg_pp, top, pre_processor_defs, inc_path);
if (ret < 0) {
fprintf(stderr, "Failed to process includes\n");
return ret;
n = snd_config_iterator_entry(i);
- ret = pre_process_includes_all(tplg_pp, n, pre_processor_defs);
+ ret = pre_process_includes_all(tplg_pp, n, pre_processor_defs, inc_path);
if (ret < 0)
return ret;
}
}
int pre_process(struct tplg_pre_processor *tplg_pp, char *config, size_t config_size,
- const char *pre_processor_defs)
+ const char *pre_processor_defs, const char *inc_path)
{
snd_input_t *in;
snd_config_t *top;
}
/* include conditional conf files */
- err = pre_process_includes_all(tplg_pp, tplg_pp->input_cfg, pre_processor_defs);
+ err = pre_process_includes_all(tplg_pp, tplg_pp->input_cfg, pre_processor_defs, inc_path);
if (err < 0) {
fprintf(stderr, "Failed to process conditional includes in input config\n");
goto err;
return err;
}
+static char *get_inc_path(const char *filename)
+{
+ const char *s = strrchr(filename, '/');
+ char *r = strdup(filename);
+ if (r && s)
+ r[s - filename] = '\0';
+ return r;
+}
+
/* Convert Topology2.0 conf to the existing conf syntax */
static int pre_process_conf(const char *source_file, const char *output_file,
const char *pre_processor_defs)
{
struct tplg_pre_processor *tplg_pp;
size_t config_size;
- char *config;
+ char *config, *inc_path;
int err;
err = load(source_file, (void **)&config, &config_size);
return err;
/* init pre-processor */
- err = init_pre_precessor(&tplg_pp, SND_OUTPUT_STDIO, output_file);
+ err = init_pre_processor(&tplg_pp, SND_OUTPUT_STDIO, output_file);
if (err < 0) {
fprintf(stderr, _("failed to init pre-processor for Topology2.0\n"));
free(config);
}
/* pre-process conf file */
- err = pre_process(tplg_pp, config, config_size, pre_processor_defs);
+ inc_path = get_inc_path(source_file);
+ err = pre_process(tplg_pp, config, config_size, pre_processor_defs, inc_path);
+ free(inc_path);
/* free pre-processor */
free_pre_preprocessor(tplg_pp);
{
struct tplg_pre_processor *tplg_pp = NULL;
snd_tplg_t *tplg;
- char *config;
+ char *config, *inc_path;
void *bin;
size_t config_size, size;
int err;
size_t size;
/* init pre-processor */
- init_pre_precessor(&tplg_pp, SND_OUTPUT_BUFFER, NULL);
+ init_pre_processor(&tplg_pp, SND_OUTPUT_BUFFER, NULL);
/* pre-process conf file */
- err = pre_process(tplg_pp, config, config_size, pre_processor_defs);
+ inc_path = get_inc_path(source_file);
+ err = pre_process(tplg_pp, config, config_size, pre_processor_defs, inc_path);
+ free(inc_path);
if (err) {
free_pre_preprocessor(tplg_pp);
free(config);