[C] Documentation changes
This commit is contained in:
parent
d010dc9cf8
commit
d6ec32cb5f
@ -3,9 +3,9 @@
|
||||
#include <wchar.h>
|
||||
#include <locale.h>
|
||||
|
||||
static FTABLE *create_basic_table(void)
|
||||
static ft_table_t *create_basic_table(void)
|
||||
{
|
||||
FTABLE *table = ft_create_table();
|
||||
ft_table_t *table = ft_create_table();
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||
|
||||
@ -25,7 +25,7 @@ int main(void)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
FTABLE *table = NULL;
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
table = ft_create_table();
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||
|
362
include/fort.h
362
include/fort.h
@ -28,7 +28,7 @@ SOFTWARE.
|
||||
* @file fort.h
|
||||
* @brief Main header file describing libfort API.
|
||||
*
|
||||
* This files contains declarations of all libfort functions and macro
|
||||
* This file contains declarations of all libfort functions and macro
|
||||
* definitions.
|
||||
*/
|
||||
|
||||
@ -115,71 +115,77 @@ typedef int fort_status_t;
|
||||
* Helper macros
|
||||
*****************************************************************************/
|
||||
|
||||
#define STR_2_CAT_(arg1, arg2) \
|
||||
#define FT_STR_2_CAT_(arg1, arg2) \
|
||||
arg1##arg2
|
||||
#define STR_2_CAT(arg1, arg2) \
|
||||
STR_2_CAT_(arg1, arg2)
|
||||
|
||||
#define FT_STR_2_CAT(arg1, arg2) \
|
||||
FT_STR_2_CAT_(arg1, arg2)
|
||||
|
||||
/**
|
||||
* @interanl
|
||||
*/
|
||||
static FT_INLINE int ft_check_if_string_helper(const char *str)
|
||||
{
|
||||
(void)str;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @interanl
|
||||
*/
|
||||
static FT_INLINE int ft_check_if_wstring_helper(const wchar_t *str)
|
||||
{
|
||||
(void)str;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define FORT_NARGS_IMPL_(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,N,...) N
|
||||
#define FT_NARGS_IMPL_(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,N,...) N
|
||||
#define FT_EXPAND_(x) x
|
||||
#define PP_NARG(...) \
|
||||
FT_EXPAND_(FORT_NARGS_IMPL_(__VA_ARGS__,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0))
|
||||
#define FT_PP_NARG_(...) \
|
||||
FT_EXPAND_(FT_NARGS_IMPL_(__VA_ARGS__,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0))
|
||||
|
||||
#define CHECK_IF_STRING_32(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_31(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_31(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_30(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_30(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_29(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_29(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_28(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_28(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_27(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_27(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_26(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_26(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_25(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_25(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_24(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_24(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_23(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_23(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_22(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_22(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_21(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_21(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_20(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_20(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_19(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_19(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_18(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_18(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_17(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_17(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_16(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_16(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_15(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_15(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_14(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_14(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_13(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_13(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_12(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_12(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_11(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_11(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_10(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_10(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_9(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_9(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_8(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_8(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_7(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_7(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_6(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_6(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_5(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_5(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_4(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_4(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_3(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_3(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_2(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_2(checker,arg,...) (checker(arg),FT_EXPAND_(CHECK_IF_STRING_1(checker,__VA_ARGS__)))
|
||||
#define CHECK_IF_STRING_1(checker,arg) (checker(arg))
|
||||
#define FT_CHECK_IF_STR_32(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_31(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_31(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_30(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_30(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_29(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_29(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_28(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_28(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_27(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_27(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_26(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_26(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_25(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_25(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_24(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_24(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_23(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_23(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_22(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_22(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_21(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_21(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_20(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_20(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_19(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_19(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_18(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_18(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_17(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_17(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_16(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_16(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_15(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_15(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_14(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_14(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_13(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_13(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_12(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_12(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_11(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_11(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_10(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_10(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_9(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_9(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_8(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_8(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_7(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_7(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_6(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_6(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_5(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_5(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_4(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_4(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_3(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_3(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_2(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_2(checker,arg,...) (checker(arg),FT_EXPAND_(FT_CHECK_IF_STR_1(checker,__VA_ARGS__)))
|
||||
#define FT_CHECK_IF_STR_1(checker,arg) (checker(arg))
|
||||
|
||||
#define CHECK_IF_ARGS_ARE_STRINGS__(checker,func, ...) \
|
||||
#define FT_CHECK_IF_ARGS_ARE_STRINGS__(checker,func, ...) \
|
||||
FT_EXPAND_(func(checker,__VA_ARGS__))
|
||||
#define CHECK_IF_ARGS_ARE_STRINGS_(checker,basis, n, ...) \
|
||||
CHECK_IF_ARGS_ARE_STRINGS__(checker,STR_2_CAT_(basis, n), __VA_ARGS__)
|
||||
#define CHECK_IF_ARGS_ARE_STRINGS(...) \
|
||||
CHECK_IF_ARGS_ARE_STRINGS_(ft_check_if_string_helper,CHECK_IF_STRING_,PP_NARG(__VA_ARGS__), __VA_ARGS__)
|
||||
#define FT_CHECK_IF_ARGS_ARE_STRINGS_(checker,basis, n, ...) \
|
||||
FT_CHECK_IF_ARGS_ARE_STRINGS__(checker,FT_STR_2_CAT_(basis, n), __VA_ARGS__)
|
||||
#define FT_CHECK_IF_ARGS_ARE_STRINGS(...) \
|
||||
FT_CHECK_IF_ARGS_ARE_STRINGS_(ft_check_if_string_helper,FT_CHECK_IF_STR_,FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
#define CHECK_IF_ARGS_ARE_WSTRINGS(...) \
|
||||
CHECK_IF_ARGS_ARE_STRINGS_(ft_check_if_wstring_helper,CHECK_IF_STRING_,PP_NARG(__VA_ARGS__), __VA_ARGS__)
|
||||
FT_CHECK_IF_ARGS_ARE_STRINGS_(ft_check_if_wstring_helper,FT_CHECK_IF_STR_,FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -205,16 +211,26 @@ static FT_INLINE int ft_check_if_wstring_helper(const wchar_t *str)
|
||||
|
||||
FT_BEGIN_DECLS
|
||||
|
||||
struct fort_table;
|
||||
typedef struct fort_table FTABLE;
|
||||
/**
|
||||
* The main structure of libfort containing information about formatted table.
|
||||
*/
|
||||
struct ft_table;
|
||||
|
||||
/**
|
||||
* The main structure of libfort containing information about formatted table.
|
||||
*
|
||||
* ft_table_t objects should be created by a call to ft_create_table and
|
||||
* destroyed with ft_destroy_table.
|
||||
*/
|
||||
typedef struct ft_table ft_table_t;
|
||||
|
||||
/**
|
||||
* Create formatted table.
|
||||
*
|
||||
* @return
|
||||
* The pointer to the new allocated FTABLE, on success. NULL on error.
|
||||
* The pointer to the new allocated ft_table_t, on success. NULL on error.
|
||||
*/
|
||||
FTABLE *ft_create_table(void);
|
||||
ft_table_t *ft_create_table(void);
|
||||
|
||||
/**
|
||||
* Destroy formatted table.
|
||||
@ -226,7 +242,7 @@ 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.
|
||||
*/
|
||||
void ft_destroy_table(FTABLE *table);
|
||||
void ft_destroy_table(ft_table_t *table);
|
||||
|
||||
/**
|
||||
* Move current position to the first cell of the next line(row).
|
||||
@ -234,7 +250,7 @@ void ft_destroy_table(FTABLE *table);
|
||||
* @param table
|
||||
* Pointer to formatted table.
|
||||
*/
|
||||
void ft_ln(FTABLE *table);
|
||||
void ft_ln(ft_table_t *table);
|
||||
|
||||
/**
|
||||
* Get row number of the current cell.
|
||||
@ -244,7 +260,7 @@ void ft_ln(FTABLE *table);
|
||||
* @return
|
||||
* Row number of the current cell.
|
||||
*/
|
||||
size_t ft_cur_row(FTABLE *table);
|
||||
size_t ft_cur_row(ft_table_t *table);
|
||||
|
||||
/**
|
||||
* Get column number of the current cell.
|
||||
@ -254,7 +270,7 @@ size_t ft_cur_row(FTABLE *table);
|
||||
* @return
|
||||
* Column number of the current cell.
|
||||
*/
|
||||
size_t ft_cur_col(FTABLE *table);
|
||||
size_t ft_cur_col(ft_table_t *table);
|
||||
|
||||
/**
|
||||
* Set current cell position.
|
||||
@ -269,14 +285,14 @@ size_t ft_cur_col(FTABLE *table);
|
||||
* @param col
|
||||
* New row number for the current cell.
|
||||
*/
|
||||
void ft_set_cur_cell(FTABLE *table, size_t row, size_t col);
|
||||
void ft_set_cur_cell(ft_table_t *table, size_t row, size_t col);
|
||||
|
||||
|
||||
|
||||
#if defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER)
|
||||
|
||||
/**
|
||||
* Writes data formatted acording to the format string to a variety of table
|
||||
* Write data formatted acording to the format string to a variety of table
|
||||
* cells.
|
||||
*
|
||||
* @param table
|
||||
@ -299,11 +315,11 @@ void ft_set_cur_cell(FTABLE *table, size_t row, size_t col);
|
||||
* - Number of printed cells
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_printf(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
|
||||
int ft_printf(ft_table_t *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
|
||||
|
||||
/**
|
||||
* Writes data formatted acording to the format string to a variety of table
|
||||
* cells and moves current position to the first cell of the next line(row).
|
||||
* Write data formatted acording to the format string to a variety of table
|
||||
* cells and move current position to the first cell of the next line(row).
|
||||
*
|
||||
* @param table
|
||||
* Pointer to formatted table.
|
||||
@ -325,38 +341,194 @@ int ft_printf(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2,
|
||||
* - Number of printed cells.
|
||||
* - (<0): In case of error.
|
||||
*/
|
||||
int ft_printf_ln(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
|
||||
int ft_printf_ln(ft_table_t *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
|
||||
|
||||
#else
|
||||
|
||||
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);
|
||||
/**
|
||||
* @cond IGNORE_DOC
|
||||
*/
|
||||
|
||||
int ft_printf_impl(ft_table_t *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
|
||||
int ft_printf_ln_impl(ft_table_t *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__))
|
||||
#define ft_printf_ln(table, ...) \
|
||||
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf_ln_impl(table, __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* @endcond
|
||||
*/
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Write strings to the the table.
|
||||
*
|
||||
* Write specified strings to the same number of consecutive cells in the
|
||||
* current row.
|
||||
*
|
||||
* @param table
|
||||
* Pointer to formatted table.
|
||||
* @param ...
|
||||
* Strings to write.
|
||||
* @return
|
||||
* - 0: Success; data were written
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
#define ft_write(table, ...)\
|
||||
(0 ? CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite(table, PP_NARG(__VA_ARGS__), __VA_ARGS__))
|
||||
(0 ? FT_CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* Write strings to the the table and go to the next line.
|
||||
*
|
||||
* Write specified strings to the same number of consecutive cells in the
|
||||
* current row and move current position to the first cell of the next
|
||||
* line(row).
|
||||
*
|
||||
* @param table
|
||||
* Pointer to formatted table.
|
||||
* @param ...
|
||||
* Strings to write.
|
||||
* @return
|
||||
* - 0: Success; data were written
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
#define ft_write_ln(table, ...)\
|
||||
(0 ? CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite_ln(table, PP_NARG(__VA_ARGS__), __VA_ARGS__))
|
||||
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, ...);
|
||||
(0 ? FT_CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite_ln(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* Write specified number of strings to the the table.
|
||||
*
|
||||
* Write specified number of strings to the same number of consecutive cells in
|
||||
* the current row.
|
||||
*
|
||||
* @note In most cases it is more preferable to use MACRO @ref ft_write instead
|
||||
* of @ref ft_nwrite, which is more safe (@ref ft_write automatically counts the
|
||||
* number of string arguments and at compile check that all passed arguments are
|
||||
* strings).
|
||||
*
|
||||
* @param table
|
||||
* Pointer to formatted table.
|
||||
* @param count
|
||||
* Number of strings to write.
|
||||
* @param cell_content
|
||||
* First string to write.
|
||||
* @param ...
|
||||
* Other strings to write.
|
||||
* @return
|
||||
* - 0: Success; data were written
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_nwrite(ft_table_t *table, size_t count, const char *cell_content, ...);
|
||||
|
||||
/**
|
||||
* Write specified number of strings to the the table and go to the next line.
|
||||
*
|
||||
* Write specified number of strings to the same number of consecutive cells
|
||||
* in the current row and move current position to the first cell of the next
|
||||
* line(row).
|
||||
*
|
||||
* @note In most cases it is more preferable to use MACRO @ref ft_write instead
|
||||
* of @ref ft_nwrite, which is more safe (@ref ft_write automatically counts the
|
||||
* number of string arguments and at compile check that all passed arguments are
|
||||
* strings).
|
||||
*
|
||||
* @param table
|
||||
* Pointer to formatted table.
|
||||
* @param count
|
||||
* Number of strings to write.
|
||||
* @param cell_content
|
||||
* First string to write.
|
||||
* @param ...
|
||||
* Other strings to write.
|
||||
* @return
|
||||
* - 0: Success; data were written
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_nwrite_ln(ft_table_t *table, size_t count, const char *cell_content, ...);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Write strings from the array to the table.
|
||||
*
|
||||
* Write specified number of strings from the array to the same number of
|
||||
* consecutive cells in the current row.
|
||||
*
|
||||
* @param table
|
||||
* Pointer to formatted table.
|
||||
* @param cols
|
||||
* Number of elements in row_cells.
|
||||
* @param row_cells
|
||||
* Array of strings to write.
|
||||
* @return
|
||||
* - 0: Success; data were written
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_row_write(ft_table_t *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[]);
|
||||
/**
|
||||
* Write strings from the array to the table and go to the next line.
|
||||
*
|
||||
* Write specified number of strings from the array to the same number of
|
||||
* consecutive cells in the current row and move current position to the first
|
||||
* cell of the next line(row).
|
||||
*
|
||||
* @param table
|
||||
* Pointer to formatted table.
|
||||
* @param cols
|
||||
* Number of elements in row_cells.
|
||||
* @param row_cells
|
||||
* Array of strings to write.
|
||||
* @return
|
||||
* - 0: Success; data were written
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_row_write_ln(ft_table_t *table, size_t cols, const char *row_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[]);
|
||||
|
||||
/**
|
||||
* Write strings from the 2D array to the table.
|
||||
*
|
||||
* Write specified number of strings from the 2D array to the formatted table.
|
||||
*
|
||||
* @param table
|
||||
* Pointer to formatted table.
|
||||
* @param rows
|
||||
* Number of rows in the 2D array.
|
||||
* @param cols
|
||||
* Number of columns in the 2D array.
|
||||
* @param table_cells
|
||||
* 2D array of strings to write.
|
||||
* @return
|
||||
* - 0: Success; data were written
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_table_write(ft_table_t *table, size_t rows, size_t cols, const char *table_cells[]);
|
||||
|
||||
/**
|
||||
* Write strings from the 2D array to the table and go to the next line.
|
||||
*
|
||||
* Write specified number of strings from the 2D array to the formatted table
|
||||
* and move current position to the first cell of the next line(row).
|
||||
*
|
||||
* @param table
|
||||
* Pointer to formatted table.
|
||||
* @param rows
|
||||
* Number of rows in the 2D array.
|
||||
* @param cols
|
||||
* Number of columns in the 2D array.
|
||||
* @param table_cells
|
||||
* 2D array of strings to write.
|
||||
* @return
|
||||
* - 0: Success; data were written
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_table_write_ln(ft_table_t *table, size_t rows, size_t cols, const char *table_cells[]);
|
||||
|
||||
|
||||
|
||||
@ -371,7 +543,7 @@ int ft_table_write_ln(FTABLE *table, size_t rows, size_t cols, const char *table
|
||||
* - 0: Success; separator was added.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_add_separator(FTABLE *table);
|
||||
int ft_add_separator(ft_table_t *table);
|
||||
|
||||
|
||||
|
||||
@ -379,7 +551,7 @@ int ft_add_separator(FTABLE *table);
|
||||
/**
|
||||
* Convert table to string representation.
|
||||
*
|
||||
* FTABLE has ownership of the returned pointer. So there is no need to
|
||||
* ft_table_t has ownership of the returned pointer. So there is no need to
|
||||
* free it. To take ownership user should explicitly copy the returned
|
||||
* string with strdup or similar functions.
|
||||
*
|
||||
@ -390,10 +562,10 @@ int ft_add_separator(FTABLE *table);
|
||||
* @param table
|
||||
* Formatted table.
|
||||
* @return
|
||||
* The pointer to the string representation of formatted table, on success.
|
||||
* NULL on error with ft_errno set appropriately.
|
||||
* - The pointer to the string representation of formatted table, on success.
|
||||
* - NULL on error with ft_errno set appropriately.
|
||||
*/
|
||||
const char *ft_to_string(const FTABLE *table);
|
||||
const char *ft_to_string(const ft_table_t *table);
|
||||
|
||||
|
||||
|
||||
@ -464,14 +636,14 @@ int ft_set_default_border_style(struct ft_border_style *style);
|
||||
* Set border style for the table.
|
||||
*
|
||||
* @param table
|
||||
* A pointer to the FTABLE structure.
|
||||
* A pointer to the ft_table_t structure.
|
||||
* @param style
|
||||
* Pointer to border style.
|
||||
* @return
|
||||
* - 0: Success; table border style was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_set_border_style(FTABLE *table, struct ft_border_style *style);
|
||||
int ft_set_border_style(ft_table_t *table, struct ft_border_style *style);
|
||||
|
||||
|
||||
|
||||
@ -537,7 +709,7 @@ int ft_set_default_cell_option(uint32_t option, int value);
|
||||
* Set option for the specified cell of the table.
|
||||
*
|
||||
* @param table
|
||||
* A pointer to the FTABLE structure.
|
||||
* A pointer to the ft_table_t structure.
|
||||
* @param row
|
||||
* Cell row.
|
||||
* @param col
|
||||
@ -550,7 +722,7 @@ int ft_set_default_cell_option(uint32_t option, int value);
|
||||
* - 0: Success; cell option was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_set_cell_option(FTABLE *table, size_t row, size_t col, uint32_t option, int value);
|
||||
int ft_set_cell_option(ft_table_t *table, size_t row, size_t col, uint32_t option, int value);
|
||||
|
||||
|
||||
/**
|
||||
@ -582,7 +754,7 @@ int ft_set_default_tbl_option(uint32_t option, int value);
|
||||
* Set table option.
|
||||
*
|
||||
* @param table
|
||||
* A pointer to the FTABLE structure.
|
||||
* A pointer to the ft_table_t structure.
|
||||
* @param option
|
||||
* Table option identifier.
|
||||
* @param value
|
||||
@ -591,14 +763,14 @@ int ft_set_default_tbl_option(uint32_t option, int value);
|
||||
* - 0: Success; default table option was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_set_tbl_option(FTABLE *table, uint32_t option, int value);
|
||||
int ft_set_tbl_option(ft_table_t *table, uint32_t option, int value);
|
||||
|
||||
|
||||
/**
|
||||
* Set column span for the specified cell of the table.
|
||||
*
|
||||
* @param table
|
||||
* A pointer to the FTABLE structure.
|
||||
* A pointer to the ft_table_t structure.
|
||||
* @param row
|
||||
* Cell row.
|
||||
* @param col
|
||||
@ -609,7 +781,7 @@ int ft_set_tbl_option(FTABLE *table, uint32_t option, int value);
|
||||
* - 0: Success; default table option was changed.
|
||||
* - (<0): In case of error
|
||||
*/
|
||||
int ft_set_cell_span(FTABLE *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);
|
||||
|
||||
|
||||
/**
|
||||
@ -634,24 +806,24 @@ void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *pt
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
|
||||
|
||||
int ft_wprintf(FTABLE *table, const wchar_t *fmt, ...);
|
||||
int ft_wprintf_ln(FTABLE *table, const wchar_t *fmt, ...);
|
||||
int ft_wprintf(ft_table_t *table, const wchar_t *fmt, ...);
|
||||
int ft_wprintf_ln(ft_table_t *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__))
|
||||
(0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite(table, FT_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__))
|
||||
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, ...);
|
||||
(0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite_ln(table, FT_PP_NARG_(__VA_ARGS__), __VA_ARGS__))
|
||||
int ft_nwwrite(ft_table_t *table, size_t n, const wchar_t *cell_content, ...);
|
||||
int ft_nwwrite_ln(ft_table_t *table, size_t n, const wchar_t *cell_content, ...);
|
||||
|
||||
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[]);
|
||||
int ft_row_wwrite(ft_table_t *table, size_t cols, const wchar_t *row_cells[]);
|
||||
int ft_row_wwrite_ln(ft_table_t *table, size_t cols, const wchar_t *row_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[]);
|
||||
int ft_table_wwrite(ft_table_t *table, size_t rows, size_t cols, const wchar_t *table_cells[]);
|
||||
int ft_table_wwrite_ln(ft_table_t *table, size_t rows, size_t cols, const wchar_t *table_cells[]);
|
||||
|
||||
const wchar_t *ft_to_wstring(const FTABLE *table);
|
||||
const wchar_t *ft_to_wstring(const ft_table_t *table);
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -236,7 +236,7 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
FTABLE *table;
|
||||
ft_table_t *table;
|
||||
std::stringstream stream;
|
||||
};
|
||||
|
||||
|
80
src/fort.c
80
src/fort.c
@ -47,9 +47,9 @@ SOFTWARE.
|
||||
* LIBFORT
|
||||
* ***************************************************************************/
|
||||
|
||||
FTABLE *ft_create_table(void)
|
||||
ft_table_t *ft_create_table(void)
|
||||
{
|
||||
FTABLE *result = (FTABLE *)F_CALLOC(1, sizeof(FTABLE));
|
||||
ft_table_t *result = (ft_table_t *)F_CALLOC(1, sizeof(ft_table_t));
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
|
||||
@ -72,7 +72,7 @@ FTABLE *ft_create_table(void)
|
||||
}
|
||||
|
||||
|
||||
void ft_destroy_table(FTABLE *table)
|
||||
void ft_destroy_table(ft_table_t *table)
|
||||
{
|
||||
size_t i = 0;
|
||||
|
||||
@ -98,26 +98,26 @@ void ft_destroy_table(FTABLE *table)
|
||||
F_FREE(table);
|
||||
}
|
||||
|
||||
void ft_ln(FTABLE *table)
|
||||
void ft_ln(ft_table_t *table)
|
||||
{
|
||||
assert(table);
|
||||
table->cur_col = 0;
|
||||
table->cur_row++;
|
||||
}
|
||||
|
||||
size_t ft_cur_row(FTABLE *table)
|
||||
size_t ft_cur_row(ft_table_t *table)
|
||||
{
|
||||
assert(table);
|
||||
return table->cur_row;
|
||||
}
|
||||
|
||||
size_t ft_cur_col(FTABLE *table)
|
||||
size_t ft_cur_col(ft_table_t *table)
|
||||
{
|
||||
assert(table);
|
||||
return table->cur_col;
|
||||
}
|
||||
|
||||
void ft_set_cur_cell(FTABLE *table, size_t row, size_t col)
|
||||
void ft_set_cur_cell(ft_table_t *table, size_t row, size_t col)
|
||||
{
|
||||
assert(table);
|
||||
table->cur_row = row;
|
||||
@ -125,7 +125,7 @@ void ft_set_cur_cell(FTABLE *table, size_t row, size_t col)
|
||||
}
|
||||
|
||||
|
||||
static int ft_row_printf_impl(FTABLE *table, size_t row, const char *fmt, va_list *va)
|
||||
static int ft_row_printf_impl(ft_table_t *table, size_t row, const char *fmt, va_list *va)
|
||||
{
|
||||
#define CREATE_ROW_FROM_FMT_STRING create_row_from_fmt_string
|
||||
size_t i = 0;
|
||||
@ -172,7 +172,7 @@ clear:
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
static int ft_row_wprintf_impl(FTABLE *table, size_t row, const wchar_t *fmt, va_list *va)
|
||||
static int ft_row_wprintf_impl(ft_table_t *table, size_t row, const wchar_t *fmt, va_list *va)
|
||||
{
|
||||
#define CREATE_ROW_FROM_FMT_STRING create_row_from_fmt_wstring
|
||||
size_t i = 0;
|
||||
@ -229,7 +229,7 @@ clear:
|
||||
|
||||
|
||||
|
||||
int FT_PRINTF(FTABLE *table, const char *fmt, ...)
|
||||
int FT_PRINTF(ft_table_t *table, const char *fmt, ...)
|
||||
{
|
||||
assert(table);
|
||||
va_list va;
|
||||
@ -239,7 +239,7 @@ int FT_PRINTF(FTABLE *table, const char *fmt, ...)
|
||||
return result;
|
||||
}
|
||||
|
||||
int FT_PRINTF_LN(FTABLE *table, const char *fmt, ...)
|
||||
int FT_PRINTF_LN(ft_table_t *table, const char *fmt, ...)
|
||||
{
|
||||
assert(table);
|
||||
va_list va;
|
||||
@ -258,7 +258,7 @@ int FT_PRINTF_LN(FTABLE *table, const char *fmt, ...)
|
||||
#undef FT_HDR_PRINTF_LN
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
int ft_wprintf(FTABLE *table, const wchar_t *fmt, ...)
|
||||
int ft_wprintf(ft_table_t *table, const wchar_t *fmt, ...)
|
||||
{
|
||||
assert(table);
|
||||
va_list va;
|
||||
@ -268,7 +268,7 @@ int ft_wprintf(FTABLE *table, const wchar_t *fmt, ...)
|
||||
return result;
|
||||
}
|
||||
|
||||
int ft_wprintf_ln(FTABLE *table, const wchar_t *fmt, ...)
|
||||
int ft_wprintf_ln(ft_table_t *table, const wchar_t *fmt, ...)
|
||||
{
|
||||
assert(table);
|
||||
va_list va;
|
||||
@ -284,7 +284,7 @@ int ft_wprintf_ln(FTABLE *table, const wchar_t *fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
static int ft_write_impl(FTABLE *table, const char *cell_content)
|
||||
static int ft_write_impl(ft_table_t *table, const char *cell_content)
|
||||
{
|
||||
assert(table);
|
||||
string_buffer_t *str_buffer = get_cur_str_buffer_and_create_if_not_exists(table);
|
||||
@ -301,7 +301,7 @@ static int ft_write_impl(FTABLE *table, const char *cell_content)
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
|
||||
static int ft_wwrite_impl(FTABLE *table, const wchar_t *cell_content)
|
||||
static int ft_wwrite_impl(ft_table_t *table, const wchar_t *cell_content)
|
||||
{
|
||||
assert(table);
|
||||
string_buffer_t *str_buffer = get_cur_str_buffer_and_create_if_not_exists(table);
|
||||
@ -318,7 +318,7 @@ static int ft_wwrite_impl(FTABLE *table, const wchar_t *cell_content)
|
||||
#endif
|
||||
|
||||
|
||||
int ft_nwrite(FTABLE *table, size_t n, const char *cell_content, ...)
|
||||
int ft_nwrite(ft_table_t *table, size_t count, const char *cell_content, ...)
|
||||
{
|
||||
size_t i = 0;
|
||||
assert(table);
|
||||
@ -328,8 +328,8 @@ int ft_nwrite(FTABLE *table, size_t n, const char *cell_content, ...)
|
||||
|
||||
va_list va;
|
||||
va_start(va, cell_content);
|
||||
--n;
|
||||
for (i = 0; i < n; ++i) {
|
||||
--count;
|
||||
for (i = 0; i < count; ++i) {
|
||||
const char *cell = va_arg(va, const char *);
|
||||
status = ft_write_impl(table, cell);
|
||||
if (FT_IS_ERROR(status))
|
||||
@ -339,7 +339,7 @@ int ft_nwrite(FTABLE *table, size_t n, const char *cell_content, ...)
|
||||
return status;
|
||||
}
|
||||
|
||||
int ft_nwrite_ln(FTABLE *table, size_t n, const char *cell_content, ...)
|
||||
int ft_nwrite_ln(ft_table_t *table, size_t count, const char *cell_content, ...)
|
||||
{
|
||||
size_t i = 0;
|
||||
assert(table);
|
||||
@ -349,8 +349,8 @@ int ft_nwrite_ln(FTABLE *table, size_t n, const char *cell_content, ...)
|
||||
|
||||
va_list va;
|
||||
va_start(va, cell_content);
|
||||
--n;
|
||||
for (i = 0; i < n; ++i) {
|
||||
--count;
|
||||
for (i = 0; i < count; ++i) {
|
||||
const char *cell = va_arg(va, const char *);
|
||||
status = ft_write_impl(table, cell);
|
||||
if (FT_IS_ERROR(status)) {
|
||||
@ -366,7 +366,7 @@ int ft_nwrite_ln(FTABLE *table, size_t n, const char *cell_content, ...)
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
|
||||
int ft_nwwrite(FTABLE *table, size_t n, const wchar_t *cell_content, ...)
|
||||
int ft_nwwrite(ft_table_t *table, size_t n, const wchar_t *cell_content, ...)
|
||||
{
|
||||
size_t i = 0;
|
||||
assert(table);
|
||||
@ -387,7 +387,7 @@ int ft_nwwrite(FTABLE *table, size_t n, const wchar_t *cell_content, ...)
|
||||
return status;
|
||||
}
|
||||
|
||||
int ft_nwwrite_ln(FTABLE *table, size_t n, const wchar_t *cell_content, ...)
|
||||
int ft_nwwrite_ln(ft_table_t *table, size_t n, const wchar_t *cell_content, ...)
|
||||
{
|
||||
size_t i = 0;
|
||||
assert(table);
|
||||
@ -414,7 +414,7 @@ int ft_nwwrite_ln(FTABLE *table, size_t n, const wchar_t *cell_content, ...)
|
||||
#endif
|
||||
|
||||
|
||||
int ft_row_write(FTABLE *table, size_t cols, const char *cells[])
|
||||
int ft_row_write(ft_table_t *table, size_t cols, const char *cells[])
|
||||
{
|
||||
size_t i = 0;
|
||||
assert(table);
|
||||
@ -428,7 +428,7 @@ int ft_row_write(FTABLE *table, size_t cols, const char *cells[])
|
||||
return FT_SUCCESS;
|
||||
}
|
||||
|
||||
int ft_row_write_ln(FTABLE *table, size_t cols, const char *cells[])
|
||||
int ft_row_write_ln(ft_table_t *table, size_t cols, const char *cells[])
|
||||
{
|
||||
assert(table);
|
||||
int status = ft_row_write(table, cols, cells);
|
||||
@ -439,7 +439,7 @@ int ft_row_write_ln(FTABLE *table, size_t cols, const char *cells[])
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
int ft_row_wwrite(FTABLE *table, size_t cols, const wchar_t *cells[])
|
||||
int ft_row_wwrite(ft_table_t *table, size_t cols, const wchar_t *cells[])
|
||||
{
|
||||
size_t i = 0;
|
||||
assert(table);
|
||||
@ -453,7 +453,7 @@ int ft_row_wwrite(FTABLE *table, size_t cols, const wchar_t *cells[])
|
||||
return FT_SUCCESS;
|
||||
}
|
||||
|
||||
int ft_row_wwrite_ln(FTABLE *table, size_t cols, const wchar_t *cells[])
|
||||
int ft_row_wwrite_ln(ft_table_t *table, size_t cols, const wchar_t *cells[])
|
||||
{
|
||||
assert(table);
|
||||
int status = ft_row_wwrite(table, cols, cells);
|
||||
@ -466,7 +466,7 @@ int ft_row_wwrite_ln(FTABLE *table, size_t cols, const wchar_t *cells[])
|
||||
|
||||
|
||||
|
||||
int ft_table_write(FTABLE *table, size_t rows, size_t cols, const char *table_cells[])
|
||||
int ft_table_write(ft_table_t *table, size_t rows, size_t cols, const char *table_cells[])
|
||||
{
|
||||
size_t i = 0;
|
||||
assert(table);
|
||||
@ -482,7 +482,7 @@ int ft_table_write(FTABLE *table, size_t rows, size_t cols, const char *table_ce
|
||||
return FT_SUCCESS;
|
||||
}
|
||||
|
||||
int ft_table_write_ln(FTABLE *table, size_t rows, size_t cols, const char *table_cells[])
|
||||
int ft_table_write_ln(ft_table_t *table, size_t rows, size_t cols, const char *table_cells[])
|
||||
{
|
||||
assert(table);
|
||||
int status = ft_table_write(table, rows, cols, table_cells);
|
||||
@ -494,7 +494,7 @@ int ft_table_write_ln(FTABLE *table, size_t rows, size_t cols, const char *table
|
||||
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
int ft_table_wwrite(FTABLE *table, size_t rows, size_t cols, const wchar_t *table_cells[])
|
||||
int ft_table_wwrite(ft_table_t *table, size_t rows, size_t cols, const wchar_t *table_cells[])
|
||||
{
|
||||
size_t i = 0;
|
||||
assert(table);
|
||||
@ -510,7 +510,7 @@ int ft_table_wwrite(FTABLE *table, size_t rows, size_t cols, const wchar_t *tabl
|
||||
return FT_SUCCESS;
|
||||
}
|
||||
|
||||
int ft_table_wwrite_ln(FTABLE *table, size_t rows, size_t cols, const wchar_t *table_cells[])
|
||||
int ft_table_wwrite_ln(ft_table_t *table, size_t rows, size_t cols, const wchar_t *table_cells[])
|
||||
{
|
||||
assert(table);
|
||||
int status = ft_table_wwrite(table, rows, cols, table_cells);
|
||||
@ -532,7 +532,7 @@ int ft_table_wwrite_ln(FTABLE *table, size_t rows, size_t cols, const wchar_t *t
|
||||
|
||||
|
||||
|
||||
const char *ft_to_string(const FTABLE *table)
|
||||
const char *ft_to_string(const ft_table_t *table)
|
||||
{
|
||||
typedef char char_type;
|
||||
const char_type *empty_string = "";
|
||||
@ -561,7 +561,7 @@ const char *ft_to_string(const FTABLE *table)
|
||||
|
||||
/* Allocate string buffer for string representation */
|
||||
if (table->conv_buffer == NULL) {
|
||||
((FTABLE *)table)->conv_buffer = create_string_buffer(sz, buf_type);
|
||||
((ft_table_t *)table)->conv_buffer = create_string_buffer(sz, buf_type);
|
||||
if (table->conv_buffer == NULL)
|
||||
return NULL;
|
||||
}
|
||||
@ -633,7 +633,7 @@ clear:
|
||||
}
|
||||
|
||||
|
||||
const wchar_t *ft_to_wstring(const FTABLE *table)
|
||||
const wchar_t *ft_to_wstring(const ft_table_t *table)
|
||||
{
|
||||
typedef wchar_t char_type;
|
||||
const char_type *empty_string = L"";
|
||||
@ -664,7 +664,7 @@ const wchar_t *ft_to_wstring(const FTABLE *table)
|
||||
|
||||
/* Allocate string buffer for string representation */
|
||||
if (table->conv_buffer == NULL) {
|
||||
((FTABLE *)table)->conv_buffer = create_string_buffer(sz, buf_type);
|
||||
((ft_table_t *)table)->conv_buffer = create_string_buffer(sz, buf_type);
|
||||
if (table->conv_buffer == NULL)
|
||||
return NULL;
|
||||
}
|
||||
@ -761,7 +761,7 @@ clear:
|
||||
|
||||
|
||||
|
||||
int ft_add_separator(FTABLE *table)
|
||||
int ft_add_separator(ft_table_t *table)
|
||||
{
|
||||
assert(table);
|
||||
assert(table->separators);
|
||||
@ -895,7 +895,7 @@ int ft_set_default_border_style(struct ft_border_style *style)
|
||||
return FT_SUCCESS;
|
||||
}
|
||||
|
||||
int ft_set_border_style(FTABLE *table, struct ft_border_style *style)
|
||||
int ft_set_border_style(ft_table_t *table, struct ft_border_style *style)
|
||||
{
|
||||
assert(table);
|
||||
if (table->options == NULL) {
|
||||
@ -909,7 +909,7 @@ int ft_set_border_style(FTABLE *table, struct ft_border_style *style)
|
||||
|
||||
|
||||
|
||||
int ft_set_cell_option(FTABLE *table, size_t row, size_t col, uint32_t option, int value)
|
||||
int ft_set_cell_option(ft_table_t *table, size_t row, size_t col, uint32_t option, int value)
|
||||
{
|
||||
assert(table);
|
||||
|
||||
@ -944,7 +944,7 @@ int ft_set_default_tbl_option(uint32_t option, int value)
|
||||
return set_default_entire_table_option(option, value);
|
||||
}
|
||||
|
||||
int ft_set_tbl_option(FTABLE *table, uint32_t option, int value)
|
||||
int ft_set_tbl_option(ft_table_t *table, uint32_t option, int value)
|
||||
{
|
||||
assert(table);
|
||||
|
||||
@ -961,7 +961,7 @@ void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *pt
|
||||
set_memory_funcs(f_malloc, f_free);
|
||||
}
|
||||
|
||||
int ft_set_cell_span(FTABLE *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);
|
||||
if (hor_span < 2)
|
||||
|
@ -47,13 +47,13 @@ enum F_BOOL
|
||||
};
|
||||
|
||||
|
||||
#define STR_2_CAT_(arg1, arg2) \
|
||||
#define FT_STR_2_CAT_(arg1, arg2) \
|
||||
arg1##arg2
|
||||
#define STR_2_CAT(arg1, arg2) \
|
||||
STR_2_CAT_(arg1, arg2)
|
||||
#define FT_STR_2_CAT(arg1, arg2) \
|
||||
FT_STR_2_CAT_(arg1, arg2)
|
||||
|
||||
#define UNIQUE_NAME_(prefix) \
|
||||
STR_2_CAT(prefix,__COUNTER__)
|
||||
FT_STR_2_CAT(prefix,__COUNTER__)
|
||||
#define UNIQUE_NAME(prefix) \
|
||||
UNIQUE_NAME_(prefix)
|
||||
|
||||
@ -98,7 +98,7 @@ typedef struct vector vector_t;
|
||||
typedef struct fort_cell fort_cell_t;
|
||||
typedef struct string_buffer string_buffer_t;
|
||||
typedef struct fort_row fort_row_t;
|
||||
typedef struct fort_table FTABLE;
|
||||
typedef struct ft_table ft_table_t;
|
||||
typedef struct separator separator_t;
|
||||
|
||||
|
||||
|
20
src/table.c
20
src/table.c
@ -3,11 +3,11 @@
|
||||
#include "cell.h"
|
||||
#include "vector.h"
|
||||
#include "row.h"
|
||||
fort_status_t get_table_sizes(const FTABLE *table, size_t *rows, size_t *cols);
|
||||
fort_status_t get_table_sizes(const ft_table_t *table, size_t *rows, size_t *cols);
|
||||
|
||||
|
||||
|
||||
fort_row_t *get_row_implementation(fort_table_t *table, size_t row, enum PolicyOnNull policy)
|
||||
fort_row_t *get_row_implementation(ft_table_t *table, size_t row, enum PolicyOnNull policy)
|
||||
{
|
||||
if (table == NULL || table->rows == NULL) {
|
||||
return NULL;
|
||||
@ -36,17 +36,17 @@ fort_row_t *get_row_implementation(fort_table_t *table, size_t row, enum PolicyO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fort_row_t *get_row(fort_table_t *table, size_t row)
|
||||
fort_row_t *get_row(ft_table_t *table, size_t row)
|
||||
{
|
||||
return get_row_implementation(table, row, DoNotCreate);
|
||||
}
|
||||
|
||||
const fort_row_t *get_row_c(const fort_table_t *table, size_t row)
|
||||
const fort_row_t *get_row_c(const ft_table_t *table, size_t row)
|
||||
{
|
||||
return get_row((fort_table_t *)table, row);
|
||||
return get_row((ft_table_t *)table, row);
|
||||
}
|
||||
|
||||
fort_row_t *get_row_and_create_if_not_exists(fort_table_t *table, size_t row)
|
||||
fort_row_t *get_row_and_create_if_not_exists(ft_table_t *table, size_t row)
|
||||
{
|
||||
return get_row_implementation(table, row, Create);
|
||||
}
|
||||
@ -54,7 +54,7 @@ fort_row_t *get_row_and_create_if_not_exists(fort_table_t *table, size_t row)
|
||||
|
||||
|
||||
|
||||
string_buffer_t *get_cur_str_buffer_and_create_if_not_exists(FTABLE *table)
|
||||
string_buffer_t *get_cur_str_buffer_and_create_if_not_exists(ft_table_t *table)
|
||||
{
|
||||
assert(table);
|
||||
|
||||
@ -72,7 +72,7 @@ string_buffer_t *get_cur_str_buffer_and_create_if_not_exists(FTABLE *table)
|
||||
/*
|
||||
* Returns number of cells (rows * cols)
|
||||
*/
|
||||
fort_status_t get_table_sizes(const FTABLE *table, size_t *rows, size_t *cols)
|
||||
fort_status_t get_table_sizes(const ft_table_t *table, size_t *rows, size_t *cols)
|
||||
{
|
||||
*rows = 0;
|
||||
*cols = 0;
|
||||
@ -88,7 +88,7 @@ fort_status_t get_table_sizes(const FTABLE *table, size_t *rows, size_t *cols)
|
||||
return FT_SUCCESS;
|
||||
}
|
||||
|
||||
fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
|
||||
fort_status_t table_rows_and_cols_geometry(const ft_table_t *table,
|
||||
size_t **col_width_arr_p, size_t *col_width_arr_sz,
|
||||
size_t **row_height_arr_p, size_t *row_height_arr_sz)
|
||||
{
|
||||
@ -197,7 +197,7 @@ fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
|
||||
/*
|
||||
* Returns geometry in characters
|
||||
*/
|
||||
fort_status_t table_geometry(const FTABLE *table, size_t *height, size_t *width)
|
||||
fort_status_t table_geometry(const ft_table_t *table, size_t *height, size_t *width)
|
||||
{
|
||||
if (table == NULL)
|
||||
return FT_ERROR;
|
||||
|
22
src/table.h
22
src/table.h
@ -4,9 +4,9 @@
|
||||
#include "fort_impl.h"
|
||||
#include "fort.h"
|
||||
|
||||
struct fort_table;
|
||||
typedef struct fort_table fort_table_t;
|
||||
struct fort_table
|
||||
struct ft_table;
|
||||
typedef struct ft_table ft_table_t;
|
||||
struct ft_table
|
||||
{
|
||||
vector_t *rows;
|
||||
fort_table_options_t *options;
|
||||
@ -34,19 +34,19 @@ void destroy_separator(separator_t *sep)
|
||||
|
||||
|
||||
|
||||
fort_status_t get_table_sizes(const FTABLE *table, size_t *rows, size_t *cols);
|
||||
fort_row_t *get_row_implementation(fort_table_t *table, size_t row, enum PolicyOnNull policy);
|
||||
fort_row_t *get_row(fort_table_t *table, size_t row);
|
||||
const fort_row_t *get_row_c(const fort_table_t *table, size_t row);
|
||||
fort_row_t *get_row_and_create_if_not_exists(fort_table_t *table, size_t row);
|
||||
fort_status_t get_table_sizes(const ft_table_t *table, size_t *rows, size_t *cols);
|
||||
fort_row_t *get_row_implementation(ft_table_t *table, size_t row, enum PolicyOnNull policy);
|
||||
fort_row_t *get_row(ft_table_t *table, size_t row);
|
||||
const fort_row_t *get_row_c(const ft_table_t *table, size_t row);
|
||||
fort_row_t *get_row_and_create_if_not_exists(ft_table_t *table, size_t row);
|
||||
|
||||
string_buffer_t * get_cur_str_buffer_and_create_if_not_exists(FTABLE * table);
|
||||
string_buffer_t * get_cur_str_buffer_and_create_if_not_exists(ft_table_t * table);
|
||||
|
||||
|
||||
|
||||
fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
|
||||
fort_status_t table_rows_and_cols_geometry(const ft_table_t *table,
|
||||
size_t **col_width_arr_p, size_t *col_width_arr_sz,
|
||||
size_t **row_height_arr_p, size_t *row_height_arr_sz);
|
||||
fort_status_t table_geometry(const FTABLE *table, size_t *height, size_t *width);
|
||||
fort_status_t table_geometry(const ft_table_t *table, size_t *height, size_t *width);
|
||||
|
||||
#endif /* TABLE_H */
|
||||
|
@ -25,7 +25,7 @@ void test_free(void *ptr)
|
||||
|
||||
static int create_simple_table_and_show(void)
|
||||
{
|
||||
FTABLE *table = NULL;
|
||||
ft_table_t *table = NULL;
|
||||
int result = 0;
|
||||
|
||||
table = ft_create_table();
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
void test_table_basic(void)
|
||||
{
|
||||
FTABLE *table = NULL;
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
WHEN("All columns are equal and not empty") {
|
||||
table = ft_create_table();
|
||||
@ -261,7 +261,7 @@ void test_table_basic(void)
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
void test_wcs_table_boundaries(void)
|
||||
{
|
||||
FTABLE *table = NULL;
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
WHEN("All columns are not equal and not empty (wide strings)") {
|
||||
table = ft_create_table();
|
||||
@ -298,7 +298,7 @@ void test_wcs_table_boundaries(void)
|
||||
|
||||
void test_table_write(void)
|
||||
{
|
||||
FTABLE *table = NULL;
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
SCENARIO("Test write functions") {
|
||||
table = ft_create_table();
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
void test_table_border_style(void)
|
||||
{
|
||||
FTABLE *table = NULL;
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
set_test_options_as_default();
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
void test_table_sizes(void)
|
||||
{
|
||||
FTABLE *table = ft_create_table();
|
||||
ft_table_t *table = ft_create_table();
|
||||
assert_true(table != NULL);
|
||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
@ -53,7 +53,7 @@ void test_table_sizes(void)
|
||||
|
||||
void test_table_geometry(void)
|
||||
{
|
||||
FTABLE *table = ft_create_table();
|
||||
ft_table_t *table = ft_create_table();
|
||||
assert_true(table != NULL);
|
||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
void test_table_tbl_options(void)
|
||||
{
|
||||
FTABLE *table = NULL;
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
WHEN("Test setting entire table options") {
|
||||
set_test_options_as_default();
|
||||
@ -134,7 +134,7 @@ void test_table_tbl_options(void)
|
||||
|
||||
void test_table_cell_options(void)
|
||||
{
|
||||
FTABLE *table = NULL;
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
|
||||
WHEN("All paddings = 1") {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "tests.h"
|
||||
#include "fort.h"
|
||||
|
||||
int set_test_options_for_table(FTABLE *table)
|
||||
int set_test_options_for_table(ft_table_t *table)
|
||||
{
|
||||
assert(table);
|
||||
int status = FT_SUCCESS;
|
||||
@ -71,9 +71,9 @@ int set_test_options_as_default(void)
|
||||
|
||||
|
||||
|
||||
FTABLE *create_test_int_table(int set_test_opts)
|
||||
ft_table_t *create_test_int_table(int set_test_opts)
|
||||
{
|
||||
FTABLE *table = NULL;
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
table = ft_create_table();
|
||||
assert_true(table != NULL);
|
||||
@ -102,9 +102,9 @@ FTABLE *create_test_int_table(int set_test_opts)
|
||||
}
|
||||
|
||||
#ifdef FT_HAVE_WCHAR
|
||||
FTABLE *create_test_int_wtable(int set_test_opts)
|
||||
ft_table_t *create_test_int_wtable(int set_test_opts)
|
||||
{
|
||||
FTABLE *table = NULL;
|
||||
ft_table_t *table = NULL;
|
||||
|
||||
table = ft_create_table();
|
||||
assert_true(table != NULL);
|
||||
|
@ -62,10 +62,10 @@ struct test_case
|
||||
exit(EXIT_FAILURE); \
|
||||
}
|
||||
|
||||
int set_test_options_for_table(FTABLE *table);
|
||||
int set_test_options_for_table(ft_table_t *table);
|
||||
int set_test_options_as_default(void);
|
||||
FTABLE *create_test_int_table(int set_test_opts);
|
||||
FTABLE *create_test_int_wtable(int set_test_opts);
|
||||
ft_table_t *create_test_int_table(int set_test_opts);
|
||||
ft_table_t *create_test_int_wtable(int set_test_opts);
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user