From a1f41743c249d280a4dc56c6433b6b5817388934 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 29 Mar 2015 08:02:45 -0700 Subject: Add crystal_add_notes() --- libcrystfel/src/crystal.c | 25 +++++++++++++++++++++++++ libcrystfel/src/crystal.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/libcrystfel/src/crystal.c b/libcrystfel/src/crystal.c index 91c3fd52..3c52ddd7 100644 --- a/libcrystfel/src/crystal.c +++ b/libcrystfel/src/crystal.c @@ -291,3 +291,28 @@ void crystal_set_notes(Crystal *cryst, const char *notes) free(cryst->notes); /* free(NULL) is OK */ cryst->notes = strdup(notes); } + + +void crystal_add_notes(Crystal *cryst, const char *notes_add) +{ + size_t len; + char *nnotes; + + if ( cryst->notes == NULL ) { + crystal_set_notes(cryst, notes_add); + return; + } + + len = strlen(notes_add) + strlen(cryst->notes) + 2; + nnotes = malloc(len); + if ( nnotes == NULL ) { + ERROR("Failed to add notes to crystal.\n"); + return; + } + + strcpy(nnotes, cryst->notes); + strcat(nnotes, "\n"); + strcat(nnotes, notes_add); + free(cryst->notes); + cryst->notes = nnotes; +} diff --git a/libcrystfel/src/crystal.h b/libcrystfel/src/crystal.h index 92f60fc3..f0d732ff 100644 --- a/libcrystfel/src/crystal.h +++ b/libcrystfel/src/crystal.h @@ -82,6 +82,8 @@ extern void crystal_set_image(Crystal *cryst, struct image *image); extern void crystal_set_mosaicity(Crystal *cryst, double m); extern void crystal_set_notes(Crystal *cryst, const char *notes); +extern void crystal_add_notes(Crystal *cryst, const char *notes_add); + #ifdef __cplusplus } #endif -- cgit v1.2.3