From 1584bced3ecc9fe699bd972a66741968a838398a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 26 Feb 2021 17:00:39 +0100 Subject: GUI: Automatically generate new job names --- src/crystfel_gui.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/crystfel_gui.c') 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 #include #include +#include #include #include @@ -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; + } +} -- cgit v1.2.3