Added the doc for the function building the element names, and a missing

free
This commit is contained in:
Celine Mercier
2016-12-05 10:46:21 +01:00
parent 852e5488c8
commit 5e0c9f878b

View File

@ -117,6 +117,23 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
static obiversion_t create_version_file(OBIDMS_column_directory_p column_directory); static obiversion_t create_version_file(OBIDMS_column_directory_p column_directory);
/**
* @brief Internal function building the default elements names of the lines of a
* column (i.e. "0;1;2;...;n").
*
* @warning The returned pointer has to be freed by the caller.
*
* @param nb_elements_per_line The number of elements per line in the column.
*
* @returns A pointer on the elements names.
* @retval NULL if an error occurred.
*
* @since December 2016
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
static char* build_default_elements_names(index_t nb_elements_per_line)
/** /**
* @brief Internal function setting the elements names of the lines of a * @brief Internal function setting the elements names of the lines of a
* column in the header of the OBIDMS column structure. * column in the header of the OBIDMS column structure.
@ -420,6 +437,36 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
} }
static char* build_default_elements_names(index_t nb_elements_per_line)
{
char* elements_names;
int i;
elements_names = (char*) malloc(ELEMENTS_NAMES_MAX * sizeof(char));
if (elements_names == NULL)
{
obi_set_errno(OBI_MALLOC_ERROR);
obidebug(1, "\nError allocating memory for elements names");
return NULL;
}
if (nb_elements_per_line > NB_ELTS_MAX_IF_DEFAULT_NAME)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nError: too many elements per line to use the default names (max = %d elements)", NB_ELTS_MAX_IF_DEFAULT_NAME);
return NULL;
}
for (i= 0; i < nb_elements_per_line; i++)
sprintf(elements_names, "%d", i);
// Terminal character
elements_names[strlen(elements_names)] = '\0';
return elements_names;
}
int obi_column_set_elements_names(OBIDMS_column_p column, const char* elements_names) int obi_column_set_elements_names(OBIDMS_column_p column, const char* elements_names)
{ {
if (strlen(elements_names) > ELEMENTS_NAMES_MAX) if (strlen(elements_names) > ELEMENTS_NAMES_MAX)
@ -551,37 +598,6 @@ size_t obi_get_platform_header_size()
} }
// TODO
char* build_default_elements_names(index_t nb_elements_per_line)
{
char* elements_names;
int i;
elements_names = (char*) malloc(ELEMENTS_NAMES_MAX * sizeof(char));
if (elements_names == NULL)
{
obi_set_errno(OBI_MALLOC_ERROR);
obidebug(1, "\nError allocating memory for elements names");
return NULL;
}
if (nb_elements_per_line > NB_ELTS_MAX_IF_DEFAULT_NAME)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obidebug(1, "\nError: too many elements per line to use the default names (max = %d elements)", NB_ELTS_MAX_IF_DEFAULT_NAME);
return NULL;
}
for (i= 0; i < nb_elements_per_line; i++)
sprintf(elements_names, "%d", i);
// Terminal character
elements_names[strlen(elements_names)] = '\0';
return elements_names;
}
OBIDMS_column_p obi_create_column(OBIDMS_p dms, OBIDMS_column_p obi_create_column(OBIDMS_p dms,
const char* column_name, const char* column_name,
OBIType_t data_type, OBIType_t data_type,
@ -802,6 +818,10 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
obi_column_set_elements_names(new_column, elements_names); obi_column_set_elements_names(new_column, elements_names);
// Free the element names if they were built
if ((elements_names == NULL) || (strcmp(elements_names, "") == 0))
free(elements_names);
strncpy(header->name, column_name, OBIDMS_COLUMN_MAX_NAME); strncpy(header->name, column_name, OBIDMS_COLUMN_MAX_NAME);
if (comments != NULL) if (comments != NULL)