From: Kevin Day Date: Sat, 15 Jan 2022 23:01:53 +0000 (-0600) Subject: Update: Lay out the foundation for proper endianness support. X-Git-Tag: 0.5.8~115 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=f6b0c3f8408cc428777079cbe5e79fd1d22d6721;p=fll Update: Lay out the foundation for proper endianness support. The endianness support is not currently a direct goal of the 0.4 versions. The 0.6 versions will deal with networking and will most certainly need proper endianness support. Ultimate the FLL needs to properly handle endianness. Provide the initial functionality needed to make this possible. The BIG_ENDIAN and LITTLE_ENDIAN cannot be directly relied on. Provide custom _is_F_endian_big and _is_F_endian_little macros where when BIG_ENDIAN is not defined default to little endian. By using the custom _is_F_endian_big and _is_F_endian_little, allow for the endianness to be explicit set at compile time. This should make it easy to configure in cases where BIG_ENDIAN and LITTLE_ENDIAN are not defined. --- diff --git a/level_0/f_status/c/status.h b/level_0/f_status/c/status.h index 3e134fd..d9ab37f 100644 --- a/level_0/f_status/c/status.h +++ b/level_0/f_status/c/status.h @@ -20,9 +20,27 @@ extern "C" { #endif /** + * Endianness. + * + * This is placed here because status is first and endianness must be set before everything else. + * + * Define either _is_F_endian_big or _is_F_endian_little (but not both) to override compiler detected endianness or to manually set endianness if not detected. + */ +#if !defined(_is_F_endian_big) && !defined(_is_F_endian_little) + #ifdef BIG_ENDIAN + #define _is_F_endian_big + #undef _is_F_endian_little + #else + #undef _is_F_endian_big + #define _is_F_endian_little + #endif // BIG_ENDIAN +#endif // !defined(_is_F_endian_big) && !defined(_is_F_endian_little) + +/** * Status masks. */ #ifndef _di_F_status_masks_ + // f_status_t is required to be exactly 16 bits, the first two high order bits represent error and warning respectively. #define F_status_bit_error 0x8000 // 1000 0000 0000 0000 #define F_status_bit_signal 0xc000 // 1100 0000 0000 0000 @@ -209,6 +227,10 @@ extern "C" { F_encoding_not, F_end, F_end_not, + F_endian, + F_endian_big, + F_endian_little, + F_endian_not, F_eoa, F_eoa_not, F_eof, diff --git a/level_0/f_status_string/c/status_string.c b/level_0/f_status_string/c/status_string.c index c089026..036dd4e 100644 --- a/level_0/f_status_string/c/status_string.c +++ b/level_0/f_status_string/c/status_string.c @@ -143,6 +143,10 @@ extern "C" { const f_string_t f_status_encoding_not_s = F_status_encoding_not_s; const f_string_t f_status_end_s = F_status_end_s; const f_string_t f_status_end_not_s = F_status_end_not_s; + const f_string_t f_status_endian_s = F_status_endian_s; + const f_string_t f_status_endian_big_s = F_status_endian_big_s; + const f_string_t f_status_endian_little_s = F_status_endian_little_s; + const f_string_t f_status_endian_not_s = F_status_endian_not_s; const f_string_t f_status_eoa_s = F_status_eoa_s; const f_string_t f_status_eoa_not_s = F_status_eoa_not_s; const f_string_t f_status_eof_s = F_status_eof_s; @@ -1120,6 +1124,22 @@ extern "C" { *string = f_status_end_not_s; break; + case F_endian: + *string = f_status_endian_s; + break; + + case F_endian_big: + *string = f_status_endian_big_s; + break; + + case F_endian_little: + *string = f_status_endian_little_s; + break; + + case F_endian_not: + *string = f_status_endian_not_s; + break; + case F_eoa: *string = f_status_eoa_s; break; diff --git a/level_0/f_status_string/c/status_string.h b/level_0/f_status_string/c/status_string.h index ec28f3f..7d6f8cc 100644 --- a/level_0/f_status_string/c/status_string.h +++ b/level_0/f_status_string/c/status_string.h @@ -296,6 +296,10 @@ extern "C" { #define F_status_encoding_not_s "F_encoding_not" #define F_status_end_s "F_end" #define F_status_end_not_s "F_end_not" + #define F_status_endian_s "F_endian" + #define F_status_endian_big_s "F_endian_big" + #define F_status_endian_little_s "F_endian_little" + #define F_status_endian_not_s "F_endian_not" #define F_status_eoa_s "F_eoa" #define F_status_eoa_not_s "F_eoa_not" #define F_status_eof_s "F_eof" @@ -536,6 +540,10 @@ extern "C" { #define F_status_encoding_not_s_length 14 #define F_status_end_s_length 5 #define F_status_end_not_s_length 9 + #define F_status_endian_s_length 8 + #define F_status_endian_big_s_length 12 + #define F_status_endian_little_s_length 19 + #define F_status_endian_not_s_length 12 #define F_status_eoa_s_length 5 #define F_status_eoa_not_s_length 9 #define F_status_eof_s_length 5 @@ -776,6 +784,10 @@ extern "C" { extern const f_string_t f_status_encoding_not_s; extern const f_string_t f_status_end_s; extern const f_string_t f_status_end_not_s; + extern const f_string_t f_status_endian_s; + extern const f_string_t f_status_endian_big_s; + extern const f_string_t f_status_endian_little_s; + extern const f_string_t f_status_endian_not_s; extern const f_string_t f_status_eoa_s; extern const f_string_t f_status_eoa_not_s; extern const f_string_t f_status_eof_s; diff --git a/level_0/f_string/c/string-common.h b/level_0/f_string/c/string-common.h index 639dde2..479bc0a 100644 --- a/level_0/f_string/c/string-common.h +++ b/level_0/f_string/c/string-common.h @@ -80,6 +80,7 @@ extern "C" { #ifndef _di_f_string_eol_s_ #define f_string_eol_s f_string_ascii_feed_line_s #define F_string_eol_s F_string_ascii_feed_line_s + #define F_string_eol_s_length 1 #endif // _di_f_string_eol_s_ @@ -90,12 +91,14 @@ extern "C" { #ifndef _di_f_string_placeholder_s_ #define f_string_placeholder_s f_string_empty_s #define F_string_placeholder_s F_string_empty_s + #define F_string_placeholder_s_length 1 #endif // _di_f_string_placeholder_s_ #ifndef _di_f_string_space_s_ #define f_string_space_s f_string_ascii_space_s #define F_string_space_s F_string_ascii_space_s + #define F_string_space_s_length 1 #endif // _di_f_string_space_s_ diff --git a/level_2/fll_status_string/c/status_string.c b/level_2/fll_status_string/c/status_string.c index df898df..5c3d2eb 100644 --- a/level_2/fll_status_string/c/status_string.c +++ b/level_2/fll_status_string/c/status_string.c @@ -817,6 +817,30 @@ extern "C" { return F_none; } + if (fl_string_compare(string, f_status_endian_s, length, F_status_endian_s_length) == F_equal_to) { + *code = F_endian; + + return F_none; + } + + if (fl_string_compare(string, f_status_endian_big_s, length, F_status_endian_big_s_length) == F_equal_to) { + *code = F_endian_big; + + return F_none; + } + + if (fl_string_compare(string, f_status_endian_little_s, length, F_status_endian_little_s_length) == F_equal_to) { + *code = F_endian_little; + + return F_none; + } + + if (fl_string_compare(string, f_status_endian_not_s, length, F_status_endian_not_s_length) == F_equal_to) { + *code = F_endian_not; + + return F_none; + } + if (fl_string_compare(string, f_status_eoa_s, length, F_status_eoa_s_length) == F_equal_to) { *code = F_eoa;