From 23fb962f0a77666ac3c7ee09dd94c1bca661ebd6 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Sat, 31 Mar 2018 13:33:37 +0300 Subject: [PATCH] [A] Added astyle --- .travis.yml | 74 ++++-- CMakeLists.txt | 80 +++++- example/main.c | 14 +- include/fort.h | 99 ++++--- src/cell.c | 27 +- src/fort.c | 107 ++++---- src/fort_impl.c | 8 +- src/options.c | 36 ++- src/row.c | 69 +++-- src/row.h | 2 +- src/string_buffer.c | 26 +- src/table.c | 14 +- src/table.h | 2 +- src/vector.c | 31 ++- src/wcwidth.c | 337 ++++++++++++------------ tests/test.c | 3 +- tests/test_string_buffer.c | 42 +-- tests/test_table_basic.c | 450 ++++++++++++++++---------------- tests/test_table_border_style.c | 80 +++--- tests/test_table_geometry.c | 60 ++--- tests/test_table_options.c | 404 ++++++++++++++-------------- tests/test_utility.c | 16 +- tests/test_vector.c | 46 ++-- tests/tests.h | 3 +- 24 files changed, 1069 insertions(+), 961 deletions(-) diff --git a/.travis.yml b/.travis.yml index d11eb3a..07bc35b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ matrix: sudo: required # to prevent fail of executables build with clang and sanitizers compiler: clang env: CC=clang + # Linux / GCC @@ -87,30 +88,63 @@ script: - ./libfort_test # Test build without optimizations and with ubsan - - if [ "${CC}" == 'gcc-7' ]; - then - cd .. ; - rm -r build/* ; - cd build ; - cmake .. -DFORT_BUILD_TYPE=ubsan ; - cmake --build . --target all ; - ls ; - ./libfort_example ; - ./libfort_test ; + - | + if [ "${CC}" = 'gcc-7' ]; then + cd .. ; + rm -r build/* ; + cd build ; + cmake .. -DFORT_BUILD_TYPE=ubsan ; + cmake --build . --target all ; + ls ; + ./libfort_example ; + ./libfort_test ; fi # Build for coveralls - - if [ "${CC}" == 'gcc' ]; - then - cd .. ; - rm -r build/* ; - cd build ; - cmake .. -DFORT_BUILD_TYPE=coveralls ; - cmake --build . --target all ; - ls ; - ./libfort_test ; + - | + if [ "${CC}" = 'gcc' ]; then + cd .. ; + rm -r build/* ; + cd build ; + cmake .. -DFORT_BUILD_TYPE=coveralls ; + cmake --build . --target all ; + ls ; + ./libfort_test ; + fi + + # Astyle Format + - | + if [ "${CC}" = 'gcc' ]; then + ls + cd .. ; + rm -r build/* ; + cd build ; + cmake .. -DFORT_ENABLE_ASTYLE=ON ; + make ; + make format ; + cd .. ; + if [[ -n $(git diff) ]]; then + echo "You must run make format before submitting a pull request" ; + echo "" ; + git diff ; + exit -1 ; + fi + cd build ; + fi + + + # Clang static analyzer + - | + if [ "${CC}" = 'clang' ]; then + cd .. ; + pwd ; + ls ; + rm -rf build/* ; + cd build ; + cmake .. ; + scan-build make ; fi - - cd .. + diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c90d11..cb3d08e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,9 +2,11 @@ project(libfort) # Required cmake version cmake_minimum_required(VERSION 2.8) +include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) # Built options option(FORT_CXX_BUILD "Compile with c++ compiler instead of c" OFF) +option(FORT_ENABLE_ASTYLE "Enable astyle" OFF) set(FORT_BUILD_TYPE "common" CACHE STRING "Built types (possible values: common, asan, ubsan, coveralls)") @@ -19,11 +21,21 @@ endif(FORT_CXX_BUILD) set(CMAKE_VERBOSE_MAKEFILE ON) + +# ------------------------------------------------------------------------------ +# Includes +# ------------------------------------------------------------------------------ + include_directories(include) include_directories(src) -# Turn on warnings + + +# ------------------------------------------------------------------------------ +# Warnings +# ------------------------------------------------------------------------------ + if(FORT_COMPILER STREQUAL "MSVC") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W4") else(FORT_COMPILER STREQUAL "MSVC") @@ -34,6 +46,9 @@ endif(FORT_COMPILER STREQUAL "MSVC") +# ------------------------------------------------------------------------------ +# Sources and executables +# ------------------------------------------------------------------------------ FILE(GLOB_RECURSE FortHeaders "include/*.h" "tests/*.h" "src/*.h") add_custom_target(headers SOURCES ${FortHeaders}) @@ -82,8 +97,10 @@ endif(FORT_CXX_BUILD) +# ------------------------------------------------------------------------------ +# sanitizers +# ------------------------------------------------------------------------------ -# Adding sanitizers if(FORT_COMPILER STREQUAL "GNU" OR FORT_COMPILER STREQUAL "Clang") # asan case if(FORT_BUILD_TYPE STREQUAL "asan") @@ -118,3 +135,62 @@ if(FORT_COMPILER STREQUAL "GNU") endif(FORT_COMPILER STREQUAL "GNU") + +# ------------------------------------------------------------------------------ +# Astyle +# ------------------------------------------------------------------------------ + +if(FORT_ENABLE_ASTYLE) + list(APPEND ASTYLE_CMAKE_ARGS + "-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}" + ) + + ExternalProject_Add( + astyle + GIT_REPOSITORY https://github.com/Bareflank/astyle.git + GIT_TAG v1.2 + GIT_SHALLOW 1 + CMAKE_ARGS ${ASTYLE_CMAKE_ARGS} + PREFIX ${CMAKE_BINARY_DIR}/external/astyle/prefix + TMP_DIR ${CMAKE_BINARY_DIR}/external/astyle/tmp + STAMP_DIR ${CMAKE_BINARY_DIR}/external/astyle/stamp + DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/external/astyle/download + SOURCE_DIR ${CMAKE_BINARY_DIR}/external/astyle/src + BINARY_DIR ${CMAKE_BINARY_DIR}/external/astyle/build + ) + + list(APPEND ASTYLE_ARGS + --style=kr + --lineend=linux + --suffix=none + --pad-oper + --unpad-paren + --align-pointer=name + --align-reference=name + --indent-switches + --keep-one-line-statements + --keep-one-line-blocks + --pad-header + --convert-tabs + --min-conditional-indent=0 + --indent=spaces=4 + ${CMAKE_SOURCE_DIR}/include/*.h + ${CMAKE_SOURCE_DIR}/src/*.c + ${CMAKE_SOURCE_DIR}/tests/*.c + ) + + if(NOT WIN32 STREQUAL "1") + add_custom_target( + format + COMMAND ${CMAKE_BINARY_DIR}/bin/astyle ${ASTYLE_ARGS} + COMMENT "running astyle" + ) + else() + add_custom_target( + format + COMMAND ${CMAKE_BINARY_DIR}/bin/astyle.exe ${ASTYLE_ARGS} + COMMENT "running astyle" + ) + endif() + +endif() diff --git a/example/main.c b/example/main.c index d7f7230..6fe45aa 100644 --- a/example/main.c +++ b/example/main.c @@ -25,6 +25,7 @@ int main(int argc, char *argv[]) { (void)argc; (void)argv; + int result = 0; FTABLE *table = NULL; @@ -170,13 +171,16 @@ int main(int argc, char *argv[]) /*FT_NWWRITE_LN(table, L"3", L"\x41a\x43e\x441\x43c\x438\x447\x435\x441\x43a\x430\x44f \x43e\x434\x438\x441\x441\x435\x44f 2001 \x433\x43e\x434\x430", L"1968", L"8.5");*/ /* Космическая одиссея 2001 года */ /*FT_NWWRITE_LN(table, L"4", L"\x411\x435\x433\x443\x449\x438\x439 \x43f\x43e \x43b\x435\x437\x432\x438\x44e", L"1982", L"8.1");*/ /* Бегущий по лезвию */ - fwprintf(stderr, L"Table:\n%ls\n ", ft_to_wstring(table)); + const wchar_t* table_wstr = ft_to_wstring(table); + if (table_wstr) { + fwprintf(stderr, L"Table:\n%ls\n ", table_wstr); + } else { + fwprintf(stderr, L"Table conversion failed !!!\n "); + result += 1; + } ft_destroy_table(table); #endif - - table = NULL; - - return 0; + return result; } diff --git a/include/fort.h b/include/fort.h index 948625c..5659edd 100644 --- a/include/fort.h +++ b/include/fort.h @@ -51,20 +51,21 @@ SOFTWARE. /* * 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) */ +#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) */ - +#endif // __STDC_VERSION__ < 199901L +#endif // if defined(__cplusplus) +*/ /* @@ -92,9 +93,9 @@ SOFTWARE. /* * C++ needs to know that types and declarations are C, not C++. */ -#ifdef __cplusplus -# define FT_BEGIN_DECLS extern "C" { -# define FT_END_DECLS } +#ifdef __cplusplus +# define FT_BEGIN_DECLS extern "C" { +# define FT_END_DECLS } #else # define FT_BEGIN_DECLS # define FT_END_DECLS @@ -125,13 +126,13 @@ SOFTWARE. STR_2_CAT_(arg1, arg2) -static FT_INLINE int ft_check_if_string_helper(const char*str) +static FT_INLINE int ft_check_if_string_helper(const char *str) { (void)str; return 0; } -static FT_INLINE int ft_check_if_wstring_helper(const wchar_t*str) +static FT_INLINE int ft_check_if_wstring_helper(const wchar_t *str) { (void)str; return 0; @@ -208,21 +209,21 @@ FT_BEGIN_DECLS struct fort_table; typedef struct fort_table FTABLE; -FT_EXTERN FTABLE * ft_create_table(void); -FT_EXTERN void ft_destroy_table(FTABLE *FT_RESTRICT table); +FT_EXTERN FTABLE *ft_create_table(void); +FT_EXTERN void ft_destroy_table(FTABLE *table); -FT_EXTERN void ft_ln(FTABLE *FT_RESTRICT table); +FT_EXTERN void ft_ln(FTABLE *table); #if defined(FT_CLANG_COMPILER) || defined(FT_GCC_COMPILER) -FT_EXTERN int ft_printf(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3); -FT_EXTERN int ft_printf_ln(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3); +FT_EXTERN int ft_printf(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3); +FT_EXTERN int ft_printf_ln(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3); #else -FT_EXTERN int ft_printf_impl(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3); -FT_EXTERN int ft_printf_ln_impl(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3); +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); #define ft_printf(table, ...) \ (( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf_impl(table, __VA_ARGS__)) @@ -232,43 +233,43 @@ FT_EXTERN int ft_printf_ln_impl(FTABLE *FT_RESTRICT table, const char* FT_RESTRI -FT_EXTERN int ft_write(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT cell_content); -FT_EXTERN int ft_write_ln(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT cell_content); +FT_EXTERN int ft_write(FTABLE *table, const char *cell_content); +FT_EXTERN int ft_write_ln(FTABLE *table, const char *cell_content); #define FT_NWRITE(table, ...)\ (0 ? CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite(table, PP_NARG(__VA_ARGS__), __VA_ARGS__)) #define FT_NWRITE_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 *FT_RESTRICT table, size_t n, const char* FT_RESTRICT cell_content, ...); -FT_EXTERN int ft_nwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const char* FT_RESTRICT cell_content, ...); +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, ...); -FT_EXTERN int ft_row_write(FTABLE *FT_RESTRICT table, size_t cols, const char* FT_RESTRICT row_cells[]); -FT_EXTERN int ft_row_write_ln(FTABLE *FT_RESTRICT table, size_t cols, const char* FT_RESTRICT row_cells[]); +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[]); #if !defined(__cplusplus) && !defined(FT_MICROSOFT_COMPILER) -FT_EXTERN int ft_s_table_write(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const char* FT_RESTRICT table_cells[rows][cols]); -FT_EXTERN int ft_s_table_write_ln(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const char* FT_RESTRICT table_cells[rows][cols]); +FT_EXTERN int ft_s_table_write(FTABLE *table, size_t rows, size_t cols, const char *table_cells[rows][cols]); +FT_EXTERN int ft_s_table_write_ln(FTABLE *table, size_t rows, size_t cols, const char *table_cells[rows][cols]); -FT_EXTERN int ft_table_write(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const char* * FT_RESTRICT table_cells[rows]); -FT_EXTERN int ft_table_write_ln(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const char* * FT_RESTRICT table_cells[rows]); +FT_EXTERN int ft_table_write(FTABLE *table, size_t rows, size_t cols, const char * * table_cells[rows]); +FT_EXTERN int ft_table_write_ln(FTABLE *table, size_t rows, size_t cols, const char * * table_cells[rows]); #endif -FT_EXTERN int ft_add_separator(FTABLE *FT_RESTRICT table); +FT_EXTERN int ft_add_separator(FTABLE *table); -FT_EXTERN const char* ft_to_string(const FTABLE *FT_RESTRICT table); +FT_EXTERN const char *ft_to_string(const FTABLE *table); /* @@ -300,21 +301,18 @@ FT_EXTERN const char* ft_to_string(const FTABLE *FT_RESTRICT table); #define FT_TOPT_RIGHT_MARGIN ((uint32_t)(0x01U << (2))) #define FT_TOPT_BOTTOM_MARGIN ((uint32_t)(0x01U << (3))) -enum TextAlignment -{ +enum TextAlignment { LeftAligned, CenterAligned, RightAligned }; -enum RowType -{ +enum RowType { Common, Header }; -struct ft_border_chars -{ +struct ft_border_chars { char top_border_ch; char separator_ch; char bottom_border_ch; @@ -323,29 +321,28 @@ struct ft_border_chars char in_intersect_ch; }; -struct ft_border_style -{ +struct ft_border_style { struct ft_border_chars border_chs; struct ft_border_chars header_border_chs; char hor_separator_char; }; /* List of built-in table border styles */ -extern struct ft_border_style * FT_BASIC_STYLE; -extern struct ft_border_style * FT_SIMPLE_STYLE; -extern struct ft_border_style * FT_PLAIN_STYLE; -extern struct ft_border_style * FT_DOT_STYLE; -extern struct ft_border_style * FT_EMPTY_STYLE; +extern struct ft_border_style *FT_BASIC_STYLE; +extern struct ft_border_style *FT_SIMPLE_STYLE; +extern struct ft_border_style *FT_PLAIN_STYLE; +extern struct ft_border_style *FT_DOT_STYLE; +extern struct ft_border_style *FT_EMPTY_STYLE; FT_EXTERN int ft_set_default_border_style(struct ft_border_style *style); -FT_EXTERN int ft_set_border_style(FTABLE * FT_RESTRICT table, struct ft_border_style *style); +FT_EXTERN int ft_set_border_style(FTABLE *table, struct ft_border_style *style); FT_EXTERN int ft_set_default_cell_option(uint32_t option, int value); -FT_EXTERN int ft_set_cell_option(FTABLE * FT_RESTRICT table, unsigned row, unsigned col, uint32_t option, int value); +FT_EXTERN int ft_set_cell_option(FTABLE *table, unsigned row, unsigned col, uint32_t option, int value); FT_EXTERN int ft_set_default_tbl_option(uint32_t option, int value); -FT_EXTERN int ft_set_tbl_option(FTABLE * FT_RESTRICT table, uint32_t option, int value); +FT_EXTERN int ft_set_tbl_option(FTABLE *table, uint32_t option, int value); @@ -356,20 +353,20 @@ FT_EXTERN int ft_set_tbl_option(FTABLE * FT_RESTRICT table, uint32_t option, int #ifdef FT_HAVE_WCHAR -FT_EXTERN int ft_wwrite(FTABLE *FT_RESTRICT table, const wchar_t* FT_RESTRICT cell_content); -FT_EXTERN int ft_wwrite_ln(FTABLE *FT_RESTRICT table, const wchar_t* FT_RESTRICT cell_content); +FT_EXTERN int ft_wwrite(FTABLE *table, const wchar_t *cell_content); +FT_EXTERN int ft_wwrite_ln(FTABLE *table, const wchar_t *cell_content); #define FT_NWWRITE(table, ...)\ (0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite(table, PP_NARG(__VA_ARGS__), __VA_ARGS__)) #define FT_NWWRITE_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 *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRICT cell_content, ...); -FT_EXTERN int ft_nwwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRICT cell_content, ...); +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, ...); -FT_EXTERN int ft_row_wwrite(FTABLE *FT_RESTRICT table, size_t cols, const wchar_t* FT_RESTRICT row_cells[]); -FT_EXTERN int ft_row_wwrite_ln(FTABLE *FT_RESTRICT table, size_t cols, const wchar_t* FT_RESTRICT row_cells[]); +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[]); -FT_EXTERN const wchar_t* ft_to_wstring(const FTABLE *FT_RESTRICT table); +FT_EXTERN const wchar_t *ft_to_wstring(const FTABLE *table); #endif diff --git a/src/cell.c b/src/cell.c index 89ac43e..9f2174d 100644 --- a/src/cell.c +++ b/src/cell.c @@ -8,13 +8,12 @@ * ***************************************************************************/ -struct fort_cell -{ +struct fort_cell { string_buffer_t *str_buffer; fort_table_options_t *options; }; -fort_cell_t * create_cell(void) +fort_cell_t *create_cell(void) { fort_cell_t *cell = (fort_cell_t *)F_CALLOC(sizeof(fort_cell_t), 1); if (cell == NULL) @@ -25,7 +24,7 @@ fort_cell_t * create_cell(void) return NULL; } cell->options = NULL; -/* init_cell_options(&(cell->options)); */ + /*init_cell_options(&(cell->options));*/ return cell; } @@ -98,12 +97,12 @@ static int lines_number_cell(fort_cell_t *cell) int cell_printf(fort_cell_t *cell, size_t row, char *buf, size_t buf_len, const context_t *context) { char space_char = ' '; - int (*buffer_printf_)(string_buffer_t *, size_t ,char *, size_t , const context_t *) = buffer_printf; - int (*snprint_n_chars_)(char *, size_t , size_t , char) = snprint_n_chars; + int (*buffer_printf_)(string_buffer_t *, size_t, char *, size_t, const context_t *) = buffer_printf; + int (*snprint_n_chars_)(char *, size_t, size_t, char) = snprint_n_chars; if (cell == NULL || buf_len == 0 - || (buf_len <= hint_width_cell(cell, context))) { + || (buf_len <= hint_width_cell(cell, context))) { return -1; } @@ -112,8 +111,8 @@ int cell_printf(fort_cell_t *cell, size_t row, char *buf, size_t buf_len, const int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING); if (row >= hint_height_cell(cell, context) - || row < cell_padding_top - || row >= (cell_padding_top + buffer_text_height(cell->str_buffer))) { + || row < cell_padding_top + || row >= (cell_padding_top + buffer_text_height(cell->str_buffer))) { return snprint_n_chars_(buf, buf_len, buf_len - 1, space_char); } @@ -150,12 +149,12 @@ clear: int cell_wprintf(fort_cell_t *cell, size_t row, wchar_t *buf, size_t buf_len, const context_t *context) { wchar_t space_char = L' '; - int (*buffer_printf_)(string_buffer_t *, size_t , wchar_t *, size_t , const context_t *) = buffer_wprintf; - int (*snprint_n_chars_)(wchar_t *, size_t , size_t , wchar_t) = wsnprint_n_chars; + int (*buffer_printf_)(string_buffer_t *, size_t, wchar_t *, size_t, const context_t *) = buffer_wprintf; + int (*snprint_n_chars_)(wchar_t *, size_t, size_t, wchar_t) = wsnprint_n_chars; if (cell == NULL || buf_len == 0 - || (buf_len <= hint_width_cell(cell, context))) { + || (buf_len <= hint_width_cell(cell, context))) { return -1; } @@ -164,8 +163,8 @@ int cell_wprintf(fort_cell_t *cell, size_t row, wchar_t *buf, size_t buf_len, co int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING); if (row >= hint_height_cell(cell, context) - || row < cell_padding_top - || row >= (cell_padding_top + buffer_text_height(cell->str_buffer))) { + || row < cell_padding_top + || row >= (cell_padding_top + buffer_text_height(cell->str_buffer))) { return snprint_n_chars_(buf, buf_len, buf_len - 1, space_char); } diff --git a/src/fort.c b/src/fort.c index 568fcc6..81f3f9a 100644 --- a/src/fort.c +++ b/src/fort.c @@ -47,18 +47,18 @@ SOFTWARE. * LIBFORT * ***************************************************************************/ -FTABLE * ft_create_table(void) +FTABLE *ft_create_table(void) { FTABLE *result = (FTABLE *)F_CALLOC(1, sizeof(FTABLE)); if (result == NULL) return NULL; - result->rows = create_vector(sizeof(fort_row_t*), DEFAULT_VECTOR_CAPACITY); + result->rows = create_vector(sizeof(fort_row_t *), DEFAULT_VECTOR_CAPACITY); if (result->rows == NULL) { F_FREE(result); return NULL; } - result->separators = create_vector(sizeof(separator_t*), DEFAULT_VECTOR_CAPACITY); + result->separators = create_vector(sizeof(separator_t *), DEFAULT_VECTOR_CAPACITY); if (result->separators == NULL) { destroy_vector(result->rows); F_FREE(result); @@ -72,7 +72,7 @@ FTABLE * ft_create_table(void) } -void ft_destroy_table(FTABLE *FT_RESTRICT table) +void ft_destroy_table(FTABLE *table) { size_t i = 0; @@ -98,7 +98,7 @@ void ft_destroy_table(FTABLE *FT_RESTRICT table) F_FREE(table); } -void ft_ln(FTABLE *FT_RESTRICT table) +void ft_ln(FTABLE *table) { assert(table); table->cur_col = 0; @@ -106,7 +106,7 @@ void ft_ln(FTABLE *FT_RESTRICT table) } -static int ft_row_printf_impl(FTABLE *FT_RESTRICT table, size_t row, const char* FT_RESTRICT fmt, va_list *va) +static int ft_row_printf_impl(FTABLE *table, size_t row, const char *fmt, va_list *va) { size_t i = 0; size_t new_cols = 0; @@ -138,7 +138,7 @@ static int ft_row_printf_impl(FTABLE *FT_RESTRICT table, size_t row, const char* /* todo: clearing pushed items in case of error */ /* todo: this function always create new row, this is not correct, it should be more complicated */ - cur_row_p = (fort_row_t**)vector_at(table->rows, row); + cur_row_p = (fort_row_t **)vector_at(table->rows, row); destroy_row(*cur_row_p); *cur_row_p = new_row; @@ -162,7 +162,7 @@ clear: -int FT_PRINTF(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT fmt, ...) +int FT_PRINTF(FTABLE *table, const char *fmt, ...) { assert(table); va_list va; @@ -172,7 +172,7 @@ int FT_PRINTF(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT fmt, ...) return result; } -int FT_PRINTF_LN(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT fmt, ...) +int FT_PRINTF_LN(FTABLE *table, const char *fmt, ...) { assert(table); va_list va; @@ -191,7 +191,7 @@ int FT_PRINTF_LN(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT fmt, ...) #undef FT_HDR_PRINTF_LN -int ft_write(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT cell_content) +int ft_write(FTABLE *table, const char *cell_content) { assert(table); string_buffer_t *str_buffer = get_cur_str_buffer_and_create_if_not_exists(table); @@ -205,7 +205,7 @@ int ft_write(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT cell_content) return status; } -int ft_write_ln(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT cell_content) +int ft_write_ln(FTABLE *table, const char *cell_content) { assert(table); int status = ft_write(table, cell_content); @@ -217,7 +217,7 @@ int ft_write_ln(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT cell_content) #ifdef FT_HAVE_WCHAR -int ft_wwrite(FTABLE *FT_RESTRICT table, const wchar_t* FT_RESTRICT cell_content) +int ft_wwrite(FTABLE *table, const wchar_t *cell_content) { assert(table); string_buffer_t *str_buffer = get_cur_str_buffer_and_create_if_not_exists(table); @@ -231,7 +231,7 @@ int ft_wwrite(FTABLE *FT_RESTRICT table, const wchar_t* FT_RESTRICT cell_content return status; } -int ft_wwrite_ln(FTABLE *FT_RESTRICT table, const wchar_t* FT_RESTRICT cell_content) +int ft_wwrite_ln(FTABLE *table, const wchar_t *cell_content) { assert(table); int status = ft_wwrite(table, cell_content); @@ -243,7 +243,7 @@ int ft_wwrite_ln(FTABLE *FT_RESTRICT table, const wchar_t* FT_RESTRICT cell_cont #endif -int ft_nwrite(FTABLE *FT_RESTRICT table, size_t n, const char* FT_RESTRICT cell_content, ...) +int ft_nwrite(FTABLE *table, size_t n, const char *cell_content, ...) { size_t i = 0; assert(table); @@ -255,7 +255,7 @@ int ft_nwrite(FTABLE *FT_RESTRICT table, size_t n, const char* FT_RESTRICT cell_ va_start(va, cell_content); --n; for (i = 0; i < n; ++i) { - const char *cell = va_arg(va, const char*); + const char *cell = va_arg(va, const char *); status = ft_write(table, cell); if (IS_ERROR(status)) return status; @@ -264,7 +264,7 @@ int ft_nwrite(FTABLE *FT_RESTRICT table, size_t n, const char* FT_RESTRICT cell_ return status; } -int ft_nwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const char* FT_RESTRICT cell_content, ...) +int ft_nwrite_ln(FTABLE *table, size_t n, const char *cell_content, ...) { size_t i = 0; assert(table); @@ -276,7 +276,7 @@ int ft_nwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const char* FT_RESTRICT ce va_start(va, cell_content); --n; for (i = 0; i < n; ++i) { - const char *cell = va_arg(va, const char*); + const char *cell = va_arg(va, const char *); status = ft_write(table, cell); if (IS_ERROR(status)) { va_end(va); @@ -291,7 +291,7 @@ int ft_nwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const char* FT_RESTRICT ce #ifdef FT_HAVE_WCHAR -int ft_nwwrite(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRICT cell_content, ...) +int ft_nwwrite(FTABLE *table, size_t n, const wchar_t *cell_content, ...) { size_t i = 0; assert(table); @@ -303,7 +303,7 @@ int ft_nwwrite(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRICT c va_start(va, cell_content); --n; for (i = 0; i < n; ++i) { - const wchar_t *cell = va_arg(va, const wchar_t*); + const wchar_t *cell = va_arg(va, const wchar_t *); status = ft_wwrite(table, cell); if (IS_ERROR(status)) return status; @@ -312,7 +312,7 @@ int ft_nwwrite(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRICT c return status; } -int ft_nwwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRICT cell_content, ...) +int ft_nwwrite_ln(FTABLE *table, size_t n, const wchar_t *cell_content, ...) { size_t i = 0; assert(table); @@ -324,7 +324,7 @@ int ft_nwwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRIC va_start(va, cell_content); --n; for (i = 0; i < n; ++i) { - const wchar_t *cell = va_arg(va, const wchar_t*); + const wchar_t *cell = va_arg(va, const wchar_t *); status = ft_wwrite(table, cell); if (IS_ERROR(status)) { va_end(va); @@ -339,7 +339,7 @@ int ft_nwwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRIC #endif -int ft_row_write(FTABLE *FT_RESTRICT table, size_t cols, const char* FT_RESTRICT cells[]) +int ft_row_write(FTABLE *table, size_t cols, const char *cells[]) { size_t i = 0; assert(table); @@ -353,7 +353,7 @@ int ft_row_write(FTABLE *FT_RESTRICT table, size_t cols, const char* FT_RESTRICT return FT_SUCCESS; } -int ft_row_write_ln(FTABLE *FT_RESTRICT table, size_t cols, const char* FT_RESTRICT cells[]) +int ft_row_write_ln(FTABLE *table, size_t cols, const char *cells[]) { assert(table); int status = ft_row_write(table, cols, cells); @@ -364,7 +364,7 @@ int ft_row_write_ln(FTABLE *FT_RESTRICT table, size_t cols, const char* FT_RESTR } #ifdef FT_HAVE_WCHAR -int ft_row_wwrite(FTABLE *FT_RESTRICT table, size_t cols, const wchar_t* FT_RESTRICT cells[]) +int ft_row_wwrite(FTABLE *table, size_t cols, const wchar_t *cells[]) { size_t i = 0; assert(table); @@ -378,7 +378,7 @@ int ft_row_wwrite(FTABLE *FT_RESTRICT table, size_t cols, const wchar_t* FT_REST return FT_SUCCESS; } -int ft_row_wwrite_ln(FTABLE *FT_RESTRICT table, size_t cols, const wchar_t* FT_RESTRICT cells[]) +int ft_row_wwrite_ln(FTABLE *table, size_t cols, const wchar_t *cells[]) { assert(table); int status = ft_row_wwrite(table, cols, cells); @@ -392,7 +392,7 @@ int ft_row_wwrite_ln(FTABLE *FT_RESTRICT table, size_t cols, const wchar_t* FT_R #if !defined(__cplusplus) && !defined(FT_MICROSOFT_COMPILER) -int ft_s_table_write(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const char* FT_RESTRICT table_cells[rows][cols]) +int ft_s_table_write(FTABLE *table, size_t rows, size_t cols, const char *table_cells[rows][cols]) { size_t i = 0; assert(table); @@ -408,7 +408,7 @@ int ft_s_table_write(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const return FT_SUCCESS; } -int ft_s_table_write_ln(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const char* FT_RESTRICT table_cells[rows][cols]) +int ft_s_table_write_ln(FTABLE *table, size_t rows, size_t cols, const char *table_cells[rows][cols]) { assert(table); int status = ft_s_table_write(table, rows, cols, table_cells); @@ -419,7 +419,7 @@ int ft_s_table_write_ln(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, con } -int ft_table_write(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const char* * FT_RESTRICT table_cells[rows]) +int ft_table_write(FTABLE *table, size_t rows, size_t cols, const char **table_cells[rows]) { size_t i = 0; assert(table); @@ -435,7 +435,7 @@ int ft_table_write(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const ch return FT_SUCCESS; } -int ft_table_write_ln(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const char* * FT_RESTRICT table_cells[rows]) +int ft_table_write_ln(FTABLE *table, size_t rows, size_t cols, const char **table_cells[rows]) { assert(table); int status = ft_table_write(table, rows, cols, table_cells); @@ -459,7 +459,7 @@ int ft_table_write_ln(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const -const char* ft_to_string(const FTABLE *FT_RESTRICT table) +const char *ft_to_string(const FTABLE *table) { #define CHECK_RESULT_AND_MOVE_DEV(statement) \ do { \ @@ -477,12 +477,12 @@ const char* ft_to_string(const FTABLE *FT_RESTRICT table) char new_line_char = '\n'; #define cur_F_STRDUP F_STRDUP int (*snprintf_row_)(const fort_row_t *, char *, size_t, size_t *, size_t, size_t, const context_t *) = snprintf_row; - int (*print_row_separator_)(char *, size_t , - const size_t *, size_t , - const fort_row_t *, const fort_row_t *, - enum HorSeparatorPos , const separator_t *, - const context_t *) = print_row_separator; - int (*snprint_n_chars_)(char *, size_t , size_t , char) = snprint_n_chars; + int (*print_row_separator_)(char *, size_t, + const size_t *, size_t, + const fort_row_t *, const fort_row_t *, + enum HorSeparatorPos, const separator_t *, + const context_t *) = print_row_separator; + int (*snprint_n_chars_)(char *, size_t, size_t, char) = snprint_n_chars; assert(table); /* Determing size of table string representation */ @@ -538,7 +538,7 @@ const char* ft_to_string(const FTABLE *FT_RESTRICT table) for (i = 0; i < rows; ++i) { cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL; - cur_row = *(fort_row_t**)vector_at(table->rows, i); + cur_row = *(fort_row_t **)vector_at(table->rows, i); enum HorSeparatorPos separatorPos = (i == 0) ? TopSeparator : InsideSeparator; context.row = i; CHECK_RESULT_AND_MOVE_DEV(print_row_separator_(buffer + dev, sz - dev, col_width_arr, cols, prev_row, cur_row, separatorPos, cur_sep, &context)); @@ -571,7 +571,7 @@ clear: } -const wchar_t* ft_to_wstring(const FTABLE *FT_RESTRICT table) +const wchar_t *ft_to_wstring(const FTABLE *table) { #define CHECK_RESULT_AND_MOVE_DEV(statement) \ do { \ @@ -589,12 +589,12 @@ const wchar_t* ft_to_wstring(const FTABLE *FT_RESTRICT table) wchar_t new_line_char = L'\n'; #define cur_F_STRDUP F_WCSDUP int (*snprintf_row_)(const fort_row_t *, wchar_t *, size_t, size_t *, size_t, size_t, const context_t *) = wsnprintf_row; - int (*print_row_separator_)(wchar_t *, size_t , - const size_t *, size_t , - const fort_row_t *, const fort_row_t *, - enum HorSeparatorPos , const separator_t *, - const context_t *) = wprint_row_separator; - int (*snprint_n_chars_)(wchar_t *, size_t , size_t , wchar_t) = wsnprint_n_chars; + int (*print_row_separator_)(wchar_t *, size_t, + const size_t *, size_t, + const fort_row_t *, const fort_row_t *, + enum HorSeparatorPos, const separator_t *, + const context_t *) = wprint_row_separator; + int (*snprint_n_chars_)(wchar_t *, size_t, size_t, wchar_t) = wsnprint_n_chars; assert(table); @@ -651,7 +651,7 @@ const wchar_t* ft_to_wstring(const FTABLE *FT_RESTRICT table) for (i = 0; i < rows; ++i) { cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL; - cur_row = *(fort_row_t**)vector_at(table->rows, i); + cur_row = *(fort_row_t **)vector_at(table->rows, i); enum HorSeparatorPos separatorPos = (i == 0) ? TopSeparator : InsideSeparator; context.row = i; CHECK_RESULT_AND_MOVE_DEV(print_row_separator_(buffer + dev, sz - dev, col_width_arr, cols, prev_row, cur_row, separatorPos, cur_sep, &context)); @@ -712,7 +712,7 @@ int ft_add_separator(FTABLE *table) assert(table); assert(table->separators); - while(vector_size(table->separators) <= table->cur_row) { + while (vector_size(table->separators) <= table->cur_row) { separator_t *sep_p = create_separator(F_FALSE); if (sep_p == NULL) return FT_MEMORY_ERROR; @@ -738,11 +738,11 @@ int ft_add_separator(FTABLE *table) /* ******************************************************************************* */ -struct ft_border_style * FT_BASIC_STYLE = (struct ft_border_style *)&FORT_BASIC_STYLE; -struct ft_border_style * FT_SIMPLE_STYLE = (struct ft_border_style *)&FORT_SIMPLE_STYLE; -struct ft_border_style * FT_PLAIN_STYLE = (struct ft_border_style *)&FORT_PLAIN_STYLE; -struct ft_border_style * FT_DOT_STYLE = (struct ft_border_style *)&FORT_DOT_STYLE; -struct ft_border_style * FT_EMPTY_STYLE = (struct ft_border_style *)&FORT_EMPTY_STYLE; +struct ft_border_style *FT_BASIC_STYLE = (struct ft_border_style *) &FORT_BASIC_STYLE; +struct ft_border_style *FT_SIMPLE_STYLE = (struct ft_border_style *) &FORT_SIMPLE_STYLE; +struct ft_border_style *FT_PLAIN_STYLE = (struct ft_border_style *) &FORT_PLAIN_STYLE; +struct ft_border_style *FT_DOT_STYLE = (struct ft_border_style *) &FORT_DOT_STYLE; +struct ft_border_style *FT_EMPTY_STYLE = (struct ft_border_style *) &FORT_EMPTY_STYLE; @@ -752,8 +752,7 @@ static void set_border_options_for_options(fort_table_options_t *options, struct || (struct fort_border_style *)style == &FORT_SIMPLE_STYLE || (struct fort_border_style *)style == &FORT_DOT_STYLE || (struct fort_border_style *)style == &FORT_PLAIN_STYLE - || (struct fort_border_style *)style == &FORT_EMPTY_STYLE) - { + || (struct fort_border_style *)style == &FORT_EMPTY_STYLE) { memcpy(&(options->border_style), (struct fort_border_style *)style, sizeof(struct fort_border_style)); return; } @@ -865,7 +864,7 @@ FT_EXTERN 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 * FT_RESTRICT table, uint32_t option, int value) +FT_EXTERN int ft_set_tbl_option(FTABLE *table, uint32_t option, int value) { assert(table); diff --git a/src/fort_impl.c b/src/fort_impl.c index 1e98074..7cb17c8 100644 --- a/src/fort_impl.c +++ b/src/fort_impl.c @@ -6,13 +6,13 @@ /***************************************************************************** * LIBFORT helpers *****************************************************************************/ -char *fort_strdup(const char* str) +char *fort_strdup(const char *str) { if (str == NULL) return NULL; size_t sz = strlen(str); - char *str_copy = (char*)F_MALLOC((sz + 1)*sizeof(char)); + char *str_copy = (char *)F_MALLOC((sz + 1) * sizeof(char)); if (str_copy == NULL) return NULL; @@ -20,13 +20,13 @@ char *fort_strdup(const char* str) return str_copy; } -wchar_t *fort_wcsdup(const wchar_t* str) +wchar_t *fort_wcsdup(const wchar_t *str) { if (str == NULL) return NULL; size_t sz = wcslen(str); - wchar_t *str_copy = (wchar_t*)F_MALLOC((sz + 1)*sizeof(wchar_t)); + wchar_t *str_copy = (wchar_t *)F_MALLOC((sz + 1) * sizeof(wchar_t)); if (str_copy == NULL) return NULL; diff --git a/src/options.c b/src/options.c index aa47ffe..1fb36b0 100644 --- a/src/options.c +++ b/src/options.c @@ -7,15 +7,14 @@ * COLUMN OPTIONS * ***************************************************************************/ -struct fort_cell_options g_default_cell_option = -{ +struct fort_cell_options g_default_cell_option = { FT_ANY_ROW, /* cell_row */ FT_ANY_COLUMN, /* cell_col */ /* options */ FT_COPT_MIN_WIDTH | FT_COPT_TEXT_ALIGN | FT_COPT_TOP_PADDING | FT_COPT_BOTTOM_PADDING | FT_COPT_LEFT_PADDING | FT_COPT_RIGHT_PADDING - | FT_COPT_EMPTY_STR_HEIGHT , + | FT_COPT_EMPTY_STR_HEIGHT, 0, /* col_min_width */ RightAligned, /* align */ @@ -58,8 +57,7 @@ static int get_option_value_if_exists_otherwise_default(const struct fort_cell_o } -fort_column_options_t g_column_options = -{ +fort_column_options_t g_column_options = { 0, /* col_min_width*/ RightAligned, /* align */ }; @@ -88,26 +86,26 @@ void destroy_cell_opt_container(fort_cell_opt_container_t *cont) destroy_vector(cont); } -const fort_cell_options_t* cget_cell_opt(const fort_cell_opt_container_t *cont, unsigned row, unsigned col) +const fort_cell_options_t *cget_cell_opt(const fort_cell_opt_container_t *cont, unsigned row, unsigned col) { assert(cont); size_t sz = vector_size(cont); size_t i = 0; for (i = 0; i < sz; ++i) { - const fort_cell_options_t* opt = (const fort_cell_options_t*)vector_at_c(cont, i); + const fort_cell_options_t *opt = (const fort_cell_options_t *)vector_at_c(cont, i); if (opt->cell_row == row && opt->cell_col == col) return opt; } return NULL; } -fort_cell_options_t* get_cell_opt_and_create_if_not_exists(fort_cell_opt_container_t *cont, unsigned row, unsigned col) +fort_cell_options_t *get_cell_opt_and_create_if_not_exists(fort_cell_opt_container_t *cont, unsigned row, unsigned col) { assert(cont); size_t sz = vector_size(cont); size_t i = 0; for (i = 0; i < sz; ++i) { - fort_cell_options_t* opt = (fort_cell_options_t*)vector_at(cont, i); + fort_cell_options_t *opt = (fort_cell_options_t *)vector_at(cont, i); if (opt->cell_row == row && opt->cell_col == col) return opt; } @@ -115,7 +113,7 @@ fort_cell_options_t* get_cell_opt_and_create_if_not_exists(fort_cell_opt_contain opt.cell_row = row; opt.cell_col = col; if (IS_SUCCESS(vector_push(cont, &opt))) { - return (fort_cell_options_t*)vector_at(cont, sz); + return (fort_cell_options_t *)vector_at(cont, sz); } return NULL; @@ -128,7 +126,7 @@ int get_cell_opt_value_hierarcial(const fort_table_options_t *options, size_t ro { assert(options); - const fort_cell_options_t* opt = NULL; + const fort_cell_options_t *opt = NULL; if (options->cell_options != NULL) { while (1) { opt = cget_cell_opt(options->cell_options, row, column); @@ -181,7 +179,7 @@ static fort_status_t set_cell_option_impl(fort_cell_options_t *opt, uint32_t opt fort_status_t set_cell_option(fort_cell_opt_container_t *cont, unsigned row, unsigned col, uint32_t option, int value) { - fort_cell_options_t* opt = get_cell_opt_and_create_if_not_exists(cont, row, col); + fort_cell_options_t *opt = get_cell_opt_and_create_if_not_exists(cont, row, col); if (opt == NULL) return FT_ERROR; @@ -292,7 +290,7 @@ fort_status_t set_default_cell_option(uint32_t option, int value) }, \ } -#define EMPTY_STYLE { \ +#define EMPTY_STYLE { \ /* border_chars */ \ { \ ' ', ' ', ' ', ' ', \ @@ -304,7 +302,7 @@ fort_status_t set_default_cell_option(uint32_t option, int value) { \ ' ', ' ', ' ', ' ', \ ' ', ' ', ' ', \ - '\0', '\0', '\0', '\0', \ + '\0', '\0', '\0', '\0', \ ' ', ' ', ' ', ' ' \ }, \ /* separator_chars */ \ @@ -366,9 +364,9 @@ fort_table_options_t g_table_options = { }; -fort_table_options_t* create_table_options() +fort_table_options_t *create_table_options() { - fort_table_options_t* options = (fort_table_options_t*)F_CALLOC(sizeof(fort_table_options_t), 1); + fort_table_options_t *options = (fort_table_options_t *)F_CALLOC(sizeof(fort_table_options_t), 1); if (options == NULL) { return NULL; } @@ -382,11 +380,11 @@ fort_table_options_t* create_table_options() return options; } -fort_table_options_t* copy_table_options(const fort_table_options_t *option) +fort_table_options_t *copy_table_options(const fort_table_options_t *option) { /* todo: normal implementation, do deep copy of col options */ - fort_table_options_t* new_opt = create_table_options(); + fort_table_options_t *new_opt = create_table_options(); if (new_opt == NULL) return NULL; @@ -404,7 +402,7 @@ fort_table_options_t* copy_table_options(const fort_table_options_t *option) } -void destroy_table_options(fort_table_options_t* options) +void destroy_table_options(fort_table_options_t *options) { if (options == NULL) return; diff --git a/src/row.c b/src/row.c index 3d2a903..c9e0c2d 100644 --- a/src/row.c +++ b/src/row.c @@ -5,20 +5,19 @@ #include "vector.h" #include "ctype.h" -struct fort_row -{ +struct fort_row { vector_t *cells; /*enum RowType type;*/ }; -fort_row_t * create_row(void) +fort_row_t *create_row(void) { - fort_row_t * row = (fort_row_t *)F_CALLOC(sizeof(fort_row_t), 1); + fort_row_t *row = (fort_row_t *)F_CALLOC(sizeof(fort_row_t), 1); if (row == NULL) return NULL; - row->cells = create_vector(sizeof(fort_cell_t*), DEFAULT_VECTOR_CAPACITY); + row->cells = create_vector(sizeof(fort_cell_t *), DEFAULT_VECTOR_CAPACITY); if (row->cells == NULL) { F_FREE(row); return NULL; @@ -71,12 +70,12 @@ fort_cell_t *get_cell_implementation(fort_row_t *row, size_t col, enum PolicyOnN switch (policy) { case DoNotCreate: if (col < columns_in_row(row)) { - return *(fort_cell_t**)vector_at(row->cells, col); + return *(fort_cell_t **)vector_at(row->cells, col); } return NULL; break; case Create: - while(col >= columns_in_row(row)) { + while (col >= columns_in_row(row)) { fort_cell_t *new_cell = create_cell(); if (new_cell == NULL) return NULL; @@ -85,7 +84,7 @@ fort_cell_t *get_cell_implementation(fort_row_t *row, size_t col, enum PolicyOnN return NULL; } } - return *(fort_cell_t**)vector_at(row->cells, col); + return *(fort_cell_t **)vector_at(row->cells, col); break; } return NULL; @@ -112,10 +111,10 @@ fort_cell_t *get_cell_and_create_if_not_exists(fort_row_t *row, size_t col) int print_row_separator(char *buffer, size_t buffer_sz, - const size_t *col_width_arr, size_t cols, - const fort_row_t *upper_row, const fort_row_t *lower_row, - enum HorSeparatorPos separatorPos, - const separator_t *sep, const context_t *context) + const size_t *col_width_arr, size_t cols, + const fort_row_t *upper_row, const fort_row_t *lower_row, + enum HorSeparatorPos separatorPos, + const separator_t *sep, const context_t *context) { #define CHECK_RESULT_AND_MOVE_DEV(statement) \ do { \ @@ -128,7 +127,7 @@ int print_row_separator(char *buffer, size_t buffer_sz, typedef char char_type; char new_line_char = '\n'; - int (*snprint_n_chars_)(char *, size_t , size_t , char) = snprint_n_chars; + int (*snprint_n_chars_)(char *, size_t, size_t, char) = snprint_n_chars; char space_char = ' '; assert(buffer); @@ -143,7 +142,7 @@ int print_row_separator(char *buffer, size_t buffer_sz, } enum RowType upper_row_type = Common; if (upper_row != NULL) { - upper_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row-1, FT_ANY_COLUMN, FT_COPT_ROW_TYPE); + upper_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row - 1, FT_ANY_COLUMN, FT_COPT_ROW_TYPE); } @@ -228,10 +227,10 @@ clear: int wprint_row_separator(wchar_t *buffer, size_t buffer_sz, - const size_t *col_width_arr, size_t cols, - const fort_row_t *upper_row, const fort_row_t *lower_row, - enum HorSeparatorPos separatorPos, const separator_t *sep, - const context_t *context) + const size_t *col_width_arr, size_t cols, + const fort_row_t *upper_row, const fort_row_t *lower_row, + enum HorSeparatorPos separatorPos, const separator_t *sep, + const context_t *context) { #define CHECK_RESULT_AND_MOVE_DEV(statement) \ do { \ @@ -244,7 +243,7 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz, typedef wchar_t char_type; char new_line_char = L'\n'; - int (*snprint_n_chars_)(wchar_t*, size_t , size_t , wchar_t) = wsnprint_n_chars; + int (*snprint_n_chars_)(wchar_t *, size_t, size_t, wchar_t) = wsnprint_n_chars; wchar_t space_char = L' '; @@ -260,7 +259,7 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz, } enum RowType upper_row_type = Common; if (upper_row != NULL) { - upper_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row-1, FT_ANY_COLUMN, FT_COPT_ROW_TYPE); + upper_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row - 1, FT_ANY_COLUMN, FT_COPT_ROW_TYPE); } /* Row separator anatomy @@ -344,13 +343,13 @@ clear: -fort_row_t* create_row_from_string(const char *str) +fort_row_t *create_row_from_string(const char *str) { char *pos = NULL; char *base_pos = NULL; int number_of_separators = 0; - fort_row_t * row = create_row(); + fort_row_t *row = create_row(); if (row == NULL) return NULL; @@ -376,7 +375,7 @@ fort_row_t* create_row_from_string(const char *str) if (cell == NULL) goto clear; -/* int status = fill_buffer_from_string(cell->str_buffer, base_pos); */ + /* int status = fill_buffer_from_string(cell->str_buffer, base_pos); */ int status = fill_cell_from_string(cell, base_pos); if (IS_ERROR(status)) { destroy_cell(cell); @@ -400,7 +399,7 @@ fort_row_t* create_row_from_string(const char *str) if (cell == NULL) goto clear; -/* int status = fill_buffer_from_string(cell->str_buffer, ""); */ + /* int status = fill_buffer_from_string(cell->str_buffer, ""); */ int status = fill_cell_from_string(cell, ""); if (IS_ERROR(status)) { destroy_cell(cell); @@ -426,7 +425,7 @@ clear: -fort_row_t* create_row_from_fmt_string(const char* FT_RESTRICT fmt, va_list *va_args) +fort_row_t *create_row_from_fmt_string(const char *fmt, va_list *va_args) { string_buffer_t *buffer = create_string_buffer(DEFAULT_STR_BUF_SIZE, CharBuf); if (buffer == NULL) @@ -474,7 +473,7 @@ clear: int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col_width_arr, size_t col_width_arr_sz, - size_t row_height, const context_t *context) + size_t row_height, const context_t *context) { #define CHECK_RESULT_AND_MOVE_DEV(statement) \ do { \ @@ -488,7 +487,7 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col typedef char char_type; char space_char = ' '; char new_line_char = '\n'; - int (*snprint_n_chars_)(char *, size_t , size_t , char) = snprint_n_chars; + int (*snprint_n_chars_)(char *, size_t, size_t, char) = snprint_n_chars; int (*cell_printf_)(fort_cell_t *, size_t, char *, size_t, const context_t *) = cell_printf; @@ -508,8 +507,8 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col typedef const char (*border_chars_point_t)[BorderItemPosSize]; enum RowType row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_COPT_ROW_TYPE); const char (*bord_chars)[BorderItemPosSize] = (row_type == Header) - ? (border_chars_point_t) (&context->table_options->border_style.header_border_chars) - : (border_chars_point_t) (&context->table_options->border_style.border_chars); + ? (border_chars_point_t)(&context->table_options->border_style.header_border_chars) + : (border_chars_point_t)(&context->table_options->border_style.border_chars); const char *L = &(*bord_chars)[LL_bip]; const char *IV = &(*bord_chars)[IV_bip]; const char *R = &(*bord_chars)[RR_bip]; @@ -527,7 +526,7 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col for (j = 0; j < col_width_arr_sz; ++j) { ((context_t *)context)->column = j; if (j < cols_in_row) { - fort_cell_t *cell = *(fort_cell_t**)vector_at(row->cells, j); + fort_cell_t *cell = *(fort_cell_t **)vector_at(row->cells, j); CHECK_RESULT_AND_MOVE_DEV(cell_printf_(cell, i, buffer + dev, col_width_arr[j] + 1, context)); } else { CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, col_width_arr[j], space_char)); @@ -554,7 +553,7 @@ clear: int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t *col_width_arr, size_t col_width_arr_sz, - size_t row_height, const context_t *context) + size_t row_height, const context_t *context) { #define CHECK_RESULT_AND_MOVE_DEV(statement) \ do { \ @@ -568,7 +567,7 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t typedef wchar_t char_type; char space_char = L' '; char new_line_char = L'\n'; - int (*snprint_n_chars_)(wchar_t *, size_t , size_t , wchar_t) = wsnprint_n_chars; + int (*snprint_n_chars_)(wchar_t *, size_t, size_t, wchar_t) = wsnprint_n_chars; int (*cell_printf_)(fort_cell_t *, size_t, wchar_t *, size_t, const context_t *) = cell_wprintf; @@ -588,8 +587,8 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t typedef const char (*border_chars_point_t)[BorderItemPosSize]; enum RowType row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_COPT_ROW_TYPE); const char (*bord_chars)[BorderItemPosSize] = (row_type) - ? (border_chars_point_t) (&context->table_options->border_style.header_border_chars) - : (border_chars_point_t) (&context->table_options->border_style.border_chars); + ? (border_chars_point_t)(&context->table_options->border_style.header_border_chars) + : (border_chars_point_t)(&context->table_options->border_style.border_chars); const char *L = &(*bord_chars)[LL_bip]; const char *IV = &(*bord_chars)[IV_bip]; const char *R = &(*bord_chars)[RR_bip]; @@ -607,7 +606,7 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t for (j = 0; j < col_width_arr_sz; ++j) { ((context_t *)context)->column = j; if (j < cols_in_row) { - fort_cell_t *cell = *(fort_cell_t**)vector_at(row->cells, j); + fort_cell_t *cell = *(fort_cell_t **)vector_at(row->cells, j); CHECK_RESULT_AND_MOVE_DEV(cell_printf_(cell, i, buffer + dev, col_width_arr[j] + 1, context)); } else { CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, col_width_arr[j], space_char)); diff --git a/src/row.h b/src/row.h index 67f61a4..a724544 100644 --- a/src/row.h +++ b/src/row.h @@ -21,7 +21,7 @@ enum RowType fort_row_t * create_row(void); void destroy_row(fort_row_t *row); fort_row_t * create_row_from_string(const char *str); -fort_row_t* create_row_from_fmt_string(const char* FT_RESTRICT fmt, va_list *va_args); +fort_row_t* create_row_from_fmt_string(const char* fmt, va_list *va_args); int columns_in_row(const fort_row_t *row); diff --git a/src/string_buffer.c b/src/string_buffer.c index c135cd0..344bd50 100644 --- a/src/string_buffer.c +++ b/src/string_buffer.c @@ -19,7 +19,7 @@ static int wcs_iter_width(const wchar_t *beg, const wchar_t *end) } -static size_t buf_str_len(const string_buffer_t*buf) +static size_t buf_str_len(const string_buffer_t *buf) { assert(buf); if (buf->type == CharBuf) { @@ -29,7 +29,7 @@ static size_t buf_str_len(const string_buffer_t*buf) } } -size_t strchr_count(const char* str, char ch) +size_t strchr_count(const char *str, char ch) { if (str == NULL) return 0; @@ -44,7 +44,7 @@ size_t strchr_count(const char* str, char ch) return count; } -size_t wstrchr_count(const wchar_t* str, wchar_t ch) +size_t wstrchr_count(const wchar_t *str, wchar_t ch) { if (str == NULL) return 0; @@ -59,7 +59,7 @@ size_t wstrchr_count(const wchar_t* str, wchar_t ch) return count; } -const char* str_n_substring_beg(const char* str, char ch_separator, size_t n) +const char *str_n_substring_beg(const char *str, char ch_separator, size_t n) { if (str == NULL) return NULL; @@ -79,7 +79,7 @@ const char* str_n_substring_beg(const char* str, char ch_separator, size_t n) return str ? (str + 1) : NULL; } -const wchar_t* wstr_n_substring_beg(const wchar_t* str, wchar_t ch_separator, size_t n) +const wchar_t *wstr_n_substring_beg(const wchar_t *str, wchar_t ch_separator, size_t n) { if (str == NULL) return NULL; @@ -99,7 +99,7 @@ const wchar_t* wstr_n_substring_beg(const wchar_t* str, wchar_t ch_separator, si return str ? (str + 1) : NULL; } -void str_n_substring(const char* str, char ch_separator, size_t n, const char **begin, const char **end) +void str_n_substring(const char *str, char ch_separator, size_t n, const char **begin, const char **end) { const char *beg = str_n_substring_beg(str, ch_separator, n); if (beg == NULL) { @@ -118,7 +118,7 @@ void str_n_substring(const char* str, char ch_separator, size_t n, const char ** return; } -void wstr_n_substring(const wchar_t* str, wchar_t ch_separator, size_t n, const wchar_t **begin, const wchar_t **end) +void wstr_n_substring(const wchar_t *str, wchar_t ch_separator, size_t n, const wchar_t **begin, const wchar_t **end) { const wchar_t *beg = wstr_n_substring_beg(str, ch_separator, n); if (beg == NULL) { @@ -138,7 +138,7 @@ void wstr_n_substring(const wchar_t* str, wchar_t ch_separator, size_t n, const } -string_buffer_t* create_string_buffer(size_t number_of_chars, enum str_buf_type type) +string_buffer_t *create_string_buffer(size_t number_of_chars, enum str_buf_type type) { size_t sz = (number_of_chars) * (type == CharBuf ? sizeof(char) : sizeof(wchar_t)); string_buffer_t *result = (string_buffer_t *)F_MALLOC(sizeof(string_buffer_t)); @@ -167,7 +167,7 @@ void destroy_string_buffer(string_buffer_t *buffer) fort_status_t realloc_string_buffer_without_copy(string_buffer_t *buffer) { assert(buffer); - char *new_str = (char*)F_MALLOC(buffer->data_sz * 2); + char *new_str = (char *)F_MALLOC(buffer->data_sz * 2); if (new_str == NULL) { return FT_MEMORY_ERROR; } @@ -183,7 +183,7 @@ fort_status_t fill_buffer_from_string(string_buffer_t *buffer, const char *str) assert(str); size_t sz = strlen(str); - char * copy = F_STRDUP(str); + char *copy = F_STRDUP(str); if (copy == NULL) return FT_MEMORY_ERROR; @@ -206,7 +206,7 @@ fort_status_t fill_buffer_from_wstring(string_buffer_t *buffer, const wchar_t *s assert(str); size_t sz = wcslen(str); - wchar_t * copy = F_WCSDUP(str); + wchar_t *copy = F_WCSDUP(str); if (copy == NULL) return FT_MEMORY_ERROR; @@ -283,7 +283,7 @@ int buffer_printf(string_buffer_t *buffer, size_t buffer_row, char *buf, size_t #define STR_ITER_WIDTH str_iter_width if (buffer == NULL || buffer->str.data == NULL - || buffer_row >= buffer_text_height(buffer) || buf_len == 0) { + || buffer_row >= buffer_text_height(buffer) || buf_len == 0) { return -1; } @@ -367,7 +367,7 @@ int buffer_wprintf(string_buffer_t *buffer, size_t buffer_row, wchar_t *buf, siz #define STR_ITER_WIDTH wcs_iter_width if (buffer == NULL || buffer->str.data == NULL - || buffer_row >= buffer_text_height(buffer) || buf_len == 0) { + || buffer_row >= buffer_text_height(buffer) || buf_len == 0) { return -1; } diff --git a/src/table.c b/src/table.c index f6afbb7..ad5b0d4 100644 --- a/src/table.c +++ b/src/table.c @@ -16,12 +16,12 @@ fort_row_t *get_row_implementation(fort_table_t *table, size_t row, enum PolicyO switch (policy) { case DoNotCreate: if (row < vector_size(table->rows)) { - return *(fort_row_t**)vector_at(table->rows, row); + return *(fort_row_t **)vector_at(table->rows, row); } return NULL; break; case Create: - while(row >= vector_size(table->rows)) { + while (row >= vector_size(table->rows)) { fort_row_t *new_row = create_row(); if (new_row == NULL) return NULL; @@ -30,7 +30,7 @@ fort_row_t *get_row_implementation(fort_table_t *table, size_t row, enum PolicyO return NULL; } } - return *(fort_row_t**)vector_at(table->rows, row); + return *(fort_row_t **)vector_at(table->rows, row); break; } return NULL; @@ -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 *FT_RESTRICT table) +string_buffer_t *get_cur_str_buffer_and_create_if_not_exists(FTABLE *table) { assert(table); @@ -79,7 +79,7 @@ fort_status_t get_table_sizes(const FTABLE *table, size_t *rows, size_t *cols) if (table && table->rows) { *rows = vector_size(table->rows); fort_row_t *row = NULL; - FOR_EACH(fort_row_t*, row, table->rows) { + FOR_EACH(fort_row_t *, row, table->rows) { size_t cols_in_row = columns_in_row(row); if (cols_in_row > *cols) *cols = cols_in_row; @@ -89,8 +89,8 @@ fort_status_t get_table_sizes(const FTABLE *table, size_t *rows, size_t *cols) } fort_status_t table_rows_and_cols_geometry(const FTABLE *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) + size_t **col_width_arr_p, size_t *col_width_arr_sz, + size_t **row_height_arr_p, size_t *row_height_arr_sz) { if (table == NULL) { return FT_ERROR; diff --git a/src/table.h b/src/table.h index b9bde18..3bdf8de 100644 --- a/src/table.h +++ b/src/table.h @@ -40,7 +40,7 @@ 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); -string_buffer_t * get_cur_str_buffer_and_create_if_not_exists(FTABLE *FT_RESTRICT table); +string_buffer_t * get_cur_str_buffer_and_create_if_not_exists(FTABLE * table); diff --git a/src/vector.c b/src/vector.c index 6c1a6e9..2ca0ef6 100644 --- a/src/vector.c +++ b/src/vector.c @@ -6,8 +6,7 @@ * VECTOR IMPLEMENTATIONS * ***************************************************************************/ -struct vector -{ +struct vector { size_t m_size; void *m_data; size_t m_capacity; @@ -28,7 +27,7 @@ static int vector_reallocate_(vector_t *vector, size_t new_capacity) /* ------------ Constructors & Destructors ----------------------------- */ -vector_t* create_vector(size_t item_size, size_t capacity) +vector_t *create_vector(size_t item_size, size_t capacity) { vector_t *vector = (vector_t *)malloc(sizeof(vector_t)); if (vector == NULL) { @@ -52,19 +51,19 @@ vector_t* create_vector(size_t item_size, size_t capacity) } -void destroy_vector(vector_t* vector) +void destroy_vector(vector_t *vector) { assert(vector); free(vector->m_data); free(vector); } -vector_t* copy_vector(vector_t *v) +vector_t *copy_vector(vector_t *v) { if (v == NULL) return NULL; - vector_t* new_vector = create_vector(v->m_item_size, v->m_capacity); + vector_t *new_vector = create_vector(v->m_item_size, v->m_capacity); if (new_vector == NULL) return NULL; @@ -78,27 +77,27 @@ vector_t* copy_vector(vector_t *v) /* ----------- Nonmodifying functions --------------------------------- */ -size_t vector_size(const vector_t* vector) +size_t vector_size(const vector_t *vector) { assert(vector); return vector->m_size; } -size_t vector_capacity(const vector_t* vector) +size_t vector_capacity(const vector_t *vector) { assert(vector); return vector->m_capacity; } -size_t vector_index_of(const vector_t* vector, const void *item) +size_t vector_index_of(const vector_t *vector, const void *item) { assert(vector); assert(item); size_t i = 0; for (i = 0; i < vector->m_size; ++i) { - void *data_pos = (char*)vector->m_data + i * vector->m_item_size; + void *data_pos = (char *)vector->m_data + i * vector->m_item_size; if (memcmp(data_pos, item, vector->m_item_size) == 0) { return i; } @@ -109,7 +108,7 @@ size_t vector_index_of(const vector_t* vector, const void *item) /* ----------- Modifying functions ------------------------------------- */ -int vector_push (vector_t* vector, const void* item) +int vector_push(vector_t *vector, const void *item) { assert(vector); assert(item); @@ -121,7 +120,7 @@ int vector_push (vector_t* vector, const void* item) } ptrdiff_t deviation = vector->m_size * vector->m_item_size; - memcpy((char*)vector->m_data + deviation, item, vector->m_item_size); + memcpy((char *)vector->m_data + deviation, item, vector->m_item_size); ++(vector->m_size); @@ -136,8 +135,8 @@ int vector_erase(vector_t *vector, size_t index) if (vector->m_size == 0 || index >= vector->m_size) return FT_ERROR; - memmove((char*)vector->m_data + vector->m_item_size * index, - (char*)vector->m_data + vector->m_item_size * (index + 1), + memmove((char *)vector->m_data + vector->m_item_size * index, + (char *)vector->m_data + vector->m_item_size * (index + 1), (vector->m_size - 1 - index) * vector->m_item_size); vector->m_size--; return FT_SUCCESS; @@ -154,7 +153,7 @@ const void *vector_at_c(const vector_t *vector, size_t index) if (index >= vector->m_size) return NULL; - return (char*)vector->m_data + index * vector->m_item_size; + return (char *)vector->m_data + index * vector->m_item_size; } @@ -163,7 +162,7 @@ void *vector_at(vector_t *vector, size_t index) if (index >= vector->m_size) return NULL; - return (char*)vector->m_data + index * vector->m_item_size; + return (char *)vector->m_data + index * vector->m_item_size; } diff --git a/src/wcwidth.c b/src/wcwidth.c index f73e624..52ee3f6 100644 --- a/src/wcwidth.c +++ b/src/wcwidth.c @@ -62,28 +62,29 @@ #include struct interval { - int first; - int last; + int first; + int last; }; /* auxiliary function for binary search in interval table */ -static int bisearch(wchar_t ucs, const struct interval *table, int max) { - int min = 0; - int mid; +static int bisearch(wchar_t ucs, const struct interval *table, int max) +{ + int min = 0; + int mid; + + if (ucs < table[0].first || ucs > table[max].last) + return 0; + while (max >= min) { + mid = (min + max) / 2; + if (ucs > table[mid].last) + min = mid + 1; + else if (ucs < table[mid].first) + max = mid - 1; + else + return 1; + } - if (ucs < table[0].first || ucs > table[max].last) return 0; - while (max >= min) { - mid = (min + max) / 2; - if (ucs > table[mid].last) - min = mid + 1; - else if (ucs < table[mid].first) - max = mid - 1; - else - return 1; - } - - return 0; } @@ -121,100 +122,100 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) { int mk_wcwidth(wchar_t ucs) { - /* sorted list of non-overlapping intervals of non-spacing characters */ - /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ - static const struct interval combining[] = { - { 0x0300, 0x036F }, { 0x0483, 0x0486 }, { 0x0488, 0x0489 }, - { 0x0591, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 }, - { 0x05C4, 0x05C5 }, { 0x05C7, 0x05C7 }, { 0x0600, 0x0603 }, - { 0x0610, 0x0615 }, { 0x064B, 0x065E }, { 0x0670, 0x0670 }, - { 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED }, - { 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A }, - { 0x07A6, 0x07B0 }, { 0x07EB, 0x07F3 }, { 0x0901, 0x0902 }, - { 0x093C, 0x093C }, { 0x0941, 0x0948 }, { 0x094D, 0x094D }, - { 0x0951, 0x0954 }, { 0x0962, 0x0963 }, { 0x0981, 0x0981 }, - { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD }, - { 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 }, { 0x0A3C, 0x0A3C }, - { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D }, - { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC }, - { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD }, - { 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C }, - { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, { 0x0B4D, 0x0B4D }, - { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 }, - { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 }, - { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0CBC, 0x0CBC }, - { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD }, - { 0x0CE2, 0x0CE3 }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D }, - { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 }, - { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, - { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC }, - { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, - { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, - { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 }, - { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, - { 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 }, - { 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x135F, 0x135F }, - { 0x1712, 0x1714 }, { 0x1732, 0x1734 }, { 0x1752, 0x1753 }, - { 0x1772, 0x1773 }, { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD }, - { 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD }, - { 0x180B, 0x180D }, { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 }, - { 0x1927, 0x1928 }, { 0x1932, 0x1932 }, { 0x1939, 0x193B }, - { 0x1A17, 0x1A18 }, { 0x1B00, 0x1B03 }, { 0x1B34, 0x1B34 }, - { 0x1B36, 0x1B3A }, { 0x1B3C, 0x1B3C }, { 0x1B42, 0x1B42 }, - { 0x1B6B, 0x1B73 }, { 0x1DC0, 0x1DCA }, { 0x1DFE, 0x1DFF }, - { 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x2060, 0x2063 }, - { 0x206A, 0x206F }, { 0x20D0, 0x20EF }, { 0x302A, 0x302F }, - { 0x3099, 0x309A }, { 0xA806, 0xA806 }, { 0xA80B, 0xA80B }, - { 0xA825, 0xA826 }, { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F }, - { 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB }, - { 0x10A01, 0x10A03 }, { 0x10A05, 0x10A06 }, { 0x10A0C, 0x10A0F }, - { 0x10A38, 0x10A3A }, { 0x10A3F, 0x10A3F }, { 0x1D167, 0x1D169 }, - { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD }, - { 0x1D242, 0x1D244 }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F }, - { 0xE0100, 0xE01EF } - }; + /* sorted list of non-overlapping intervals of non-spacing characters */ + /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ + static const struct interval combining[] = { + { 0x0300, 0x036F }, { 0x0483, 0x0486 }, { 0x0488, 0x0489 }, + { 0x0591, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 }, + { 0x05C4, 0x05C5 }, { 0x05C7, 0x05C7 }, { 0x0600, 0x0603 }, + { 0x0610, 0x0615 }, { 0x064B, 0x065E }, { 0x0670, 0x0670 }, + { 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED }, + { 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A }, + { 0x07A6, 0x07B0 }, { 0x07EB, 0x07F3 }, { 0x0901, 0x0902 }, + { 0x093C, 0x093C }, { 0x0941, 0x0948 }, { 0x094D, 0x094D }, + { 0x0951, 0x0954 }, { 0x0962, 0x0963 }, { 0x0981, 0x0981 }, + { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD }, + { 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 }, { 0x0A3C, 0x0A3C }, + { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D }, + { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC }, + { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD }, + { 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C }, + { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, { 0x0B4D, 0x0B4D }, + { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 }, + { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 }, + { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0CBC, 0x0CBC }, + { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD }, + { 0x0CE2, 0x0CE3 }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D }, + { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 }, + { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, + { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC }, + { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, + { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, + { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 }, + { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, + { 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 }, + { 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x135F, 0x135F }, + { 0x1712, 0x1714 }, { 0x1732, 0x1734 }, { 0x1752, 0x1753 }, + { 0x1772, 0x1773 }, { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD }, + { 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD }, + { 0x180B, 0x180D }, { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 }, + { 0x1927, 0x1928 }, { 0x1932, 0x1932 }, { 0x1939, 0x193B }, + { 0x1A17, 0x1A18 }, { 0x1B00, 0x1B03 }, { 0x1B34, 0x1B34 }, + { 0x1B36, 0x1B3A }, { 0x1B3C, 0x1B3C }, { 0x1B42, 0x1B42 }, + { 0x1B6B, 0x1B73 }, { 0x1DC0, 0x1DCA }, { 0x1DFE, 0x1DFF }, + { 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x2060, 0x2063 }, + { 0x206A, 0x206F }, { 0x20D0, 0x20EF }, { 0x302A, 0x302F }, + { 0x3099, 0x309A }, { 0xA806, 0xA806 }, { 0xA80B, 0xA80B }, + { 0xA825, 0xA826 }, { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F }, + { 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB }, + { 0x10A01, 0x10A03 }, { 0x10A05, 0x10A06 }, { 0x10A0C, 0x10A0F }, + { 0x10A38, 0x10A3A }, { 0x10A3F, 0x10A3F }, { 0x1D167, 0x1D169 }, + { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD }, + { 0x1D242, 0x1D244 }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F }, + { 0xE0100, 0xE01EF } + }; - /* test for 8-bit control characters */ - if (ucs == 0) - return 0; - if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0)) - return -1; + /* test for 8-bit control characters */ + if (ucs == 0) + return 0; + if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0)) + return -1; - /* binary search in table of non-spacing characters */ - if (bisearch(ucs, combining, - sizeof(combining) / sizeof(struct interval) - 1)) - return 0; + /* binary search in table of non-spacing characters */ + if (bisearch(ucs, combining, + sizeof(combining) / sizeof(struct interval) - 1)) + return 0; - /* if we arrive here, ucs is not a combining or C0/C1 control character */ + /* if we arrive here, ucs is not a combining or C0/C1 control character */ - return 1 + - (ucs >= 0x1100 && - (ucs <= 0x115f || /* Hangul Jamo init. consonants */ - ucs == 0x2329 || ucs == 0x232a || - (ucs >= 0x2e80 && ucs <= 0xa4cf && - ucs != 0x303f) || /* CJK ... Yi */ - (ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */ - (ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */ - (ucs >= 0xfe10 && ucs <= 0xfe19) || /* Vertical forms */ - (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */ - (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */ - (ucs >= 0xffe0 && ucs <= 0xffe6) || - (ucs >= 0x20000 && ucs <= 0x2fffd) || - (ucs >= 0x30000 && ucs <= 0x3fffd))); + return 1 + + (ucs >= 0x1100 && + (ucs <= 0x115f || /* Hangul Jamo init. consonants */ + ucs == 0x2329 || ucs == 0x232a || + (ucs >= 0x2e80 && ucs <= 0xa4cf && + ucs != 0x303f) || /* CJK ... Yi */ + (ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */ + (ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */ + (ucs >= 0xfe10 && ucs <= 0xfe19) || /* Vertical forms */ + (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */ + (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */ + (ucs >= 0xffe0 && ucs <= 0xffe6) || + (ucs >= 0x20000 && ucs <= 0x2fffd) || + (ucs >= 0x30000 && ucs <= 0x3fffd))); } int mk_wcswidth(const wchar_t *pwcs, size_t n) { - int w, width = 0; + int w, width = 0; - for (;*pwcs && n-- > 0; pwcs++) - if ((w = mk_wcwidth(*pwcs)) < 0) - return -1; - else - width += w; + for (; *pwcs && n-- > 0; pwcs++) + if ((w = mk_wcwidth(*pwcs)) < 0) + return -1; + else + width += w; - return width; + return width; } @@ -229,81 +230,81 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n) */ int mk_wcwidth_cjk(wchar_t ucs) { - /* sorted list of non-overlapping intervals of East Asian Ambiguous - * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */ - static const struct interval ambiguous[] = { - { 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 }, - { 0x00AA, 0x00AA }, { 0x00AE, 0x00AE }, { 0x00B0, 0x00B4 }, - { 0x00B6, 0x00BA }, { 0x00BC, 0x00BF }, { 0x00C6, 0x00C6 }, - { 0x00D0, 0x00D0 }, { 0x00D7, 0x00D8 }, { 0x00DE, 0x00E1 }, - { 0x00E6, 0x00E6 }, { 0x00E8, 0x00EA }, { 0x00EC, 0x00ED }, - { 0x00F0, 0x00F0 }, { 0x00F2, 0x00F3 }, { 0x00F7, 0x00FA }, - { 0x00FC, 0x00FC }, { 0x00FE, 0x00FE }, { 0x0101, 0x0101 }, - { 0x0111, 0x0111 }, { 0x0113, 0x0113 }, { 0x011B, 0x011B }, - { 0x0126, 0x0127 }, { 0x012B, 0x012B }, { 0x0131, 0x0133 }, - { 0x0138, 0x0138 }, { 0x013F, 0x0142 }, { 0x0144, 0x0144 }, - { 0x0148, 0x014B }, { 0x014D, 0x014D }, { 0x0152, 0x0153 }, - { 0x0166, 0x0167 }, { 0x016B, 0x016B }, { 0x01CE, 0x01CE }, - { 0x01D0, 0x01D0 }, { 0x01D2, 0x01D2 }, { 0x01D4, 0x01D4 }, - { 0x01D6, 0x01D6 }, { 0x01D8, 0x01D8 }, { 0x01DA, 0x01DA }, - { 0x01DC, 0x01DC }, { 0x0251, 0x0251 }, { 0x0261, 0x0261 }, - { 0x02C4, 0x02C4 }, { 0x02C7, 0x02C7 }, { 0x02C9, 0x02CB }, - { 0x02CD, 0x02CD }, { 0x02D0, 0x02D0 }, { 0x02D8, 0x02DB }, - { 0x02DD, 0x02DD }, { 0x02DF, 0x02DF }, { 0x0391, 0x03A1 }, - { 0x03A3, 0x03A9 }, { 0x03B1, 0x03C1 }, { 0x03C3, 0x03C9 }, - { 0x0401, 0x0401 }, { 0x0410, 0x044F }, { 0x0451, 0x0451 }, - { 0x2010, 0x2010 }, { 0x2013, 0x2016 }, { 0x2018, 0x2019 }, - { 0x201C, 0x201D }, { 0x2020, 0x2022 }, { 0x2024, 0x2027 }, - { 0x2030, 0x2030 }, { 0x2032, 0x2033 }, { 0x2035, 0x2035 }, - { 0x203B, 0x203B }, { 0x203E, 0x203E }, { 0x2074, 0x2074 }, - { 0x207F, 0x207F }, { 0x2081, 0x2084 }, { 0x20AC, 0x20AC }, - { 0x2103, 0x2103 }, { 0x2105, 0x2105 }, { 0x2109, 0x2109 }, - { 0x2113, 0x2113 }, { 0x2116, 0x2116 }, { 0x2121, 0x2122 }, - { 0x2126, 0x2126 }, { 0x212B, 0x212B }, { 0x2153, 0x2154 }, - { 0x215B, 0x215E }, { 0x2160, 0x216B }, { 0x2170, 0x2179 }, - { 0x2190, 0x2199 }, { 0x21B8, 0x21B9 }, { 0x21D2, 0x21D2 }, - { 0x21D4, 0x21D4 }, { 0x21E7, 0x21E7 }, { 0x2200, 0x2200 }, - { 0x2202, 0x2203 }, { 0x2207, 0x2208 }, { 0x220B, 0x220B }, - { 0x220F, 0x220F }, { 0x2211, 0x2211 }, { 0x2215, 0x2215 }, - { 0x221A, 0x221A }, { 0x221D, 0x2220 }, { 0x2223, 0x2223 }, - { 0x2225, 0x2225 }, { 0x2227, 0x222C }, { 0x222E, 0x222E }, - { 0x2234, 0x2237 }, { 0x223C, 0x223D }, { 0x2248, 0x2248 }, - { 0x224C, 0x224C }, { 0x2252, 0x2252 }, { 0x2260, 0x2261 }, - { 0x2264, 0x2267 }, { 0x226A, 0x226B }, { 0x226E, 0x226F }, - { 0x2282, 0x2283 }, { 0x2286, 0x2287 }, { 0x2295, 0x2295 }, - { 0x2299, 0x2299 }, { 0x22A5, 0x22A5 }, { 0x22BF, 0x22BF }, - { 0x2312, 0x2312 }, { 0x2460, 0x24E9 }, { 0x24EB, 0x254B }, - { 0x2550, 0x2573 }, { 0x2580, 0x258F }, { 0x2592, 0x2595 }, - { 0x25A0, 0x25A1 }, { 0x25A3, 0x25A9 }, { 0x25B2, 0x25B3 }, - { 0x25B6, 0x25B7 }, { 0x25BC, 0x25BD }, { 0x25C0, 0x25C1 }, - { 0x25C6, 0x25C8 }, { 0x25CB, 0x25CB }, { 0x25CE, 0x25D1 }, - { 0x25E2, 0x25E5 }, { 0x25EF, 0x25EF }, { 0x2605, 0x2606 }, - { 0x2609, 0x2609 }, { 0x260E, 0x260F }, { 0x2614, 0x2615 }, - { 0x261C, 0x261C }, { 0x261E, 0x261E }, { 0x2640, 0x2640 }, - { 0x2642, 0x2642 }, { 0x2660, 0x2661 }, { 0x2663, 0x2665 }, - { 0x2667, 0x266A }, { 0x266C, 0x266D }, { 0x266F, 0x266F }, - { 0x273D, 0x273D }, { 0x2776, 0x277F }, { 0xE000, 0xF8FF }, - { 0xFFFD, 0xFFFD }, { 0xF0000, 0xFFFFD }, { 0x100000, 0x10FFFD } - }; + /* sorted list of non-overlapping intervals of East Asian Ambiguous + * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */ + static const struct interval ambiguous[] = { + { 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 }, + { 0x00AA, 0x00AA }, { 0x00AE, 0x00AE }, { 0x00B0, 0x00B4 }, + { 0x00B6, 0x00BA }, { 0x00BC, 0x00BF }, { 0x00C6, 0x00C6 }, + { 0x00D0, 0x00D0 }, { 0x00D7, 0x00D8 }, { 0x00DE, 0x00E1 }, + { 0x00E6, 0x00E6 }, { 0x00E8, 0x00EA }, { 0x00EC, 0x00ED }, + { 0x00F0, 0x00F0 }, { 0x00F2, 0x00F3 }, { 0x00F7, 0x00FA }, + { 0x00FC, 0x00FC }, { 0x00FE, 0x00FE }, { 0x0101, 0x0101 }, + { 0x0111, 0x0111 }, { 0x0113, 0x0113 }, { 0x011B, 0x011B }, + { 0x0126, 0x0127 }, { 0x012B, 0x012B }, { 0x0131, 0x0133 }, + { 0x0138, 0x0138 }, { 0x013F, 0x0142 }, { 0x0144, 0x0144 }, + { 0x0148, 0x014B }, { 0x014D, 0x014D }, { 0x0152, 0x0153 }, + { 0x0166, 0x0167 }, { 0x016B, 0x016B }, { 0x01CE, 0x01CE }, + { 0x01D0, 0x01D0 }, { 0x01D2, 0x01D2 }, { 0x01D4, 0x01D4 }, + { 0x01D6, 0x01D6 }, { 0x01D8, 0x01D8 }, { 0x01DA, 0x01DA }, + { 0x01DC, 0x01DC }, { 0x0251, 0x0251 }, { 0x0261, 0x0261 }, + { 0x02C4, 0x02C4 }, { 0x02C7, 0x02C7 }, { 0x02C9, 0x02CB }, + { 0x02CD, 0x02CD }, { 0x02D0, 0x02D0 }, { 0x02D8, 0x02DB }, + { 0x02DD, 0x02DD }, { 0x02DF, 0x02DF }, { 0x0391, 0x03A1 }, + { 0x03A3, 0x03A9 }, { 0x03B1, 0x03C1 }, { 0x03C3, 0x03C9 }, + { 0x0401, 0x0401 }, { 0x0410, 0x044F }, { 0x0451, 0x0451 }, + { 0x2010, 0x2010 }, { 0x2013, 0x2016 }, { 0x2018, 0x2019 }, + { 0x201C, 0x201D }, { 0x2020, 0x2022 }, { 0x2024, 0x2027 }, + { 0x2030, 0x2030 }, { 0x2032, 0x2033 }, { 0x2035, 0x2035 }, + { 0x203B, 0x203B }, { 0x203E, 0x203E }, { 0x2074, 0x2074 }, + { 0x207F, 0x207F }, { 0x2081, 0x2084 }, { 0x20AC, 0x20AC }, + { 0x2103, 0x2103 }, { 0x2105, 0x2105 }, { 0x2109, 0x2109 }, + { 0x2113, 0x2113 }, { 0x2116, 0x2116 }, { 0x2121, 0x2122 }, + { 0x2126, 0x2126 }, { 0x212B, 0x212B }, { 0x2153, 0x2154 }, + { 0x215B, 0x215E }, { 0x2160, 0x216B }, { 0x2170, 0x2179 }, + { 0x2190, 0x2199 }, { 0x21B8, 0x21B9 }, { 0x21D2, 0x21D2 }, + { 0x21D4, 0x21D4 }, { 0x21E7, 0x21E7 }, { 0x2200, 0x2200 }, + { 0x2202, 0x2203 }, { 0x2207, 0x2208 }, { 0x220B, 0x220B }, + { 0x220F, 0x220F }, { 0x2211, 0x2211 }, { 0x2215, 0x2215 }, + { 0x221A, 0x221A }, { 0x221D, 0x2220 }, { 0x2223, 0x2223 }, + { 0x2225, 0x2225 }, { 0x2227, 0x222C }, { 0x222E, 0x222E }, + { 0x2234, 0x2237 }, { 0x223C, 0x223D }, { 0x2248, 0x2248 }, + { 0x224C, 0x224C }, { 0x2252, 0x2252 }, { 0x2260, 0x2261 }, + { 0x2264, 0x2267 }, { 0x226A, 0x226B }, { 0x226E, 0x226F }, + { 0x2282, 0x2283 }, { 0x2286, 0x2287 }, { 0x2295, 0x2295 }, + { 0x2299, 0x2299 }, { 0x22A5, 0x22A5 }, { 0x22BF, 0x22BF }, + { 0x2312, 0x2312 }, { 0x2460, 0x24E9 }, { 0x24EB, 0x254B }, + { 0x2550, 0x2573 }, { 0x2580, 0x258F }, { 0x2592, 0x2595 }, + { 0x25A0, 0x25A1 }, { 0x25A3, 0x25A9 }, { 0x25B2, 0x25B3 }, + { 0x25B6, 0x25B7 }, { 0x25BC, 0x25BD }, { 0x25C0, 0x25C1 }, + { 0x25C6, 0x25C8 }, { 0x25CB, 0x25CB }, { 0x25CE, 0x25D1 }, + { 0x25E2, 0x25E5 }, { 0x25EF, 0x25EF }, { 0x2605, 0x2606 }, + { 0x2609, 0x2609 }, { 0x260E, 0x260F }, { 0x2614, 0x2615 }, + { 0x261C, 0x261C }, { 0x261E, 0x261E }, { 0x2640, 0x2640 }, + { 0x2642, 0x2642 }, { 0x2660, 0x2661 }, { 0x2663, 0x2665 }, + { 0x2667, 0x266A }, { 0x266C, 0x266D }, { 0x266F, 0x266F }, + { 0x273D, 0x273D }, { 0x2776, 0x277F }, { 0xE000, 0xF8FF }, + { 0xFFFD, 0xFFFD }, { 0xF0000, 0xFFFFD }, { 0x100000, 0x10FFFD } + }; - /* binary search in table of non-spacing characters */ - if (bisearch(ucs, ambiguous, - sizeof(ambiguous) / sizeof(struct interval) - 1)) - return 2; + /* binary search in table of non-spacing characters */ + if (bisearch(ucs, ambiguous, + sizeof(ambiguous) / sizeof(struct interval) - 1)) + return 2; - return mk_wcwidth(ucs); + return mk_wcwidth(ucs); } int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) { - int w, width = 0; + int w, width = 0; - for (;*pwcs && n-- > 0; pwcs++) - if ((w = mk_wcwidth_cjk(*pwcs)) < 0) - return -1; - else - width += w; + for (; *pwcs && n-- > 0; pwcs++) + if ((w = mk_wcwidth_cjk(*pwcs)) < 0) + return -1; + else + width += w; - return width; + return width; } diff --git a/tests/test.c b/tests/test.c index dbebf10..891f1a1 100644 --- a/tests/test.c +++ b/tests/test.c @@ -14,7 +14,8 @@ struct test_case test_suit [] = { {"test_table_tbl_options", test_table_tbl_options}, }; -int main(void) { +int main(void) +{ int n_tests = sizeof(test_suit) / sizeof(test_suit[0]); fprintf(stderr, "[==========] Running %d test(s).\n", n_tests); int i; diff --git a/tests/test_string_buffer.c b/tests/test_string_buffer.c index 6b21691..5c9447e 100644 --- a/tests/test_string_buffer.c +++ b/tests/test_string_buffer.c @@ -5,14 +5,14 @@ #include "wchar.h" -size_t strchr_count(const char* str, char ch); -size_t wstrchr_count(const wchar_t* str, wchar_t ch); +size_t strchr_count(const char *str, char ch); +size_t wstrchr_count(const wchar_t *str, wchar_t ch); -const char* str_n_substring_beg(const char* str, char ch_separator, size_t n); -const wchar_t* wstr_n_substring_beg(const wchar_t* str, wchar_t ch_separator, size_t n); +const char *str_n_substring_beg(const char *str, char ch_separator, size_t n); +const wchar_t *wstr_n_substring_beg(const wchar_t *str, wchar_t ch_separator, size_t n); -fort_status_t str_n_substring(const char* str, char ch_separator, size_t n, const char **begin, const char **end); -void wstr_n_substring(const wchar_t* str, wchar_t ch_separator, size_t n, const wchar_t **begin, const wchar_t **end); +fort_status_t str_n_substring(const char *str, char ch_separator, size_t n, const char **begin, const char **end); +void wstr_n_substring(const wchar_t *str, wchar_t ch_separator, size_t n, const wchar_t **begin, const wchar_t **end); size_t buffer_text_width(string_buffer_t *buffer); @@ -149,14 +149,14 @@ void test_str_n_substring(void) assert_true(wbeg == wstr && wend == wstr + 1); str_n_substring(str, '\n', 1, &beg, &end); - assert_true(beg == str +4 && end == str + 8); + assert_true(beg == str + 4 && end == str + 8); str_n_substring(str, '\n', 2, &beg, &end); assert_true(beg == str + 9 && end == str + strlen(str)); str_n_substring(str, '\n', 3, &beg, &end); assert_true(beg == NULL && end == NULL); wstr_n_substring(wstr, L'\n', 1, &wbeg, &wend); - assert_true(wbeg == wstr +4 && wend == wstr + 8); + assert_true(wbeg == wstr + 4 && wend == wstr + 8); wstr_n_substring(wstr, L'\n', 2, &wbeg, &wend); assert_true(wbeg == wstr + 9 && wend == wstr + wcslen(wstr)); wstr_n_substring(wstr, L'\n', 3, &wbeg, &wend); @@ -200,22 +200,22 @@ void test_buffer_text_width(void) buffer->type = CharBuf; char *old_value = buffer->str.cstr; - buffer->str.cstr = (char*)""; + buffer->str.cstr = (char *)""; assert_true(buffer_text_width(buffer) == 0); - buffer->str.cstr = (char*)"\n\n\n\n"; + buffer->str.cstr = (char *)"\n\n\n\n"; assert_true(buffer_text_width(buffer) == 0); - buffer->str.cstr = (char*)"12345"; + buffer->str.cstr = (char *)"12345"; assert_true(buffer_text_width(buffer) == 5); - buffer->str.cstr = (char*)"12345\n1234567"; + buffer->str.cstr = (char *)"12345\n1234567"; assert_true(buffer_text_width(buffer) == 7); - buffer->str.cstr = (char*)"12345\n1234567\n"; + buffer->str.cstr = (char *)"12345\n1234567\n"; assert_true(buffer_text_width(buffer) == 7); - buffer->str.cstr = (char*)"12345\n1234567\n123"; + buffer->str.cstr = (char *)"12345\n1234567\n123"; assert_true(buffer_text_width(buffer) == 7); @@ -253,25 +253,25 @@ void test_buffer_text_height(void) buffer->type = CharBuf; char *old_value = buffer->str.cstr; - buffer->str.cstr = (char*)""; + buffer->str.cstr = (char *)""; assert_true(buffer_text_height(buffer) == 0); - buffer->str.cstr = (char*)"\n"; + buffer->str.cstr = (char *)"\n"; assert_true(buffer_text_height(buffer) == 2); - buffer->str.cstr = (char*)"\n\n"; + buffer->str.cstr = (char *)"\n\n"; assert_true(buffer_text_height(buffer) == 3); - buffer->str.cstr = (char*)"\n\n\n\n"; + buffer->str.cstr = (char *)"\n\n\n\n"; assert_true(buffer_text_height(buffer) == 5); - buffer->str.cstr = (char*)"12345"; + buffer->str.cstr = (char *)"12345"; assert_true(buffer_text_height(buffer) == 1); - buffer->str.cstr = (char*)"\n12345"; + buffer->str.cstr = (char *)"\n12345"; assert_true(buffer_text_height(buffer) == 2); - buffer->str.cstr = (char*)"\n12345\n\n2"; + buffer->str.cstr = (char *)"\n12345\n\n2"; assert_true(buffer_text_height(buffer) == 4); diff --git a/tests/test_table_basic.c b/tests/test_table_basic.c index ce16da6..6a0f796 100644 --- a/tests/test_table_basic.c +++ b/tests/test_table_basic.c @@ -7,60 +7,60 @@ void test_table_basic(void) WHEN("All columns are equal and not empty") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); - assert_true( FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS); - assert_true( FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS); - assert_true( FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+---+---+-----+----------+\n" - "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" - "| | | | |\n" - "+---+---+-----+----------+\n" - "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" - "| | | | |\n" - "+---+---+-----+----------+\n" - "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" - "| | | | |\n" - "+---+---+-----+----------+\n"; + "+---+---+-----+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+---+---+-----+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+---+---+-----+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+---+---+-----+----------+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } WHEN("All columns are equal and not empty (wide strings)") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); - assert_true( FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS); - assert_true( FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS); - assert_true( FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS); const wchar_t *table_str = ft_to_wstring(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const wchar_t *table_str_etalon = - L"+---+---+-----+----------+\n" - L"| | | | |\n" - L"| 3 | c | 234 | 3.140000 |\n" - L"| | | | |\n" - L"+---+---+-----+----------+\n" - L"| | | | |\n" - L"| 3 | c | 234 | 3.140000 |\n" - L"| | | | |\n" - L"+---+---+-----+----------+\n" - L"| | | | |\n" - L"| 3 | c | 234 | 3.140000 |\n" - L"| | | | |\n" - L"+---+---+-----+----------+\n"; + L"+---+---+-----+----------+\n" + L"| | | | |\n" + L"| 3 | c | 234 | 3.140000 |\n" + L"| | | | |\n" + L"+---+---+-----+----------+\n" + L"| | | | |\n" + L"| 3 | c | 234 | 3.140000 |\n" + L"| | | | |\n" + L"+---+---+-----+----------+\n" + L"| | | | |\n" + L"| 3 | c | 234 | 3.140000 |\n" + L"| | | | |\n" + L"+---+---+-----+----------+\n"; assert_wcs_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -69,180 +69,180 @@ void test_table_basic(void) WHEN("All columns are not equal and not empty") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); - assert_true( FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS); - assert_true( FT_NWRITE_LN(table, "c", "234", "3.140000", "3") == FT_SUCCESS); - assert_true( FT_NWRITE_LN(table, "234", "3.140000", "3", "c") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "c", "234", "3.140000", "3") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "234", "3.140000", "3", "c") == FT_SUCCESS); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| c | 234 | 3.140000 | 3 |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| 234 | 3.140000 | 3 | c |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n"; + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| c | 234 | 3.140000 | 3 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 234 | 3.140000 | 3 | c |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } WHEN("All columns are not equal and not empty (wide strings)") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); - assert_true( FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS); - assert_true( FT_NWWRITE_LN(table, L"c", L"234", L"3.140000", L"3") == FT_SUCCESS); - assert_true( FT_NWWRITE_LN(table, L"234", L"3.140000", L"3", L"c") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"c", L"234", L"3.140000", L"3") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"234", L"3.140000", L"3", L"c") == FT_SUCCESS); const wchar_t *table_str = ft_to_wstring(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const wchar_t *table_str_etalon = - L"+-----+----------+----------+----------+\n" - L"| | | | |\n" - L"| 3 | c | 234 | 3.140000 |\n" - L"| | | | |\n" - L"+-----+----------+----------+----------+\n" - L"| | | | |\n" - L"| c | 234 | 3.140000 | 3 |\n" - L"| | | | |\n" - L"+-----+----------+----------+----------+\n" - L"| | | | |\n" - L"| 234 | 3.140000 | 3 | c |\n" - L"| | | | |\n" - L"+-----+----------+----------+----------+\n"; + L"+-----+----------+----------+----------+\n" + L"| | | | |\n" + L"| 3 | c | 234 | 3.140000 |\n" + L"| | | | |\n" + L"+-----+----------+----------+----------+\n" + L"| | | | |\n" + L"| c | 234 | 3.140000 | 3 |\n" + L"| | | | |\n" + L"+-----+----------+----------+----------+\n" + L"| | | | |\n" + L"| 234 | 3.140000 | 3 | c |\n" + L"| | | | |\n" + L"+-----+----------+----------+----------+\n"; assert_wcs_equal(table_str, table_str_etalon); ft_destroy_table(table); } WHEN("All columns are not equal and some cells are empty") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); - assert_true( FT_NWRITE_LN(table, "", "", "234", "3.140000") == FT_SUCCESS); - assert_true( FT_NWRITE_LN(table, "c", "234", "3.140000", "") == FT_SUCCESS); - assert_true( FT_NWRITE_LN(table, "234", "3.140000", "", "") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "", "", "234", "3.140000") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "c", "234", "3.140000", "") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "234", "3.140000", "", "") == FT_SUCCESS); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| | | 234 | 3.140000 |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| c | 234 | 3.140000 | |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| 234 | 3.140000 | | |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n"; + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| | | 234 | 3.140000 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| c | 234 | 3.140000 | |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 234 | 3.140000 | | |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } WHEN("All columns are not equal and some cells are empty (wide strings)") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); - assert_true( FT_NWWRITE_LN(table, L"", L"", L"234", L"3.140000") == FT_SUCCESS); - assert_true( FT_NWWRITE_LN(table, L"c", L"234", L"3.140000", L"") == FT_SUCCESS); - assert_true( FT_NWWRITE_LN(table, L"234", L"3.140000", L"", L"") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"", L"", L"234", L"3.140000") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"c", L"234", L"3.140000", L"") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"234", L"3.140000", L"", L"") == FT_SUCCESS); const wchar_t *table_str = ft_to_wstring(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const wchar_t *table_str_etalon = - L"+-----+----------+----------+----------+\n" - L"| | | | |\n" - L"| | | 234 | 3.140000 |\n" - L"| | | | |\n" - L"+-----+----------+----------+----------+\n" - L"| | | | |\n" - L"| c | 234 | 3.140000 | |\n" - L"| | | | |\n" - L"+-----+----------+----------+----------+\n" - L"| | | | |\n" - L"| 234 | 3.140000 | | |\n" - L"| | | | |\n" - L"+-----+----------+----------+----------+\n"; + L"+-----+----------+----------+----------+\n" + L"| | | | |\n" + L"| | | 234 | 3.140000 |\n" + L"| | | | |\n" + L"+-----+----------+----------+----------+\n" + L"| | | | |\n" + L"| c | 234 | 3.140000 | |\n" + L"| | | | |\n" + L"+-----+----------+----------+----------+\n" + L"| | | | |\n" + L"| 234 | 3.140000 | | |\n" + L"| | | | |\n" + L"+-----+----------+----------+----------+\n"; assert_wcs_equal(table_str, table_str_etalon); ft_destroy_table(table); } WHEN("All cells are empty") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); - assert_true( FT_NWRITE_LN(table, "", "", "", "") == FT_SUCCESS); - assert_true( FT_NWRITE_LN(table, "", "", "", "") == FT_SUCCESS); - assert_true( FT_NWRITE_LN(table, "", "", "", "") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "", "", "", "") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "", "", "", "") == FT_SUCCESS); + assert_true(FT_NWRITE_LN(table, "", "", "", "") == FT_SUCCESS); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+--+--+--+--+\n" - "| | | | |\n" - "| | | | |\n" - "| | | | |\n" - "+--+--+--+--+\n" - "| | | | |\n" - "| | | | |\n" - "| | | | |\n" - "+--+--+--+--+\n" - "| | | | |\n" - "| | | | |\n" - "| | | | |\n" - "+--+--+--+--+\n"; + "+--+--+--+--+\n" + "| | | | |\n" + "| | | | |\n" + "| | | | |\n" + "+--+--+--+--+\n" + "| | | | |\n" + "| | | | |\n" + "| | | | |\n" + "+--+--+--+--+\n" + "| | | | |\n" + "| | | | |\n" + "| | | | |\n" + "+--+--+--+--+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } WHEN("All cells are empty (wide strings)") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); - assert_true( FT_NWWRITE_LN(table, L"", L"", L"", L"") == FT_SUCCESS); - assert_true( FT_NWWRITE_LN(table, L"", L"", L"", L"") == FT_SUCCESS); - assert_true( FT_NWWRITE_LN(table, L"", L"", L"", L"") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"", L"", L"", L"") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"", L"", L"", L"") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"", L"", L"", L"") == FT_SUCCESS); const wchar_t *table_str = ft_to_wstring(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const wchar_t *table_str_etalon = - L"+--+--+--+--+\n" - L"| | | | |\n" - L"| | | | |\n" - L"| | | | |\n" - L"+--+--+--+--+\n" - L"| | | | |\n" - L"| | | | |\n" - L"| | | | |\n" - L"+--+--+--+--+\n" - L"| | | | |\n" - L"| | | | |\n" - L"| | | | |\n" - L"+--+--+--+--+\n"; + L"+--+--+--+--+\n" + L"| | | | |\n" + L"| | | | |\n" + L"| | | | |\n" + L"+--+--+--+--+\n" + L"| | | | |\n" + L"| | | | |\n" + L"| | | | |\n" + L"+--+--+--+--+\n" + L"| | | | |\n" + L"| | | | |\n" + L"| | | | |\n" + L"+--+--+--+--+\n"; assert_wcs_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -257,30 +257,30 @@ void test_wcs_table_boundaries(void) WHEN("All columns are not equal and not empty (wide strings)") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); - assert_true( FT_NWWRITE_LN(table, L"3", L"12345\x8888\x8888", L"c") == FT_SUCCESS); /* \x8888,\x8888 - occupy 2 columns each */ - assert_true( FT_NWWRITE_LN(table, L"c", L"12345678\x500", L"c") == FT_SUCCESS); /* \x500 - occupies 1 column */ - assert_true( FT_NWWRITE_LN(table, L"234", L"123456789", L"c") == FT_SUCCESS); + assert_true(FT_NWWRITE_LN(table, L"3", L"12345\x8888\x8888", L"c") == FT_SUCCESS); /* \x8888,\x8888 - occupy 2 columns each */ + assert_true(FT_NWWRITE_LN(table, L"c", L"12345678\x500", L"c") == FT_SUCCESS); /* \x500 - occupies 1 column */ + assert_true(FT_NWWRITE_LN(table, L"234", L"123456789", L"c") == FT_SUCCESS); const wchar_t *table_str = ft_to_wstring(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const wchar_t *table_str_etalon = - L"+-----+-----------+---+\n" - L"| | | |\n" - L"| 3 | 12345\x8888\x8888 | c |\n" - L"| | | |\n" - L"+-----+-----------+---+\n" - L"| | | |\n" - L"| c | 12345678\x500 | c |\n" - L"| | | |\n" - L"+-----+-----------+---+\n" - L"| | | |\n" - L"| 234 | 123456789 | c |\n" - L"| | | |\n" - L"+-----+-----------+---+\n"; + L"+-----+-----------+---+\n" + L"| | | |\n" + L"| 3 | 12345\x8888\x8888 | c |\n" + L"| | | |\n" + L"+-----+-----------+---+\n" + L"| | | |\n" + L"| c | 12345678\x500 | c |\n" + L"| | | |\n" + L"+-----+-----------+---+\n" + L"| | | |\n" + L"| 234 | 123456789 | c |\n" + L"| | | |\n" + L"+-----+-----------+---+\n"; assert_wcs_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -293,8 +293,8 @@ void test_table_write(void) SCENARIO("Test row_write functions") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); const char *row_0[4] = {"3", "c", "234", "3.140000"}; @@ -305,29 +305,29 @@ void test_table_write(void) assert_true(ft_row_write_ln(table, 4, row_2) == FT_SUCCESS); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| c | 234 | 3.140000 | 3 |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| 234 | 3.140000 | 3 | c |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n"; - assert_str_equal( table_str, table_str_etalon ); + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| c | 234 | 3.140000 | 3 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 234 | 3.140000 | 3 | c |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n"; + assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } SCENARIO("Test row_write functions(wide strings)") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); const wchar_t *row_0[4] = {L"3", L"c", L"234", L"3.140000"}; @@ -338,56 +338,56 @@ void test_table_write(void) assert_true(ft_row_wwrite_ln(table, 4, row_2) == FT_SUCCESS); const wchar_t *table_str = ft_to_wstring(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const wchar_t *table_str_etalon = - L"+-----+----------+----------+----------+\n" - L"| | | | |\n" - L"| 3 | c | 234 | 3.140000 |\n" - L"| | | | |\n" - L"+-----+----------+----------+----------+\n" - L"| | | | |\n" - L"| c | 234 | 3.140000 | 3 |\n" - L"| | | | |\n" - L"+-----+----------+----------+----------+\n" - L"| | | | |\n" - L"| 234 | 3.140000 | 3 | c |\n" - L"| | | | |\n" - L"+-----+----------+----------+----------+\n"; - assert_wcs_equal( table_str, table_str_etalon ); + L"+-----+----------+----------+----------+\n" + L"| | | | |\n" + L"| 3 | c | 234 | 3.140000 |\n" + L"| | | | |\n" + L"+-----+----------+----------+----------+\n" + L"| | | | |\n" + L"| c | 234 | 3.140000 | 3 |\n" + L"| | | | |\n" + L"+-----+----------+----------+----------+\n" + L"| | | | |\n" + L"| 234 | 3.140000 | 3 | c |\n" + L"| | | | |\n" + L"+-----+----------+----------+----------+\n"; + assert_wcs_equal(table_str, table_str_etalon); ft_destroy_table(table); } SCENARIO("Test printf functions") { table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); int n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14); - assert_true( n == 4 ); + assert_true(n == 4); n = ft_printf_ln(table, "%c|%s|%f|%d", 'c', "234", 3.14, 3); - assert_true( n == 4 ); + assert_true(n == 4); n = ft_printf_ln(table, "%s|%f|%d|%c", "234", 3.14, 3, 'c'); - assert_true( n == 4 ); + assert_true(n == 4); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| c | 234 | 3.140000 | 3 |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n" - "| | | | |\n" - "| 234 | 3.140000 | 3 | c |\n" - "| | | | |\n" - "+-----+----------+----------+----------+\n"; - assert_str_equal( table_str, table_str_etalon ); + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| c | 234 | 3.140000 | 3 |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n" + "| | | | |\n" + "| 234 | 3.140000 | 3 | c |\n" + "| | | | |\n" + "+-----+----------+----------+----------+\n"; + assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } diff --git a/tests/test_table_border_style.c b/tests/test_table_border_style.c index 9a82533..e16eda5 100644 --- a/tests/test_table_border_style.c +++ b/tests/test_table_border_style.c @@ -34,21 +34,21 @@ void test_table_border_style(void) table = create_test_int_table(0); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+***+***+****+****+\n" - "v v v v v\n" - "v 3 v 4 v 55 v 67 v\n" - "v v v v v\n" - "+***#***#****#****+\n" - "= = = = =\n" - "= 3 = 4 = 55 = 67 =\n" - "= = = = =\n" - "+|||#|||#||||#||||+\n" - "= = = = =\n" - "= 3 = 4 = 55 = 67 =\n" - "= = = = =\n" - "+|||+|||+||||+||||+\n"; + "+***+***+****+****+\n" + "v v v v v\n" + "v 3 v 4 v 55 v 67 v\n" + "v v v v v\n" + "+***#***#****#****+\n" + "= = = = =\n" + "= 3 = 4 = 55 = 67 =\n" + "= = = = =\n" + "+|||#|||#||||#||||+\n" + "= = = = =\n" + "= 3 = 4 = 55 = 67 =\n" + "= = = = =\n" + "+|||+|||+||||+||||+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); @@ -79,14 +79,14 @@ void test_table_border_style(void) table = create_test_int_table(0); table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); table_str_etalon = - "+***+***+****+****+\n" - "v 3 v 4 v 55 v 67 v\n" - "+***#***#****#****+\n" - "= 3 = 4 = 55 = 67 =\n" - "= 3 = 4 = 55 = 67 =\n" - "+|||+|||+||||+||||+\n"; + "+***+***+****+****+\n" + "v 3 v 4 v 55 v 67 v\n" + "+***#***#****#****+\n" + "= 3 = 4 = 55 = 67 =\n" + "= 3 = 4 = 55 = 67 =\n" + "+|||+|||+||||+||||+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -99,28 +99,28 @@ void test_table_border_style(void) ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67); - assert_true( n == 4 ); + assert_true(n == 4); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+===+===+====+====+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n"; + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+===+===+====+====+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } diff --git a/tests/test_table_geometry.c b/tests/test_table_geometry.c index f312b2e..3040dfc 100644 --- a/tests/test_table_geometry.c +++ b/tests/test_table_geometry.c @@ -5,8 +5,8 @@ void test_table_sizes(void) { FTABLE *table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); size_t rows = 0; @@ -15,36 +15,36 @@ void test_table_sizes(void) WHEN("Table is empty") { status = get_table_sizes(table, &rows, &cols); - assert_true( IS_SUCCESS(status) ); - assert_true( rows == 0 ); - assert_true( cols == 0 ); + assert_true(IS_SUCCESS(status)); + assert_true(rows == 0); + assert_true(cols == 0); } WHEN("Insert one cell") { int n = ft_printf_ln(table, "%c", 'c'); - assert_true( n == 1 ); + assert_true(n == 1); status = get_table_sizes(table, &rows, &cols); - assert_true( IS_SUCCESS(status) ); - assert_true( rows == 1 ); - assert_true( cols == 1 ); + assert_true(IS_SUCCESS(status)); + assert_true(rows == 1); + assert_true(cols == 1); } WHEN("Insert two cells in the next row") { int n = ft_printf_ln(table, "%c|%c", 'c', 'd'); - assert_true( n == 2 ); + assert_true(n == 2); status = get_table_sizes(table, &rows, &cols); - assert_true( IS_SUCCESS(status) ); - assert_true( rows == 2 ); - assert_true( cols == 2 ); + assert_true(IS_SUCCESS(status)); + assert_true(rows == 2); + assert_true(cols == 2); } WHEN("Insert five cells in the next row") { int n = ft_printf_ln(table, "%d|%d|%d|%d|%d", 1, 2, 3, 4, 5); - assert_true( n == 5 ); + assert_true(n == 5); status = get_table_sizes(table, &rows, &cols); - assert_true( IS_SUCCESS(status) ); - assert_true( rows == 3 ); - assert_true( cols == 5 ); + assert_true(IS_SUCCESS(status)); + assert_true(rows == 3); + assert_true(cols == 5); } ft_destroy_table(table); @@ -54,8 +54,8 @@ void test_table_sizes(void) void test_table_geometry(void) { FTABLE *table = ft_create_table(); - assert_true( table != NULL ); - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(table != NULL); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); size_t height = 0; size_t width = 0; @@ -63,27 +63,27 @@ void test_table_geometry(void) WHEN("Table is empty") { status = table_geometry(table, &height, &width); - assert_true( IS_SUCCESS(status) ); - assert_true( height == 2 ); - assert_true( width == 3 ); + assert_true(IS_SUCCESS(status)); + assert_true(height == 2); + assert_true(width == 3); } WHEN("Table has one cell") { int n = ft_printf_ln(table, "%c", 'c'); - assert_true( n == 1 ); + assert_true(n == 1); status = table_geometry(table, &height, &width); - assert_true( IS_SUCCESS(status) ); - assert_true( height == 5 ); - assert_true( width == 6 ); + assert_true(IS_SUCCESS(status)); + assert_true(height == 5); + assert_true(width == 6); } WHEN("Inserting 3 cells in the next row") { int n = ft_printf_ln(table, "%c|%s|%c", 'c', "as", 'e'); - assert_true( n == 3 ); + assert_true(n == 3); status = table_geometry(table, &height, &width); - assert_true( IS_SUCCESS(status) ); - assert_true( height == 9 ); - assert_true( width == 15 ); + assert_true(IS_SUCCESS(status)); + assert_true(height == 9); + assert_true(width == 15); } ft_destroy_table(table); diff --git a/tests/test_table_options.c b/tests/test_table_options.c index a573cd6..889b7df 100644 --- a/tests/test_table_options.c +++ b/tests/test_table_options.c @@ -19,21 +19,21 @@ void test_table_tbl_options(void) table = create_test_int_table(0); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n"; + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n"; assert_str_equal(table_str, table_str_etalon); /* Now set table options */ @@ -42,28 +42,28 @@ void test_table_tbl_options(void) ft_set_tbl_option(table, FT_TOPT_LEFT_MARGIN, 1); ft_set_tbl_option(table, FT_TOPT_RIGHT_MARGIN, 2); table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); table_str_etalon = - " \n" - " \n" - " \n" - " +---+---+----+----+ \n" - " | | | | | \n" - " | 3 | 4 | 55 | 67 | \n" - " | | | | | \n" - " +---+---+----+----+ \n" - " | | | | | \n" - " | 3 | 4 | 55 | 67 | \n" - " | | | | | \n" - " +---+---+----+----+ \n" - " | | | | | \n" - " | 3 | 4 | 55 | 67 | \n" - " | | | | | \n" - " +---+---+----+----+ \n" - " \n" - " \n" - " \n" - " \n"; + " \n" + " \n" + " \n" + " +---+---+----+----+ \n" + " | | | | | \n" + " | 3 | 4 | 55 | 67 | \n" + " | | | | | \n" + " +---+---+----+----+ \n" + " | | | | | \n" + " | 3 | 4 | 55 | 67 | \n" + " | | | | | \n" + " +---+---+----+----+ \n" + " | | | | | \n" + " | 3 | 4 | 55 | 67 | \n" + " | | | | | \n" + " +---+---+----+----+ \n" + " \n" + " \n" + " \n" + " \n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); @@ -76,21 +76,21 @@ void test_table_tbl_options(void) table = create_test_int_wtable(0); const wchar_t *table_str = ft_to_wstring(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const wchar_t *table_str_etalon = - L"+---+---+----+----+\n" - L"| | | | |\n" - L"| 3 | 4 | 55 | 67 |\n" - L"| | | | |\n" - L"+---+---+----+----+\n" - L"| | | | |\n" - L"| 3 | 4 | 55 | 67 |\n" - L"| | | | |\n" - L"+---+---+----+----+\n" - L"| | | | |\n" - L"| 3 | 4 | 55 | 67 |\n" - L"| | | | |\n" - L"+---+---+----+----+\n"; + L"+---+---+----+----+\n" + L"| | | | |\n" + L"| 3 | 4 | 55 | 67 |\n" + L"| | | | |\n" + L"+---+---+----+----+\n" + L"| | | | |\n" + L"| 3 | 4 | 55 | 67 |\n" + L"| | | | |\n" + L"+---+---+----+----+\n" + L"| | | | |\n" + L"| 3 | 4 | 55 | 67 |\n" + L"| | | | |\n" + L"+---+---+----+----+\n"; assert_wcs_equal(table_str, table_str_etalon); /* Now set table options */ @@ -99,28 +99,28 @@ void test_table_tbl_options(void) ft_set_tbl_option(table, FT_TOPT_LEFT_MARGIN, 1); ft_set_tbl_option(table, FT_TOPT_RIGHT_MARGIN, 2); table_str = ft_to_wstring(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); table_str_etalon = - L" \n" - L" \n" - L" \n" - L" +---+---+----+----+ \n" - L" | | | | | \n" - L" | 3 | 4 | 55 | 67 | \n" - L" | | | | | \n" - L" +---+---+----+----+ \n" - L" | | | | | \n" - L" | 3 | 4 | 55 | 67 | \n" - L" | | | | | \n" - L" +---+---+----+----+ \n" - L" | | | | | \n" - L" | 3 | 4 | 55 | 67 | \n" - L" | | | | | \n" - L" +---+---+----+----+ \n" - L" \n" - L" \n" - L" \n" - L" \n"; + L" \n" + L" \n" + L" \n" + L" +---+---+----+----+ \n" + L" | | | | | \n" + L" | 3 | 4 | 55 | 67 | \n" + L" | | | | | \n" + L" +---+---+----+----+ \n" + L" | | | | | \n" + L" | 3 | 4 | 55 | 67 | \n" + L" | | | | | \n" + L" +---+---+----+----+ \n" + L" | | | | | \n" + L" | 3 | 4 | 55 | 67 | \n" + L" | | | | | \n" + L" +---+---+----+----+ \n" + L" \n" + L" \n" + L" \n" + L" \n"; assert_wcs_equal(table_str, table_str_etalon); ft_destroy_table(table); @@ -145,21 +145,21 @@ void test_table_cell_options(void) table = create_test_int_table(0); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n"; + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -176,15 +176,15 @@ void test_table_cell_options(void) table = create_test_int_table(0); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+---+---+----+----+\n" - "| 3 | 4 | 55 | 67 |\n" - "+---+---+----+----+\n" - "| 3 | 4 | 55 | 67 |\n" - "+---+---+----+----+\n" - "| 3 | 4 | 55 | 67 |\n" - "+---+---+----+----+\n"; + "+---+---+----+----+\n" + "| 3 | 4 | 55 | 67 |\n" + "+---+---+----+----+\n" + "| 3 | 4 | 55 | 67 |\n" + "+---+---+----+----+\n" + "| 3 | 4 | 55 | 67 |\n" + "+---+---+----+----+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -199,21 +199,21 @@ void test_table_cell_options(void) table = create_test_int_table(0); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+-+-+--+--+\n" - "| | | | |\n" - "|3|4|55|67|\n" - "| | | | |\n" - "+-+-+--+--+\n" - "| | | | |\n" - "|3|4|55|67|\n" - "| | | | |\n" - "+-+-+--+--+\n" - "| | | | |\n" - "|3|4|55|67|\n" - "| | | | |\n" - "+-+-+--+--+\n"; + "+-+-+--+--+\n" + "| | | | |\n" + "|3|4|55|67|\n" + "| | | | |\n" + "+-+-+--+--+\n" + "| | | | |\n" + "|3|4|55|67|\n" + "| | | | |\n" + "+-+-+--+--+\n" + "| | | | |\n" + "|3|4|55|67|\n" + "| | | | |\n" + "+-+-+--+--+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -228,15 +228,15 @@ void test_table_cell_options(void) table = create_test_int_table(0); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+-+-+--+--+\n" - "|3|4|55|67|\n" - "+-+-+--+--+\n" - "|3|4|55|67|\n" - "+-+-+--+--+\n" - "|3|4|55|67|\n" - "+-+-+--+--+\n"; + "+-+-+--+--+\n" + "|3|4|55|67|\n" + "+-+-+--+--+\n" + "|3|4|55|67|\n" + "+-+-+--+--+\n" + "|3|4|55|67|\n" + "+-+-+--+--+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -251,27 +251,27 @@ void test_table_cell_options(void) table = create_test_int_table(0); int n = ft_printf_ln(table, "|||"); - assert_true( n == 4 ); + assert_true(n == 4); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+---+----+----+\n" - "| | | | |\n" - "| | | | |\n" - "+---+---+----+----+\n"; + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+---+----+----+\n" + "| | | | |\n" + "| | | | |\n" + "+---+---+----+----+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -288,15 +288,15 @@ void test_table_cell_options(void) ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 0); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+-+-+--+--+\n" - "|3|4|55|67|\n" - "+-+-+--+--+\n" - "|3|4|55|67|\n" - "+-+-+--+--+\n" - "|3|4|55|67|\n" - "+-+-+--+--+\n"; + "+-+-+--+--+\n" + "|3|4|55|67|\n" + "+-+-+--+--+\n" + "|3|4|55|67|\n" + "+-+-+--+--+\n" + "|3|4|55|67|\n" + "+-+-+--+--+\n"; assert_str_equal(table_str, table_str_etalon); @@ -307,21 +307,21 @@ void test_table_cell_options(void) ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_EMPTY_STR_HEIGHT, 0); table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); table_str_etalon = - "+-+-+--+--+\n" - "| | | | |\n" - "|3|4|55|67|\n" - "| | | | |\n" - "+-+-+--+--+\n" - "| | | | |\n" - "|3|4|55|67|\n" - "| | | | |\n" - "+-+-+--+--+\n" - "| | | | |\n" - "|3|4|55|67|\n" - "| | | | |\n" - "+-+-+--+--+\n"; + "+-+-+--+--+\n" + "| | | | |\n" + "|3|4|55|67|\n" + "| | | | |\n" + "+-+-+--+--+\n" + "| | | | |\n" + "|3|4|55|67|\n" + "| | | | |\n" + "+-+-+--+--+\n" + "| | | | |\n" + "|3|4|55|67|\n" + "| | | | |\n" + "+-+-+--+--+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -342,25 +342,25 @@ void test_table_cell_options(void) status |= ft_set_cell_option(table, 2, 3, FT_COPT_MIN_WIDTH, 6); status |= ft_set_cell_option(table, 2, 3, FT_COPT_TEXT_ALIGN, LeftAligned); - assert_true( status == FT_SUCCESS); + assert_true(status == FT_SUCCESS); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+---+-------+--------+------+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+-------+--------+------+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+-------+--------+------+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+---+-------+--------+------+\n"; + "+---+-------+--------+------+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+-------+--------+------+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+-------+--------+------+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+---+-------+--------+------+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -372,26 +372,26 @@ void test_table_cell_options(void) int status = FT_SUCCESS; status |= ft_set_default_cell_option(FT_COPT_MIN_WIDTH, 5); status |= ft_set_default_cell_option(FT_COPT_TEXT_ALIGN, CenterAligned); - assert_true( status == FT_SUCCESS); + assert_true(status == FT_SUCCESS); table = create_test_int_table(0); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+-----+-----+-----+-----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+-----+-----+-----+-----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+-----+-----+-----+-----+\n" - "| | | | |\n" - "| 3 | 4 | 55 | 67 |\n" - "| | | | |\n" - "+-----+-----+-----+-----+\n"; + "+-----+-----+-----+-----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+-----+-----+-----+-----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+-----+-----+-----+-----+\n" + "| | | | |\n" + "| 3 | 4 | 55 | 67 |\n" + "| | | | |\n" + "+-----+-----+-----+-----+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } @@ -404,29 +404,29 @@ void test_table_cell_options(void) ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); int n = ft_printf_ln(table, "%d|%c|%s|%f", 4, 'c', "234", 3.14); - assert_true( n == 4 ); + assert_true(n == 4); n = FT_NWRITE_LN(table, "5", "c", "234\n12", "3.140000"); - assert_true( n == FT_SUCCESS ); + assert_true(n == FT_SUCCESS); n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14); - assert_true( n == 4 ); + assert_true(n == 4); const char *table_str = ft_to_string(table); - assert_true( table_str != NULL ); + assert_true(table_str != NULL); const char *table_str_etalon = - "+---+---+-----+----------+\n" - "| | | | |\n" - "| 4 | c | 234 | 3.140000 |\n" - "| | | | |\n" - "+---+---+-----+----------+\n" - "| | | | |\n" - "| 5 | c | 234 | 3.140000 |\n" - "| | | 12 | |\n" - "| | | | |\n" - "+---+---+-----+----------+\n" - "| | | | |\n" - "| 3 | c | 234 | 3.140000 |\n" - "| | | | |\n" - "+---+---+-----+----------+\n"; + "+---+---+-----+----------+\n" + "| | | | |\n" + "| 4 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+---+---+-----+----------+\n" + "| | | | |\n" + "| 5 | c | 234 | 3.140000 |\n" + "| | | 12 | |\n" + "| | | | |\n" + "+---+---+-----+----------+\n" + "| | | | |\n" + "| 3 | c | 234 | 3.140000 |\n" + "| | | | |\n" + "+---+---+-----+----------+\n"; assert_str_equal(table_str, table_str_etalon); ft_destroy_table(table); } diff --git a/tests/test_utility.c b/tests/test_utility.c index f2138fb..1edfb93 100644 --- a/tests/test_utility.c +++ b/tests/test_utility.c @@ -11,7 +11,7 @@ int set_test_options_for_table(FTABLE *table) status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 1); status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_EMPTY_STR_HEIGHT, 1); - assert_true( status == FT_SUCCESS ); + assert_true(status == FT_SUCCESS); struct ft_border_style brdr_style; @@ -46,7 +46,7 @@ int set_test_options_as_default() status |= ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1); status |= ft_set_default_cell_option(FT_COPT_EMPTY_STR_HEIGHT, 1); - assert_true( status == FT_SUCCESS ); + assert_true(status == FT_SUCCESS); struct ft_border_style brdr_style; @@ -76,12 +76,12 @@ FTABLE *create_test_int_table(int set_test_opts) FTABLE *table = NULL; table = ft_create_table(); - assert_true( table != NULL ); + assert_true(table != NULL); if (set_test_opts) { - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); } - assert_true (table != NULL); + assert_true(table != NULL); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); // int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67); @@ -106,12 +106,12 @@ FTABLE *create_test_int_wtable(int set_test_opts) FTABLE *table = NULL; table = ft_create_table(); - assert_true( table != NULL ); + assert_true(table != NULL); if (set_test_opts) { - assert_true( set_test_options_for_table(table) == FT_SUCCESS); + assert_true(set_test_options_for_table(table) == FT_SUCCESS); } - assert_true (table != NULL); + assert_true(table != NULL); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header); // int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67); diff --git a/tests/test_vector.c b/tests/test_vector.c index 86308ee..187ec85 100644 --- a/tests/test_vector.c +++ b/tests/test_vector.c @@ -12,9 +12,9 @@ void test_vector_basic(void) const size_t init_capacity = 10; vector_t *vector = create_vector(sizeof(item_t), init_capacity); - assert_true( vector != NULL ); - assert_true( vector_size(vector) == 0 ); - assert_true( vector_capacity(vector) == init_capacity ); + assert_true(vector != NULL); + assert_true(vector_size(vector) == 0); + assert_true(vector_capacity(vector) == init_capacity); WHEN("Pushing less items than initial capacity") { for (i = 0; i < init_capacity; ++i) { @@ -23,8 +23,8 @@ void test_vector_basic(void) } THEN("Then capacity is not changed") { - assert_true( vector_size(vector) == init_capacity ); - assert_true( vector_capacity(vector) == init_capacity ); + assert_true(vector_size(vector) == init_capacity); + assert_true(vector_capacity(vector) == init_capacity); } } @@ -32,7 +32,7 @@ void test_vector_basic(void) vector_clear(vector); THEN("Then size == 0") { - assert_true( vector_size(vector) == 0 ); + assert_true(vector_size(vector) == 0); } } @@ -43,37 +43,37 @@ void test_vector_basic(void) } THEN("Then capacity is increased") { - assert_true( vector_size(vector) == 2 * init_capacity ); - assert_true( vector_capacity(vector) > init_capacity ); + assert_true(vector_size(vector) == 2 * init_capacity); + assert_true(vector_capacity(vector) > init_capacity); } WHEN("Checking indexes of items") { item_t item = 6; - assert_true( vector_index_of(vector, &item) == 3 ); + assert_true(vector_index_of(vector, &item) == 3); item = 14; - assert_true( vector_index_of(vector, &item) == 7 ); + assert_true(vector_index_of(vector, &item) == 7); item = 25; - assert_true( vector_index_of(vector, &item) == INVALID_VEC_INDEX ); + assert_true(vector_index_of(vector, &item) == INVALID_VEC_INDEX); } WHEN("Checking access to items") { - assert_true( *(item_t *)vector_at(vector, 0) == 0 ); - assert_true( *(item_t *)vector_at(vector, 10) == 20 ); - assert_true( (item_t *)vector_at(vector, 20) == NULL ); + assert_true(*(item_t *)vector_at(vector, 0) == 0); + assert_true(*(item_t *)vector_at(vector, 10) == 20); + assert_true((item_t *)vector_at(vector, 20) == NULL); } WHEN("Erasing items") { - assert_true( vector_erase(vector, 20) != FT_SUCCESS ); + assert_true(vector_erase(vector, 20) != FT_SUCCESS); - assert_true( vector_erase(vector, 0) == FT_SUCCESS ); - assert_true( vector_erase(vector, 10) == FT_SUCCESS ); + assert_true(vector_erase(vector, 0) == FT_SUCCESS); + assert_true(vector_erase(vector, 10) == FT_SUCCESS); - item_t first_item = *(item_t*)vector_at(vector, 0); - assert_true( first_item == 2 ); + item_t first_item = *(item_t *)vector_at(vector, 0); + assert_true(first_item == 2); item_t item = 6; - assert_true( vector_index_of(vector, &item) == 2 ); + assert_true(vector_index_of(vector, &item) == 2); item = 26; - assert_true( vector_index_of(vector, &item) == 11 ); + assert_true(vector_index_of(vector, &item) == 11); } } @@ -81,9 +81,9 @@ void test_vector_basic(void) vector_clear(vector); THEN("Then size == 0") { - assert_true( vector_size(vector) == 0 ); + assert_true(vector_size(vector) == 0); } } - destroy_vector( vector ); + destroy_vector(vector); } diff --git a/tests/tests.h b/tests/tests.h index c62ef03..becf2fe 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -50,10 +50,11 @@ struct test_case #define assert_wcs_equal(str1, str2) \ if (wcscmp(str1, str2) != 0) \ { \ + fprintf(stderr, "%s:%d(%s):Abort! Not equals strings:\n",__FILE__,__LINE__, __FUNCTION__); \ setlocale(LC_CTYPE, ""); \ - fwprintf(stdout, L"%s:%d(%s):Abort! Not equals strings:\n",__FILE__,__LINE__, __FUNCTION__); \ fwprintf(stdout, L"Left string:\n%ls\n", str1); \ fwprintf(stdout, L"Right string:\n%ls\n", str2); \ + fflush(stdout); \ exit(EXIT_FAILURE); \ }