[F] Fixed compilation errors

This commit is contained in:
seleznevae 2018-11-16 21:27:25 +03:00
parent 78f6173486
commit ae9103a714
6 changed files with 41 additions and 8 deletions

View File

@ -7,7 +7,7 @@ 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)
option(FORT_ENABLE_WCHAR "Enable wchar support" ON)
option(FORT_ENABLE_WCHAR "Enable wchar support" OFF)
set(FORT_BUILD_TYPE "common" CACHE STRING "Build types(common, asan, ubsan, coveralls)")

View File

@ -149,6 +149,8 @@ void custom_border_style_example(void)
void colorfull_table(void)
{
#if defined(FT_HAVE_WCHAR)
setlocale(LC_CTYPE, "");
ft_table_t *table = ft_create_table();
@ -205,6 +207,7 @@ void colorfull_table(void)
}
ft_destroy_table(table);
#endif
}
int main(void)

View File

@ -165,9 +165,11 @@ void set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *ptr))
char *fort_strdup(const char *str);
wchar_t *fort_wcsdup(const wchar_t *str);
size_t number_of_columns_in_format_string(const char *fmt);
#if defined(FT_HAVE_WCHAR)
wchar_t *fort_wcsdup(const wchar_t *str);
size_t number_of_columns_in_format_wstring(const wchar_t *fmt);
#endif
/*int snprint_n_chars(char *buf, size_t length, size_t n, char ch);*/
/*int wsnprint_n_chars(wchar_t *buf, size_t length, size_t n, wchar_t ch);*/
int snprint_n_strings(char *buf, size_t length, size_t n, const char *str);
@ -4059,6 +4061,7 @@ char *fort_strdup(const char *str)
return str_copy;
}
#if defined(FT_HAVE_WCHAR)
wchar_t *fort_wcsdup(const wchar_t *str)
{
if (str == NULL)
@ -4072,6 +4075,8 @@ wchar_t *fort_wcsdup(const wchar_t *str)
wcscpy(str_copy, str);
return str_copy;
}
#endif
size_t number_of_columns_in_format_string(const char *fmt)
{
@ -4088,6 +4093,7 @@ size_t number_of_columns_in_format_string(const char *fmt)
return separator_counter + 1;
}
#if defined(FT_HAVE_WCHAR)
size_t number_of_columns_in_format_wstring(const wchar_t *fmt)
{
int separator_counter = 0;
@ -4102,6 +4108,8 @@ size_t number_of_columns_in_format_wstring(const wchar_t *fmt)
}
return separator_counter + 1;
}
#endif
//int snprint_n_chars(char *buf, size_t length, size_t n, char ch)

View File

@ -113,6 +113,7 @@ char *fort_strdup(const char *str)
return str_copy;
}
#if defined(FT_HAVE_WCHAR)
wchar_t *fort_wcsdup(const wchar_t *str)
{
if (str == NULL)
@ -126,6 +127,8 @@ wchar_t *fort_wcsdup(const wchar_t *str)
wcscpy(str_copy, str);
return str_copy;
}
#endif
size_t number_of_columns_in_format_string(const char *fmt)
{
@ -142,6 +145,7 @@ size_t number_of_columns_in_format_string(const char *fmt)
return separator_counter + 1;
}
#if defined(FT_HAVE_WCHAR)
size_t number_of_columns_in_format_wstring(const wchar_t *fmt)
{
int separator_counter = 0;
@ -156,6 +160,8 @@ size_t number_of_columns_in_format_wstring(const wchar_t *fmt)
}
return separator_counter + 1;
}
#endif
//int snprint_n_chars(char *buf, size_t length, size_t n, char ch)

View File

@ -128,9 +128,11 @@ void set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *ptr))
char *fort_strdup(const char *str);
wchar_t *fort_wcsdup(const wchar_t *str);
size_t number_of_columns_in_format_string(const char *fmt);
#if defined(FT_HAVE_WCHAR)
wchar_t *fort_wcsdup(const wchar_t *str);
size_t number_of_columns_in_format_wstring(const wchar_t *fmt);
#endif
/*int snprint_n_chars(char *buf, size_t length, size_t n, char ch);*/
/*int wsnprint_n_chars(wchar_t *buf, size_t length, size_t n, wchar_t ch);*/
int snprint_n_strings(char *buf, size_t length, size_t n, const char *str);

View File

@ -73,10 +73,12 @@ void test_str_n_substring(void)
assert_true(str_n_substring_beg(empty_str, '\n', 1) == NULL);
assert_true(str_n_substring_beg(empty_str, '\n', 2) == NULL);
#if defined(FT_HAVE_WCHAR)
const wchar_t *empty_wstr = L"";
assert_true(wstr_n_substring_beg(empty_wstr, L'\n', 0) == empty_wstr);
assert_true(wstr_n_substring_beg(empty_wstr, L'\n', 1) == NULL);
assert_true(wstr_n_substring_beg(empty_wstr, L'\n', 2) == NULL);
#endif
const char *str = "123\n5678\n9";
assert_true(str_n_substring_beg(NULL, '\n', 0) == NULL);
@ -87,6 +89,7 @@ void test_str_n_substring(void)
assert_true(str_n_substring_beg(str, '\n', 2) == str + 9);
assert_true(str_n_substring_beg(str, '\n', 3) == NULL);
#if defined(FT_HAVE_WCHAR)
const wchar_t *wstr = L"123\n5678\n9";
assert_true(wstr_n_substring_beg(NULL, L'\n', 0) == NULL);
assert_true(wstr_n_substring_beg(wstr, L'\n', 0) == wstr);
@ -95,6 +98,7 @@ void test_str_n_substring(void)
assert_true(wstr_n_substring_beg(wstr, L'\n', 1) == wstr + 4);
assert_true(wstr_n_substring_beg(wstr, L'\n', 2) == wstr + 9);
assert_true(wstr_n_substring_beg(wstr, L'\n', 3) == NULL);
#endif
const char *str2 = "\n123\n56\n\n9\n";
assert_true(str_n_substring_beg(str2, '\n', 0) == str2);
@ -105,6 +109,7 @@ void test_str_n_substring(void)
assert_true(str_n_substring_beg(str2, '\n', 5) == str2 + 11);
assert_true(str_n_substring_beg(str2, '\n', 6) == NULL);
#if defined(FT_HAVE_WCHAR)
const wchar_t *wstr2 = L"\xff0fy23\xff0fy6\xff0f\xff0fy\xff0f";
assert_true(wstr_n_substring_beg(wstr2, L'\xff0f', 0) == wstr2);
assert_true(wstr_n_substring_beg(wstr2, L'\xff0f', 1) == wstr2 + 1);
@ -113,6 +118,7 @@ void test_str_n_substring(void)
assert_true(wstr_n_substring_beg(wstr2, L'\xff0f', 4) == wstr2 + 9);
assert_true(wstr_n_substring_beg(wstr2, L'\xff0f', 5) == wstr2 + 11);
assert_true(wstr_n_substring_beg(wstr2, L'\xff0f', 6) == NULL);
#endif
const char *beg = NULL;
const char *end = NULL;
@ -123,6 +129,7 @@ void test_str_n_substring(void)
str_n_substring(empty_str, '\n', 2, &beg, &end);
assert_true(beg == NULL && end == NULL);
#if defined(FT_HAVE_WCHAR)
const wchar_t *wbeg = NULL;
const wchar_t *wend = NULL;
wstr_n_substring(empty_wstr, L'\n', 0, &wbeg, &wend);
@ -131,6 +138,8 @@ void test_str_n_substring(void)
assert_true(wbeg == NULL && wend == NULL);
wstr_n_substring(empty_wstr, L'\n', 2, &wbeg, &wend);
assert_true(wbeg == NULL && wend == NULL);
#endif
str_n_substring(NULL, '\n', 0, &beg, &end);
assert_true(beg == NULL && end == NULL);
@ -139,12 +148,14 @@ void test_str_n_substring(void)
str_n_substring(str, '2', 0, &beg, &end);
assert_true(beg == str && end == str + 1);
#if defined(FT_HAVE_WCHAR)
wstr_n_substring(NULL, L'\n', 0, &wbeg, &wend);
assert_true(wbeg == NULL && wend == NULL);
wstr_n_substring(wstr, L'\n', 0, &wbeg, &wend);
assert_true(wbeg == wstr && wend == wstr + 3);
wstr_n_substring(wstr, L'2', 0, &wbeg, &wend);
assert_true(wbeg == wstr && wend == wstr + 1);
#endif
str_n_substring(str, '\n', 1, &beg, &end);
assert_true(beg == str + 4 && end == str + 8);
@ -153,12 +164,14 @@ void test_str_n_substring(void)
str_n_substring(str, '\n', 3, &beg, &end);
assert_true(beg == NULL && end == NULL);
#if defined(FT_HAVE_WCHAR)
wstr_n_substring(wstr, L'\n', 1, &wbeg, &wend);
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);
assert_true(wbeg == NULL && wend == NULL);
#endif
str_n_substring(str2, '\n', 0, &beg, &end);
assert_true(beg == str2 && end == str2);
@ -175,7 +188,7 @@ void test_str_n_substring(void)
str_n_substring(str2, '\n', 6, &beg, &end);
assert_true(beg == NULL && end == NULL);
#if defined(FT_HAVE_WCHAR)
wstr_n_substring(wstr2, L'\xff0f', 0, &wbeg, &wend);
assert_true(wbeg == wstr2 && wend == wstr2);
wstr_n_substring(wstr2, L'\xff0f', 1, &wbeg, &wend);
@ -190,6 +203,7 @@ void test_str_n_substring(void)
assert_true(wbeg == wstr2 + 11 && wend == wstr2 + 11);
wstr_n_substring(wstr2, L'\xff0f', 6, &wbeg, &wend);
assert_true(wbeg == NULL && wend == NULL);
#endif
}
void test_buffer_text_width(void)
@ -216,8 +230,7 @@ void test_buffer_text_width(void)
buffer->str.cstr = (char *)"12345\n1234567\n123";
assert_true(buffer_text_width(buffer) == 7);
#if defined(FT_HAVE_WCHAR)
buffer->type = WCharBuf;
buffer->str.wstr = (wchar_t *)L"";
@ -237,7 +250,7 @@ void test_buffer_text_width(void)
buffer->str.wstr = (wchar_t *)L"12345\n1234567\n123";
assert_true(buffer_text_width(buffer) == 7);
#endif
buffer->type = CharBuf;
buffer->str.cstr = old_value;
@ -272,7 +285,7 @@ void test_buffer_text_height(void)
buffer->str.cstr = (char *)"\n12345\n\n2";
assert_true(buffer_text_height(buffer) == 4);
#if defined(FT_HAVE_WCHAR)
buffer->type = WCharBuf;
buffer->str.wstr = (wchar_t *)L"";
assert_true(buffer_text_height(buffer) == 0);
@ -294,6 +307,7 @@ void test_buffer_text_height(void)
buffer->str.wstr = (wchar_t *)L"\n12345\n\n2";
assert_true(buffer_text_height(buffer) == 4);
#endif
buffer->type = CharBuf;