[A] Improved code readability
This commit is contained in:
parent
b2ef407da5
commit
63ea186a4a
@ -21,10 +21,8 @@ static FTABLE *create_basic_table()
|
|||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(void)
|
||||||
{
|
{
|
||||||
(void)argc;
|
|
||||||
(void)argv;
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
FTABLE *table = NULL;
|
FTABLE *table = NULL;
|
||||||
|
48
src/cell.c
48
src/cell.c
@ -117,33 +117,23 @@ int cell_printf(fort_cell_t *cell, size_t row, char *buf, size_t buf_len, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define CHECK_RESULT_AND_MOVE_DEV(statement) \
|
int written = 0;
|
||||||
do { \
|
int tmp = 0;
|
||||||
k = statement; \
|
|
||||||
if (k < 0) {\
|
|
||||||
goto clear; \
|
|
||||||
} \
|
|
||||||
dev += k; \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
int dev = 0;
|
|
||||||
int k = 0;
|
|
||||||
int left = cell_padding_left;
|
int left = cell_padding_left;
|
||||||
int right = cell_padding_right;
|
int right = cell_padding_right;
|
||||||
|
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, left, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buf + written, buf_len - written, left, space_char));
|
||||||
|
|
||||||
if (cell->str_buffer)
|
if (cell->str_buffer)
|
||||||
CHECK_RESULT_AND_MOVE_DEV(buffer_printf_(cell->str_buffer, row - cell_padding_top, buf + dev, buf_len - dev - right, context));
|
CHCK_RSLT_ADD_TO_WRITTEN(buffer_printf_(cell->str_buffer, row - cell_padding_top, buf + written, buf_len - written - right, context));
|
||||||
else
|
else
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, buf_len - dev - right, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buf + written, buf_len - written, buf_len - written - right, space_char));
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, right, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buf + written, buf_len - written, right, space_char));
|
||||||
|
|
||||||
return dev;
|
return written;
|
||||||
|
|
||||||
clear:
|
clear:
|
||||||
return -1;
|
return -1;
|
||||||
#undef CHECK_RESULT_AND_MOVE_DEV
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int cell_wprintf(fort_cell_t *cell, size_t row, wchar_t *buf, size_t buf_len, const context_t *context)
|
int cell_wprintf(fort_cell_t *cell, size_t row, wchar_t *buf, size_t buf_len, const context_t *context)
|
||||||
@ -168,33 +158,23 @@ int cell_wprintf(fort_cell_t *cell, size_t row, wchar_t *buf, size_t buf_len, co
|
|||||||
return snprint_n_chars_(buf, buf_len, buf_len - 1, space_char);
|
return snprint_n_chars_(buf, buf_len, buf_len - 1, space_char);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK_RESULT_AND_MOVE_DEV(statement) \
|
int written = 0;
|
||||||
do { \
|
int tmp = 0;
|
||||||
k = statement; \
|
|
||||||
if (k < 0) {\
|
|
||||||
goto clear; \
|
|
||||||
} \
|
|
||||||
dev += k; \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
int dev = 0;
|
|
||||||
int k = 0;
|
|
||||||
int left = cell_padding_left;
|
int left = cell_padding_left;
|
||||||
int right = cell_padding_right;
|
int right = cell_padding_right;
|
||||||
|
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, left, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buf + written, buf_len - written, left, space_char));
|
||||||
|
|
||||||
if (cell->str_buffer)
|
if (cell->str_buffer)
|
||||||
CHECK_RESULT_AND_MOVE_DEV(buffer_printf_(cell->str_buffer, row - cell_padding_top, buf + dev, buf_len - dev - right, context));
|
CHCK_RSLT_ADD_TO_WRITTEN(buffer_printf_(cell->str_buffer, row - cell_padding_top, buf + written, buf_len - written - right, context));
|
||||||
else
|
else
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, buf_len - dev - right, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buf + written, buf_len - written, buf_len - written - right, space_char));
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, right, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buf + written, buf_len - written, right, space_char));
|
||||||
|
|
||||||
return dev;
|
return written;
|
||||||
|
|
||||||
clear:
|
clear:
|
||||||
return -1;
|
return -1;
|
||||||
#undef CHECK_RESULT_AND_MOVE_DEV
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
59
src/fort.c
59
src/fort.c
@ -461,15 +461,6 @@ int ft_table_write_ln(FTABLE *table, size_t rows, size_t cols, const char **tabl
|
|||||||
|
|
||||||
const char *ft_to_string(const FTABLE *table)
|
const char *ft_to_string(const FTABLE *table)
|
||||||
{
|
{
|
||||||
#define CHECK_RESULT_AND_MOVE_DEV(statement) \
|
|
||||||
do { \
|
|
||||||
k = statement; \
|
|
||||||
if (k < 0) {\
|
|
||||||
goto clear; \
|
|
||||||
} \
|
|
||||||
dev += k; \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
typedef char char_type;
|
typedef char char_type;
|
||||||
const char_type *empty_string = "";
|
const char_type *empty_string = "";
|
||||||
const enum str_buf_type buf_type = CharBuf;
|
const enum str_buf_type buf_type = CharBuf;
|
||||||
@ -520,8 +511,8 @@ const char *ft_to_string(const FTABLE *table)
|
|||||||
if (IS_ERROR(status))
|
if (IS_ERROR(status))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
int dev = 0;
|
int written = 0;
|
||||||
int k = 0;
|
int tmp = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
context_t context;
|
context_t context;
|
||||||
context.table_options = (table->options ? table->options : &g_table_options);
|
context.table_options = (table->options ? table->options : &g_table_options);
|
||||||
@ -532,8 +523,8 @@ const char *ft_to_string(const FTABLE *table)
|
|||||||
|
|
||||||
/* Print top margin */
|
/* Print top margin */
|
||||||
for (i = 0; i < context.table_options->entire_table_options.top_margin; ++i) {
|
for (i = 0; i < context.table_options->entire_table_options.top_margin; ++i) {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, width - 1/* minus new_line*/, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, sz - written, 1, new_line_char));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < rows; ++i) {
|
for (i = 0; i < rows; ++i) {
|
||||||
@ -541,18 +532,18 @@ const char *ft_to_string(const FTABLE *table)
|
|||||||
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;
|
enum HorSeparatorPos separatorPos = (i == 0) ? TopSeparator : InsideSeparator;
|
||||||
context.row = i;
|
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));
|
CHCK_RSLT_ADD_TO_WRITTEN(print_row_separator_(buffer + written, sz - written, col_width_arr, cols, prev_row, cur_row, separatorPos, cur_sep, &context));
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprintf_row_(cur_row, buffer + dev, sz - dev, col_width_arr, cols, row_height_arr[i], &context));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprintf_row_(cur_row, buffer + written, sz - written, col_width_arr, cols, row_height_arr[i], &context));
|
||||||
prev_row = cur_row;
|
prev_row = cur_row;
|
||||||
}
|
}
|
||||||
cur_row = NULL;
|
cur_row = NULL;
|
||||||
cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL;
|
cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL;
|
||||||
CHECK_RESULT_AND_MOVE_DEV(print_row_separator_(buffer + dev, sz - dev, col_width_arr, cols, prev_row, cur_row, BottomSeparator, cur_sep, &context));
|
CHCK_RSLT_ADD_TO_WRITTEN(print_row_separator_(buffer + written, sz - written, col_width_arr, cols, prev_row, cur_row, BottomSeparator, cur_sep, &context));
|
||||||
|
|
||||||
/* Print bottom margin */
|
/* Print bottom margin */
|
||||||
for (i = 0; i < context.table_options->entire_table_options.bottom_margin; ++i) {
|
for (i = 0; i < context.table_options->entire_table_options.bottom_margin; ++i) {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, width - 1/* minus new_line*/, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, sz - written, 1, new_line_char));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -565,23 +556,12 @@ clear:
|
|||||||
F_FREE(row_height_arr);
|
F_FREE(row_height_arr);
|
||||||
F_FREE(buffer);
|
F_FREE(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
#undef cur_F_STRDUP
|
#undef cur_F_STRDUP
|
||||||
#undef CHECK_RESULT_AND_MOVE_DEV
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const wchar_t *ft_to_wstring(const FTABLE *table)
|
const wchar_t *ft_to_wstring(const FTABLE *table)
|
||||||
{
|
{
|
||||||
#define CHECK_RESULT_AND_MOVE_DEV(statement) \
|
|
||||||
do { \
|
|
||||||
k = statement; \
|
|
||||||
if (k < 0) {\
|
|
||||||
goto clear; \
|
|
||||||
} \
|
|
||||||
dev += k; \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
typedef wchar_t char_type;
|
typedef wchar_t char_type;
|
||||||
const char_type *empty_string = L"";
|
const char_type *empty_string = L"";
|
||||||
const enum str_buf_type buf_type = WCharBuf;
|
const enum str_buf_type buf_type = WCharBuf;
|
||||||
@ -633,8 +613,8 @@ const wchar_t *ft_to_wstring(const FTABLE *table)
|
|||||||
if (IS_ERROR(status))
|
if (IS_ERROR(status))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
int dev = 0;
|
int written = 0;
|
||||||
int k = 0;
|
int tmp = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
context_t context;
|
context_t context;
|
||||||
context.table_options = (table->options ? table->options : &g_table_options);
|
context.table_options = (table->options ? table->options : &g_table_options);
|
||||||
@ -645,8 +625,8 @@ const wchar_t *ft_to_wstring(const FTABLE *table)
|
|||||||
|
|
||||||
/* Print top margin */
|
/* Print top margin */
|
||||||
for (i = 0; i < context.table_options->entire_table_options.top_margin; ++i) {
|
for (i = 0; i < context.table_options->entire_table_options.top_margin; ++i) {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, width - 1/* minus new_line*/, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, sz - written, 1, new_line_char));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < rows; ++i) {
|
for (i = 0; i < rows; ++i) {
|
||||||
@ -654,18 +634,18 @@ const wchar_t *ft_to_wstring(const FTABLE *table)
|
|||||||
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;
|
enum HorSeparatorPos separatorPos = (i == 0) ? TopSeparator : InsideSeparator;
|
||||||
context.row = i;
|
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));
|
CHCK_RSLT_ADD_TO_WRITTEN(print_row_separator_(buffer + written, sz - written, col_width_arr, cols, prev_row, cur_row, separatorPos, cur_sep, &context));
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprintf_row_(cur_row, buffer + dev, sz - dev, col_width_arr, cols, row_height_arr[i], &context));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprintf_row_(cur_row, buffer + written, sz - written, col_width_arr, cols, row_height_arr[i], &context));
|
||||||
prev_row = cur_row;
|
prev_row = cur_row;
|
||||||
}
|
}
|
||||||
cur_row = NULL;
|
cur_row = NULL;
|
||||||
cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL;
|
cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL;
|
||||||
CHECK_RESULT_AND_MOVE_DEV(print_row_separator_(buffer + dev, sz - dev, col_width_arr, cols, prev_row, cur_row, BottomSeparator, cur_sep, &context));
|
CHCK_RSLT_ADD_TO_WRITTEN(print_row_separator_(buffer + written, sz - written, col_width_arr, cols, prev_row, cur_row, BottomSeparator, cur_sep, &context));
|
||||||
|
|
||||||
/* Print bottom margin */
|
/* Print bottom margin */
|
||||||
for (i = 0; i < context.table_options->entire_table_options.bottom_margin; ++i) {
|
for (i = 0; i < context.table_options->entire_table_options.bottom_margin; ++i) {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, width - 1/* minus new_line*/, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, sz - written, 1, new_line_char));
|
||||||
}
|
}
|
||||||
|
|
||||||
F_FREE(col_width_arr);
|
F_FREE(col_width_arr);
|
||||||
@ -677,8 +657,7 @@ clear:
|
|||||||
F_FREE(row_height_arr);
|
F_FREE(row_height_arr);
|
||||||
F_FREE(buffer);
|
F_FREE(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#undef cur_F_STRDUP
|
||||||
#undef CHECK_RESULT_AND_MOVE_DEV
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,4 +116,13 @@ 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 wsnprint_n_chars(wchar_t *buf, size_t length, size_t n, wchar_t ch);
|
||||||
|
|
||||||
|
|
||||||
|
#define CHCK_RSLT_ADD_TO_WRITTEN(statement) \
|
||||||
|
do { \
|
||||||
|
tmp = statement; \
|
||||||
|
if (tmp < 0) {\
|
||||||
|
goto clear; \
|
||||||
|
} \
|
||||||
|
written += tmp; \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
#endif /* FORT_IMPL_H */
|
#endif /* FORT_IMPL_H */
|
||||||
|
127
src/row.c
127
src/row.c
@ -116,15 +116,6 @@ int print_row_separator(char *buffer, size_t buffer_sz,
|
|||||||
enum HorSeparatorPos separatorPos,
|
enum HorSeparatorPos separatorPos,
|
||||||
const separator_t *sep, const context_t *context)
|
const separator_t *sep, const context_t *context)
|
||||||
{
|
{
|
||||||
#define CHECK_RESULT_AND_MOVE_DEV(statement) \
|
|
||||||
do { \
|
|
||||||
k = statement; \
|
|
||||||
if (k < 0) {\
|
|
||||||
goto clear; \
|
|
||||||
} \
|
|
||||||
dev += k; \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
typedef char char_type;
|
typedef char char_type;
|
||||||
char new_line_char = '\n';
|
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;
|
||||||
@ -133,8 +124,8 @@ int print_row_separator(char *buffer, size_t buffer_sz,
|
|||||||
assert(buffer);
|
assert(buffer);
|
||||||
assert(context);
|
assert(context);
|
||||||
|
|
||||||
int dev = 0;
|
int written = 0;
|
||||||
int k = 0;
|
int tmp = 0;
|
||||||
|
|
||||||
enum RowType lower_row_type = Common;
|
enum RowType lower_row_type = Common;
|
||||||
if (lower_row != NULL) {
|
if (lower_row != NULL) {
|
||||||
@ -199,29 +190,27 @@ int print_row_separator(char *buffer, size_t buffer_sz,
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
/* Print left margin */
|
/* Print left margin */
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, context->table_options->entire_table_options.left_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.left_margin, space_char));
|
||||||
|
|
||||||
for (i = 0; i < cols; ++i) {
|
for (i = 0; i < cols; ++i) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, 1, (char_type)*L));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, 1, (char_type)*L));
|
||||||
} else {
|
} else {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, 1, (char_type)*IV));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, 1, (char_type)*IV));
|
||||||
}
|
}
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, col_width_arr[i], (char_type)*I));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, col_width_arr[i], (char_type)*I));
|
||||||
}
|
}
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, 1, (char_type)*R));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, 1, (char_type)*R));
|
||||||
|
|
||||||
/* Print right margin */
|
/* Print right margin */
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, context->table_options->entire_table_options.right_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.right_margin, space_char));
|
||||||
|
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, 1, new_line_char));
|
||||||
|
|
||||||
return dev;
|
return written;
|
||||||
|
|
||||||
clear:
|
clear:
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#undef CHECK_RESULT_AND_MOVE_DEV
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -232,26 +221,16 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz,
|
|||||||
enum HorSeparatorPos separatorPos, const separator_t *sep,
|
enum HorSeparatorPos separatorPos, const separator_t *sep,
|
||||||
const context_t *context)
|
const context_t *context)
|
||||||
{
|
{
|
||||||
#define CHECK_RESULT_AND_MOVE_DEV(statement) \
|
|
||||||
do { \
|
|
||||||
k = statement; \
|
|
||||||
if (k < 0) {\
|
|
||||||
goto clear; \
|
|
||||||
} \
|
|
||||||
dev += k; \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
typedef wchar_t char_type;
|
typedef wchar_t char_type;
|
||||||
char new_line_char = L'\n';
|
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' ';
|
wchar_t space_char = L' ';
|
||||||
|
|
||||||
|
|
||||||
assert(buffer);
|
assert(buffer);
|
||||||
assert(context);
|
assert(context);
|
||||||
|
|
||||||
int dev = 0;
|
int written = 0;
|
||||||
int k = 0;
|
int tmp = 0;
|
||||||
|
|
||||||
enum RowType lower_row_type = Common;
|
enum RowType lower_row_type = Common;
|
||||||
if (lower_row != NULL) {
|
if (lower_row != NULL) {
|
||||||
@ -316,29 +295,27 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz,
|
|||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
/* Print left margin */
|
/* Print left margin */
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, context->table_options->entire_table_options.left_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.left_margin, space_char));
|
||||||
|
|
||||||
for (i = 0; i < cols; ++i) {
|
for (i = 0; i < cols; ++i) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, 1, (char_type)*L));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, 1, (char_type)*L));
|
||||||
} else {
|
} else {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, 1, (char_type)*IV));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, 1, (char_type)*IV));
|
||||||
}
|
}
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, col_width_arr[i], (char_type)*I));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, col_width_arr[i], (char_type)*I));
|
||||||
}
|
}
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, 1, (char_type)*R));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, 1, (char_type)*R));
|
||||||
|
|
||||||
/* Print right margin */
|
/* Print right margin */
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, context->table_options->entire_table_options.right_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.right_margin, space_char));
|
||||||
|
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buffer_sz - dev, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buffer_sz - written, 1, new_line_char));
|
||||||
|
|
||||||
return dev;
|
return written;
|
||||||
|
|
||||||
clear:
|
clear:
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#undef CHECK_RESULT_AND_MOVE_DEV
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -475,15 +452,6 @@ clear:
|
|||||||
int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col_width_arr, size_t col_width_arr_sz,
|
int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col_width_arr, size_t col_width_arr_sz,
|
||||||
size_t row_height, const context_t *context)
|
size_t row_height, const context_t *context)
|
||||||
{
|
{
|
||||||
#define CHECK_RESULT_AND_MOVE_DEV(statement) \
|
|
||||||
do { \
|
|
||||||
k = statement; \
|
|
||||||
if (k < 0) {\
|
|
||||||
goto clear; \
|
|
||||||
} \
|
|
||||||
dev += k; \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
typedef char char_type;
|
typedef char char_type;
|
||||||
char space_char = ' ';
|
char space_char = ' ';
|
||||||
char new_line_char = '\n';
|
char new_line_char = '\n';
|
||||||
@ -514,40 +482,39 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col
|
|||||||
const char *R = &(*bord_chars)[RR_bip];
|
const char *R = &(*bord_chars)[RR_bip];
|
||||||
|
|
||||||
|
|
||||||
int dev = 0;
|
int written = 0;
|
||||||
int k = 0;
|
int tmp = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (i = 0; i < row_height; ++i) {
|
for (i = 0; i < row_height; ++i) {
|
||||||
/* Print left margin */
|
/* Print left margin */
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, context->table_options->entire_table_options.left_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, context->table_options->entire_table_options.left_margin, space_char));
|
||||||
|
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, 1, (char_type)*L));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, 1, (char_type)*L));
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
for (j = 0; j < col_width_arr_sz; ++j) {
|
for (j = 0; j < col_width_arr_sz; ++j) {
|
||||||
((context_t *)context)->column = j;
|
((context_t *)context)->column = j;
|
||||||
if (j < cols_in_row) {
|
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));
|
CHCK_RSLT_ADD_TO_WRITTEN(cell_printf_(cell, i, buffer + written, col_width_arr[j] + 1, context));
|
||||||
} else {
|
} else {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, col_width_arr[j], space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, col_width_arr[j], space_char));
|
||||||
}
|
}
|
||||||
if (j == col_width_arr_sz - 1) {
|
if (j == col_width_arr_sz - 1) {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, 1, (char_type)*R));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, 1, (char_type)*R));
|
||||||
} else {
|
} else {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, 1, (char_type)*IV));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, 1, (char_type)*IV));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print right margin */
|
/* Print right margin */
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, context->table_options->entire_table_options.right_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, context->table_options->entire_table_options.right_margin, space_char));
|
||||||
|
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, 1, new_line_char));
|
||||||
}
|
}
|
||||||
return dev;
|
return written;
|
||||||
|
|
||||||
clear:
|
clear:
|
||||||
return -1;
|
return -1;
|
||||||
#undef CHECK_RESULT_AND_MOVE_DEV
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -555,15 +522,6 @@ clear:
|
|||||||
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,
|
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)
|
size_t row_height, const context_t *context)
|
||||||
{
|
{
|
||||||
#define CHECK_RESULT_AND_MOVE_DEV(statement) \
|
|
||||||
do { \
|
|
||||||
k = statement; \
|
|
||||||
if (k < 0) {\
|
|
||||||
goto clear; \
|
|
||||||
} \
|
|
||||||
dev += k; \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
typedef wchar_t char_type;
|
typedef wchar_t char_type;
|
||||||
char space_char = L' ';
|
char space_char = L' ';
|
||||||
char new_line_char = L'\n';
|
char new_line_char = L'\n';
|
||||||
@ -594,39 +552,38 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t
|
|||||||
const char *R = &(*bord_chars)[RR_bip];
|
const char *R = &(*bord_chars)[RR_bip];
|
||||||
|
|
||||||
|
|
||||||
int dev = 0;
|
int written = 0;
|
||||||
int k = 0;
|
int tmp = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (i = 0; i < row_height; ++i) {
|
for (i = 0; i < row_height; ++i) {
|
||||||
/* Print left margin */
|
/* Print left margin */
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, context->table_options->entire_table_options.left_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, context->table_options->entire_table_options.left_margin, space_char));
|
||||||
|
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, 1, (char_type)*L));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, 1, (char_type)*L));
|
||||||
size_t j = 0;
|
size_t j = 0;
|
||||||
for (j = 0; j < col_width_arr_sz; ++j) {
|
for (j = 0; j < col_width_arr_sz; ++j) {
|
||||||
((context_t *)context)->column = j;
|
((context_t *)context)->column = j;
|
||||||
if (j < cols_in_row) {
|
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));
|
CHCK_RSLT_ADD_TO_WRITTEN(cell_printf_(cell, i, buffer + written, col_width_arr[j] + 1, context));
|
||||||
} else {
|
} else {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, col_width_arr[j], space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, col_width_arr[j], space_char));
|
||||||
}
|
}
|
||||||
if (j == col_width_arr_sz - 1) {
|
if (j == col_width_arr_sz - 1) {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, 1, (char_type)*R));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, 1, (char_type)*R));
|
||||||
} else {
|
} else {
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, 1, (char_type)*IV));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, 1, (char_type)*IV));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print right margin */
|
/* Print right margin */
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, context->table_options->entire_table_options.right_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, context->table_options->entire_table_options.right_margin, space_char));
|
||||||
|
|
||||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, buf_sz - dev, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_chars_(buffer + written, buf_sz - written, 1, new_line_char));
|
||||||
}
|
}
|
||||||
return dev;
|
return written;
|
||||||
|
|
||||||
clear:
|
clear:
|
||||||
return -1;
|
return -1;
|
||||||
#undef CHECK_RESULT_AND_MOVE_DEV
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user