[C] Preparations for doxygen

This commit is contained in:
seleznevae 2018-05-05 18:38:45 +03:00
parent 25992d0f9d
commit d010dc9cf8
10 changed files with 262 additions and 212 deletions

View File

@ -24,6 +24,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* @file fort.h
* @brief Main header file describing libfort API.
*
* This files contains declarations of all libfort functions and macro
* definitions.
*/
#ifndef LIBFORT_H
#define LIBFORT_H
@ -41,75 +49,8 @@ SOFTWARE.
*/
/** #define FT_CONGIG_HAVE_WCHAR */
/*****************************************************************************
* Determine compiler
*****************************************************************************/
#if defined(__clang__)
#define FT_CLANG_COMPILER
#elif defined(__GNUC__)
#define FT_GCC_COMPILER
#elif defined(_MSC_VER)
#define FT_MICROSOFT_COMPILER
#else
#define FT_UNDEFINED_COMPILER
#endif
/*****************************************************************************
* Declare restrict
*****************************************************************************/
/*
#if defined(__cplusplus)
#if defined(FT_CLANG_COMPILER)
#define FT_RESTRICT __restrict__
#else
#define FT_RESTRICT __restrict
#endif // if defined(FT_CLANG_COMPILER)
#else
#if __STDC_VERSION__ < 199901L
#define FT_RESTRICT
#else
#define FT_RESTRICT restrict
#endif // __STDC_VERSION__ < 199901L
#endif // if defined(__cplusplus)
*/
/*****************************************************************************
* Declare inline
*****************************************************************************/
#if defined(__cplusplus)
#define FT_INLINE inline
#else
#define FT_INLINE __inline
#endif /* if defined(__cplusplus) */
/*****************************************************************************
* Attribute format for argument checking
*****************************************************************************/
#if defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER)
#define FT_PRINTF_ATTRIBUTE_FORMAT(string_index, first_to_check) \
__attribute__ ((format (printf, string_index, first_to_check)))
#else
#define FT_PRINTF_ATTRIBUTE_FORMAT(string_index, first_to_check)
#endif /* defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER) */
/*****************************************************************************
* C++ needs to know that types and declarations are C, not C++.
*****************************************************************************/
#ifdef __cplusplus
# define FT_BEGIN_DECLS extern "C" {
# define FT_END_DECLS }
#else
# define FT_BEGIN_DECLS
# define FT_END_DECLS
#endif
#ifndef FT_EXTERN
#define FT_EXTERN extern
#if defined(FT_CONGIG_HAVE_WCHAR)
#define FT_HAVE_WCHAR
#endif
@ -121,15 +62,52 @@ typedef int fort_status_t;
#define FT_MEMORY_ERROR -1
#define FT_ERROR -2
#define FT_EINVAL -3
#define IS_SUCCESS(arg) ((arg) >= 0)
#define IS_ERROR(arg) ((arg) < 0)
#define FT_IS_SUCCESS(arg) ((arg) >= 0)
#define FT_IS_ERROR(arg) ((arg) < 0)
/**
* @cond HELPER_MACROS
*/
/*****************************************************************************
* Wchar support
* Determine compiler
*****************************************************************************/
#if defined(FT_CONGIG_HAVE_WCHAR)
#define FT_HAVE_WCHAR
#if defined(__clang__)
#define FT_CLANG_COMPILER
#elif defined(__GNUC__)
#define FT_GCC_COMPILER
#elif defined(_MSC_VER)
#define FT_MICROSOFT_COMPILER
#else
#define FT_UNDEFINED_COMPILER
#endif
/*****************************************************************************
* Declare inline
*****************************************************************************/
#if defined(__cplusplus)
#define FT_INLINE inline
#else
#define FT_INLINE __inline
#endif /* if defined(__cplusplus) */
/*****************************************************************************
* C++ needs to know that types and declarations are C, not C++.
*****************************************************************************/
#ifdef __cplusplus
# define FT_BEGIN_DECLS extern "C" {
# define FT_END_DECLS }
#else
# define FT_BEGIN_DECLS
# define FT_END_DECLS
#endif
@ -204,12 +182,27 @@ static FT_INLINE int ft_check_if_wstring_helper(const wchar_t *str)
CHECK_IF_ARGS_ARE_STRINGS_(ft_check_if_wstring_helper,CHECK_IF_STRING_,PP_NARG(__VA_ARGS__), __VA_ARGS__)
#endif
/**
* @endcond
*/
/*****************************************************************************
* Attribute format for argument checking
*****************************************************************************/
#if defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER)
#define FT_PRINTF_ATTRIBUTE_FORMAT(string_index, first_to_check) \
__attribute__ ((format (printf, string_index, first_to_check)))
#else
#define FT_PRINTF_ATTRIBUTE_FORMAT(string_index, first_to_check)
#endif /* defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER) */
/*****************************************************************************
* libfort API
*****************************************************************************/
FT_BEGIN_DECLS
struct fort_table;
@ -221,7 +214,7 @@ typedef struct fort_table FTABLE;
* @return
* The pointer to the new allocated FTABLE, on success. NULL on error.
*/
FT_EXTERN FTABLE *ft_create_table(void);
FTABLE *ft_create_table(void);
/**
* Destroy formatted table.
@ -233,7 +226,7 @@ FT_EXTERN FTABLE *ft_create_table(void);
* Pointer to formatted table previousley created with ft_create_table. If
* table is a null pointer, the function does nothing.
*/
FT_EXTERN void ft_destroy_table(FTABLE *table);
void ft_destroy_table(FTABLE *table);
/**
* Move current position to the first cell of the next line(row).
@ -241,7 +234,7 @@ FT_EXTERN void ft_destroy_table(FTABLE *table);
* @param table
* Pointer to formatted table.
*/
FT_EXTERN void ft_ln(FTABLE *table);
void ft_ln(FTABLE *table);
/**
* Get row number of the current cell.
@ -251,7 +244,7 @@ FT_EXTERN void ft_ln(FTABLE *table);
* @return
* Row number of the current cell.
*/
FT_EXTERN size_t ft_cur_row(FTABLE *table);
size_t ft_cur_row(FTABLE *table);
/**
* Get column number of the current cell.
@ -261,7 +254,7 @@ FT_EXTERN size_t ft_cur_row(FTABLE *table);
* @return
* Column number of the current cell.
*/
FT_EXTERN size_t ft_cur_col(FTABLE *table);
size_t ft_cur_col(FTABLE *table);
/**
* Set current cell position.
@ -276,7 +269,7 @@ FT_EXTERN size_t ft_cur_col(FTABLE *table);
* @param col
* New row number for the current cell.
*/
FT_EXTERN void ft_set_cur_cell(FTABLE *table, size_t row, size_t col);
void ft_set_cur_cell(FTABLE *table, size_t row, size_t col);
@ -306,7 +299,7 @@ FT_EXTERN void ft_set_cur_cell(FTABLE *table, size_t row, size_t col);
* - Number of printed cells
* - (<0): In case of error
*/
FT_EXTERN int ft_printf(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
int ft_printf(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
/**
* Writes data formatted acording to the format string to a variety of table
@ -332,12 +325,12 @@ FT_EXTERN int ft_printf(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE
* - Number of printed cells.
* - (<0): In case of error.
*/
FT_EXTERN int ft_printf_ln(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
int ft_printf_ln(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
#else
FT_EXTERN int ft_printf_impl(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
FT_EXTERN int ft_printf_ln_impl(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
int ft_printf_impl(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
int ft_printf_ln_impl(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
#define ft_printf(table, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf_impl(table, __VA_ARGS__))
@ -351,19 +344,19 @@ FT_EXTERN int ft_printf_ln_impl(FTABLE *table, const char *fmt, ...) FT_PRINTF_A
(0 ? CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite(table, PP_NARG(__VA_ARGS__), __VA_ARGS__))
#define ft_write_ln(table, ...)\
(0 ? CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite_ln(table, PP_NARG(__VA_ARGS__), __VA_ARGS__))
FT_EXTERN int ft_nwrite(FTABLE *table, size_t n, const char *cell_content, ...);
FT_EXTERN int ft_nwrite_ln(FTABLE *table, size_t n, const char *cell_content, ...);
int ft_nwrite(FTABLE *table, size_t n, const char *cell_content, ...);
int ft_nwrite_ln(FTABLE *table, size_t n, const char *cell_content, ...);
FT_EXTERN int ft_row_write(FTABLE *table, size_t cols, const char *row_cells[]);
FT_EXTERN int ft_row_write_ln(FTABLE *table, size_t cols, const char *row_cells[]);
int ft_row_write(FTABLE *table, size_t cols, const char *row_cells[]);
int ft_row_write_ln(FTABLE *table, size_t cols, const char *row_cells[]);
FT_EXTERN int ft_table_write(FTABLE *table, size_t rows, size_t cols, const char *table_cells[]);
FT_EXTERN int ft_table_write_ln(FTABLE *table, size_t rows, size_t cols, const char *table_cells[]);
int ft_table_write(FTABLE *table, size_t rows, size_t cols, const char *table_cells[]);
int ft_table_write_ln(FTABLE *table, size_t rows, size_t cols, const char *table_cells[]);
@ -378,7 +371,7 @@ FT_EXTERN int ft_table_write_ln(FTABLE *table, size_t rows, size_t cols, const c
* - 0: Success; separator was added.
* - (<0): In case of error
*/
FT_EXTERN int ft_add_separator(FTABLE *table);
int ft_add_separator(FTABLE *table);
@ -400,7 +393,7 @@ FT_EXTERN int ft_add_separator(FTABLE *table);
* The pointer to the string representation of formatted table, on success.
* NULL on error with ft_errno set appropriately.
*/
FT_EXTERN const char *ft_to_string(const FTABLE *table);
const char *ft_to_string(const FTABLE *table);
@ -436,7 +429,9 @@ struct ft_border_style {
};
/**
* Built-in table border styles.
* @defgroup BasicStyles
* @name Built-in table border styles.
* @{
*/
extern struct ft_border_style *FT_BASIC_STYLE;
extern struct ft_border_style *FT_SIMPLE_STYLE;
@ -450,6 +445,9 @@ extern struct ft_border_style *FT_DOUBLE2_STYLE;
extern struct ft_border_style *FT_BOLD_STYLE;
extern struct ft_border_style *FT_BOLD2_STYLE;
extern struct ft_border_style *FT_FRAME_STYLE;
/** @} */
/**
* Set default border style for all new formatted tables.
@ -460,7 +458,7 @@ extern struct ft_border_style *FT_FRAME_STYLE;
* - 0: Success; default border style was changed.
* - (<0): In case of error
*/
FT_EXTERN int ft_set_default_border_style(struct ft_border_style *style);
int ft_set_default_border_style(struct ft_border_style *style);
/**
* Set border style for the table.
@ -473,18 +471,25 @@ FT_EXTERN int ft_set_default_border_style(struct ft_border_style *style);
* - 0: Success; table border style was changed.
* - (<0): In case of error
*/
FT_EXTERN int ft_set_border_style(FTABLE *table, struct ft_border_style *style);
int ft_set_border_style(FTABLE *table, struct ft_border_style *style);
/**
* Special macros to define cell position (row and column).
* @name Special macros to define cell position (row and column).
* @{
*/
#define FT_ANY_COLUMN (UINT_MAX)
#define FT_CUR_COLUMN (UINT_MAX - 1)
#define FT_ANY_ROW (UINT_MAX)
#define FT_CUR_ROW (UINT_MAX - 1)
#define FT_ANY_COLUMN (UINT_MAX) /**< Any column (can be used to refer to all cells in a row)*/
#define FT_CUR_COLUMN (UINT_MAX - 1) /**< Current column */
#define FT_ANY_ROW (UINT_MAX) /**< Any row (can be used to refer to all cells in a column)*/
#define FT_CUR_ROW (UINT_MAX - 1) /**< Current row */
/** @} */
/**
* Cell options identifiers.
* @name Cell options identifiers.
* @{
*/
#define FT_COPT_MIN_WIDTH (0x01U << 0) /**< Minimum width */
#define FT_COPT_TEXT_ALIGN (0x01U << 1) /**< Text alignmemnt */
@ -494,22 +499,25 @@ FT_EXTERN int ft_set_border_style(FTABLE *table, struct ft_border_style *style);
#define FT_COPT_RIGHT_PADDING (0x01U << 5) /**< Right padding for cell content */
#define FT_COPT_EMPTY_STR_HEIGHT (0x01U << 6) /**< Height of empty cell */
#define FT_COPT_ROW_TYPE (0x01U << 7) /**< Row type */
/** @} */
/**
* Alignment of cell content.
*/
enum ft_text_alignment {
FT_ALIGNED_LEFT,
FT_ALIGNED_CENTER,
FT_ALIGNED_RIGHT
FT_ALIGNED_LEFT = 0, /**< Align left */
FT_ALIGNED_CENTER, /**< Align center */
FT_ALIGNED_RIGHT /**< Align right */
};
/**
* Type of table row.
* Type of table row. Determines appearance of row.
*/
enum ft_row_type {
FT_ROW_COMMON,
FT_ROW_HEADER
FT_ROW_COMMON = 0, /**< Common row */
FT_ROW_HEADER /**< Header row */
};
/**
@ -523,7 +531,7 @@ enum ft_row_type {
* - 0: Success; default cell option was changed.
* - (<0): In case of error
*/
FT_EXTERN int ft_set_default_cell_option(uint32_t option, int value);
int ft_set_default_cell_option(uint32_t option, int value);
/**
* Set option for the specified cell of the table.
@ -542,15 +550,20 @@ FT_EXTERN int ft_set_default_cell_option(uint32_t option, int value);
* - 0: Success; cell option was changed.
* - (<0): In case of error
*/
FT_EXTERN int ft_set_cell_option(FTABLE *table, size_t row, size_t col, uint32_t option, int value);
int ft_set_cell_option(FTABLE *table, size_t row, size_t col, uint32_t option, int value);
/**
* Table options identifiers.
* @name Table options identifiers.
* @{
*/
#define FT_TOPT_LEFT_MARGIN (0x01U << 0)
#define FT_TOPT_TOP_MARGIN (0x01U << 1)
#define FT_TOPT_RIGHT_MARGIN (0x01U << 2)
#define FT_TOPT_BOTTOM_MARGIN (0x01U << 3)
/** @} */
/**
* Set default table option.
@ -563,7 +576,7 @@ FT_EXTERN int ft_set_cell_option(FTABLE *table, size_t row, size_t col, uint32_t
* - 0: Success; default table option was changed.
* - (<0): In case of error
*/
FT_EXTERN int ft_set_default_tbl_option(uint32_t option, int value);
int ft_set_default_tbl_option(uint32_t option, int value);
/**
* Set table option.
@ -578,7 +591,7 @@ FT_EXTERN int ft_set_default_tbl_option(uint32_t option, int value);
* - 0: Success; default table option was changed.
* - (<0): In case of error
*/
FT_EXTERN int ft_set_tbl_option(FTABLE *table, uint32_t option, int value);
int ft_set_tbl_option(FTABLE *table, uint32_t option, int value);
/**
@ -596,7 +609,7 @@ FT_EXTERN int ft_set_tbl_option(FTABLE *table, uint32_t option, int value);
* - 0: Success; default table option was changed.
* - (<0): In case of error
*/
FT_EXTERN int ft_set_cell_span(FTABLE *table, size_t row, size_t col, size_t hor_span);
int ft_set_cell_span(FTABLE *table, size_t row, size_t col, size_t hor_span);
/**
@ -613,7 +626,7 @@ FT_EXTERN int ft_set_cell_span(FTABLE *table, size_t row, size_t col, size_t hor
* To return memory allocation/deallocation functions to their standard values
* set f_malloc and f_free to NULL.
*/
FT_EXTERN 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));
@ -621,24 +634,24 @@ FT_EXTERN void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free
#ifdef FT_HAVE_WCHAR
FT_EXTERN int ft_wprintf(FTABLE *table, const wchar_t *fmt, ...);
FT_EXTERN int ft_wprintf_ln(FTABLE *table, const wchar_t *fmt, ...);
int ft_wprintf(FTABLE *table, const wchar_t *fmt, ...);
int ft_wprintf_ln(FTABLE *table, const wchar_t *fmt, ...);
#define ft_wwrite(table, ...)\
(0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite(table, PP_NARG(__VA_ARGS__), __VA_ARGS__))
#define ft_wwrite_ln(table, ...)\
(0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite_ln(table, PP_NARG(__VA_ARGS__), __VA_ARGS__))
FT_EXTERN int ft_nwwrite(FTABLE *table, size_t n, const wchar_t *cell_content, ...);
FT_EXTERN int ft_nwwrite_ln(FTABLE *table, size_t n, const wchar_t *cell_content, ...);
int ft_nwwrite(FTABLE *table, size_t n, const wchar_t *cell_content, ...);
int ft_nwwrite_ln(FTABLE *table, size_t n, const wchar_t *cell_content, ...);
FT_EXTERN int ft_row_wwrite(FTABLE *table, size_t cols, const wchar_t *row_cells[]);
FT_EXTERN int ft_row_wwrite_ln(FTABLE *table, size_t cols, const wchar_t *row_cells[]);
int ft_row_wwrite(FTABLE *table, size_t cols, const wchar_t *row_cells[]);
int ft_row_wwrite_ln(FTABLE *table, size_t cols, const wchar_t *row_cells[]);
FT_EXTERN int ft_table_wwrite(FTABLE *table, size_t rows, size_t cols, const wchar_t *table_cells[]);
FT_EXTERN int ft_table_wwrite_ln(FTABLE *table, size_t rows, size_t cols, const wchar_t *table_cells[]);
int ft_table_wwrite(FTABLE *table, size_t rows, size_t cols, const wchar_t *table_cells[]);
int ft_table_wwrite_ln(FTABLE *table, size_t rows, size_t cols, const wchar_t *table_cells[]);
FT_EXTERN const wchar_t *ft_to_wstring(const FTABLE *table);
const wchar_t *ft_to_wstring(const FTABLE *table);
#endif

View File

@ -1,3 +1,36 @@
/*
libfort
MIT License
Copyright (c) 2017 - 2018 Seleznev Anton
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* @file fort.hpp
* @brief Main header file describing libfort C++ API .
*
* This files contains C++ wrappers around libfort API that can
* be used in C++ code.
*/
#ifndef LIBFORT_HPP
#define LIBFORT_HPP
@ -24,6 +57,11 @@ const TableManipulator header(0);
const TableManipulator endl(1);
const TableManipulator separator(2);
/**
* Table - here is a short description.
*
* Here is detailed description.
*/
class Table {
public:
Table()
@ -75,12 +113,12 @@ public:
bool write(const char *str)
{
return IS_SUCCESS(ft_write(table, str));
return FT_IS_SUCCESS(ft_write(table, str));
}
bool write_ln(const char *str)
{
return IS_SUCCESS(ft_write_ln(table, str));
return FT_IS_SUCCESS(ft_write_ln(table, str));
}
bool write(const std::string &str)

View File

@ -149,7 +149,7 @@ static int ft_row_printf_impl(FTABLE *table, size_t row, const char *fmt, va_lis
if (padding_row == NULL)
goto clear;
if (IS_ERROR(vector_push(table->rows, &padding_row))) {
if (FT_IS_ERROR(vector_push(table->rows, &padding_row))) {
destroy_row(padding_row);
goto clear;
}
@ -196,7 +196,7 @@ static int ft_row_wprintf_impl(FTABLE *table, size_t row, const wchar_t *fmt, va
if (padding_row == NULL)
goto clear;
if (IS_ERROR(vector_push(table->rows, &padding_row))) {
if (FT_IS_ERROR(vector_push(table->rows, &padding_row))) {
destroy_row(padding_row);
goto clear;
}
@ -292,7 +292,7 @@ static int ft_write_impl(FTABLE *table, const char *cell_content)
return FT_ERROR;
int status = fill_buffer_from_string(str_buffer, cell_content);
if (IS_SUCCESS(status)) {
if (FT_IS_SUCCESS(status)) {
table->cur_col++;
}
return status;
@ -309,7 +309,7 @@ static int ft_wwrite_impl(FTABLE *table, const wchar_t *cell_content)
return FT_ERROR;
int status = fill_buffer_from_wstring(str_buffer, cell_content);
if (IS_SUCCESS(status)) {
if (FT_IS_SUCCESS(status)) {
table->cur_col++;
}
return status;
@ -323,7 +323,7 @@ int ft_nwrite(FTABLE *table, size_t n, const char *cell_content, ...)
size_t i = 0;
assert(table);
int status = ft_write_impl(table, cell_content);
if (IS_ERROR(status))
if (FT_IS_ERROR(status))
return status;
va_list va;
@ -332,7 +332,7 @@ int ft_nwrite(FTABLE *table, size_t n, const char *cell_content, ...)
for (i = 0; i < n; ++i) {
const char *cell = va_arg(va, const char *);
status = ft_write_impl(table, cell);
if (IS_ERROR(status))
if (FT_IS_ERROR(status))
return status;
}
va_end(va);
@ -344,7 +344,7 @@ int ft_nwrite_ln(FTABLE *table, size_t n, const char *cell_content, ...)
size_t i = 0;
assert(table);
int status = ft_write_impl(table, cell_content);
if (IS_ERROR(status))
if (FT_IS_ERROR(status))
return status;
va_list va;
@ -353,7 +353,7 @@ int ft_nwrite_ln(FTABLE *table, size_t n, const char *cell_content, ...)
for (i = 0; i < n; ++i) {
const char *cell = va_arg(va, const char *);
status = ft_write_impl(table, cell);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
va_end(va);
return status;
}
@ -371,7 +371,7 @@ int ft_nwwrite(FTABLE *table, size_t n, const wchar_t *cell_content, ...)
size_t i = 0;
assert(table);
int status = ft_wwrite_impl(table, cell_content);
if (IS_ERROR(status))
if (FT_IS_ERROR(status))
return status;
va_list va;
@ -380,7 +380,7 @@ int ft_nwwrite(FTABLE *table, size_t n, const wchar_t *cell_content, ...)
for (i = 0; i < n; ++i) {
const wchar_t *cell = va_arg(va, const wchar_t *);
status = ft_wwrite_impl(table, cell);
if (IS_ERROR(status))
if (FT_IS_ERROR(status))
return status;
}
va_end(va);
@ -392,7 +392,7 @@ int ft_nwwrite_ln(FTABLE *table, size_t n, const wchar_t *cell_content, ...)
size_t i = 0;
assert(table);
int status = ft_wwrite_impl(table, cell_content);
if (IS_ERROR(status))
if (FT_IS_ERROR(status))
return status;
va_list va;
@ -401,7 +401,7 @@ int ft_nwwrite_ln(FTABLE *table, size_t n, const wchar_t *cell_content, ...)
for (i = 0; i < n; ++i) {
const wchar_t *cell = va_arg(va, const wchar_t *);
status = ft_wwrite_impl(table, cell);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
va_end(va);
return status;
}
@ -420,7 +420,7 @@ int ft_row_write(FTABLE *table, size_t cols, const char *cells[])
assert(table);
for (i = 0; i < cols; ++i) {
int status = ft_write_impl(table, cells[i]);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
/* todo: maybe current pos in case of error should be equal to the one before function call? */
return status;
}
@ -432,7 +432,7 @@ int ft_row_write_ln(FTABLE *table, size_t cols, const char *cells[])
{
assert(table);
int status = ft_row_write(table, cols, cells);
if (IS_SUCCESS(status)) {
if (FT_IS_SUCCESS(status)) {
ft_ln(table);
}
return status;
@ -445,7 +445,7 @@ int ft_row_wwrite(FTABLE *table, size_t cols, const wchar_t *cells[])
assert(table);
for (i = 0; i < cols; ++i) {
int status = ft_wwrite_impl(table, cells[i]);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
/* todo: maybe current pos in case of error should be equal to the one before function call? */
return status;
}
@ -457,7 +457,7 @@ int ft_row_wwrite_ln(FTABLE *table, size_t cols, const wchar_t *cells[])
{
assert(table);
int status = ft_row_wwrite(table, cols, cells);
if (IS_SUCCESS(status)) {
if (FT_IS_SUCCESS(status)) {
ft_ln(table);
}
return status;
@ -472,7 +472,7 @@ int ft_table_write(FTABLE *table, size_t rows, size_t cols, const char *table_ce
assert(table);
for (i = 0; i < rows; ++i) {
int status = ft_row_write(table, cols, (const char **)&table_cells[i * cols]);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
/* todo: maybe current pos in case of error should be equal to the one before function call? */
return status;
}
@ -486,7 +486,7 @@ int ft_table_write_ln(FTABLE *table, size_t rows, size_t cols, const char *table
{
assert(table);
int status = ft_table_write(table, rows, cols, table_cells);
if (IS_SUCCESS(status)) {
if (FT_IS_SUCCESS(status)) {
ft_ln(table);
}
return status;
@ -500,7 +500,7 @@ int ft_table_wwrite(FTABLE *table, size_t rows, size_t cols, const wchar_t *tabl
assert(table);
for (i = 0; i < rows; ++i) {
int status = ft_row_wwrite(table, cols, (const wchar_t **)&table_cells[i * cols]);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
/* todo: maybe current pos in case of error should be equal to the one before function call? */
return status;
}
@ -514,7 +514,7 @@ int ft_table_wwrite_ln(FTABLE *table, size_t rows, size_t cols, const wchar_t *t
{
assert(table);
int status = ft_table_wwrite(table, rows, cols, table_cells);
if (IS_SUCCESS(status)) {
if (FT_IS_SUCCESS(status)) {
ft_ln(table);
}
return status;
@ -554,7 +554,7 @@ const char *ft_to_string(const FTABLE *table)
size_t height = 0;
size_t width = 0;
int status = table_geometry(table, &height, &width);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
return NULL;
}
size_t sz = height * width + 1;
@ -566,7 +566,7 @@ const char *ft_to_string(const FTABLE *table)
return NULL;
}
while (string_buffer_capacity(table->conv_buffer) < sz) {
if (IS_ERROR(realloc_string_buffer_without_copy(table->conv_buffer))) {
if (FT_IS_ERROR(realloc_string_buffer_without_copy(table->conv_buffer))) {
return NULL;
}
}
@ -578,7 +578,7 @@ const char *ft_to_string(const FTABLE *table)
size_t *col_width_arr = NULL;
size_t *row_height_arr = NULL;
status = table_rows_and_cols_geometry(table, &col_width_arr, &cols, &row_height_arr, &rows);
if (IS_ERROR(status))
if (FT_IS_ERROR(status))
return NULL;
if (rows == 0)
@ -657,7 +657,7 @@ const wchar_t *ft_to_wstring(const FTABLE *table)
size_t height = 0;
size_t width = 0;
int status = table_geometry(table, &height, &width);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
return NULL;
}
size_t sz = height * width + 1;
@ -669,7 +669,7 @@ const wchar_t *ft_to_wstring(const FTABLE *table)
return NULL;
}
while (string_buffer_capacity(table->conv_buffer) < sz) {
if (IS_ERROR(realloc_string_buffer_without_copy(table->conv_buffer))) {
if (FT_IS_ERROR(realloc_string_buffer_without_copy(table->conv_buffer))) {
return NULL;
}
}
@ -685,7 +685,7 @@ const wchar_t *ft_to_wstring(const FTABLE *table)
if (rows == 0)
return cur_F_STRDUP(empty_string);
if (IS_ERROR(status))
if (FT_IS_ERROR(status))
return NULL;
int written = 0;
@ -771,7 +771,7 @@ int ft_add_separator(FTABLE *table)
if (sep_p == NULL)
return FT_MEMORY_ERROR;
int status = vector_push(table->separators, &sep_p);
if (IS_ERROR(status))
if (FT_IS_ERROR(status))
return status;
}
@ -939,12 +939,12 @@ int ft_set_default_cell_option(uint32_t option, int value)
}
FT_EXTERN int ft_set_default_tbl_option(uint32_t option, int value)
int ft_set_default_tbl_option(uint32_t option, int value)
{
return set_default_entire_table_option(option, value);
}
FT_EXTERN int ft_set_tbl_option(FTABLE *table, uint32_t option, int value)
int ft_set_tbl_option(FTABLE *table, uint32_t option, int value)
{
assert(table);
@ -956,12 +956,12 @@ FT_EXTERN int ft_set_tbl_option(FTABLE *table, uint32_t option, int value)
return set_entire_table_option(table->options, option, value);
}
FT_EXTERN 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))
{
set_memory_funcs(f_malloc, f_free);
}
FT_EXTERN int ft_set_cell_span(FTABLE *table, size_t row, size_t col, size_t hor_span)
int ft_set_cell_span(FTABLE *table, size_t row, size_t col, size_t hor_span)
{
assert(table);
if (hor_span < 2)

View File

@ -112,7 +112,7 @@ fort_cell_options_t *get_cell_opt_and_create_if_not_exists(fort_cell_opt_contain
fort_cell_options_t opt = g_default_cell_option;// DEFAULT_CELL_OPTION;
opt.cell_row = row;
opt.cell_col = col;
if (IS_SUCCESS(vector_push(cont, &opt))) {
if (FT_IS_SUCCESS(vector_push(cont, &opt))) {
return (fort_cell_options_t *)vector_at(cont, sz);
}

View File

@ -79,7 +79,7 @@ fort_cell_t *get_cell_implementation(fort_row_t *row, size_t col, enum PolicyOnN
fort_cell_t *new_cell = create_cell();
if (new_cell == NULL)
return NULL;
if (IS_ERROR(vector_push(row->cells, &new_cell))) {
if (FT_IS_ERROR(vector_push(row->cells, &new_cell))) {
destroy_cell(new_cell);
return NULL;
}
@ -573,13 +573,13 @@ fort_row_t *create_row_from_string(const char *str)
goto clear;
int status = fill_cell_from_string_(cell, base_pos);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
destroy_cell(cell);
goto clear;
}
status = vector_push(row->cells, &cell);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
destroy_cell(cell);
goto clear;
}
@ -596,13 +596,13 @@ fort_row_t *create_row_from_string(const char *str)
goto clear;
int status = fill_cell_from_string_(cell, zero_string);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
destroy_cell(cell);
goto clear;
}
status = vector_push(row->cells, &cell);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
destroy_cell(cell);
goto clear;
}
@ -661,13 +661,13 @@ fort_row_t *create_row_from_wstring(const wchar_t *str)
goto clear;
int status = fill_cell_from_string_(cell, base_pos);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
destroy_cell(cell);
goto clear;
}
status = vector_push(row->cells, &cell);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
destroy_cell(cell);
goto clear;
}
@ -684,13 +684,13 @@ fort_row_t *create_row_from_wstring(const wchar_t *str)
goto clear;
int status = fill_cell_from_string_(cell, zero_string);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
destroy_cell(cell);
goto clear;
}
status = vector_push(row->cells, &cell);
if (IS_ERROR(status)) {
if (FT_IS_ERROR(status)) {
destroy_cell(cell);
goto clear;
}
@ -736,7 +736,7 @@ fort_row_t *create_row_from_fmt_string(const char *fmt, va_list *va_args)
break;
/* Otherwise buffer was too small, so incr. buffer size ant try again. */
if (!IS_SUCCESS(realloc_string_buffer_without_copy(buffer)))
if (!FT_IS_SUCCESS(realloc_string_buffer_without_copy(buffer)))
goto clear;
}
@ -793,7 +793,7 @@ fort_row_t *create_row_from_fmt_wstring(const wchar_t *fmt, va_list *va_args)
break;
/* Otherwise buffer was too small, so incr. buffer size ant try again. */
if (!IS_SUCCESS(realloc_string_buffer_without_copy(buffer)))
if (!FT_IS_SUCCESS(realloc_string_buffer_without_copy(buffer)))
goto clear;
}

View File

@ -198,7 +198,7 @@ fort_status_t fill_buffer_from_string(string_buffer_t *buffer, const char *str)
while (sz >= string_buffer_capacity(buffer)) {
int status = realloc_string_buffer_without_copy(buffer);
if (!IS_SUCCESS(status)) {
if (!FT_IS_SUCCESS(status)) {
return status;
}
}
@ -221,7 +221,7 @@ fort_status_t fill_buffer_from_wstring(string_buffer_t *buffer, const wchar_t *s
while (sz >= string_buffer_capacity(buffer)) {
int status = realloc_string_buffer_without_copy(buffer);
if (!IS_SUCCESS(status)) {
if (!FT_IS_SUCCESS(status)) {
return status;
}
}

View File

@ -25,7 +25,7 @@ fort_row_t *get_row_implementation(fort_table_t *table, size_t row, enum PolicyO
fort_row_t *new_row = create_row();
if (new_row == NULL)
return NULL;
if (IS_ERROR(vector_push(table->rows, &new_row))) {
if (FT_IS_ERROR(vector_push(table->rows, &new_row))) {
destroy_row(new_row);
return NULL;
}
@ -101,7 +101,7 @@ fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
size_t cols = 0;
size_t rows = 0;
int status = get_table_sizes(table, &rows, &cols);
if (IS_ERROR(status))
if (FT_IS_ERROR(status))
return status;
size_t *col_width_arr = (size_t *)F_CALLOC(sizeof(size_t), cols);
@ -210,7 +210,7 @@ fort_status_t table_geometry(const FTABLE *table, size_t *height, size_t *width)
size_t *row_height_arr = NULL;
int status = table_rows_and_cols_geometry(table, &col_width_arr, &cols, &row_height_arr, &rows);
if (IS_ERROR(status))
if (FT_IS_ERROR(status))
return status;
*width = 1 + (cols == 0 ? 1 : cols) + 1; /* for boundaries (that take 1 symbol) + newline */

View File

@ -306,26 +306,26 @@ void test_table_write(void)
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
assert_true(IS_SUCCESS(ft_write(table, "3")));
assert_true(IS_SUCCESS(ft_write(table, "c")));
assert_true(IS_SUCCESS(ft_write(table, "234")));
assert_true(IS_SUCCESS(ft_write(table, "3.140000")));
assert_true(FT_IS_SUCCESS(ft_write(table, "3")));
assert_true(FT_IS_SUCCESS(ft_write(table, "c")));
assert_true(FT_IS_SUCCESS(ft_write(table, "234")));
assert_true(FT_IS_SUCCESS(ft_write(table, "3.140000")));
ft_ln(table);
assert_true(IS_SUCCESS(ft_write(table, "c")));
assert_true(IS_SUCCESS(ft_write(table, "235")));
assert_true(IS_SUCCESS(ft_write(table, "3.150000")));
assert_true(IS_SUCCESS(ft_write_ln(table, "5")));
assert_true(FT_IS_SUCCESS(ft_write(table, "c")));
assert_true(FT_IS_SUCCESS(ft_write(table, "235")));
assert_true(FT_IS_SUCCESS(ft_write(table, "3.150000")));
assert_true(FT_IS_SUCCESS(ft_write_ln(table, "5")));
assert_true(IS_SUCCESS(ft_write(table, "234")));
assert_true(IS_SUCCESS(ft_write(table, "3.140000")));
assert_true(IS_SUCCESS(ft_write(table, "3")));
assert_true(IS_SUCCESS(ft_write_ln(table, "c")));
assert_true(FT_IS_SUCCESS(ft_write(table, "234")));
assert_true(FT_IS_SUCCESS(ft_write(table, "3.140000")));
assert_true(FT_IS_SUCCESS(ft_write(table, "3")));
assert_true(FT_IS_SUCCESS(ft_write_ln(table, "c")));
/* Replace old values */
ft_set_cur_cell(table, 1, 1);
assert_true(IS_SUCCESS(ft_write(table, "234")));
assert_true(IS_SUCCESS(ft_write(table, "3.140000")));
assert_true(IS_SUCCESS(ft_write_ln(table, "3")));
assert_true(FT_IS_SUCCESS(ft_write(table, "234")));
assert_true(FT_IS_SUCCESS(ft_write(table, "3.140000")));
assert_true(FT_IS_SUCCESS(ft_write_ln(table, "3")));
const char *table_str = ft_to_string(table);
assert_true(table_str != NULL);
@ -354,26 +354,26 @@ void test_table_write(void)
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
assert_true(IS_SUCCESS(ft_wwrite(table, L"3")));
assert_true(IS_SUCCESS(ft_wwrite(table, L"c")));
assert_true(IS_SUCCESS(ft_wwrite(table, L"234")));
assert_true(IS_SUCCESS(ft_wwrite(table, L"3.140000")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"c")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"234")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3.140000")));
ft_ln(table);
assert_true(IS_SUCCESS(ft_wwrite(table, L"c")));
assert_true(IS_SUCCESS(ft_wwrite(table, L"235")));
assert_true(IS_SUCCESS(ft_wwrite(table, L"3.150000")));
assert_true(IS_SUCCESS(ft_wwrite_ln(table, L"5")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"c")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"235")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3.150000")));
assert_true(FT_IS_SUCCESS(ft_wwrite_ln(table, L"5")));
assert_true(IS_SUCCESS(ft_wwrite(table, L"234")));
assert_true(IS_SUCCESS(ft_wwrite(table, L"3.140000")));
assert_true(IS_SUCCESS(ft_wwrite(table, L"3")));
assert_true(IS_SUCCESS(ft_wwrite_ln(table, L"c")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"234")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3.140000")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3")));
assert_true(FT_IS_SUCCESS(ft_wwrite_ln(table, L"c")));
/* Replace old values */
ft_set_cur_cell(table, 1, 1);
assert_true(IS_SUCCESS(ft_wwrite(table, L"234")));
assert_true(IS_SUCCESS(ft_wwrite(table, L"3.140000")));
assert_true(IS_SUCCESS(ft_wwrite_ln(table, L"3")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"234")));
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3.140000")));
assert_true(FT_IS_SUCCESS(ft_wwrite_ln(table, L"3")));
const wchar_t *table_str = ft_to_wstring(table);
assert_true(table_str != NULL);

View File

@ -15,7 +15,7 @@ void test_table_sizes(void)
WHEN("Table is empty") {
status = get_table_sizes(table, &rows, &cols);
assert_true(IS_SUCCESS(status));
assert_true(FT_IS_SUCCESS(status));
assert_true(rows == 0);
assert_true(cols == 0);
}
@ -24,7 +24,7 @@ void test_table_sizes(void)
int n = ft_printf_ln(table, "%c", 'c');
assert_true(n == 1);
status = get_table_sizes(table, &rows, &cols);
assert_true(IS_SUCCESS(status));
assert_true(FT_IS_SUCCESS(status));
assert_true(rows == 1);
assert_true(cols == 1);
}
@ -33,7 +33,7 @@ void test_table_sizes(void)
int n = ft_printf_ln(table, "%c|%c", 'c', 'd');
assert_true(n == 2);
status = get_table_sizes(table, &rows, &cols);
assert_true(IS_SUCCESS(status));
assert_true(FT_IS_SUCCESS(status));
assert_true(rows == 2);
assert_true(cols == 2);
}
@ -42,7 +42,7 @@ void test_table_sizes(void)
int n = ft_printf_ln(table, "%d|%d|%d|%d|%d", 1, 2, 3, 4, 5);
assert_true(n == 5);
status = get_table_sizes(table, &rows, &cols);
assert_true(IS_SUCCESS(status));
assert_true(FT_IS_SUCCESS(status));
assert_true(rows == 3);
assert_true(cols == 5);
}
@ -63,7 +63,7 @@ void test_table_geometry(void)
WHEN("Table is empty") {
status = table_geometry(table, &height, &width);
assert_true(IS_SUCCESS(status));
assert_true(FT_IS_SUCCESS(status));
assert_true(height == 2);
assert_true(width == 3);
}
@ -72,7 +72,7 @@ void test_table_geometry(void)
int n = ft_printf_ln(table, "%c", 'c');
assert_true(n == 1);
status = table_geometry(table, &height, &width);
assert_true(IS_SUCCESS(status));
assert_true(FT_IS_SUCCESS(status));
assert_true(height == 5);
assert_true(width == 6);
}
@ -81,7 +81,7 @@ void test_table_geometry(void)
int n = ft_printf_ln(table, "%c|%s|%c", 'c', "as", 'e');
assert_true(n == 3);
status = table_geometry(table, &height, &width);
assert_true(IS_SUCCESS(status));
assert_true(FT_IS_SUCCESS(status));
assert_true(height == 9);
assert_true(width == 15);
}

View File

@ -1,4 +1,3 @@
//#define FT_EXTERN static
#include "tests.h"
#include "fort.h"
#include <string.h>