aboutsummaryrefslogtreecommitdiff
path: root/src/crystfel_gui.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2021-02-26 17:00:39 +0100
committerThomas White <taw@physics.org>2021-02-26 17:00:39 +0100
commit1584bced3ecc9fe699bd972a66741968a838398a (patch)
tree9ebdf74a44408102d616ce6e1e58684cb417f218 /src/crystfel_gui.c
parentab1591885a44b675a1301d88b041e261a36f7c36 (diff)
GUI: Automatically generate new job names
Diffstat (limited to 'src/crystfel_gui.c')
-rw-r--r--src/crystfel_gui.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c
index 8b330bb9..e2be0841 100644
--- a/src/crystfel_gui.c
+++ b/src/crystfel_gui.c
@@ -41,6 +41,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+#include <ctype.h>
#include <datatemplate.h>
#include <peaks.h>
@@ -1135,3 +1136,38 @@ void force_refls_on(struct crystfelproject *proj)
w = gtk_ui_manager_get_widget(proj->ui, "/ui/mainwindow/view/refls");
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), 1);
}
+
+
+/* Given an "old" job title (possibly NULL), generate a new job title */
+char *make_new_job_title(const char *orig_old_title)
+{
+ size_t len, i;
+ char *old_title;
+
+ if ( orig_old_title == NULL ) return NULL;
+
+ old_title = strdup(orig_old_title);
+ if ( old_title == NULL ) return NULL;
+
+ len = strlen(old_title);
+
+ for ( i=len-1; i>0; i-- ) {
+ if ( !isdigit(old_title[i]) ) break;
+ }
+ if ( i == len-1 ) {
+ /* No digits at end */
+ char *new_title = malloc(len+3);
+ if ( new_title == NULL ) return NULL;
+ strcpy(new_title, old_title);
+ strcat(new_title, "-2");
+ return new_title;
+ } else {
+ /* Digits at end */
+ int n = atoi(&old_title[i+1]);
+ char *new_title = malloc(len+6);
+ if ( new_title == NULL ) return NULL;
+ old_title[i+1] = '\0';
+ snprintf(new_title, len+6, "%s%i", old_title, n+1);
+ return new_title;
+ }
+}