Merge pull request #41 from seleznevae/issue-38
Add string descriptions of errors
This commit is contained in:
commit
b0e52f4848
@ -7,6 +7,8 @@
|
|||||||
- `ft_ln` returns status of operation.
|
- `ft_ln` returns status of operation.
|
||||||
- Add new table property `adding_strategy` (2 strategies available - replace(default) and insert).
|
- Add new table property `adding_strategy` (2 strategies available - replace(default) and insert).
|
||||||
- Add function `ft_row_count` (`row_count` in C++ API) to get number of rows in the table.
|
- Add function `ft_row_count` (`row_count` in C++ API) to get number of rows in the table.
|
||||||
|
- Add function `ft_strerror` to get string descriptions of error codes.
|
||||||
|
- Change error code names and values.
|
||||||
|
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ These pages contain the API documentation of **libfort** - simple library to cre
|
|||||||
- @link ft_set_default_printf_field_separator ft_set_default_printf_field_separator @endlink -- Set field separator for ft_printf, ft_printf_ln
|
- @link ft_set_default_printf_field_separator ft_set_default_printf_field_separator @endlink -- Set field separator for ft_printf, ft_printf_ln
|
||||||
- @link ft_is_empty ft_is_empty @endlink -- check if table is empty
|
- @link ft_is_empty ft_is_empty @endlink -- check if table is empty
|
||||||
- @link ft_row_count ft_row_count @endlink -- get number of rows in the table
|
- @link ft_row_count ft_row_count @endlink -- get number of rows in the table
|
||||||
|
- @link ft_strerror ft_strerror @endlink -- get string describing the error code
|
||||||
|
|
||||||
- Data structures and types
|
- Data structures and types
|
||||||
- @link ft_table_t ft_table_t @endlink -- table handler
|
- @link ft_table_t ft_table_t @endlink -- table handler
|
||||||
|
63
lib/fort.c
63
lib/fort.c
@ -2580,7 +2580,7 @@ f_status fill_cell_from_buffer(f_cell_t *cell, const f_string_buffer_t *buffer)
|
|||||||
#endif /* FT_HAVE_UTF8 */
|
#endif /* FT_HAVE_UTF8 */
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -2761,7 +2761,7 @@ static int split_cur_row(ft_table_t *table, f_row_t **tail_of_cur_row)
|
|||||||
f_row_t *tail = split_row(row, table->cur_col);
|
f_row_t *tail = split_row(row, table->cur_col);
|
||||||
if (!tail) {
|
if (!tail) {
|
||||||
tail_of_cur_row = NULL;
|
tail_of_cur_row = NULL;
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
*tail_of_cur_row = tail;
|
*tail_of_cur_row = tail;
|
||||||
@ -2776,12 +2776,12 @@ int ft_ln(ft_table_t *table)
|
|||||||
case FT_STRATEGY_INSERT: {
|
case FT_STRATEGY_INSERT: {
|
||||||
f_row_t *new_row = NULL;
|
f_row_t *new_row = NULL;
|
||||||
if (FT_IS_ERROR(split_cur_row(table, &new_row))) {
|
if (FT_IS_ERROR(split_cur_row(table, &new_row))) {
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
if (new_row) {
|
if (new_row) {
|
||||||
if (FT_IS_ERROR(vector_insert(table->rows, &new_row, table->cur_row + 1))) {
|
if (FT_IS_ERROR(vector_insert(table->rows, &new_row, table->cur_row + 1))) {
|
||||||
destroy_row(new_row);
|
destroy_row(new_row);
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -3034,7 +3034,7 @@ static int ft_write_impl_(ft_table_t *table, const f_string_view_t *cell_content
|
|||||||
assert(table);
|
assert(table);
|
||||||
f_string_buffer_t *buf = get_cur_str_buffer_and_create_if_not_exists(table);
|
f_string_buffer_t *buf = get_cur_str_buffer_and_create_if_not_exists(table);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
|
|
||||||
int status = FT_SUCCESS;
|
int status = FT_SUCCESS;
|
||||||
switch (cell_content->type) {
|
switch (cell_content->type) {
|
||||||
@ -3052,7 +3052,7 @@ static int ft_write_impl_(ft_table_t *table, const f_string_view_t *cell_content
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
status = FT_ERROR;
|
status = FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
if (FT_IS_SUCCESS(status)) {
|
if (FT_IS_SUCCESS(status)) {
|
||||||
table->cur_col++;
|
table->cur_col++;
|
||||||
@ -3436,7 +3436,7 @@ int ft_add_separator(ft_table_t *table)
|
|||||||
(*sep_p)->enabled = F_TRUE;
|
(*sep_p)->enabled = F_TRUE;
|
||||||
|
|
||||||
if (*sep_p == NULL)
|
if (*sep_p == NULL)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
return FT_SUCCESS;
|
return FT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3574,7 +3574,7 @@ int ft_set_cell_prop(ft_table_t *table, size_t row, size_t col, uint32_t propert
|
|||||||
if (table->properties->cell_properties == NULL) {
|
if (table->properties->cell_properties == NULL) {
|
||||||
table->properties->cell_properties = create_cell_prop_container();
|
table->properties->cell_properties = create_cell_prop_container();
|
||||||
if (table->properties->cell_properties == NULL) {
|
if (table->properties->cell_properties == NULL) {
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3614,6 +3614,25 @@ void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *pt
|
|||||||
set_memory_funcs(f_malloc, f_free);
|
set_memory_funcs(f_malloc, f_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *ft_strerror(int error_code)
|
||||||
|
{
|
||||||
|
switch (error_code) {
|
||||||
|
case FT_MEMORY_ERROR:
|
||||||
|
return "Out of memory";
|
||||||
|
case FT_GEN_ERROR:
|
||||||
|
return "General error";
|
||||||
|
case FT_EINVAL:
|
||||||
|
return "Invalid argument";
|
||||||
|
case FT_INTERN_ERROR:
|
||||||
|
return "Internal libfort error";
|
||||||
|
default:
|
||||||
|
if (error_code < 0)
|
||||||
|
return "Unknown error code";
|
||||||
|
else
|
||||||
|
return "Success";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
|
int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
|
||||||
{
|
{
|
||||||
assert(table);
|
assert(table);
|
||||||
@ -3627,7 +3646,7 @@ int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
|
|||||||
|
|
||||||
f_row_t *row_p = get_row_and_create_if_not_exists(table, row);
|
f_row_t *row_p = get_row_and_create_if_not_exists(table, row);
|
||||||
if (row_p == NULL)
|
if (row_p == NULL)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
|
|
||||||
return row_set_cell_span(row_p, col, hor_span);
|
return row_set_cell_span(row_p, col, hor_span);
|
||||||
}
|
}
|
||||||
@ -4683,7 +4702,7 @@ f_status set_cell_property(f_cell_prop_container_t *cont, size_t row, size_t col
|
|||||||
{
|
{
|
||||||
f_cell_props_t *opt = get_cell_prop_and_create_if_not_exists(cont, row, col);
|
f_cell_props_t *opt = get_cell_prop_and_create_if_not_exists(cont, row, col);
|
||||||
if (opt == NULL)
|
if (opt == NULL)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
|
|
||||||
return set_cell_property_impl(opt, property, value);
|
return set_cell_property_impl(opt, property, value);
|
||||||
/*
|
/*
|
||||||
@ -5479,7 +5498,7 @@ f_status insert_row(f_row_t *cur_row, f_row_t *ins_row, size_t pos)
|
|||||||
while (vector_size(cur_row->cells) < pos) {
|
while (vector_size(cur_row->cells) < pos) {
|
||||||
f_cell_t *new_cell = create_cell();
|
f_cell_t *new_cell = create_cell();
|
||||||
if (!new_cell)
|
if (!new_cell)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
vector_push(cur_row->cells, &new_cell);
|
vector_push(cur_row->cells, &new_cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5492,7 +5511,7 @@ f_status insert_row(f_row_t *cur_row, f_row_t *ins_row, size_t pos)
|
|||||||
while (i--) {
|
while (i--) {
|
||||||
vector_erase(cur_row->cells, pos);
|
vector_erase(cur_row->cells, pos);
|
||||||
}
|
}
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Clear cells so that it will be safe to destroy this row */
|
/* Clear cells so that it will be safe to destroy this row */
|
||||||
@ -5554,7 +5573,7 @@ f_status row_set_cell_span(f_row_t *row, size_t cell_column, size_t hor_span)
|
|||||||
|
|
||||||
f_cell_t *main_cell = get_cell_and_create_if_not_exists(row, cell_column);
|
f_cell_t *main_cell = get_cell_and_create_if_not_exists(row, cell_column);
|
||||||
if (main_cell == NULL) {
|
if (main_cell == NULL) {
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
set_cell_type(main_cell, GROUP_MASTER_CELL);
|
set_cell_type(main_cell, GROUP_MASTER_CELL);
|
||||||
--hor_span;
|
--hor_span;
|
||||||
@ -5563,7 +5582,7 @@ f_status row_set_cell_span(f_row_t *row, size_t cell_column, size_t hor_span)
|
|||||||
while (hor_span) {
|
while (hor_span) {
|
||||||
f_cell_t *slave_cell = get_cell_and_create_if_not_exists(row, cell_column);
|
f_cell_t *slave_cell = get_cell_and_create_if_not_exists(row, cell_column);
|
||||||
if (slave_cell == NULL) {
|
if (slave_cell == NULL) {
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
set_cell_type(slave_cell, GROUP_SLAVE_CELL);
|
set_cell_type(slave_cell, GROUP_SLAVE_CELL);
|
||||||
--hor_span;
|
--hor_span;
|
||||||
@ -5582,7 +5601,7 @@ int print_row_separator_impl(f_conv_context_t *cntx,
|
|||||||
{
|
{
|
||||||
assert(cntx);
|
assert(cntx);
|
||||||
|
|
||||||
int status = FT_ERROR;
|
int status = FT_GEN_ERROR;
|
||||||
|
|
||||||
const f_context_t *context = cntx->cntx;
|
const f_context_t *context = cntx->cntx;
|
||||||
|
|
||||||
@ -7011,7 +7030,7 @@ f_status table_rows_and_cols_geometry(const ft_table_t *table,
|
|||||||
enum f_geometry_type geom)
|
enum f_geometry_type geom)
|
||||||
{
|
{
|
||||||
if (table == NULL) {
|
if (table == NULL) {
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t max_invis_codepoints = 0;
|
size_t max_invis_codepoints = 0;
|
||||||
@ -7026,7 +7045,7 @@ f_status table_rows_and_cols_geometry(const ft_table_t *table,
|
|||||||
if (col_width_arr == NULL || row_height_arr == NULL) {
|
if (col_width_arr == NULL || row_height_arr == NULL) {
|
||||||
F_FREE(col_width_arr);
|
F_FREE(col_width_arr);
|
||||||
F_FREE(row_height_arr);
|
F_FREE(row_height_arr);
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int combined_cells_found = 0;
|
int combined_cells_found = 0;
|
||||||
@ -7144,7 +7163,7 @@ FT_INTERNAL
|
|||||||
f_status table_geometry(const ft_table_t *table, size_t *height, size_t *width)
|
f_status table_geometry(const ft_table_t *table, size_t *height, size_t *width)
|
||||||
{
|
{
|
||||||
if (table == NULL)
|
if (table == NULL)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
|
|
||||||
*height = 0;
|
*height = 0;
|
||||||
*width = 0;
|
*width = 0;
|
||||||
@ -7283,7 +7302,7 @@ int vector_push(f_vector_t *vector, const void *item)
|
|||||||
|
|
||||||
if (vector->m_size == vector->m_capacity) {
|
if (vector->m_size == vector->m_capacity) {
|
||||||
if (vector_reallocate_(vector, vector->m_capacity * 2) == -1)
|
if (vector_reallocate_(vector, vector->m_capacity * 2) == -1)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
vector->m_capacity = vector->m_capacity * 2;
|
vector->m_capacity = vector->m_capacity * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7303,7 +7322,7 @@ int vector_insert(f_vector_t *vector, const void *item, size_t pos)
|
|||||||
size_t needed_capacity = MAX(pos + 1, vector->m_size + 1);
|
size_t needed_capacity = MAX(pos + 1, vector->m_size + 1);
|
||||||
if (vector->m_capacity < needed_capacity) {
|
if (vector->m_capacity < needed_capacity) {
|
||||||
if (vector_reallocate_(vector, needed_capacity) == -1)
|
if (vector_reallocate_(vector, needed_capacity) == -1)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
vector->m_capacity = needed_capacity;
|
vector->m_capacity = needed_capacity;
|
||||||
}
|
}
|
||||||
size_t offset = pos * vector->m_item_size;
|
size_t offset = pos * vector->m_item_size;
|
||||||
@ -7383,7 +7402,7 @@ f_status vector_swap(f_vector_t *cur_vec, f_vector_t *mv_vec, size_t pos)
|
|||||||
size_t min_targ_size = pos + mv_sz;
|
size_t min_targ_size = pos + mv_sz;
|
||||||
if (vector_capacity(cur_vec) < min_targ_size) {
|
if (vector_capacity(cur_vec) < min_targ_size) {
|
||||||
if (vector_reallocate_(cur_vec, min_targ_size) == -1)
|
if (vector_reallocate_(cur_vec, min_targ_size) == -1)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
cur_vec->m_capacity = min_targ_size;
|
cur_vec->m_capacity = min_targ_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7432,7 +7451,7 @@ int vector_erase(f_vector_t *vector, size_t index)
|
|||||||
assert(vector);
|
assert(vector);
|
||||||
|
|
||||||
if (vector->m_size == 0 || index >= vector->m_size)
|
if (vector->m_size == 0 || index >= vector->m_size)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
|
|
||||||
memmove((char *)vector->m_data + vector->m_item_size * index,
|
memmove((char *)vector->m_data + vector->m_item_size * index,
|
||||||
(char *)vector->m_data + vector->m_item_size * (index + 1),
|
(char *)vector->m_data + vector->m_item_size * (index + 1),
|
||||||
|
46
lib/fort.h
46
lib/fort.h
@ -73,10 +73,40 @@ SOFTWARE.
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* RETURN CODES
|
* RETURN CODES
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operation successfully ended.
|
||||||
|
*/
|
||||||
#define FT_SUCCESS 0
|
#define FT_SUCCESS 0
|
||||||
#define FT_MEMORY_ERROR -1
|
|
||||||
#define FT_ERROR -2
|
/**
|
||||||
#define FT_EINVAL -3
|
* Memory allocation failed.
|
||||||
|
*/
|
||||||
|
#define FT_MEMORY_ERROR -1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalid argument.
|
||||||
|
*/
|
||||||
|
#define FT_EINVAL -2
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Libfort internal logic error.
|
||||||
|
*
|
||||||
|
* Usually such errors mean that something is wrong in
|
||||||
|
* libfort internal logic and in most of cases cause of
|
||||||
|
* these errors is a library bug.
|
||||||
|
*/
|
||||||
|
#define FT_INTERN_ERROR -3
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General error.
|
||||||
|
*
|
||||||
|
* Different errors that do not belong to the group of errors
|
||||||
|
* mentioned above.
|
||||||
|
*/
|
||||||
|
#define FT_GEN_ERROR -4
|
||||||
|
|
||||||
|
|
||||||
#define FT_IS_SUCCESS(arg) ((arg) >= 0)
|
#define FT_IS_SUCCESS(arg) ((arg) >= 0)
|
||||||
#define FT_IS_ERROR(arg) ((arg) < 0)
|
#define FT_IS_ERROR(arg) ((arg) < 0)
|
||||||
|
|
||||||
@ -937,6 +967,16 @@ int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
|
|||||||
void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *ptr));
|
void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *ptr));
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return string describing the `error_code`.
|
||||||
|
*
|
||||||
|
* @param error_code
|
||||||
|
* Error code returned by the library.
|
||||||
|
* @return
|
||||||
|
* String describing the error.
|
||||||
|
*/
|
||||||
|
const char *ft_strerror(int error_code);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef FT_HAVE_WCHAR
|
#ifdef FT_HAVE_WCHAR
|
||||||
|
@ -391,9 +391,8 @@ public:
|
|||||||
: property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, this),
|
: property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, this),
|
||||||
table_(ft_create_table())
|
table_(ft_create_table())
|
||||||
{
|
{
|
||||||
|
|
||||||
if (table_ == NULL)
|
if (table_ == NULL)
|
||||||
throw std::runtime_error("Libfort runtime error");
|
throw std::bad_alloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -413,7 +412,7 @@ public:
|
|||||||
if (tbl.table_) {
|
if (tbl.table_) {
|
||||||
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
||||||
if (table_copy == NULL)
|
if (table_copy == NULL)
|
||||||
throw std::runtime_error("Libfort runtime error");
|
throw std::runtime_error("Error during table copy");
|
||||||
|
|
||||||
stream_.str(std::string());
|
stream_.str(std::string());
|
||||||
if (tbl.stream_.tellp() >= 0) {
|
if (tbl.stream_.tellp() >= 0) {
|
||||||
@ -447,7 +446,7 @@ public:
|
|||||||
if (tbl.table_) {
|
if (tbl.table_) {
|
||||||
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
||||||
if (table_copy == NULL)
|
if (table_copy == NULL)
|
||||||
throw std::runtime_error("Libfort runtime error");
|
throw std::runtime_error("Error during table copy");
|
||||||
|
|
||||||
stream_.str(std::string());
|
stream_.str(std::string());
|
||||||
if (tbl.stream_.tellp() >= 0) {
|
if (tbl.stream_.tellp() >= 0) {
|
||||||
@ -491,7 +490,7 @@ public:
|
|||||||
{
|
{
|
||||||
const char *str = c_str();
|
const char *str = c_str();
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
throw std::runtime_error("Libfort runtime error");
|
throw std::runtime_error("Error during table to string conversion");
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ f_status fill_cell_from_buffer(f_cell_t *cell, const f_string_buffer_t *buffer)
|
|||||||
#endif /* FT_HAVE_UTF8 */
|
#endif /* FT_HAVE_UTF8 */
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
46
src/fort.h
46
src/fort.h
@ -73,10 +73,40 @@ SOFTWARE.
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* RETURN CODES
|
* RETURN CODES
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operation successfully ended.
|
||||||
|
*/
|
||||||
#define FT_SUCCESS 0
|
#define FT_SUCCESS 0
|
||||||
#define FT_MEMORY_ERROR -1
|
|
||||||
#define FT_ERROR -2
|
/**
|
||||||
#define FT_EINVAL -3
|
* Memory allocation failed.
|
||||||
|
*/
|
||||||
|
#define FT_MEMORY_ERROR -1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalid argument.
|
||||||
|
*/
|
||||||
|
#define FT_EINVAL -2
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Libfort internal logic error.
|
||||||
|
*
|
||||||
|
* Usually such errors mean that something is wrong in
|
||||||
|
* libfort internal logic and in most of cases cause of
|
||||||
|
* these errors is a library bug.
|
||||||
|
*/
|
||||||
|
#define FT_INTERN_ERROR -3
|
||||||
|
|
||||||
|
/**
|
||||||
|
* General error.
|
||||||
|
*
|
||||||
|
* Different errors that do not belong to the group of errors
|
||||||
|
* mentioned above.
|
||||||
|
*/
|
||||||
|
#define FT_GEN_ERROR -4
|
||||||
|
|
||||||
|
|
||||||
#define FT_IS_SUCCESS(arg) ((arg) >= 0)
|
#define FT_IS_SUCCESS(arg) ((arg) >= 0)
|
||||||
#define FT_IS_ERROR(arg) ((arg) < 0)
|
#define FT_IS_ERROR(arg) ((arg) < 0)
|
||||||
|
|
||||||
@ -937,6 +967,16 @@ int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
|
|||||||
void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *ptr));
|
void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *ptr));
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return string describing the `error_code`.
|
||||||
|
*
|
||||||
|
* @param error_code
|
||||||
|
* Error code returned by the library.
|
||||||
|
* @return
|
||||||
|
* String describing the error.
|
||||||
|
*/
|
||||||
|
const char *ft_strerror(int error_code);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef FT_HAVE_WCHAR
|
#ifdef FT_HAVE_WCHAR
|
||||||
|
@ -391,9 +391,8 @@ public:
|
|||||||
: property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, this),
|
: property_owner_t(FT_ANY_ROW, FT_ANY_COLUMN, this),
|
||||||
table_(ft_create_table())
|
table_(ft_create_table())
|
||||||
{
|
{
|
||||||
|
|
||||||
if (table_ == NULL)
|
if (table_ == NULL)
|
||||||
throw std::runtime_error("Libfort runtime error");
|
throw std::bad_alloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -413,7 +412,7 @@ public:
|
|||||||
if (tbl.table_) {
|
if (tbl.table_) {
|
||||||
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
||||||
if (table_copy == NULL)
|
if (table_copy == NULL)
|
||||||
throw std::runtime_error("Libfort runtime error");
|
throw std::runtime_error("Error during table copy");
|
||||||
|
|
||||||
stream_.str(std::string());
|
stream_.str(std::string());
|
||||||
if (tbl.stream_.tellp() >= 0) {
|
if (tbl.stream_.tellp() >= 0) {
|
||||||
@ -447,7 +446,7 @@ public:
|
|||||||
if (tbl.table_) {
|
if (tbl.table_) {
|
||||||
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
ft_table_t *table_copy = ft_copy_table(tbl.table_);
|
||||||
if (table_copy == NULL)
|
if (table_copy == NULL)
|
||||||
throw std::runtime_error("Libfort runtime error");
|
throw std::runtime_error("Error during table copy");
|
||||||
|
|
||||||
stream_.str(std::string());
|
stream_.str(std::string());
|
||||||
if (tbl.stream_.tellp() >= 0) {
|
if (tbl.stream_.tellp() >= 0) {
|
||||||
@ -491,7 +490,7 @@ public:
|
|||||||
{
|
{
|
||||||
const char *str = c_str();
|
const char *str = c_str();
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
throw std::runtime_error("Libfort runtime error");
|
throw std::runtime_error("Error during table to string conversion");
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ static int split_cur_row(ft_table_t *table, f_row_t **tail_of_cur_row)
|
|||||||
f_row_t *tail = split_row(row, table->cur_col);
|
f_row_t *tail = split_row(row, table->cur_col);
|
||||||
if (!tail) {
|
if (!tail) {
|
||||||
tail_of_cur_row = NULL;
|
tail_of_cur_row = NULL;
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
*tail_of_cur_row = tail;
|
*tail_of_cur_row = tail;
|
||||||
@ -180,12 +180,12 @@ int ft_ln(ft_table_t *table)
|
|||||||
case FT_STRATEGY_INSERT: {
|
case FT_STRATEGY_INSERT: {
|
||||||
f_row_t *new_row = NULL;
|
f_row_t *new_row = NULL;
|
||||||
if (FT_IS_ERROR(split_cur_row(table, &new_row))) {
|
if (FT_IS_ERROR(split_cur_row(table, &new_row))) {
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
if (new_row) {
|
if (new_row) {
|
||||||
if (FT_IS_ERROR(vector_insert(table->rows, &new_row, table->cur_row + 1))) {
|
if (FT_IS_ERROR(vector_insert(table->rows, &new_row, table->cur_row + 1))) {
|
||||||
destroy_row(new_row);
|
destroy_row(new_row);
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -438,7 +438,7 @@ static int ft_write_impl_(ft_table_t *table, const f_string_view_t *cell_content
|
|||||||
assert(table);
|
assert(table);
|
||||||
f_string_buffer_t *buf = get_cur_str_buffer_and_create_if_not_exists(table);
|
f_string_buffer_t *buf = get_cur_str_buffer_and_create_if_not_exists(table);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
|
|
||||||
int status = FT_SUCCESS;
|
int status = FT_SUCCESS;
|
||||||
switch (cell_content->type) {
|
switch (cell_content->type) {
|
||||||
@ -456,7 +456,7 @@ static int ft_write_impl_(ft_table_t *table, const f_string_view_t *cell_content
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
status = FT_ERROR;
|
status = FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
if (FT_IS_SUCCESS(status)) {
|
if (FT_IS_SUCCESS(status)) {
|
||||||
table->cur_col++;
|
table->cur_col++;
|
||||||
@ -840,7 +840,7 @@ int ft_add_separator(ft_table_t *table)
|
|||||||
(*sep_p)->enabled = F_TRUE;
|
(*sep_p)->enabled = F_TRUE;
|
||||||
|
|
||||||
if (*sep_p == NULL)
|
if (*sep_p == NULL)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
return FT_SUCCESS;
|
return FT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -978,7 +978,7 @@ int ft_set_cell_prop(ft_table_t *table, size_t row, size_t col, uint32_t propert
|
|||||||
if (table->properties->cell_properties == NULL) {
|
if (table->properties->cell_properties == NULL) {
|
||||||
table->properties->cell_properties = create_cell_prop_container();
|
table->properties->cell_properties = create_cell_prop_container();
|
||||||
if (table->properties->cell_properties == NULL) {
|
if (table->properties->cell_properties == NULL) {
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1018,6 +1018,25 @@ void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *pt
|
|||||||
set_memory_funcs(f_malloc, f_free);
|
set_memory_funcs(f_malloc, f_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *ft_strerror(int error_code)
|
||||||
|
{
|
||||||
|
switch (error_code) {
|
||||||
|
case FT_MEMORY_ERROR:
|
||||||
|
return "Out of memory";
|
||||||
|
case FT_GEN_ERROR:
|
||||||
|
return "General error";
|
||||||
|
case FT_EINVAL:
|
||||||
|
return "Invalid argument";
|
||||||
|
case FT_INTERN_ERROR:
|
||||||
|
return "Internal libfort error";
|
||||||
|
default:
|
||||||
|
if (error_code < 0)
|
||||||
|
return "Unknown error code";
|
||||||
|
else
|
||||||
|
return "Success";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
|
int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
|
||||||
{
|
{
|
||||||
assert(table);
|
assert(table);
|
||||||
@ -1031,7 +1050,7 @@ int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span)
|
|||||||
|
|
||||||
f_row_t *row_p = get_row_and_create_if_not_exists(table, row);
|
f_row_t *row_p = get_row_and_create_if_not_exists(table, row);
|
||||||
if (row_p == NULL)
|
if (row_p == NULL)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
|
|
||||||
return row_set_cell_span(row_p, col, hor_span);
|
return row_set_cell_span(row_p, col, hor_span);
|
||||||
}
|
}
|
||||||
|
@ -462,7 +462,7 @@ f_status set_cell_property(f_cell_prop_container_t *cont, size_t row, size_t col
|
|||||||
{
|
{
|
||||||
f_cell_props_t *opt = get_cell_prop_and_create_if_not_exists(cont, row, col);
|
f_cell_props_t *opt = get_cell_prop_and_create_if_not_exists(cont, row, col);
|
||||||
if (opt == NULL)
|
if (opt == NULL)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
|
|
||||||
return set_cell_property_impl(opt, property, value);
|
return set_cell_property_impl(opt, property, value);
|
||||||
/*
|
/*
|
||||||
|
10
src/row.c
10
src/row.c
@ -226,7 +226,7 @@ f_status insert_row(f_row_t *cur_row, f_row_t *ins_row, size_t pos)
|
|||||||
while (vector_size(cur_row->cells) < pos) {
|
while (vector_size(cur_row->cells) < pos) {
|
||||||
f_cell_t *new_cell = create_cell();
|
f_cell_t *new_cell = create_cell();
|
||||||
if (!new_cell)
|
if (!new_cell)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
vector_push(cur_row->cells, &new_cell);
|
vector_push(cur_row->cells, &new_cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ f_status insert_row(f_row_t *cur_row, f_row_t *ins_row, size_t pos)
|
|||||||
while (i--) {
|
while (i--) {
|
||||||
vector_erase(cur_row->cells, pos);
|
vector_erase(cur_row->cells, pos);
|
||||||
}
|
}
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Clear cells so that it will be safe to destroy this row */
|
/* Clear cells so that it will be safe to destroy this row */
|
||||||
@ -301,7 +301,7 @@ f_status row_set_cell_span(f_row_t *row, size_t cell_column, size_t hor_span)
|
|||||||
|
|
||||||
f_cell_t *main_cell = get_cell_and_create_if_not_exists(row, cell_column);
|
f_cell_t *main_cell = get_cell_and_create_if_not_exists(row, cell_column);
|
||||||
if (main_cell == NULL) {
|
if (main_cell == NULL) {
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
set_cell_type(main_cell, GROUP_MASTER_CELL);
|
set_cell_type(main_cell, GROUP_MASTER_CELL);
|
||||||
--hor_span;
|
--hor_span;
|
||||||
@ -310,7 +310,7 @@ f_status row_set_cell_span(f_row_t *row, size_t cell_column, size_t hor_span)
|
|||||||
while (hor_span) {
|
while (hor_span) {
|
||||||
f_cell_t *slave_cell = get_cell_and_create_if_not_exists(row, cell_column);
|
f_cell_t *slave_cell = get_cell_and_create_if_not_exists(row, cell_column);
|
||||||
if (slave_cell == NULL) {
|
if (slave_cell == NULL) {
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
set_cell_type(slave_cell, GROUP_SLAVE_CELL);
|
set_cell_type(slave_cell, GROUP_SLAVE_CELL);
|
||||||
--hor_span;
|
--hor_span;
|
||||||
@ -329,7 +329,7 @@ int print_row_separator_impl(f_conv_context_t *cntx,
|
|||||||
{
|
{
|
||||||
assert(cntx);
|
assert(cntx);
|
||||||
|
|
||||||
int status = FT_ERROR;
|
int status = FT_GEN_ERROR;
|
||||||
|
|
||||||
const f_context_t *context = cntx->cntx;
|
const f_context_t *context = cntx->cntx;
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ f_status table_rows_and_cols_geometry(const ft_table_t *table,
|
|||||||
enum f_geometry_type geom)
|
enum f_geometry_type geom)
|
||||||
{
|
{
|
||||||
if (table == NULL) {
|
if (table == NULL) {
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t max_invis_codepoints = 0;
|
size_t max_invis_codepoints = 0;
|
||||||
@ -155,7 +155,7 @@ f_status table_rows_and_cols_geometry(const ft_table_t *table,
|
|||||||
if (col_width_arr == NULL || row_height_arr == NULL) {
|
if (col_width_arr == NULL || row_height_arr == NULL) {
|
||||||
F_FREE(col_width_arr);
|
F_FREE(col_width_arr);
|
||||||
F_FREE(row_height_arr);
|
F_FREE(row_height_arr);
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int combined_cells_found = 0;
|
int combined_cells_found = 0;
|
||||||
@ -273,7 +273,7 @@ FT_INTERNAL
|
|||||||
f_status table_geometry(const ft_table_t *table, size_t *height, size_t *width)
|
f_status table_geometry(const ft_table_t *table, size_t *height, size_t *width)
|
||||||
{
|
{
|
||||||
if (table == NULL)
|
if (table == NULL)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
|
|
||||||
*height = 0;
|
*height = 0;
|
||||||
*width = 0;
|
*width = 0;
|
||||||
|
@ -79,7 +79,7 @@ int vector_push(f_vector_t *vector, const void *item)
|
|||||||
|
|
||||||
if (vector->m_size == vector->m_capacity) {
|
if (vector->m_size == vector->m_capacity) {
|
||||||
if (vector_reallocate_(vector, vector->m_capacity * 2) == -1)
|
if (vector_reallocate_(vector, vector->m_capacity * 2) == -1)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
vector->m_capacity = vector->m_capacity * 2;
|
vector->m_capacity = vector->m_capacity * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ int vector_insert(f_vector_t *vector, const void *item, size_t pos)
|
|||||||
size_t needed_capacity = MAX(pos + 1, vector->m_size + 1);
|
size_t needed_capacity = MAX(pos + 1, vector->m_size + 1);
|
||||||
if (vector->m_capacity < needed_capacity) {
|
if (vector->m_capacity < needed_capacity) {
|
||||||
if (vector_reallocate_(vector, needed_capacity) == -1)
|
if (vector_reallocate_(vector, needed_capacity) == -1)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
vector->m_capacity = needed_capacity;
|
vector->m_capacity = needed_capacity;
|
||||||
}
|
}
|
||||||
size_t offset = pos * vector->m_item_size;
|
size_t offset = pos * vector->m_item_size;
|
||||||
@ -179,7 +179,7 @@ f_status vector_swap(f_vector_t *cur_vec, f_vector_t *mv_vec, size_t pos)
|
|||||||
size_t min_targ_size = pos + mv_sz;
|
size_t min_targ_size = pos + mv_sz;
|
||||||
if (vector_capacity(cur_vec) < min_targ_size) {
|
if (vector_capacity(cur_vec) < min_targ_size) {
|
||||||
if (vector_reallocate_(cur_vec, min_targ_size) == -1)
|
if (vector_reallocate_(cur_vec, min_targ_size) == -1)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
cur_vec->m_capacity = min_targ_size;
|
cur_vec->m_capacity = min_targ_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ int vector_erase(f_vector_t *vector, size_t index)
|
|||||||
assert(vector);
|
assert(vector);
|
||||||
|
|
||||||
if (vector->m_size == 0 || index >= vector->m_size)
|
if (vector->m_size == 0 || index >= vector->m_size)
|
||||||
return FT_ERROR;
|
return FT_GEN_ERROR;
|
||||||
|
|
||||||
memmove((char *)vector->m_data + vector->m_item_size * index,
|
memmove((char *)vector->m_data + vector->m_item_size * index,
|
||||||
(char *)vector->m_data + vector->m_item_size * (index + 1),
|
(char *)vector->m_data + vector->m_item_size * (index + 1),
|
||||||
|
@ -12,6 +12,7 @@ add_executable(${PROJECT_NAME}_test_dev
|
|||||||
bb_tests/test_table_border_style.c
|
bb_tests/test_table_border_style.c
|
||||||
bb_tests/test_table_properties.c
|
bb_tests/test_table_properties.c
|
||||||
bb_tests/test_memory_errors.c
|
bb_tests/test_memory_errors.c
|
||||||
|
bb_tests/test_error_codes.c
|
||||||
tests.c
|
tests.c
|
||||||
test_utils.c)
|
test_utils.c)
|
||||||
target_link_libraries(${PROJECT_NAME}_test_dev
|
target_link_libraries(${PROJECT_NAME}_test_dev
|
||||||
@ -30,6 +31,7 @@ add_executable(${PROJECT_NAME}_test
|
|||||||
bb_tests/test_table_border_style.c
|
bb_tests/test_table_border_style.c
|
||||||
bb_tests/test_table_properties.c
|
bb_tests/test_table_properties.c
|
||||||
bb_tests/test_memory_errors.c
|
bb_tests/test_memory_errors.c
|
||||||
|
bb_tests/test_error_codes.c
|
||||||
tests.c
|
tests.c
|
||||||
test_utils.c)
|
test_utils.c)
|
||||||
target_link_libraries(${PROJECT_NAME}_test
|
target_link_libraries(${PROJECT_NAME}_test
|
||||||
|
28
tests/bb_tests/test_error_codes.c
Normal file
28
tests/bb_tests/test_error_codes.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "tests.h"
|
||||||
|
#include "fort.h"
|
||||||
|
|
||||||
|
|
||||||
|
void test_error_codes(void)
|
||||||
|
{
|
||||||
|
// Nonnegative code is success
|
||||||
|
{
|
||||||
|
assert_str_equal(ft_strerror(FT_SUCCESS), "Success");
|
||||||
|
assert_str_equal(ft_strerror(0), "Success");
|
||||||
|
assert_str_equal(ft_strerror(1), "Success");
|
||||||
|
assert_str_equal(ft_strerror(2), "Success");
|
||||||
|
assert_str_equal(ft_strerror(42), "Success");
|
||||||
|
assert_str_equal(ft_strerror(INT_MAX), "Success");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error codes
|
||||||
|
{
|
||||||
|
assert_str_equal(ft_strerror(FT_MEMORY_ERROR), "Out of memory");
|
||||||
|
assert_str_equal(ft_strerror(FT_EINVAL), "Invalid argument");
|
||||||
|
assert_str_equal(ft_strerror(FT_INTERN_ERROR), "Internal libfort error");
|
||||||
|
assert_str_equal(ft_strerror(FT_GEN_ERROR), "General error");
|
||||||
|
|
||||||
|
assert_str_equal(ft_strerror(-42), "Unknown error code");
|
||||||
|
assert_str_equal(ft_strerror(-666), "Unknown error code");
|
||||||
|
assert_str_equal(ft_strerror(-INT_MAX), "Unknown error code");
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,7 @@ void test_table_cell_properties(void);
|
|||||||
void test_table_text_styles(void);
|
void test_table_text_styles(void);
|
||||||
void test_table_tbl_properties(void);
|
void test_table_tbl_properties(void);
|
||||||
void test_memory_errors(void);
|
void test_memory_errors(void);
|
||||||
|
void test_error_codes(void);
|
||||||
#ifdef FT_HAVE_UTF8
|
#ifdef FT_HAVE_UTF8
|
||||||
void test_utf8_table(void);
|
void test_utf8_table(void);
|
||||||
#endif
|
#endif
|
||||||
@ -60,6 +61,7 @@ struct test_case bb_test_suite [] = {
|
|||||||
{"test_table_tbl_properties", test_table_tbl_properties},
|
{"test_table_tbl_properties", test_table_tbl_properties},
|
||||||
{"test_table_text_styles", test_table_text_styles},
|
{"test_table_text_styles", test_table_text_styles},
|
||||||
{"test_memory_errors", test_memory_errors},
|
{"test_memory_errors", test_memory_errors},
|
||||||
|
{"test_error_codes", test_error_codes},
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef FORT_WB_TESTING_ENABLED
|
#ifdef FORT_WB_TESTING_ENABLED
|
||||||
|
Loading…
Reference in New Issue
Block a user