[D] Removed redundant hdr functions

This commit is contained in:
seleznevae 2018-03-05 21:18:26 +03:00
parent 8ba3d99565
commit f5e067e7f2
6 changed files with 40 additions and 196 deletions

View File

@ -39,7 +39,10 @@ int main()
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned); 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_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
ft_hdr_printf_ln(table, "#|Planet|Avg. speed"); // 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);
ft_printf_ln(table, "%d|%s|%5.2f km/s", 1, "Mercury", 47.362); ft_printf_ln(table, "%d|%s|%5.2f km/s", 1, "Mercury", 47.362);
ft_printf_ln(table, "%d|%s|%5.2f km/s", 2, "Venus", 35.02); ft_printf_ln(table, "%d|%s|%5.2f km/s", 2, "Venus", 35.02);
ft_printf_ln(table, "%d|%s|%5.2f km/s", 3, "Earth", 29.78); ft_printf_ln(table, "%d|%s|%5.2f km/s", 3, "Earth", 29.78);
@ -54,7 +57,10 @@ int main()
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned); 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_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
ft_hdr_printf_ln(table, "Rank|Title|Year|Rating"); // 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");
FT_NWRITE_LN(table, "1", "The Shawshank Redemption", "1994", "9.5"); FT_NWRITE_LN(table, "1", "The Shawshank Redemption", "1994", "9.5");
FT_NWRITE_LN(table, "2", "12 Angry Men", "1957", "8.8"); FT_NWRITE_LN(table, "2", "12 Angry Men", "1957", "8.8");
FT_NWRITE_LN(table, "3", "2001: A Space Odyssey", "1968", "8.5"); FT_NWRITE_LN(table, "3", "2001: A Space Odyssey", "1968", "8.5");
@ -71,7 +77,10 @@ int main()
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, LeftAligned); 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_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, CenterAligned);
ft_hdr_printf_ln(table, "Commodity|Farm price|Avg. spread"); // 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");
const char *row1[] = {"Potatoes", "$1.60", "200.94%"}; const char *row1[] = {"Potatoes", "$1.60", "200.94%"};
const char *row2[] = {"Carrots", "$0.32 ", "190.63%"}; const char *row2[] = {"Carrots", "$0.32 ", "190.63%"};
ft_row_write_ln(table, 3, row1); ft_row_write_ln(table, 3, row1);
@ -87,7 +96,9 @@ int main()
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, LeftAligned); 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_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, CenterAligned);
ft_hdr_printf_ln(table, "No.|Name|Avg. Mark"); // 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] = { const char *ctab[2][3] = {
{"1", "Joe Public", "3.14"}, {"1", "Joe Public", "3.14"},
{"2", "John Doe", "4.50"} {"2", "John Doe", "4.50"}
@ -104,7 +115,9 @@ int main()
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned); 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_set_cell_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
ft_hdr_printf_ln(table, "No.|Name|Avg. Mark"); // 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] = { const char **tab[2] = {
row1, row1,
row2 row2

View File

@ -190,25 +190,16 @@ FORT_EXTERN void ft_ln(FTABLE *FORT_RESTRICT table);
#if defined(FORT_CLANG_COMPILER) || defined(FORT_GCC_COMPILER) #if defined(FORT_CLANG_COMPILER) || defined(FORT_GCC_COMPILER)
FORT_EXTERN int ft_printf(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_PRINTF_ATTRIBUTE_FORMAT(2, 3); FORT_EXTERN int ft_printf(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
FORT_EXTERN int ft_printf_ln(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_PRINTF_ATTRIBUTE_FORMAT(2, 3); FORT_EXTERN int ft_printf_ln(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
FORT_EXTERN int ft_hdr_printf(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
FORT_EXTERN int ft_hdr_printf_ln(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
#else #else
FORT_EXTERN int ft_printf_impl(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_PRINTF_ATTRIBUTE_FORMAT(2, 3); FORT_EXTERN int ft_printf_impl(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
FORT_EXTERN int ft_printf_ln_impl(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_PRINTF_ATTRIBUTE_FORMAT(2, 3); FORT_EXTERN int ft_printf_ln_impl(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
FORT_EXTERN int ft_hdr_printf_impl(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_PRINTF_ATTRIBUTE_FORMAT(2, 3);
FORT_EXTERN int ft_hdr_printf_ln_impl(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) FORT_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__))
#define ft_printf_ln(table, ...) \ #define ft_printf_ln(table, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf_ln_impl(table, __VA_ARGS__)) (( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_printf_ln_impl(table, __VA_ARGS__))
#define ft_hdr_printf(table, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_hdr_printf_impl(table, __VA_ARGS__))
#define ft_hdr_printf_ln(table, ...) \
(( 0 ? fprintf(stderr, __VA_ARGS__) : 1), ft_hdr_printf_ln_impl(table, __VA_ARGS__))
#endif #endif

View File

@ -150,59 +150,12 @@ clear:
#if defined(FORT_CLANG_COMPILER) || defined(FORT_GCC_COMPILER) #if defined(FORT_CLANG_COMPILER) || defined(FORT_GCC_COMPILER)
#define FT_PRINTF ft_printf #define FT_PRINTF ft_printf
#define FT_PRINTF_LN ft_printf_ln #define FT_PRINTF_LN ft_printf_ln
#define FT_HDR_PRINTF ft_hdr_printf
#define FT_HDR_PRINTF_LN ft_hdr_printf_ln
#else #else
#define FT_PRINTF ft_printf_impl #define FT_PRINTF ft_printf_impl
#define FT_PRINTF_LN ft_printf_ln_impl #define FT_PRINTF_LN ft_printf_ln_impl
#define FT_HDR_PRINTF ft_hdr_printf_impl
#define FT_HDR_PRINTF_LN ft_hdr_printf_ln_impl
#endif #endif
int FT_HDR_PRINTF(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...)
{
assert(table);
assert(fmt);
va_list va;
va_start(va, fmt);
int result = ft_row_printf_impl(table, table->cur_row, fmt, &va);
va_end(va);
if (result >= 0 && table->rows) {
int sz = vector_size(table->rows);
if (sz != 0) {
// set_row_type(*(fort_row_t**)vector_at(table->rows, sz - 1), Header);
int ignore = ft_set_cell_option(table, sz - 1, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
(void)ignore;
assert(ignore == F_SUCCESS);
}
}
return result;
}
int FT_HDR_PRINTF_LN(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...)
{
assert(table);
assert(fmt);
va_list va;
va_start(va, fmt);
int result = ft_row_printf_impl(table, table->cur_row, fmt, &va);
va_end(va);
if (result >= 0 && table->rows) {
int sz = vector_size(table->rows);
if (sz != 0) {
// set_row_type(*(fort_row_t**)vector_at(table->rows, sz - 1), Header);
int ignore = ft_set_cell_option(table, sz - 1, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
(void)ignore;
assert(ignore == F_SUCCESS);
}
}
if (result >= 0) {
ft_ln(table);
}
return result;
}
int FT_PRINTF(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...) int FT_PRINTF(FTABLE *FORT_RESTRICT table, const char* FORT_RESTRICT fmt, ...)
{ {

View File

@ -316,98 +316,5 @@ void destroy_table_options(fort_table_options_t* options)
F_FREE(options); F_FREE(options);
} }
/*
#define FORT_OPTIONS_SET_COLUMN_OPTION(options, column, opt_name, opt_value) \
assert(options);\
\
if (options->col_options == NULL) {\
options->col_options = create_vector(sizeof(fort_column_options_t), DEFAULT_VECTOR_CAPACITY);\
if (options->col_options == NULL) \
return F_MEMORY_ERROR; \
} \
\
while (vector_size(options->col_options) <= column) {\
fort_column_options_t def_option = create_column_options();\
vector_push(options->col_options, &def_option);\
}\
\
fort_column_options_t *col_option = (fort_column_options_t*)vector_at(options->col_options, column);\
col_option->opt_name = opt_value;\
\
return F_SUCCESS;*/
//fort_status_t fort_options_set_column_min_width(fort_table_options_t *options, size_t column, size_t width)
//{
// FORT_OPTIONS_SET_COLUMN_OPTION(options, column, col_min_width, width);
//}
//fort_status_t fort_options_set_column_alignment(fort_table_options_t *options, size_t column, enum TextAlignment al)
//{
// FORT_OPTIONS_SET_COLUMN_OPTION(options, column, align, al);
//}
//int fort_options_column_width(const fort_table_options_t *options, size_t column)
//{
// assert(options);
// if (options->col_options == NULL)
// return -1;
// if (vector_size(options->col_options) <= column)
// return -1;
// return ((fort_column_options_t*)vector_at(options->col_options, column))->col_min_width;
//}
//int fort_options_column_width(const fort_table_options_t *options, size_t column)
//{
// assert(options);
// if (options->cell_options == NULL)
// return -1;
// const fort_cell_options_t* col_opt = cget_cell_opt(options->cell_options, FT_ANY_ROW, column);
// if (col_opt == NULL || ((col_opt->options & FT_OPT_MIN_WIDTH) == 0))
// return -1;
// else {
// return col_opt->col_min_width;
// }
//}
//int fort_options_column_alignment(const fort_table_options_t *options, size_t column)
//{
// assert(options);
// enum TextAlignment align = g_column_options.align;
// if (options->col_options == NULL)
// return align;
// if (vector_size(options->col_options) <= column)
// return align;
// return ((fort_column_options_t*)vector_at(options->col_options, column))->align;
//}
//int fort_options_column_alignment(const fort_table_options_t *options, size_t column)
//{
// assert(options);
// enum TextAlignment defaultAlign = g_column_options.align;
// if (options->cell_options == NULL)
// return defaultAlign;
// const fort_cell_options_t* col_opt = cget_cell_opt(options->cell_options, FT_ANY_ROW, column);
// if (col_opt == NULL || ((col_opt->options & FT_OPT_TEXT_ALIGN) == 0))
// return defaultAlign;
// else {
// return col_opt->align;
// }
//}

View File

@ -163,10 +163,7 @@ extern fort_table_options_t g_table_options;
fort_table_options_t* create_table_options(); fort_table_options_t* create_table_options();
fort_table_options_t* copy_table_options(const fort_table_options_t *option); fort_table_options_t* copy_table_options(const fort_table_options_t *option);
void destroy_table_options(fort_table_options_t* options); void destroy_table_options(fort_table_options_t* options);
//fort_status_t fort_options_set_column_min_width(fort_table_options_t *options, size_t column, size_t width);
//fort_status_t fort_options_set_column_alignment(fort_table_options_t *options, size_t column, enum TextAlignment al);
//int fort_options_column_width(const fort_table_options_t *options, size_t column);
//int fort_options_column_alignment(const fort_table_options_t *options, size_t column);
#endif // OPTIONS_H #endif // OPTIONS_H

View File

@ -10,37 +10,6 @@
#include "vector.h" #include "vector.h"
//fort_table_options_t test_table_opts = {
// 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 */
// {
// '+', '-', '+', '+',
// '|', '|', '|',
// '+', '-', '+', '+',
// '+', '-', '+', '+'
// },
// /* separator_chars */
// {
// '+', '=', '+', '+',
// },
// NULL, /* col_options */
//};
int set_test_options_for_table(FTABLE *table) int set_test_options_for_table(FTABLE *table)
{ {
assert(table); assert(table);
@ -210,7 +179,9 @@ void test_table_basic(void **state)
// ft_set_table_options(table, &test_table_opts); // ft_set_table_options(table, &test_table_opts);
assert_true( set_test_options_for_table(table) == F_SUCCESS); assert_true( set_test_options_for_table(table) == F_SUCCESS);
int n = ft_hdr_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
int n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 ); assert_true( n == 4 );
n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14); n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 ); assert_true( n == 4 );
@ -248,7 +219,9 @@ void test_table_basic(void **state)
// ft_set_table_options(table, &test_table_opts); // ft_set_table_options(table, &test_table_opts);
assert_true( set_test_options_for_table(table) == F_SUCCESS); assert_true( set_test_options_for_table(table) == F_SUCCESS);
int n = ft_hdr_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
int n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
assert_true( n == 4 ); assert_true( n == 4 );
n = ft_printf_ln(table, "%c|%s|%f|%d", 'c', "234", 3.14, 3); n = ft_printf_ln(table, "%c|%s|%f|%d", 'c', "234", 3.14, 3);
assert_true( n == 4 ); assert_true( n == 4 );
@ -284,7 +257,9 @@ void test_table_basic(void **state)
// ft_set_table_options(table, &test_table_opts); // ft_set_table_options(table, &test_table_opts);
assert_true( set_test_options_for_table(table) == F_SUCCESS); assert_true( set_test_options_for_table(table) == F_SUCCESS);
int n = ft_hdr_printf_ln(table, "||%s|%f", "234", 3.14); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
int n = ft_printf_ln(table, "||%s|%f", "234", 3.14);
assert_true( n == 4 ); assert_true( n == 4 );
n = ft_printf_ln(table, "%c|%s|%f", 'c', "234", 3.14); n = ft_printf_ln(table, "%c|%s|%f", 'c', "234", 3.14);
assert_true( n == 3 ); assert_true( n == 3 );
@ -320,7 +295,9 @@ void test_table_basic(void **state)
// ft_set_table_options(table, &test_table_opts); // ft_set_table_options(table, &test_table_opts);
assert_true( set_test_options_for_table(table) == F_SUCCESS); assert_true( set_test_options_for_table(table) == F_SUCCESS);
int n = ft_hdr_printf_ln(table, "|||"); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
int n = ft_printf_ln(table, "|||");
assert_true( n == 4 ); assert_true( n == 4 );
n = ft_printf_ln(table, "|||"); n = ft_printf_ln(table, "|||");
assert_true( n == 4 ); assert_true( n == 4 );
@ -367,7 +344,9 @@ FTABLE *create_test_int_table(int set_test_opts)
assert_true (table != NULL); assert_true (table != NULL);
int n = ft_hdr_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67);
assert_true( n == 4 ); assert_true( n == 4 );
assert(ft_write(table, "3") == F_SUCCESS); assert(ft_write(table, "3") == F_SUCCESS);
@ -429,7 +408,9 @@ void test_table_options(void **state)
table = create_test_int_table(0); table = create_test_int_table(0);
ft_add_separator(table); ft_add_separator(table);
int n = ft_hdr_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67);
assert_true( n == 4 ); assert_true( n == 4 );
const char *table_str = ft_to_string(table); const char *table_str = ft_to_string(table);
@ -802,7 +783,9 @@ void test_table_options(void **state)
table = ft_create_table(); table = ft_create_table();
int n = ft_hdr_printf_ln(table, "%d|%c|%s|%f", 4, 'c', "234", 3.14); ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
int n = ft_printf_ln(table, "%d|%c|%s|%f", 4, 'c', "234", 3.14);
assert_true( n == 4 ); assert_true( n == 4 );
n = FT_NWRITE_LN(table, "5", "c", "234\n12", "3.140000"); n = FT_NWRITE_LN(table, "5", "c", "234\n12", "3.140000");
assert_true( n == F_SUCCESS ); assert_true( n == F_SUCCESS );