From 8abbfa203af7abba3ce940f60021ee3a00d3ed66 Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Wed, 23 Nov 2016 11:32:39 +0100 Subject: [PATCH] Good file for commit 6fa9a8bd: When a view is cloned, a comment is added to the new view specifying the name of the cloned view --- src/obiview.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/obiview.c b/src/obiview.c index c9a64ea..288464b 100644 --- a/src/obiview.c +++ b/src/obiview.c @@ -1133,6 +1133,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl Obiview_p view; int i; index_t line_nb; + char* clone_comment; // Check that the DMS is a valid pointer if (dms == NULL) @@ -1277,6 +1278,27 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl } else view->predicate_functions = NULL; + + // Write comment specifying the name of the cloned view + clone_comment = (char*) malloc((strlen((view_to_clone->infos)->name) + 15)*sizeof(char)); + if (clone_comment == NULL) + { + obi_set_errno(OBI_MALLOC_ERROR); + obidebug(1, "\nError allocating memory for a view comment"); + return NULL; + } + if (sprintf(clone_comment, "Cloned from %s.\n", (view_to_clone->infos)->name) < 0) + { + obi_set_errno(OBIVIEW_ERROR); + obidebug(1, "\nError building a view comment"); + return NULL; + } + if (write_comments_to_view_file(view, clone_comment) < 0) + { + obidebug(1, "\nError writing comments when creating a view"); + obi_close_view(view); + return NULL; + } } // Else, fill empty view structure @@ -1297,7 +1319,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl strcpy((view->infos)->name, view_name); (view->infos)->creation_date = time(NULL); - if (write_comments_to_view_file(view, comments) < 0) // TODO copy comments if cloning view? + if (write_comments_to_view_file(view, comments) < 0) { obidebug(1, "\nError writing comments when creating a view"); obi_close_view(view); @@ -1324,7 +1346,6 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl } // Once the view has been created with all its elements and informations, add the columns if the view is cloned from another view - // Add the columns from the view to clone in the new view if (view_to_clone != NULL) { (view->infos)->column_count = 0;