aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/events.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcrystfel/src/events.c')
-rw-r--r--libcrystfel/src/events.c54
1 files changed, 24 insertions, 30 deletions
diff --git a/libcrystfel/src/events.c b/libcrystfel/src/events.c
index 25771a69..0f170bb5 100644
--- a/libcrystfel/src/events.c
+++ b/libcrystfel/src/events.c
@@ -3,10 +3,11 @@
*
* Event properties
*
- * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY,
+ * Copyright © 2012-2017 Deutsches Elektronen-Synchrotron DESY,
* a research centre of the Helmholtz Association.
*
* Authors:
+ * 2017 Thomas White
* 2014 Valerio Mariani
*
* This file is part of CrystFEL.
@@ -30,6 +31,7 @@
#define _GNU_SOURCE
#include "events.h"
+#include "utils.h"
#include <hdf5.h>
#include <string.h>
@@ -585,46 +587,38 @@ char *retrieve_full_path(struct event *ev, const char *data)
{
int ei ;
char *return_value;
+ char *pholder;
return_value = strdup(data);
+ pholder = strstr(return_value,"%");
+ ei = 0;
- for ( ei=0; ei<ev->path_length; ei++ ) {
+ while ( pholder != NULL ) {
char *tmp;
- tmp = event_path_placeholder_subst(ev->path_entries[ei],
- return_value);
-
- free(return_value);
- return_value = tmp;
-
- }
-
- return return_value;
-
-}
-
-
-char *partial_event_substitution(struct event *ev, const char *data)
-{
- int ei ;
- char *return_value;
- char *pholder;
- return_value = strdup(data);
- pholder = strstr(return_value,"%");
- ei = 0;
+ /* Check we have enough things to put in the placeholders */
+ if ( ei >= ev->path_length ) {
+ ERROR("Too many placeholders ('%%') in location.\n");
+ return NULL;
+ }
- while( pholder != NULL) {
+ /* Substitute one placeholder */
+ tmp = event_path_placeholder_subst(ev->path_entries[ei++],
+ return_value);
- char *tmp_subst_data;
+ if ( tmp == NULL ) {
+ ERROR("Couldn't substitute placeholder\n");
+ return NULL;
+ }
- tmp_subst_data = event_path_placeholder_subst(ev->path_entries[ei],
- return_value);
+ /* Next time, we will substitute the next part of the path into
+ * the partially substituted string */
free(return_value);
- return_value = strdup(tmp_subst_data);
- free(tmp_subst_data);
+ return_value = tmp;
+
pholder = strstr(return_value, "%");
- ei += 1;
+
}
return return_value;