aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libcrystfel/src/utils.c23
-rw-r--r--libcrystfel/src/utils.h1
-rw-r--r--src/crystfel_gui.c15
3 files changed, 26 insertions, 13 deletions
diff --git a/libcrystfel/src/utils.c b/libcrystfel/src/utils.c
index 1da0dfca..1e225778 100644
--- a/libcrystfel/src/utils.c
+++ b/libcrystfel/src/utils.c
@@ -612,6 +612,29 @@ void strip_extension(char *bfn)
}
+const char *filename_extension(const char *fn, const char **pext2)
+{
+ const char *ext = NULL;
+ const char *ext2 = NULL;
+ size_t r = strlen(fn)-1;
+
+ while ( r > 0 ) {
+ if ( fn[r] == '.' ) {
+ if ( ext != NULL ) {
+ ext2 = fn+r;
+ break;
+ } else {
+ ext = fn+r;
+ }
+ }
+ r--;
+ }
+
+ if ( pext2 != NULL ) *pext2 = ext2;
+ return ext;
+}
+
+
/* Force the linker to bring in CBLAS to make GSL happy */
void utils_fudge_gslcblas()
{
diff --git a/libcrystfel/src/utils.h b/libcrystfel/src/utils.h
index 39ee8848..9607708f 100644
--- a/libcrystfel/src/utils.h
+++ b/libcrystfel/src/utils.h
@@ -219,6 +219,7 @@ extern char *safe_basename(const char *in);
extern char *safe_strdup(const char *in);
extern void strip_extension(char *bfn);
extern char *load_entire_file(const char *filename);
+extern const char *filename_extension(const char *fn, const char **ext2);
/* ------------------------------ Useful stuff ------------------------------ */
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c
index db2fc1b3..a567ddcf 100644
--- a/src/crystfel_gui.c
+++ b/src/crystfel_gui.c
@@ -109,23 +109,12 @@ static int match_filename(const char *fn, enum match_type_id mt)
{
const char *ext = NULL;
const char *ext2 = NULL;
- size_t r = strlen(fn)-1;
-
- while ( r > 0 ) {
- if ( fn[r] == '.' ) {
- if ( ext != NULL ) {
- ext2 = fn+r;
- break;
- } else {
- ext = fn+r;
- }
- }
- r--;
- }
if ( mt == MATCH_EVERYTHING ) return 1;
+ ext = filename_extension(fn, &ext2);
if ( ext == NULL ) return 0;
+
if ( mt == MATCH_CHEETAH_LCLS_H5 ) {
return ((strcmp(ext, ".h5")==0)
&& (strncmp(fn, "LCLS", 4)==0));