Commit 12087a6c by Celine Mercier

C, views: made 'view_exists' function public (now 'obi_view_exists')

parent fbabbceb
......@@ -84,20 +84,6 @@ static char* build_unfinished_obiview_file_name(const char* view_name);
/**
* Internal function checking if a view (either finished or unfinished) with a given name already exists in a DMS.
*
* @param dms The DMS.
* @param view_name The name of the view.
*
* @returns A boolean value indicating whether the view already exists or not.
*
* @since September 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
static bool view_exists(OBIDMS_p dms, const char* view_name);
/**
* Internal function checking if a view is finished.
*
* @param dms The DMS.
......@@ -553,55 +539,6 @@ static char* build_unfinished_obiview_file_name(const char* view_name)
}
static bool view_exists(OBIDMS_p dms, const char* view_name)
{
struct dirent* dp;
char* file_name;
// Check finished views
// Create file name
file_name = build_obiview_file_name(view_name);
if (file_name == NULL)
return -1;
rewinddir(dms->view_directory);
while ((dp = readdir(dms->view_directory)) != NULL)
{
if ((dp->d_name)[0] == '.')
continue;
if (strcmp(dp->d_name, file_name) == 0)
{
free(file_name);
return true;
}
}
free(file_name);
// Check unfinished views
// Create file name
file_name = build_unfinished_obiview_file_name(view_name);
if (file_name == NULL)
return -1;
rewinddir(dms->view_directory);
while ((dp = readdir(dms->view_directory)) != NULL)
{
if ((dp->d_name)[0] == '.')
continue;
if (strcmp(dp->d_name, file_name) == 0)
{
free(file_name);
return true;
}
}
free(file_name);
return false;
}
static int view_is_finished(OBIDMS_p dms, const char* view_name)
{
struct dirent* dp;
......@@ -1557,6 +1494,55 @@ static int view_check_all_predicates(Obiview_p view, bool write)
**********************************************************************/
bool obi_view_exists(OBIDMS_p dms, const char* view_name)
{
struct dirent* dp;
char* file_name;
// Check finished views
// Create file name
file_name = build_obiview_file_name(view_name);
if (file_name == NULL)
return -1;
rewinddir(dms->view_directory);
while ((dp = readdir(dms->view_directory)) != NULL)
{
if ((dp->d_name)[0] == '.')
continue;
if (strcmp(dp->d_name, file_name) == 0)
{
free(file_name);
return true;
}
}
free(file_name);
// Check unfinished views
// Create file name
file_name = build_unfinished_obiview_file_name(view_name);
if (file_name == NULL)
return -1;
rewinddir(dms->view_directory);
while ((dp = readdir(dms->view_directory)) != NULL)
{
if ((dp->d_name)[0] == '.')
continue;
if (strcmp(dp->d_name, file_name) == 0)
{
free(file_name);
return true;
}
}
free(file_name);
return false;
}
Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_clone, index_t* line_selection, const char* comments)
{
Obiview_p view;
......@@ -1582,7 +1568,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
}
// Check uniqueness of name
if (view_exists(dms, view_name))
if (obi_view_exists(dms, view_name))
{
obi_set_errno(OBIVIEW_ALREADY_EXISTS_ERROR);
obidebug(1, "\nName of new view ('%s') already exists", view_name);
......@@ -2872,7 +2858,7 @@ int obi_delete_view(OBIDMS_p dms, const char* view_name)
int finished_view;
// Check that the view exists
if (view_exists(dms, view_name) == false)
if (obi_view_exists(dms, view_name) == false)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError trying to delete a view: view '%s' does not exist", view_name);
......
......@@ -139,6 +139,20 @@ typedef struct Obiview {
/**
* Function checking if a view (either finished or unfinished) with a given name already exists in a DMS.
*
* @param dms The DMS.
* @param view_name The name of the view.
*
* @returns A boolean value indicating whether the view already exists or not.
*
* @since September 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
bool obi_view_exists(OBIDMS_p dms, const char* view_name);
/**
* @brief Creates a new view.
*
* Fails if a view with the same name already exists.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment