1
0
Fork 0

[F] Fixed building

This commit is contained in:
seleznevae 2018-03-09 12:44:16 +03:00
parent 1d8e03612b
commit d0df283850
17 changed files with 167 additions and 170 deletions

View File

@ -10,7 +10,7 @@ set(CMAKE_VERBOSE_MAKEFILE ON)
include_directories(include)
include_directories(src)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g ")

View File

@ -42,7 +42,6 @@ int main()
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
// ft_hdr_printf_ln(table, "#|Planet|Avg. speed");
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
ft_printf_ln(table, "%d|%s|%5.2f km/s", 1, "Mercury", 47.362);
@ -60,7 +59,6 @@ int main()
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
// ft_hdr_printf_ln(table, "Rank|Title|Year|Rating");
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
ft_printf_ln(table, "Rank|Title|Year|Rating");
@ -80,7 +78,6 @@ int main()
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, LeftAligned);
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, CenterAligned);
// ft_hdr_printf_ln(table, "Commodity|Farm price|Avg. spread");
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
ft_printf_ln(table, "Commodity|Farm price|Avg. spread");
@ -99,7 +96,6 @@ int main()
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, LeftAligned);
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, CenterAligned);
// ft_hdr_printf_ln(table, "No.|Name|Avg. Mark");
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
ft_printf_ln(table, "No.|Name|Avg. Mark");
const char *ctab[2][3] = {
@ -118,7 +114,6 @@ int main()
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
// ft_hdr_printf_ln(table, "No.|Name|Avg. Mark");
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
ft_printf_ln(table, "No.|Name|Avg. Mark");
const char **tab[2] = {
@ -133,8 +128,7 @@ int main()
/*-------------------------------------------------------------*/
table = NULL;
table = NULL;
return 0;
}

View File

@ -46,24 +46,38 @@ SOFTWARE.
#define FORT_UNDEFINED_COMPILER
#endif
/*
* Declare restrict
*/
//#if defined(__cplusplus)
//#if defined(FORT_CLANG_COMPILER)
//#define FORT_RESTRICT __restrict__
//#else
//#define FORT_RESTRICT __restrict
//#endif /* if defined(FORT_CLANG_COMPILER) */
//#else
//#if __STDC_VERSION__ < 199901L
//#define FORT_RESTRICT restrict
//#else
//#define FORT_RESTRICT
//#endif /* __STDC_VERSION__ < 199901L */
//#endif /* if defined(__cplusplus) */
#if defined(__cplusplus)
#if defined(FORT_CLANG_COMPILER)
#define FORT_RESTRICT __restrict__
#else
#define FORT_RESTRICT __restrict
#endif /* if defined(FORT_CLANG_COMPILER) */
#else
#if __STDC_VERSION__ < 199901L
#define FORT_RESTRICT
#else
#define FORT_RESTRICT restrict
#endif /* __STDC_VERSION__ < 199901L */
#endif /* if defined(__cplusplus) */
/* #define FORT_RESTRICT*/
/*
* Declare restrict
*/
#if defined(__cplusplus)
#define FORT_INLINE inline
#else
#define FORT_INLINE __inline
#endif /* if defined(__cplusplus) */
/* #define FORT_RESTRICT*/
/*
@ -97,7 +111,6 @@ SOFTWARE.
#define STRING2(x) #x
#define STRING(x) STRING2(x)
#pragma message(STRING(FORT_RESTRICT))
/*
* Wchar support
@ -114,13 +127,13 @@ SOFTWARE.
STR_2_CAT_(arg1, arg2)
static inline int fort_check_if_string_helper(const char*str)
static FORT_INLINE int fort_check_if_string_helper(const char*str)
{
(void)str;
return 0;
}
static inline int fort_check_if_wstring_helper(const wchar_t*str)
static FORT_INLINE int fort_check_if_wstring_helper(const wchar_t*str)
{
(void)str;
return 0;
@ -264,7 +277,7 @@ FORT_EXTERN int ft_add_separator(FTABLE *FORT_RESTRICT table);
FORT_EXTERN const char* ft_to_string(const FTABLE *FORT_RESTRICT table);
FORT_EXTERN const wchar_t* ft_to_wstring(const FTABLE *FORT_RESTRICT table);
//FORT_EXTERN ssize_t ft_n_to_string(const FTABLE *FORT_RESTRICT table, char *FORT_RESTRICT dst, size_t dst_len);
/*FORT_EXTERN ssize_t ft_n_to_string(const FTABLE *FORT_RESTRICT table, char *FORT_RESTRICT dst, size_t dst_len);*/
@ -293,4 +306,4 @@ FORT_EXTERN int ft_set_cell_option(FTABLE * FORT_RESTRICT table, unsigned row, u
FORT_END_DECLS
#endif // LIBFORT_H
#endif /* LIBFORT_H */

View File

@ -24,7 +24,7 @@ fort_cell_t * create_cell()
return NULL;
}
cell->options = NULL;
// init_cell_options(&(cell->options));
/* init_cell_options(&(cell->options)); */
return cell;
}
@ -76,21 +76,23 @@ int hint_height_cell(const fort_cell_t *cell, const context_t *context)
* Returns number of lines in cell. If cell is empty or
* contains empty string, then 0 is returned.
*/
//static int lines_number_cell(fort_cell_t *cell)
//{
// assert(cell);
// if (cell->str_buffer == NULL || cell->str_buffer->str == NULL || cell->str_buffer->str[0] == '\0') {
// return 0;
// }
/*
static int lines_number_cell(fort_cell_t *cell)
{
assert(cell);
if (cell->str_buffer == NULL || cell->str_buffer->str == NULL || cell->str_buffer->str[0] == '\0') {
return 0;
}
// int result = 0;
// char *pos = cell->str_buffer->str;
// while ((pos = strchr(pos, '\n')) != NULL) {
// result++;
// pos++;
// }
// return result + 1;
//}
int result = 0;
char *pos = cell->str_buffer->str;
while ((pos = strchr(pos, '\n')) != NULL) {
result++;
pos++;
}
return result + 1;
}
*/
int cell_printf(fort_cell_t *cell, size_t row, size_t column, char *buf, size_t buf_len, const context_t *context)
{

View File

@ -22,7 +22,7 @@ int hint_height_cell(const fort_cell_t *cell, const context_t *context);
* Returns number of lines in cell. If cell is empty or
* contains empty string, then 0 is returned.
*/
//static int lines_number_cell(fort_cell_t *cell);
/* static int lines_number_cell(fort_cell_t *cell); */
int cell_printf(fort_cell_t *cell, size_t row, size_t column, char *buf, size_t buf_len, const context_t *context);
int cell_wprintf(fort_cell_t *cell, size_t row, size_t column, wchar_t *buf, size_t buf_len, const context_t *context);
@ -32,4 +32,4 @@ fort_status_t fill_cell_from_string(fort_cell_t *cell, const char *str);
string_buffer_t* cell_get_string_buffer(fort_cell_t *cell);
#endif // CELL_H
#endif /* CELL_H */

View File

@ -74,19 +74,21 @@ FTABLE * ft_create_table(void)
void ft_destroy_table(FTABLE *FORT_RESTRICT table)
{
size_t i = 0;
if (table == NULL)
return;
if (table->rows) {
size_t row_n = vector_size(table->rows);
for (size_t i = 0; i < row_n; ++i) {
for (i = 0; i < row_n; ++i) {
destroy_row(*(fort_row_t **)vector_at(table->rows, i));
}
destroy_vector(table->rows);
}
if (table->separators) {
size_t row_n = vector_size(table->separators);
for (size_t i = 0; i < row_n; ++i) {
for (i = 0; i < row_n; ++i) {
destroy_separator(*(separator_t **)vector_at(table->separators, i));
}
destroy_vector(table->separators);
@ -106,6 +108,8 @@ void ft_ln(FTABLE *FORT_RESTRICT table)
static int ft_row_printf_impl(FTABLE *FORT_RESTRICT table, size_t row, const char* FORT_RESTRICT fmt, va_list *va)
{
size_t i = 0;
if (table == NULL)
return -1;
@ -119,7 +123,7 @@ static int ft_row_printf_impl(FTABLE *FORT_RESTRICT table, size_t row, const cha
size_t sz = vector_size(table->rows);
if (row >= sz) {
size_t push_n = row - sz + 1;
for (size_t i = 0; i < push_n; ++i) {
for (i = 0; i < push_n; ++i) {
fort_row_t *new_row = create_row();
if (new_row == NULL)
goto clear;
@ -237,6 +241,7 @@ int ft_wwrite_ln(FTABLE *FORT_RESTRICT table, const wchar_t* FORT_RESTRICT cell_
int ft_nwrite(FTABLE *FORT_RESTRICT table, size_t n, const char* FORT_RESTRICT cell_content, ...)
{
size_t i = 0;
assert(table);
int status = ft_write(table, cell_content);
if (IS_ERROR(status))
@ -245,7 +250,7 @@ int ft_nwrite(FTABLE *FORT_RESTRICT table, size_t n, const char* FORT_RESTRICT c
va_list va;
va_start(va, cell_content);
--n;
for (size_t i = 0; i < n; ++i) {
for (i = 0; i < n; ++i) {
const char *cell = va_arg(va, const char*);
status = ft_write(table, cell);
if (IS_ERROR(status))
@ -257,6 +262,7 @@ int ft_nwrite(FTABLE *FORT_RESTRICT table, size_t n, const char* FORT_RESTRICT c
int ft_nwrite_ln(FTABLE *FORT_RESTRICT table, size_t n, const char* FORT_RESTRICT cell_content, ...)
{
size_t i = 0;
assert(table);
int status = ft_write(table, cell_content);
if (IS_ERROR(status))
@ -265,7 +271,7 @@ int ft_nwrite_ln(FTABLE *FORT_RESTRICT table, size_t n, const char* FORT_RESTRIC
va_list va;
va_start(va, cell_content);
--n;
for (size_t i = 0; i < n; ++i) {
for (i = 0; i < n; ++i) {
const char *cell = va_arg(va, const char*);
status = ft_write(table, cell);
if (IS_ERROR(status)) {
@ -282,6 +288,7 @@ int ft_nwrite_ln(FTABLE *FORT_RESTRICT table, size_t n, const char* FORT_RESTRIC
int ft_nwwrite(FTABLE *FORT_RESTRICT table, size_t n, const wchar_t* FORT_RESTRICT cell_content, ...)
{
size_t i = 0;
assert(table);
int status = ft_wwrite(table, cell_content);
if (IS_ERROR(status))
@ -290,7 +297,7 @@ int ft_nwwrite(FTABLE *FORT_RESTRICT table, size_t n, const wchar_t* FORT_RESTRI
va_list va;
va_start(va, cell_content);
--n;
for (size_t i = 0; i < n; ++i) {
for (i = 0; i < n; ++i) {
const wchar_t *cell = va_arg(va, const wchar_t*);
status = ft_wwrite(table, cell);
if (IS_ERROR(status))
@ -302,6 +309,7 @@ int ft_nwwrite(FTABLE *FORT_RESTRICT table, size_t n, const wchar_t* FORT_RESTRI
int ft_nwwrite_ln(FTABLE *FORT_RESTRICT table, size_t n, const wchar_t* FORT_RESTRICT cell_content, ...)
{
size_t i = 0;
assert(table);
int status = ft_wwrite(table, cell_content);
if (IS_ERROR(status))
@ -310,7 +318,7 @@ int ft_nwwrite_ln(FTABLE *FORT_RESTRICT table, size_t n, const wchar_t* FORT_RES
va_list va;
va_start(va, cell_content);
--n;
for (size_t i = 0; i < n; ++i) {
for (i = 0; i < n; ++i) {
const wchar_t *cell = va_arg(va, const wchar_t*);
status = ft_wwrite(table, cell);
if (IS_ERROR(status)) {
@ -327,11 +335,12 @@ int ft_nwwrite_ln(FTABLE *FORT_RESTRICT table, size_t n, const wchar_t* FORT_RES
FORT_EXTERN int ft_row_write(FTABLE *FORT_RESTRICT table, size_t cols, const char* FORT_RESTRICT cells[])
{
size_t i = 0;
assert(table);
for (size_t i = 0; i < cols; ++i) {
for (i = 0; i < cols; ++i) {
int status = ft_write(table, cells[i]);
if (IS_ERROR(status)) {
//todo: maybe current pos in case of error should be equal to the one before function call?
/* todo: maybe current pos in case of error should be equal to the one before function call? */
return status;
}
}
@ -353,11 +362,12 @@ FORT_EXTERN int ft_row_write_ln(FTABLE *FORT_RESTRICT table, size_t cols, const
int ft_s_table_write(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char* FORT_RESTRICT table_cells[rows][cols])
{
size_t i = 0;
assert(table);
for (size_t i = 0; i < rows; ++i) {
for (i = 0; i < rows; ++i) {
int status = ft_row_write(table, cols, table_cells[i]);
if (IS_ERROR(status)) {
//todo: maybe current pos in case of error should be equal to the one before function call?
/* todo: maybe current pos in case of error should be equal to the one before function call? */
return status;
}
if (i != rows - 1)
@ -379,11 +389,12 @@ int ft_s_table_write_ln(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, c
int ft_table_write(FTABLE *FORT_RESTRICT table, size_t rows, size_t cols, const char* * FORT_RESTRICT table_cells[rows])
{
size_t i = 0;
assert(table);
for (size_t i = 0; i < rows; ++i) {
for (i = 0; i < rows; ++i) {
int status = ft_row_write(table, cols, table_cells[i]);
if (IS_ERROR(status)) {
//todo: maybe current pos in case of error should be equal to the one before function call?
/* todo: maybe current pos in case of error should be equal to the one before function call? */
return status;
}
if (i != rows - 1)
@ -452,7 +463,7 @@ const char* ft_to_string(const FTABLE *FORT_RESTRICT table)
if (table->conv_buffer == NULL)
return NULL;
}
while (string_buffer_capacity(table->conv_buffer) < sz) {// table->conv_buffer->str_sz < sz) {
while (string_buffer_capacity(table->conv_buffer) < sz) {
if (IS_ERROR(realloc_string_buffer_without_copy(table->conv_buffer))) {
return NULL;
}
@ -546,7 +557,7 @@ const wchar_t* ft_to_wstring(const FTABLE *FORT_RESTRICT table)
if (table->conv_buffer == NULL)
return NULL;
}
while (string_buffer_capacity(table->conv_buffer) < sz) {// table->conv_buffer->str_sz < sz) {
while (string_buffer_capacity(table->conv_buffer) < sz) {
if (IS_ERROR(realloc_string_buffer_without_copy(table->conv_buffer))) {
return NULL;
}
@ -656,15 +667,17 @@ static void set_border_options_for_options(fort_table_options_t *options, struct
#define BOR_CHARS options->border_chars
#define H_BOR_CHARS options->header_border_chars
// BOR_CHARS[TL_bip] = BOR_CHARS[TT_bip] = BOR_CHARS[TV_bip] = BOR_CHARS[TR_bip] = border_chs->top_border_ch;
// BOR_CHARS[LH_bip] = BOR_CHARS[IH_bip] = BOR_CHARS[II_bip] = BOR_CHARS[RH_bip] = border_chs->separator_ch;
// BOR_CHARS[BL_bip] = BOR_CHARS[BB_bip] = BOR_CHARS[BV_bip] = BOR_CHARS[BR_bip] = border_chs->bottom_border_ch;
// BOR_CHARS[LL_bip] = BOR_CHARS[IV_bip] = BOR_CHARS[RR_bip] = border_chs->side_border_ch;
/*
BOR_CHARS[TL_bip] = BOR_CHARS[TT_bip] = BOR_CHARS[TV_bip] = BOR_CHARS[TR_bip] = border_chs->top_border_ch;
BOR_CHARS[LH_bip] = BOR_CHARS[IH_bip] = BOR_CHARS[II_bip] = BOR_CHARS[RH_bip] = border_chs->separator_ch;
BOR_CHARS[BL_bip] = BOR_CHARS[BB_bip] = BOR_CHARS[BV_bip] = BOR_CHARS[BR_bip] = border_chs->bottom_border_ch;
BOR_CHARS[LL_bip] = BOR_CHARS[IV_bip] = BOR_CHARS[RR_bip] = border_chs->side_border_ch;
// H_BOR_CHARS[TL_bip] = H_BOR_CHARS[TT_bip] = H_BOR_CHARS[TV_bip] = H_BOR_CHARS[TR_bip] = header_border_chs->top_border_ch;
// H_BOR_CHARS[LH_bip] = H_BOR_CHARS[IH_bip] = H_BOR_CHARS[II_bip] = H_BOR_CHARS[RH_bip] = header_border_chs->separator_ch;
// H_BOR_CHARS[BL_bip] = H_BOR_CHARS[BB_bip] = H_BOR_CHARS[BV_bip] = H_BOR_CHARS[BR_bip] = header_border_chs->bottom_border_ch;
// H_BOR_CHARS[LL_bip] = H_BOR_CHARS[IV_bip] = H_BOR_CHARS[RR_bip] = header_border_chs->side_border_ch;
H_BOR_CHARS[TL_bip] = H_BOR_CHARS[TT_bip] = H_BOR_CHARS[TV_bip] = H_BOR_CHARS[TR_bip] = header_border_chs->top_border_ch;
H_BOR_CHARS[LH_bip] = H_BOR_CHARS[IH_bip] = H_BOR_CHARS[II_bip] = H_BOR_CHARS[RH_bip] = header_border_chs->separator_ch;
H_BOR_CHARS[BL_bip] = H_BOR_CHARS[BB_bip] = H_BOR_CHARS[BV_bip] = H_BOR_CHARS[BR_bip] = header_border_chs->bottom_border_ch;
H_BOR_CHARS[LL_bip] = H_BOR_CHARS[IV_bip] = H_BOR_CHARS[RR_bip] = header_border_chs->side_border_ch;
*/
BOR_CHARS[TT_bip] = border_chs->top_border_ch;
BOR_CHARS[IH_bip] = border_chs->separator_ch;

View File

@ -61,7 +61,8 @@ int snprint_n_chars(char *buf, size_t length, size_t n, char ch)
if (status < 0)
return status;
for (size_t i = 0; i < n; ++i) {
size_t i = 0;
for (i = 0; i < n; ++i) {
*buf = ch;
buf++;
}
@ -81,7 +82,8 @@ int wsnprint_n_chars(wchar_t *buf, size_t length, size_t n, wchar_t ch)
if (status < 0)
return status;
for (size_t i = 0; i < n; ++i) {
size_t i = 0;
for (i = 0; i < n; ++i) {
*buf = ch;
buf++;
}

View File

@ -114,4 +114,4 @@ 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);
#endif // FORT_IMPL_H
#endif /* FORT_IMPL_H */

View File

@ -51,7 +51,7 @@ static int get_option_value_if_exists_otherwise_default(const struct fort_cell_o
case FT_OPT_ROW_TYPE:
return cell_opts->row_type;
default:
// todo: implement later
/* todo: implement later */
exit(333);
}
}
@ -91,7 +91,8 @@ const fort_cell_options_t* cget_cell_opt(const fort_cell_opt_container_t *cont,
{
assert(cont);
size_t sz = vector_size(cont);
for (size_t i = 0; i < sz; ++i) {
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);
if (opt->cell_row == row && opt->cell_col == col)
return opt;
@ -103,7 +104,8 @@ fort_cell_options_t* get_cell_opt_and_create_if_not_exists(fort_cell_opt_contain
{
assert(cont);
size_t sz = vector_size(cont);
for (size_t i = 0; i < sz; ++i) {
size_t i = 0;
for (i = 0; i < sz; ++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;
@ -183,14 +185,16 @@ fort_status_t set_cell_option(fort_cell_opt_container_t *cont, unsigned row, uns
return F_ERROR;
return set_cell_option_impl(opt, option, value);
// OPTION_SET(opt->options, option);
// if (OPTION_IS_SET(option, FT_OPT_MIN_WIDTH)) {
// opt->col_min_width = value;
// } else if (OPTION_IS_SET(option, FT_OPT_TEXT_ALIGN)) {
// opt->align = value;
// }
/*
OPTION_SET(opt->options, option);
if (OPTION_IS_SET(option, FT_OPT_MIN_WIDTH)) {
opt->col_min_width = value;
} else if (OPTION_IS_SET(option, FT_OPT_TEXT_ALIGN)) {
opt->align = value;
}
// return F_SUCCESS;
return F_SUCCESS;
*/
}
fort_status_t set_default_cell_option(uint32_t option, int value)
@ -204,40 +208,9 @@ fort_status_t set_default_cell_option(uint32_t option, int value)
//fort_table_options_t g_table_options = {
// 1, /* cell_padding_top */
// 1, /* cell_padding_bottom */
// 1, /* cell_padding_left */
// 1, /* cell_padding_right */
// 1, /* cell_empty_string_height */
// /* border_chars */
// {
// '+', '-', '+', '+',
// '|', '|', '|',
// '+', '-', '+', '+',
// '+', '-', '+', '+'
// },
// /* header_border_chars */
// {
// '+', '-', '+', '+',
// '|', '|', '|',
// '+', '-', '+', '+',
// '+', '-', '+', '+'
// },
// NULL, /* col_options */
//};
fort_table_options_t g_table_options = {
// 0, /* cell_padding_top */
// 0, /* cell_padding_bottom */
// 1, /* cell_padding_left */
// 1, /* cell_padding_right */
// 1, /* cell_empty_string_height */
/* border_chars */
{
'+', '-', '+', '+',
@ -259,7 +232,6 @@ fort_table_options_t g_table_options = {
'+', '=', '+', '+',
},
// NULL, /* col_options */
NULL, /* cell_options */
};
@ -307,9 +279,6 @@ void destroy_table_options(fort_table_options_t* options)
if (options == NULL)
return;
// if (options->col_options != NULL) {
// destroy_vector(options->col_options);
// }
if (options->cell_options != NULL) {
destroy_cell_opt_container(options->cell_options);
}

View File

@ -141,21 +141,14 @@ enum SeparatorItemPos
struct fort_table_options
{
// int cell_padding_top;
// int cell_padding_bottom;
// int cell_padding_left;
// int cell_padding_right;
// int cell_empty_string_height;
char border_chars[BorderItemPosSize];
char header_border_chars[BorderItemPosSize];
char separator_chars[SepratorItemPosSize];
// vector_t *col_options;
fort_cell_opt_container_t * cell_options;
};
typedef struct fort_table_options fort_table_options_t;
//typedef fort_table_options_t context_t;
/*typedef fort_table_options_t context_t;*/
extern fort_table_options_t g_table_options;
@ -166,4 +159,4 @@ void destroy_table_options(fort_table_options_t* options);
#endif // OPTIONS_H
#endif /* OPTIONS_H */

View File

@ -8,7 +8,7 @@
struct fort_row
{
vector_t *cells;
enum RowType type;
/*enum RowType type;*/
};
@ -23,19 +23,23 @@ fort_row_t * create_row()
F_FREE(row);
return NULL;
}
// row->is_header = F_FALSE;
// row->type = Common;
/*
row->is_header = F_FALSE;
row->type = Common;
*/
return row;
}
void destroy_row(fort_row_t *row)
{
size_t i = 0;
if (row == NULL)
return;
if (row->cells) {
size_t cells_n = vector_size(row->cells);
for (size_t i = 0; i < cells_n; ++i) {
for (i = 0; i < cells_n; ++i) {
fort_cell_t *cell = *(fort_cell_t **)vector_at(row->cells, i);
destroy_cell(cell);
}
@ -190,7 +194,8 @@ int print_row_separator(char *buffer, size_t buffer_sz,
if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R))
return 0;
for (size_t i = 0; i < cols; ++i) {
size_t i = 0;
for (i = 0; i < cols; ++i) {
if (i == 0) {
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, 1, (char_type)*L));
} else {
@ -295,7 +300,8 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz,
if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R))
return 0;
for (size_t i = 0; i < cols; ++i) {
size_t i = 0;
for (i = 0; i < cols; ++i) {
if (i == 0) {
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, 1, (char_type)*L));
} else {
@ -345,7 +351,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);
@ -369,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, "");
/* int status = fill_buffer_from_string(cell->str_buffer, ""); */
int status = fill_cell_from_string(cell, "");
if (IS_ERROR(status)) {
destroy_cell(cell);
@ -413,7 +419,7 @@ fort_row_t* create_row_from_fmt_string(const char* FORT_RESTRICT fmt, va_list *v
goto clear;
/* Successful write */
if (virtual_sz < string_buffer_capacity(buffer))// buffer->str_sz)
if (virtual_sz < string_buffer_capacity(buffer))
break;
/* Otherwise buffer was too small, so incr. buffer size ant try again. */
@ -474,9 +480,11 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col
int dev = 0;
for (size_t i = 0; i < row_height; ++i) {
size_t i = 0;
for (i = 0; i < row_height; ++i) {
dev += snprint_n_chars_(buffer + dev, buf_sz - dev, 1, (char_type)*L);
for (size_t j = 0; j < col_width_arr_sz; ++j) {
size_t j = 0;
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);
@ -530,9 +538,11 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t
int dev = 0;
for (size_t i = 0; i < row_height; ++i) {
size_t i = 0;
for (i = 0; i < row_height; ++i) {
dev += snprint_n_chars_(buffer + dev, buf_sz - dev, 1, (char_type)*L);
for (size_t j = 0; j < col_width_arr_sz; ++j) {
size_t j = 0;
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);
@ -551,10 +561,3 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t
return dev;
}
//void set_row_type(fort_row_t *row, enum RowType type)
//{
// assert(row);
// row->type = type;
//}

View File

@ -8,11 +8,13 @@
struct fort_row;
typedef struct fort_row fort_row_t;
//enum RowType
//{
// Common,
// Header
//};
/*
enum RowType
{
Common,
Header
};
*/
fort_row_t * create_row();
@ -53,6 +55,5 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col
int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t *col_width_arr, size_t col_width_arr_sz,
size_t row_height, const context_t *context);
//void set_row_type(fort_row_t *row, enum RowType type);
#endif // ROW_H
#endif /* ROW_H */

View File

@ -45,4 +45,4 @@ int buffer_wprintf(string_buffer_t *buffer, size_t buffer_row, size_t table_colu
#endif // STRING_BUFFER_H
#endif /* STRING_BUFFER_H */

View File

@ -114,9 +114,11 @@ fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
context_t context;
context.table_options = (table->options ? table->options : &g_table_options);
for (size_t col = 0; col < cols; ++col) {
size_t col = 0;
for (col = 0; col < cols; ++col) {
col_width_arr[col] = 0;
for (size_t row = 0; row < rows; ++row) {
size_t row = 0;
for (row = 0; row < rows; ++row) {
const fort_row_t *row_p = get_row_c(table, row);
const fort_cell_t *cell = get_cell_c(row_p, col);
context.column = col;
@ -132,11 +134,13 @@ fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
* At the moment min width includes paddings. Maybe it is better that min width weren't include
* paddings but be min width of the cell content without padding
*/
// if (table->options) {
// for (size_t i = 0; i < cols; ++i) {
// col_width_arr[i] = MAX((int)col_width_arr[i], fort_options_column_width(table->options, i));
// }
// }
/*
if (table->options) {
for (size_t i = 0; i < cols; ++i) {
col_width_arr[i] = MAX((int)col_width_arr[i], fort_options_column_width(table->options, i));
}
}
*/
*col_width_arr_p = col_width_arr;
*col_width_arr_sz = cols;
@ -164,14 +168,15 @@ fort_status_t table_geometry(const FTABLE *table, size_t *height, size_t *width)
if (IS_ERROR(status))
return status;
*width = 1 + (cols == 0 ? 1 : cols) + 1; // for boundaries (that take 1 symbol) + newline
for (size_t i = 0; i < cols; ++i) {
*width = 1 + (cols == 0 ? 1 : cols) + 1; /* for boundaries (that take 1 symbol) + newline */
size_t i = 0;
for (i = 0; i < cols; ++i) {
*width += col_width_arr[i];
}
/* todo: add check for non printable horizontal row separators */
*height = 1 + (rows == 0 ? 1 : rows); // for boundaries (that take 1 symbol)
for (size_t i = 0; i < rows; ++i) {
*height = 1 + (rows == 0 ? 1 : rows); /* for boundaries (that take 1 symbol) */
for (i = 0; i < rows; ++i) {
*height += row_height_arr[i];
}
F_FREE(col_width_arr);

View File

@ -16,7 +16,7 @@ struct fort_table
vector_t *separators;
};
static inline
static FORT_INLINE
separator_t *create_separator(int enabled)
{
separator_t *res = F_CALLOC(1, sizeof(separator_t));
@ -26,7 +26,7 @@ separator_t *create_separator(int enabled)
return res;
}
static inline
static FORT_INLINE
void destroy_separator(separator_t *sep)
{
F_FREE(sep);
@ -49,4 +49,4 @@ fort_status_t table_rows_and_cols_geometry(const FTABLE *table,
size_t **row_height_arr_p, size_t *row_height_arr_sz);
fort_status_t table_geometry(const FTABLE *table, size_t *height, size_t *width);
#endif // TABLE_H
#endif /* TABLE_H */

View File

@ -95,7 +95,8 @@ size_t vector_index_of(const vector_t* vector, const void *item)
assert(vector);
assert(item);
for (size_t i = 0; i < vector->m_size; ++i) {
size_t i = 0;
for (i = 0; i < vector->m_size; ++i) {
void *data_pos = vector->m_data + i * vector->m_item_size;
if (memcmp(data_pos, item, vector->m_item_size) == 0) {
return i;

View File

@ -29,9 +29,10 @@ extern void* vector_at(vector_t*, size_t index);
#define FOR_EACH_(type, item, vector, index_name) \
for (size_t index_name = 0; (index_name < vector_size(vector)) ? ((item = *(type*)vector_at(vector, index_name)), 1) : 0; ++index_name)
size_t index_name = 0; \
for (index_name = 0; (index_name < vector_size(vector)) ? ((item = *(type*)vector_at(vector, index_name)), 1) : 0; ++index_name)
#define FOR_EACH(type, item, vector) \
FOR_EACH_(type, item, vector, UNIQUE_NAME(i))
#endif // VECTOR_H
#endif /* VECTOR_H */