diff options
Diffstat (limited to 'src')
-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 |
12 files changed, 40 insertions, 38 deletions
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); |