From 354aec6eec501d9388ae3e620396bbbc9e29b049 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Mon, 3 Dec 2018 23:25:17 +0300 Subject: [PATCH] [F] Fixed some issues --- .travis.yml | 4 +-- lib/fort.c | 67 ++++++++++++++++++++++++++++++------------------ src/properties.c | 23 ++++++++++------- src/row.c | 44 +++++++++++++++++++------------ 4 files changed, 86 insertions(+), 52 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4b1ecf9..96d0bfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -126,9 +126,9 @@ script: export CXX=${FORT_CXX_COMPILER}; fi - # basic build with old c standard + # basic build with old c standard (use gnu89 instead of c89 because some functions are not defines in c89) - cd lib - - ${CC} -Wextra -Wall -Werror --std=c89 fort.c -c -o fort.o + - ${CC} -Wall -Wextra -Werror --std=gnu89 -DFT_CONGIG_HAVE_WCHAR fort.c -c -o fort.o - rm fort.o - cd .. diff --git a/lib/fort.c b/lib/fort.c index 481c6f4..78fe6bc 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -2566,6 +2566,7 @@ void get_style_tag_for_cell(const fort_table_properties_t *props, size_t row, size_t col, char *style_tag, size_t sz) { (void)sz; + size_t i = 0; unsigned bg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_BG_COLOR); unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_TEXT_STYLE); @@ -2573,7 +2574,7 @@ void get_style_tag_for_cell(const fort_table_properties_t *props, style_tag[0] = '\0'; if (text_style < (1U << n_styles)) { - for (size_t i = 0; i < n_styles; ++i) { + for (i = 0; i < n_styles; ++i) { if (text_style & (1 << i)) { strcat(style_tag, text_styles[i]); } @@ -2591,7 +2592,7 @@ void get_style_tag_for_cell(const fort_table_properties_t *props, return; error: - // shouldn't be here + /* shouldn't be here */ assert(0); style_tag[0] = '\0'; return; @@ -2601,6 +2602,7 @@ void get_reset_style_tag_for_cell(const fort_table_properties_t *props, size_t row, size_t col, char *reset_style_tag, size_t sz) { (void)sz; + size_t i = 0; unsigned bg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_BG_COLOR); unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_TEXT_STYLE); @@ -2608,7 +2610,7 @@ void get_reset_style_tag_for_cell(const fort_table_properties_t *props, reset_style_tag[0] = '\0'; if (text_style < (1U << n_styles)) { - for (size_t i = 0; i < n_styles; ++i) { + for (i = 0; i < n_styles; ++i) { if (text_style & (1 << i)) { strcat(reset_style_tag, reset_text_styles[i]); } @@ -2626,7 +2628,7 @@ void get_reset_style_tag_for_cell(const fort_table_properties_t *props, return; error: - // shouldn't be here + /* shouldn't be here */ assert(0); reset_style_tag[0] = '\0'; return; @@ -2637,6 +2639,7 @@ void get_style_tag_for_content(const fort_table_properties_t *props, size_t row, size_t col, char *style_tag, size_t sz) { (void)sz; + size_t i = 0; unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_TEXT_STYLE); unsigned fg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_FG_COLOR); @@ -2645,7 +2648,7 @@ void get_style_tag_for_content(const fort_table_properties_t *props, style_tag[0] = '\0'; if (text_style < (1U << n_styles)) { - for (size_t i = 0; i < n_styles; ++i) { + for (i = 0; i < n_styles; ++i) { if (text_style & (1 << i)) { strcat(style_tag, text_styles[i]); } @@ -2669,7 +2672,7 @@ void get_style_tag_for_content(const fort_table_properties_t *props, return; error: - // shouldn't be here + /* shouldn't be here */ assert(0); style_tag[0] = '\0'; return; @@ -2679,6 +2682,7 @@ void get_reset_style_tag_for_content(const fort_table_properties_t *props, size_t row, size_t col, char *reset_style_tag, size_t sz) { (void)sz; + size_t i = 0; unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_TEXT_STYLE); unsigned fg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_FG_COLOR); @@ -2687,7 +2691,7 @@ void get_reset_style_tag_for_content(const fort_table_properties_t *props, reset_style_tag[0] = '\0'; if (text_style < (1U << n_styles)) { - for (size_t i = 0; i < n_styles; ++i) { + for (i = 0; i < n_styles; ++i) { if (text_style & (1 << i)) { strcat(reset_style_tag, reset_text_styles[i]); } @@ -2711,7 +2715,7 @@ void get_reset_style_tag_for_content(const fort_table_properties_t *props, return; error: - // shouldn't be here + /* shouldn't be here */ assert(0); reset_style_tag[0] = '\0'; return; @@ -3438,8 +3442,9 @@ fort_cell_prop_container_t *copy_cell_properties(fort_cell_prop_container_t *con if (result == NULL) return NULL; + size_t i = 0; size_t sz = vector_size(cont); - for (size_t i = 0; i < sz; ++i) { + for (i = 0; i < sz; ++i) { fort_cell_props_t *opt = (fort_cell_props_t *)vector_at(cont, i); if (FT_IS_ERROR(vector_push(result, opt))) { destroy_cell_prop_container(result); @@ -3518,9 +3523,10 @@ void destroy_row(fort_row_t *row) if (row == NULL) return; + size_t i = 0; if (row->cells) { size_t cells_n = vector_size(row->cells); - for (size_t i = 0; i < cells_n; ++i) { + for (i = 0; i < cells_n; ++i) { fort_cell_t *cell = *(fort_cell_t **)vector_at(row->cells, i); destroy_cell(cell); } @@ -3538,8 +3544,9 @@ fort_row_t *copy_row(fort_row_t *row) if (result == NULL) return NULL; + size_t i = 0; size_t cols_n = vector_size(row->cells); - for (size_t i = 0; i < cols_n; ++i) { + for (i = 0; i < cols_n; ++i) { fort_cell_t *cell = *(fort_cell_t **)vector_at(row->cells, i); fort_cell_t *new_cell = copy_cell(cell); if (new_cell == NULL) { @@ -3815,8 +3822,10 @@ int print_row_separator(char *buffer, size_t buffer_sz, IV = &(*border_chars)[II_bip]; R = &(*border_chars)[RH_bip]; -// IT = &(*border_chars)[TV_bip]; -// IB = &(*border_chars)[BV_bip]; + /* + IT = &(*border_chars)[TV_bip]; + IB = &(*border_chars)[BV_bip]; + */ IT = &(*border_chars)[TI_bip]; IB = &(*border_chars)[BI_bip]; II = &(*border_chars)[IH_bip]; @@ -3838,11 +3847,14 @@ int print_row_separator(char *buffer, size_t buffer_sz, size_t i = 0; - /* If all chars are not printable, skip line separator */ /* todo: add processing for wchar_t */ -// if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { -// status = 0; -// goto clear; -// } + /* If all chars are not printable, skip line separator */ + /* todo: add processing for wchar_t */ + /* + if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { + status = 0; + goto clear; + } + */ if ((strlen(*L) == 0 || (strlen(*L) == 1 && !isprint(**L))) && (strlen(*I) == 0 || (strlen(*I) == 1 && !isprint(**I))) && (strlen(*IV) == 0 || (strlen(*IV) == 1 && !isprint(**IV))) @@ -3997,8 +4009,10 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz, IV = &(*border_chars)[II_bip]; R = &(*border_chars)[RH_bip]; -// IT = &(*border_chars)[TV_bip]; -// IB = &(*border_chars)[BV_bip]; + /* + IT = &(*border_chars)[TV_bip]; + IB = &(*border_chars)[BV_bip]; + */ IT = &(*border_chars)[TI_bip]; IB = &(*border_chars)[BI_bip]; II = &(*border_chars)[IH_bip]; @@ -4020,11 +4034,14 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz, size_t i = 0; - /* If all chars are not printable, skip line separator */ /* todo: add processing for wchar_t */ -// if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { -// status = 0; -// goto clear; -// } + /* If all chars are not printable, skip line separator */ + /* todo: add processing for wchar_t */ + /* + if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { + status = 0; + goto clear; + } + */ if ((strlen(*L) == 0 || (strlen(*L) == 1 && !isprint(**L))) && (strlen(*I) == 0 || (strlen(*I) == 1 && !isprint(**I))) && (strlen(*IV) == 0 || (strlen(*IV) == 1 && !isprint(**IV))) diff --git a/src/properties.c b/src/properties.c index 6c97dd0..da82769 100644 --- a/src/properties.c +++ b/src/properties.c @@ -117,6 +117,7 @@ void get_style_tag_for_cell(const fort_table_properties_t *props, size_t row, size_t col, char *style_tag, size_t sz) { (void)sz; + size_t i = 0; unsigned bg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_BG_COLOR); unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_TEXT_STYLE); @@ -124,7 +125,7 @@ void get_style_tag_for_cell(const fort_table_properties_t *props, style_tag[0] = '\0'; if (text_style < (1U << n_styles)) { - for (size_t i = 0; i < n_styles; ++i) { + for (i = 0; i < n_styles; ++i) { if (text_style & (1 << i)) { strcat(style_tag, text_styles[i]); } @@ -142,7 +143,7 @@ void get_style_tag_for_cell(const fort_table_properties_t *props, return; error: - // shouldn't be here + /* shouldn't be here */ assert(0); style_tag[0] = '\0'; return; @@ -152,6 +153,7 @@ void get_reset_style_tag_for_cell(const fort_table_properties_t *props, size_t row, size_t col, char *reset_style_tag, size_t sz) { (void)sz; + size_t i = 0; unsigned bg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_BG_COLOR); unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_TEXT_STYLE); @@ -159,7 +161,7 @@ void get_reset_style_tag_for_cell(const fort_table_properties_t *props, reset_style_tag[0] = '\0'; if (text_style < (1U << n_styles)) { - for (size_t i = 0; i < n_styles; ++i) { + for (i = 0; i < n_styles; ++i) { if (text_style & (1 << i)) { strcat(reset_style_tag, reset_text_styles[i]); } @@ -177,7 +179,7 @@ void get_reset_style_tag_for_cell(const fort_table_properties_t *props, return; error: - // shouldn't be here + /* shouldn't be here */ assert(0); reset_style_tag[0] = '\0'; return; @@ -188,6 +190,7 @@ void get_style_tag_for_content(const fort_table_properties_t *props, size_t row, size_t col, char *style_tag, size_t sz) { (void)sz; + size_t i = 0; unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_TEXT_STYLE); unsigned fg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_FG_COLOR); @@ -196,7 +199,7 @@ void get_style_tag_for_content(const fort_table_properties_t *props, style_tag[0] = '\0'; if (text_style < (1U << n_styles)) { - for (size_t i = 0; i < n_styles; ++i) { + for (i = 0; i < n_styles; ++i) { if (text_style & (1 << i)) { strcat(style_tag, text_styles[i]); } @@ -220,7 +223,7 @@ void get_style_tag_for_content(const fort_table_properties_t *props, return; error: - // shouldn't be here + /* shouldn't be here */ assert(0); style_tag[0] = '\0'; return; @@ -230,6 +233,7 @@ void get_reset_style_tag_for_content(const fort_table_properties_t *props, size_t row, size_t col, char *reset_style_tag, size_t sz) { (void)sz; + size_t i = 0; unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_TEXT_STYLE); unsigned fg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_FG_COLOR); @@ -238,7 +242,7 @@ void get_reset_style_tag_for_content(const fort_table_properties_t *props, reset_style_tag[0] = '\0'; if (text_style < (1U << n_styles)) { - for (size_t i = 0; i < n_styles; ++i) { + for (i = 0; i < n_styles; ++i) { if (text_style & (1 << i)) { strcat(reset_style_tag, reset_text_styles[i]); } @@ -262,7 +266,7 @@ void get_reset_style_tag_for_content(const fort_table_properties_t *props, return; error: - // shouldn't be here + /* shouldn't be here */ assert(0); reset_style_tag[0] = '\0'; return; @@ -989,8 +993,9 @@ fort_cell_prop_container_t *copy_cell_properties(fort_cell_prop_container_t *con if (result == NULL) return NULL; + size_t i = 0; size_t sz = vector_size(cont); - for (size_t i = 0; i < sz; ++i) { + for (i = 0; i < sz; ++i) { fort_cell_props_t *opt = (fort_cell_props_t *)vector_at(cont, i); if (FT_IS_ERROR(vector_push(result, opt))) { destroy_cell_prop_container(result); diff --git a/src/row.c b/src/row.c index 3366054..f78d7d7 100644 --- a/src/row.c +++ b/src/row.c @@ -37,9 +37,10 @@ void destroy_row(fort_row_t *row) if (row == NULL) return; + size_t i = 0; if (row->cells) { size_t cells_n = vector_size(row->cells); - for (size_t i = 0; i < cells_n; ++i) { + for (i = 0; i < cells_n; ++i) { fort_cell_t *cell = *(fort_cell_t **)vector_at(row->cells, i); destroy_cell(cell); } @@ -57,8 +58,9 @@ fort_row_t *copy_row(fort_row_t *row) if (result == NULL) return NULL; + size_t i = 0; size_t cols_n = vector_size(row->cells); - for (size_t i = 0; i < cols_n; ++i) { + for (i = 0; i < cols_n; ++i) { fort_cell_t *cell = *(fort_cell_t **)vector_at(row->cells, i); fort_cell_t *new_cell = copy_cell(cell); if (new_cell == NULL) { @@ -334,8 +336,10 @@ int print_row_separator(char *buffer, size_t buffer_sz, IV = &(*border_chars)[II_bip]; R = &(*border_chars)[RH_bip]; -// IT = &(*border_chars)[TV_bip]; -// IB = &(*border_chars)[BV_bip]; + /* + IT = &(*border_chars)[TV_bip]; + IB = &(*border_chars)[BV_bip]; + */ IT = &(*border_chars)[TI_bip]; IB = &(*border_chars)[BI_bip]; II = &(*border_chars)[IH_bip]; @@ -357,11 +361,14 @@ int print_row_separator(char *buffer, size_t buffer_sz, size_t i = 0; - /* If all chars are not printable, skip line separator */ /* todo: add processing for wchar_t */ -// if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { -// status = 0; -// goto clear; -// } + /* If all chars are not printable, skip line separator */ + /* todo: add processing for wchar_t */ + /* + if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { + status = 0; + goto clear; + } + */ if ((strlen(*L) == 0 || (strlen(*L) == 1 && !isprint(**L))) && (strlen(*I) == 0 || (strlen(*I) == 1 && !isprint(**I))) && (strlen(*IV) == 0 || (strlen(*IV) == 1 && !isprint(**IV))) @@ -516,8 +523,10 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz, IV = &(*border_chars)[II_bip]; R = &(*border_chars)[RH_bip]; -// IT = &(*border_chars)[TV_bip]; -// IB = &(*border_chars)[BV_bip]; + /* + IT = &(*border_chars)[TV_bip]; + IB = &(*border_chars)[BV_bip]; + */ IT = &(*border_chars)[TI_bip]; IB = &(*border_chars)[BI_bip]; II = &(*border_chars)[IH_bip]; @@ -539,11 +548,14 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz, size_t i = 0; - /* If all chars are not printable, skip line separator */ /* todo: add processing for wchar_t */ -// if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { -// status = 0; -// goto clear; -// } + /* If all chars are not printable, skip line separator */ + /* todo: add processing for wchar_t */ + /* + if (!isprint(*L) && !isprint(*I) && !isprint(*IV) && !isprint(*R)) { + status = 0; + goto clear; + } + */ if ((strlen(*L) == 0 || (strlen(*L) == 1 && !isprint(**L))) && (strlen(*I) == 0 || (strlen(*I) == 1 && !isprint(**I))) && (strlen(*IV) == 0 || (strlen(*IV) == 1 && !isprint(**IV)))