Skip to content

Commit

Permalink
add config path processing in generator function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Splinter1984 committed Nov 9, 2023
1 parent 8fb9d0d commit 38546c3
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions idlpy/src/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ generate(const idl_pstate_t *pstate, const idlc_generator_config_t *config)
idlpy_ctx ctx;
idl_retcode_t ret = IDL_RETCODE_NO_MEMORY;

const char *sep, *file, *path, *ext;
const char *sep, *file, *path, *ext, *dir;
char empty[1] = {'\0'};
char *basename = NULL;

assert(pstate->paths);
assert(pstate->paths->name);
(void) config;

path = pstate->sources->path->name;
sep = ext = NULL;
Expand All @@ -52,10 +52,28 @@ generate(const idl_pstate_t *pstate, const idlc_generator_config_t *config)
}

file = sep ? sep + 1 : path;
if (idl_isabsolute(path) || !sep)
dir = empty;
else if (!(dir = idl_strndup(path, (size_t)(sep-path))))
goto err;
if (!(basename = idl_strndup(file, ext ? (size_t)(ext-file) : strlen(file))))
goto err;

char *output_dir = config->output_dir;
char *output_path = "./";
sep = dir[0] == '\0' ? "" : "/";
if(output_dir && output_dir[0] != '\0') {
if(idl_asprintf(&output_path, "%s%s%s/", output_dir, sep, dir) < 0)
goto err;
sep = "/";
} else {
if(!(output_path = idl_strdup(dir)))
goto err;
}
if (!strcmp(output_path, ""))
output_path = "./";

ctx = idlpy_ctx_new("./", basename, prefix_root_module);
ctx = idlpy_ctx_new(output_path, basename, prefix_root_module);

// Enter root
if (idlpy_ctx_enter_module(ctx, "") != IDL_VISIT_REVISIT) {
Expand Down Expand Up @@ -92,4 +110,5 @@ static const idlc_option_t *opts[] = {
const idlc_option_t** generator_options(void)
{
return opts;
}
}

0 comments on commit 38546c3

Please sign in to comment.