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 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'libcrystfel/src/crystal.c') 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; +} -- cgit v1.2.3