aboutsummaryrefslogtreecommitdiff
path: root/src/dw-hdfsee.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-10-12 14:00:43 +0200
committerThomas White <taw@physics.org>2017-10-12 14:26:12 +0200
commitecd10f35e3babd9856b67e878fcd46b8ae72f705 (patch)
tree889344fdbb7a575df625c783c8222c6b11f2a8c7 /src/dw-hdfsee.c
parent9f18d76585c529f8055eaf13e4c92429d30beb1c (diff)
hdfsee: Add event ID to exported image filename
Diffstat (limited to 'src/dw-hdfsee.c')
-rw-r--r--src/dw-hdfsee.c53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c
index 28e78560..7ce62559 100644
--- a/src/dw-hdfsee.c
+++ b/src/dw-hdfsee.c
@@ -1681,6 +1681,43 @@ static gint displaywindow_save_response(GtkWidget *d, gint response,
}
+static void strip_extension(char *bfn)
+{
+ size_t r = strlen(bfn)-1;
+ while ( r > 0 ) {
+ if ( bfn[r] == '.') {
+ bfn[r] = '\0';
+ return;
+ }
+ r--;
+ }
+}
+
+
+static void move_back_one(char *a)
+{
+ int i;
+ size_t r = strlen(a);
+ for ( i=0; i<r; i++ ) {
+ a[i] = a[i+1];
+ }
+}
+
+
+static void substitute_slashes(char *bfn)
+{
+ size_t i;
+ size_t r = strlen(bfn);
+ for ( i=0; i<r; i++ ) {
+ if ( bfn[i] == '/') bfn[i] = '_';
+ while ( bfn[i+1] == '/' ) {
+ move_back_one(&bfn[i+1]);
+ }
+
+ }
+}
+
+
static gint displaywindow_save(GtkWidget *widget, DisplayWindow *dw)
{
GtkWidget *d, *hbox, *l, *cb;
@@ -1695,10 +1732,22 @@ static gint displaywindow_save(GtkWidget *widget, DisplayWindow *dw)
NULL);
bfn = safe_basename(dw->image->filename);
+ strip_extension(bfn);
if ( bfn != NULL ) {
- fn = malloc(strlen(bfn)+10);
+ size_t l = strlen(bfn)+10;
+ fn = malloc(l);
if ( fn != NULL ) {
- sprintf(fn, "%s.png", bfn);
+ char *evs;
+ if ( dw->multi_event ) {
+ struct event *ev = dw->ev_list->events[dw->curr_event];
+ evs = get_event_string(ev);
+ substitute_slashes(evs);
+ } else {
+ evs = strdup("");
+ }
+
+ snprintf(fn, l, "%s%s.png", bfn, evs);
+ free(evs);
STATUS("%s'\n", fn);
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(d),
fn);