[C] Renames options to properties
This commit is contained in:
parent
01da9c3f68
commit
ece19c8bcb
@ -67,7 +67,7 @@ set(FORT_DEV_SOURCES
|
|||||||
src/fort_impl.c
|
src/fort_impl.c
|
||||||
src/vector.c
|
src/vector.c
|
||||||
src/string_buffer.c
|
src/string_buffer.c
|
||||||
src/options.c
|
src/properties.c
|
||||||
src/cell.c
|
src/cell.c
|
||||||
src/row.c
|
src/row.c
|
||||||
src/table.c
|
src/table.c
|
||||||
@ -96,7 +96,7 @@ set(TEST_SOURCES_DEV
|
|||||||
tests/wb_tests/test_table_geometry.c
|
tests/wb_tests/test_table_geometry.c
|
||||||
tests/bb_tests/test_table_basic.c
|
tests/bb_tests/test_table_basic.c
|
||||||
tests/bb_tests/test_table_border_style.c
|
tests/bb_tests/test_table_border_style.c
|
||||||
tests/bb_tests/test_table_options.c
|
tests/bb_tests/test_table_properties.c
|
||||||
tests/bb_tests/test_memory_errors.c
|
tests/bb_tests/test_memory_errors.c
|
||||||
tests/test_utils.c)
|
tests/test_utils.c)
|
||||||
add_executable(${PROJECT_NAME}_test_dev
|
add_executable(${PROJECT_NAME}_test_dev
|
||||||
@ -110,7 +110,7 @@ set(TEST_SOURCES
|
|||||||
tests/main_test.c
|
tests/main_test.c
|
||||||
tests/bb_tests/test_table_basic.c
|
tests/bb_tests/test_table_basic.c
|
||||||
tests/bb_tests/test_table_border_style.c
|
tests/bb_tests/test_table_border_style.c
|
||||||
tests/bb_tests/test_table_options.c
|
tests/bb_tests/test_table_properties.c
|
||||||
tests/bb_tests/test_memory_errors.c
|
tests/bb_tests/test_memory_errors.c
|
||||||
tests/test_utils.c)
|
tests/test_utils.c)
|
||||||
add_executable(${PROJECT_NAME}_test
|
add_executable(${PROJECT_NAME}_test
|
||||||
|
15
README.md
15
README.md
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
**Features:**
|
**Features:**
|
||||||
- Easy to integrate (only 2 files)
|
- Easy to integrate (only 2 files)
|
||||||
- Customization of appearance (various border styles and row/column/cell options for indentation, alignment, padding)
|
- Customization of appearance (various border styles and row/column/cell properties for indentation, alignment, padding)
|
||||||
- A number of functions to fill the table (add content by adding separate cells, rows or use _printf_ like functions)
|
- A number of functions to fill the table (add content by adding separate cells, rows or use _printf_ like functions)
|
||||||
- Support of multiple lines in cells
|
- Support of multiple lines in cells
|
||||||
- Support of wide characters
|
- Support of wide characters
|
||||||
@ -56,7 +56,7 @@ See [wiki](https://github.com/seleznevae/libfort/wiki) of the project.
|
|||||||
The common libfort usage pattern:
|
The common libfort usage pattern:
|
||||||
- create a table (`_ft_create_table_`);
|
- create a table (`_ft_create_table_`);
|
||||||
- fill it with data (`_ft_write_ln_`, `_fr_ptrintf_ln_`, `_ft_row_write_`, ...);
|
- fill it with data (`_ft_write_ln_`, `_fr_ptrintf_ln_`, `_ft_row_write_`, ...);
|
||||||
- modify basic table appearance (`_ft_set_cell_option_`, `ft_set_border_style` ...)
|
- modify basic table appearance (`_ft_set_cell_prop_`, `ft_set_border_style` ...)
|
||||||
- convert table to string representation (`_ft_to_string_`);
|
- convert table to string representation (`_ft_to_string_`);
|
||||||
- destroy the table (`_ft_destroy_table_`)
|
- destroy the table (`_ft_destroy_table_`)
|
||||||
|
|
||||||
@ -73,7 +73,8 @@ int main(void)
|
|||||||
{
|
{
|
||||||
ft_table_t *table = ft_create_table();
|
ft_table_t *table = ft_create_table();
|
||||||
/* Set "header" type for the first row */
|
/* Set "header" type for the first row */
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
|
|
||||||
ft_write_ln(table, "N", "Driver", "Time", "Avg Speed");
|
ft_write_ln(table, "N", "Driver", "Time", "Avg Speed");
|
||||||
|
|
||||||
ft_write_ln(table, "1", "Ricciardo", "1:25.945", "222.128");
|
ft_write_ln(table, "1", "Ricciardo", "1:25.945", "222.128");
|
||||||
@ -126,7 +127,7 @@ int main(void)
|
|||||||
ft_set_border_style(table, FT_DOUBLE2_STYLE);
|
ft_set_border_style(table, FT_DOUBLE2_STYLE);
|
||||||
|
|
||||||
/* Set "header" type for the first row */
|
/* Set "header" type for the first row */
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_write_ln(table, "Movie title", "Director", "Year", "Rating");
|
ft_write_ln(table, "Movie title", "Director", "Year", "Rating");
|
||||||
|
|
||||||
ft_write_ln(table, "The Shawshank Redemption", "Frank Darabont", "1994", "9.5");
|
ft_write_ln(table, "The Shawshank Redemption", "Frank Darabont", "1994", "9.5");
|
||||||
@ -134,8 +135,8 @@ int main(void)
|
|||||||
ft_write_ln(table, "2001: A Space Odyssey", "Stanley Kubrick", "1968", "8.5");
|
ft_write_ln(table, "2001: A Space Odyssey", "Stanley Kubrick", "1968", "8.5");
|
||||||
|
|
||||||
/* Set center alignment for the 1st and 3rd columns */
|
/* Set center alignment for the 1st and 3rd columns */
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 3, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 3, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
|
|
||||||
printf("%s\n", ft_to_string(table));
|
printf("%s\n", ft_to_string(table));
|
||||||
ft_destroy_table(table);
|
ft_destroy_table(table);
|
||||||
@ -189,7 +190,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
ft_table_t *table = ft_create_table();
|
ft_table_t *table = ft_create_table();
|
||||||
/* Set "header" type for the first row */
|
/* Set "header" type for the first row */
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_write_ln(table, "N", "Planet", "Speed, km/s", "Temperature, K");
|
ft_write_ln(table, "N", "Planet", "Speed, km/s", "Temperature, K");
|
||||||
|
|
||||||
/* Fill row with printf like function */
|
/* Fill row with printf like function */
|
||||||
|
@ -95,7 +95,7 @@ def main():
|
|||||||
"vector.h",
|
"vector.h",
|
||||||
"wcwidth.h",
|
"wcwidth.h",
|
||||||
"string_buffer.h",
|
"string_buffer.h",
|
||||||
"options.h",
|
"properties.h",
|
||||||
"cell.h",
|
"cell.h",
|
||||||
"row.h",
|
"row.h",
|
||||||
"table.h"
|
"table.h"
|
||||||
@ -106,4 +106,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
static ft_table_t *create_basic_table(void)
|
static ft_table_t *create_basic_table(void)
|
||||||
{
|
{
|
||||||
ft_table_t *table = ft_create_table();
|
ft_table_t *table = ft_create_table();
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_write_ln(table, "Rank", "Title", "Year", "Rating");
|
ft_write_ln(table, "Rank", "Title", "Year", "Rating");
|
||||||
|
|
||||||
ft_write_ln(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
ft_write_ln(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
||||||
@ -36,7 +36,7 @@ void print_char_str(const char *str)
|
|||||||
void base_example(void)
|
void base_example(void)
|
||||||
{
|
{
|
||||||
ft_table_t *table = ft_create_table();
|
ft_table_t *table = ft_create_table();
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_write_ln(table, "N", "Driver", "Time", "Avg Speed");
|
ft_write_ln(table, "N", "Driver", "Time", "Avg Speed");
|
||||||
|
|
||||||
ft_write_ln(table, "1", "Ricciardo", "1:25.945", "222.128");
|
ft_write_ln(table, "1", "Ricciardo", "1:25.945", "222.128");
|
||||||
@ -54,7 +54,7 @@ void complex_layout_example(void)
|
|||||||
ft_set_border_style(table, FT_DOUBLE2_STYLE);
|
ft_set_border_style(table, FT_DOUBLE2_STYLE);
|
||||||
|
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_write_ln(table, "Sed", "Aenean", "Text");
|
ft_write_ln(table, "Sed", "Aenean", "Text");
|
||||||
|
|
||||||
ft_write_ln(table, "Duis", "Aliquam",
|
ft_write_ln(table, "Duis", "Aliquam",
|
||||||
@ -65,21 +65,21 @@ void complex_layout_example(void)
|
|||||||
"quam pellentesque.");
|
"quam pellentesque.");
|
||||||
ft_write_ln(table, "Summary", "", "Sed tempor est eget odio varius dignissim.");
|
ft_write_ln(table, "Summary", "", "Sed tempor est eget odio varius dignissim.");
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, 2, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, 0, 2, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
ft_set_cell_option(table, 3, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, 3, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
ft_set_cell_span(table, 3, 0, 2);
|
ft_set_cell_span(table, 3, 0, 2);
|
||||||
printf("%s\n", ft_to_string(table));
|
printf("%s\n", ft_to_string(table));
|
||||||
ft_destroy_table(table);
|
ft_destroy_table(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
void different_cell_options_example(void)
|
void different_cell_properties_example(void)
|
||||||
{
|
{
|
||||||
ft_table_t *table = ft_create_table();
|
ft_table_t *table = ft_create_table();
|
||||||
/* Change border style */
|
/* Change border style */
|
||||||
ft_set_border_style(table, FT_DOUBLE2_STYLE);
|
ft_set_border_style(table, FT_DOUBLE2_STYLE);
|
||||||
|
|
||||||
/* Set "header" type for the first row */
|
/* Set "header" type for the first row */
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_write_ln(table, "Movie title", "Director", "Year", "Rating");
|
ft_write_ln(table, "Movie title", "Director", "Year", "Rating");
|
||||||
|
|
||||||
ft_write_ln(table, "The Shawshank Redemption", "Frank Darabont", "1994", "9.5");
|
ft_write_ln(table, "The Shawshank Redemption", "Frank Darabont", "1994", "9.5");
|
||||||
@ -87,8 +87,8 @@ void different_cell_options_example(void)
|
|||||||
ft_write_ln(table, "2001: A Space Odyssey", "Stanley Kubrick", "1968", "8.5");
|
ft_write_ln(table, "2001: A Space Odyssey", "Stanley Kubrick", "1968", "8.5");
|
||||||
|
|
||||||
/* Set center alignment for the 1st and 3rd columns */
|
/* Set center alignment for the 1st and 3rd columns */
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 3, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 3, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
|
|
||||||
printf("%s\n", ft_to_string(table));
|
printf("%s\n", ft_to_string(table));
|
||||||
ft_destroy_table(table);
|
ft_destroy_table(table);
|
||||||
@ -98,7 +98,7 @@ void fill_table_with_data_example(void)
|
|||||||
{
|
{
|
||||||
ft_table_t *table = ft_create_table();
|
ft_table_t *table = ft_create_table();
|
||||||
/* Set "header" type for the first row */
|
/* Set "header" type for the first row */
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_write_ln(table, "N", "Planet", "Speed, km/s", "Temperature, K");
|
ft_write_ln(table, "N", "Planet", "Speed, km/s", "Temperature, K");
|
||||||
|
|
||||||
/* Fill row with printf like function */
|
/* Fill row with printf like function */
|
||||||
@ -118,7 +118,7 @@ void fill_table_with_data_example(void)
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
base_example();
|
base_example();
|
||||||
different_cell_options_example();
|
different_cell_properties_example();
|
||||||
fill_table_with_data_example();
|
fill_table_with_data_example();
|
||||||
complex_layout_example();
|
complex_layout_example();
|
||||||
|
|
||||||
@ -127,10 +127,10 @@ int main(void)
|
|||||||
ft_table_t *table = NULL;
|
ft_table_t *table = NULL;
|
||||||
|
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_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", 1, "Mercury", 47.362);
|
||||||
@ -144,10 +144,10 @@ int main(void)
|
|||||||
/*-------------------------------------------------------------*/
|
/*-------------------------------------------------------------*/
|
||||||
|
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_write_ln(table, "Rank", "Title", "Year", "Rating");
|
ft_write_ln(table, "Rank", "Title", "Year", "Rating");
|
||||||
|
|
||||||
ft_write_ln(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
ft_write_ln(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
||||||
@ -163,10 +163,10 @@ int main(void)
|
|||||||
/*-------------------------------------------------------------*/
|
/*-------------------------------------------------------------*/
|
||||||
|
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_printf_ln(table, "Commodity|Farm price|Avg. spread");
|
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%"};
|
||||||
@ -180,10 +180,10 @@ int main(void)
|
|||||||
|
|
||||||
/*-------------------------------------------------------------*/
|
/*-------------------------------------------------------------*/
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_printf_ln(table, "No.|Name|Avg. Mark");
|
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"},
|
||||||
@ -260,7 +260,7 @@ int main(void)
|
|||||||
/* Debug */
|
/* Debug */
|
||||||
ft_set_default_border_style(FT_SOLID_STYLE);
|
ft_set_default_border_style(FT_SOLID_STYLE);
|
||||||
table = create_basic_table();
|
table = create_basic_table();
|
||||||
ft_set_cell_option(table, FT_CUR_ROW, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, FT_CUR_ROW, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_write_ln(table, "Summary", "", "", "8.7");
|
ft_write_ln(table, "Summary", "", "", "8.7");
|
||||||
ft_set_cell_span(table, 6, 0, 3);
|
ft_set_cell_span(table, 6, 0, 3);
|
||||||
ft_set_cell_span(table, 0, 0, 3);
|
ft_set_cell_span(table, 0, 0, 3);
|
||||||
@ -275,10 +275,10 @@ int main(void)
|
|||||||
ft_set_default_border_style(FT_BASIC_STYLE);
|
ft_set_default_border_style(FT_BASIC_STYLE);
|
||||||
|
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_wwrite_ln(table, L"Ранг", L"Название", L"Год", L"Рейтинг");
|
ft_wwrite_ln(table, L"Ранг", L"Название", L"Год", L"Рейтинг");
|
||||||
|
|
||||||
ft_wwrite_ln(table, L"1", L"Побег из Шоушенка", L"1994", L"9.5");
|
ft_wwrite_ln(table, L"1", L"Побег из Шоушенка", L"1994", L"9.5");
|
||||||
|
@ -38,7 +38,7 @@ void base_example(void)
|
|||||||
std::cout << table.to_string() << std::endl;
|
std::cout << table.to_string() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void different_cell_options_example(void)
|
void different_cell_properties_example(void)
|
||||||
{
|
{
|
||||||
fort::Table table;
|
fort::Table table;
|
||||||
/* Change border style */
|
/* Change border style */
|
||||||
@ -87,7 +87,7 @@ void fill_table_with_data_example(void)
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
base_example();
|
base_example();
|
||||||
different_cell_options_example();
|
different_cell_properties_example();
|
||||||
fill_table_with_data_example();
|
fill_table_with_data_example();
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -103,11 +103,11 @@ int main()
|
|||||||
<< "5" << "Blade Runner" << "1982" << "8.1" << fort::endr
|
<< "5" << "Blade Runner" << "1982" << "8.1" << fort::endr
|
||||||
<< fort::endr;
|
<< fort::endr;
|
||||||
|
|
||||||
using fort::CellOption;
|
using fort::CellProperty;
|
||||||
using fort::TableOption;
|
using fort::TableProperty;
|
||||||
table.set_option<CellOption::MinWidth>(0, 0, 20);
|
table.set_property<CellProperty::MinWidth>(0, 0, 20);
|
||||||
table.set_option<CellOption::TextAlign>(0, 0, fort::TextAlign::Left);
|
table.set_property<CellProperty::TextAlign>(0, 0, fort::TextAlign::Left);
|
||||||
table.set_option<CellOption::RowType>(2, FT_ANY_COLUMN, fort::RowType::Header);
|
table.set_property<CellProperty::RowType>(2, FT_ANY_COLUMN, fort::RowType::Header);
|
||||||
|
|
||||||
std::cout << table.to_string() << std::endl;
|
std::cout << table.to_string() << std::endl;
|
||||||
}
|
}
|
||||||
@ -124,14 +124,14 @@ int main()
|
|||||||
table.write_ln("4", "2001: A Space Odyssey", "1968", "8.5");
|
table.write_ln("4", "2001: A Space Odyssey", "1968", "8.5");
|
||||||
table.write_ln("5", "Blade Runner", "1982", "8.1");
|
table.write_ln("5", "Blade Runner", "1982", "8.1");
|
||||||
|
|
||||||
using fort::CellOption;
|
using fort::CellProperty;
|
||||||
using fort::TableOption;
|
using fort::TableProperty;
|
||||||
table.set_cell_min_width(0, 0, 20);
|
table.set_cell_min_width(0, 0, 20);
|
||||||
table.set_cell_text_align(0, 0, fort::TextAlign::Left);
|
table.set_cell_text_align(0, 0, fort::TextAlign::Left);
|
||||||
table.set_cell_row_type(2, FT_ANY_COLUMN, fort::RowType::Header);
|
table.set_cell_row_type(2, FT_ANY_COLUMN, fort::RowType::Header);
|
||||||
|
|
||||||
|
|
||||||
table.set_option<TableOption::LeftMargin>(4);
|
table.set_property<TableProperty::LeftMargin>(4);
|
||||||
|
|
||||||
table.set_border_style(FT_SOLID_STYLE);
|
table.set_border_style(FT_SOLID_STYLE);
|
||||||
std::cout << table.to_string();
|
std::cout << table.to_string();
|
||||||
|
496
lib/fort.c
496
lib/fort.c
File diff suppressed because it is too large
Load Diff
78
lib/fort.h
78
lib/fort.h
@ -672,17 +672,17 @@ int ft_set_border_style(ft_table_t *table, const struct ft_border_style *style);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Cell options identifiers.
|
* @name Cell properties identifiers.
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define FT_COPT_MIN_WIDTH (0x01U << 0) /**< Minimum width */
|
#define FT_CPROP_MIN_WIDTH (0x01U << 0) /**< Minimum width */
|
||||||
#define FT_COPT_TEXT_ALIGN (0x01U << 1) /**< Text alignment */
|
#define FT_CPROP_TEXT_ALIGN (0x01U << 1) /**< Text alignment */
|
||||||
#define FT_COPT_TOP_PADDING (0x01U << 2) /**< Top padding for cell content */
|
#define FT_CPROP_TOP_PADDING (0x01U << 2) /**< Top padding for cell content */
|
||||||
#define FT_COPT_BOTTOM_PADDING (0x01U << 3) /**< Bottom padding for cell content */
|
#define FT_CPROP_BOTTOM_PADDING (0x01U << 3) /**< Bottom padding for cell content */
|
||||||
#define FT_COPT_LEFT_PADDING (0x01U << 4) /**< Left padding for cell content */
|
#define FT_CPROP_LEFT_PADDING (0x01U << 4) /**< Left padding for cell content */
|
||||||
#define FT_COPT_RIGHT_PADDING (0x01U << 5) /**< Right padding for cell content */
|
#define FT_CPROP_RIGHT_PADDING (0x01U << 5) /**< Right padding for cell content */
|
||||||
#define FT_COPT_EMPTY_STR_HEIGHT (0x01U << 6) /**< Height of empty cell */
|
#define FT_CPROP_EMPTY_STR_HEIGHT (0x01U << 6) /**< Height of empty cell */
|
||||||
#define FT_COPT_ROW_TYPE (0x01U << 7) /**< Row type */
|
#define FT_CPROP_ROW_TYPE (0x01U << 7) /**< Row type */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
||||||
@ -705,20 +705,20 @@ enum ft_row_type {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set default cell option for all new formatted tables.
|
* Set default cell property for all new formatted tables.
|
||||||
*
|
*
|
||||||
* @param option
|
* @param property
|
||||||
* Cell option identifier.
|
* Cell property identifier.
|
||||||
* @param value
|
* @param value
|
||||||
* Cell option value.
|
* Cell property value.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; default cell option was changed.
|
* - 0: Success; default cell property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
int ft_set_default_cell_option(uint32_t option, int value);
|
int ft_set_default_cell_prop(uint32_t property, int value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set option for the specified cell of the table.
|
* Set property for the specified cell of the table.
|
||||||
*
|
*
|
||||||
* @param table
|
* @param table
|
||||||
* A pointer to the ft_table_t structure.
|
* A pointer to the ft_table_t structure.
|
||||||
@ -726,56 +726,56 @@ int ft_set_default_cell_option(uint32_t option, int value);
|
|||||||
* Cell row.
|
* Cell row.
|
||||||
* @param col
|
* @param col
|
||||||
* Cell column.
|
* Cell column.
|
||||||
* @param option
|
* @param property
|
||||||
* Cell option identifier.
|
* Cell property identifier.
|
||||||
* @param value
|
* @param value
|
||||||
* Cell option value.
|
* Cell property value.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; cell option was changed.
|
* - 0: Success; cell property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
int ft_set_cell_option(ft_table_t *table, size_t row, size_t col, uint32_t option, int value);
|
int ft_set_cell_prop(ft_table_t *table, size_t row, size_t col, uint32_t property, int value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Table options identifiers.
|
* @name Table properties identifiers.
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define FT_TOPT_LEFT_MARGIN (0x01U << 0)
|
#define FT_TPROP_LEFT_MARGIN (0x01U << 0)
|
||||||
#define FT_TOPT_TOP_MARGIN (0x01U << 1)
|
#define FT_TPROP_TOP_MARGIN (0x01U << 1)
|
||||||
#define FT_TOPT_RIGHT_MARGIN (0x01U << 2)
|
#define FT_TPROP_RIGHT_MARGIN (0x01U << 2)
|
||||||
#define FT_TOPT_BOTTOM_MARGIN (0x01U << 3)
|
#define FT_TPROP_BOTTOM_MARGIN (0x01U << 3)
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set default table option.
|
* Set default table property.
|
||||||
*
|
*
|
||||||
* @param option
|
* @param property
|
||||||
* Table option identifier.
|
* Table property identifier.
|
||||||
* @param value
|
* @param value
|
||||||
* Table option value.
|
* Table property value.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; default table option was changed.
|
* - 0: Success; default table property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
int ft_set_default_tbl_option(uint32_t option, int value);
|
int ft_set_default_tbl_prop(uint32_t property, int value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set table option.
|
* Set table property.
|
||||||
*
|
*
|
||||||
* @param table
|
* @param table
|
||||||
* A pointer to the ft_table_t structure.
|
* A pointer to the ft_table_t structure.
|
||||||
* @param option
|
* @param property
|
||||||
* Table option identifier.
|
* Table property identifier.
|
||||||
* @param value
|
* @param value
|
||||||
* Table option value.
|
* Table property value.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; default table option was changed.
|
* - 0: Success; default table property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
int ft_set_tbl_option(ft_table_t *table, uint32_t option, int value);
|
int ft_set_tbl_prop(ft_table_t *table, uint32_t property, int value);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -790,7 +790,7 @@ int ft_set_tbl_option(ft_table_t *table, uint32_t option, int value);
|
|||||||
* @param hor_span
|
* @param hor_span
|
||||||
* Column span.
|
* Column span.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; default table option was changed.
|
* - 0: Success; cell span was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span);
|
int ft_set_cell_span(ft_table_t *table, size_t row, size_t col, size_t hor_span);
|
||||||
|
108
lib/fort.hpp
108
lib/fort.hpp
@ -42,7 +42,7 @@ SOFTWARE.
|
|||||||
namespace fort
|
namespace fort
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class CellOption {
|
enum class CellProperty {
|
||||||
MinWidth,
|
MinWidth,
|
||||||
TextAlign,
|
TextAlign,
|
||||||
TopPadding,
|
TopPadding,
|
||||||
@ -53,7 +53,7 @@ enum class CellOption {
|
|||||||
RowType
|
RowType
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class TableOption {
|
enum class TableProperty {
|
||||||
LeftMargin,
|
LeftMargin,
|
||||||
TopMargin,
|
TopMargin,
|
||||||
RightMargin,
|
RightMargin,
|
||||||
@ -241,7 +241,7 @@ public:
|
|||||||
Table &operator<<(const TableManipulator &arg)
|
Table &operator<<(const TableManipulator &arg)
|
||||||
{
|
{
|
||||||
if (arg.value == header.value)
|
if (arg.value == header.value)
|
||||||
ft_set_cell_option(table, FT_CUR_ROW, FT_ANY_ROW, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, FT_CUR_ROW, FT_ANY_ROW, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
else if (arg.value == endr.value)
|
else if (arg.value == endr.value)
|
||||||
ft_ln(table);
|
ft_ln(table);
|
||||||
else if (arg.value == separator.value)
|
else if (arg.value == separator.value)
|
||||||
@ -402,12 +402,12 @@ public:
|
|||||||
* @param value
|
* @param value
|
||||||
* Value of the min width.
|
* Value of the min width.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; cell option was changed.
|
* - 0: Success; cell property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
bool set_cell_min_width(size_t row, size_t col, unsigned value)
|
bool set_cell_min_width(size_t row, size_t col, unsigned value)
|
||||||
{
|
{
|
||||||
return FT_IS_SUCCESS(ft_set_cell_option(table, row, col, FT_COPT_MIN_WIDTH, value));
|
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_MIN_WIDTH, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -420,12 +420,12 @@ public:
|
|||||||
* @param value
|
* @param value
|
||||||
* Value of the text alignment.
|
* Value of the text alignment.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; cell option was changed.
|
* - 0: Success; cell property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
bool set_cell_text_align(size_t row, size_t col, enum TextAlign value)
|
bool set_cell_text_align(size_t row, size_t col, enum TextAlign value)
|
||||||
{
|
{
|
||||||
return FT_IS_SUCCESS(ft_set_cell_option(table, row, col, FT_COPT_TEXT_ALIGN, static_cast<int>(value)));
|
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_TEXT_ALIGN, static_cast<int>(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -438,12 +438,12 @@ public:
|
|||||||
* @param value
|
* @param value
|
||||||
* Value of the top padding.
|
* Value of the top padding.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; cell option was changed.
|
* - 0: Success; cell property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
bool set_cell_top_padding(size_t row, size_t col, unsigned value)
|
bool set_cell_top_padding(size_t row, size_t col, unsigned value)
|
||||||
{
|
{
|
||||||
return FT_IS_SUCCESS(ft_set_cell_option(table, row, col, FT_COPT_TOP_PADDING, value));
|
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_TOP_PADDING, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -456,12 +456,12 @@ public:
|
|||||||
* @param value
|
* @param value
|
||||||
* Value of the bottom padding.
|
* Value of the bottom padding.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; cell option was changed.
|
* - 0: Success; cell property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
bool set_cell_bottom_padding(size_t row, size_t col, unsigned value)
|
bool set_cell_bottom_padding(size_t row, size_t col, unsigned value)
|
||||||
{
|
{
|
||||||
return FT_IS_SUCCESS(ft_set_cell_option(table, row, col, FT_COPT_BOTTOM_PADDING, value));
|
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_BOTTOM_PADDING, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -474,12 +474,12 @@ public:
|
|||||||
* @param value
|
* @param value
|
||||||
* Value of the left padding.
|
* Value of the left padding.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; cell option was changed.
|
* - 0: Success; cell property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
bool set_cell_left_padding(size_t row, size_t col, unsigned value)
|
bool set_cell_left_padding(size_t row, size_t col, unsigned value)
|
||||||
{
|
{
|
||||||
return FT_IS_SUCCESS(ft_set_cell_option(table, row, col, FT_COPT_LEFT_PADDING, value));
|
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_LEFT_PADDING, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -492,12 +492,12 @@ public:
|
|||||||
* @param value
|
* @param value
|
||||||
* Value of the left padding.
|
* Value of the left padding.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; cell option was changed.
|
* - 0: Success; cell property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
bool set_cell_right_padding(size_t row, size_t col, unsigned value)
|
bool set_cell_right_padding(size_t row, size_t col, unsigned value)
|
||||||
{
|
{
|
||||||
return FT_IS_SUCCESS(ft_set_cell_option(table, row, col, FT_COPT_RIGHT_PADDING, value));
|
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_RIGHT_PADDING, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -510,12 +510,12 @@ public:
|
|||||||
* @param value
|
* @param value
|
||||||
* Value of the empty string height.
|
* Value of the empty string height.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; cell option was changed.
|
* - 0: Success; cell property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
bool set_cell_empty_str_height(size_t row, size_t col, unsigned value)
|
bool set_cell_empty_str_height(size_t row, size_t col, unsigned value)
|
||||||
{
|
{
|
||||||
return FT_IS_SUCCESS(ft_set_cell_option(table, row, col, FT_COPT_EMPTY_STR_HEIGHT, value));
|
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_EMPTY_STR_HEIGHT, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -528,25 +528,25 @@ public:
|
|||||||
* @param value
|
* @param value
|
||||||
* Value of the row type.
|
* Value of the row type.
|
||||||
* @return
|
* @return
|
||||||
* - 0: Success; cell option was changed.
|
* - 0: Success; cell property was changed.
|
||||||
* - (<0): In case of error
|
* - (<0): In case of error
|
||||||
*/
|
*/
|
||||||
bool set_cell_row_type(size_t row, size_t col, enum RowType value)
|
bool set_cell_row_type(size_t row, size_t col, enum RowType value)
|
||||||
{
|
{
|
||||||
return FT_IS_SUCCESS(ft_set_cell_option(table, row, col, FT_COPT_ROW_TYPE, static_cast<int>(value)));
|
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, FT_CPROP_ROW_TYPE, static_cast<int>(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <CellOption option>
|
template <CellProperty property>
|
||||||
bool set_option(size_t row, size_t col, unsigned value);
|
bool set_property(size_t row, size_t col, unsigned value);
|
||||||
|
|
||||||
template <CellOption option>
|
template <CellProperty property>
|
||||||
bool set_option(size_t row, size_t col, enum TextAlign align);
|
bool set_property(size_t row, size_t col, enum TextAlign align);
|
||||||
|
|
||||||
template <CellOption option>
|
template <CellProperty property>
|
||||||
bool set_option(size_t row, size_t col, enum RowType rowType);
|
bool set_property(size_t row, size_t col, enum RowType rowType);
|
||||||
|
|
||||||
template <TableOption option>
|
template <TableProperty property>
|
||||||
bool set_option(unsigned value);
|
bool set_property(unsigned value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set border style for the table.
|
* Set border style for the table.
|
||||||
@ -646,49 +646,49 @@ bool set_default_border_style(struct ft_border_style *style)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Declare specializations for set_option functions
|
* Declare specializations for set_property functions
|
||||||
*/
|
*/
|
||||||
#define DECLARE_SPECS_FOR_CELL_OPTIONS_X \
|
#define DECLARE_SPECS_FOR_CELL_PROPS_X \
|
||||||
SET_CELL_OPTION_SPEC(CellOption::MinWidth, FT_COPT_MIN_WIDTH, unsigned) \
|
SET_CELL_PROP_SPEC(CellProperty::MinWidth, FT_CPROP_MIN_WIDTH, unsigned) \
|
||||||
SET_CELL_OPTION_SPEC(CellOption::TextAlign, FT_COPT_TEXT_ALIGN, TextAlign) \
|
SET_CELL_PROP_SPEC(CellProperty::TextAlign, FT_CPROP_TEXT_ALIGN, TextAlign) \
|
||||||
SET_CELL_OPTION_SPEC(CellOption::TopPadding, FT_COPT_TOP_PADDING, unsigned) \
|
SET_CELL_PROP_SPEC(CellProperty::TopPadding, FT_CPROP_TOP_PADDING, unsigned) \
|
||||||
SET_CELL_OPTION_SPEC(CellOption::BottomPadding, FT_COPT_BOTTOM_PADDING, unsigned) \
|
SET_CELL_PROP_SPEC(CellProperty::BottomPadding, FT_CPROP_BOTTOM_PADDING, unsigned) \
|
||||||
SET_CELL_OPTION_SPEC(CellOption::LeftPadding, FT_COPT_LEFT_PADDING, unsigned) \
|
SET_CELL_PROP_SPEC(CellProperty::LeftPadding, FT_CPROP_LEFT_PADDING, unsigned) \
|
||||||
SET_CELL_OPTION_SPEC(CellOption::RightPading, FT_COPT_RIGHT_PADDING, unsigned) \
|
SET_CELL_PROP_SPEC(CellProperty::RightPading, FT_CPROP_RIGHT_PADDING, unsigned) \
|
||||||
SET_CELL_OPTION_SPEC(CellOption::EmptyStrHeight, FT_COPT_EMPTY_STR_HEIGHT, unsigned) \
|
SET_CELL_PROP_SPEC(CellProperty::EmptyStrHeight, FT_CPROP_EMPTY_STR_HEIGHT, unsigned) \
|
||||||
SET_CELL_OPTION_SPEC(CellOption::RowType, FT_COPT_ROW_TYPE, RowType)
|
SET_CELL_PROP_SPEC(CellProperty::RowType, FT_CPROP_ROW_TYPE, RowType)
|
||||||
|
|
||||||
#define SET_CELL_OPTION_SPEC(CELL_OPTION, C_OPTION, VALUE_TYPE) \
|
#define SET_CELL_PROP_SPEC(CELL_OPTION, C_OPTION, VALUE_TYPE) \
|
||||||
template <> \
|
template <> \
|
||||||
bool Table::set_option<CELL_OPTION>(size_t row, size_t col, VALUE_TYPE value) \
|
bool Table::set_property<CELL_OPTION>(size_t row, size_t col, VALUE_TYPE value) \
|
||||||
{ \
|
{ \
|
||||||
return FT_IS_SUCCESS(ft_set_cell_option(table, row, col, C_OPTION, static_cast<int>(value))); \
|
return FT_IS_SUCCESS(ft_set_cell_prop(table, row, col, C_OPTION, static_cast<int>(value))); \
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLARE_SPECS_FOR_CELL_OPTIONS_X
|
DECLARE_SPECS_FOR_CELL_PROPS_X
|
||||||
|
|
||||||
#undef SET_TABLE_OPTION_SPEC
|
#undef SET_TABLE_PROP_SPEC
|
||||||
#undef DECLARE_SPECS_FOR_CELL_OPTIONS_X
|
#undef DECLARE_SPECS_FOR_PROPS_X
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define DECLARE_SPECS_FOR_TABLE_OPTIONS_X \
|
#define DECLARE_SPECS_FOR_TABLE_PROPS_X \
|
||||||
SET_TABLE_OPTION_SPEC(TableOption::LeftMargin, FT_TOPT_LEFT_MARGIN) \
|
SET_TABLE_PROP_SPEC(TableProperty::LeftMargin, FT_TPROP_LEFT_MARGIN) \
|
||||||
SET_TABLE_OPTION_SPEC(TableOption::TopMargin, FT_TOPT_TOP_MARGIN) \
|
SET_TABLE_PROP_SPEC(TableProperty::TopMargin, FT_TPROP_TOP_MARGIN) \
|
||||||
SET_TABLE_OPTION_SPEC(TableOption::RightMargin, FT_TOPT_RIGHT_MARGIN) \
|
SET_TABLE_PROP_SPEC(TableProperty::RightMargin, FT_TPROP_RIGHT_MARGIN) \
|
||||||
SET_TABLE_OPTION_SPEC(TableOption::BottomMargin, FT_TOPT_BOTTOM_MARGIN)
|
SET_TABLE_PROP_SPEC(TableProperty::BottomMargin, FT_TPROP_BOTTOM_MARGIN)
|
||||||
|
|
||||||
#define SET_TABLE_OPTION_SPEC(TABLE_OPTION, TBL_OPTION) \
|
#define SET_TABLE_PROP_SPEC(TABLE_OPTION, TBL_OPTION) \
|
||||||
template <> \
|
template <> \
|
||||||
bool Table::set_option<TABLE_OPTION>(unsigned value) \
|
bool Table::set_property<TABLE_OPTION>(unsigned value) \
|
||||||
{ \
|
{ \
|
||||||
return FT_IS_SUCCESS(ft_set_tbl_option(table, TBL_OPTION, static_cast<int>(value))); \
|
return FT_IS_SUCCESS(ft_set_tbl_prop(table, TBL_OPTION, static_cast<int>(value))); \
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLARE_SPECS_FOR_TABLE_OPTIONS_X
|
DECLARE_SPECS_FOR_TABLE_PROPS_X
|
||||||
|
|
||||||
#undef SET_TABLE_OPTION_SPEC
|
#undef SET_TABLE_PROP_SPEC
|
||||||
#undef DECLARE_SPECS_FOR_TABLE_OPTIONS_X
|
#undef DECLARE_SPECS_FOR_TABLE_PROPS_X
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
26
src/cell.c
26
src/cell.c
@ -1,5 +1,5 @@
|
|||||||
#include "cell.h"
|
#include "cell.h"
|
||||||
#include "options.h"
|
#include "properties.h"
|
||||||
#include "string_buffer.h"
|
#include "string_buffer.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
@ -73,13 +73,13 @@ size_t hint_width_cell(const fort_cell_t *cell, const context_t *context)
|
|||||||
|
|
||||||
assert(cell);
|
assert(cell);
|
||||||
assert(context);
|
assert(context);
|
||||||
size_t cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
|
size_t cell_padding_left = get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_LEFT_PADDING);
|
||||||
size_t cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
|
size_t cell_padding_right = get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_RIGHT_PADDING);
|
||||||
size_t result = cell_padding_left + cell_padding_right;
|
size_t result = cell_padding_left + cell_padding_right;
|
||||||
if (cell->str_buffer && cell->str_buffer->str.data) {
|
if (cell->str_buffer && cell->str_buffer->str.data) {
|
||||||
result += buffer_text_width(cell->str_buffer);
|
result += buffer_text_width(cell->str_buffer);
|
||||||
}
|
}
|
||||||
result = MAX(result, (size_t)get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_MIN_WIDTH));
|
result = MAX(result, (size_t)get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_MIN_WIDTH));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,9 +88,9 @@ size_t hint_height_cell(const fort_cell_t *cell, const context_t *context)
|
|||||||
{
|
{
|
||||||
assert(cell);
|
assert(cell);
|
||||||
assert(context);
|
assert(context);
|
||||||
size_t cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
|
size_t cell_padding_top = get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_TOP_PADDING);
|
||||||
size_t cell_padding_bottom = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_BOTTOM_PADDING);
|
size_t cell_padding_bottom = get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_BOTTOM_PADDING);
|
||||||
size_t cell_empty_string_height = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_EMPTY_STR_HEIGHT);
|
size_t cell_empty_string_height = get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_EMPTY_STR_HEIGHT);
|
||||||
size_t result = cell_padding_top + cell_padding_bottom;
|
size_t result = cell_padding_top + cell_padding_bottom;
|
||||||
if (cell->str_buffer && cell->str_buffer->str.data) {
|
if (cell->str_buffer && cell->str_buffer->str.data) {
|
||||||
size_t text_height = buffer_text_height(cell->str_buffer);
|
size_t text_height = buffer_text_height(cell->str_buffer);
|
||||||
@ -115,9 +115,9 @@ int cell_printf(fort_cell_t *cell, size_t row, char *buf, size_t buf_len, const
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
|
unsigned int cell_padding_top = get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_TOP_PADDING);
|
||||||
unsigned int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
|
unsigned int cell_padding_left = get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_LEFT_PADDING);
|
||||||
unsigned int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
|
unsigned int cell_padding_right = get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_RIGHT_PADDING);
|
||||||
|
|
||||||
if (row >= hint_height_cell(cell, context)
|
if (row >= hint_height_cell(cell, context)
|
||||||
|| row < cell_padding_top
|
|| row < cell_padding_top
|
||||||
@ -161,9 +161,9 @@ int cell_wprintf(fort_cell_t *cell, size_t row, wchar_t *buf, size_t buf_len, co
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
|
unsigned int cell_padding_top = get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_TOP_PADDING);
|
||||||
unsigned int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
|
unsigned int cell_padding_left = get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_LEFT_PADDING);
|
||||||
unsigned int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
|
unsigned int cell_padding_right = get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_RIGHT_PADDING);
|
||||||
|
|
||||||
if (row >= hint_height_cell(cell, context)
|
if (row >= hint_height_cell(cell, context)
|
||||||
|| row < cell_padding_top
|
|| row < cell_padding_top
|
||||||
|
@ -38,7 +38,7 @@ SOFTWARE.
|
|||||||
#include "string_buffer.h"
|
#include "string_buffer.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
#include "row.h"
|
#include "row.h"
|
||||||
#include "options.h"
|
#include "properties.h"
|
||||||
|
|
||||||
|
|
||||||
ft_table_t *ft_create_table(void)
|
ft_table_t *ft_create_table(void)
|
||||||
@ -58,7 +58,7 @@ ft_table_t *ft_create_table(void)
|
|||||||
F_FREE(result);
|
F_FREE(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
result->options = NULL;
|
result->properties = NULL;
|
||||||
result->conv_buffer = NULL;
|
result->conv_buffer = NULL;
|
||||||
result->cur_row = 0;
|
result->cur_row = 0;
|
||||||
result->cur_col = 0;
|
result->cur_col = 0;
|
||||||
@ -87,7 +87,7 @@ void ft_destroy_table(ft_table_t *table)
|
|||||||
}
|
}
|
||||||
destroy_vector(table->separators);
|
destroy_vector(table->separators);
|
||||||
}
|
}
|
||||||
destroy_table_options(table->options);
|
destroy_table_properties(table->properties);
|
||||||
destroy_string_buffer(table->conv_buffer);
|
destroy_string_buffer(table->conv_buffer);
|
||||||
F_FREE(table);
|
F_FREE(table);
|
||||||
}
|
}
|
||||||
@ -124,8 +124,8 @@ ft_table_t *ft_copy_table(ft_table_t *table)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
result->options = copy_table_options(table->options);
|
result->properties = copy_table_properties(table->properties);
|
||||||
if (result->options == NULL) {
|
if (result->properties == NULL) {
|
||||||
ft_destroy_table(result);
|
ft_destroy_table(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -622,14 +622,14 @@ const char *ft_to_string(const ft_table_t *table)
|
|||||||
int tmp = 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_properties = (table->properties ? table->properties : &g_table_properties);
|
||||||
fort_row_t *prev_row = NULL;
|
fort_row_t *prev_row = NULL;
|
||||||
fort_row_t *cur_row = NULL;
|
fort_row_t *cur_row = NULL;
|
||||||
separator_t *cur_sep = NULL;
|
separator_t *cur_sep = NULL;
|
||||||
size_t sep_size = vector_size(table->separators);
|
size_t sep_size = vector_size(table->separators);
|
||||||
|
|
||||||
/* 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_properties->entire_table_properties.top_margin; ++i) {
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, 1, new_line_char));
|
||||||
}
|
}
|
||||||
@ -648,7 +648,7 @@ const char *ft_to_string(const ft_table_t *table)
|
|||||||
CHCK_RSLT_ADD_TO_WRITTEN(print_row_separator_(buffer + written, sz - written, 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_properties->entire_table_properties.bottom_margin; ++i) {
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, 1, new_line_char));
|
||||||
}
|
}
|
||||||
@ -727,14 +727,14 @@ const wchar_t *ft_to_wstring(const ft_table_t *table)
|
|||||||
int tmp = 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_properties = (table->properties ? table->properties : &g_table_properties);
|
||||||
fort_row_t *prev_row = NULL;
|
fort_row_t *prev_row = NULL;
|
||||||
fort_row_t *cur_row = NULL;
|
fort_row_t *cur_row = NULL;
|
||||||
separator_t *cur_sep = NULL;
|
separator_t *cur_sep = NULL;
|
||||||
size_t sep_size = vector_size(table->separators);
|
size_t sep_size = vector_size(table->separators);
|
||||||
|
|
||||||
/* 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_properties->entire_table_properties.top_margin; ++i) {
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, 1, new_line_char));
|
||||||
}
|
}
|
||||||
@ -753,7 +753,7 @@ const wchar_t *ft_to_wstring(const ft_table_t *table)
|
|||||||
CHCK_RSLT_ADD_TO_WRITTEN(print_row_separator_(buffer + written, sz - written, 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_properties->entire_table_properties.bottom_margin; ++i) {
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, width - 1/* minus new_line*/, space_char));
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, sz - written, 1, new_line_char));
|
||||||
}
|
}
|
||||||
@ -844,7 +844,7 @@ struct ft_border_style *FT_FRAME_STYLE = (struct ft_border_style *) &FORT_FRAME
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void set_border_options_for_options(fort_table_options_t *options, const struct ft_border_style *style)
|
static void set_border_props_for_props(fort_table_properties_t *properties, const struct ft_border_style *style)
|
||||||
{
|
{
|
||||||
if ((struct fort_border_style *)style == &FORT_BASIC_STYLE
|
if ((struct fort_border_style *)style == &FORT_BASIC_STYLE
|
||||||
|| (struct fort_border_style *)style == &FORT_BASIC2_STYLE
|
|| (struct fort_border_style *)style == &FORT_BASIC2_STYLE
|
||||||
@ -859,16 +859,16 @@ static void set_border_options_for_options(fort_table_options_t *options, const
|
|||||||
|| (struct fort_border_style *)style == &FORT_BOLD_STYLE
|
|| (struct fort_border_style *)style == &FORT_BOLD_STYLE
|
||||||
|| (struct fort_border_style *)style == &FORT_BOLD2_STYLE
|
|| (struct fort_border_style *)style == &FORT_BOLD2_STYLE
|
||||||
|| (struct fort_border_style *)style == &FORT_FRAME_STYLE) {
|
|| (struct fort_border_style *)style == &FORT_FRAME_STYLE) {
|
||||||
memcpy(&(options->border_style), (struct fort_border_style *)style, sizeof(struct fort_border_style));
|
memcpy(&(properties->border_style), (struct fort_border_style *)style, sizeof(struct fort_border_style));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct ft_border_chars *border_chs = &(style->border_chs);
|
const struct ft_border_chars *border_chs = &(style->border_chs);
|
||||||
const struct ft_border_chars *header_border_chs = &(style->header_border_chs);
|
const struct ft_border_chars *header_border_chs = &(style->header_border_chs);
|
||||||
|
|
||||||
#define BOR_CHARS options->border_style.border_chars
|
#define BOR_CHARS properties->border_style.border_chars
|
||||||
#define H_BOR_CHARS options->border_style.header_border_chars
|
#define H_BOR_CHARS properties->border_style.header_border_chars
|
||||||
#define SEP_CHARS options->border_style.separator_chars
|
#define SEP_CHARS properties->border_style.separator_chars
|
||||||
|
|
||||||
/*
|
/*
|
||||||
BOR_CHARS[TL_bip] = BOR_CHARS[TT_bip] = BOR_CHARS[TV_bip] = BOR_CHARS[TR_bip] = border_chs->top_border_ch;
|
BOR_CHARS[TL_bip] = BOR_CHARS[TT_bip] = BOR_CHARS[TV_bip] = BOR_CHARS[TR_bip] = border_chs->top_border_ch;
|
||||||
@ -933,36 +933,36 @@ static void set_border_options_for_options(fort_table_options_t *options, const
|
|||||||
|
|
||||||
int ft_set_default_border_style(const struct ft_border_style *style)
|
int ft_set_default_border_style(const struct ft_border_style *style)
|
||||||
{
|
{
|
||||||
set_border_options_for_options(&g_table_options, style);
|
set_border_props_for_props(&g_table_properties, style);
|
||||||
return FT_SUCCESS;
|
return FT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_set_border_style(ft_table_t *table, const struct ft_border_style *style)
|
int ft_set_border_style(ft_table_t *table, const struct ft_border_style *style)
|
||||||
{
|
{
|
||||||
assert(table);
|
assert(table);
|
||||||
if (table->options == NULL) {
|
if (table->properties == NULL) {
|
||||||
table->options = create_table_options();
|
table->properties = create_table_properties();
|
||||||
if (table->options == NULL)
|
if (table->properties == NULL)
|
||||||
return FT_MEMORY_ERROR;
|
return FT_MEMORY_ERROR;
|
||||||
}
|
}
|
||||||
set_border_options_for_options(table->options, style);
|
set_border_props_for_props(table->properties, style);
|
||||||
return FT_SUCCESS;
|
return FT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int ft_set_cell_option(ft_table_t *table, size_t row, size_t col, uint32_t option, int value)
|
int ft_set_cell_prop(ft_table_t *table, size_t row, size_t col, uint32_t property, int value)
|
||||||
{
|
{
|
||||||
assert(table);
|
assert(table);
|
||||||
|
|
||||||
if (table->options == NULL) {
|
if (table->properties == NULL) {
|
||||||
table->options = create_table_options();
|
table->properties = create_table_properties();
|
||||||
if (table->options == NULL)
|
if (table->properties == NULL)
|
||||||
return FT_MEMORY_ERROR;
|
return FT_MEMORY_ERROR;
|
||||||
}
|
}
|
||||||
if (table->options->cell_options == NULL) {
|
if (table->properties->cell_properties == NULL) {
|
||||||
table->options->cell_options = create_cell_opt_container();
|
table->properties->cell_properties = create_cell_prop_container();
|
||||||
if (table->options->cell_options == NULL) {
|
if (table->properties->cell_properties == NULL) {
|
||||||
return FT_ERROR;
|
return FT_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -972,30 +972,30 @@ int ft_set_cell_option(ft_table_t *table, size_t row, size_t col, uint32_t optio
|
|||||||
if (row == FT_CUR_COLUMN)
|
if (row == FT_CUR_COLUMN)
|
||||||
col = table->cur_col;
|
col = table->cur_col;
|
||||||
|
|
||||||
return set_cell_option(table->options->cell_options, row, col, option, value);
|
return set_cell_property(table->properties->cell_properties, row, col, property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_set_default_cell_option(uint32_t option, int value)
|
int ft_set_default_cell_prop(uint32_t property, int value)
|
||||||
{
|
{
|
||||||
return set_default_cell_option(option, value);
|
return set_default_cell_property(property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ft_set_default_tbl_option(uint32_t option, int value)
|
int ft_set_default_tbl_prop(uint32_t property, int value)
|
||||||
{
|
{
|
||||||
return set_default_entire_table_option(option, value);
|
return set_default_entire_table_property(property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_set_tbl_option(ft_table_t *table, uint32_t option, int value)
|
int ft_set_tbl_prop(ft_table_t *table, uint32_t property, int value)
|
||||||
{
|
{
|
||||||
assert(table);
|
assert(table);
|
||||||
|
|
||||||
if (table->options == NULL) {
|
if (table->properties == NULL) {
|
||||||
table->options = create_table_options();
|
table->properties = create_table_properties();
|
||||||
if (table->options == NULL)
|
if (table->properties == NULL)
|
||||||
return FT_MEMORY_ERROR;
|
return FT_MEMORY_ERROR;
|
||||||
}
|
}
|
||||||
return set_entire_table_option(table->options, option, value);
|
return set_entire_table_property(table->properties, property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *ptr))
|
void ft_set_memory_funcs(void *(*f_malloc)(size_t size), void (*f_free)(void *ptr))
|
||||||
|
@ -80,8 +80,8 @@ enum F_BOOL {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct fort_table_options;
|
struct fort_table_properties;
|
||||||
struct fort_column_options;
|
struct fort_column_properties;
|
||||||
struct fort_row;
|
struct fort_row;
|
||||||
struct vector;
|
struct vector;
|
||||||
struct fort_cell;
|
struct fort_cell;
|
||||||
@ -90,14 +90,14 @@ struct separator {
|
|||||||
int enabled;
|
int enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct fort_table_options fort_table_options_t;
|
typedef struct fort_table_properties fort_table_properties_t;
|
||||||
struct fort_context {
|
struct fort_context {
|
||||||
fort_table_options_t *table_options;
|
fort_table_properties_t *table_properties;
|
||||||
size_t row;
|
size_t row;
|
||||||
size_t column;
|
size_t column;
|
||||||
};
|
};
|
||||||
typedef struct fort_context context_t;
|
typedef struct fort_context context_t;
|
||||||
typedef struct fort_column_options fort_column_options_t;
|
typedef struct fort_column_properties fort_column_properties_t;
|
||||||
typedef struct vector vector_t;
|
typedef struct vector vector_t;
|
||||||
typedef struct fort_cell fort_cell_t;
|
typedef struct fort_cell fort_cell_t;
|
||||||
typedef struct string_buffer string_buffer_t;
|
typedef struct string_buffer string_buffer_t;
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "options.h"
|
#include "properties.h"
|
||||||
#include "fort_utils.h"
|
#include "fort_utils.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* COLUMN OPTIONS
|
* COLUMN PROPERTIES
|
||||||
* ***************************************************************************/
|
* ***************************************************************************/
|
||||||
|
|
||||||
struct fort_cell_options g_default_cell_option = {
|
struct fort_cell_props g_default_cell_properties = {
|
||||||
FT_ANY_ROW, /* cell_row */
|
FT_ANY_ROW, /* cell_row */
|
||||||
FT_ANY_COLUMN, /* cell_col */
|
FT_ANY_COLUMN, /* cell_col */
|
||||||
|
|
||||||
/* options */
|
/* properties */
|
||||||
FT_COPT_MIN_WIDTH | FT_COPT_TEXT_ALIGN | FT_COPT_TOP_PADDING
|
FT_CPROP_MIN_WIDTH | FT_CPROP_TEXT_ALIGN | FT_CPROP_TOP_PADDING
|
||||||
| FT_COPT_BOTTOM_PADDING | FT_COPT_LEFT_PADDING | FT_COPT_RIGHT_PADDING
|
| FT_CPROP_BOTTOM_PADDING | FT_CPROP_LEFT_PADDING | FT_CPROP_RIGHT_PADDING
|
||||||
| FT_COPT_EMPTY_STR_HEIGHT,
|
| FT_CPROP_EMPTY_STR_HEIGHT,
|
||||||
|
|
||||||
0, /* col_min_width */
|
0, /* col_min_width */
|
||||||
FT_ALIGNED_LEFT, /* align */
|
FT_ALIGNED_LEFT, /* align */
|
||||||
@ -27,28 +27,28 @@ struct fort_cell_options g_default_cell_option = {
|
|||||||
FT_ROW_COMMON, /* row_type */
|
FT_ROW_COMMON, /* row_type */
|
||||||
};
|
};
|
||||||
|
|
||||||
static int get_option_value_if_exists_otherwise_default(const struct fort_cell_options *cell_opts, uint32_t option)
|
static int get_prop_value_if_exists_otherwise_default(const struct fort_cell_props *cell_opts, uint32_t property)
|
||||||
{
|
{
|
||||||
if (cell_opts == NULL || !OPTION_IS_SET(cell_opts->options, option)) {
|
if (cell_opts == NULL || !PROP_IS_SET(cell_opts->properties, property)) {
|
||||||
cell_opts = &g_default_cell_option;
|
cell_opts = &g_default_cell_properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (option) {
|
switch (property) {
|
||||||
case FT_COPT_MIN_WIDTH:
|
case FT_CPROP_MIN_WIDTH:
|
||||||
return cell_opts->col_min_width;
|
return cell_opts->col_min_width;
|
||||||
case FT_COPT_TEXT_ALIGN:
|
case FT_CPROP_TEXT_ALIGN:
|
||||||
return cell_opts->align;
|
return cell_opts->align;
|
||||||
case FT_COPT_TOP_PADDING:
|
case FT_CPROP_TOP_PADDING:
|
||||||
return cell_opts->cell_padding_top;
|
return cell_opts->cell_padding_top;
|
||||||
case FT_COPT_BOTTOM_PADDING:
|
case FT_CPROP_BOTTOM_PADDING:
|
||||||
return cell_opts->cell_padding_bottom;
|
return cell_opts->cell_padding_bottom;
|
||||||
case FT_COPT_LEFT_PADDING:
|
case FT_CPROP_LEFT_PADDING:
|
||||||
return cell_opts->cell_padding_left;
|
return cell_opts->cell_padding_left;
|
||||||
case FT_COPT_RIGHT_PADDING:
|
case FT_CPROP_RIGHT_PADDING:
|
||||||
return cell_opts->cell_padding_right;
|
return cell_opts->cell_padding_right;
|
||||||
case FT_COPT_EMPTY_STR_HEIGHT:
|
case FT_CPROP_EMPTY_STR_HEIGHT:
|
||||||
return cell_opts->cell_empty_string_height;
|
return cell_opts->cell_empty_string_height;
|
||||||
case FT_COPT_ROW_TYPE:
|
case FT_CPROP_ROW_TYPE:
|
||||||
return cell_opts->row_type;
|
return cell_opts->row_type;
|
||||||
default:
|
default:
|
||||||
/* todo: implement later */
|
/* todo: implement later */
|
||||||
@ -57,17 +57,16 @@ static int get_option_value_if_exists_otherwise_default(const struct fort_cell_o
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//#define DEFAULT_CELL_OPTION {FT_ROW_UNSPEC, FT_COLUMN_UNSPEC, 0, 0, 0}
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_cell_opt_container_t *create_cell_opt_container(void)
|
fort_cell_prop_container_t *create_cell_prop_container(void)
|
||||||
{
|
{
|
||||||
fort_cell_opt_container_t *ret = create_vector(sizeof(fort_cell_options_t), DEFAULT_VECTOR_CAPACITY);
|
fort_cell_prop_container_t *ret = create_vector(sizeof(fort_cell_props_t), DEFAULT_VECTOR_CAPACITY);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
void destroy_cell_opt_container(fort_cell_opt_container_t *cont)
|
void destroy_cell_prop_container(fort_cell_prop_container_t *cont)
|
||||||
{
|
{
|
||||||
if (cont)
|
if (cont)
|
||||||
destroy_vector(cont);
|
destroy_vector(cont);
|
||||||
@ -75,13 +74,13 @@ void destroy_cell_opt_container(fort_cell_opt_container_t *cont)
|
|||||||
|
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
const fort_cell_options_t *cget_cell_opt(const fort_cell_opt_container_t *cont, size_t row, size_t col)
|
const fort_cell_props_t *cget_cell_prop(const fort_cell_prop_container_t *cont, size_t row, size_t col)
|
||||||
{
|
{
|
||||||
assert(cont);
|
assert(cont);
|
||||||
size_t sz = vector_size(cont);
|
size_t sz = vector_size(cont);
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (i = 0; i < sz; ++i) {
|
for (i = 0; i < sz; ++i) {
|
||||||
const fort_cell_options_t *opt = (const fort_cell_options_t *)vector_at_c(cont, i);
|
const fort_cell_props_t *opt = (const fort_cell_props_t *)vector_at_c(cont, i);
|
||||||
if (opt->cell_row == row && opt->cell_col == col)
|
if (opt->cell_row == row && opt->cell_col == col)
|
||||||
return opt;
|
return opt;
|
||||||
}
|
}
|
||||||
@ -90,28 +89,27 @@ const fort_cell_options_t *cget_cell_opt(const fort_cell_opt_container_t *cont,
|
|||||||
|
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_cell_options_t *get_cell_opt_and_create_if_not_exists(fort_cell_opt_container_t *cont, size_t row, size_t col)
|
fort_cell_props_t *get_cell_prop_and_create_if_not_exists(fort_cell_prop_container_t *cont, size_t row, size_t col)
|
||||||
{
|
{
|
||||||
assert(cont);
|
assert(cont);
|
||||||
size_t sz = vector_size(cont);
|
size_t sz = vector_size(cont);
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (i = 0; i < sz; ++i) {
|
for (i = 0; i < sz; ++i) {
|
||||||
fort_cell_options_t *opt = (fort_cell_options_t *)vector_at(cont, i);
|
fort_cell_props_t *opt = (fort_cell_props_t *)vector_at(cont, i);
|
||||||
if (opt->cell_row == row && opt->cell_col == col)
|
if (opt->cell_row == row && opt->cell_col == col)
|
||||||
return opt;
|
return opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fort_cell_options_t opt = g_default_cell_option;// DEFAULT_CELL_OPTION;
|
fort_cell_props_t opt;
|
||||||
fort_cell_options_t opt;
|
|
||||||
if (row == FT_ANY_ROW && col == FT_ANY_COLUMN)
|
if (row == FT_ANY_ROW && col == FT_ANY_COLUMN)
|
||||||
memcpy(&opt, &g_default_cell_option, sizeof(fort_cell_options_t));
|
memcpy(&opt, &g_default_cell_properties, sizeof(fort_cell_props_t));
|
||||||
else
|
else
|
||||||
memset(&opt, 0, sizeof(fort_cell_options_t));
|
memset(&opt, 0, sizeof(fort_cell_props_t));
|
||||||
|
|
||||||
opt.cell_row = row;
|
opt.cell_row = row;
|
||||||
opt.cell_col = col;
|
opt.cell_col = col;
|
||||||
if (FT_IS_SUCCESS(vector_push(cont, &opt))) {
|
if (FT_IS_SUCCESS(vector_push(cont, &opt))) {
|
||||||
return (fort_cell_options_t *)vector_at(cont, sz);
|
return (fort_cell_props_t *)vector_at(cont, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -119,15 +117,15 @@ fort_cell_options_t *get_cell_opt_and_create_if_not_exists(fort_cell_opt_contain
|
|||||||
|
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
int get_cell_opt_value_hierarcial(const fort_table_options_t *options, size_t row, size_t column, uint32_t option)
|
int get_cell_property_value_hierarcial(const fort_table_properties_t *propertiess, size_t row, size_t column, uint32_t property)
|
||||||
{
|
{
|
||||||
assert(options);
|
assert(propertiess);
|
||||||
|
|
||||||
const fort_cell_options_t *opt = NULL;
|
const fort_cell_props_t *opt = NULL;
|
||||||
if (options->cell_options != NULL) {
|
if (propertiess->cell_properties != NULL) {
|
||||||
while (1) {
|
while (1) {
|
||||||
opt = cget_cell_opt(options->cell_options, row, column);
|
opt = cget_cell_prop(propertiess->cell_properties, row, column);
|
||||||
if (opt != NULL && OPTION_IS_SET(opt->options, option))
|
if (opt != NULL && PROP_IS_SET(opt->properties, property))
|
||||||
break;
|
break;
|
||||||
if (row != FT_ANY_ROW) {
|
if (row != FT_ANY_ROW) {
|
||||||
row = FT_ANY_ROW;
|
row = FT_ANY_ROW;
|
||||||
@ -143,36 +141,36 @@ int get_cell_opt_value_hierarcial(const fort_table_options_t *options, size_t ro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return get_option_value_if_exists_otherwise_default(opt, option);
|
return get_prop_value_if_exists_otherwise_default(opt, property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static fort_status_t set_cell_option_impl(fort_cell_options_t *opt, uint32_t option, int value)
|
static fort_status_t set_cell_property_impl(fort_cell_props_t *opt, uint32_t property, int value)
|
||||||
{
|
{
|
||||||
assert(opt);
|
assert(opt);
|
||||||
|
|
||||||
OPTION_SET(opt->options, option);
|
PROP_SET(opt->properties, property);
|
||||||
if (OPTION_IS_SET(option, FT_COPT_MIN_WIDTH)) {
|
if (PROP_IS_SET(property, FT_CPROP_MIN_WIDTH)) {
|
||||||
CHECK_NOT_NEGATIVE(value);
|
CHECK_NOT_NEGATIVE(value);
|
||||||
opt->col_min_width = value;
|
opt->col_min_width = value;
|
||||||
} else if (OPTION_IS_SET(option, FT_COPT_TEXT_ALIGN)) {
|
} else if (PROP_IS_SET(property, FT_CPROP_TEXT_ALIGN)) {
|
||||||
opt->align = (enum ft_text_alignment)value;
|
opt->align = (enum ft_text_alignment)value;
|
||||||
} else if (OPTION_IS_SET(option, FT_COPT_TOP_PADDING)) {
|
} else if (PROP_IS_SET(property, FT_CPROP_TOP_PADDING)) {
|
||||||
CHECK_NOT_NEGATIVE(value);
|
CHECK_NOT_NEGATIVE(value);
|
||||||
opt->cell_padding_top = value;
|
opt->cell_padding_top = value;
|
||||||
} else if (OPTION_IS_SET(option, FT_COPT_BOTTOM_PADDING)) {
|
} else if (PROP_IS_SET(property, FT_CPROP_BOTTOM_PADDING)) {
|
||||||
CHECK_NOT_NEGATIVE(value);
|
CHECK_NOT_NEGATIVE(value);
|
||||||
opt->cell_padding_bottom = value;
|
opt->cell_padding_bottom = value;
|
||||||
} else if (OPTION_IS_SET(option, FT_COPT_LEFT_PADDING)) {
|
} else if (PROP_IS_SET(property, FT_CPROP_LEFT_PADDING)) {
|
||||||
CHECK_NOT_NEGATIVE(value);
|
CHECK_NOT_NEGATIVE(value);
|
||||||
opt->cell_padding_left = value;
|
opt->cell_padding_left = value;
|
||||||
} else if (OPTION_IS_SET(option, FT_COPT_RIGHT_PADDING)) {
|
} else if (PROP_IS_SET(property, FT_CPROP_RIGHT_PADDING)) {
|
||||||
CHECK_NOT_NEGATIVE(value);
|
CHECK_NOT_NEGATIVE(value);
|
||||||
opt->cell_padding_right = value;
|
opt->cell_padding_right = value;
|
||||||
} else if (OPTION_IS_SET(option, FT_COPT_EMPTY_STR_HEIGHT)) {
|
} else if (PROP_IS_SET(property, FT_CPROP_EMPTY_STR_HEIGHT)) {
|
||||||
CHECK_NOT_NEGATIVE(value);
|
CHECK_NOT_NEGATIVE(value);
|
||||||
opt->cell_empty_string_height = value;
|
opt->cell_empty_string_height = value;
|
||||||
} else if (OPTION_IS_SET(option, FT_COPT_ROW_TYPE)) {
|
} else if (PROP_IS_SET(property, FT_CPROP_ROW_TYPE)) {
|
||||||
opt->row_type = (enum ft_row_type)value;
|
opt->row_type = (enum ft_row_type)value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,18 +182,18 @@ fort_fail:
|
|||||||
|
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_status_t set_cell_option(fort_cell_opt_container_t *cont, size_t row, size_t col, uint32_t option, int value)
|
fort_status_t set_cell_property(fort_cell_prop_container_t *cont, size_t row, size_t col, uint32_t property, int value)
|
||||||
{
|
{
|
||||||
fort_cell_options_t *opt = get_cell_opt_and_create_if_not_exists(cont, row, col);
|
fort_cell_props_t *opt = get_cell_prop_and_create_if_not_exists(cont, row, col);
|
||||||
if (opt == NULL)
|
if (opt == NULL)
|
||||||
return FT_ERROR;
|
return FT_ERROR;
|
||||||
|
|
||||||
return set_cell_option_impl(opt, option, value);
|
return set_cell_property_impl(opt, property, value);
|
||||||
/*
|
/*
|
||||||
OPTION_SET(opt->options, option);
|
PROP_SET(opt->propertiess, property);
|
||||||
if (OPTION_IS_SET(option, FT_COPT_MIN_WIDTH)) {
|
if (PROP_IS_SET(property, FT_CPROP_MIN_WIDTH)) {
|
||||||
opt->col_min_width = value;
|
opt->col_min_width = value;
|
||||||
} else if (OPTION_IS_SET(option, FT_COPT_TEXT_ALIGN)) {
|
} else if (PROP_IS_SET(property, FT_CPROP_TEXT_ALIGN)) {
|
||||||
opt->align = value;
|
opt->align = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,13 +203,13 @@ fort_status_t set_cell_option(fort_cell_opt_container_t *cont, size_t row, size_
|
|||||||
|
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_status_t set_default_cell_option(uint32_t option, int value)
|
fort_status_t set_default_cell_property(uint32_t property, int value)
|
||||||
{
|
{
|
||||||
return set_cell_option_impl(&g_default_cell_option, option, value);
|
return set_cell_property_impl(&g_default_cell_properties, property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* OPTIONS
|
* PROPERTIESS
|
||||||
* ***************************************************************************/
|
* ***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
@ -535,25 +533,25 @@ struct fort_border_style FORT_FRAME_STYLE = FRAME_STYLE;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
fort_entire_table_options_t g_entire_table_options = {
|
fort_entire_table_properties_t g_entire_table_properties = {
|
||||||
0, /* left_margin */
|
0, /* left_margin */
|
||||||
0, /* top_margin */
|
0, /* top_margin */
|
||||||
0, /* right_margin */
|
0, /* right_margin */
|
||||||
0, /* bottom_margin */
|
0, /* bottom_margin */
|
||||||
};
|
};
|
||||||
|
|
||||||
static fort_status_t set_entire_table_option_internal(fort_entire_table_options_t *options, uint32_t option, int value)
|
static fort_status_t set_entire_table_property_internal(fort_entire_table_properties_t *properties, uint32_t property, int value)
|
||||||
{
|
{
|
||||||
assert(options);
|
assert(properties);
|
||||||
CHECK_NOT_NEGATIVE(value);
|
CHECK_NOT_NEGATIVE(value);
|
||||||
if (OPTION_IS_SET(option, FT_TOPT_LEFT_MARGIN)) {
|
if (PROP_IS_SET(property, FT_TPROP_LEFT_MARGIN)) {
|
||||||
options->left_margin = value;
|
properties->left_margin = value;
|
||||||
} else if (OPTION_IS_SET(option, FT_TOPT_TOP_MARGIN)) {
|
} else if (PROP_IS_SET(property, FT_TPROP_TOP_MARGIN)) {
|
||||||
options->top_margin = value;
|
properties->top_margin = value;
|
||||||
} else if (OPTION_IS_SET(option, FT_TOPT_RIGHT_MARGIN)) {
|
} else if (PROP_IS_SET(property, FT_TPROP_RIGHT_MARGIN)) {
|
||||||
options->right_margin = value;
|
properties->right_margin = value;
|
||||||
} else if (OPTION_IS_SET(option, FT_TOPT_BOTTOM_MARGIN)) {
|
} else if (PROP_IS_SET(property, FT_TPROP_BOTTOM_MARGIN)) {
|
||||||
options->bottom_margin = value;
|
properties->bottom_margin = value;
|
||||||
} else {
|
} else {
|
||||||
return FT_EINVAL;
|
return FT_EINVAL;
|
||||||
}
|
}
|
||||||
@ -565,48 +563,48 @@ fort_fail:
|
|||||||
|
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_status_t set_entire_table_option(fort_table_options_t *table_options, uint32_t option, int value)
|
fort_status_t set_entire_table_property(fort_table_properties_t *table_properties, uint32_t property, int value)
|
||||||
{
|
{
|
||||||
assert(table_options);
|
assert(table_properties);
|
||||||
return set_entire_table_option_internal(&table_options->entire_table_options, option, value);
|
return set_entire_table_property_internal(&table_properties->entire_table_properties, property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_status_t set_default_entire_table_option(uint32_t option, int value)
|
fort_status_t set_default_entire_table_property(uint32_t property, int value)
|
||||||
{
|
{
|
||||||
return set_entire_table_option_internal(&g_entire_table_options, option, value);
|
return set_entire_table_property_internal(&g_entire_table_properties, property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
size_t max_border_elem_strlen(struct fort_table_options *options)
|
size_t max_border_elem_strlen(struct fort_table_properties *properties)
|
||||||
{
|
{
|
||||||
assert(options);
|
assert(properties);
|
||||||
size_t result = 1;
|
size_t result = 1;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < BorderItemPosSize; ++i) {
|
for (i = 0; i < BorderItemPosSize; ++i) {
|
||||||
result = MAX(result, strlen(options->border_style.border_chars[i]));
|
result = MAX(result, strlen(properties->border_style.border_chars[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (i = 0; i < BorderItemPosSize; ++i) {
|
for (i = 0; i < BorderItemPosSize; ++i) {
|
||||||
result = MAX(result, strlen(options->border_style.header_border_chars[i]));
|
result = MAX(result, strlen(properties->border_style.header_border_chars[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (i = 0; i < SepratorItemPosSize; ++i) {
|
for (i = 0; i < SepratorItemPosSize; ++i) {
|
||||||
result = MAX(result, strlen(options->border_style.separator_chars[i]));
|
result = MAX(result, strlen(properties->border_style.separator_chars[i]));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fort_table_options_t g_table_options = {
|
fort_table_properties_t g_table_properties = {
|
||||||
/* border_style */
|
/* border_style */
|
||||||
BASIC_STYLE,
|
BASIC_STYLE,
|
||||||
NULL, /* cell_options */
|
NULL, /* cell_properties */
|
||||||
/* entire_table_options */
|
/* entire_table_properties */
|
||||||
{
|
{
|
||||||
0, /* left_margin */
|
0, /* left_margin */
|
||||||
0, /* top_margin */
|
0, /* top_margin */
|
||||||
@ -617,46 +615,46 @@ fort_table_options_t g_table_options = {
|
|||||||
|
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_table_options_t *create_table_options(void)
|
fort_table_properties_t *create_table_properties(void)
|
||||||
{
|
{
|
||||||
fort_table_options_t *options = (fort_table_options_t *)F_CALLOC(sizeof(fort_table_options_t), 1);
|
fort_table_properties_t *properties = (fort_table_properties_t *)F_CALLOC(sizeof(fort_table_properties_t), 1);
|
||||||
if (options == NULL) {
|
if (properties == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy(options, &g_table_options, sizeof(fort_table_options_t));
|
memcpy(properties, &g_table_properties, sizeof(fort_table_properties_t));
|
||||||
options->cell_options = create_cell_opt_container();
|
properties->cell_properties = create_cell_prop_container();
|
||||||
if (options->cell_options == NULL) {
|
if (properties->cell_properties == NULL) {
|
||||||
destroy_table_options(options);
|
destroy_table_properties(properties);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy(&options->entire_table_options, &g_entire_table_options, sizeof(fort_entire_table_options_t));
|
memcpy(&properties->entire_table_properties, &g_entire_table_properties, sizeof(fort_entire_table_properties_t));
|
||||||
return options;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
void destroy_table_options(fort_table_options_t *options)
|
void destroy_table_properties(fort_table_properties_t *properties)
|
||||||
{
|
{
|
||||||
if (options == NULL)
|
if (properties == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (options->cell_options != NULL) {
|
if (properties->cell_properties != NULL) {
|
||||||
destroy_cell_opt_container(options->cell_options);
|
destroy_cell_prop_container(properties->cell_properties);
|
||||||
}
|
}
|
||||||
F_FREE(options);
|
F_FREE(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
fort_cell_opt_container_t *copy_cell_options(fort_cell_opt_container_t *cont)
|
fort_cell_prop_container_t *copy_cell_properties(fort_cell_prop_container_t *cont)
|
||||||
{
|
{
|
||||||
fort_cell_opt_container_t *result = create_cell_opt_container();
|
fort_cell_prop_container_t *result = create_cell_prop_container();
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
size_t sz = vector_size(cont);
|
size_t sz = vector_size(cont);
|
||||||
for (size_t i = 0; i < sz; ++i) {
|
for (size_t i = 0; i < sz; ++i) {
|
||||||
fort_cell_options_t *opt = (fort_cell_options_t *)vector_at(cont, i);
|
fort_cell_props_t *opt = (fort_cell_props_t *)vector_at(cont, i);
|
||||||
if (FT_IS_ERROR(vector_push(result, opt))) {
|
if (FT_IS_ERROR(vector_push(result, opt))) {
|
||||||
destroy_cell_opt_container(result);
|
destroy_cell_prop_container(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -664,22 +662,22 @@ fort_cell_opt_container_t *copy_cell_options(fort_cell_opt_container_t *cont)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_table_options_t *copy_table_options(const fort_table_options_t *option)
|
fort_table_properties_t *copy_table_properties(const fort_table_properties_t *properties)
|
||||||
{
|
{
|
||||||
fort_table_options_t *new_opt = create_table_options();
|
fort_table_properties_t *new_opt = create_table_properties();
|
||||||
if (new_opt == NULL)
|
if (new_opt == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
destroy_vector(new_opt->cell_options);
|
destroy_vector(new_opt->cell_properties);
|
||||||
new_opt->cell_options = copy_cell_options(option->cell_options);
|
new_opt->cell_properties = copy_cell_properties(properties->cell_properties);
|
||||||
if (new_opt == NULL) {
|
if (new_opt == NULL) {
|
||||||
destroy_table_options(new_opt);
|
destroy_table_properties(new_opt);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&new_opt->border_style, &option->border_style, sizeof(struct fort_border_style));
|
memcpy(&new_opt->border_style, &properties->border_style, sizeof(struct fort_border_style));
|
||||||
memcpy(&new_opt->entire_table_options,
|
memcpy(&new_opt->entire_table_properties,
|
||||||
&option->entire_table_options, sizeof(fort_entire_table_options_t));
|
&properties->entire_table_properties, sizeof(fort_entire_table_properties_t));
|
||||||
|
|
||||||
return new_opt;
|
return new_opt;
|
||||||
}
|
}
|
@ -1,18 +1,18 @@
|
|||||||
#ifndef OPTIONS_H
|
#ifndef PROPERTIES_H
|
||||||
#define OPTIONS_H
|
#define PROPERTIES_H
|
||||||
|
|
||||||
#include "fort_utils.h"
|
#include "fort_utils.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#define OPTION_IS_SET(ft_opts, option) ((ft_opts) & (option))
|
#define PROP_IS_SET(ft_props, property) ((ft_props) & (property))
|
||||||
#define OPTION_SET(ft_opts, option) ((ft_opts) |=(option))
|
#define PROP_SET(ft_props, property) ((ft_props) |=(property))
|
||||||
#define OPTION_UNSET(ft_opts, option) ((ft_opts) &= ~((uint32_t)option))
|
#define PROP_UNSET(ft_props, property) ((ft_props) &= ~((uint32_t)property))
|
||||||
|
|
||||||
struct fort_cell_options {
|
struct fort_cell_props {
|
||||||
size_t cell_row;
|
size_t cell_row;
|
||||||
size_t cell_col;
|
size_t cell_col;
|
||||||
uint32_t options;
|
uint32_t properties;
|
||||||
unsigned int col_min_width;
|
unsigned int col_min_width;
|
||||||
enum ft_text_alignment align;
|
enum ft_text_alignment align;
|
||||||
unsigned int cell_padding_top;
|
unsigned int cell_padding_top;
|
||||||
@ -23,29 +23,29 @@ struct fort_cell_options {
|
|||||||
enum ft_row_type row_type;
|
enum ft_row_type row_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct fort_cell_options fort_cell_options_t;
|
typedef struct fort_cell_props fort_cell_props_t;
|
||||||
typedef vector_t fort_cell_opt_container_t;
|
typedef vector_t fort_cell_prop_container_t;
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_cell_opt_container_t *create_cell_opt_container(void);
|
fort_cell_prop_container_t *create_cell_prop_container(void);
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
void destroy_cell_opt_container(fort_cell_opt_container_t *cont);
|
void destroy_cell_prop_container(fort_cell_prop_container_t *cont);
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
const fort_cell_options_t *cget_cell_opt(const fort_cell_opt_container_t *cont, size_t row, size_t col);
|
const fort_cell_props_t *cget_cell_prop(const fort_cell_prop_container_t *cont, size_t row, size_t col);
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_cell_options_t *get_cell_opt_and_create_if_not_exists(fort_cell_opt_container_t *cont, size_t row, size_t col);
|
fort_cell_props_t *get_cell_prop_and_create_if_not_exists(fort_cell_prop_container_t *cont, size_t row, size_t col);
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_status_t set_cell_option(fort_cell_opt_container_t *cont, size_t row, size_t col, uint32_t option, int value);
|
fort_status_t set_cell_property(fort_cell_prop_container_t *cont, size_t row, size_t col, uint32_t property, int value);
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
int get_cell_opt_value_hierarcial(const fort_table_options_t *options, size_t row, size_t column, uint32_t option);
|
int get_cell_property_value_hierarcial(const fort_table_properties_t *properties, size_t row, size_t column, uint32_t property);
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_status_t set_default_cell_option(uint32_t option, int value);
|
fort_status_t set_default_cell_property(uint32_t property, int value);
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* TABLE BORDER
|
* TABLE BORDER
|
||||||
@ -142,38 +142,38 @@ extern struct fort_border_style FORT_BOLD2_STYLE;
|
|||||||
extern struct fort_border_style FORT_FRAME_STYLE;
|
extern struct fort_border_style FORT_FRAME_STYLE;
|
||||||
|
|
||||||
|
|
||||||
struct fort_entire_table_options {
|
struct fort_entire_table_properties {
|
||||||
unsigned int left_margin;
|
unsigned int left_margin;
|
||||||
unsigned int top_margin;
|
unsigned int top_margin;
|
||||||
unsigned int right_margin;
|
unsigned int right_margin;
|
||||||
unsigned int bottom_margin;
|
unsigned int bottom_margin;
|
||||||
};
|
};
|
||||||
typedef struct fort_entire_table_options fort_entire_table_options_t;
|
typedef struct fort_entire_table_properties fort_entire_table_properties_t;
|
||||||
extern fort_entire_table_options_t g_entire_table_options;
|
extern fort_entire_table_properties_t g_entire_table_properties;
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_status_t set_entire_table_option(fort_table_options_t *table_options, uint32_t option, int value);
|
fort_status_t set_entire_table_property(fort_table_properties_t *table_properties, uint32_t property, int value);
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_status_t set_default_entire_table_option(uint32_t option, int value);
|
fort_status_t set_default_entire_table_property(uint32_t property, int value);
|
||||||
|
|
||||||
struct fort_table_options {
|
struct fort_table_properties {
|
||||||
struct fort_border_style border_style;
|
struct fort_border_style border_style;
|
||||||
fort_cell_opt_container_t *cell_options;
|
fort_cell_prop_container_t *cell_properties;
|
||||||
fort_entire_table_options_t entire_table_options;
|
fort_entire_table_properties_t entire_table_properties;
|
||||||
};
|
};
|
||||||
extern fort_table_options_t g_table_options;
|
extern fort_table_properties_t g_table_properties;
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
size_t max_border_elem_strlen(struct fort_table_options *);
|
size_t max_border_elem_strlen(struct fort_table_properties *);
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_table_options_t *create_table_options(void);
|
fort_table_properties_t *create_table_properties(void);
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
void destroy_table_options(fort_table_options_t *options);
|
void destroy_table_properties(fort_table_properties_t *properties);
|
||||||
|
|
||||||
FT_INTERNAL
|
FT_INTERNAL
|
||||||
fort_table_options_t *copy_table_options(const fort_table_options_t *option);
|
fort_table_properties_t *copy_table_properties(const fort_table_properties_t *property);
|
||||||
|
|
||||||
#endif /* OPTIONS_H */
|
#endif /* PROPERTIES_H */
|
72
src/row.c
72
src/row.c
@ -271,11 +271,11 @@ int print_row_separator(char *buffer, size_t buffer_sz,
|
|||||||
|
|
||||||
enum ft_row_type lower_row_type = FT_ROW_COMMON;
|
enum ft_row_type lower_row_type = FT_ROW_COMMON;
|
||||||
if (lower_row != NULL) {
|
if (lower_row != NULL) {
|
||||||
lower_row_type = (enum ft_row_type)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
lower_row_type = (enum ft_row_type)get_cell_property_value_hierarcial(context->table_properties, context->row, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE);
|
||||||
}
|
}
|
||||||
enum ft_row_type upper_row_type = FT_ROW_COMMON;
|
enum ft_row_type upper_row_type = FT_ROW_COMMON;
|
||||||
if (upper_row != NULL) {
|
if (upper_row != NULL) {
|
||||||
upper_row_type = (enum ft_row_type)get_cell_opt_value_hierarcial(context->table_options, context->row - 1, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
upper_row_type = (enum ft_row_type)get_cell_property_value_hierarcial(context->table_properties, context->row - 1, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Row separator anatomy
|
/* Row separator anatomy
|
||||||
@ -295,20 +295,20 @@ int print_row_separator(char *buffer, size_t buffer_sz,
|
|||||||
|
|
||||||
typedef const char *(*border_chars_point_t)[BorderItemPosSize];
|
typedef const char *(*border_chars_point_t)[BorderItemPosSize];
|
||||||
const char *(*border_chars)[BorderItemPosSize] = NULL;
|
const char *(*border_chars)[BorderItemPosSize] = NULL;
|
||||||
border_chars = (border_chars_point_t)&context->table_options->border_style.border_chars;
|
border_chars = (border_chars_point_t)&context->table_properties->border_style.border_chars;
|
||||||
if (upper_row_type == FT_ROW_HEADER || lower_row_type == FT_ROW_HEADER) {
|
if (upper_row_type == FT_ROW_HEADER || lower_row_type == FT_ROW_HEADER) {
|
||||||
border_chars = (border_chars_point_t)&context->table_options->border_style.header_border_chars;
|
border_chars = (border_chars_point_t)&context->table_properties->border_style.header_border_chars;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sep && sep->enabled) {
|
if (sep && sep->enabled) {
|
||||||
L = &(context->table_options->border_style.separator_chars[LH_sip]);
|
L = &(context->table_properties->border_style.separator_chars[LH_sip]);
|
||||||
I = &(context->table_options->border_style.separator_chars[IH_sip]);
|
I = &(context->table_properties->border_style.separator_chars[IH_sip]);
|
||||||
IV = &(context->table_options->border_style.separator_chars[II_sip]);
|
IV = &(context->table_properties->border_style.separator_chars[II_sip]);
|
||||||
R = &(context->table_options->border_style.separator_chars[RH_sip]);
|
R = &(context->table_properties->border_style.separator_chars[RH_sip]);
|
||||||
|
|
||||||
IT = &(context->table_options->border_style.separator_chars[II_sip]);
|
IT = &(context->table_properties->border_style.separator_chars[II_sip]);
|
||||||
IB = &(context->table_options->border_style.separator_chars[II_sip]);
|
IB = &(context->table_properties->border_style.separator_chars[II_sip]);
|
||||||
II = &(context->table_options->border_style.separator_chars[IH_sip]);
|
II = &(context->table_properties->border_style.separator_chars[IH_sip]);
|
||||||
} else {
|
} else {
|
||||||
switch (separatorPos) {
|
switch (separatorPos) {
|
||||||
case TopSeparator:
|
case TopSeparator:
|
||||||
@ -364,7 +364,7 @@ int print_row_separator(char *buffer, size_t buffer_sz,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Print left margin */
|
/* Print left margin */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.left_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_properties->entire_table_properties.left_margin, space_char));
|
||||||
|
|
||||||
for (i = 0; i < cols; ++i) {
|
for (i = 0; i < cols; ++i) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
@ -386,7 +386,7 @@ int print_row_separator(char *buffer, size_t buffer_sz,
|
|||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, 1, *R));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, 1, *R));
|
||||||
|
|
||||||
/* Print right margin */
|
/* Print right margin */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.right_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_properties->entire_table_properties.right_margin, space_char));
|
||||||
|
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, 1, "\n"));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, 1, "\n"));
|
||||||
|
|
||||||
@ -446,11 +446,11 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz,
|
|||||||
|
|
||||||
enum ft_row_type lower_row_type = FT_ROW_COMMON;
|
enum ft_row_type lower_row_type = FT_ROW_COMMON;
|
||||||
if (lower_row != NULL) {
|
if (lower_row != NULL) {
|
||||||
lower_row_type = (enum ft_row_type)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
lower_row_type = (enum ft_row_type)get_cell_property_value_hierarcial(context->table_properties, context->row, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE);
|
||||||
}
|
}
|
||||||
enum ft_row_type upper_row_type = FT_ROW_COMMON;
|
enum ft_row_type upper_row_type = FT_ROW_COMMON;
|
||||||
if (upper_row != NULL) {
|
if (upper_row != NULL) {
|
||||||
upper_row_type = (enum ft_row_type)get_cell_opt_value_hierarcial(context->table_options, context->row - 1, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
upper_row_type = (enum ft_row_type)get_cell_property_value_hierarcial(context->table_properties, context->row - 1, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Row separator anatomy
|
/* Row separator anatomy
|
||||||
@ -470,20 +470,20 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz,
|
|||||||
|
|
||||||
typedef const char *(*border_chars_point_t)[BorderItemPosSize];
|
typedef const char *(*border_chars_point_t)[BorderItemPosSize];
|
||||||
const char *(*border_chars)[BorderItemPosSize] = NULL;
|
const char *(*border_chars)[BorderItemPosSize] = NULL;
|
||||||
border_chars = (border_chars_point_t)&context->table_options->border_style.border_chars;
|
border_chars = (border_chars_point_t)&context->table_properties->border_style.border_chars;
|
||||||
if (upper_row_type == FT_ROW_HEADER || lower_row_type == FT_ROW_HEADER) {
|
if (upper_row_type == FT_ROW_HEADER || lower_row_type == FT_ROW_HEADER) {
|
||||||
border_chars = (border_chars_point_t)&context->table_options->border_style.header_border_chars;
|
border_chars = (border_chars_point_t)&context->table_properties->border_style.header_border_chars;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sep && sep->enabled) {
|
if (sep && sep->enabled) {
|
||||||
L = &(context->table_options->border_style.separator_chars[LH_sip]);
|
L = &(context->table_properties->border_style.separator_chars[LH_sip]);
|
||||||
I = &(context->table_options->border_style.separator_chars[IH_sip]);
|
I = &(context->table_properties->border_style.separator_chars[IH_sip]);
|
||||||
IV = &(context->table_options->border_style.separator_chars[II_sip]);
|
IV = &(context->table_properties->border_style.separator_chars[II_sip]);
|
||||||
R = &(context->table_options->border_style.separator_chars[RH_sip]);
|
R = &(context->table_properties->border_style.separator_chars[RH_sip]);
|
||||||
|
|
||||||
IT = &(context->table_options->border_style.separator_chars[II_sip]);
|
IT = &(context->table_properties->border_style.separator_chars[II_sip]);
|
||||||
IB = &(context->table_options->border_style.separator_chars[II_sip]);
|
IB = &(context->table_properties->border_style.separator_chars[II_sip]);
|
||||||
II = &(context->table_options->border_style.separator_chars[IH_sip]);
|
II = &(context->table_properties->border_style.separator_chars[IH_sip]);
|
||||||
} else {
|
} else {
|
||||||
switch (separatorPos) {
|
switch (separatorPos) {
|
||||||
case TopSeparator:
|
case TopSeparator:
|
||||||
@ -539,7 +539,7 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Print left margin */
|
/* Print left margin */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.left_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_properties->entire_table_properties.left_margin, space_char));
|
||||||
|
|
||||||
for (i = 0; i < cols; ++i) {
|
for (i = 0; i < cols; ++i) {
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
@ -561,7 +561,7 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz,
|
|||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, 1, *R));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, 1, *R));
|
||||||
|
|
||||||
/* Print right margin */
|
/* Print right margin */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_options->entire_table_options.right_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, context->table_properties->entire_table_properties.right_margin, space_char));
|
||||||
|
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, 1, "\n"));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buffer_sz - written, 1, "\n"));
|
||||||
|
|
||||||
@ -945,10 +945,10 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
typedef const char *(*border_chars_point_t)[BorderItemPosSize];
|
typedef const char *(*border_chars_point_t)[BorderItemPosSize];
|
||||||
enum ft_row_type row_type = (enum ft_row_type)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
enum ft_row_type row_type = (enum ft_row_type)get_cell_property_value_hierarcial(context->table_properties, context->row, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE);
|
||||||
const char *(*bord_chars)[BorderItemPosSize] = (row_type == FT_ROW_HEADER)
|
const char *(*bord_chars)[BorderItemPosSize] = (row_type == FT_ROW_HEADER)
|
||||||
? (border_chars_point_t)(&context->table_options->border_style.header_border_chars)
|
? (border_chars_point_t)(&context->table_properties->border_style.header_border_chars)
|
||||||
: (border_chars_point_t)(&context->table_options->border_style.border_chars);
|
: (border_chars_point_t)(&context->table_properties->border_style.border_chars);
|
||||||
const char **L = &(*bord_chars)[LL_bip];
|
const char **L = &(*bord_chars)[LL_bip];
|
||||||
const char **IV = &(*bord_chars)[IV_bip];
|
const char **IV = &(*bord_chars)[IV_bip];
|
||||||
const char **R = &(*bord_chars)[RR_bip];
|
const char **R = &(*bord_chars)[RR_bip];
|
||||||
@ -959,7 +959,7 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col
|
|||||||
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 */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, context->table_options->entire_table_options.left_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, context->table_properties->entire_table_properties.left_margin, space_char));
|
||||||
|
|
||||||
/* Print left table boundary */
|
/* Print left table boundary */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, *L));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, *L));
|
||||||
@ -996,7 +996,7 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col
|
|||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, *R));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, *R));
|
||||||
|
|
||||||
/* Print right margin */
|
/* Print right margin */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, context->table_options->entire_table_options.right_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, context->table_properties->entire_table_properties.right_margin, space_char));
|
||||||
|
|
||||||
/* Print new line character */
|
/* Print new line character */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, new_line_char));
|
||||||
@ -1035,10 +1035,10 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
typedef const char *(*border_chars_point_t)[BorderItemPosSize];
|
typedef const char *(*border_chars_point_t)[BorderItemPosSize];
|
||||||
enum ft_row_type row_type = (enum ft_row_type)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
enum ft_row_type row_type = (enum ft_row_type)get_cell_property_value_hierarcial(context->table_properties, context->row, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE);
|
||||||
const char *(*bord_chars)[BorderItemPosSize] = (row_type == FT_ROW_HEADER)
|
const char *(*bord_chars)[BorderItemPosSize] = (row_type == FT_ROW_HEADER)
|
||||||
? (border_chars_point_t)(&context->table_options->border_style.header_border_chars)
|
? (border_chars_point_t)(&context->table_properties->border_style.header_border_chars)
|
||||||
: (border_chars_point_t)(&context->table_options->border_style.border_chars);
|
: (border_chars_point_t)(&context->table_properties->border_style.border_chars);
|
||||||
const char **L = &(*bord_chars)[LL_bip];
|
const char **L = &(*bord_chars)[LL_bip];
|
||||||
const char **IV = &(*bord_chars)[IV_bip];
|
const char **IV = &(*bord_chars)[IV_bip];
|
||||||
const char **R = &(*bord_chars)[RR_bip];
|
const char **R = &(*bord_chars)[RR_bip];
|
||||||
@ -1049,7 +1049,7 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t
|
|||||||
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 */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, context->table_options->entire_table_options.left_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, context->table_properties->entire_table_properties.left_margin, space_char));
|
||||||
|
|
||||||
/* Print left table boundary */
|
/* Print left table boundary */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, *L));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, *L));
|
||||||
@ -1086,7 +1086,7 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t
|
|||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, *R));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, *R));
|
||||||
|
|
||||||
/* Print right margin */
|
/* Print right margin */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, context->table_options->entire_table_options.right_margin, space_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, context->table_properties->entire_table_properties.right_margin, space_char));
|
||||||
|
|
||||||
/* Print new line character */
|
/* Print new line character */
|
||||||
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, new_line_char));
|
CHCK_RSLT_ADD_TO_WRITTEN(snprint_n_strings_(buffer + written, buf_sz - written, 1, new_line_char));
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "fort_utils.h"
|
#include "fort_utils.h"
|
||||||
#include "fort.h"
|
#include "fort.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "options.h"
|
#include "properties.h"
|
||||||
#ifdef FT_HAVE_WCHAR
|
#ifdef FT_HAVE_WCHAR
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include "string_buffer.h"
|
#include "string_buffer.h"
|
||||||
#include "options.h"
|
#include "properties.h"
|
||||||
#include "wcwidth.h"
|
#include "wcwidth.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@ -363,7 +363,7 @@ int buffer_printf(string_buffer_t *buffer, size_t buffer_row, char *buf, size_t
|
|||||||
size_t left = 0;
|
size_t left = 0;
|
||||||
size_t right = 0;
|
size_t right = 0;
|
||||||
|
|
||||||
switch (get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TEXT_ALIGN)) {
|
switch (get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_TEXT_ALIGN)) {
|
||||||
case FT_ALIGNED_LEFT:
|
case FT_ALIGNED_LEFT:
|
||||||
left = 0;
|
left = 0;
|
||||||
right = (buf_len - 1) - content_width;
|
right = (buf_len - 1) - content_width;
|
||||||
@ -451,7 +451,7 @@ int buffer_wprintf(string_buffer_t *buffer, size_t buffer_row, wchar_t *buf, siz
|
|||||||
size_t left = 0;
|
size_t left = 0;
|
||||||
size_t right = 0;
|
size_t right = 0;
|
||||||
|
|
||||||
switch (get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TEXT_ALIGN)) {
|
switch (get_cell_property_value_hierarcial(context->table_properties, context->row, context->column, FT_CPROP_TEXT_ALIGN)) {
|
||||||
case FT_ALIGNED_LEFT:
|
case FT_ALIGNED_LEFT:
|
||||||
left = 0;
|
left = 0;
|
||||||
right = (buf_len - 1) - content_width;
|
right = (buf_len - 1) - content_width;
|
||||||
|
20
src/table.c
20
src/table.c
@ -146,7 +146,7 @@ fort_status_t table_rows_and_cols_geometry(const ft_table_t *table,
|
|||||||
|
|
||||||
int combined_cells_found = 0;
|
int combined_cells_found = 0;
|
||||||
context_t context;
|
context_t context;
|
||||||
context.table_options = (table->options ? table->options : &g_table_options);
|
context.table_properties = (table->properties ? table->properties : &g_table_properties);
|
||||||
size_t col = 0;
|
size_t col = 0;
|
||||||
for (col = 0; col < cols; ++col) {
|
for (col = 0; col < cols; ++col) {
|
||||||
col_width_arr[col] = 0;
|
col_width_arr[col] = 0;
|
||||||
@ -212,9 +212,9 @@ fort_status_t table_rows_and_cols_geometry(const ft_table_t *table,
|
|||||||
* paddings but be min width of the cell content without padding
|
* paddings but be min width of the cell content without padding
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
if (table->options) {
|
if (table->properties) {
|
||||||
for (size_t i = 0; i < cols; ++i) {
|
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[i] = MAX((int)col_width_arr[i], fort_props_column_width(table->properties, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
@ -261,16 +261,16 @@ fort_status_t table_geometry(const ft_table_t *table, size_t *height, size_t *wi
|
|||||||
F_FREE(col_width_arr);
|
F_FREE(col_width_arr);
|
||||||
F_FREE(row_height_arr);
|
F_FREE(row_height_arr);
|
||||||
|
|
||||||
if (table->options) {
|
if (table->properties) {
|
||||||
*height += table->options->entire_table_options.top_margin;
|
*height += table->properties->entire_table_properties.top_margin;
|
||||||
*height += table->options->entire_table_options.bottom_margin;
|
*height += table->properties->entire_table_properties.bottom_margin;
|
||||||
*width += table->options->entire_table_options.left_margin;
|
*width += table->properties->entire_table_properties.left_margin;
|
||||||
*width += table->options->entire_table_options.right_margin;
|
*width += table->properties->entire_table_properties.right_margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Take into account that border elements can be more than one byte long */
|
/* Take into account that border elements can be more than one byte long */
|
||||||
fort_table_options_t *table_options = table->options ? table->options : &g_table_options;
|
fort_table_properties_t *table_properties = table->properties ? table->properties : &g_table_properties;
|
||||||
size_t max_border_elem_len = max_border_elem_strlen(table_options);
|
size_t max_border_elem_len = max_border_elem_strlen(table_properties);
|
||||||
*width *= max_border_elem_len;
|
*width *= max_border_elem_len;
|
||||||
|
|
||||||
return FT_SUCCESS;
|
return FT_SUCCESS;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
struct ft_table {
|
struct ft_table {
|
||||||
vector_t *rows;
|
vector_t *rows;
|
||||||
fort_table_options_t *options;
|
fort_table_properties_t *properties;
|
||||||
string_buffer_t *conv_buffer;
|
string_buffer_t *conv_buffer;
|
||||||
size_t cur_row;
|
size_t cur_row;
|
||||||
size_t cur_col;
|
size_t cur_col;
|
||||||
|
@ -35,11 +35,11 @@ static int create_simple_table_and_show(void)
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if (set_test_options_for_table(table) != FT_SUCCESS)
|
if (set_test_props_for_table(table) != FT_SUCCESS)
|
||||||
return 2;
|
return 2;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER) != FT_SUCCESS) {
|
if (ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER) != FT_SUCCESS) {
|
||||||
result = 3;
|
result = 3;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,9 @@ void test_table_basic(void)
|
|||||||
WHEN("All columns are equal and not empty") {
|
WHEN("All columns are equal and not empty") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||||
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||||
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||||
@ -40,9 +40,9 @@ void test_table_basic(void)
|
|||||||
WHEN("All columns are equal and not empty (wide strings)") {
|
WHEN("All columns are equal and not empty (wide strings)") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||||
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||||
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||||
@ -71,9 +71,9 @@ void test_table_basic(void)
|
|||||||
WHEN("All columns are not equal and not empty") {
|
WHEN("All columns are not equal and not empty") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||||
assert_true(ft_write_ln(table, "c", "234", "3.140000", "3") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "c", "234", "3.140000", "3") == FT_SUCCESS);
|
||||||
assert_true(ft_write_ln(table, "234", "3.140000", "3", "c") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "234", "3.140000", "3", "c") == FT_SUCCESS);
|
||||||
@ -102,9 +102,9 @@ void test_table_basic(void)
|
|||||||
WHEN("All columns are not equal and not empty (wide strings)") {
|
WHEN("All columns are not equal and not empty (wide strings)") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||||
assert_true(ft_wwrite_ln(table, L"c", L"234", L"3.140000", L"3") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"c", L"234", L"3.140000", L"3") == FT_SUCCESS);
|
||||||
assert_true(ft_wwrite_ln(table, L"234", L"3.140000", L"3", L"c") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"234", L"3.140000", L"3", L"c") == FT_SUCCESS);
|
||||||
@ -133,9 +133,9 @@ void test_table_basic(void)
|
|||||||
WHEN("All columns are not equal and some cells are empty") {
|
WHEN("All columns are not equal and some cells are empty") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(ft_write_ln(table, "", "", "234", "3.140000") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "", "", "234", "3.140000") == FT_SUCCESS);
|
||||||
assert_true(ft_write_ln(table, "c", "234", "3.140000", "") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "c", "234", "3.140000", "") == FT_SUCCESS);
|
||||||
assert_true(ft_write_ln(table, "234", "3.140000", "", "") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "234", "3.140000", "", "") == FT_SUCCESS);
|
||||||
@ -164,9 +164,9 @@ void test_table_basic(void)
|
|||||||
WHEN("All columns are not equal and some cells are empty (wide strings)") {
|
WHEN("All columns are not equal and some cells are empty (wide strings)") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(ft_wwrite_ln(table, L"", L"", L"234", L"3.140000") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"", L"", L"234", L"3.140000") == FT_SUCCESS);
|
||||||
assert_true(ft_wwrite_ln(table, L"c", L"234", L"3.140000", L"") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"c", L"234", L"3.140000", L"") == FT_SUCCESS);
|
||||||
assert_true(ft_wwrite_ln(table, L"234", L"3.140000", L"", L"") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"234", L"3.140000", L"", L"") == FT_SUCCESS);
|
||||||
@ -195,9 +195,9 @@ void test_table_basic(void)
|
|||||||
WHEN("All cells are empty") {
|
WHEN("All cells are empty") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(ft_write_ln(table, "", "", "", "") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "", "", "", "") == FT_SUCCESS);
|
||||||
assert_true(ft_write_ln(table, "", "", "", "") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "", "", "", "") == FT_SUCCESS);
|
||||||
assert_true(ft_write_ln(table, "", "", "", "") == FT_SUCCESS);
|
assert_true(ft_write_ln(table, "", "", "", "") == FT_SUCCESS);
|
||||||
@ -226,9 +226,9 @@ void test_table_basic(void)
|
|||||||
WHEN("All cells are empty (wide strings)") {
|
WHEN("All cells are empty (wide strings)") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(ft_wwrite_ln(table, L"", L"", L"", L"") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"", L"", L"", L"") == FT_SUCCESS);
|
||||||
assert_true(ft_wwrite_ln(table, L"", L"", L"", L"") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"", L"", L"", L"") == FT_SUCCESS);
|
||||||
assert_true(ft_wwrite_ln(table, L"", L"", L"", L"") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"", L"", L"", L"") == FT_SUCCESS);
|
||||||
@ -265,9 +265,9 @@ void test_wcs_table_boundaries(void)
|
|||||||
WHEN("All columns are not equal and not empty (wide strings)") {
|
WHEN("All columns are not equal and not empty (wide strings)") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(ft_wwrite_ln(table, L"3", L"12345\x8888\x8888", L"c") == FT_SUCCESS); /* \x8888,\x8888 - occupy 2 columns each */
|
assert_true(ft_wwrite_ln(table, L"3", L"12345\x8888\x8888", L"c") == FT_SUCCESS); /* \x8888,\x8888 - occupy 2 columns each */
|
||||||
assert_true(ft_wwrite_ln(table, L"c", L"12345678\x500", L"c") == FT_SUCCESS); /* \x500 - occupies 1 column */
|
assert_true(ft_wwrite_ln(table, L"c", L"12345678\x500", L"c") == FT_SUCCESS); /* \x500 - occupies 1 column */
|
||||||
assert_true(ft_wwrite_ln(table, L"234", L"123456789", L"c") == FT_SUCCESS);
|
assert_true(ft_wwrite_ln(table, L"234", L"123456789", L"c") == FT_SUCCESS);
|
||||||
@ -302,9 +302,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test write functions") {
|
SCENARIO("Test write functions") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(FT_IS_SUCCESS(ft_write(table, "3")));
|
assert_true(FT_IS_SUCCESS(ft_write(table, "3")));
|
||||||
assert_true(FT_IS_SUCCESS(ft_write(table, "c")));
|
assert_true(FT_IS_SUCCESS(ft_write(table, "c")));
|
||||||
assert_true(FT_IS_SUCCESS(ft_write(table, "234")));
|
assert_true(FT_IS_SUCCESS(ft_write(table, "234")));
|
||||||
@ -350,9 +350,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test wwrite functions(wide strings)") {
|
SCENARIO("Test wwrite functions(wide strings)") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3")));
|
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"3")));
|
||||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"c")));
|
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"c")));
|
||||||
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"234")));
|
assert_true(FT_IS_SUCCESS(ft_wwrite(table, L"234")));
|
||||||
@ -398,9 +398,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test nwrite functions") {
|
SCENARIO("Test nwrite functions") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(ft_nwrite(table, 4, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
assert_true(ft_nwrite(table, 4, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||||
ft_ln(table);
|
ft_ln(table);
|
||||||
assert_true(ft_nwrite_ln(table, 4, "c", "235", "3.150000", "5") == FT_SUCCESS);
|
assert_true(ft_nwrite_ln(table, 4, "c", "235", "3.150000", "5") == FT_SUCCESS);
|
||||||
@ -434,9 +434,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test nwwrite functions(wide strings)") {
|
SCENARIO("Test nwwrite functions(wide strings)") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(ft_nwwrite(table, 4, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
assert_true(ft_nwwrite(table, 4, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||||
ft_ln(table);
|
ft_ln(table);
|
||||||
assert_true(ft_nwwrite_ln(table, 4, L"c", L"235", L"3.150000", L"5") == FT_SUCCESS);
|
assert_true(ft_nwwrite_ln(table, 4, L"c", L"235", L"3.150000", L"5") == FT_SUCCESS);
|
||||||
@ -471,9 +471,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test row_write functions") {
|
SCENARIO("Test row_write functions") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
const char *row_0[4] = {"3", "c", "234", "3.140000"};
|
const char *row_0[4] = {"3", "c", "234", "3.140000"};
|
||||||
const char *row_1[4] = {"c", "235", "3.150000", "5"};
|
const char *row_1[4] = {"c", "235", "3.150000", "5"};
|
||||||
const char *row_2[4] = {"234", "3.140000", "3", "c"};
|
const char *row_2[4] = {"234", "3.140000", "3", "c"};
|
||||||
@ -512,9 +512,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test row_write functions(wide strings)") {
|
SCENARIO("Test row_write functions(wide strings)") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
const wchar_t *row_0[4] = {L"3", L"c", L"234", L"3.140000"};
|
const wchar_t *row_0[4] = {L"3", L"c", L"234", L"3.140000"};
|
||||||
const wchar_t *row_1[4] = {L"c", L"235", L"3.150000", L"5"};
|
const wchar_t *row_1[4] = {L"c", L"235", L"3.150000", L"5"};
|
||||||
const wchar_t *row_2[4] = {L"234", L"3.140000", L"3", L"c"};
|
const wchar_t *row_2[4] = {L"234", L"3.140000", L"3", L"c"};
|
||||||
@ -553,9 +553,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test table_write functions") {
|
SCENARIO("Test table_write functions") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
const char *table_cont[3][4] = {
|
const char *table_cont[3][4] = {
|
||||||
{"3", "c", "234", "3.140000"},
|
{"3", "c", "234", "3.140000"},
|
||||||
{"c", "234", "3.140000", "3"},
|
{"c", "234", "3.140000", "3"},
|
||||||
@ -587,9 +587,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test table_write functions(wide strings)") {
|
SCENARIO("Test table_write functions(wide strings)") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
const wchar_t *table_cont[3][4] = {
|
const wchar_t *table_cont[3][4] = {
|
||||||
{L"3", L"c", L"234", L"3.140000"},
|
{L"3", L"c", L"234", L"3.140000"},
|
||||||
{L"c", L"234", L"3.140000", L"3"},
|
{L"c", L"234", L"3.140000", L"3"},
|
||||||
@ -621,9 +621,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test printf functions") {
|
SCENARIO("Test printf functions") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
int n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
|
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(table, "%c|%s|%f|%d", 'c', "235", 3.15, 5);
|
n = ft_printf(table, "%c|%s|%f|%d", 'c', "235", 3.15, 5);
|
||||||
@ -661,9 +661,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test printf functions(wide strings)") {
|
SCENARIO("Test printf functions(wide strings)") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
int n = ft_wprintf_ln(table, L"%d|%c|%ls|%f", 3, 'c', L"234", 3.14);
|
int n = ft_wprintf_ln(table, L"%d|%c|%ls|%f", 3, 'c', L"234", 3.14);
|
||||||
assert_true(n == 4);
|
assert_true(n == 4);
|
||||||
n = ft_wprintf(table, L"%c|%ls|%f|%d", 'c', L"235", 3.15, 5);
|
n = ft_wprintf(table, L"%c|%ls|%f|%d", 'c', L"235", 3.15, 5);
|
||||||
@ -701,9 +701,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test printf functions with strings with separators inside them") {
|
SCENARIO("Test printf functions with strings with separators inside them") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
int n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
|
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(table, "%c", 'c');
|
n = ft_printf(table, "%c", 'c');
|
||||||
@ -742,9 +742,9 @@ void test_table_write(void)
|
|||||||
SCENARIO("Test printf functions with strings with separators inside them") {
|
SCENARIO("Test printf functions with strings with separators inside them") {
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
int n = ft_wprintf_ln(table, L"%d|%c|%ls|%f", 3, 'c', L"234", 3.14);
|
int n = ft_wprintf_ln(table, L"%d|%c|%ls|%f", 3, 'c', L"234", 3.14);
|
||||||
assert_true(n == 4);
|
assert_true(n == 4);
|
||||||
n = ft_wprintf(table, L"%c", 'c');
|
n = ft_wprintf(table, L"%c", 'c');
|
||||||
@ -791,16 +791,16 @@ void test_table_copy(void)
|
|||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
|
|
||||||
assert_true(ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_BOTTOM_PADDING, 1) == FT_SUCCESS);
|
assert_true(ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_BOTTOM_PADDING, 1) == FT_SUCCESS);
|
||||||
assert_true(ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_TOP_PADDING, 1) == FT_SUCCESS);
|
assert_true(ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 1) == FT_SUCCESS);
|
||||||
assert_true(ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_LEFT_PADDING, 2) == FT_SUCCESS);
|
assert_true(ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_LEFT_PADDING, 2) == FT_SUCCESS);
|
||||||
assert_true(ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 2) == FT_SUCCESS);
|
assert_true(ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_RIGHT_PADDING, 2) == FT_SUCCESS);
|
||||||
|
|
||||||
|
|
||||||
ft_set_border_style(table, FT_DOUBLE2_STYLE);
|
ft_set_border_style(table, FT_DOUBLE2_STYLE);
|
||||||
|
|
||||||
/* Set "header" type for the first row */
|
/* Set "header" type for the first row */
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_write_ln(table, "Movie title", "Director", "Year", "Rating");
|
ft_write_ln(table, "Movie title", "Director", "Year", "Rating");
|
||||||
|
|
||||||
ft_write_ln(table, "The Shawshank Redemption", "Frank Darabont", "1994", "9.5");
|
ft_write_ln(table, "The Shawshank Redemption", "Frank Darabont", "1994", "9.5");
|
||||||
@ -810,8 +810,8 @@ void test_table_copy(void)
|
|||||||
ft_write_ln(table, "2001: A Space Odyssey", "Stanley Kubrick", "1968", "8.5");
|
ft_write_ln(table, "2001: A Space Odyssey", "Stanley Kubrick", "1968", "8.5");
|
||||||
|
|
||||||
/* Set center alignment for the 1st and 3rd columns */
|
/* Set center alignment for the 1st and 3rd columns */
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 3, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 3, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
|
|
||||||
|
|
||||||
ft_table_t *table_copy = ft_copy_table(table);
|
ft_table_t *table_copy = ft_copy_table(table);
|
||||||
|
@ -9,7 +9,7 @@ void test_table_border_style(void)
|
|||||||
{
|
{
|
||||||
ft_table_t *table = NULL;
|
ft_table_t *table = NULL;
|
||||||
|
|
||||||
set_test_options_as_default();
|
set_test_properties_as_default();
|
||||||
|
|
||||||
|
|
||||||
WHEN("Changing cell separators") {
|
WHEN("Changing cell separators") {
|
||||||
@ -74,11 +74,11 @@ void test_table_border_style(void)
|
|||||||
|
|
||||||
ft_set_default_border_style(&brdr_style);
|
ft_set_default_border_style(&brdr_style);
|
||||||
|
|
||||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 0);
|
ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 0);
|
||||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 0);
|
ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 0);
|
||||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_EMPTY_STR_HEIGHT, 0);
|
ft_set_default_cell_prop(FT_CPROP_EMPTY_STR_HEIGHT, 0);
|
||||||
|
|
||||||
|
|
||||||
table = create_test_int_table(0);
|
table = create_test_int_table(0);
|
||||||
@ -100,7 +100,7 @@ void test_table_border_style(void)
|
|||||||
table = create_test_int_table(1);
|
table = create_test_int_table(1);
|
||||||
ft_add_separator(table);
|
ft_add_separator(table);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67);
|
int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67);
|
||||||
|
|
||||||
assert_true(n == 4);
|
assert_true(n == 4);
|
||||||
@ -134,10 +134,10 @@ void test_table_border_style(void)
|
|||||||
static ft_table_t *create_basic_table(void)
|
static ft_table_t *create_basic_table(void)
|
||||||
{
|
{
|
||||||
ft_table_t *table = ft_create_table();
|
ft_table_t *table = ft_create_table();
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
ft_set_cell_prop(table, FT_ANY_ROW, 0, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
ft_write_ln(table, "Rank", "Title", "Year", "Rating");
|
ft_write_ln(table, "Rank", "Title", "Year", "Rating");
|
||||||
|
|
||||||
ft_write_ln(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
ft_write_ln(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
||||||
|
@ -3,17 +3,17 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "options.h"
|
#include "properties.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void test_table_tbl_options(void)
|
void test_table_tbl_properties(void)
|
||||||
{
|
{
|
||||||
ft_table_t *table = NULL;
|
ft_table_t *table = NULL;
|
||||||
|
|
||||||
WHEN("Test setting entire table options") {
|
WHEN("Test setting entire table properties") {
|
||||||
set_test_options_as_default();
|
set_test_properties_as_default();
|
||||||
|
|
||||||
table = create_test_int_table(0);
|
table = create_test_int_table(0);
|
||||||
|
|
||||||
@ -35,11 +35,11 @@ void test_table_tbl_options(void)
|
|||||||
"+---+---+----+----+\n";
|
"+---+---+----+----+\n";
|
||||||
assert_str_equal(table_str, table_str_etalon);
|
assert_str_equal(table_str, table_str_etalon);
|
||||||
|
|
||||||
/* Now set table options */
|
/* Now set table properties */
|
||||||
ft_set_tbl_option(table, FT_TOPT_TOP_MARGIN, 3);
|
ft_set_tbl_prop(table, FT_TPROP_TOP_MARGIN, 3);
|
||||||
ft_set_tbl_option(table, FT_TOPT_BOTTOM_MARGIN, 4);
|
ft_set_tbl_prop(table, FT_TPROP_BOTTOM_MARGIN, 4);
|
||||||
ft_set_tbl_option(table, FT_TOPT_LEFT_MARGIN, 1);
|
ft_set_tbl_prop(table, FT_TPROP_LEFT_MARGIN, 1);
|
||||||
ft_set_tbl_option(table, FT_TOPT_RIGHT_MARGIN, 2);
|
ft_set_tbl_prop(table, FT_TPROP_RIGHT_MARGIN, 2);
|
||||||
table_str = ft_to_string(table);
|
table_str = ft_to_string(table);
|
||||||
assert_true(table_str != NULL);
|
assert_true(table_str != NULL);
|
||||||
table_str_etalon =
|
table_str_etalon =
|
||||||
@ -72,8 +72,8 @@ void test_table_tbl_options(void)
|
|||||||
|
|
||||||
|
|
||||||
#ifdef FT_HAVE_WCHAR
|
#ifdef FT_HAVE_WCHAR
|
||||||
WHEN("Test setting entire table options(wide strings case)") {
|
WHEN("Test setting entire table properties(wide strings case)") {
|
||||||
set_test_options_as_default();
|
set_test_properties_as_default();
|
||||||
|
|
||||||
table = create_test_int_wtable(0);
|
table = create_test_int_wtable(0);
|
||||||
|
|
||||||
@ -95,11 +95,11 @@ void test_table_tbl_options(void)
|
|||||||
L"+---+---+----+----+\n";
|
L"+---+---+----+----+\n";
|
||||||
assert_wcs_equal(table_str, table_str_etalon);
|
assert_wcs_equal(table_str, table_str_etalon);
|
||||||
|
|
||||||
/* Now set table options */
|
/* Now set table properties */
|
||||||
ft_set_tbl_option(table, FT_TOPT_TOP_MARGIN, 3);
|
ft_set_tbl_prop(table, FT_TPROP_TOP_MARGIN, 3);
|
||||||
ft_set_tbl_option(table, FT_TOPT_BOTTOM_MARGIN, 4);
|
ft_set_tbl_prop(table, FT_TPROP_BOTTOM_MARGIN, 4);
|
||||||
ft_set_tbl_option(table, FT_TOPT_LEFT_MARGIN, 1);
|
ft_set_tbl_prop(table, FT_TPROP_LEFT_MARGIN, 1);
|
||||||
ft_set_tbl_option(table, FT_TOPT_RIGHT_MARGIN, 2);
|
ft_set_tbl_prop(table, FT_TPROP_RIGHT_MARGIN, 2);
|
||||||
table_str = ft_to_wstring(table);
|
table_str = ft_to_wstring(table);
|
||||||
assert_true(table_str != NULL);
|
assert_true(table_str != NULL);
|
||||||
table_str_etalon =
|
table_str_etalon =
|
||||||
@ -132,18 +132,18 @@ void test_table_tbl_options(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void test_table_cell_options(void)
|
void test_table_cell_properties(void)
|
||||||
{
|
{
|
||||||
ft_table_t *table = NULL;
|
ft_table_t *table = NULL;
|
||||||
|
|
||||||
|
|
||||||
WHEN("All paddings = 1") {
|
WHEN("All paddings = 1") {
|
||||||
set_test_options_as_default();
|
set_test_properties_as_default();
|
||||||
|
|
||||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 1);
|
||||||
|
|
||||||
table = create_test_int_table(0);
|
table = create_test_int_table(0);
|
||||||
|
|
||||||
@ -171,10 +171,10 @@ void test_table_cell_options(void)
|
|||||||
|
|
||||||
WHEN("Top and bottom padding = 0") {
|
WHEN("Top and bottom padding = 0") {
|
||||||
|
|
||||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 0);
|
ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 0);
|
||||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 0);
|
ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 0);
|
||||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 1);
|
||||||
|
|
||||||
table = create_test_int_table(0);
|
table = create_test_int_table(0);
|
||||||
|
|
||||||
@ -194,10 +194,10 @@ void test_table_cell_options(void)
|
|||||||
|
|
||||||
WHEN("Left and right padding = 0") {
|
WHEN("Left and right padding = 0") {
|
||||||
|
|
||||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 0);
|
ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 0);
|
||||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 0);
|
ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 0);
|
||||||
|
|
||||||
table = create_test_int_table(0);
|
table = create_test_int_table(0);
|
||||||
|
|
||||||
@ -223,10 +223,10 @@ void test_table_cell_options(void)
|
|||||||
|
|
||||||
WHEN("All paddings = 0") {
|
WHEN("All paddings = 0") {
|
||||||
|
|
||||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 0);
|
ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 0);
|
||||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 0);
|
ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 0);
|
||||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 0);
|
ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 0);
|
||||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 0);
|
ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 0);
|
||||||
|
|
||||||
table = create_test_int_table(0);
|
table = create_test_int_table(0);
|
||||||
|
|
||||||
@ -246,11 +246,11 @@ void test_table_cell_options(void)
|
|||||||
|
|
||||||
WHEN("Empty string has 0 heigt") {
|
WHEN("Empty string has 0 heigt") {
|
||||||
|
|
||||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 1);
|
||||||
ft_set_default_cell_option(FT_COPT_EMPTY_STR_HEIGHT, 0);
|
ft_set_default_cell_prop(FT_CPROP_EMPTY_STR_HEIGHT, 0);
|
||||||
|
|
||||||
table = create_test_int_table(0);
|
table = create_test_int_table(0);
|
||||||
int n = ft_printf_ln(table, "|||");
|
int n = ft_printf_ln(table, "|||");
|
||||||
@ -280,15 +280,15 @@ void test_table_cell_options(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WHEN("Setting options for a particular table") {
|
WHEN("Setting properties for a particular table") {
|
||||||
|
|
||||||
table = create_test_int_table(0);
|
table = create_test_int_table(0);
|
||||||
set_test_options_for_table(table);
|
set_test_props_for_table(table);
|
||||||
|
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_BOTTOM_PADDING, 0);
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_BOTTOM_PADDING, 0);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_TOP_PADDING, 0);
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 0);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_LEFT_PADDING, 0);
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_LEFT_PADDING, 0);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 0);
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_RIGHT_PADDING, 0);
|
||||||
|
|
||||||
const char *table_str = ft_to_string(table);
|
const char *table_str = ft_to_string(table);
|
||||||
assert_true(table_str != NULL);
|
assert_true(table_str != NULL);
|
||||||
@ -303,11 +303,11 @@ void test_table_cell_options(void)
|
|||||||
assert_str_equal(table_str, table_str_etalon);
|
assert_str_equal(table_str, table_str_etalon);
|
||||||
|
|
||||||
|
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_BOTTOM_PADDING, 1);
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_BOTTOM_PADDING, 1);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_TOP_PADDING, 1);
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 1);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_LEFT_PADDING, 0);
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_LEFT_PADDING, 0);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 0);
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_RIGHT_PADDING, 0);
|
||||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_EMPTY_STR_HEIGHT, 0);
|
ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_EMPTY_STR_HEIGHT, 0);
|
||||||
|
|
||||||
table_str = ft_to_string(table);
|
table_str = ft_to_string(table);
|
||||||
assert_true(table_str != NULL);
|
assert_true(table_str != NULL);
|
||||||
@ -333,18 +333,18 @@ void test_table_cell_options(void)
|
|||||||
|
|
||||||
WHEN("Set table width and column alignment") {
|
WHEN("Set table width and column alignment") {
|
||||||
|
|
||||||
set_test_options_as_default();
|
set_test_properties_as_default();
|
||||||
|
|
||||||
table = create_test_int_table(0);
|
table = create_test_int_table(0);
|
||||||
int status = FT_SUCCESS;
|
int status = FT_SUCCESS;
|
||||||
|
|
||||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_MIN_WIDTH, 7);
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_MIN_WIDTH, 7);
|
||||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 2, FT_COPT_MIN_WIDTH, 8);
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, 2, FT_CPROP_MIN_WIDTH, 8);
|
||||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 2, FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, 2, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
|
|
||||||
status |= ft_set_cell_option(table, 2, 3, FT_COPT_MIN_WIDTH, 6);
|
status |= ft_set_cell_prop(table, 2, 3, FT_CPROP_MIN_WIDTH, 6);
|
||||||
status |= ft_set_cell_option(table, 2, 3, FT_COPT_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
status |= ft_set_cell_prop(table, 2, 3, FT_CPROP_TEXT_ALIGN, FT_ALIGNED_LEFT);
|
||||||
assert_true(status == FT_SUCCESS);
|
assert_true(status == FT_SUCCESS);
|
||||||
|
|
||||||
|
|
||||||
@ -370,11 +370,11 @@ void test_table_cell_options(void)
|
|||||||
|
|
||||||
WHEN("Set table width and column alignment as default") {
|
WHEN("Set table width and column alignment as default") {
|
||||||
|
|
||||||
set_test_options_as_default();
|
set_test_properties_as_default();
|
||||||
|
|
||||||
int status = FT_SUCCESS;
|
int status = FT_SUCCESS;
|
||||||
status |= ft_set_default_cell_option(FT_COPT_MIN_WIDTH, 5);
|
status |= ft_set_default_cell_prop(FT_CPROP_MIN_WIDTH, 5);
|
||||||
status |= ft_set_default_cell_option(FT_COPT_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
status |= ft_set_default_cell_prop(FT_CPROP_TEXT_ALIGN, FT_ALIGNED_CENTER);
|
||||||
assert_true(status == FT_SUCCESS);
|
assert_true(status == FT_SUCCESS);
|
||||||
|
|
||||||
table = create_test_int_table(0);
|
table = create_test_int_table(0);
|
||||||
@ -400,11 +400,11 @@ void test_table_cell_options(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
WHEN("Multiline cell") {
|
WHEN("Multiline cell") {
|
||||||
set_test_options_as_default();
|
set_test_properties_as_default();
|
||||||
|
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
int n = ft_printf_ln(table, "%d|%c|%s|%f", 4, 'c', "234", 3.14);
|
int n = ft_printf_ln(table, "%d|%c|%s|%f", 4, 'c', "234", 3.14);
|
||||||
|
|
||||||
assert_true(n == 4);
|
assert_true(n == 4);
|
||||||
@ -436,7 +436,7 @@ void test_table_cell_options(void)
|
|||||||
|
|
||||||
|
|
||||||
WHEN("Cells with spans") {
|
WHEN("Cells with spans") {
|
||||||
set_test_options_as_default();
|
set_test_properties_as_default();
|
||||||
|
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
int n = ft_set_cell_span(table, 0, 0, 5);
|
int n = ft_set_cell_span(table, 0, 0, 5);
|
||||||
@ -444,9 +444,9 @@ void test_table_cell_options(void)
|
|||||||
n = ft_set_cell_span(table, 1, 1, 3);
|
n = ft_set_cell_span(table, 1, 1, 3);
|
||||||
assert_true(n == FT_SUCCESS);
|
assert_true(n == FT_SUCCESS);
|
||||||
|
|
||||||
n = ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
n = ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(n == FT_SUCCESS);
|
assert_true(n == FT_SUCCESS);
|
||||||
n = ft_set_cell_option(table, 1, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
n = ft_set_cell_prop(table, 1, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(n == FT_SUCCESS);
|
assert_true(n == FT_SUCCESS);
|
||||||
|
|
||||||
n = ft_write_ln(table, "111", "2222", "33333", "444444", "55555555");
|
n = ft_write_ln(table, "111", "2222", "33333", "444444", "55555555");
|
||||||
@ -494,7 +494,7 @@ void test_table_cell_options(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
WHEN("Cells with spans in common and header cells") {
|
WHEN("Cells with spans in common and header cells") {
|
||||||
set_test_options_as_default();
|
set_test_properties_as_default();
|
||||||
|
|
||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
ft_set_border_style(table, FT_DOUBLE2_STYLE);
|
ft_set_border_style(table, FT_DOUBLE2_STYLE);
|
||||||
@ -506,7 +506,7 @@ void test_table_cell_options(void)
|
|||||||
n = ft_set_cell_span(table, 1, 1, 3);
|
n = ft_set_cell_span(table, 1, 1, 3);
|
||||||
assert_true(n == FT_SUCCESS);
|
assert_true(n == FT_SUCCESS);
|
||||||
|
|
||||||
n = ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
n = ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
assert_true(n == FT_SUCCESS);
|
assert_true(n == FT_SUCCESS);
|
||||||
|
|
||||||
n = ft_write_ln(table, "111", "2222", "33333", "444444", "55555555");
|
n = ft_write_ln(table, "111", "2222", "33333", "444444", "55555555");
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#define assert_string_equal(str1, str2) assert_str_equal(str1.c_str(), str2.c_str())
|
#define assert_string_equal(str1, str2) assert_str_equal(str1.c_str(), str2.c_str())
|
||||||
|
|
||||||
bool set_test_options_for_table(fort::Table *table)
|
bool set_test_props_for_table(fort::Table *table)
|
||||||
{
|
{
|
||||||
assert_true(table->set_cell_bottom_padding(FT_ANY_ROW, FT_ANY_COLUMN, 1));
|
assert_true(table->set_cell_bottom_padding(FT_ANY_ROW, FT_ANY_COLUMN, 1));
|
||||||
assert_true(table->set_cell_top_padding(FT_ANY_ROW, FT_ANY_COLUMN, 1));
|
assert_true(table->set_cell_top_padding(FT_ANY_ROW, FT_ANY_COLUMN, 1));
|
||||||
@ -36,7 +36,7 @@ void test_cpp_table_basic(void)
|
|||||||
{
|
{
|
||||||
WHEN("All columns are equal and not empty.") {
|
WHEN("All columns are equal and not empty.") {
|
||||||
fort::Table table;
|
fort::Table table;
|
||||||
assert_true(set_test_options_for_table(&table));
|
assert_true(set_test_props_for_table(&table));
|
||||||
|
|
||||||
table << fort::header
|
table << fort::header
|
||||||
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
||||||
@ -63,7 +63,7 @@ void test_cpp_table_basic(void)
|
|||||||
|
|
||||||
WHEN("Checking basic constructors and assignmets.") {
|
WHEN("Checking basic constructors and assignmets.") {
|
||||||
fort::Table table;
|
fort::Table table;
|
||||||
assert_true(set_test_options_for_table(&table));
|
assert_true(set_test_props_for_table(&table));
|
||||||
|
|
||||||
table << fort::header
|
table << fort::header
|
||||||
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
||||||
@ -98,7 +98,7 @@ void test_cpp_table_basic(void)
|
|||||||
|
|
||||||
WHEN("All columns are not equal and not empty") {
|
WHEN("All columns are not equal and not empty") {
|
||||||
fort::Table table;
|
fort::Table table;
|
||||||
assert_true(set_test_options_for_table(&table));
|
assert_true(set_test_props_for_table(&table));
|
||||||
|
|
||||||
table << fort::header
|
table << fort::header
|
||||||
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
<< "3" << "c" << "234" << "3.140000" << fort::endr
|
||||||
@ -125,7 +125,7 @@ void test_cpp_table_basic(void)
|
|||||||
|
|
||||||
WHEN("All columns are not equal and some cells are empty") {
|
WHEN("All columns are not equal and some cells are empty") {
|
||||||
fort::Table table;
|
fort::Table table;
|
||||||
assert_true(set_test_options_for_table(&table));
|
assert_true(set_test_props_for_table(&table));
|
||||||
|
|
||||||
table << fort::header
|
table << fort::header
|
||||||
<< "" << "" << "234" << "3.140000" << fort::endr
|
<< "" << "" << "234" << "3.140000" << fort::endr
|
||||||
@ -152,7 +152,7 @@ void test_cpp_table_basic(void)
|
|||||||
|
|
||||||
WHEN("All cells are empty") {
|
WHEN("All cells are empty") {
|
||||||
fort::Table table;
|
fort::Table table;
|
||||||
assert_true(set_test_options_for_table(&table));
|
assert_true(set_test_props_for_table(&table));
|
||||||
|
|
||||||
table << fort::header
|
table << fort::header
|
||||||
<< "" << "" << "" << "" << fort::endr
|
<< "" << "" << "" << "" << fort::endr
|
||||||
@ -183,7 +183,7 @@ void test_cpp_table_write(void)
|
|||||||
{
|
{
|
||||||
SCENARIO("Test write functions") {
|
SCENARIO("Test write functions") {
|
||||||
fort::Table table;
|
fort::Table table;
|
||||||
assert_true(set_test_options_for_table(&table));
|
assert_true(set_test_props_for_table(&table));
|
||||||
table << fort::header;
|
table << fort::header;
|
||||||
assert_true(table.write("3"));
|
assert_true(table.write("3"));
|
||||||
assert_true(table.write("c"));
|
assert_true(table.write("c"));
|
||||||
@ -225,7 +225,7 @@ void test_cpp_table_write(void)
|
|||||||
|
|
||||||
SCENARIO("Test n write functions") {
|
SCENARIO("Test n write functions") {
|
||||||
fort::Table table;
|
fort::Table table;
|
||||||
assert_true(set_test_options_for_table(&table));
|
assert_true(set_test_props_for_table(&table));
|
||||||
table << fort::header;
|
table << fort::header;
|
||||||
assert_true(table.write("3", "c", "234", "3.140000"));
|
assert_true(table.write("3", "c", "234", "3.140000"));
|
||||||
table << fort::endr;
|
table << fort::endr;
|
||||||
@ -257,7 +257,7 @@ void test_cpp_table_write(void)
|
|||||||
|
|
||||||
SCENARIO("Test row_write functions") {
|
SCENARIO("Test row_write functions") {
|
||||||
fort::Table table;
|
fort::Table table;
|
||||||
assert_true(set_test_options_for_table(&table));
|
assert_true(set_test_props_for_table(&table));
|
||||||
|
|
||||||
table << fort::header;
|
table << fort::header;
|
||||||
const char *row_0[4] = {"3", "c", "234", "3.140000"};
|
const char *row_0[4] = {"3", "c", "234", "3.140000"};
|
||||||
|
@ -22,8 +22,8 @@ struct test_case bb_test_suit [] = {
|
|||||||
{"test_table_write", test_table_write},
|
{"test_table_write", test_table_write},
|
||||||
{"test_table_border_style", test_table_border_style},
|
{"test_table_border_style", test_table_border_style},
|
||||||
{"test_table_builtin_border_styles", test_table_builtin_border_styles},
|
{"test_table_builtin_border_styles", test_table_builtin_border_styles},
|
||||||
{"test_table_cell_options", test_table_cell_options},
|
{"test_table_cell_properties", test_table_cell_properties},
|
||||||
{"test_table_tbl_options", test_table_tbl_options},
|
{"test_table_tbl_properties", test_table_tbl_properties},
|
||||||
{"test_memory_errors", test_memory_errors},
|
{"test_memory_errors", test_memory_errors},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
#include "fort.h"
|
#include "fort.h"
|
||||||
|
|
||||||
int set_test_options_for_table(struct ft_table *table)
|
int set_test_props_for_table(struct ft_table *table)
|
||||||
{
|
{
|
||||||
assert(table);
|
assert(table);
|
||||||
int status = FT_SUCCESS;
|
int status = FT_SUCCESS;
|
||||||
status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_BOTTOM_PADDING, 1);
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_BOTTOM_PADDING, 1);
|
||||||
status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_TOP_PADDING, 1);
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 1);
|
||||||
status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_LEFT_PADDING, 1);
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_LEFT_PADDING, 1);
|
||||||
status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 1);
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_RIGHT_PADDING, 1);
|
||||||
status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_EMPTY_STR_HEIGHT, 1);
|
status |= ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_EMPTY_STR_HEIGHT, 1);
|
||||||
|
|
||||||
assert_true(status == FT_SUCCESS);
|
assert_true(status == FT_SUCCESS);
|
||||||
|
|
||||||
@ -33,18 +33,18 @@ int set_test_options_for_table(struct ft_table *table)
|
|||||||
return ft_set_border_style(table, &brdr_style);
|
return ft_set_border_style(table, &brdr_style);
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_test_options_as_default(void)
|
int set_test_properties_as_default(void)
|
||||||
{
|
{
|
||||||
int status = FT_SUCCESS;
|
int status = FT_SUCCESS;
|
||||||
|
|
||||||
status |= ft_set_default_cell_option(FT_COPT_MIN_WIDTH, 0);
|
status |= ft_set_default_cell_prop(FT_CPROP_MIN_WIDTH, 0);
|
||||||
status |= ft_set_default_cell_option(FT_COPT_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
status |= ft_set_default_cell_prop(FT_CPROP_TEXT_ALIGN, FT_ALIGNED_RIGHT);
|
||||||
|
|
||||||
status |= ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 1);
|
status |= ft_set_default_cell_prop(FT_CPROP_BOTTOM_PADDING, 1);
|
||||||
status |= ft_set_default_cell_option(FT_COPT_TOP_PADDING, 1);
|
status |= ft_set_default_cell_prop(FT_CPROP_TOP_PADDING, 1);
|
||||||
status |= ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
status |= ft_set_default_cell_prop(FT_CPROP_LEFT_PADDING, 1);
|
||||||
status |= ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
status |= ft_set_default_cell_prop(FT_CPROP_RIGHT_PADDING, 1);
|
||||||
status |= ft_set_default_cell_option(FT_COPT_EMPTY_STR_HEIGHT, 1);
|
status |= ft_set_default_cell_prop(FT_CPROP_EMPTY_STR_HEIGHT, 1);
|
||||||
|
|
||||||
assert_true(status == FT_SUCCESS);
|
assert_true(status == FT_SUCCESS);
|
||||||
|
|
||||||
@ -78,12 +78,12 @@ struct ft_table *create_test_int_table(int set_test_opts)
|
|||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
if (set_test_opts) {
|
if (set_test_opts) {
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
int n = ft_write_ln(table, "3", "4", "55", "67");
|
int n = ft_write_ln(table, "3", "4", "55", "67");
|
||||||
assert(n == FT_SUCCESS);
|
assert(n == FT_SUCCESS);
|
||||||
|
|
||||||
@ -108,12 +108,12 @@ struct ft_table *create_test_int_wtable(int set_test_opts)
|
|||||||
table = ft_create_table();
|
table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
if (set_test_opts) {
|
if (set_test_opts) {
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
|
|
||||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, FT_ROW_HEADER);
|
ft_set_cell_prop(table, 0, FT_ANY_COLUMN, FT_CPROP_ROW_TYPE, FT_ROW_HEADER);
|
||||||
int n = ft_wwrite_ln(table, L"3", L"4", L"55", L"67");
|
int n = ft_wwrite_ln(table, L"3", L"4", L"55", L"67");
|
||||||
assert(n == FT_SUCCESS);
|
assert(n == FT_SUCCESS);
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ void test_wcs_table_boundaries(void);
|
|||||||
void test_table_write(void);
|
void test_table_write(void);
|
||||||
void test_table_border_style(void);
|
void test_table_border_style(void);
|
||||||
void test_table_builtin_border_styles(void);
|
void test_table_builtin_border_styles(void);
|
||||||
void test_table_cell_options(void);
|
void test_table_cell_properties(void);
|
||||||
void test_table_tbl_options(void);
|
void test_table_tbl_properties(void);
|
||||||
void test_memory_errors(void);
|
void test_memory_errors(void);
|
||||||
|
|
||||||
struct test_case {
|
struct test_case {
|
||||||
@ -73,8 +73,8 @@ struct ft_table;
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int set_test_options_for_table(struct ft_table *table);
|
int set_test_props_for_table(struct ft_table *table);
|
||||||
int set_test_options_as_default(void);
|
int set_test_properties_as_default(void);
|
||||||
struct ft_table *create_test_int_table(int set_test_opts);
|
struct ft_table *create_test_int_table(int set_test_opts);
|
||||||
struct ft_table *create_test_int_wtable(int set_test_opts);
|
struct ft_table *create_test_int_wtable(int set_test_opts);
|
||||||
void run_test_suit(const char *test_suit_name, int n_tests, struct test_case test_suit[]);
|
void run_test_suit(const char *test_suit_name, int n_tests, struct test_case test_suit[]);
|
||||||
|
@ -5,7 +5,7 @@ void test_table_sizes(void)
|
|||||||
{
|
{
|
||||||
ft_table_t *table = ft_create_table();
|
ft_table_t *table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
|
|
||||||
size_t rows = 0;
|
size_t rows = 0;
|
||||||
@ -54,7 +54,7 @@ void test_table_geometry(void)
|
|||||||
{
|
{
|
||||||
ft_table_t *table = ft_create_table();
|
ft_table_t *table = ft_create_table();
|
||||||
assert_true(table != NULL);
|
assert_true(table != NULL);
|
||||||
assert_true(set_test_options_for_table(table) == FT_SUCCESS);
|
assert_true(set_test_props_for_table(table) == FT_SUCCESS);
|
||||||
|
|
||||||
size_t height = 0;
|
size_t height = 0;
|
||||||
size_t width = 0;
|
size_t width = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user