[F] Fixed c++ support

This commit is contained in:
seleznevae 2018-03-18 12:17:33 +03:00
parent 5ad1ede916
commit 757502a4b8
7 changed files with 101 additions and 68 deletions

View File

@ -41,28 +41,30 @@ set(FORT_SOURCES
src/table.c src/table.c
src/fort_impl.c) src/fort_impl.c)
if(FORT_CXX_BUILD)
SET_SOURCE_FILES_PROPERTIES( ${FORT_SOURCES} PROPERTIES LANGUAGE CXX)
endif(FORT_CXX_BUILD)
set(EXAMPLE_SOURCES
example/main.c)
add_executable(${PROJECT_NAME}_example add_executable(${PROJECT_NAME}_example
example/main.c ${EXAMPLE_SOURCES}
${FORT_SOURCES}) ${FORT_SOURCES})
set(TEST_SOURCES
add_executable(${PROJECT_NAME}_test
${FORT_SOURCES}
tests/test.c tests/test.c
tests/test_vector.c tests/test_vector.c
tests/test_table.c tests/test_table.c
tests/test_string_buffer.c) tests/test_string_buffer.c)
add_executable(${PROJECT_NAME}_test
${FORT_SOURCES}
${TEST_SOURCES})
if(FORT_CXX_BUILD)
SET_SOURCE_FILES_PROPERTIES( ${FORT_SOURCES} PROPERTIES LANGUAGE CXX)
SET_SOURCE_FILES_PROPERTIES( ${EXAMPLE_SOURCES} PROPERTIES LANGUAGE CXX)
SET_SOURCE_FILES_PROPERTIES( ${TEST_SOURCES} PROPERTIES LANGUAGE CXX)
endif(FORT_CXX_BUILD)
if(FORT_TEST_BUILD AND NOT FORT_MSVC_BUILD) if(FORT_TEST_BUILD AND NOT FORT_MSVC_BUILD)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")

View File

@ -29,10 +29,10 @@ SOFTWARE.
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include "options.h"
/* /*
* Determine compiler * Determine compiler
*/ */
@ -51,21 +51,20 @@ 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) */
#define FT_RESTRICT
/* /*
@ -269,10 +268,39 @@ FT_EXTERN int ft_add_separator(FTABLE *FT_RESTRICT table);
FT_EXTERN const char* ft_to_string(const FTABLE *FT_RESTRICT table); FT_EXTERN const char* ft_to_string(const FTABLE *FT_RESTRICT table);
/*
* Setting table appearance
*/
#define FT_ANY_COLUMN (UINT_MAX)
#define FT_ANY_ROW (UINT_MAX)
#define FT_ROW_UNSPEC (UINT_MAX-1)
#define FT_COLUMN_UNSPEC (UINT_MAX-1)
#define FT_OPT_MIN_WIDTH ((uint32_t)(0x01U << (0)))
#define FT_OPT_TEXT_ALIGN ((uint32_t)(0x01U << (1)))
#define FT_OPT_TOP_PADDING ((uint32_t)(0x01U << (2)))
#define FT_OPT_BOTTOM_PADDING ((uint32_t)(0x01U << (3)))
#define FT_OPT_LEFT_PADDING ((uint32_t)(0x01U << (4)))
#define FT_OPT_RIGHT_PADDING ((uint32_t)(0x01U << (5)))
#define FT_OPT_EMPTY_STR_HEIGHT ((uint32_t)(0x01U << (6)))
#define FT_OPT_ROW_TYPE ((uint32_t)(0x01U << (7)))
enum TextAlignment
{
LeftAligned,
CenterAligned,
RightAligned
};
enum RowType
{
Common,
Header
};
struct ft_border_chars struct ft_border_chars
{ {
@ -308,7 +336,9 @@ FT_EXTERN int ft_set_option(FTABLE * FT_RESTRICT table, unsigned row, unsigned c
/*
* WChar support
*/
#ifdef FT_HAVE_WCHAR #ifdef FT_HAVE_WCHAR

View File

@ -9,7 +9,6 @@
/***************************************************************************** /*****************************************************************************
* CELL * CELL
* ***************************************************************************/ * ***************************************************************************/
fort_cell_t * create_cell(); fort_cell_t * create_cell();

View File

@ -6,6 +6,7 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include "fort.h"
#define FORT_COL_SEPARATOR '|' #define FORT_COL_SEPARATOR '|'

View File

@ -5,18 +5,18 @@
#include <stdint.h> #include <stdint.h>
#include <limits.h> #include <limits.h>
enum TextAlignment //enum TextAlignment
{ //{
LeftAligned, // LeftAligned,
CenterAligned, // CenterAligned,
RightAligned // RightAligned
}; //};
enum RowType //enum RowType
{ //{
Common, // Common,
Header // Header
}; //};
struct fort_column_options struct fort_column_options

View File

@ -4,6 +4,7 @@
#include "fort_impl.h" #include "fort_impl.h"
#include "fort.h" #include "fort.h"
#include "stdarg.h" #include "stdarg.h"
#include "options.h"
struct fort_row; struct fort_row;
typedef struct fort_row fort_row_t; typedef struct fort_row fort_row_t;

View File

@ -5,10 +5,10 @@
#include "wchar.h" #include "wchar.h"
size_t strchr_count(const char* str, int ch); size_t strchr_count(const char* str, char ch);
size_t wstrchr_count(const wchar_t* str, wchar_t ch); size_t wstrchr_count(const wchar_t* str, wchar_t ch);
const char* str_n_substring_beg(const char* str, int ch, int 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); 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); fort_status_t str_n_substring(const char* str, char ch_separator, size_t n, const char **begin, const char **end);
@ -202,44 +202,44 @@ void test_buffer_text_width(void)
buffer->type = CharBuf; buffer->type = CharBuf;
char *old_value = buffer->str.cstr; char *old_value = buffer->str.cstr;
buffer->str.cstr = ""; buffer->str.cstr = (char*)"";
assert_true(buffer_text_width(buffer) == 0); assert_true(buffer_text_width(buffer) == 0);
buffer->str.cstr = "\n\n\n\n"; buffer->str.cstr = (char*)"\n\n\n\n";
assert_true(buffer_text_width(buffer) == 0); assert_true(buffer_text_width(buffer) == 0);
buffer->str.cstr = "12345"; buffer->str.cstr = (char*)"12345";
assert_true(buffer_text_width(buffer) == 5); assert_true(buffer_text_width(buffer) == 5);
buffer->str.cstr = "12345\n1234567"; buffer->str.cstr = (char*)"12345\n1234567";
assert_true(buffer_text_width(buffer) == 7); assert_true(buffer_text_width(buffer) == 7);
buffer->str.cstr = "12345\n1234567\n"; buffer->str.cstr = (char*)"12345\n1234567\n";
assert_true(buffer_text_width(buffer) == 7); assert_true(buffer_text_width(buffer) == 7);
buffer->str.cstr = "12345\n1234567\n123"; buffer->str.cstr = (char*)"12345\n1234567\n123";
assert_true(buffer_text_width(buffer) == 7); assert_true(buffer_text_width(buffer) == 7);
buffer->type = WCharBuf; buffer->type = WCharBuf;
buffer->str.wstr = L""; buffer->str.wstr = (wchar_t *)L"";
assert_true(buffer_text_width(buffer) == 0); assert_true(buffer_text_width(buffer) == 0);
buffer->str.wstr = L"\n\n\n\n"; buffer->str.wstr = (wchar_t *)L"\n\n\n\n";
assert_true(buffer_text_width(buffer) == 0); assert_true(buffer_text_width(buffer) == 0);
buffer->str.wstr = L"12345"; buffer->str.wstr = (wchar_t *)L"12345";
assert_true(buffer_text_width(buffer) == 5); assert_true(buffer_text_width(buffer) == 5);
buffer->str.wstr = L"12345\n1234567"; buffer->str.wstr = (wchar_t *)L"12345\n1234567";
assert_true(buffer_text_width(buffer) == 7); assert_true(buffer_text_width(buffer) == 7);
buffer->str.wstr = L"12345\n1234567\n"; buffer->str.wstr = (wchar_t *)L"12345\n1234567\n";
assert_true(buffer_text_width(buffer) == 7); assert_true(buffer_text_width(buffer) == 7);
buffer->str.wstr = L"12345\n1234567\n123"; buffer->str.wstr = (wchar_t *)L"12345\n1234567\n123";
assert_true(buffer_text_width(buffer) == 7); assert_true(buffer_text_width(buffer) == 7);
@ -255,48 +255,48 @@ void test_buffer_text_height(void)
buffer->type = CharBuf; buffer->type = CharBuf;
char *old_value = buffer->str.cstr; char *old_value = buffer->str.cstr;
buffer->str.cstr = ""; buffer->str.cstr = (char*)"";
assert_true(buffer_text_height(buffer) == 0); assert_true(buffer_text_height(buffer) == 0);
buffer->str.cstr = "\n"; buffer->str.cstr = (char*)"\n";
assert_true(buffer_text_height(buffer) == 2); assert_true(buffer_text_height(buffer) == 2);
buffer->str.cstr = "\n\n"; buffer->str.cstr = (char*)"\n\n";
assert_true(buffer_text_height(buffer) == 3); assert_true(buffer_text_height(buffer) == 3);
buffer->str.cstr = "\n\n\n\n"; buffer->str.cstr = (char*)"\n\n\n\n";
assert_true(buffer_text_height(buffer) == 5); assert_true(buffer_text_height(buffer) == 5);
buffer->str.cstr = "12345"; buffer->str.cstr = (char*)"12345";
assert_true(buffer_text_height(buffer) == 1); assert_true(buffer_text_height(buffer) == 1);
buffer->str.cstr = "\n12345"; buffer->str.cstr = (char*)"\n12345";
assert_true(buffer_text_height(buffer) == 2); assert_true(buffer_text_height(buffer) == 2);
buffer->str.cstr = "\n12345\n\n2"; buffer->str.cstr = (char*)"\n12345\n\n2";
assert_true(buffer_text_height(buffer) == 4); assert_true(buffer_text_height(buffer) == 4);
buffer->type = WCharBuf; buffer->type = WCharBuf;
buffer->str.wstr = L""; buffer->str.wstr = (wchar_t *)L"";
assert_true(buffer_text_height(buffer) == 0); assert_true(buffer_text_height(buffer) == 0);
buffer->str.wstr = L"\n"; buffer->str.wstr = (wchar_t *)L"\n";
assert_true(buffer_text_height(buffer) == 2); assert_true(buffer_text_height(buffer) == 2);
buffer->str.wstr = L"\n\n"; buffer->str.wstr = (wchar_t *)L"\n\n";
assert_true(buffer_text_height(buffer) == 3); assert_true(buffer_text_height(buffer) == 3);
buffer->str.wstr = L"\n\n\n\n"; buffer->str.wstr = (wchar_t *)L"\n\n\n\n";
assert_true(buffer_text_height(buffer) == 5); assert_true(buffer_text_height(buffer) == 5);
buffer->str.wstr = L"\xff0fy2345\xff0f"; buffer->str.wstr = (wchar_t *)L"\xff0fy2345\xff0f";
assert_true(buffer_text_height(buffer) == 1); assert_true(buffer_text_height(buffer) == 1);
buffer->str.wstr = L"\n12345"; buffer->str.wstr = (wchar_t *)L"\n12345";
assert_true(buffer_text_height(buffer) == 2); assert_true(buffer_text_height(buffer) == 2);
buffer->str.wstr = L"\n12345\n\n2"; buffer->str.wstr = (wchar_t *)L"\n12345\n\n2";
assert_true(buffer_text_height(buffer) == 4); assert_true(buffer_text_height(buffer) == 4);