Commit 6899896c authored by Tobias Ellinghaus's avatar Tobias Ellinghaus

variables: Support recursive replacements

This now allows things like "$(TITLE-$(FILE_NAME))" or
"$(RIGHTS/XXXX/$(YEAR))".
parent 2df5fa71
......@@ -248,26 +248,19 @@ const char *dt_import_session_filename(struct dt_import_session_t *self, gboolea
return NULL;
}
dt_variables_expand(self->vp, pattern, TRUE);
/* verify that expanded path and filename yields a unique file */
path = dt_import_session_path(self, TRUE);
gchar *result_fname = dt_variables_get_result(self->vp);
gchar *result_fname = dt_variables_expand(self->vp, pattern, TRUE);
previous_fname = fname = g_build_path(G_DIR_SEPARATOR_S, path, result_fname, (char *)NULL);
g_free(result_fname);
result_fname = NULL;
if(g_file_test(fname, G_FILE_TEST_EXISTS) == TRUE)
{
fprintf(stderr, "[import_session] File %s exists.\n", fname);
do
{
/* file exists, yield a new filename */
dt_variables_expand(self->vp, pattern, TRUE);
result_fname = dt_variables_get_result(self->vp);
fname = g_build_path(G_DIR_SEPARATOR_S, path, result_fname, (char *)NULL);
g_free(result_fname);
result_fname = NULL;
result_fname = dt_variables_expand(self->vp, pattern, TRUE);
fname = g_build_path(G_DIR_SEPARATOR_S, path, result_fname, (char *)NULL);
fprintf(stderr, "[import_session] Testing %s.\n", fname);
/* check if same filename was yielded as before */
......@@ -289,7 +282,7 @@ const char *dt_import_session_filename(struct dt_import_session_t *self, gboolea
g_free(previous_fname);
g_free(pattern);
self->current_filename = dt_variables_get_result(self->vp);
self->current_filename = result_fname;
fprintf(stderr, "[import_session] Using filename %s.\n", self->current_filename);
return self->current_filename;
......@@ -311,8 +304,7 @@ const char *dt_import_session_path(struct dt_import_session_t *self, gboolean cu
return NULL;
}
dt_variables_expand(self->vp, pattern, FALSE);
new_path = dt_variables_get_result(self->vp);
new_path = dt_variables_expand(self->vp, pattern, FALSE);
g_free(pattern);
/* did the session path change ? */
......
This diff is collapsed.
......@@ -50,10 +50,8 @@ void dt_variables_set_time(dt_variables_params_t *params, time_t time);
/** set the time to use for EXIF variables */
void dt_variables_set_exif_time(dt_variables_params_t *params, time_t time);
/** expands variables in string, this free's previous expanding result */
void dt_variables_expand(dt_variables_params_t *params, gchar *string, gboolean iterate);
/** get the expanded string result. the result should be freed with g_free(). */
gchar *dt_variables_get_result(dt_variables_params_t *params);
/** expands variables in string. the result should be freed with g_free(). */
char *dt_variables_expand(dt_variables_params_t *params, gchar *source, gboolean iterate);
/** reset sequence number */
void dt_variables_reset_sequence(dt_variables_params_t *params);
......
......@@ -220,9 +220,8 @@ try_again:
d->vp->jobcode = "export";
d->vp->imgid = imgid;
d->vp->sequence = num;
dt_variables_expand(d->vp, d->filename, TRUE);
gchar *result_filename = dt_variables_get_result(d->vp);
gchar *result_filename = dt_variables_expand(d->vp, d->filename, TRUE);
g_strlcpy(filename, result_filename, sizeof(filename));
g_free(result_filename);
......
......@@ -222,9 +222,8 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co
d->vp->jobcode = "export";
d->vp->imgid = imgid;
d->vp->sequence = num;
dt_variables_expand(d->vp, d->filename, TRUE);
gchar *result_tmp_dir = dt_variables_get_result(d->vp);
gchar *result_tmp_dir = dt_variables_expand(d->vp, d->filename, TRUE);
g_strlcpy(tmp_dir, result_tmp_dir, sizeof(tmp_dir));
g_free(result_tmp_dir);
......@@ -244,9 +243,7 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co
g_strlcpy(d->filename, fixed_path, sizeof(d->filename));
g_free(fixed_path);
dt_variables_expand(d->vp, d->filename, TRUE);
gchar *result_filename = dt_variables_get_result(d->vp);
gchar *result_filename = dt_variables_expand(d->vp, d->filename, TRUE);
g_strlcpy(filename, result_filename, sizeof(filename));
g_free(result_filename);
......
......@@ -241,9 +241,8 @@ int store(dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, co
d->vp->jobcode = "export";
d->vp->imgid = imgid;
d->vp->sequence = num;
dt_variables_expand(d->vp, d->filename, TRUE);
gchar *result_filename = dt_variables_get_result(d->vp);
gchar *result_filename = dt_variables_expand(d->vp, d->filename, TRUE);
g_strlcpy(filename, result_filename, sizeof(filename));
g_free(result_filename);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment