summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile91
-rw-r--r--README.md4
-rw-r--r--changelog.md16
-rw-r--r--docs/u8c_abrt.314
-rw-r--r--docs/u8c_abrtfn.327
-rw-r--r--docs/u8c_u32max.318
-rw-r--r--docs/u8c_unimax.319
-rw-r--r--docs/u8c_ver.32
-rw-r--r--include/u8c/intern.h (renamed from src/u8c/intern.h)8
-rw-r--r--include/u8c/main.h8
-rw-r--r--include/u8c/u16.h4
-rw-r--r--include/u8c/u32.h22
-rw-r--r--src/u8c/err.h.d/geterr.c (renamed from src/u8c/geterr.c)4
-rw-r--r--src/u8c/err.h.d/regerrhandl.c (renamed from src/u8c/regerrhandl.c)2
-rw-r--r--src/u8c/err.h.d/seterr.c (renamed from src/u8c/seterr.c)2
-rw-r--r--src/u8c/fmt.h.d/fmt.c (renamed from src/u8c/fmt.c)0
-rw-r--r--src/u8c/fmt.h.d/print.c (renamed from src/u8c/print.c)0
-rw-r--r--src/u8c/fmt.h.d/println.c (renamed from src/u8c/println.c)0
-rw-r--r--src/u8c/fmt.h.d/setfmt.c (renamed from src/u8c/setfmt.c)2
-rw-r--r--src/u8c/fmt.h.d/vfmt.c (renamed from src/u8c/vfmt.c)2
-rw-r--r--src/u8c/fmt.h.d/vprint.c (renamed from src/u8c/vprint.c)2
-rw-r--r--src/u8c/intern.h.d/dat.c (renamed from src/u8c/dat.c)2
-rw-r--r--src/u8c/is.h.d/isalnum.c (renamed from src/u8c/isalnum.c)0
-rw-r--r--src/u8c/is.h.d/isalpha.c (renamed from src/u8c/isalpha.c)0
-rw-r--r--src/u8c/is.h.d/iscntrl.c (renamed from src/u8c/iscntrl.c)0
-rw-r--r--src/u8c/is.h.d/isdigit.c (renamed from src/u8c/isdigit.c)0
-rw-r--r--src/u8c/is.h.d/ispunct.c (renamed from src/u8c/ispunct.c)0
-rw-r--r--src/u8c/is.h.d/isspace.c (renamed from src/u8c/isspace.c)0
-rw-r--r--src/u8c/is.h.d/isxdigit.c (renamed from src/u8c/isxdigit.c)0
-rw-r--r--src/u8c/main.h.d/abrtfn.c (renamed from src/u8c/abrt.c)6
-rw-r--r--src/u8c/main.h.d/debug.c (renamed from src/u8c/debug.c)0
-rw-r--r--src/u8c/main.h.d/end.c (renamed from src/u8c/end.c)2
-rw-r--r--src/u8c/main.h.d/init.c (renamed from src/u8c/init.c)3
-rw-r--r--src/u8c/main.h.d/thrdsafe.c (renamed from src/u8c/thrdsafe.c)0
-rw-r--r--src/u8c/u16.h.d/u16alloc.c (renamed from src/u8c/u16alloc.c)1
-rw-r--r--src/u8c/u16.h.d/u16free.c (renamed from src/u8c/u16free.c)0
-rw-r--r--src/u8c/u32.h.d/u32alloc.c (renamed from src/u8c/u32alloc.c)1
-rw-r--r--src/u8c/u32.h.d/u32cat.c (renamed from src/u8c/u32cat.c)0
-rw-r--r--src/u8c/u32.h.d/u32cmp.c (renamed from src/u8c/u32cmp.c)0
-rw-r--r--src/u8c/u32.h.d/u32cp.c (renamed from src/u8c/u32cp.c)0
-rw-r--r--src/u8c/u32.h.d/u32fndchr.c (renamed from src/u8c/u32fndchr.c)0
-rw-r--r--src/u8c/u32.h.d/u32fndpat.c (renamed from src/u8c/u32fndpat.c)0
-rw-r--r--src/u8c/u32.h.d/u32free.c (renamed from src/u8c/u32free.c)0
-rw-r--r--src/u8c/u32.h.d/u32ins.c (renamed from src/u8c/u32ins.c)0
-rw-r--r--src/u8c/u32.h.d/u32substr.c (renamed from src/u8c/u32substr.c)0
-rw-r--r--src/u8c/u32.h.d/u32sz.c (renamed from src/u8c/u32sz.c)0
-rw-r--r--src/u8c/u8.h.d/u8alloc.c (renamed from src/u8c/u8alloc.c)1
-rw-r--r--src/u8c/u8.h.d/u8dec.c (renamed from src/u8c/u8dec.c)34
-rw-r--r--src/u8c/u8.h.d/u8enc.c (renamed from src/u8c/u8enc.c)18
-rw-r--r--src/u8c/u8.h.d/u8free.c (renamed from src/u8c/u8free.c)0
-rw-r--r--test.c505
51 files changed, 453 insertions, 367 deletions
diff --git a/Makefile b/Makefile
index 6557d62..b65ad88 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
-CC = clang
-CFLAGS = -std=c17 -Wall -Wextra -Wmissing-prototypes -pedantic-errors -Iinclude -fPIC
+CC = gcc
+CFLAGS = -std=c2x -Wall -Wextra -Wmissing-prototypes -pedantic-errors -Iinclude -fPIC
ifneq ($(thrdsafe),0)
CFLAGS += -Du8c_bethrdsafe
endif
@@ -19,46 +19,46 @@ HDRS = \
include/u8c/u32.h \
include/u8c/u8.h
HDRS_PRIV = \
- src/u8c/intern.h
+ include/u8c/intern.h
SRCS = \
- src/u8c/abrt.c \
- src/u8c/dat.c \
- src/u8c/debug.c \
- src/u8c/end.c \
- src/u8c/fmt.c \
- src/u8c/geterr.c \
- src/u8c/init.c \
- src/u8c/isalnum.c \
- src/u8c/isalpha.c \
- src/u8c/iscntrl.c \
- src/u8c/isdigit.c \
- src/u8c/isspace.c \
- src/u8c/ispunct.c \
- src/u8c/isxdigit.c \
- src/u8c/print.c \
- src/u8c/println.c \
- src/u8c/regerrhandl.c \
- src/u8c/seterr.c \
- src/u8c/setfmt.c \
- src/u8c/thrdsafe.c \
- src/u8c/u16alloc.c \
- src/u8c/u16free.c \
- src/u8c/u32alloc.c \
- src/u8c/u32cat.c \
- src/u8c/u32cmp.c \
- src/u8c/u32cp.c \
- src/u8c/u32fndchr.c \
- src/u8c/u32fndpat.c \
- src/u8c/u32free.c \
- src/u8c/u32ins.c \
- src/u8c/u32substr.c \
- src/u8c/u32sz.c \
- src/u8c/u8alloc.c \
- src/u8c/u8dec.c \
- src/u8c/u8enc.c \
- src/u8c/u8free.c \
- src/u8c/vfmt.c \
- src/u8c/vprint.c
+ src/u8c/err.h.d/geterr.c \
+ src/u8c/err.h.d/regerrhandl.c \
+ src/u8c/err.h.d/seterr.c \
+ src/u8c/fmt.h.d/fmt.c \
+ src/u8c/fmt.h.d/print.c \
+ src/u8c/fmt.h.d/println.c \
+ src/u8c/fmt.h.d/setfmt.c \
+ src/u8c/fmt.h.d/vfmt.c \
+ src/u8c/fmt.h.d/vprint.c \
+ src/u8c/intern.h.d/dat.c \
+ src/u8c/is.h.d/isalnum.c \
+ src/u8c/is.h.d/isalpha.c \
+ src/u8c/is.h.d/iscntrl.c \
+ src/u8c/is.h.d/isdigit.c \
+ src/u8c/is.h.d/ispunct.c \
+ src/u8c/is.h.d/isspace.c \
+ src/u8c/is.h.d/isxdigit.c \
+ src/u8c/main.h.d/abrtfn.c \
+ src/u8c/main.h.d/debug.c \
+ src/u8c/main.h.d/end.c \
+ src/u8c/main.h.d/init.c \
+ src/u8c/main.h.d/thrdsafe.c \
+ src/u8c/u8.h.d/u8alloc.c \
+ src/u8c/u8.h.d/u8dec.c \
+ src/u8c/u8.h.d/u8enc.c \
+ src/u8c/u8.h.d/u8free.c \
+ src/u8c/u16.h.d/u16alloc.c \
+ src/u8c/u16.h.d/u16free.c \
+ src/u8c/u32.h.d/u32alloc.c \
+ src/u8c/u32.h.d/u32cat.c \
+ src/u8c/u32.h.d/u32cmp.c \
+ src/u8c/u32.h.d/u32cp.c \
+ src/u8c/u32.h.d/u32fndchr.c \
+ src/u8c/u32.h.d/u32fndpat.c \
+ src/u8c/u32.h.d/u32free.c \
+ src/u8c/u32.h.d/u32ins.c \
+ src/u8c/u32.h.d/u32substr.c \
+ src/u8c/u32.h.d/u32sz.c
OBJS = $(SRCS:.c=.o)
LIB = libu8c.so
$(LIB): $(OBJS)
@@ -66,6 +66,7 @@ $(LIB): $(OBJS)
$(OBJS): $(HDRS) $(HDRS_PRIV)
DOCS = \
docs/u8c_abrt.3.gz \
+ docs/u8c_abrtfn.3.gz \
docs/u8c_col.3.gz \
docs/u8c_dbg.3.gz \
docs/u8c_dbgprint.3.gz \
@@ -79,7 +80,7 @@ DOCS = \
docs/u8c_isalnum.3.gz \
docs/u8c_isalpha.3.gz \
docs/u8c_iscntrl.3.gz \
- docs/u8c_isdigit.3.gz \
+ docs/u8c_isdigit.3.gz \
docs/u8c_ispunct.3.gz \
docs/u8c_isspace.3.gz \
docs/u8c_isxdigit.3.gz \
@@ -103,14 +104,14 @@ DOCS = \
docs/u8c_u32ins.3.gz \
docs/u8c_u32substr.3.gz \
docs/u8c_u32sz.3.gz \
- docs/u8c_unimax.3.gz \
+ docs/u8c_u32max.3.gz \
docs/u8c_ver.3.gz \
docs/u8c_vfmt.3.gz \
docs/u8c_vprint.3.gz
-$(DOCS):errhandltyp
+$(DOCS):
gzip --keep $(DOCS:.gz=)
test: $(LIB) test.c
- $(CC) -std=c17 -Wall -Wextra -Wpedantic -Iinclude -O3 -g -L. -lu8c -o $@ [email protected]
+ $(CC) -std=c2x -Wall -Wextra -Wpedantic -Iinclude -O3 -g -L. -lu8c -o $@ [email protected]
.PHONY: clean docs install runtest
clean:
rm --force test $(DOCS) $(LIB) $(OBJS)
diff --git a/README.md b/README.md
index 3480dce..20933de 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,13 @@
# u8c
-[*u8c*](https://mandelbrot.dk/delta/u8c) is a cross-platform, free, and open-source library for transforming Unicode codepoints, as well as encoding them into UTF-8.
+[*u8c*](https://mandelbrot.dk/delta/u8c) is a free, open-source and portable library for Unicode manipulation.
## Installing
*u8c* can be installed, either via the `install` target in the provided Makefile, or using the PKGBUILD found [here](https://mandelbrot.dk/pkgbuild/delta/u8c).
+If it's installed so, one must make a note of the output, as it logs what system files have changed.
+
Using the PKGBUILD is as simple as `git clone https://mandelbrot.dk/pkgbuild/delta/u8c.git && cd u8c && makepkg --clean --install --syncdeps` (on Arch-based distributions).
## Copyright & License
diff --git a/changelog.md b/changelog.md
index 583941f..bad655b 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,3 +1,15 @@
+# 21
+
+* Update readme.
+* Require C23 (C2x).
+* Use GCC (has better C23 support).
+* Cleanup UTF-8 decoder and encoder (using binary literals).
+* Rename `u8c_u32max` to `u8c_u32max` and move it to `u8c/u32.h`.
+* Don't clear last error message on calls to `u8c_geterr`.
+* Restructure source files.
+* Fix makefile.
+* Update test program.
+
# 20
* Update documentation.
@@ -38,7 +50,7 @@
* `u8c_end`
* `u8c_init`
* `u8c_thrdsafe`
- * `u8c_unimax`
+ * `u8c_u32max`
* `u8c_ver`
* `u8c/u16.h`:
* `u8c_u16alloc`
@@ -121,7 +133,7 @@
* Remove `u8c_txt` in favour of Unicode string literals (much clearer code, but less portable).
* Add function for getting a sub-string of an UTF-32 string; `u8c_u32substr`.
* Don't count the null-terminator in string sizes.
-* Add macro for maximum valid Unicode codepoint; `u8c_unimax`.
+* Add macro for maximum valid Unicode codepoint; `u8c_u32max`.
* Remove `txttolit`.
* Add function for deallocating UTF-8 strings; `u8c_u8free`.
* Turn both `u8c_dbg` and `u8c_thrdsafe` into type `bool` from `uint_least8_t`.
diff --git a/docs/u8c_abrt.3 b/docs/u8c_abrt.3
index 6ea816c..7c92b28 100644
--- a/docs/u8c_abrt.3
+++ b/docs/u8c_abrt.3
@@ -7,19 +7,13 @@ u8c_abrt - Abort - Abort program with diagnostic information.
.nf
\f[C]
/* # include <u8c/main.h> */
-# include <stdbool.h
-# include <stdnoreturn.h>
-# include <uchar.h>
-extern noreturn bool u8c_abrt(char const * const fl,long long const ln,char const * const fn,char const * const why);
+# include <u8c/main.h
+# define u8c_abrt(why) u8c_abrtfn(__FILE__,(long)__LINE__,__func__,why)
\f[R]
.fi
.SH DESCRIPTION
.PP
-The function \f[B]u8c_abrt\f[R] aborts the program and prints diagnostic infiormation to \f[B]stderr\f[R].
-.PP
-\f[B]__FILE__\f[R] is to be passed at \f[B]fl\f[R], \f[B](long long)__LINE__\f[R] at \f[B]ln\f[R], and \f[B]__func__\f[R] at \f[B]fn\f[R]. A standard string (\f[B]char const *\f[R]) must be passed at \f[B]why\f[R], which explains the reason for aborting.
-.PP
-All arguments are printed, in the end followed by a timestamp representing the number of seconds passed since the current epoch (as returned by \f[B]time(NULL)\f[R]).
+The macro \f[B]u8c_abrt\f[R] expands to a valid call to \f[B]u8c_abrtfn\f[R].
.SH VERSION
.PP
-u8c 16
+u8c 21
diff --git a/docs/u8c_abrtfn.3 b/docs/u8c_abrtfn.3
new file mode 100644
index 0000000..5fbba82
--- /dev/null
+++ b/docs/u8c_abrtfn.3
@@ -0,0 +1,27 @@
+.TH "u8c_abrtfn" "3" "" "u8c" "u8c API Manual"
+.SH NAME
+.PP
+u8c_abrtfn - Abort functions - Abort program with diagnostic information.
+.SH DECLARATION
+.PP
+.nf
+\f[C]
+/* # include <u8c/main.h> */
+# include <stdbool.h
+# include <stdnoreturn.h>
+# include <uchar.h>
+extern noreturn bool u8c_abrtfn(char const * const fl,long const ln,char const * const fn,char const * const why);
+\f[R]
+.fi
+.SH DESCRIPTION
+.PP
+The function \f[B]u8c_abrtfn\f[R] aborts the program and prints diagnostic infiormation to \f[B]stderr\f[R].
+.PP
+\f[B]__FILE__\f[R] is to be passed at \f[B]fl\f[R], \f[B](long)__LINE__\f[R] at \f[B]ln\f[R], and \f[B]__func__\f[R] at \f[B]fn\f[R]. A standard string (\f[B]char const *\f[R]) must be passed at \f[B]why\f[R], which explains the reason for aborting.
+.PP
+All arguments are printed, in the end followed by a timestamp representing the number of seconds passed since the current epoch (as returned by \f[B]time(NULL)\f[R]).
+.PP
+It's recommended to use the convenience macro \f[B]u8c_abrt\f[R], as it expands to a valid call to \f[B]u8c_abrt\f[R].
+.SH VERSION
+.PP
+u8c 16 (as \f[B]u8c_abrt\f[R]), u8c 21
diff --git a/docs/u8c_u32max.3 b/docs/u8c_u32max.3
new file mode 100644
index 0000000..fdb7270
--- /dev/null
+++ b/docs/u8c_u32max.3
@@ -0,0 +1,18 @@
+.TH "u8c_u32max" "3" "" "u8c" "u8c API Manual"
+.SH NAME
+.PP
+u8c_u32max - UTF-32 maximum - Maximum valid UTF-32 value.
+.SH DECLARATION
+.PP
+.nf
+\f[C]
+/* # include <u8c/u32.h> */
+# include <uchar.h>
+static char32_t const u8c_u32max = U'\x10FFFF';
+\f[R]
+.fi
+.SH DESCRIPTION
+.PP
+.SH VERSION
+.PP
+u8c 16 (as \f[B]u8c_unimax\f[R]), u8c 21
diff --git a/docs/u8c_unimax.3 b/docs/u8c_unimax.3
deleted file mode 100644
index 8f6165d..0000000
--- a/docs/u8c_unimax.3
+++ /dev/null
@@ -1,19 +0,0 @@
-.TH "u8c_unimax" "3" "" "u8c" "u8c API Manual"
-.SH NAME
-.PP
-u8c_unimax - Unicode maximum - Maximum valid Unicode codepoint.
-.SH DECLARATION
-.PP
-.nf
-\f[C]
-/* # include <u8c/main.h> */
-# include <stdint.h>
-# include <uchar.h>
-# define u8c_unimax ((char32_t)UINT32_C(0x10FFFF))
-\f[R]
-.fi
-.SH DESCRIPTION
-.PP
-.SH VERSION
-.PP
-u8c 16
diff --git a/docs/u8c_ver.3 b/docs/u8c_ver.3
index 388b5cb..c1a2dc3 100644
--- a/docs/u8c_ver.3
+++ b/docs/u8c_ver.3
@@ -8,7 +8,7 @@ u8c_ver - Version - Version of the u8c API.
\f[C]
/* # include <u8c/main.h> */
# include <stdint.h>
-# define u8c_ver (UINT64_C(/* version */))
+static uint_least64_t const u8c_ver = /* version */;
\f[R]
.fi
.SH DESCRIPTION
diff --git a/src/u8c/intern.h b/include/u8c/intern.h
index ab7644c..6aeaee2 100644
--- a/src/u8c/intern.h
+++ b/include/u8c/intern.h
@@ -35,10 +35,10 @@ struct u8c_dattyp {
bool fmtendian;
uint_least8_t stat;
# if defined(u8c_bethrdsafe)
- mtx_t errlock;
- mtx_t errhandlslock;
- mtx_t fmtlock;
- mtx_t outlock;
+ mtx_t errlock;
+ mtx_t errhandlslock;
+ mtx_t fmtlock;
+ mtx_t outlock;
# endif
};
/* Functions */
diff --git a/include/u8c/main.h b/include/u8c/main.h
index 49049f6..2a13cc0 100644
--- a/include/u8c/main.h
+++ b/include/u8c/main.h
@@ -24,13 +24,13 @@
/* Type definitions: */
/* Structures: */
/* Functions */
-extern noreturn bool u8c_abrt(char const * const fl,long long const ln,char const * const fn,char const * const why);
-extern bool u8c_end( void);
-extern bool u8c_init(void);
+extern noreturn bool u8c_abrtfn(char const * const fl,long const ln,char const * const fn,char const * const why);
+extern bool u8c_end( void);
+extern bool u8c_init( void);
/* Constants & Variables: */
extern bool const u8c_dbg;
extern bool const u8c_thrdsafe;
-static char32_t const u8c_unimax = (char32_t)UINT32_C(0x10FFFF);
static uint_least64_t const u8c_ver = UINT64_C(0x19);
/* Macros: */
+# define u8c_abrt(why) u8c_abrtfn(__FILE__,(long)__LINE__,__func__,why)
# endif
diff --git a/include/u8c/u16.h b/include/u8c/u16.h
index 1babb69..8d81784 100644
--- a/include/u8c/u16.h
+++ b/include/u8c/u16.h
@@ -22,8 +22,8 @@
/* Type definitions: */
/* Structures: */
/* Functions */
-extern bool u8c_u16alloc(char16_t * * const u16,size_t const sz);
-extern bool u8c_u16free(char16_t const * * const u16);
+extern bool u8c_u16alloc(char16_t * * const u16,size_t const sz);
+extern bool u8c_u16free( char16_t const * * const u16);
/* Constants & Variables: */
/* Macros: */
# endif
diff --git a/include/u8c/u32.h b/include/u8c/u32.h
index 08ac161..e5567e7 100644
--- a/include/u8c/u32.h
+++ b/include/u8c/u32.h
@@ -17,21 +17,23 @@
# define u8c_hdr_u32
# include <stdbool.h>
# include <stddef.h>
+# include <stdint.h>
# include <uchar.h>
/* Enumerations: */
/* Type definitions: */
/* Structures: */
/* Functions */
-extern bool u8c_u32alloc(char32_t * * const u32,size_t const sz);
-extern bool u8c_u32cat(size_t * const sz,char32_t const * * const out,char32_t const * const lstr,char32_t const * const rstr);
-extern bool u8c_u32cmp(uint_least8_t * const res,char32_t const * const lstr,char32_t const * const rstr);
-extern bool u8c_u32cp(size_t * const sz,char32_t const * * const out,char32_t const * const in);
-extern bool u8c_u32fndchr(size_t * const pos,char32_t const * const in,char32_t const chr);
-extern bool u8c_u32fndpat(size_t * const pos,char32_t const * const in,char32_t const * const pat);
-extern bool u8c_u32free(char32_t const * * const u32);
-extern bool u8c_u32ins(size_t * const sz,char32_t const * * const out,size_t const pos,char32_t const * const str0,char32_t const * const str1);
-extern bool u8c_u32substr(char32_t const * * const out,size_t const start,size_t const len,char32_t const * const in);
-extern bool u8c_u32sz(size_t * sz,char32_t const * in);
+extern bool u8c_u32alloc( char32_t * * const u32,size_t const sz);
+extern bool u8c_u32cat( size_t * const sz, char32_t const * * const out, char32_t const * const lstr,char32_t const * const rstr);
+extern bool u8c_u32cmp( uint_least8_t * const res,char32_t const * const lstr, char32_t const * const rstr);
+extern bool u8c_u32cp( size_t * const sz, char32_t const * * const out, char32_t const * const in);
+extern bool u8c_u32fndchr(size_t * const pos,char32_t const * const in, char32_t const chr);
+extern bool u8c_u32fndpat(size_t * const pos,char32_t const * const in, char32_t const * const pat);
+extern bool u8c_u32free( char32_t const * * const u32);
+extern bool u8c_u32ins( size_t * const sz, char32_t const * * const out, size_t const pos, char32_t const * const str0,char32_t const * const str1);
+extern bool u8c_u32substr(char32_t const * * const out,size_t const start,size_t const len, char32_t const * const in);
+extern bool u8c_u32sz( size_t * sz, char32_t const * in);
/* Constants & Variables: */
+static char32_t const u8c_u32max = U'\x10FFFF';
/* Macros: */
# endif
diff --git a/src/u8c/geterr.c b/src/u8c/err.h.d/geterr.c
index 3d8c220..58f3612 100644
--- a/src/u8c/geterr.c
+++ b/src/u8c/err.h.d/geterr.c
@@ -13,19 +13,17 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include "intern.h"
# include <stdbool.h>
# include <stddef.h>
# include <stdint.h>
# include <u8c/err.h>
+# include <u8c/intern.h>
# include <u8c/u32.h>
bool u8c_geterr(size_t * const _sz,char32_t const * * const _out) {
# if defined(u8c_bethrdsafe)
mtx_lock(&u8c_dat.errlock);
# endif
u8c_u32cp(_sz,_out,u8c_dat.err);
- u8c_u32free(&u8c_dat.err);
- u8c_u32cp(_sz,&u8c_dat.err,U"");
# if defined(u8c_bethrdsafe)
mtx_unlock(&u8c_dat.errlock);
# endif
diff --git a/src/u8c/regerrhandl.c b/src/u8c/err.h.d/regerrhandl.c
index ef41e31..5e97177 100644
--- a/src/u8c/regerrhandl.c
+++ b/src/u8c/err.h.d/regerrhandl.c
@@ -13,10 +13,10 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include "intern.h"
# include <stdbool.h>
# include <stddef.h>
# include <u8c/err.h>
+# include <u8c/intern.h>
static void u8c_regerrhandl_seterrhandl(enum u8c_errtyp _typ,u8c_errhandltyp _errhandl) {
u8c_dat.errhandls[(size_t)_typ] = _errhandl;
}
diff --git a/src/u8c/seterr.c b/src/u8c/err.h.d/seterr.c
index f356e5f..017e45e 100644
--- a/src/u8c/seterr.c
+++ b/src/u8c/err.h.d/seterr.c
@@ -13,13 +13,13 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include "intern.h"
# include <assert.h>
# include <stdbool.h>
# include <stddef.h>
# include <stdint.h>
# include <u8c/err.h>
# include <u8c/fmt.h>
+# include <u8c/intern.h>
# include <u8c/u32.h>
# if defined(u8c_bethrdsafe)
# include <threads.h>
diff --git a/src/u8c/fmt.c b/src/u8c/fmt.h.d/fmt.c
index 43f1ea4..43f1ea4 100644
--- a/src/u8c/fmt.c
+++ b/src/u8c/fmt.h.d/fmt.c
diff --git a/src/u8c/print.c b/src/u8c/fmt.h.d/print.c
index 8785ad8..8785ad8 100644
--- a/src/u8c/print.c
+++ b/src/u8c/fmt.h.d/print.c
diff --git a/src/u8c/println.c b/src/u8c/fmt.h.d/println.c
index 1a924ad..1a924ad 100644
--- a/src/u8c/println.c
+++ b/src/u8c/fmt.h.d/println.c
diff --git a/src/u8c/setfmt.c b/src/u8c/fmt.h.d/setfmt.c
index 05fa9c1..7956ea3 100644
--- a/src/u8c/setfmt.c
+++ b/src/u8c/fmt.h.d/setfmt.c
@@ -13,10 +13,10 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include "intern.h"
# include <stdbool.h>
# include <stdint.h>
# include <u8c/fmt.h>
+# include <u8c/intern.h>
# if defined(u8c_bethrdsafe)
# include <threads.h>
# endif
diff --git a/src/u8c/vfmt.c b/src/u8c/fmt.h.d/vfmt.c
index ed7e13f..5b0c1e1 100644
--- a/src/u8c/vfmt.c
+++ b/src/u8c/fmt.h.d/vfmt.c
@@ -21,6 +21,6 @@
# if defined(u8c_bethrdsafe)
# include <threads.h>
# endif
-bool u8c_vfmt(size_t * const _sz,char32_t const * * const _out,char32_t const * const _in,va_list _args) {
+bool u8c_vfmt(size_t * const _sz,char32_t const * * const _out,char32_t const * const _in,[[maybe_unused]] va_list _args) {
return u8c_u32cp(_sz,_out,_in);
}
diff --git a/src/u8c/vprint.c b/src/u8c/fmt.h.d/vprint.c
index 7555ce1..8d824a8 100644
--- a/src/u8c/vprint.c
+++ b/src/u8c/fmt.h.d/vprint.c
@@ -13,7 +13,6 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include "intern.h"
# include <assert.h>
# include <stdarg.h>
# include <stdbool.h>
@@ -23,6 +22,7 @@
# include <u8c/SIZE_C.h>
# include <u8c/err.h>
# include <u8c/fmt.h>
+# include <u8c/intern.h>
# include <u8c/u32.h>
# include <u8c/u8.h>
# include <uchar.h>
diff --git a/src/u8c/dat.c b/src/u8c/intern.h.d/dat.c
index 55203c6..77d4962 100644
--- a/src/u8c/dat.c
+++ b/src/u8c/intern.h.d/dat.c
@@ -13,11 +13,11 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include "intern.h"
# include <stdbool.h>
# include <stddef.h>
# include <stdint.h>
# include <u8c/SIZE_C.h>
+# include <u8c/intern.h>
struct u8c_dattyp u8c_dat = {
.err = NULL,
.fmtendian = false,
diff --git a/src/u8c/isalnum.c b/src/u8c/is.h.d/isalnum.c
index 13834c3..13834c3 100644
--- a/src/u8c/isalnum.c
+++ b/src/u8c/is.h.d/isalnum.c
diff --git a/src/u8c/isalpha.c b/src/u8c/is.h.d/isalpha.c
index d5952dc..d5952dc 100644
--- a/src/u8c/isalpha.c
+++ b/src/u8c/is.h.d/isalpha.c
diff --git a/src/u8c/iscntrl.c b/src/u8c/is.h.d/iscntrl.c
index 4dcf543..4dcf543 100644
--- a/src/u8c/iscntrl.c
+++ b/src/u8c/is.h.d/iscntrl.c
diff --git a/src/u8c/isdigit.c b/src/u8c/is.h.d/isdigit.c
index 8b799d9..8b799d9 100644
--- a/src/u8c/isdigit.c
+++ b/src/u8c/is.h.d/isdigit.c
diff --git a/src/u8c/ispunct.c b/src/u8c/is.h.d/ispunct.c
index f6b041f..f6b041f 100644
--- a/src/u8c/ispunct.c
+++ b/src/u8c/is.h.d/ispunct.c
diff --git a/src/u8c/isspace.c b/src/u8c/is.h.d/isspace.c
index 9473476..9473476 100644
--- a/src/u8c/isspace.c
+++ b/src/u8c/is.h.d/isspace.c
diff --git a/src/u8c/isxdigit.c b/src/u8c/is.h.d/isxdigit.c
index 4a59b0d..4a59b0d 100644
--- a/src/u8c/isxdigit.c
+++ b/src/u8c/is.h.d/isxdigit.c
diff --git a/src/u8c/abrt.c b/src/u8c/main.h.d/abrtfn.c
index 6773827..80a03e3 100644
--- a/src/u8c/abrt.c
+++ b/src/u8c/main.h.d/abrtfn.c
@@ -13,7 +13,6 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include "intern.h"
# include <inttypes.h>
# include <stdbool.h>
# include <stdint.h>
@@ -21,9 +20,10 @@
# include <stdlib.h>
# include <stdnoreturn.h>
# include <time.h>
+# include <u8c/intern.h>
# include <u8c/main.h>
-noreturn bool u8c_abrt(char const * const _fl,long long const _ln,char const * const _fn,char const * const _why) {
- fprintf(stderr,"u8c: *** Aborted (\"%s\":%lld in function \"%s\": \"%s\" @ %" PRIuMAX ") ***\nLibrary diagnostics:\n debug:%s\n status:%" PRIuLEAST8 "\n thread-safe:%s\n version:%" PRIuLEAST64 "\n",_fl,_ln,_fn,_why,(intmax_t)time(NULL),u8c_dbg ? "true" : "false",u8c_dat.stat,u8c_thrdsafe ? "true" : "false",u8c_ver);
+noreturn bool u8c_abrtfn(char const * const _fl,long const _ln,char const * const _fn,char const * const _why) {
+ fprintf(stderr,"u8c: *** Aborted (\"%s\":%li in function \"%s\": \"%s\" @ %" PRIuMAX ") ***\nLibrary diagnostics:\n debug:%s\n status:%" PRIuLEAST8 "\n thread-safe:%s\n version:%" PRIuLEAST64 "\n",_fl,_ln,_fn,_why,(intmax_t)time(NULL),u8c_dbg ? "true" : "false",u8c_dat.stat,u8c_thrdsafe ? "true" : "false",u8c_ver);
fprintf(stderr,"Trying to clean up...\n");
u8c_end();
fprintf(stderr,"Aborting...\n");
diff --git a/src/u8c/debug.c b/src/u8c/main.h.d/debug.c
index e42275c..e42275c 100644
--- a/src/u8c/debug.c
+++ b/src/u8c/main.h.d/debug.c
diff --git a/src/u8c/end.c b/src/u8c/main.h.d/end.c
index f0e82e3..ef8114c 100644
--- a/src/u8c/end.c
+++ b/src/u8c/main.h.d/end.c
@@ -13,11 +13,11 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include "intern.h"
# include <stdbool.h>
# include <stdint.h>
# include <stdlib.h>
# include <u8c/SIZE_C.h>
+# include <u8c/intern.h>
# include <u8c/main.h>
# include <u8c/u32.h>
# if defined(u8c_bethrdsafe)
diff --git a/src/u8c/init.c b/src/u8c/main.h.d/init.c
index 3769109..0b34577 100644
--- a/src/u8c/init.c
+++ b/src/u8c/main.h.d/init.c
@@ -16,12 +16,11 @@
# if !defined(__STDC_UTF_32__)
# error UTF-32 is required.
# endif
-# include "intern.h"
-# include <setjmp.h>
# include <stdbool.h>
# include <stddef.h>
# include <stdint.h>
# include <u8c/err.h>
+# include <u8c/intern.h>
# include <u8c/main.h>
# include <u8c/u32.h>
# if defined(u8c_bethrdsafe)
diff --git a/src/u8c/thrdsafe.c b/src/u8c/main.h.d/thrdsafe.c
index 9d8e41a..9d8e41a 100644
--- a/src/u8c/thrdsafe.c
+++ b/src/u8c/main.h.d/thrdsafe.c
diff --git a/src/u8c/u16alloc.c b/src/u8c/u16.h.d/u16alloc.c
index 2945e79..3906017 100644
--- a/src/u8c/u16alloc.c
+++ b/src/u8c/u16.h.d/u16alloc.c
@@ -13,7 +13,6 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include "intern.h"
# include <stdbool.h>
# include <stdlib.h>
# include <u8c/err.h>
diff --git a/src/u8c/u16free.c b/src/u8c/u16.h.d/u16free.c
index d447562..d447562 100644
--- a/src/u8c/u16free.c
+++ b/src/u8c/u16.h.d/u16free.c
diff --git a/src/u8c/u32alloc.c b/src/u8c/u32.h.d/u32alloc.c
index 341fa03..b64a1ee 100644
--- a/src/u8c/u32alloc.c
+++ b/src/u8c/u32.h.d/u32alloc.c
@@ -13,7 +13,6 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include "intern.h"
# include <stdbool.h>
# include <stdlib.h>
# include <u8c/err.h>
diff --git a/src/u8c/u32cat.c b/src/u8c/u32.h.d/u32cat.c
index 600e0dc..600e0dc 100644
--- a/src/u8c/u32cat.c
+++ b/src/u8c/u32.h.d/u32cat.c
diff --git a/src/u8c/u32cmp.c b/src/u8c/u32.h.d/u32cmp.c
index 8a6617d..8a6617d 100644
--- a/src/u8c/u32cmp.c
+++ b/src/u8c/u32.h.d/u32cmp.c
diff --git a/src/u8c/u32cp.c b/src/u8c/u32.h.d/u32cp.c
index 95a9b35..95a9b35 100644
--- a/src/u8c/u32cp.c
+++ b/src/u8c/u32.h.d/u32cp.c
diff --git a/src/u8c/u32fndchr.c b/src/u8c/u32.h.d/u32fndchr.c
index 228c553..228c553 100644
--- a/src/u8c/u32fndchr.c
+++ b/src/u8c/u32.h.d/u32fndchr.c
diff --git a/src/u8c/u32fndpat.c b/src/u8c/u32.h.d/u32fndpat.c
index 5a1b5d2..5a1b5d2 100644
--- a/src/u8c/u32fndpat.c
+++ b/src/u8c/u32.h.d/u32fndpat.c
diff --git a/src/u8c/u32free.c b/src/u8c/u32.h.d/u32free.c
index a0b120b..a0b120b 100644
--- a/src/u8c/u32free.c
+++ b/src/u8c/u32.h.d/u32free.c
diff --git a/src/u8c/u32ins.c b/src/u8c/u32.h.d/u32ins.c
index 7fccb7c..7fccb7c 100644
--- a/src/u8c/u32ins.c
+++ b/src/u8c/u32.h.d/u32ins.c
diff --git a/src/u8c/u32substr.c b/src/u8c/u32.h.d/u32substr.c
index 855d062..855d062 100644
--- a/src/u8c/u32substr.c
+++ b/src/u8c/u32.h.d/u32substr.c
diff --git a/src/u8c/u32sz.c b/src/u8c/u32.h.d/u32sz.c
index deb1ecd..deb1ecd 100644
--- a/src/u8c/u32sz.c
+++ b/src/u8c/u32.h.d/u32sz.c
diff --git a/src/u8c/u8alloc.c b/src/u8c/u8.h.d/u8alloc.c
index a046a28..ba02bc8 100644
--- a/src/u8c/u8alloc.c
+++ b/src/u8c/u8.h.d/u8alloc.c
@@ -13,7 +13,6 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include "intern.h"
# include <stdbool.h>
# include <stdlib.h>
# include <u8c/err.h>
diff --git a/src/u8c/u8dec.c b/src/u8c/u8.h.d/u8dec.c
index a484601..365c81a 100644
--- a/src/u8c/u8dec.c
+++ b/src/u8c/u8.h.d/u8dec.c
@@ -33,19 +33,19 @@ bool u8c_u8dec(size_t * const _sz,char32_t const * * const _out,unsigned char co
insz = n;
goto nottoobig;
}
- if(tmp >= UINT8_C(0xF8)) { /* Too big. */
+ if(tmp >= UINT8_C(0b11111000)) { /* Too big. */
u8c_seterr(U"u8c_u8dec: Character out of range (too big).",u8c_errtyp_u8oor);
return true;
}
- if(tmp >= UINT8_C(0xF0)) { /* Four byte. */
+ if(tmp >= UINT8_C(0b11110000)) { /* Four byte. */
n += SIZE_C(0x4);
continue;
}
- if(tmp >= UINT8_C(0xE0)) { /* Three bytes. */
+ if(tmp >= UINT8_C(0b11100000)) { /* Three bytes. */
n += SIZE_C(0x3);
continue;
}
- if(tmp >= UINT8_C(0xC0)) { /* Two bytes. */
+ if(tmp >= UINT8_C(0b11000000)) { /* Two bytes. */
n += SIZE_C(0x2);
continue;
}
@@ -64,39 +64,39 @@ nottoobig:;
return false;
}
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);
+ if(_in[n] >= UINT8_C(0b11110000)) { /* Four bytes. */
+ uint_least32_t codep = (_in[n] ^ UINT32_C(0b11110000)) << UINT32_C(0x12);
n += SIZE_C(0x1);
- codep += (_in[n] ^ UINT32_C(0x80)) << UINT32_C(0xC);
+ codep += (_in[n] ^ UINT32_C(0b10000000)) << UINT32_C(0xC);
n += SIZE_C(0x1);
- codep += (_in[n] ^ UINT32_C(0x80)) << UINT32_C(0x6);
+ codep += (_in[n] ^ UINT32_C(0b10000000)) << UINT32_C(0x6);
n += SIZE_C(0x1);
- codep += (uint_least32_t)(_in[n]) ^ SIZE_C(0x80);
+ codep += (uint_least32_t)(_in[n]) ^ SIZE_C(0b10000000);
n += SIZE_C(0x1);
out[outn] = codep;
continue;
}
- if(_in[n] >= UINT8_C(0xE0)) { /* Three bytes. */
- uint_least32_t codep = (_in[n] ^ UINT32_C(0xE0)) << UINT32_C(0xC);
+ if(_in[n] >= UINT8_C(0b11100000)) { /* Three bytes. */
+ uint_least32_t codep = (_in[n] ^ UINT32_C(0b11100000)) << UINT32_C(0xC);
n += SIZE_C(0x1);
- codep += (_in[n] ^ UINT32_C(0x80)) << UINT32_C(0x6);
+ codep += (_in[n] ^ UINT32_C(0b10000000)) << UINT32_C(0x6);
n += SIZE_C(0x1);
- codep += _in[n] ^ UINT32_C(0x80);
+ codep += _in[n] ^ UINT32_C(0b10000000);
n += SIZE_C(0x1);
out[outn] = codep;
continue;
}
- if(_in[n] >= UINT8_C(0xC0)) { /* Two bytes. */
- uint_least32_t codep = (_in[n] ^ UINT32_C(0xC0)) << UINT32_C(0x6);
+ if(_in[n] >= UINT8_C(0b11000000)) { /* Two bytes. */
+ uint_least32_t codep = (_in[n] ^ UINT32_C(0b11000000)) << UINT32_C(0x6);
n += SIZE_C(0x1);
- codep += _in[n] ^ UINT32_C(0x80);
+ codep += _in[n] ^ UINT32_C(0b10000000);
n += SIZE_C(0x1);
out[outn] = codep;
continue;
}
/* One byte. */
out[outn] = (uint_least32_t)(_in[n]);
- n += SIZE_C(0x1);
+ n += SIZE_C(0x1);
continue;
}
u8c_u32free(_out);
diff --git a/src/u8c/u8enc.c b/src/u8c/u8.h.d/u8enc.c
index 61ccb2a..f3f3570 100644
--- a/src/u8c/u8enc.c
+++ b/src/u8c/u8.h.d/u8enc.c
@@ -19,7 +19,7 @@
# include <stdint.h>
# include <u8c/SIZE_C.h>
# include <u8c/err.h>
-# include <u8c/main.h>
+# include <u8c/u32.h>
# include <u8c/u8.h>
# include <uchar.h>
bool u8c_u8enc(size_t * const _sz,unsigned char const * * const _out,char32_t const * const _in) {
@@ -29,7 +29,7 @@ bool u8c_u8enc(size_t * const _sz,unsigned char const * * const _out,char32_t co
size_t outsz = SIZE_C(0x0); /* Size of output array /bytes). */
for(register 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. */
register char32_t const tmp = _in[n];
- if(tmp > u8c_unimax) { /* Codepoint out of range. */
+ if(tmp > u8c_u32max) { /* Codepoint out of range. */
u8c_seterr(U"u8c_u8enc: Codepoint out of range (too big).",u8c_errtyp_u32oor);
return true;
}
@@ -65,27 +65,27 @@ nottoobig:;
for(register 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. */
register char32_t const tmp = _in[n];
if(tmp >= UINT32_C(0x10000)) { // Four bytes.
- out[outn] = UINT8_C(0xF0) + (uint_least8_t)(tmp >> UINT32_C(0x12));
+ out[outn] = UINT8_C(0b11110000) + (uint_least8_t)(tmp >> UINT32_C(0x12));
outn += SIZE_C(0x1);
- out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0xC) & UINT8_C(0x3F));
+ out[outn] = UINT8_C(0b10000000) + (uint_least8_t)(tmp >> UINT32_C(0xC) & UINT8_C(0b00111111));
outn += SIZE_C(0x1);
- out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0x6) & UINT8_C(0x3F));
+ out[outn] = UINT8_C(0b10000000) + (uint_least8_t)(tmp >> UINT32_C(0x6) & UINT8_C(0b00111111));
outn += SIZE_C(0x1);
- out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT32_C(0x3F));
+ out[outn] = UINT8_C(0b10000000) + (uint_least8_t)(tmp & UINT32_C(0b00111111));
continue;
}
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)(tmp >> UINT32_C(0x6) & UINT8_C(0x3F));
+ out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp >> UINT32_C(0x6) & UINT8_C(0b00111111));
outn += SIZE_C(0x1);
- out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT32_C(0x3F));
+ out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT32_C(0b00111111));
continue;
}
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)(tmp & UINT8_C(0x3F));
+ out[outn] = UINT8_C(0x80) + (uint_least8_t)(tmp & UINT8_C(0b00111111));
continue;
}
/* One byte. */
diff --git a/src/u8c/u8free.c b/src/u8c/u8.h.d/u8free.c
index af5a6bd..af5a6bd 100644
--- a/src/u8c/u8free.c
+++ b/src/u8c/u8.h.d/u8free.c
diff --git a/test.c b/test.c
index 3f65afc..b638ded 100644
--- a/test.c
+++ b/test.c
@@ -1,5 +1,4 @@
# include <inttypes.h>
-# include <setjmp.h>
# include <stdarg.h>
# include <stdint.h>
# include <stdio.h>
@@ -11,6 +10,280 @@
# include <u8c/main.h>
# include <u8c/u32.h>
# include <u8c/u8.h>
+static void errhandl(enum u8c_errtyp errtyp);
+static void test( int n);
+static void testmsg( char const * fmt,...);
+static void testmsgdone( void);
+static void errhandl(enum u8c_errtyp errtyp) {
+ printf(":: Error handler called with type %d.\n",(int)errtyp);
+}
+static void test(int n) {
+ switch(n) {
+ case 0x0:
+ testmsg("(0) Error messages");
+ {
+ char32_t const * err = NULL;
+ u8c_geterr(NULL,&err);
+ printf("default error message: ");
+ u8c_println(stdout,err);
+ u8c_seterr(U"Gluchwein!",u8c_errtyp_deferr);
+ u8c_geterr(NULL,&err);
+ printf("set error message: ");
+ u8c_println(stdout,err);
+ u8c_u32free(&err);
+ }
+ testmsgdone();
+ break;
+ case 0x1:
+ testmsg("(1) UTF-8 encoding/decoding");
+ {
+ char32_t const * msg0 = U"¢,ह,𐍈,€,↊,👋";
+ unsigned char const * msg1 = NULL;
+ u8c_u8enc(NULL,&msg1,msg0);
+ msg0 = NULL;
+ printf("Encoded: %s\n",msg1);
+ u8c_u8dec(NULL,&msg0,msg1);
+ u8c_u8enc(NULL,&msg1,msg0);
+ printf("Encoded -> Decoded -> Encoded: %s\n",msg1);
+ u8c_u32free(&msg0);
+ u8c_u8free(&msg1);
+ }
+ testmsgdone();
+ break;
+ case 0x2:
+ testmsg("Printing (u8c_print)");
+ {
+ u8c_print(stdout,U"Hello");
+ u8c_print(stdout,U" ðere!");
+ }
+ testmsgdone();
+ break;
+ case 0x3:
+ testmsg("(3) Printing (u8c_println)");
+ {
+ u8c_println(stdout,U"Hello");
+ u8c_println(stdout,U" ðere!");
+ }
+ testmsgdone();
+ break;
+ case 0x4:
+ testmsg("(4) Text formatting");
+ {
+ u8c_println(stdout,U"The \uFFFCnumber\uFFFC is \uFFFC.",u8c_fmttyp_fgcol,u8c_col_mint,u8c_fmttyp_fgcol0,u8c_fmttyp_int,(int_least64_t){-0x10});
+ }
+ testmsgdone();
+ break;
+ case 0x5:
+ testmsg("(5) Colour text");
+ {
+ u8c_println(stdout,U"\uFFFCred\uFFFCorange\uFFFCyellow\uFFFCchartreuse\uFFFCgreen\uFFFCmint\uFFFCcyan\uFFFCazure\uFFFCblue\uFFFCviolet\uFFFCmagenta\uFFFCrose\uFFFC",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);
+ }
+ testmsgdone();
+ break;
+ case 0x6:
+ testmsg("(6) Combining characters");
+ {
+ for(register uint_least32_t n = UINT32_C(0x300);n <= UINT32_C(0x36F);n += UINT32_C(0x1)) {
+ u8c_print(stdout,(uint_least32_t[]){UINT32_C(0x61),n,UINT32_C(0x20),UINT32_C(0x0),});
+ fflush(stdout);
+ }
+ u8c_print(stdout,U"\n");
+ }
+ testmsgdone();
+ break;
+ case 0x7:
+ testmsg("(7) String comparison");
+ {
+ char32_t const * str0 = U"Hello";
+ char32_t const * str1 = U"Hello";
+ char32_t const * str2 = U"Goodbye";
+ printf("str0: ");
+ u8c_println(stdout,str0);
+ printf("str1: ");
+ u8c_println(stdout,str1);
+ printf("str2: ");
+ u8c_println(stdout,str2);
+ uint_least8_t res = UINT8_C(0x0);
+ u8c_u32cmp(&res,str0,str1);
+ printf("str0,str1: %" PRIXLEAST8 ".\n",res);
+ u8c_u32cmp(&res,str1,str2);
+ printf("str0,str2: %" PRIXLEAST8 ".\n",res);
+ u8c_u32cmp(&res,str2,str1);
+ printf("str2,str1: %" PRIXLEAST8 ".\n",res);
+ }
+ testmsgdone();
+ break;
+ case 0x8:
+ testmsg("(8) u8c_isalnum");
+ {
+ for(register uint_least32_t n = UINT32_C(0x1);n <= UINT32_C(0x10FFFF);n += UINT32_C(0x1)) {
+ uint_least8_t res = UINT8_C(0x0);
+ u8c_isalnum(&res,n);
+ if(res) {
+ u8c_print(stdout,(uint_least32_t[]){n,UINT32_C(0x20),UINT32_C(0x0),});
+ }
+ }
+ u8c_println(stdout,U"");
+ }
+ testmsgdone();
+ break;
+ case 0x9:
+ testmsg("(9) u8c_isalpha");
+ {
+ for(register uint_least32_t n = UINT32_C(0x1);n <= UINT32_C(0x10FFFF);n += UINT32_C(0x1)) {
+ uint_least8_t res = UINT8_C(0x0);
+ u8c_isalpha(&res,n);
+ if(res) {
+ u8c_print(stdout,(uint_least32_t[]){n,UINT32_C(0x20),UINT32_C(0x0),});
+ }
+ }
+ u8c_println(stdout,U"");
+ }
+ testmsgdone();
+ break;
+ case 0xA:
+ testmsg("(10) u8c_isdigit");
+ {
+ for(register uint_least32_t n = UINT32_C(0x1);n <= UINT32_C(0x10FFFF);n += UINT32_C(0x1)) {
+ uint_least8_t res = UINT8_C(0x0);
+ u8c_isdigit(&res,n);
+ if(res) {
+ u8c_print(stdout,(uint_least32_t[]){n,UINT32_C(0x20),UINT32_C(0x0),});
+ }
+ }
+ u8c_println(stdout,U"");
+ }
+ testmsgdone();
+ break;
+ case 0xB:
+ testmsg("(11) u8c_ispunct"); /* This test appears broken on some incomplete fonts, altough it is not. */
+ {
+ for(register uint_least32_t n = UINT32_C(0x1);n <= UINT32_C(0x10FFFF);n += UINT32_C(0x1)) {
+ uint_least8_t res = UINT8_C(0x0);
+ u8c_ispunct(&res,n);
+ if(res) {
+ u8c_print(stdout,(uint_least32_t[]){n,UINT32_C(0x20),UINT32_C(0x0),});
+ }
+ }
+ u8c_println(stdout,U"");
+ }
+ testmsgdone();
+ break;
+ case 0xC:
+ testmsg("(12) UTF-32 string literals");
+ {
+ u8c_println(stdout,U"Can you see ðis?");
+ }
+ testmsgdone();
+ break;
+ case 0xD:
+ testmsg("(13) string concatenation");
+ {
+ char32_t const * str0 = U"Free_as_in";
+ char32_t const * str1 = U"_freedom!";
+ char32_t const * str2 = NULL;
+ u8c_u32cat(NULL,&str2,str0,str1);
+ printf("string #0: ");
+ u8c_println(stdout,str0);
+ printf("string #1: ");
+ u8c_println(stdout,str1);
+ printf("string #2: ");
+ u8c_println(stdout,str2);
+ u8c_u32free(&str2);
+
+ }
+ testmsgdone();
+ break;
+ case 0xE:
+ testmsg("(14) sub-strings");
+ {
+ char32_t const * str0 = U"I_wish_to_suck_big_duck.";
+ char32_t const * str1 = NULL;
+ u8c_u32substr(&str1,SIZE_C(0x0),SIZE_C(0xE),str0);
+ char32_t const * str2 = NULL;
+ u8c_u32substr(&str2,SIZE_C(0xF),SIZE_C(0x0),str0);
+ printf("string #0: ");
+ u8c_println(stdout,str0);
+ printf("string #1: ");
+ u8c_println(stdout,str1);
+ printf("string #2: ");
+ u8c_println(stdout,str2);
+ u8c_u32free(&str1);
+ u8c_u32free(&str2);
+ }
+ testmsgdone();
+ break;
+ case 0xF:
+ testmsg("(15) u8c_isxdigit");
+ {
+ for(register uint_least32_t n = UINT32_C(0x1);n <= UINT32_C(0x10FFFF);n += UINT32_C(0x1)) {
+ uint_least8_t res = UINT8_C(0x0);
+ u8c_isxdigit(&res,n);
+ if(res) {
+ u8c_print(stdout,(uint_least32_t[]){n,UINT32_C(0x20),UINT32_C(0x0),});
+ }
+ }
+ u8c_println(stdout,(uint_least32_t[]){UINT32_C(0x0),});
+ }
+ testmsgdone();
+ break;
+ case 0x10:
+ testmsg("(16) Printing (u8c_dbgprint)");
+ {
+ u8c_dbgprint(U"Hello");
+ u8c_dbgprint(U" ðere!");
+ }
+ testmsgdone();
+ break;
+ case 0x11:
+ testmsg("(17) u8c_u32fndchr");
+ {
+ char32_t const * str = U"Proprietary as in Micro$oft.";
+ size_t pos0 = SIZE_C(0x0);
+ size_t pos1 = SIZE_C(0x0);
+ u8c_u32fndchr(&pos0,str,U'M');
+ u8c_u32fndchr(&pos1,str,U'ŋ');
+ printf("string: ");
+ u8c_println(stdout,str);
+ printf("Position of 'M': %zu\n",pos0);
+ printf("Position of 'ŋ': %zu\n",pos1);
+ }
+ testmsgdone();
+ break;
+ case 0x12:
+ testmsg("(18) u8c_u32fndpat");
+ {
+ char32_t const * str = U"Proprietary as in Micro$oft.";
+ size_t pos0 = SIZE_C(0x0);
+ size_t pos1 = SIZE_C(0x0);
+ u8c_u32fndpat(&pos0,str,U"as in");
+ u8c_u32fndpat(&pos1,str,U"forever");
+ printf("string: ");
+ u8c_println(stdout,str);
+ printf("Position of \"as in\": %zu\n",pos0);
+ printf("Position of \"forever\": %zu\n",pos1);
+ }
+ testmsgdone();
+ break;
+ case 0x13:
+ testmsg("(19) string insertion");
+ {
+ char32_t const * str0 = U"There_is_I_love.";
+ char32_t const * str1 = U"just_somebody_that_";
+ char32_t const * str2 = NULL;
+ u8c_u32ins(NULL,&str2,SIZE_C(0x9),str0,str1);
+ printf("String #0: ");
+ u8c_println(stdout,str0);
+ printf("String #1: ");
+ u8c_println(stdout,str1);
+ printf("String #2: ");
+ u8c_println(stdout,str2);
+ u8c_u32free(&str2);
+ }
+ testmsgdone();
+ break;
+ }
+}
static void testmsg(char const * fmt,...) {
va_list args;
va_start(args,fmt);
@@ -24,10 +297,7 @@ static void testmsgdone() {
/* printf("\n+->\n| \x1b[38:2::61:225:169mDone\x1b[0m!\n+->\n"); */
printf("\n+->\n| \x1b[38;2;61;225;169mDone\x1b[0m!\n+->\n");
}
-static void errhandl(enum u8c_errtyp errtyp) {
- printf(":: Error handler called with type %d.\n",(int)errtyp);
-}
-int main(void) {
+int main(int const argc,char const * * argv) {
if(u8c_init()) {
printf("Unable to initialise u8c!\n");
exit(EXIT_FAILURE);
@@ -37,229 +307,14 @@ int main(void) {
printf("u8c version: %" PRIXLEAST64 ".\n",u8c_ver);
printf("Debug build: %" PRIXLEAST8 ".\n",u8c_dbg);
printf("Thread safe: %" PRIXLEAST8 ".\n",u8c_thrdsafe);
- testmsg("Error messages");
- {
- char32_t const * err = NULL;
- u8c_geterr(NULL,&err);
- printf("default error message: ");
- u8c_println(stdout,err);
- u8c_seterr(U"Gluchwein!",u8c_errtyp_deferr);
- u8c_geterr(NULL,&err);
- printf("set error message: ");
- u8c_println(stdout,err);
- u8c_u32free(&err);
- }
- testmsgdone();
- testmsg("UTF-8 encoding/decoding");
- {
- char32_t const * msg0 = U"¢,ह,𐍈,€,↊,👋";
- unsigned char const * msg1 = NULL;
- u8c_u8enc(NULL,&msg1,msg0);
- msg0 = NULL;
- printf("Encoded: %s\n",msg1);
- u8c_u8dec(NULL,&msg0,msg1);
- u8c_u8enc(NULL,&msg1,msg0);
- printf("Encoded -> Decoded -> Encoded: %s\n",msg1);
- u8c_u32free(&msg0);
- u8c_u8free(&msg1);
- }
- testmsgdone();
- testmsg("Printing (u8c_print)");
- {
- u8c_print(stdout,U"Hello");
- u8c_print(stdout,U" ðere!");
- }
- testmsgdone();
- testmsg("Printing (u8c_println)");
- {
- u8c_println(stdout,U"Hello");
- u8c_println(stdout,U" ðere!");
- }
- testmsgdone();
- testmsg("Text formatting");
- {
- u8c_println(stdout,U"The \uFFFCnumber\uFFFC is \uFFFC.",u8c_fmttyp_fgcol,u8c_col_mint,u8c_fmttyp_fgcol0,u8c_fmttyp_int,(int_least64_t){-0x10});
- }
- testmsgdone();
- testmsg("Colour text");
- {
- u8c_println(stdout,U"\uFFFCred\uFFFCorange\uFFFCyellow\uFFFCchartreuse\uFFFCgreen\uFFFCmint\uFFFCcyan\uFFFCazure\uFFFCblue\uFFFCviolet\uFFFCmagenta\uFFFCrose\uFFFC",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);
- }
- testmsgdone();
- testmsg("Combining characters");
- {
- for(register uint_least32_t n = UINT32_C(0x300);n <= UINT32_C(0x36F);n += UINT32_C(0x1)) {
- u8c_print(stdout,(uint_least32_t[]){UINT32_C(0x61),n,UINT32_C(0x20),UINT32_C(0x0),});
- fflush(stdout);
- }
- u8c_print(stdout,U"\n");
- }
- testmsgdone();
- testmsg("String comparison");
- {
- char32_t const * str0 = U"Hello";
- char32_t const * str1 = U"Hello";
- char32_t const * str2 = U"Goodbye";
- printf("str0: ");
- u8c_println(stdout,str0);
- printf("str1: ");
- u8c_println(stdout,str1);
- printf("str2: ");
- u8c_println(stdout,str2);
- uint_least8_t res = UINT8_C(0x0);
- u8c_u32cmp(&res,str0,str1);
- printf("str0,str1: %" PRIXLEAST8 ".\n",res);
- u8c_u32cmp(&res,str1,str2);
- printf("str0,str2: %" PRIXLEAST8 ".\n",res);
- u8c_u32cmp(&res,str2,str1);
- printf("str2,str1: %" PRIXLEAST8 ".\n",res);
+ if(argc == 0x2) {
+ test(atoi(argv[SIZE_C(0x1)]));
}
- testmsgdone();
- testmsg("u8c_isalnum");
- {
- for(register uint_least32_t n = UINT32_C(0x1);n <= UINT32_C(0x10FFFF);n += UINT32_C(0x1)) {
- uint_least8_t res = UINT8_C(0x0);
- u8c_isalnum(&res,n);
- if(res) {
- u8c_print(stdout,(uint_least32_t[]){n,UINT32_C(0x20),UINT32_C(0x0),});
- }
+ else {
+ for(int n = 0x0;n <= 0x13;n += 0x1) {
+ test(n);
}
- u8c_println(stdout,U"");
- }
- testmsgdone();
- testmsg("u8c_isalpha");
- {
- for(register uint_least32_t n = UINT32_C(0x1);n <= UINT32_C(0x10FFFF);n += UINT32_C(0x1)) {
- uint_least8_t res = UINT8_C(0x0);
- u8c_isalpha(&res,n);
- if(res) {
- u8c_print(stdout,(uint_least32_t[]){n,UINT32_C(0x20),UINT32_C(0x0),});
- }
- }
- u8c_println(stdout,U"");
- }
- testmsgdone();
- testmsg("u8c_isdigit");
- {
- for(register uint_least32_t n = UINT32_C(0x1);n <= UINT32_C(0x10FFFF);n += UINT32_C(0x1)) {
- uint_least8_t res = UINT8_C(0x0);
- u8c_isdigit(&res,n);
- if(res) {
- u8c_print(stdout,(uint_least32_t[]){n,UINT32_C(0x20),UINT32_C(0x0),});
- }
- }
- u8c_println(stdout,U"");
- }
- testmsgdone();
- testmsg("u8c_ispunct"); /* This test appears broken on some incomplete fonts, altough it is not. */
- {
- for(register uint_least32_t n = UINT32_C(0x1);n <= UINT32_C(0x10FFFF);n += UINT32_C(0x1)) {
- uint_least8_t res = UINT8_C(0x0);
- u8c_ispunct(&res,n);
- if(res) {
- u8c_print(stdout,(uint_least32_t[]){n,UINT32_C(0x20),UINT32_C(0x0),});
- }
- }
- u8c_println(stdout,U"");
- }
- testmsgdone();
- testmsg("UTF-32 string literals");
- {
- u8c_println(stdout,U"Can you see ðis?");
- }
- testmsgdone();
- testmsg("string concatenation");
- {
- char32_t const * str0 = U"Free_as_in";
- char32_t const * str1 = U"_freedom!";
- char32_t const * str2 = NULL;
- u8c_u32cat(NULL,&str2,str0,str1);
- printf("string #0: ");
- u8c_println(stdout,str0);
- printf("string #1: ");
- u8c_println(stdout,str1);
- printf("string #2: ");
- u8c_println(stdout,str2);
- u8c_u32free(&str2);
-
- }
- testmsgdone();
- testmsg("sub-strings");
- {
- char32_t const * str0 = U"I_wish_to_suck_big_duck.";
- char32_t const * str1 = NULL;
- u8c_u32substr(&str1,SIZE_C(0x0),SIZE_C(0xE),str0);
- char32_t const * str2 = NULL;
- u8c_u32substr(&str2,SIZE_C(0xF),SIZE_C(0x0),str0);
- printf("string #0: ");
- u8c_println(stdout,str0);
- printf("string #1: ");
- u8c_println(stdout,str1);
- printf("string #2: ");
- u8c_println(stdout,str2);
- u8c_u32free(&str1);
- u8c_u32free(&str2);
- }
- testmsgdone();
- testmsg("u8c_isxdigit");
- {
- for(register uint_least32_t n = UINT32_C(0x1);n <= UINT32_C(0x10FFFF);n += UINT32_C(0x1)) {
- uint_least8_t res = UINT8_C(0x0);
- u8c_isxdigit(&res,n);
- if(res) {
- u8c_print(stdout,(uint_least32_t[]){n,UINT32_C(0x20),UINT32_C(0x0),});
- }
- }
- u8c_println(stdout,(uint_least32_t[]){UINT32_C(0x0),});
- }
- testmsgdone();
- testmsg("Printing (u8c_dbgprint)");
- {
- u8c_dbgprint(U"Hello");
- u8c_dbgprint(U" ðere!");
- }
- testmsgdone();
- testmsg("u8c_u32fndchr");
- {
- char32_t const * str = U"Proprietary as in Micro$oft.";
- size_t pos0 = SIZE_C(0x0);
- size_t pos1 = SIZE_C(0x0);
- u8c_u32fndchr(&pos0,str,U'M');
- u8c_u32fndchr(&pos1,str,U'ŋ');
- printf("string: ");
- u8c_println(stdout,str);
- printf("Position of 'M': %zu\n",pos0);
- printf("Position of 'ŋ': %zu\n",pos1);
- }
- testmsgdone();
- testmsg("u8c_u32fndpat");
- {
- char32_t const * str = U"Proprietary as in Micro$oft.";
- size_t pos0 = SIZE_C(0x0);
- size_t pos1 = SIZE_C(0x0);
- u8c_u32fndpat(&pos0,str,U"as in");
- u8c_u32fndpat(&pos1,str,U"forever");
- printf("string: ");
- u8c_println(stdout,str);
- printf("Position of \"as in\": %zu\n",pos0);
- printf("Position of \"forever\": %zu\n",pos1);
- }
- testmsgdone();
- testmsg("string insertion");
- {
- char32_t const * str0 = U"There_is_I_love.";
- char32_t const * str1 = U"just_somebody_that_";
- char32_t const * str2 = NULL;
- u8c_u32ins(NULL,&str2,SIZE_C(0x9),str0,str1);
- printf("String #0: ");
- u8c_println(stdout,str0);
- printf("String #1: ");
- u8c_println(stdout,str1);
- printf("String #2: ");
- u8c_println(stdout,str2);
- u8c_u32free(&str2);
}
- testmsgdone();
u8c_end();
exit(EXIT_SUCCESS);
}