From 535641cddf9bd99efc264055b85d4548a1767559 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Sat, 27 Apr 2019 16:00:20 +0300 Subject: [PATCH] [A] Added more builds --- CMakeLists.txt | 16 +++++++++++ example/main.c | 2 +- lib/fort.c | 71 ++++++++++++++++++++++++++----------------------- lib/fort.h | 30 ++++++++++----------- lib/fort.hpp | 2 +- src/fort.h | 30 ++++++++++----------- src/fort.hpp | 2 +- src/fort_impl.c | 71 ++++++++++++++++++++++++++----------------------- 8 files changed, 125 insertions(+), 99 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a49e75..c6f6227 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,6 +110,22 @@ if("${FORT_COMPILER}" STREQUAL "GNU") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=gold") endif() +# ------------------------------------------------------------------------------ +# Disable NDEBUG for all builds +# ------------------------------------------------------------------------------ +foreach(flags_var_to_scrub + CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_RELWITHDEBINFO + CMAKE_CXX_FLAGS_MINSIZEREL + CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_RELWITHDEBINFO + CMAKE_C_FLAGS_MINSIZEREL + ) + string (REGEX REPLACE "(^| )[/-]D *NDEBUG($| )" " " + "${flags_var_to_scrub}" "${${flags_var_to_scrub}}") +endforeach() + + # ------------------------------------------------------------------------------ # Add WChar support for the build # ------------------------------------------------------------------------------ diff --git a/example/main.c b/example/main.c index d0eb77c..2ce29ae 100644 --- a/example/main.c +++ b/example/main.c @@ -244,7 +244,7 @@ void print_different_border_styles() ft_set_cell_prop(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_CPROP_TOP_PADDING, 3); ft_set_cell_prop(table, FT_ANY_ROW, 1, FT_CPROP_LEFT_PADDING, 10); - struct ft_border_style *styles[] = { + const struct ft_border_style *styles[] = { FT_BASIC_STYLE, FT_BASIC2_STYLE, FT_SIMPLE_STYLE, diff --git a/lib/fort.c b/lib/fort.c index aaf96f7..d8fe61f 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -1967,44 +1967,49 @@ int ft_add_separator(ft_table_t *table) return FT_SUCCESS; } +static const struct fort_border_style * built_in_styles[] = { + &FORT_BASIC_STYLE, + &FORT_BASIC2_STYLE, + &FORT_SIMPLE_STYLE, + &FORT_PLAIN_STYLE, + &FORT_DOT_STYLE, + &FORT_EMPTY_STYLE, + &FORT_EMPTY2_STYLE, + &FORT_SOLID_STYLE, + &FORT_SOLID_ROUND_STYLE, + &FORT_NICE_STYLE, + &FORT_DOUBLE_STYLE, + &FORT_DOUBLE2_STYLE, + &FORT_BOLD_STYLE, + &FORT_BOLD2_STYLE, + &FORT_FRAME_STYLE, +}; +#define BUILT_IN_STYLES_SZ (sizeof(built_in_styles) / sizeof(built_in_styles[0])) +/* todo: remove this stupide and dangerous code */ +static const struct ft_border_style built_in_external_styles[BUILT_IN_STYLES_SZ]; -struct ft_border_style *const FT_BASIC_STYLE = (struct ft_border_style *) &FORT_BASIC_STYLE; -struct ft_border_style *const FT_BASIC2_STYLE = (struct ft_border_style *) &FORT_BASIC2_STYLE; -struct ft_border_style *const FT_SIMPLE_STYLE = (struct ft_border_style *) &FORT_SIMPLE_STYLE; -struct ft_border_style *const FT_PLAIN_STYLE = (struct ft_border_style *) &FORT_PLAIN_STYLE; -struct ft_border_style *const FT_DOT_STYLE = (struct ft_border_style *) &FORT_DOT_STYLE; -struct ft_border_style *const FT_EMPTY_STYLE = (struct ft_border_style *) &FORT_EMPTY_STYLE; -struct ft_border_style *const FT_EMPTY2_STYLE = (struct ft_border_style *) &FORT_EMPTY2_STYLE; -struct ft_border_style *const FT_SOLID_STYLE = (struct ft_border_style *) &FORT_SOLID_STYLE; -struct ft_border_style *const FT_SOLID_ROUND_STYLE = (struct ft_border_style *) &FORT_SOLID_ROUND_STYLE; -struct ft_border_style *const FT_NICE_STYLE = (struct ft_border_style *) &FORT_NICE_STYLE; -struct ft_border_style *const FT_DOUBLE_STYLE = (struct ft_border_style *) &FORT_DOUBLE_STYLE; -struct ft_border_style *const FT_DOUBLE2_STYLE = (struct ft_border_style *) &FORT_DOUBLE2_STYLE; -struct ft_border_style *const FT_BOLD_STYLE = (struct ft_border_style *) &FORT_BOLD_STYLE; -struct ft_border_style *const FT_BOLD2_STYLE = (struct ft_border_style *) &FORT_BOLD2_STYLE; -struct ft_border_style *const FT_FRAME_STYLE = (struct ft_border_style *) &FORT_FRAME_STYLE; - - +const struct ft_border_style *const FT_BASIC_STYLE = &built_in_external_styles[0]; +const struct ft_border_style *const FT_BASIC2_STYLE = &built_in_external_styles[1]; +const struct ft_border_style *const FT_SIMPLE_STYLE = &built_in_external_styles[2]; +const struct ft_border_style *const FT_PLAIN_STYLE = &built_in_external_styles[3]; +const struct ft_border_style *const FT_DOT_STYLE = &built_in_external_styles[4]; +const struct ft_border_style *const FT_EMPTY_STYLE = &built_in_external_styles[5]; +const struct ft_border_style *const FT_EMPTY2_STYLE = &built_in_external_styles[6]; +const struct ft_border_style *const FT_SOLID_STYLE = &built_in_external_styles[7]; +const struct ft_border_style *const FT_SOLID_ROUND_STYLE = &built_in_external_styles[8]; +const struct ft_border_style *const FT_NICE_STYLE = &built_in_external_styles[9]; +const struct ft_border_style *const FT_DOUBLE_STYLE = &built_in_external_styles[10]; +const struct ft_border_style *const FT_DOUBLE2_STYLE = &built_in_external_styles[11]; +const struct ft_border_style *const FT_BOLD_STYLE = &built_in_external_styles[12]; +const struct ft_border_style *const FT_BOLD2_STYLE = &built_in_external_styles[13]; +const struct ft_border_style *const FT_FRAME_STYLE = &built_in_external_styles[14]; static void set_border_props_for_props(fort_table_properties_t *properties, const struct ft_border_style *style) { - if ((const struct fort_border_style *)style == &FORT_BASIC_STYLE - || (const struct fort_border_style *)style == &FORT_BASIC2_STYLE - || (const struct fort_border_style *)style == &FORT_SIMPLE_STYLE - || (const struct fort_border_style *)style == &FORT_DOT_STYLE - || (const struct fort_border_style *)style == &FORT_PLAIN_STYLE - || (const struct fort_border_style *)style == &FORT_EMPTY_STYLE - || (const struct fort_border_style *)style == &FORT_EMPTY2_STYLE - || (const struct fort_border_style *)style == &FORT_SOLID_STYLE - || (const struct fort_border_style *)style == &FORT_SOLID_ROUND_STYLE - || (const struct fort_border_style *)style == &FORT_NICE_STYLE - || (const struct fort_border_style *)style == &FORT_DOUBLE_STYLE - || (const struct fort_border_style *)style == &FORT_DOUBLE2_STYLE - || (const struct fort_border_style *)style == &FORT_BOLD_STYLE - || (const struct fort_border_style *)style == &FORT_BOLD2_STYLE - || (const struct fort_border_style *)style == &FORT_FRAME_STYLE) { - memcpy(&(properties->border_style), (const struct fort_border_style *)style, sizeof(struct fort_border_style)); + if (style >= built_in_external_styles && style < (built_in_external_styles + BUILT_IN_STYLES_SZ)) { + size_t pos = (size_t)(style - built_in_external_styles); + memcpy(&(properties->border_style), built_in_styles[pos], sizeof(struct fort_border_style)); return; } diff --git a/lib/fort.h b/lib/fort.h index 897c838..ce4e78a 100644 --- a/lib/fort.h +++ b/lib/fort.h @@ -616,21 +616,21 @@ struct ft_border_style { * @name Built-in table border styles. * @{ */ -extern struct ft_border_style *const FT_BASIC_STYLE; -extern struct ft_border_style *const FT_BASIC2_STYLE; -extern struct ft_border_style *const FT_SIMPLE_STYLE; -extern struct ft_border_style *const FT_PLAIN_STYLE; -extern struct ft_border_style *const FT_DOT_STYLE; -extern struct ft_border_style *const FT_EMPTY_STYLE; -extern struct ft_border_style *const FT_EMPTY2_STYLE; -extern struct ft_border_style *const FT_SOLID_STYLE; -extern struct ft_border_style *const FT_SOLID_ROUND_STYLE; -extern struct ft_border_style *const FT_NICE_STYLE; -extern struct ft_border_style *const FT_DOUBLE_STYLE; -extern struct ft_border_style *const FT_DOUBLE2_STYLE; -extern struct ft_border_style *const FT_BOLD_STYLE; -extern struct ft_border_style *const FT_BOLD2_STYLE; -extern struct ft_border_style *const FT_FRAME_STYLE; +extern const struct ft_border_style *const FT_BASIC_STYLE; +extern const struct ft_border_style *const FT_BASIC2_STYLE; +extern const struct ft_border_style *const FT_SIMPLE_STYLE; +extern const struct ft_border_style *const FT_PLAIN_STYLE; +extern const struct ft_border_style *const FT_DOT_STYLE; +extern const struct ft_border_style *const FT_EMPTY_STYLE; +extern const struct ft_border_style *const FT_EMPTY2_STYLE; +extern const struct ft_border_style *const FT_SOLID_STYLE; +extern const struct ft_border_style *const FT_SOLID_ROUND_STYLE; +extern const struct ft_border_style *const FT_NICE_STYLE; +extern const struct ft_border_style *const FT_DOUBLE_STYLE; +extern const struct ft_border_style *const FT_DOUBLE2_STYLE; +extern const struct ft_border_style *const FT_BOLD_STYLE; +extern const struct ft_border_style *const FT_BOLD2_STYLE; +extern const struct ft_border_style *const FT_FRAME_STYLE; /** @} */ diff --git a/lib/fort.hpp b/lib/fort.hpp index bd7598f..e34933f 100644 --- a/lib/fort.hpp +++ b/lib/fort.hpp @@ -763,7 +763,7 @@ public: * - True: Success; table border style was changed. * - False: Error */ - bool set_border_style(struct ft_border_style *style) + bool set_border_style(const struct ft_border_style *style) { return FT_IS_SUCCESS(ft_set_border_style(table_, style)); } diff --git a/src/fort.h b/src/fort.h index 897c838..ce4e78a 100644 --- a/src/fort.h +++ b/src/fort.h @@ -616,21 +616,21 @@ struct ft_border_style { * @name Built-in table border styles. * @{ */ -extern struct ft_border_style *const FT_BASIC_STYLE; -extern struct ft_border_style *const FT_BASIC2_STYLE; -extern struct ft_border_style *const FT_SIMPLE_STYLE; -extern struct ft_border_style *const FT_PLAIN_STYLE; -extern struct ft_border_style *const FT_DOT_STYLE; -extern struct ft_border_style *const FT_EMPTY_STYLE; -extern struct ft_border_style *const FT_EMPTY2_STYLE; -extern struct ft_border_style *const FT_SOLID_STYLE; -extern struct ft_border_style *const FT_SOLID_ROUND_STYLE; -extern struct ft_border_style *const FT_NICE_STYLE; -extern struct ft_border_style *const FT_DOUBLE_STYLE; -extern struct ft_border_style *const FT_DOUBLE2_STYLE; -extern struct ft_border_style *const FT_BOLD_STYLE; -extern struct ft_border_style *const FT_BOLD2_STYLE; -extern struct ft_border_style *const FT_FRAME_STYLE; +extern const struct ft_border_style *const FT_BASIC_STYLE; +extern const struct ft_border_style *const FT_BASIC2_STYLE; +extern const struct ft_border_style *const FT_SIMPLE_STYLE; +extern const struct ft_border_style *const FT_PLAIN_STYLE; +extern const struct ft_border_style *const FT_DOT_STYLE; +extern const struct ft_border_style *const FT_EMPTY_STYLE; +extern const struct ft_border_style *const FT_EMPTY2_STYLE; +extern const struct ft_border_style *const FT_SOLID_STYLE; +extern const struct ft_border_style *const FT_SOLID_ROUND_STYLE; +extern const struct ft_border_style *const FT_NICE_STYLE; +extern const struct ft_border_style *const FT_DOUBLE_STYLE; +extern const struct ft_border_style *const FT_DOUBLE2_STYLE; +extern const struct ft_border_style *const FT_BOLD_STYLE; +extern const struct ft_border_style *const FT_BOLD2_STYLE; +extern const struct ft_border_style *const FT_FRAME_STYLE; /** @} */ diff --git a/src/fort.hpp b/src/fort.hpp index bd7598f..e34933f 100644 --- a/src/fort.hpp +++ b/src/fort.hpp @@ -763,7 +763,7 @@ public: * - True: Success; table border style was changed. * - False: Error */ - bool set_border_style(struct ft_border_style *style) + bool set_border_style(const struct ft_border_style *style) { return FT_IS_SUCCESS(ft_set_border_style(table_, style)); } diff --git a/src/fort_impl.c b/src/fort_impl.c index 5a457ac..0ae7856 100644 --- a/src/fort_impl.c +++ b/src/fort_impl.c @@ -806,44 +806,49 @@ int ft_add_separator(ft_table_t *table) return FT_SUCCESS; } +static const struct fort_border_style * built_in_styles[] = { + &FORT_BASIC_STYLE, + &FORT_BASIC2_STYLE, + &FORT_SIMPLE_STYLE, + &FORT_PLAIN_STYLE, + &FORT_DOT_STYLE, + &FORT_EMPTY_STYLE, + &FORT_EMPTY2_STYLE, + &FORT_SOLID_STYLE, + &FORT_SOLID_ROUND_STYLE, + &FORT_NICE_STYLE, + &FORT_DOUBLE_STYLE, + &FORT_DOUBLE2_STYLE, + &FORT_BOLD_STYLE, + &FORT_BOLD2_STYLE, + &FORT_FRAME_STYLE, +}; +#define BUILT_IN_STYLES_SZ (sizeof(built_in_styles) / sizeof(built_in_styles[0])) +/* todo: remove this stupide and dangerous code */ +static const struct ft_border_style built_in_external_styles[BUILT_IN_STYLES_SZ]; -struct ft_border_style *const FT_BASIC_STYLE = (struct ft_border_style *) &FORT_BASIC_STYLE; -struct ft_border_style *const FT_BASIC2_STYLE = (struct ft_border_style *) &FORT_BASIC2_STYLE; -struct ft_border_style *const FT_SIMPLE_STYLE = (struct ft_border_style *) &FORT_SIMPLE_STYLE; -struct ft_border_style *const FT_PLAIN_STYLE = (struct ft_border_style *) &FORT_PLAIN_STYLE; -struct ft_border_style *const FT_DOT_STYLE = (struct ft_border_style *) &FORT_DOT_STYLE; -struct ft_border_style *const FT_EMPTY_STYLE = (struct ft_border_style *) &FORT_EMPTY_STYLE; -struct ft_border_style *const FT_EMPTY2_STYLE = (struct ft_border_style *) &FORT_EMPTY2_STYLE; -struct ft_border_style *const FT_SOLID_STYLE = (struct ft_border_style *) &FORT_SOLID_STYLE; -struct ft_border_style *const FT_SOLID_ROUND_STYLE = (struct ft_border_style *) &FORT_SOLID_ROUND_STYLE; -struct ft_border_style *const FT_NICE_STYLE = (struct ft_border_style *) &FORT_NICE_STYLE; -struct ft_border_style *const FT_DOUBLE_STYLE = (struct ft_border_style *) &FORT_DOUBLE_STYLE; -struct ft_border_style *const FT_DOUBLE2_STYLE = (struct ft_border_style *) &FORT_DOUBLE2_STYLE; -struct ft_border_style *const FT_BOLD_STYLE = (struct ft_border_style *) &FORT_BOLD_STYLE; -struct ft_border_style *const FT_BOLD2_STYLE = (struct ft_border_style *) &FORT_BOLD2_STYLE; -struct ft_border_style *const FT_FRAME_STYLE = (struct ft_border_style *) &FORT_FRAME_STYLE; - - +const struct ft_border_style *const FT_BASIC_STYLE = &built_in_external_styles[0]; +const struct ft_border_style *const FT_BASIC2_STYLE = &built_in_external_styles[1]; +const struct ft_border_style *const FT_SIMPLE_STYLE = &built_in_external_styles[2]; +const struct ft_border_style *const FT_PLAIN_STYLE = &built_in_external_styles[3]; +const struct ft_border_style *const FT_DOT_STYLE = &built_in_external_styles[4]; +const struct ft_border_style *const FT_EMPTY_STYLE = &built_in_external_styles[5]; +const struct ft_border_style *const FT_EMPTY2_STYLE = &built_in_external_styles[6]; +const struct ft_border_style *const FT_SOLID_STYLE = &built_in_external_styles[7]; +const struct ft_border_style *const FT_SOLID_ROUND_STYLE = &built_in_external_styles[8]; +const struct ft_border_style *const FT_NICE_STYLE = &built_in_external_styles[9]; +const struct ft_border_style *const FT_DOUBLE_STYLE = &built_in_external_styles[10]; +const struct ft_border_style *const FT_DOUBLE2_STYLE = &built_in_external_styles[11]; +const struct ft_border_style *const FT_BOLD_STYLE = &built_in_external_styles[12]; +const struct ft_border_style *const FT_BOLD2_STYLE = &built_in_external_styles[13]; +const struct ft_border_style *const FT_FRAME_STYLE = &built_in_external_styles[14]; static void set_border_props_for_props(fort_table_properties_t *properties, const struct ft_border_style *style) { - if ((const struct fort_border_style *)style == &FORT_BASIC_STYLE - || (const struct fort_border_style *)style == &FORT_BASIC2_STYLE - || (const struct fort_border_style *)style == &FORT_SIMPLE_STYLE - || (const struct fort_border_style *)style == &FORT_DOT_STYLE - || (const struct fort_border_style *)style == &FORT_PLAIN_STYLE - || (const struct fort_border_style *)style == &FORT_EMPTY_STYLE - || (const struct fort_border_style *)style == &FORT_EMPTY2_STYLE - || (const struct fort_border_style *)style == &FORT_SOLID_STYLE - || (const struct fort_border_style *)style == &FORT_SOLID_ROUND_STYLE - || (const struct fort_border_style *)style == &FORT_NICE_STYLE - || (const struct fort_border_style *)style == &FORT_DOUBLE_STYLE - || (const struct fort_border_style *)style == &FORT_DOUBLE2_STYLE - || (const struct fort_border_style *)style == &FORT_BOLD_STYLE - || (const struct fort_border_style *)style == &FORT_BOLD2_STYLE - || (const struct fort_border_style *)style == &FORT_FRAME_STYLE) { - memcpy(&(properties->border_style), (const struct fort_border_style *)style, sizeof(struct fort_border_style)); + if (style >= built_in_external_styles && style < (built_in_external_styles + BUILT_IN_STYLES_SZ)) { + size_t pos = (size_t)(style - built_in_external_styles); + memcpy(&(properties->border_style), built_in_styles[pos], sizeof(struct fort_border_style)); return; }