[A] Added astyle

This commit is contained in:
seleznevae 2018-03-31 13:33:37 +03:00
parent 7b16e1aec1
commit 23fb962f0a
24 changed files with 1069 additions and 961 deletions

View File

@ -14,6 +14,7 @@ matrix:
env: CC=clang env: CC=clang
# Linux / GCC # Linux / GCC
- os: linux - os: linux
sudo: false sudo: false
@ -87,8 +88,8 @@ script:
- ./libfort_test - ./libfort_test
# Test build without optimizations and with ubsan # Test build without optimizations and with ubsan
- if [ "${CC}" == 'gcc-7' ]; - |
then if [ "${CC}" = 'gcc-7' ]; then
cd .. ; cd .. ;
rm -r build/* ; rm -r build/* ;
cd build ; cd build ;
@ -100,8 +101,8 @@ script:
fi fi
# Build for coveralls # Build for coveralls
- if [ "${CC}" == 'gcc' ]; - |
then if [ "${CC}" = 'gcc' ]; then
cd .. ; cd .. ;
rm -r build/* ; rm -r build/* ;
cd build ; cd build ;
@ -110,7 +111,40 @@ script:
ls ; ls ;
./libfort_test ; ./libfort_test ;
fi 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

View File

@ -2,9 +2,11 @@ project(libfort)
# Required cmake version # Required cmake version
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
# Built options # Built options
option(FORT_CXX_BUILD "Compile with c++ compiler instead of c" OFF) 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)") 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) set(CMAKE_VERBOSE_MAKEFILE ON)
# ------------------------------------------------------------------------------
# Includes
# ------------------------------------------------------------------------------
include_directories(include) include_directories(include)
include_directories(src) include_directories(src)
# Turn on warnings
# ------------------------------------------------------------------------------
# Warnings
# ------------------------------------------------------------------------------
if(FORT_COMPILER STREQUAL "MSVC") if(FORT_COMPILER STREQUAL "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W4") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W4")
else(FORT_COMPILER STREQUAL "MSVC") 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") FILE(GLOB_RECURSE FortHeaders "include/*.h" "tests/*.h" "src/*.h")
add_custom_target(headers SOURCES ${FortHeaders}) 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") if(FORT_COMPILER STREQUAL "GNU" OR FORT_COMPILER STREQUAL "Clang")
# asan case # asan case
if(FORT_BUILD_TYPE STREQUAL "asan") if(FORT_BUILD_TYPE STREQUAL "asan")
@ -118,3 +135,62 @@ if(FORT_COMPILER STREQUAL "GNU")
endif(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()

View File

@ -25,6 +25,7 @@ int main(int argc, char *argv[])
{ {
(void)argc; (void)argc;
(void)argv; (void)argv;
int result = 0;
FTABLE *table = NULL; 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"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");*/ /* Бегущий по лезвию */ /*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); ft_destroy_table(table);
#endif #endif
return result;
table = NULL;
return 0;
} }

View File

@ -51,20 +51,21 @@ SOFTWARE.
/* /*
* Declare restrict * Declare restrict
*/ */
/*
#if defined(__cplusplus) #if defined(__cplusplus)
#if defined(FT_CLANG_COMPILER) #if defined(FT_CLANG_COMPILER)
#define FT_RESTRICT __restrict__ #define FT_RESTRICT __restrict__
#else #else
#define FT_RESTRICT __restrict #define FT_RESTRICT __restrict
#endif /* if defined(FT_CLANG_COMPILER) */ #endif // if defined(FT_CLANG_COMPILER)
#else #else
#if __STDC_VERSION__ < 199901L #if __STDC_VERSION__ < 199901L
#define FT_RESTRICT #define FT_RESTRICT
#else #else
#define FT_RESTRICT restrict #define FT_RESTRICT restrict
#endif /* __STDC_VERSION__ < 199901L */ #endif // __STDC_VERSION__ < 199901L
#endif /* if defined(__cplusplus) */ #endif // if defined(__cplusplus)
*/
/* /*
@ -209,20 +210,20 @@ struct fort_table;
typedef struct fort_table FTABLE; typedef struct fort_table FTABLE;
FT_EXTERN FTABLE *ft_create_table(void); FT_EXTERN FTABLE *ft_create_table(void);
FT_EXTERN void ft_destroy_table(FTABLE *FT_RESTRICT table); 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) #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(FTABLE *table, const char *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_ln(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
#else #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_impl(FTABLE *table, const char *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_ln_impl(FTABLE *table, const char *fmt, ...) FT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
#define ft_printf(table, ...) \ #define ft_printf(table, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf_impl(table, __VA_ARGS__)) (( 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(FTABLE *table, const char *cell_content);
FT_EXTERN int ft_write_ln(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT cell_content); FT_EXTERN int ft_write_ln(FTABLE *table, const char *cell_content);
#define FT_NWRITE(table, ...)\ #define FT_NWRITE(table, ...)\
(0 ? CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite(table, PP_NARG(__VA_ARGS__), __VA_ARGS__)) (0 ? CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite(table, PP_NARG(__VA_ARGS__), __VA_ARGS__))
#define FT_NWRITE_LN(table, ...)\ #define FT_NWRITE_LN(table, ...)\
(0 ? CHECK_IF_ARGS_ARE_STRINGS(__VA_ARGS__) : ft_nwrite_ln(table, PP_NARG(__VA_ARGS__), __VA_ARGS__)) (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(FTABLE *table, size_t n, const char *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_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(FTABLE *table, size_t cols, const char *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_ln(FTABLE *table, size_t cols, const char *row_cells[]);
#if !defined(__cplusplus) && !defined(FT_MICROSOFT_COMPILER) #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(FTABLE *table, size_t rows, size_t cols, const char *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_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(FTABLE *table, size_t rows, size_t cols, const char * * 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_ln(FTABLE *table, size_t rows, size_t cols, const char * * table_cells[rows]);
#endif #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_RIGHT_MARGIN ((uint32_t)(0x01U << (2)))
#define FT_TOPT_BOTTOM_MARGIN ((uint32_t)(0x01U << (3))) #define FT_TOPT_BOTTOM_MARGIN ((uint32_t)(0x01U << (3)))
enum TextAlignment enum TextAlignment {
{
LeftAligned, LeftAligned,
CenterAligned, CenterAligned,
RightAligned RightAligned
}; };
enum RowType enum RowType {
{
Common, Common,
Header Header
}; };
struct ft_border_chars struct ft_border_chars {
{
char top_border_ch; char top_border_ch;
char separator_ch; char separator_ch;
char bottom_border_ch; char bottom_border_ch;
@ -323,8 +321,7 @@ struct ft_border_chars
char in_intersect_ch; char in_intersect_ch;
}; };
struct ft_border_style struct ft_border_style {
{
struct ft_border_chars border_chs; struct ft_border_chars border_chs;
struct ft_border_chars header_border_chs; struct ft_border_chars header_border_chs;
char hor_separator_char; char hor_separator_char;
@ -339,13 +336,13 @@ 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_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_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_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 #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(FTABLE *table, const wchar_t *cell_content);
FT_EXTERN int ft_wwrite_ln(FTABLE *FT_RESTRICT table, const wchar_t* FT_RESTRICT cell_content); FT_EXTERN int ft_wwrite_ln(FTABLE *table, const wchar_t *cell_content);
#define FT_NWWRITE(table, ...)\ #define FT_NWWRITE(table, ...)\
(0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite(table, PP_NARG(__VA_ARGS__), __VA_ARGS__)) (0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite(table, PP_NARG(__VA_ARGS__), __VA_ARGS__))
#define FT_NWWRITE_LN(table, ...)\ #define FT_NWWRITE_LN(table, ...)\
(0 ? CHECK_IF_ARGS_ARE_WSTRINGS(__VA_ARGS__) : ft_nwwrite_ln(table, PP_NARG(__VA_ARGS__), __VA_ARGS__)) (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(FTABLE *table, size_t n, const wchar_t *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_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(FTABLE *table, size_t cols, const wchar_t *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_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 #endif

View File

@ -8,8 +8,7 @@
* ***************************************************************************/ * ***************************************************************************/
struct fort_cell struct fort_cell {
{
string_buffer_t *str_buffer; string_buffer_t *str_buffer;
fort_table_options_t *options; fort_table_options_t *options;
}; };

View File

@ -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; size_t i = 0;
@ -98,7 +98,7 @@ void ft_destroy_table(FTABLE *FT_RESTRICT table)
F_FREE(table); F_FREE(table);
} }
void ft_ln(FTABLE *FT_RESTRICT table) void ft_ln(FTABLE *table)
{ {
assert(table); assert(table);
table->cur_col = 0; 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 i = 0;
size_t new_cols = 0; size_t new_cols = 0;
@ -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); assert(table);
va_list va; va_list va;
@ -172,7 +172,7 @@ int FT_PRINTF(FTABLE *FT_RESTRICT table, const char* FT_RESTRICT fmt, ...)
return result; 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); assert(table);
va_list va; 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 #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); assert(table);
string_buffer_t *str_buffer = get_cur_str_buffer_and_create_if_not_exists(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; 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); assert(table);
int status = ft_write(table, cell_content); 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 #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); assert(table);
string_buffer_t *str_buffer = get_cur_str_buffer_and_create_if_not_exists(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; 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); assert(table);
int status = ft_wwrite(table, cell_content); 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 #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; size_t i = 0;
assert(table); assert(table);
@ -264,7 +264,7 @@ int ft_nwrite(FTABLE *FT_RESTRICT table, size_t n, const char* FT_RESTRICT cell_
return status; 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; size_t i = 0;
assert(table); assert(table);
@ -291,7 +291,7 @@ int ft_nwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const char* FT_RESTRICT ce
#ifdef FT_HAVE_WCHAR #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; size_t i = 0;
assert(table); assert(table);
@ -312,7 +312,7 @@ int ft_nwwrite(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRICT c
return status; 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; size_t i = 0;
assert(table); assert(table);
@ -339,7 +339,7 @@ int ft_nwwrite_ln(FTABLE *FT_RESTRICT table, size_t n, const wchar_t* FT_RESTRIC
#endif #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; size_t i = 0;
assert(table); assert(table);
@ -353,7 +353,7 @@ int ft_row_write(FTABLE *FT_RESTRICT table, size_t cols, const char* FT_RESTRICT
return FT_SUCCESS; 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); assert(table);
int status = ft_row_write(table, cols, cells); 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 #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; size_t i = 0;
assert(table); 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; 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); assert(table);
int status = ft_row_wwrite(table, cols, cells); 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) #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; size_t i = 0;
assert(table); 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; 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); assert(table);
int status = ft_s_table_write(table, rows, cols, table_cells); 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; size_t i = 0;
assert(table); 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; 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); assert(table);
int status = ft_table_write(table, rows, cols, table_cells); 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) \ #define CHECK_RESULT_AND_MOVE_DEV(statement) \
do { \ do { \
@ -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) \ #define CHECK_RESULT_AND_MOVE_DEV(statement) \
do { \ do { \
@ -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_SIMPLE_STYLE
|| (struct fort_border_style *)style == &FORT_DOT_STYLE || (struct fort_border_style *)style == &FORT_DOT_STYLE
|| (struct fort_border_style *)style == &FORT_PLAIN_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)); memcpy(&(options->border_style), (struct fort_border_style *)style, sizeof(struct fort_border_style));
return; 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); 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); assert(table);

View File

@ -7,8 +7,7 @@
* COLUMN OPTIONS * 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_ROW, /* cell_row */
FT_ANY_COLUMN, /* cell_col */ FT_ANY_COLUMN, /* cell_col */
@ -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*/ 0, /* col_min_width*/
RightAligned, /* align */ RightAligned, /* align */
}; };

View File

@ -5,8 +5,7 @@
#include "vector.h" #include "vector.h"
#include "ctype.h" #include "ctype.h"
struct fort_row struct fort_row {
{
vector_t *cells; vector_t *cells;
/*enum RowType type;*/ /*enum RowType type;*/
}; };
@ -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); string_buffer_t *buffer = create_string_buffer(DEFAULT_STR_BUF_SIZE, CharBuf);
if (buffer == NULL) if (buffer == NULL)

View File

@ -21,7 +21,7 @@ enum RowType
fort_row_t * create_row(void); fort_row_t * create_row(void);
void destroy_row(fort_row_t *row); void destroy_row(fort_row_t *row);
fort_row_t * create_row_from_string(const char *str); 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); int columns_in_row(const fort_row_t *row);

View File

@ -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); assert(table);

View File

@ -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); const fort_row_t *get_row_c(const fort_table_t *table, size_t row);
fort_row_t *get_row_and_create_if_not_exists(fort_table_t *table, size_t row); fort_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);

View File

@ -6,8 +6,7 @@
* VECTOR IMPLEMENTATIONS * VECTOR IMPLEMENTATIONS
* ***************************************************************************/ * ***************************************************************************/
struct vector struct vector {
{
size_t m_size; size_t m_size;
void *m_data; void *m_data;
size_t m_capacity; size_t m_capacity;

View File

@ -67,7 +67,8 @@ struct interval {
}; };
/* auxiliary function for binary search in interval table */ /* 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 min = 0;
int mid; int mid;

View File

@ -14,7 +14,8 @@ struct test_case test_suit [] = {
{"test_table_tbl_options", test_table_tbl_options}, {"test_table_tbl_options", test_table_tbl_options},
}; };
int main(void) { int main(void)
{
int n_tests = sizeof(test_suit) / sizeof(test_suit[0]); int n_tests = sizeof(test_suit) / sizeof(test_suit[0]);
fprintf(stderr, "[==========] Running %d test(s).\n", n_tests); fprintf(stderr, "[==========] Running %d test(s).\n", n_tests);
int i; int i;

View File

@ -50,10 +50,11 @@ struct test_case
#define assert_wcs_equal(str1, str2) \ #define assert_wcs_equal(str1, str2) \
if (wcscmp(str1, str2) != 0) \ if (wcscmp(str1, str2) != 0) \
{ \ { \
fprintf(stderr, "%s:%d(%s):Abort! Not equals strings:\n",__FILE__,__LINE__, __FUNCTION__); \
setlocale(LC_CTYPE, ""); \ 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"Left string:\n%ls\n", str1); \
fwprintf(stdout, L"Right string:\n%ls\n", str2); \ fwprintf(stdout, L"Right string:\n%ls\n", str2); \
fflush(stdout); \
exit(EXIT_FAILURE); \ exit(EXIT_FAILURE); \
} }