[A] Added astyle
This commit is contained in:
parent
7b16e1aec1
commit
23fb962f0a
44
.travis.yml
44
.travis.yml
@ -14,6 +14,7 @@ matrix:
|
||||
env: CC=clang
|
||||
|
||||
|
||||
|
||||
# Linux / GCC
|
||||
- os: linux
|
||||
sudo: false
|
||||
@ -87,8 +88,8 @@ script:
|
||||
- ./libfort_test
|
||||
|
||||
# Test build without optimizations and with ubsan
|
||||
- if [ "${CC}" == 'gcc-7' ];
|
||||
then
|
||||
- |
|
||||
if [ "${CC}" = 'gcc-7' ]; then
|
||||
cd .. ;
|
||||
rm -r build/* ;
|
||||
cd build ;
|
||||
@ -100,8 +101,8 @@ script:
|
||||
fi
|
||||
|
||||
# Build for coveralls
|
||||
- if [ "${CC}" == 'gcc' ];
|
||||
then
|
||||
- |
|
||||
if [ "${CC}" = 'gcc' ]; then
|
||||
cd .. ;
|
||||
rm -r build/* ;
|
||||
cd build ;
|
||||
@ -110,7 +111,40 @@ script:
|
||||
ls ;
|
||||
./libfort_test ;
|
||||
fi
|
||||
- cd ..
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
@ -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
|
||||
|
||||
|
||||
|
15
src/cell.c
15
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,8 +97,8 @@ 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
|
||||
@ -150,8 +149,8 @@ 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
|
||||
|
99
src/fort.c
99
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 ,
|
||||
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 *,
|
||||
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 (*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 ,
|
||||
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 *,
|
||||
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 (*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);
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
49
src/row.c
49
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;
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
@ -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));
|
||||
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
10
src/table.c
10
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;
|
||||
|
@ -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);
|
||||
|
||||
|
||||
|
||||
|
31
src/vector.c
31
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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,7 +67,8 @@ struct interval {
|
||||
};
|
||||
|
||||
/* auxiliary function for binary search in interval table */
|
||||
static int bisearch(wchar_t ucs, const struct interval *table, int max) {
|
||||
static int bisearch(wchar_t ucs, const struct interval *table, int max)
|
||||
{
|
||||
int min = 0;
|
||||
int mid;
|
||||
|
||||
@ -208,7 +209,7 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n)
|
||||
{
|
||||
int w, width = 0;
|
||||
|
||||
for (;*pwcs && n-- > 0; pwcs++)
|
||||
for (; *pwcs && n-- > 0; pwcs++)
|
||||
if ((w = mk_wcwidth(*pwcs)) < 0)
|
||||
return -1;
|
||||
else
|
||||
@ -299,7 +300,7 @@ int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n)
|
||||
{
|
||||
int w, width = 0;
|
||||
|
||||
for (;*pwcs && n-- > 0; pwcs++)
|
||||
for (; *pwcs && n-- > 0; pwcs++)
|
||||
if ((w = mk_wcwidth_cjk(*pwcs)) < 0)
|
||||
return -1;
|
||||
else
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
||||
|
@ -7,16 +7,16 @@ 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"
|
||||
@ -37,16 +37,16 @@ void test_table_basic(void)
|
||||
|
||||
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"
|
||||
@ -69,16 +69,16 @@ 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"
|
||||
@ -99,16 +99,16 @@ void test_table_basic(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"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"
|
||||
@ -129,16 +129,16 @@ void test_table_basic(void)
|
||||
|
||||
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"
|
||||
@ -159,16 +159,16 @@ void test_table_basic(void)
|
||||
|
||||
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"
|
||||
@ -189,16 +189,16 @@ void test_table_basic(void)
|
||||
|
||||
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"
|
||||
@ -219,16 +219,16 @@ void test_table_basic(void)
|
||||
|
||||
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"
|
||||
@ -257,16 +257,16 @@ 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"
|
||||
@ -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,7 +305,7 @@ 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"
|
||||
@ -320,14 +320,14 @@ void test_table_write(void)
|
||||
"| 234 | 3.140000 | 3 | c |\n"
|
||||
"| | | | |\n"
|
||||
"+-----+----------+----------+----------+\n";
|
||||
assert_str_equal( table_str, table_str_etalon );
|
||||
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,7 +338,7 @@ 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"
|
||||
@ -353,26 +353,26 @@ void test_table_write(void)
|
||||
L"| 234 | 3.140000 | 3 | c |\n"
|
||||
L"| | | | |\n"
|
||||
L"+-----+----------+----------+----------+\n";
|
||||
assert_wcs_equal( table_str, table_str_etalon );
|
||||
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"
|
||||
@ -387,7 +387,7 @@ void test_table_write(void)
|
||||
"| 234 | 3.140000 | 3 | c |\n"
|
||||
"| | | | |\n"
|
||||
"+-----+----------+----------+----------+\n";
|
||||
assert_str_equal( table_str, table_str_etalon );
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ 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"
|
||||
@ -79,7 +79,7 @@ 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"
|
||||
@ -99,10 +99,10 @@ 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"
|
||||
|
@ -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);
|
||||
|
@ -19,7 +19,7 @@ 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"
|
||||
@ -42,7 +42,7 @@ 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"
|
||||
@ -76,7 +76,7 @@ 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"
|
||||
@ -99,7 +99,7 @@ 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"
|
||||
@ -145,7 +145,7 @@ 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"
|
||||
@ -176,7 +176,7 @@ 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"
|
||||
@ -199,7 +199,7 @@ 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"
|
||||
@ -228,7 +228,7 @@ 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"
|
||||
@ -251,10 +251,10 @@ 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"
|
||||
@ -288,7 +288,7 @@ 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"
|
||||
@ -307,7 +307,7 @@ 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"
|
||||
@ -342,11 +342,11 @@ 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"
|
||||
@ -372,12 +372,12 @@ 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"
|
||||
@ -404,14 +404,14 @@ 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"
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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); \
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user