diff options
-rw-r--r-- | changelog.md | 4 | ||||
-rw-r--r-- | include/u8c/fmt.h | 2 | ||||
-rw-r--r-- | include/u8c/geterr.h | 2 | ||||
-rw-r--r-- | include/u8c/print.h | 2 | ||||
-rw-r--r-- | include/u8c/println.h | 2 | ||||
-rw-r--r-- | include/u8c/u32cp.h | 2 | ||||
-rw-r--r-- | include/u8c/u32sz.h | 2 | ||||
-rw-r--r-- | include/u8c/u8dec.h | 2 | ||||
-rw-r--r-- | include/u8c/u8enc.h | 2 | ||||
-rw-r--r-- | include/u8c/ver.h | 2 | ||||
-rw-r--r-- | include/u8c/vfmt.h | 2 | ||||
-rw-r--r-- | include/u8c/vprint.h | 2 | ||||
-rw-r--r-- | src/u8c/fmt.c | 2 | ||||
-rw-r--r-- | src/u8c/geterr.c | 4 | ||||
-rw-r--r-- | src/u8c/print.c | 2 | ||||
-rw-r--r-- | src/u8c/println.c | 2 | ||||
-rw-r--r-- | src/u8c/seterr.c | 2 | ||||
-rw-r--r-- | src/u8c/seterr.h | 2 | ||||
-rw-r--r-- | src/u8c/u32cp.c | 2 | ||||
-rw-r--r-- | src/u8c/u32sz.c | 2 | ||||
-rw-r--r-- | src/u8c/u8dec.c | 14 | ||||
-rw-r--r-- | src/u8c/u8enc.c | 40 | ||||
-rw-r--r-- | src/u8c/vfmt.c | 4 | ||||
-rw-r--r-- | src/u8c/vprint.c | 2 | ||||
-rw-r--r-- | test.c | 25 |
25 files changed, 70 insertions, 59 deletions
diff --git a/changelog.md b/changelog.md index 4ab3161..b769c1d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,7 @@ +# 7 + +* Optimisations. + # 6 * Remove unneeded include directives. diff --git a/include/u8c/fmt.h b/include/u8c/fmt.h index 262c3dc..70aea51 100644 --- a/include/u8c/fmt.h +++ b/include/u8c/fmt.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_fmt(size_t * outstrsz,uint_least32_t * * outstr,uint_least32_t * instr,...); +extern uint_least8_t u8c_fmt(size_t * const restrict outsz,uint_least32_t * restrict * const restrict out,uint_least32_t * const restrict in,...); # if defined(__cplusplus) } # endif diff --git a/include/u8c/geterr.h b/include/u8c/geterr.h index d20499f..fe0a51d 100644 --- a/include/u8c/geterr.h +++ b/include/u8c/geterr.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_geterr(size_t * sz,uint_least32_t * * u32); +extern uint_least8_t u8c_geterr(size_t * const restrict sz,uint_least32_t * restrict * const restrict out); # if defined(__cplusplus) } # endif diff --git a/include/u8c/print.h b/include/u8c/print.h index acbda08..f30b485 100644 --- a/include/u8c/print.h +++ b/include/u8c/print.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_print(FILE * fp,uint_least32_t * msg,...); +extern uint_least8_t u8c_print(FILE * fp,uint_least32_t * const msg,...); # if defined(__cplusplus) } # endif diff --git a/include/u8c/println.h b/include/u8c/println.h index 10ebff3..2887726 100644 --- a/include/u8c/println.h +++ b/include/u8c/println.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_println(FILE * fp,uint_least32_t * msg,...); +extern uint_least8_t u8c_println(FILE * fp,uint_least32_t * const msg,...); # if defined(__cplusplus) } # endif diff --git a/include/u8c/u32cp.h b/include/u8c/u32cp.h index b0ca35f..8ec1864 100644 --- a/include/u8c/u32cp.h +++ b/include/u8c/u32cp.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_u32cp(size_t * sz,uint_least32_t * * out,uint_least32_t * in); +extern uint_least8_t u8c_u32cp(size_t * const restrict sz,uint_least32_t * restrict * const restrict out,uint_least32_t * const restrict in); # if defined(__cplusplus) } # endif diff --git a/include/u8c/u32sz.h b/include/u8c/u32sz.h index 28ef2e4..5b39393 100644 --- a/include/u8c/u32sz.h +++ b/include/u8c/u32sz.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_u32sz(size_t * sz,uint_least32_t * u32); +extern uint_least8_t u8c_u32sz(size_t * restrict sz,uint_least32_t * restrict in); # if defined(__cplusplus) } # endif diff --git a/include/u8c/u8dec.h b/include/u8c/u8dec.h index 8ebf64e..851cc4c 100644 --- a/include/u8c/u8dec.h +++ b/include/u8c/u8dec.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_u8dec(size_t * outsz,uint_least32_t * * out,uint_least8_t * in); +extern uint_least8_t u8c_u8dec(size_t * const restrict sz,uint_least32_t * restrict * const restrict out,uint_least8_t * const restrict in); # if defined(__cplusplus) } # endif diff --git a/include/u8c/u8enc.h b/include/u8c/u8enc.h index f4bdfa5..72710a1 100644 --- a/include/u8c/u8enc.h +++ b/include/u8c/u8enc.h @@ -21,7 +21,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_u8enc(size_t * sz,uint_least8_t * * out,uint_least32_t * in); +extern uint_least8_t u8c_u8enc(size_t * const restrict sz,uint_least8_t * restrict * const restrict out,uint_least32_t * const restrict in); # if defined(__cplusplus) } # endif diff --git a/include/u8c/ver.h b/include/u8c/ver.h index c754571..c31642c 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(0x6)) +# define u8c_ver (UINT64_C(0x7)) # endif diff --git a/include/u8c/vfmt.h b/include/u8c/vfmt.h index c12e251..60e744e 100644 --- a/include/u8c/vfmt.h +++ b/include/u8c/vfmt.h @@ -22,7 +22,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_vfmt(size_t * outsz,uint_least32_t * * out,uint_least32_t * in,va_list args); +extern uint_least8_t u8c_vfmt(size_t * const restrict sz,uint_least32_t * restrict * const restrict out,uint_least32_t * const restrict in,va_list args); # if defined(__cplusplus) } # endif diff --git a/include/u8c/vprint.h b/include/u8c/vprint.h index 154aef6..a10a50a 100644 --- a/include/u8c/vprint.h +++ b/include/u8c/vprint.h @@ -22,7 +22,7 @@ # if defined(__cplusplus) extern "C" { # endif -extern uint_least8_t u8c_vprint(FILE * fp,uint_least32_t * msg,va_list args); +extern uint_least8_t u8c_vprint(FILE * fp,uint_least32_t * const restrict msg,va_list args); # if defined(__cplusplus) } # endif diff --git a/src/u8c/fmt.c b/src/u8c/fmt.c index ddaaec8..1f1f63a 100644 --- a/src/u8c/fmt.c +++ b/src/u8c/fmt.c @@ -18,7 +18,7 @@ # 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,...) { +uint_least8_t u8c_fmt(size_t * const restrict _outsz,uint_least32_t * restrict * const restrict _out,uint_least32_t * const restrict _in,...) { va_list args; va_start(args,_in); uint_least8_t val = u8c_vfmt(_outsz,_out,_in,args); diff --git a/src/u8c/geterr.c b/src/u8c/geterr.c index 12b5c14..b2005b2 100644 --- a/src/u8c/geterr.c +++ b/src/u8c/geterr.c @@ -19,11 +19,11 @@ # include <stdint.h> # include <u8c/geterr.h> # include <u8c/u32cp.h> -uint_least8_t u8c_geterr(size_t * _sz,uint_least32_t * * _u32) { +uint_least8_t u8c_geterr(size_t * const restrict _sz,uint_least32_t * restrict * const restrict _out) { # if defined(u8c_bethrdsafe) mtx_lock(&u8c_errlock); # endif - u8c_u32cp(_sz,_u32,u8c_err); + u8c_u32cp(_sz,_out,u8c_err); # if defined(u8c_bethrdsafe) mtx_unlock(&u8c_errlock); # endif diff --git a/src/u8c/print.c b/src/u8c/print.c index 5308f18..f982a25 100644 --- a/src/u8c/print.c +++ b/src/u8c/print.c @@ -17,7 +17,7 @@ # include <stdint.h> # include <u8c/print.h> # include <u8c/vprint.h> -uint_least8_t u8c_print(FILE * _fp,uint_least32_t * _msg,...) { +uint_least8_t u8c_print(FILE * _fp,uint_least32_t * const _msg,...) { va_list args; va_start(args,_msg); uint_least8_t val = u8c_vprint(_fp,_msg,args); diff --git a/src/u8c/println.c b/src/u8c/println.c index 5865dfa..6bbca02 100644 --- a/src/u8c/println.c +++ b/src/u8c/println.c @@ -20,7 +20,7 @@ # include <stdio.h> # include <u8c/println.h> # include <u8c/vprint.h> -uint_least8_t u8c_println(FILE * _fp,uint_least32_t * _msg,...) { +uint_least8_t u8c_println(FILE * _fp,uint_least32_t * const _msg,...) { assert(_fp != NULL); va_list args; va_start(args,_msg); diff --git a/src/u8c/seterr.c b/src/u8c/seterr.c index 4692348..3efbb14 100644 --- a/src/u8c/seterr.c +++ b/src/u8c/seterr.c @@ -24,7 +24,7 @@ # if defined(u8c_bethrdsafe) # include <threads.h> # endif -uint_least8_t u8c_seterr(uint_least32_t * _msg) { +uint_least8_t u8c_seterr(uint_least32_t * const restrict _msg) { assert(_msg != NULL); u8c_dbgprint(_msg); # if defined(u8c_bethrdsafe) diff --git a/src/u8c/seterr.h b/src/u8c/seterr.h index c7832c2..0aee4e6 100644 --- a/src/u8c/seterr.h +++ b/src/u8c/seterr.h @@ -16,5 +16,5 @@ # if !defined(u8c_sym_seterr) # define u8c_sym_seterr # include <stdint.h> -extern uint_least8_t u8c_seterr(uint_least32_t * msg); +extern uint_least8_t u8c_seterr(uint_least32_t * const restrict msg); # endif diff --git a/src/u8c/u32cp.c b/src/u8c/u32cp.c index 628e57f..80a058e 100644 --- a/src/u8c/u32cp.c +++ b/src/u8c/u32cp.c @@ -20,7 +20,7 @@ # include <u8c/SIZE_C.h> # include <u8c/u32cp.h> # include <u8c/u32sz.h> -uint_least8_t u8c_u32cp(size_t * _sz,uint_least32_t * * _out,uint_least32_t * _in) { +uint_least8_t u8c_u32cp(size_t * const restrict _sz,uint_least32_t * restrict * const restrict _out,uint_least32_t * const restrict _in) { assert(_in != NULL); size_t insz = SIZE_C(0x0); u8c_u32sz(&insz,_in); diff --git a/src/u8c/u32sz.c b/src/u8c/u32sz.c index 0d4fd99..3404a42 100644 --- a/src/u8c/u32sz.c +++ b/src/u8c/u32sz.c @@ -19,7 +19,7 @@ # include <stdint.h> # include <u8c/SIZE_C.h> # include <u8c/u32sz.h> -uint_least8_t u8c_u32sz(size_t * _sz,uint_least32_t * _u32) { +uint_least8_t u8c_u32sz(size_t * const restrict _sz,uint_least32_t * const restrict _u32) { assert(_sz != NULL); assert(_u32 != NULL); for(size_t n = SIZE_C(0x0);n <= SIZE_MAX;n += SIZE_C(0x1)) { diff --git a/src/u8c/u8dec.c b/src/u8c/u8dec.c index 2447b6a..ee860b5 100644 --- a/src/u8c/u8dec.c +++ b/src/u8c/u8dec.c @@ -19,11 +19,11 @@ # include <stdlib.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) { +uint_least8_t u8c_u8dec(size_t * const restrict _sz,uint_least32_t * restrict * const restrict _out,uint_least8_t * const restrict _in) { assert(_in != NULL); - size_t insz = SIZE_C(0x0); - size_t outsz = SIZE_C(0x1); - for(size_t n = SIZE_C(0x0);n <= SIZE_MAX;outsz += SIZE_C(0x1)) { /* First pass: get size of input array and determine size of output array. */ + register size_t insz = SIZE_C(0x0); + register size_t outsz = SIZE_C(0x1); + for(register size_t n = SIZE_C(0x0);n <= SIZE_MAX;outsz += SIZE_C(0x1)) { /* First pass: get size of input array and determine size of output array. */ if(_in[n] == UINT8_C(0x0)) { /* Null-terminator: end of string has been reached. */ insz = n + SIZE_C(0x1); goto nottoobig; @@ -51,11 +51,11 @@ uint_least8_t u8c_u8dec(size_t * _outsz,uint_least32_t * * _out,uint_least8_t * u8c_seterr((uint_least32_t[]){UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x63),UINT32_C(0x5F),UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x64),UINT32_C(0x65),UINT32_C(0x63),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_u8dec: Unterminated input. */ return UINT8_C(0x1); nottoobig:; - if(_outsz != NULL) { - *_outsz = outsz; + if(_sz != NULL) { + *_sz = outsz; } *_out = calloc(sizeof(uint_least32_t),outsz); - for(size_t n = SIZE_C(0x0),outn = SIZE_C(0x0);n < insz;outn += SIZE_C(0x1)) { /* Second pass: decode UTF-8. */ + for(register size_t n = SIZE_C(0x0),outn = SIZE_C(0x0);n < insz;outn += SIZE_C(0x1)) { /* Second pass: decode UTF-8. */ if(_in[n] >= UINT8_C(0xF0)) { /* Four byte. */ uint_least32_t codep = (_in[n] ^ UINT32_C(0xF0)) << UINT32_C(0x12); n += SIZE_C(0x1); diff --git a/src/u8c/u8enc.c b/src/u8c/u8enc.c index 5ebd479..e49a6c3 100644 --- a/src/u8c/u8enc.c +++ b/src/u8c/u8enc.c @@ -19,30 +19,31 @@ # include <stdlib.h> # include <u8c/u8enc.h> # include <u8c/SIZE_C.h> -uint_least8_t u8c_u8enc(size_t * _sz,uint_least8_t * * _out,uint_least32_t * _in) { +uint_least8_t u8c_u8enc(size_t * const restrict _sz,uint_least8_t * restrict * const restrict _out,uint_least32_t * const restrict _in) { assert(_in != NULL); size_t insz = SIZE_C(0x0); /* Size of input array (bytes). */ size_t outsz = SIZE_C(0x0); /* Size of output array /bytes). */ for(size_t n = SIZE_C(0x0);n <= SIZE_MAX;n += SIZE_C(0x1)) { /* First pass: get size of input array, and determine size of output array. */ - if(_in[n] >= UINT32_C(0x110000)) { /* Codepoint out of range. */ + register uint_least32_t const tmp = _in[n]; + if(tmp >= UINT32_C(0x110000)) { /* Codepoint out of range. */ u8c_seterr((uint_least32_t[]){UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x63),UINT32_C(0x5F),UINT32_C(0x75),UINT32_C(0x38),UINT32_C(0x65),UINT32_C(0x6E),UINT32_C(0x63),UINT32_C(0x3A),UINT32_C(0x20),UINT32_C(0x43),UINT32_C(0x6F),UINT32_C(0x64),UINT32_C(0x65),UINT32_C(0x70),UINT32_C(0x6F),UINT32_C(0x69),UINT32_C(0x6E),UINT32_C(0x74),UINT32_C(0x20),UINT32_C(0x6F),UINT32_C(0x75),UINT32_C(0x74),UINT32_C(0x20),UINT32_C(0x6F),UINT32_C(0x66),UINT32_C(0x20),UINT32_C(0x72),UINT32_C(0x61),UINT32_C(0x6E),UINT32_C(0x67),UINT32_C(0x65),UINT32_C(0x20),UINT32_C(0x28),UINT32_C(0x74),UINT32_C(0x6F),UINT32_C(0x6F),UINT32_C(0x20),UINT32_C(0x62),UINT32_C(0x69),UINT32_C(0x67),UINT32_C(0x29),UINT32_C(0x2E),UINT32_C(0x0),}); /* u8c_u8enc: Codepoint out of range (too big). */ return UINT8_C(0x1); } - if(_in[n] >= UINT32_C(0x10000)) { /* 4 bytes. */ + if(tmp >= UINT32_C(0x10000)) { /* 4 bytes. */ outsz += SIZE_C(0x4); continue; } - if(_in[n] >= UINT32_C(0x800)) { /* 3 bytes. */ + if(tmp >= UINT32_C(0x800)) { /* 3 bytes. */ outsz += SIZE_C(0x3); continue; } - if(_in[n] >= UINT32_C(0x80)) { /* 2 bytes. */ + if(tmp >= UINT32_C(0x80)) { /* 2 bytes. */ outsz += SIZE_C(0x2); continue; } /* 1 byte. */ outsz += SIZE_C(0x1); - if(_in[n] == UINT32_C(0x0)) { + if(tmp == UINT32_C(0x0)) { insz = n + SIZE_C(0x1); goto nottoobig; } @@ -55,32 +56,33 @@ nottoobig:; } *_out = calloc(sizeof(uint_least8_t),outsz); /* Allocate space for output array. */ for(size_t n = SIZE_C(0x0), outn = SIZE_C(0x0);n < insz;n += SIZE_C(0x1),outn += SIZE_C(0x1)) { /* Second pass: encode each codepoint into UTF-8. */ - if(_in[n] >= UINT32_C(0x10000)) { // Four bytes. - (*_out)[outn] = UINT8_C(0xF0) + (uint_least8_t)(_in[n] >> UINT32_C(0x12)); + register uint_least32_t const tmp = _in[n]; + if(tmp >= UINT32_C(0x10000)) { // Four bytes. + (*_out)[outn] = UINT8_C(0xF0) + (uint_least8_t)(tmp >> UINT32_C(0x12)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(_in[n] >> UINT32_C(0xC) & UINT8_C(0x3F)); + (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0xC) & UINT8_C(0x3F)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(_in[n] >> UINT32_C(0x6) & UINT8_C(0x3F)); + (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0x6) & UINT8_C(0x3F)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(_in[n] & UINT32_C(0x3F)); + (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT32_C(0x3F)); continue; } - if(_in[n] >= UINT32_C(0x800)) { /* Three bytes. */ - (*_out)[outn] = UINT8_C(0xE0) + (uint_least8_t)(_in[n] >> UINT32_C(0xC)); + if(tmp >= UINT32_C(0x800)) { /* Three bytes. */ + (*_out)[outn] = UINT8_C(0xE0) + (uint_least8_t)(tmp >> UINT32_C(0xC)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(_in[n] >> UINT32_C(0x6) & UINT8_C(0x3F)); + (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0x6) & UINT8_C(0x3F)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(_in[n] & UINT32_C(0x3F)); + (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT32_C(0x3F)); continue; } - if(_in[n] >= UINT32_C(0x80)) { /* Two bytes. */ - (*_out)[outn] = UINT8_C(0xC0) + (uint_least8_t)(_in[n] >> UINT8_C(0x6)); + if(tmp >= UINT32_C(0x80)) { /* Two bytes. */ + (*_out)[outn] = UINT8_C(0xC0) + (uint_least8_t)(tmp >> UINT8_C(0x6)); outn += SIZE_C(0x1); - (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(_in[n] & UINT8_C(0x3F)); + (*_out)[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT8_C(0x3F)); continue; } /* One byte. */ - (*_out)[outn] = (uint_least8_t)_in[n]; + (*_out)[outn] = (uint_least8_t)tmp; } return UINT8_C(0x0); } diff --git a/src/u8c/vfmt.c b/src/u8c/vfmt.c index 4c00629..c1a7fc8 100644 --- a/src/u8c/vfmt.c +++ b/src/u8c/vfmt.c @@ -17,7 +17,7 @@ # include <stdint.h> # include <u8c/u32cp.h> # include <u8c/vfmt.h> -uint_least8_t u8c_vfmt(size_t * _outsz,uint_least32_t * * _out,uint_least32_t * _in,va_list _args) { +uint_least8_t u8c_vfmt(size_t * const restrict _sz,uint_least32_t * restrict * const restrict _out,uint_least32_t * const restrict _in,va_list _args) { /* To be added. */ - return u8c_u32cp(_outsz,_out,_in); + return u8c_u32cp(_sz,_out,_in); } diff --git a/src/u8c/vprint.c b/src/u8c/vprint.c index 2eb00e0..3b78f4c 100644 --- a/src/u8c/vprint.c +++ b/src/u8c/vprint.c @@ -23,7 +23,7 @@ # include <u8c/SIZE_C.h> # include <u8c/vfmt.h> # include <u8c/vprint.h> -uint_least8_t u8c_vprint(FILE * _fp,uint_least32_t * _msg,va_list _args) { +uint_least8_t u8c_vprint(FILE * _fp,uint_least32_t * const restrict _msg,va_list _args) { assert(_msg != NULL); uint_least32_t * str0 = NULL; u8c_vfmt(NULL,&str0,_msg,_args); @@ -3,7 +3,6 @@ # include <stdint.h> # include <stdio.h> # include <stdlib.h> -# include <threads.h> # include <u8c/col.h> # include <u8c/dbgprint.h> # include <u8c/debug.h> @@ -41,18 +40,19 @@ int main(void) { printf("u8c version: %" PRIXLEAST64 ".\n",u8c_ver); printf("Debug build: %" PRIXLEAST8 ".\n",u8c_debug); printf("Thread safe: %" PRIXLEAST8 ".\n",u8c_thrdsafe); - uint_least32_t errcount0 = UINT8_C(0x0); + uint_least32_t errcount0 = UINT32_C(0x0); uint_least8_t errcount1 = UINT8_C(0x0); testmsg("Error messages"); - { + while(!errcount1) { uint_least32_t * err = NULL; errcount1 += u8c_geterr(NULL,&err); errcount1 += u8c_println(stdout,err); free(err); + break; } testmsgdone(&errcount0,&errcount1); testmsg("UTF-8 encoding/decoding"); - { + while(!errcount1) { uint_least32_t * msg0 = (uint_least32_t[]){UINT32_C(0xA2),UINT32_C(0x2C),UINT32_C(0x939),UINT32_C(0x2C),UINT32_C(0x10348),UINT32_C(0x2C),UINT32_C(0x20AC),UINT32_C(0x2C),UINT32_C(0x218A),UINT32_C(0x2C),UINT32_C(0x1F44B),UINT32_C(0x0)}; uint_least8_t * msg1 = NULL; errcount1 += u8c_u8enc(NULL,&msg1,msg0); @@ -62,38 +62,43 @@ int main(void) { printf("Encoded -> Decoded -> Encoded: %s\n",msg1); free(msg0); free(msg1); + break; } testmsgdone(&errcount0,&errcount1); testmsg("Printing (u8c_print)"); - { + while(!errcount1) { errcount1 += u8c_print(stdout,(uint_least32_t[]){UINT32_C(0x48),UINT32_C(0x65),UINT32_C(0x6C),UINT32_C(0x6C),UINT32_C(0x6F),UINT32_C(0x0),}); errcount1 += u8c_print(stdout,(uint_least32_t[]){UINT32_C(0x20),UINT32_C(0xF0),UINT32_C(0x65),UINT32_C(0x72),UINT32_C(0x65),UINT32_C(0x21),UINT32_C(0xA),UINT32_C(0x0),}); + break; } testmsgdone(&errcount0,&errcount1); testmsg("Printing (u8c_println)"); - { + while(!errcount1) { errcount1 += u8c_println(stdout,(uint_least32_t[]){UINT32_C(0x48),UINT32_C(0x65),UINT32_C(0x6C),UINT32_C(0x6C),UINT32_C(0x6F),UINT32_C(0x0),}); errcount1 += u8c_println(stdout,(uint_least32_t[]){UINT32_C(0x20),UINT32_C(0xF0),UINT32_C(0x65),UINT32_C(0x72),UINT32_C(0x65),UINT32_C(0x21),UINT32_C(0x0),}); + break; } testmsgdone(&errcount0,&errcount1); testmsg("Text formatting"); - { + while(!errcount1) { errcount1 += u8c_println(stdout,(uint_least32_t[]){UINT32_C(0x54),UINT32_C(0x68),UINT32_C(0x65),UINT32_C(0x20),UINT32_C(0xFFFD),UINT32_C(0x6E),UINT32_C(0x75),UINT32_C(0x6D),UINT32_C(0x62),UINT32_C(0x65),UINT32_C(0x72),UINT32_C(0xFFFD),UINT32_C(0x20),UINT32_C(0x69),UINT32_C(0x73),UINT32_C(0x20),UINT32_C(0xFFFD),UINT32_C(0x2E),UINT32_C(0x0),},u8c_fmttyp_fgcol,u8c_col_mint,u8c_fmttyp_fgcol0,u8c_fmttyp_int,(int_least64_t){-0x10}); + break; } testmsgdone(&errcount0,&errcount1); testmsg("Colour text"); - { + while(!errcount1) { errcount1 += u8c_println(stdout,(uint_least32_t[]){UINT32_C(0xFFFD),UINT32_C(0x72),UINT32_C(0x65),UINT32_C(0x64),UINT32_C(0xFFFD),UINT32_C(0x6F),UINT32_C(0x72),UINT32_C(0x61),UINT32_C(0x6E),UINT32_C(0x67),UINT32_C(0x65),UINT32_C(0xFFFD),UINT32_C(0x79),UINT32_C(0x65),UINT32_C(0x6C),UINT32_C(0x6C),UINT32_C(0x6F),UINT32_C(0x77),UINT32_C(0xFFFD),UINT32_C(0x63),UINT32_C(0x68),UINT32_C(0x61),UINT32_C(0x72),UINT32_C(0x74),UINT32_C(0x72),UINT32_C(0x65),UINT32_C(0x75),UINT32_C(0x73),UINT32_C(0x65),UINT32_C(0xFFFD),UINT32_C(0x67),UINT32_C(0x72),UINT32_C(0x65),UINT32_C(0x65),UINT32_C(0x6E),UINT32_C(0xFFFD),UINT32_C(0x6D),UINT32_C(0x69),UINT32_C(0x6E),UINT32_C(0x74),UINT32_C(0xFFFD),UINT32_C(0x63),UINT32_C(0x79),UINT32_C(0x61),UINT32_C(0x6E),UINT32_C(0xFFFD),UINT32_C(0x61),UINT32_C(0x7A),UINT32_C(0x75),UINT32_C(0x72),UINT32_C(0x65),UINT32_C(0xFFFD),UINT32_C(0x62),UINT32_C(0x6C),UINT32_C(0x75),UINT32_C(0x65),UINT32_C(0xFFFD),UINT32_C(0x76),UINT32_C(0x69),UINT32_C(0x6F),UINT32_C(0x6C),UINT32_C(0x65),UINT32_C(0x74),UINT32_C(0xFFFD),UINT32_C(0x6D),UINT32_C(0x61),UINT32_C(0x67),UINT32_C(0x65),UINT32_C(0x6E),UINT32_C(0x74),UINT32_C(0x61),UINT32_C(0xFFFD),UINT32_C(0x72),UINT32_C(0x6F),UINT32_C(0x73),UINT32_C(0x65),UINT32_C(0xFFFD),UINT32_C(0x0),},u8c_fmttyp_fgcol,u8c_col_red,u8c_fmttyp_fgcol,u8c_col_orange,u8c_fmttyp_fgcol,u8c_col_yellow,u8c_fmttyp_fgcol,u8c_col_chartreuse,u8c_fmttyp_fgcol,u8c_col_green,u8c_fmttyp_fgcol,u8c_col_mint,u8c_fmttyp_fgcol,u8c_col_cyan,u8c_fmttyp_fgcol,u8c_col_azure,u8c_fmttyp_fgcol,u8c_col_blue,u8c_fmttyp_fgcol,u8c_col_violet,u8c_fmttyp_fgcol,u8c_col_magenta,u8c_fmttyp_fgcol,u8c_col_rose,u8c_fmttyp_fgcol0); + break; } testmsgdone(&errcount0,&errcount1); testmsg("Combining characters"); - { + while(!errcount1) { for(uint_least32_t n = UINT32_C(0x300);n <= UINT32_C(0x36F);n += UINT32_C(0x1)) { errcount1 += u8c_print(stdout,(uint_least32_t[]){UINT32_C(0x41),n,UINT32_C(0x20),UINT32_C(0x0),}); fflush(stdout); - thrd_sleep(&(struct timespec){.tv_nsec = 0x13DE435},NULL); } errcount1 += u8c_print(stdout,(uint_least32_t[]){UINT32_C(0xA),UINT32_C(0x0),}); + break; } testmsgdone(&errcount0,&errcount1); printf("\n"); |