diff options
-rw-r--r-- | changelog.md | 7 | ||||
-rw-r--r-- | include/u8c/SIZE_C.h | 21 | ||||
-rw-r--r-- | include/u8c/col.h | 1 | ||||
-rw-r--r-- | include/u8c/dbgprint.h | 3 | ||||
-rw-r--r-- | include/u8c/fmttyp.h | 12 | ||||
-rw-r--r-- | include/u8c/geterr.h | 1 | ||||
-rw-r--r-- | include/u8c/ver.h | 2 | ||||
-rw-r--r-- | src/u8c/end.c | 1 | ||||
-rw-r--r-- | src/u8c/fmt.c | 6 | ||||
-rw-r--r-- | src/u8c/geterr.c | 4 | ||||
-rw-r--r-- | src/u8c/init.c | 5 | ||||
-rw-r--r-- | src/u8c/println.c | 3 | ||||
-rw-r--r-- | src/u8c/stat.h | 4 | ||||
-rw-r--r-- | src/u8c/u32cp.c | 1 | ||||
-rw-r--r-- | src/u8c/u32sz.c | 5 | ||||
-rw-r--r-- | src/u8c/u8dec.c | 1 | ||||
-rw-r--r-- | src/u8c/vfmt.c | 7 | ||||
-rw-r--r-- | src/u8c/vprint.c | 1 | ||||
-rw-r--r-- | txttolit.c | 7 |
19 files changed, 45 insertions, 47 deletions
diff --git a/changelog.md b/changelog.md index 9607c40..4ab3161 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,10 @@ +# 6 + +* Remove unneeded include directives. +* Update `SIZE_C` to utilise the C++23 `std::size_t` literal suffix (`uz`). +* Fix include guard in `include/u8c/stat.h`. +* Add more error messages. + # 5 * Add logo (`u8c.svg`). diff --git a/include/u8c/SIZE_C.h b/include/u8c/SIZE_C.h index 7c9d1a9..1591252 100644 --- a/include/u8c/SIZE_C.h +++ b/include/u8c/SIZE_C.h @@ -14,17 +14,13 @@ If not, see <https://www.gnu.org/licenses/>. */ /* Size constant */ -# if !defined SIZE_C +# if !defined(SIZE_C) +# if !defined(__cplusplus) # include <limits.h> -# include <stdint.h> -# if SIZE_MAX == USHRT_MAX -# if defined(__cplusplus) -/* C++ : Use variable initialisation. */ -# define SIZE_C(val) (unsigned short{val}) -# else -/* C : Use compound literal. */ -# define SIZE_C(val) ((unsigned short){val}) # endif +# if defined(__cplusplus) && __cplusplus > 0x31512l +/* C++23 has a size_t suffix. */ +# define SIZE_C(val) val ## uz # elif SIZE_MAX == UINT_MAX # define SIZE_C(val) val # elif SIZE_MAX == ULONG_MAX @@ -32,12 +28,17 @@ # elif SIZE_MAX == ULLONG_MAX # define SIZE_C(val) val ## ull # elif SIZE_MAX == UINTMAX_MAX -# define SIZE_C(val) UINTMAX_C(val) +# include <stdint.h> +# define SIZE_C(val) (UINTMAX_C(val)) # else /* Cannot match width; construct new element of type "size_t" */ # if defined(__cplusplus) +/* C++ has value initialisation. */ +# include <cstddef> # define SIZE_C(val) (std::size_t{val}) # else +/* C has compound literals. */ +# include <stddef.h> # define SIZE_C(val) ((size_t){val}) # endif # endif diff --git a/include/u8c/col.h b/include/u8c/col.h index 54a2b4e..9096608 100644 --- a/include/u8c/col.h +++ b/include/u8c/col.h @@ -16,6 +16,7 @@ /* Colour */ # if !defined(u8c_sym_col) # define u8c_sym_col +# include <stdint.h> # define u8c_col_azure (UINT32_C(0x3DA9E1)) # define u8c_col_ash (UINT32_C(0xD2D2CC)) # define u8c_col_black (UINT32_C(0x444747)) diff --git a/include/u8c/dbgprint.h b/include/u8c/dbgprint.h index 57cb219..fd7a460 100644 --- a/include/u8c/dbgprint.h +++ b/include/u8c/dbgprint.h @@ -17,13 +17,12 @@ # if !defined(u8c_dbgprint) # if defined(NDEBUG) # if defined(__cplusplus) -# define u8c_dbgprint(...) static_cast<void>(0x0); +# define u8c_dbgprint(...) (static_cast<void>(0x0)); # else # define u8c_dbgprint(...) ((void)0x0) # endif # else # include <u8c/print.h> -# include <stdint.h> # include <stdio.h> # define u8c_dbgprint(...) u8c_print(stderr,__VA_ARGS__) # endif diff --git a/include/u8c/fmttyp.h b/include/u8c/fmttyp.h index e81e774..d9b27de 100644 --- a/include/u8c/fmttyp.h +++ b/include/u8c/fmttyp.h @@ -18,12 +18,12 @@ # define u8c_sym_fmttyp enum u8c_fmttyp { u8c_fmttyp_bgcol, /* Background colour */ - u8c_fmttyp_bgcol0, /* Background colour #0 */ - u8c_fmttyp_chr, /* Character */ + u8c_fmttyp_bgcol0, /* Background colour #0 */ + u8c_fmttyp_chr, /* Character */ u8c_fmttyp_fgcol, /* Foreground colour */ - u8c_fmttyp_fgcol0, /* Foreground colour #0 */ - u8c_fmttyp_int, /* Integer */ - u8c_fmttyp_str, /* String */ - u8c_fmttyp_uint, /* Unsigned integer */ + u8c_fmttyp_fgcol0, /* Foreground colour #0 */ + u8c_fmttyp_int, /* Integer */ + u8c_fmttyp_str, /* String */ + u8c_fmttyp_uint, /* Unsigned integer */ }; # endif diff --git a/include/u8c/geterr.h b/include/u8c/geterr.h index 279f1fb..d20499f 100644 --- a/include/u8c/geterr.h +++ b/include/u8c/geterr.h @@ -16,6 +16,7 @@ /* Get error */ # if !defined(u8c_sym_geterr) # define u8c_sym_geterr +# include <stddef.h> # include <stdint.h> # if defined(__cplusplus) extern "C" { diff --git a/include/u8c/ver.h b/include/u8c/ver.h index a626a0c..c754571 100644 --- a/include/u8c/ver.h +++ b/include/u8c/ver.h @@ -16,5 +16,5 @@ /* Version */ # if !defined(u8c_ver) # include <stdint.h> -# define u8c_ver (UINT64_C(0x5)) +# define u8c_ver (UINT64_C(0x6)) # endif diff --git a/src/u8c/end.c b/src/u8c/end.c index 60ed58d..924540b 100644 --- a/src/u8c/end.c +++ b/src/u8c/end.c @@ -19,7 +19,6 @@ # include <stdint.h> # include <stdlib.h> # include <u8c/end.h> -# include <u8c/print.h> # if defined(u8c_bethrdsafe) # include <threads.h> # endif diff --git a/src/u8c/fmt.c b/src/u8c/fmt.c index dabf376..ddaaec8 100644 --- a/src/u8c/fmt.c +++ b/src/u8c/fmt.c @@ -13,13 +13,11 @@ If not, see <https://www.gnu.org/licenses/>. */ -# include <u8c/fmt.h> -# include <u8c/fmttyp.h> -# include <u8c/u8enc.h> -# include <u8c/vfmt.h> # include <stdarg.h> # include <stddef.h> # include <stdint.h> +# include <u8c/fmt.h> +# include <u8c/vfmt.h> uint_least8_t u8c_fmt(size_t * _outsz,uint_least32_t * * _out,uint_least32_t * _in,...) { va_list args; va_start(args,_in); diff --git a/src/u8c/geterr.c b/src/u8c/geterr.c index 113281e..12b5c14 100644 --- a/src/u8c/geterr.c +++ b/src/u8c/geterr.c @@ -15,10 +15,10 @@ */ # include "err.h" # include "errlock.h" +# include <stddef.h> # include <stdint.h> -# include <stdlib.h> -# include <u8c/u32cp.h> # include <u8c/geterr.h> +# include <u8c/u32cp.h> uint_least8_t u8c_geterr(size_t * _sz,uint_least32_t * * _u32) { # if defined(u8c_bethrdsafe) mtx_lock(&u8c_errlock); diff --git a/src/u8c/init.c b/src/u8c/init.c index f2d171d..e73272e 100644 --- a/src/u8c/init.c +++ b/src/u8c/init.c @@ -16,12 +16,9 @@ # include "err.h" # include "errlock.h" # include "stat.h" -# include <assert.h> +# include <stddef.h> # include <stdint.h> -# include <stdlib.h> -# include <u8c/end.h> # include <u8c/init.h> -# include <u8c/SIZE_C.h> # include <u8c/u32cp.h> # if defined(u8c_bethrdsafe) # include <threads.h> diff --git a/src/u8c/println.c b/src/u8c/println.c index 1b1830d..5865dfa 100644 --- a/src/u8c/println.c +++ b/src/u8c/println.c @@ -14,13 +14,14 @@ If not, see <https://www.gnu.org/licenses/>. */ # include "seterr.h" +# include <assert.h> # include <stdarg.h> # include <stdint.h> # include <stdio.h> # include <u8c/println.h> -# include <u8c/SIZE_C.h> # include <u8c/vprint.h> uint_least8_t u8c_println(FILE * _fp,uint_least32_t * _msg,...) { + assert(_fp != NULL); va_list args; va_start(args,_msg); if(u8c_vprint(_fp,_msg,args)) { diff --git a/src/u8c/stat.h b/src/u8c/stat.h index 92b2063..644f345 100644 --- a/src/u8c/stat.h +++ b/src/u8c/stat.h @@ -13,8 +13,8 @@ If not, see <https://www.gnu.org/licenses/>. */ -# if !defined(u8c_sym_done) -# define u8c_sym_done +# if !defined(u8c_sym_stat) +# define u8c_sym_stat # include <stdint.h> extern uint_least8_t u8c_stat; # endif diff --git a/src/u8c/u32cp.c b/src/u8c/u32cp.c index 2462d85..628e57f 100644 --- a/src/u8c/u32cp.c +++ b/src/u8c/u32cp.c @@ -15,7 +15,6 @@ */ # include "seterr.h" # include <assert.h> -# include <stddef.h> # include <stdint.h> # include <stdlib.h> # include <u8c/SIZE_C.h> diff --git a/src/u8c/u32sz.c b/src/u8c/u32sz.c index 614557c..0d4fd99 100644 --- a/src/u8c/u32sz.c +++ b/src/u8c/u32sz.c @@ -13,10 +13,10 @@ If not, see <https://www.gnu.org/licenses/>. */ +# include "seterr.h" # include <assert.h> # include <stddef.h> # include <stdint.h> -# include <stdio.h> # include <u8c/SIZE_C.h> # include <u8c/u32sz.h> uint_least8_t u8c_u32sz(size_t * _sz,uint_least32_t * _u32) { @@ -24,9 +24,10 @@ uint_least8_t u8c_u32sz(size_t * _sz,uint_least32_t * _u32) { assert(_u32 != NULL); for(size_t n = SIZE_C(0x0);n <= SIZE_MAX;n += SIZE_C(0x1)) { if(_u32[n] == UINT32_C(0x0)) { - *_sz = n += SIZE_C(0x1); + *_sz = n + SIZE_C(0x1); return UINT8_C(0x0); } } + u8c_seterr((uint_least32_t[]){UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x63),UINT32_C(0x5F),UINT32_C(0x75),UINT32_C(0x33),UINT32_C(0x32),UINT32_C(0x73),UINT32_C(0x7A),UINT32_C(0x3A),UINT32_C(0x20),UINT32_C(0x55),UINT32_C(0x6E),UINT32_C(0x74),UINT32_C(0x65),UINT32_C(0x72),UINT32_C(0x6D),UINT32_C(0x69),UINT32_C(0x6E),UINT32_C(0x61),UINT32_C(0x74),UINT32_C(0x65),UINT32_C(0x64),UINT32_C(0x20),UINT32_C(0x69),UINT32_C(0x6E),UINT32_C(0x70),UINT32_C(0x75),UINT32_C(0x74),UINT32_C(0x2E),UINT32_C(0x0),}); /* u8c_u32sz: Unterminated input. */ return UINT8_C(0x1); } diff --git a/src/u8c/u8dec.c b/src/u8c/u8dec.c index fa530ee..2447b6a 100644 --- a/src/u8c/u8dec.c +++ b/src/u8c/u8dec.c @@ -17,7 +17,6 @@ # include <assert.h> # include <stdint.h> # include <stdlib.h> -# include <u8c/dbgprint.h> # include <u8c/u8dec.h> # include <u8c/SIZE_C.h> uint_least8_t u8c_u8dec(size_t * _outsz,uint_least32_t * * _out,uint_least8_t * _in) { diff --git a/src/u8c/vfmt.c b/src/u8c/vfmt.c index c84aca2..4c00629 100644 --- a/src/u8c/vfmt.c +++ b/src/u8c/vfmt.c @@ -13,16 +13,9 @@ If not, see <https://www.gnu.org/licenses/>. */ -# include <assert.h> # include <stdarg.h> # include <stdint.h> -# include <stdio.h> -# include <stdlib.h> -# include <string.h> -# include <u8c/fmttyp.h> # include <u8c/u32cp.h> -# include <u8c/u8enc.h> -# include <u8c/SIZE_C.h> # include <u8c/vfmt.h> uint_least8_t u8c_vfmt(size_t * _outsz,uint_least32_t * * _out,uint_least32_t * _in,va_list _args) { /* To be added. */ diff --git a/src/u8c/vprint.c b/src/u8c/vprint.c index d5241b7..2eb00e0 100644 --- a/src/u8c/vprint.c +++ b/src/u8c/vprint.c @@ -19,7 +19,6 @@ # include <stdint.h> # include <stdio.h> # include <stdlib.h> -# include <u8c/col.h> # include <u8c/u8enc.h> # include <u8c/SIZE_C.h> # include <u8c/vfmt.h> @@ -8,11 +8,14 @@ # include <inttypes.h> # include <stdio.h> # include <stdlib.h> -# include <u8c.h> +# include <u8c/end.h> +# include <u8c/init.h> +# include <u8c/SIZE_C.h> +# include <u8c/u32sz.h> int main(void) { u8c_init(); size_t u32sz = SIZE_C(0x0); - uint_least32_t * u32 = U"Hello there."; /* Place string here. */ + uint_least32_t * u32 = U"u8c_u32sz: Unterminated input."; /* Place string here. */ u8c_u32sz(&u32sz,u32); printf("Arrray:\n{"); for(size_t n = SIZE_C(0x0);n < u32sz;n += SIZE_C(0x1)) { |