diff options
Diffstat (limited to 'zap')
-rw-r--r-- | zap/GNUmakefile | 24 | ||||
-rw-r--r-- | zap/include/zap/bs.h | 139 | ||||
-rw-r--r-- | zap/include/zap/mem.h | 27 | ||||
-rw-r--r-- | zap/source/any/mem/cp.c | 6 | ||||
-rw-r--r-- | zap/source/any/mem/eq.c | 12 | ||||
-rw-r--r-- | zap/source/any/mem/fill.c | 6 | ||||
-rw-r--r-- | zap/source/any/mem/srch.c | 6 | ||||
-rw-r--r-- | zap/source/any/mem/streq.c | 23 | ||||
-rw-r--r-- | zap/source/any/mem/strlen.c | 13 | ||||
-rw-r--r-- | zap/source/any/mem/utf8dec.c | 26 | ||||
-rw-r--r-- | zap/source/any/mem/utf8declen.c | 6 | ||||
-rw-r--r-- | zap/source/any/mem/utf8enc.c | 18 | ||||
-rw-r--r-- | zap/source/any/mem/utf8enclen.c | 6 | ||||
-rw-r--r-- | zap/source/any/mem/win1252dec.c | 8 | ||||
-rw-r--r-- | zap/source/any/mem/win1252enc.c | 10 |
15 files changed, 233 insertions, 97 deletions
diff --git a/zap/GNUmakefile b/zap/GNUmakefile index ade3245..2814f55 100644 --- a/zap/GNUmakefile +++ b/zap/GNUmakefile @@ -19,6 +19,8 @@ OBJ_MEM_CP := source/any/mem/cp.o OBJ_MEM_EQ := source/any/mem/eq.o OBJ_MEM_FILL := source/any/mem/fill.o OBJ_MEM_SRCH := source/any/mem/srch.o +OBJ_MEM_STREQ := source/any/mem/streq.o +OBJ_MEM_STRLEN := source/any/mem/strlen.o OBJ_MEM_UTF8DEC := source/any/mem/utf8dec.o OBJ_MEM_UTF8DECLEN := source/any/mem/utf8declen.o OBJ_MEM_UTF8ENC := source/any/mem/utf8enc.o @@ -46,6 +48,8 @@ OBJS := \ $(OBJ_MEM_EQ) \ $(OBJ_MEM_FILL) \ $(OBJ_MEM_SRCH) \ + $(OBJ_MEM_STREQ) \ + $(OBJ_MEM_STRLEN) \ $(OBJ_MEM_UTF8DEC) \ $(OBJ_MEM_UTF8DECLEN) \ $(OBJ_MEM_UTF8ENC) \ @@ -61,16 +65,16 @@ HDRS := \ include/zap/mem.h CFLAGS := \ - -Iinclude \ - -Oz \ - -Wall \ - -Wextra \ - -Wpadded \ - -Wpedantic \ - -ffreestanding \ - -fshort-enums \ - -nostdlib \ - -pipe \ + -Iinclude \ + -Oz \ + -Wall \ + -Wextra \ + -Wpadded \ + -Wpedantic \ + -ffreestanding \ + -fshort-enums \ + -nostdlib \ + -pipe \ -std=c99 .PHONY: clean install purge diff --git a/zap/include/zap/bs.h b/zap/include/zap/bs.h index 04a3d16..0b7a770 100644 --- a/zap/include/zap/bs.h +++ b/zap/include/zap/bs.h @@ -51,48 +51,141 @@ zap_priv_cdecl -#define zap_ver ((unsigned long)+0x16u) +#define zap_ver ((unsigned long)+0x17u) -#define zap_bytesz ((zap_sz)+0x8u) +#define zap_bytelen ((zap_sz)+0x8u) +#define zap_nopos zap_maxval_sz -#define zap_false ((zap_bool)+0x0u) -#define zap_true ((zap_bool)-0x1) +#define zap_nullptr ((void *)0x0) -#define zap_nopos ((zap_sz)-0x1) +#define zap_minval_uc ((unsigned char) +0x0u) +#define zap_minval_us ((unsigned short) +0x0u) +#define zap_minval_ui ((unsigned int) +0x0u) +#define zap_minval_ul ((unsigned long) +0x0u) +#define zap_minval_ull ((unsigned long long)+0x0) +#define zap_minval_sc ((signed char) -0x80) +#define zap_minval_s ((short) -0x8000) +#define zap_minval_ll ((long long) -0x8000000000000000) -#define zap_nullptr ((void *)0x0u) +#define zap_maxval_uc ((unsigned char) +0xFFu) +#define zap_maxval_us ((unsigned short) +0xFFFFu) +#define zap_maxval_ull ((unsigned long long)+0xFFFFFFFFFFFFFFFFu) +#define zap_maxval_sc ((signed char) +0x7F) +#define zap_maxval_s ((short) +0x7FFF) +#define zap_maxval_ll ((long long) +0x7FFFFFFFFFFFFFFF) + +typedef unsigned char zap_i8; +typedef unsigned short zap_i01; + +typedef signed char zap_i8s; +typedef short zap_i01s; + +#define zap_minval_i8 zap_minval_uc +#define zap_minval_i01 zap_minval_us +#define zap_minval_i8s zap_minval_sc +#define zap_minval_i01s zap_minval_s + +#define zap_maxval_i8 zap_maxval_uc +#define zap_maxval_i01 zap_maxval_us +#define zap_maxval_i8s zap_maxval_sc +#define zap_maxval_i01s zap_maxval_s -typedef unsigned char zap_i8; -typedef unsigned short zap_i01; -typedef unsigned int zap_i02; #if \ - csys_arch_arm \ - || csys_arch_ia32 \ - || (csys_os_win && csys_arch_amd64) -typedef unsigned long long zap_i04; + csys_arch_arm \ + || csys_arch_arm64 +#define zap_minval_c zap_minval_uc +#define zap_maxval_c zap_maxval_uc #else -typedef unsigned long zap_i04; +#define zap_minval_c zap_minval_sc +#define zap_maxval_c zap_maxval_sc #endif -typedef signed char zap_i8s; -typedef short zap_i01s; -typedef int zap_i02s; -typedef long zap_i04s; +#if \ + csys_arch_amd64 \ + || csys_arch_arm64 \ + || csys_arch_arm \ + || csys_arch_ia32 +/* int: 32 */ +#define zap_minval_i ((int) -0x80000000) + +#define zap_maxval_ui ((unsigned int)+0xFFFFFFFFu) +#define zap_maxval_i ((int) +0x7FFFFFFF) + +typedef unsigned int zap_i02; +typedef int zap_i02s; + +#define zap_minval_i02 zap_minval_ui +#define zap_minval_i02s zap_minval_i + +#define zap_maxval_i02 zap_maxval_ui +#define zap_maxval_i02s zap_maxval_i +#else +/* int: 16 */ +#define zap_minval_i ((int) -0x8000) -typedef zap_i8 zap_chr8; -typedef zap_i01 zap_chr01; -typedef zap_i02 zap_chr02; +#define zap_maxval_ui ((unsigned int)+0xFFFFu) +#define zap_maxval_i ((int) +0x7FFF) -typedef zap_i8 zap_bool; +typedef unsigned long zap_i02; +typedef long zap_i02s; -typedef zap_i8 zap_byte; +#define zap_minval_i02 zap_minval_ul +#define zap_minval_i02s zap_minval_l + +#define zap_maxval_i02 zap_maxval_ul +#define zap_maxval_i02s zap_maxval_l +#endif + +#if \ + csys_arch_amd64 \ + || csys_arch_arm64 +/* long: 64 */ +#define zap_minval_l ((long) -0x8000000000000000) + +#define zap_maxval_ul ((unsigned long)+0xFFFFFFFFFFFFFFFFu) +#define zap_maxval_l ((long) +0x7FFFFFFFFFFFFFFF) + +typedef unsigned long zap_i04; +typedef long zap_i04s; + +#define zap_minval_i04 zap_minval_ul +#define zap_minval_i04s zap_minval_l + +#define zap_maxval_i04 zap_maxval_ul +#define zap_maxval_i04s zap_maxval_l +#else +/* long: 32 */ +#define zap_minval_l ((long) -0x80000000) + +#define zap_maxval_ul ((unsigned long)+0xFFFFFFFFu) +#define zap_maxval_l ((long) +0x7FFFFFFF) + +typedef unsigned long long zap_i04; +typedef long long zap_i04s; + +#define zap_minval_i04 zap_minval_ull +#define zap_minval_i04s zap_minval_ll + +#define zap_maxval_i04 zap_maxval_ull +#define zap_maxval_i04s zap_maxval_ll +#endif #if \ csys_arch_arm \ || csys_arch_ia32 +#define zap_minval_ptr zap_minval_i02 +#define zap_minval_sz zap_minval_i02 +#define zap_maxval_ptr zap_maxval_i02 +#define zap_maxval_sz zap_maxval_i02 + typedef zap_i02 zap_ptr; typedef zap_i02 zap_sz; #else +#define zap_minval_ptr zap_minval_i04 +#define zap_minval_sz zap_minval_i04 +#define zap_maxval_ptr zap_maxval_i04 +#define zap_maxval_sz zap_maxval_i04 + typedef zap_i04 zap_ptr; typedef zap_i04 zap_sz; #endif diff --git a/zap/include/zap/mem.h b/zap/include/zap/mem.h index c1544d0..8110a85 100644 --- a/zap/include/zap/mem.h +++ b/zap/include/zap/mem.h @@ -11,18 +11,21 @@ zap_priv_cdecl -void zap_cp( void * zap_priv_restr dest,void const * zap_priv_restr src, zap_sz num); -zap_bool zap_eq( void const * lbuf,void const * rbuf,zap_sz num); -void zap_fill(void * dest,zap_byte val, zap_sz num); -void * zap_srch(void const * buf, zap_byte val, zap_sz num); - -zap_sz zap_utf8declen(zap_chr8 const * buf); -zap_sz zap_utf8enclen(zap_chr02 const * buf); - -void zap_utf8dec( zap_chr02 * zap_priv_restr dest,zap_chr8 const * zap_priv_restr src); -void zap_utf8enc( zap_chr8 * zap_priv_restr dest,zap_chr02 const * zap_priv_restr src); -void zap_win1252dec(zap_chr02 * zap_priv_restr dest,zap_chr8 const * zap_priv_restr src); -void zap_win1252enc(zap_chr8 * zap_priv_restr dest,zap_chr02 const * zap_priv_restr src); +void zap_cp( void * zap_priv_restr dest,void const * zap_priv_restr src, zap_sz num); +zap_i8 zap_eq( void const * lbuf,void const * rbuf,zap_sz num); +void zap_fill(void * dest,zap_i8 val, zap_sz num); +void * zap_srch(void const * buf, zap_i8 val, zap_sz num); + +zap_i8 zap_streq( char const * lstr,char const * rstr); +zap_sz zap_strlen(char const * str); + +zap_sz zap_utf8declen(zap_i8 const * buf); +zap_sz zap_utf8enclen(zap_i02 const * buf); + +void zap_utf8dec( zap_i02 * zap_priv_restr dest,zap_i8 const * zap_priv_restr src); +void zap_utf8enc( zap_i8 * zap_priv_restr dest,zap_i02 const * zap_priv_restr src); +void zap_win1252dec(zap_i02 * zap_priv_restr dest,zap_i8 const * zap_priv_restr src); +void zap_win1252enc(zap_i8 * zap_priv_restr dest,zap_i02 const * zap_priv_restr src); zap_priv_cdeclend diff --git a/zap/source/any/mem/cp.c b/zap/source/any/mem/cp.c index 9bfd895..2c1b265 100644 --- a/zap/source/any/mem/cp.c +++ b/zap/source/any/mem/cp.c @@ -7,9 +7,9 @@ #include <zap/mem.h> void zap_cp(void * const zap_priv_restr _dest,void const * const zap_priv_restr _src,zap_sz const _num) { - zap_byte * dest; - zap_byte const * src; - zap_byte * const stop = (zap_byte *)_dest + _num; + zap_i8 * dest; + zap_i8 const * src; + zap_i8 * const stop = (zap_i8 *)_dest + _num; for (dest = _dest,src = _src;dest != stop;++dest,++src) { *dest = *src; } diff --git a/zap/source/any/mem/eq.c b/zap/source/any/mem/eq.c index 0229fb6..3f6cd8e 100644 --- a/zap/source/any/mem/eq.c +++ b/zap/source/any/mem/eq.c @@ -6,14 +6,14 @@ #include <zap/mem.h> -zap_bool zap_eq(void const * const _lbuf,void const * const _rbuf,zap_sz const _num) { - zap_byte const * lbuf; - zap_byte const * rbuf; - zap_byte * const stop = (zap_byte *)_lbuf + _num; +zap_i8 zap_eq(void const * const _lbuf,void const * const _rbuf,zap_sz const _num) { + zap_i8 const * lbuf; + zap_i8 const * rbuf; + zap_i8 * const stop = (zap_i8 *)_lbuf + _num; for (lbuf = _lbuf,rbuf = _rbuf;lbuf != stop;++lbuf,++rbuf) { if (*lbuf != *rbuf) { - return zap_false; + return 0x0u; } } - return zap_true; + return 0x1u; } diff --git a/zap/source/any/mem/fill.c b/zap/source/any/mem/fill.c index 11f5b59..dc59263 100644 --- a/zap/source/any/mem/fill.c +++ b/zap/source/any/mem/fill.c @@ -6,9 +6,9 @@ #include <zap/mem.h> -void zap_fill(void * const _dest,zap_byte const _val,zap_sz const _num) { - zap_byte * dest; - zap_byte * const stop = (zap_byte *)_dest + _num; +void zap_fill(void * const _dest,zap_i8 const _val,zap_sz const _num) { + zap_i8 * dest; + zap_i8 * const stop = (zap_i8 *)_dest + _num; for (dest = _dest;dest != stop;++dest) { *dest = _val; } diff --git a/zap/source/any/mem/srch.c b/zap/source/any/mem/srch.c index 494e2d8..9f86634 100644 --- a/zap/source/any/mem/srch.c +++ b/zap/source/any/mem/srch.c @@ -6,9 +6,9 @@ #include <zap/mem.h> -void * zap_srch(void const * const _buf,zap_byte const _val,zap_sz const _num) { - zap_byte const * buf; - zap_byte * const stop = (zap_byte *)_buf + _num; +void * zap_srch(void const * const _buf,zap_i8 const _val,zap_sz const _num) { + zap_i8 const * buf; + zap_i8 * const stop = (zap_i8 *)_buf + _num; for (buf = _buf;buf != stop;++buf) { if (*buf == _val) { return (void *)buf; diff --git a/zap/source/any/mem/streq.c b/zap/source/any/mem/streq.c new file mode 100644 index 0000000..69c6bf6 --- /dev/null +++ b/zap/source/any/mem/streq.c @@ -0,0 +1,23 @@ +/* + Copyright 2022-2023 Gabriel Jensen. + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. +*/ + +#include <zap/mem.h> + +zap_i8 zap_streq(char const * const _lstr,char const * const _rstr) { + char const * lpos = _lstr; + char const * rpos = _rstr; + for (;;++lpos,++rpos) { + char const lchr = *lpos; + char const rchr = *rpos; + if (lchr != rchr) { + return 0x0u; + } + if (lchr == '\x0') { + break; + } + } + return zap_maxval_i8; +} diff --git a/zap/source/any/mem/strlen.c b/zap/source/any/mem/strlen.c new file mode 100644 index 0000000..200269c --- /dev/null +++ b/zap/source/any/mem/strlen.c @@ -0,0 +1,13 @@ +/* + Copyright 2022-2023 Gabriel Jensen. + This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. + If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>. +*/ + +#include <zap/mem.h> + +zap_sz zap_strlen(char const * const _str) { + char const * pos = _str; + for (;*pos != '\x0';++pos) {} + return (zap_sz)(pos - _str); +} diff --git a/zap/source/any/mem/utf8dec.c b/zap/source/any/mem/utf8dec.c index f9a0eac..6f3141a 100644 --- a/zap/source/any/mem/utf8dec.c +++ b/zap/source/any/mem/utf8dec.c @@ -6,40 +6,40 @@ #include <zap/mem.h> -void zap_utf8dec(zap_chr02 * const _dest,zap_chr8 const * const _src) { - zap_chr02 * dest; - zap_chr8 const * src; +void zap_utf8dec(zap_i02 * const _dest,zap_i8 const * const _src) { + zap_i02 * dest; + zap_i8 const * src; for (dest = _dest,src = _src;;++dest) { - zap_chr8 const oct = *src; + zap_i8 const oct = *src; if (oct == 0x0u) { break; } if (oct >= 0xF0u) { /* Four octets. */ - zap_chr02 chr = ((zap_chr02)oct ^ 0xF0u) << 0x12u; + zap_i02 chr = ((zap_i02)oct ^ 0xF0u) << 0x12u; ++src; - chr += ((zap_chr02)*src ^ 0x80u) << 0xCu; + chr += ((zap_i02)*src ^ 0x80u) << 0xCu; ++src; - chr += ((zap_chr02)*src ^ 0x80u) << 0x6u; + chr += ((zap_i02)*src ^ 0x80u) << 0x6u; ++src; - chr += (zap_chr02)*src ^ 0x80u; + chr += (zap_i02)*src ^ 0x80u; ++src; *dest = chr; continue; } if (oct >= 0xE0u) { /* Three octets. */ - zap_chr02 chr = ((zap_chr02)oct ^ 0xE0u) << 0xCu; + zap_i02 chr = ((zap_i02)oct ^ 0xE0u) << 0xCu; ++src; - chr += ((zap_chr02)*src ^ 0x80u) << 0x6u; + chr += ((zap_i02)*src ^ 0x80u) << 0x6u; ++src; - chr += (zap_chr02)*src ^ 0x80u; + chr += (zap_i02)*src ^ 0x80u; ++src; *dest = chr; continue; } if (oct >= 0xC0u) { /* Two octets. */ - zap_chr02 chr = ((zap_chr02)oct ^ 0xC0u) << 0x6u; + zap_i02 chr = ((zap_i02)oct ^ 0xC0u) << 0x6u; ++src; - chr += (zap_chr02)*src ^ 0x80u; + chr += (zap_i02)*src ^ 0x80u; ++src; *dest = chr; continue; diff --git a/zap/source/any/mem/utf8declen.c b/zap/source/any/mem/utf8declen.c index 81fd274..99c224b 100644 --- a/zap/source/any/mem/utf8declen.c +++ b/zap/source/any/mem/utf8declen.c @@ -6,11 +6,11 @@ #include <zap/mem.h> -zap_sz zap_utf8declen(zap_chr8 const * const _buf) { +zap_sz zap_utf8declen(zap_i8 const * const _buf) { zap_sz len = 0x0u; - zap_chr8 const * pos; + zap_i8 const * pos; for (pos = _buf;;++len) { - zap_chr8 const oct = *pos; + zap_i8 const oct = *pos; if (oct == 0x0u) { break; } diff --git a/zap/source/any/mem/utf8enc.c b/zap/source/any/mem/utf8enc.c index 04febb2..ea62d52 100644 --- a/zap/source/any/mem/utf8enc.c +++ b/zap/source/any/mem/utf8enc.c @@ -6,11 +6,11 @@ #include <zap/mem.h> -void zap_utf8enc(zap_chr8 * const _dest,zap_chr02 const * const _src) { - zap_chr8 * dest; - zap_chr02 const * src; +void zap_utf8enc(zap_i8 * const _dest,zap_i02 const * const _src) { + zap_i8 * dest; + zap_i02 const * src; for (dest = _dest,src = _src;;++src) { - zap_chr02 const chr = *src; + zap_i02 const chr = *src; if (chr > 0xFFFFu) { /* Four octets. */ *dest = 0xF0u + (chr >> 0x12u); ++dest; @@ -23,18 +23,18 @@ void zap_utf8enc(zap_chr8 * const _dest,zap_chr02 const * const _src) { continue; } if (chr >= 0x7FFu) { /* Three octets. */ - *dest = 0xE0u + (zap_chr8)(chr >> 0xCu); + *dest = 0xE0u + (zap_i8)(chr >> 0xCu); ++dest; - *dest = 0x80u + (zap_chr8)(chr >> 0x6u & 0x3Fu); + *dest = 0x80u + (zap_i8)(chr >> 0x6u & 0x3Fu); ++dest; - *dest = 0x80u + (zap_chr8)(chr & 0x3Fu); + *dest = 0x80u + (zap_i8)(chr & 0x3Fu); ++dest; continue; } if (chr >= 0x7Fu) { /* Two octets. */ - *dest = 0xC0u + (zap_chr8)(chr >> 0x6u); + *dest = 0xC0u + (zap_i8)(chr >> 0x6u); ++dest; - *dest = 0x80u + (zap_chr8)(chr & 0x3Fu); + *dest = 0x80u + (zap_i8)(chr & 0x3Fu); ++dest; continue; } diff --git a/zap/source/any/mem/utf8enclen.c b/zap/source/any/mem/utf8enclen.c index 67d938d..c159653 100644 --- a/zap/source/any/mem/utf8enclen.c +++ b/zap/source/any/mem/utf8enclen.c @@ -6,11 +6,11 @@ #include <zap/mem.h> -zap_sz zap_utf8enclen(zap_chr02 const * const _buf) { +zap_sz zap_utf8enclen(zap_i02 const * const _buf) { zap_sz len = 0x0u; - zap_chr02 const * pos; + zap_i02 const * pos; for (pos = _buf;;++pos) { - zap_chr02 const chr = *pos; + zap_i02 const chr = *pos; if (chr == 0x0u) { break; } diff --git a/zap/source/any/mem/win1252dec.c b/zap/source/any/mem/win1252dec.c index b808c9b..7dc7067 100644 --- a/zap/source/any/mem/win1252dec.c +++ b/zap/source/any/mem/win1252dec.c @@ -6,11 +6,11 @@ #include <zap/mem.h> -void zap_win1252dec(zap_chr02 * const _dest,zap_chr8 const * const _src) { - zap_chr02 * dest; - zap_chr8 const * src; +void zap_win1252dec(zap_i02 * const _dest,zap_i8 const * const _src) { + zap_i02 * dest; + zap_i8 const * src; for (dest = _dest,src = _src;;++src,++dest) { - zap_chr8 const chr = *src; + zap_i8 const chr = *src; if (chr == 0x0u) { break; } diff --git a/zap/source/any/mem/win1252enc.c b/zap/source/any/mem/win1252enc.c index f773540..8f80288 100644 --- a/zap/source/any/mem/win1252enc.c +++ b/zap/source/any/mem/win1252enc.c @@ -6,15 +6,15 @@ #include <zap/mem.h> -void zap_win1252enc(zap_chr8 * const _dest,zap_chr02 const * const _src) { - zap_chr8 * dest; - zap_chr02 const * src; +void zap_win1252enc(zap_i8 * const _dest,zap_i02 const * const _src) { + zap_i8 * dest; + zap_i02 const * src; for (dest = _dest,src = _src;;++src,++dest) { - zap_chr02 const chr = *src; + zap_i02 const chr = *src; if (chr == 0x0u) { break; } - zap_chr8 const bad = 0x3Fu; + zap_i8 const bad = 0x3Fu; switch (chr) { default: if (chr > 0xFFu) { |