Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions topology/pre-processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,12 @@ static int pre_process_include_conf(struct tplg_pre_processor *tplg_pp, snd_conf
snd_input_t *in;
snd_config_t *n;
regex_t regex;
const char *filename;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aiChaoSONG the code looks good. Can you please add an example of this in the commit message and what the limitations are?

const char *matched_value;
const char *id;
char *full_path;
char *file_ext;
bool is_conf_file;
const char* conf_file_ext = ".conf";

n = snd_config_iterator_entry(i);
if (snd_config_get_id(n, &id) < 0)
Expand All @@ -504,23 +507,39 @@ static int pre_process_include_conf(struct tplg_pre_processor *tplg_pp, snd_conf
if (ret)
continue;

/* regex matched. now include the conf file */
ret = snd_config_get_string(n, &filename);
/* regex matched. get the value for the matched key */
ret = snd_config_get_string(n, &matched_value);
if (ret < 0)
goto err;

if (filename && filename[0] != '/')
full_path = tplg_snprintf("%s/%s", tplg_pp->inc_path, filename);
else
full_path = tplg_snprintf("%s", filename);

ret = snd_input_stdio_open(&in, full_path, "r");
if (ret < 0) {
fprintf(stderr, "Unable to open included conf file %s\n", full_path);
/*
* Check whether the value for the matched key is a conf file or conf block,
* If it ends with '.conf', it is a conf file, otherwise, it is conf block.
*/

@lgirdwood lgirdwood Jan 18, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add in the comment what the supported input strings are and how they are converted to the runtime string value.

file_ext = matched_value + strlen(matched_value) - strlen(conf_file_ext);
is_conf_file = !strcmp(file_ext, conf_file_ext);

if (is_conf_file) {
if (matched_value[0] != '/')
full_path = tplg_snprintf("%s/%s", tplg_pp->inc_path, matched_value);
else
full_path = tplg_snprintf("%s", matched_value);

ret = snd_input_stdio_open(&in, full_path, "r");
if (ret < 0) {
fprintf(stderr, "Unable to open included conf file %s\n", full_path);
free(full_path);
goto err;
}
free(full_path);
goto err;
} else {
ret = snd_input_buffer_open(&in, matched_value, -1);
if (ret < 0) {
fprintf(stderr, "Unable to open buffer for conf input\n");
goto err;
}
}
free(full_path);

/* load config */
ret = snd_config_load(*new, in);
Expand Down