From: Kevin Day Date: Fri, 30 Dec 2022 15:43:42 +0000 (-0600) Subject: Update: Use an enumeration rather than a define macro for the conversion flags. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=c8dcf37ac1eb48af868d6a27f3b641ad775d9ad4;p=fll Update: Use an enumeration rather than a define macro for the conversion flags. --- diff --git a/level_1/fl_conversion/c/conversion/common.c b/level_1/fl_conversion/c/conversion/common.c index 6289e98..c06455e 100644 --- a/level_1/fl_conversion/c/conversion/common.c +++ b/level_1/fl_conversion/c/conversion/common.c @@ -26,11 +26,11 @@ extern "C" { #endif // _di_fl_conversion_data_base_16_c_ #ifndef _di_fl_conversion_data_endian_big_c_ - const fl_conversion_data_t fl_conversion_data_endian_big_c = macro_fl_conversion_data_t_initialize(10, FL_conversion_data_flag_endian_big_d); + const fl_conversion_data_t fl_conversion_data_endian_big_c = macro_fl_conversion_data_t_initialize(10, fl_conversion_data_flag_endian_big_e); #endif // _di_fl_conversion_data_endian_big_c_ #ifndef _di_fl_conversion_data_endian_little_c_ - const fl_conversion_data_t fl_conversion_data_endian_little_c = macro_fl_conversion_data_t_initialize(10, FL_conversion_data_flag_endian_little_d); + const fl_conversion_data_t fl_conversion_data_endian_little_c = macro_fl_conversion_data_t_initialize(10, fl_conversion_data_flag_endian_little_e); #endif // _di_fl_conversion_data_endian_little_c_ #endif // _di_fl_conversion_data_c_ diff --git a/level_1/fl_conversion/c/conversion/common.h b/level_1/fl_conversion/c/conversion/common.h index 214038a..6f7d680 100644 --- a/level_1/fl_conversion/c/conversion/common.h +++ b/level_1/fl_conversion/c/conversion/common.h @@ -88,11 +88,13 @@ extern "C" { * - endian_little: Use little-endian rather than host byte order or big-endian when converting. * - negative: Treat the string as a negative number. */ -#ifndef _di_fl_conversion_data_flag_d_ - #define FL_conversion_data_flag_endian_big_d 0x1 - #define FL_conversion_data_flag_endian_little_d 0x2 - #define FL_conversion_data_flag_negative_d 0x4 -#endif // _di_fl_conversion_data_flag_d_ +#ifndef _di_fl_conversion_data_flag_e_ + enum { + fl_conversion_data_flag_endian_big_e = 0x1, + fl_conversion_data_flag_endian_little_e = 0x2, + fl_conversion_data_flag_negative_e = 0x4, + }; +#endif // _di_fl_conversion_data_flag_e_ #ifdef __cplusplus } // extern "C" diff --git a/level_1/fl_conversion/c/private-conversion.c b/level_1/fl_conversion/c/private-conversion.c index 5d8439f..1383fcf 100644 --- a/level_1/fl_conversion/c/private-conversion.c +++ b/level_1/fl_conversion/c/private-conversion.c @@ -22,15 +22,15 @@ extern "C" { if (digits) { ++digits; - if (flag & FL_conversion_data_flag_negative_d) { + if (flag & fl_conversion_data_flag_negative_e) { if (digits > F_conversion_digits_binary_signed_d) { return F_status_set_error(F_number_underflow); } - if (flag & FL_conversion_data_flag_endian_big_d) { + if (flag & fl_conversion_data_flag_endian_big_e) { converted >>= 1; } - else if (flag & FL_conversion_data_flag_endian_little_d) { + else if (flag & fl_conversion_data_flag_endian_little_e) { converted <<= 1; } else { @@ -48,10 +48,10 @@ extern "C" { return F_status_set_error(F_number_overflow); } - if (flag & FL_conversion_data_flag_endian_big_d) { + if (flag & fl_conversion_data_flag_endian_big_e) { converted >>= 1; } - else if (flag & FL_conversion_data_flag_endian_little_d) { + else if (flag & fl_conversion_data_flag_endian_little_e) { converted <<= 1; } else { @@ -68,7 +68,7 @@ extern "C" { else if (digit) { digits = 1; - if (flag & FL_conversion_data_flag_negative_d) { + if (flag & fl_conversion_data_flag_negative_e) { converted = (f_number_unsigned_t) (0 - digit); } else { @@ -108,10 +108,10 @@ extern "C" { return F_status_set_error(F_number_overflow); } - if (flag & FL_conversion_data_flag_endian_big_d) { + if (flag & fl_conversion_data_flag_endian_big_e) { converted >>= 1; } - else if (flag & FL_conversion_data_flag_endian_little_d) { + else if (flag & fl_conversion_data_flag_endian_little_e) { converted <<= 1; } else { @@ -172,7 +172,7 @@ extern "C" { if (digits) { ++digits; - if (data.flag & FL_conversion_data_flag_negative_d) { + if (data.flag & fl_conversion_data_flag_negative_e) { if (digits > F_conversion_digits_decimal_signed_d) { if ((converted * data.base) - digit < F_number_t_size_negative_d || (converted * data.base) - digit > converted) { return F_status_set_error(F_number_underflow); @@ -196,7 +196,7 @@ extern "C" { else if (digit) { digits = 1; - if (data.flag & FL_conversion_data_flag_negative_d) { + if (data.flag & fl_conversion_data_flag_negative_e) { converted = (f_number_unsigned_t) (0 - digit); } else { @@ -211,7 +211,7 @@ extern "C" { // Ensure bytes are in correct order by reversing bytes if requested byte order is different than the host byte order. #ifdef _is_F_endian_big - if (data.flag & FL_conversion_data_flag_endian_little_d) { + if (data.flag & fl_conversion_data_flag_endian_little_e) { *number = macro_f_utf_char_t_from_char_1_le(macro_f_utf_char_t_to_char_1_be(converted)) | macro_f_utf_char_t_from_char_2_le(macro_f_utf_char_t_to_char_2_be(converted)) | macro_f_utf_char_t_from_char_3_le(macro_f_utf_char_t_to_char_3_be(converted)) @@ -220,7 +220,7 @@ extern "C" { return F_none; } #else - if (data.flag & FL_conversion_data_flag_endian_big_d) { + if (data.flag & fl_conversion_data_flag_endian_big_e) { *number = macro_f_utf_char_t_from_char_1_be(macro_f_utf_char_t_to_char_1_le(converted)) | macro_f_utf_char_t_from_char_2_be(macro_f_utf_char_t_to_char_2_le(converted)) | macro_f_utf_char_t_from_char_3_be(macro_f_utf_char_t_to_char_3_le(converted)) @@ -289,7 +289,7 @@ extern "C" { // Ensure bytes are in correct order by reversing bytes if requested byte order is different than the host byte order. #ifdef _is_F_endian_big - if (data.flag & FL_conversion_data_flag_endian_little_d) { + if (data.flag & fl_conversion_data_flag_endian_little_e) { *number = macro_f_utf_char_t_from_char_1_le(macro_f_utf_char_t_to_char_1_be(converted)) | macro_f_utf_char_t_from_char_2_le(macro_f_utf_char_t_to_char_2_be(converted)) | macro_f_utf_char_t_from_char_3_le(macro_f_utf_char_t_to_char_3_be(converted)) @@ -298,7 +298,7 @@ extern "C" { return F_none; } #else - if (data.flag & FL_conversion_data_flag_endian_big_d) { + if (data.flag & fl_conversion_data_flag_endian_big_e) { *number = macro_f_utf_char_t_from_char_1_be(macro_f_utf_char_t_to_char_1_le(converted)) | macro_f_utf_char_t_from_char_2_be(macro_f_utf_char_t_to_char_2_le(converted)) | macro_f_utf_char_t_from_char_3_be(macro_f_utf_char_t_to_char_3_le(converted)) @@ -453,10 +453,10 @@ extern "C" { fl_conversion_data_t data = macro_fl_conversion_data_t_initialize(mode, flag); if (vector == -1) { - data.flag |= FL_conversion_data_flag_negative_d; + data.flag |= fl_conversion_data_flag_negative_e; } - else if (data.flag & FL_conversion_data_flag_negative_d) { - data.flag -= FL_conversion_data_flag_negative_d; + else if (data.flag & fl_conversion_data_flag_negative_e) { + data.flag -= fl_conversion_data_flag_negative_e; } if (mode == 10 || mode == 16 || mode == 12 || mode == 8) { @@ -596,8 +596,8 @@ extern "C" { fl_conversion_data_t data = macro_fl_conversion_data_t_initialize(mode, flag); - if (data.flag & FL_conversion_data_flag_negative_d) { - data.flag -= FL_conversion_data_flag_negative_d; + if (data.flag & fl_conversion_data_flag_negative_e) { + data.flag -= fl_conversion_data_flag_negative_e; } if (mode == 10 || mode == 16 || mode == 12 || mode == 8) {