From 9d958b9db93e2009f403ad81fc7846036914f8fe Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 16 Jun 2020 16:25:20 +0200 Subject: Remove events.c, part 2 New event parsing, done at the last minute in image-hdf5.c --- src/crystfel_gui.c | 12 +++++++----- src/im-sandbox.c | 57 +++++++++++++++++++++++++++++------------------------- src/partialator.c | 2 +- 3 files changed, 39 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c index 87f57e7c..77a064f3 100644 --- a/src/crystfel_gui.c +++ b/src/crystfel_gui.c @@ -138,19 +138,21 @@ static void add_all_events(struct crystfelproject *proj, const char *filename, const DataTemplate *dtempl) { - struct event_list *events; + char **events; int i; + int n_events; - events = image_expand_frames(dtempl, filename); + events = image_expand_frames(dtempl, filename, &n_events); if ( events == NULL ) { ERROR("Couldn't expand event list\n"); return; } - for ( i=0; inum_events; i++ ) { - add_file_to_project(proj, filename, - get_event_string(events->events[i])); + for ( i=0; i 2 ) n--; - if ( n != 2 ) { - /* Event descriptor must contain "//". - * If it doesn't, assume the filename just contains a - * space. */ - if ( strstr(&line[n], "//") != NULL ) { - line[n] = '\0'; - *event = strdup(&line[n+1]); - } - } /* else no spaces at all */ - } + /* Chop off event ID */ + size_t n = strlen(line); + while ( line[n] != ' ' && n > 2 ) n--; + if ( n != 2 ) { + /* Event descriptor must contain "//". + * If it doesn't, assume the filename just contains a + * space. */ + if ( strstr(&line[n], "//") != NULL ) { + line[n] = '\0'; + *event = strdup(&line[n+1]); + } + } /* else no spaces at all */ if ( gpctx->use_basename ) { char *tmp; @@ -256,10 +256,10 @@ static int get_pattern(struct get_pattern_ctx *gpctx, /* Is an event available already? */ if ( (gpctx->events != NULL) - && (gpctx->event_index < gpctx->events->num_events) ) + && (gpctx->event_index < gpctx->n_events) ) { - *pfilename = strdup(gpctx->filename); - *pevent = get_event_string(gpctx->events->events[gpctx->event_index++]); + *pfilename = gpctx->filename; + *pevent = gpctx->events[gpctx->event_index++]; return 1; } @@ -272,13 +272,17 @@ static int get_pattern(struct get_pattern_ctx *gpctx, /* Does the line from the input file contain an event ID? * If so, just send it straight back. */ if ( evstr != NULL ) { - *pfilename = strdup(filename); - *pevent = strdup(evstr); + *pfilename = filename; + *pevent = evstr; return 1; } - free_event_list(gpctx->events); - gpctx->events = image_expand_frames(gpctx->dtempl, filename); + /* We got a filename, but no event. Attempt to expand... */ + free(gpctx->events); /* Free the old list. + * NB The actual strings were freed + * by fill_queue */ + gpctx->events = image_expand_frames(gpctx->dtempl, filename, + &gpctx->n_events); if ( gpctx->events == NULL ) { ERROR("Failed to get event list.\n"); return 0; @@ -289,8 +293,8 @@ static int get_pattern(struct get_pattern_ctx *gpctx, gpctx->filename = filename; gpctx->event_index = 0; - *pfilename = strdup(gpctx->filename); - *pevent = get_event_string(gpctx->events->events[gpctx->event_index++]); + *pfilename = gpctx->filename; + *pevent = gpctx->events[gpctx->event_index++]; return 1; } @@ -788,6 +792,7 @@ static int fill_queue(struct get_pattern_ctx *gpctx, struct sandbox *sb) snprintf(sb->shared->queue[sb->shared->n_events++], MAX_EV_LEN, "%s %s %i", filename, evstr, sb->serial++); sem_post(sb->queue_sem); + free(evstr); } return 0; diff --git a/src/partialator.c b/src/partialator.c index 11005555..1126095a 100644 --- a/src/partialator.c +++ b/src/partialator.c @@ -484,7 +484,7 @@ static struct custom_split *load_custom_split(const char *filename) ds = bits[2]; } else { fn = bits[0]; - evs = get_event_string(NULL); + evs = strdup("(none)"); ds = bits[1]; } free(bits); -- cgit v1.2.3