summaryrefslogtreecommitdiff
path: root/src/u8c/fmt.h.d
diff options
context:
space:
mode:
Diffstat (limited to 'src/u8c/fmt.h.d')
-rw-r--r--src/u8c/fmt.h.d/fmt.c12
-rw-r--r--src/u8c/fmt.h.d/print.c8
-rw-r--r--src/u8c/fmt.h.d/println.c22
-rw-r--r--src/u8c/fmt.h.d/setfmt.c14
-rw-r--r--src/u8c/fmt.h.d/vfmt.c13
-rw-r--r--src/u8c/fmt.h.d/vprint.c30
6 files changed, 55 insertions, 44 deletions
diff --git a/src/u8c/fmt.h.d/fmt.c b/src/u8c/fmt.h.d/fmt.c
index 43f1ea4..59feb74 100644
--- a/src/u8c/fmt.h.d/fmt.c
+++ b/src/u8c/fmt.h.d/fmt.c
@@ -18,11 +18,15 @@
# include <stddef.h>
# include <stdint.h>
# include <u8c/fmt.h>
-# include <u8c/u32.h>
-bool u8c_fmt(size_t * const _outsz,char32_t const * * const _out,char32_t const * const _in,...) {
+# include <u8c/str.h>
+struct u8c_fmt_tuple u8c_fmt(char32_t const * const restrict _in,...) {
+ struct u8c_fmt_tuple ret;
va_list args;
va_start(args,_in);
- uint_least8_t val = u8c_vfmt(_outsz,_out,_in,args);
+ struct u8c_vfmt_tuple tuple = u8c_vfmt(_in,args);
va_end(args);
- return val;
+ ret.stat = tuple.stat;
+ ret.str = tuple.str;
+ ret.strsz = tuple.strsz;
+ return ret;
}
diff --git a/src/u8c/fmt.h.d/print.c b/src/u8c/fmt.h.d/print.c
index 8785ad8..e2f4802 100644
--- a/src/u8c/fmt.h.d/print.c
+++ b/src/u8c/fmt.h.d/print.c
@@ -17,10 +17,12 @@
# include <stdbool.h>
# include <stdint.h>
# include <u8c/fmt.h>
-bool u8c_print(FILE * _fp,char32_t const * const _msg,...) {
+struct u8c_print_tuple u8c_print(FILE * restrict _fp,char32_t const * const restrict _msg,...) {
+ struct u8c_print_tuple ret;
va_list args;
va_start(args,_msg);
- uint_least8_t val = u8c_vprint(_fp,_msg,args);
+ struct u8c_vprint_tuple tuple = u8c_vprint(_fp,_msg,args);
va_end(args);
- return val;
+ ret.stat = tuple.stat;
+ return ret;
}
diff --git a/src/u8c/fmt.h.d/println.c b/src/u8c/fmt.h.d/println.c
index 1a924ad..d73a897 100644
--- a/src/u8c/fmt.h.d/println.c
+++ b/src/u8c/fmt.h.d/println.c
@@ -13,27 +13,21 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include <assert.h>
# include <stdarg.h>
# include <stdbool.h>
# include <stdint.h>
# include <stdio.h>
# include <u8c/fmt.h>
-# include <u8c/u32.h>
+# include <u8c/str.h>
# include <uchar.h>
-bool u8c_println(FILE * _fp,char32_t const * const _msg,...) {
- assert(_fp != NULL);
+struct u8c_println_tuple u8c_println(FILE * restrict _fp,char32_t const * const restrict _msg,...) {
+ struct u8c_println_tuple ret;
va_list args;
va_start(args,_msg);
- char32_t const * msg = NULL;
- u8c_u32cat(NULL,&msg,_msg,U"\n");
- {
- register bool const val = u8c_vprint(_fp,msg,args);
- u8c_u32free(&msg);
- if(val) {
- return true;
- }
- }
+ char32_t const * msg = u8c_strcat(_msg,U"\n").str;
+ register struct u8c_vprint_tuple const tuple = u8c_vprint(_fp,msg,args);
+ u8c_strfree(msg);
va_end(args);
- return false;
+ ret.stat = tuple.stat;
+ return ret;
}
diff --git a/src/u8c/fmt.h.d/setfmt.c b/src/u8c/fmt.h.d/setfmt.c
index 7956ea3..4c6d3a3 100644
--- a/src/u8c/fmt.h.d/setfmt.c
+++ b/src/u8c/fmt.h.d/setfmt.c
@@ -20,15 +20,15 @@
# if defined(u8c_bethrdsafe)
# include <threads.h>
# endif
-bool u8c_setfmt(unsigned char const _base,unsigned char const _endian) {
- uint_least8_t base = _base;
- uint_least8_t endian = _endian;
+struct u8c_setfmt_tuple u8c_setfmt(uint_least8_t const _base,bool const _endian) {
+ struct u8c_setfmt_tuple ret = {
+ .stat = false,
+ };
+ register uint_least8_t base = _base;
+ register bool endian = _endian;
if(_base > UINT8_C(0x20)) {
base = UINT8_C(0xC);
}
- if(_endian > UINT8_C(0x1)) {
- endian = UINT8_C(0x0);
- }
# if defined(u8c_bethrdsafe)
mtx_lock(&u8c_dat.fmtlock);
# endif
@@ -37,5 +37,5 @@ bool u8c_setfmt(unsigned char const _base,unsigned char const _endian) {
# if defined(u8c_bethrdsafe)
mtx_unlock(&u8c_dat.fmtlock);
# endif
- return false;
+ return ret;
}
diff --git a/src/u8c/fmt.h.d/vfmt.c b/src/u8c/fmt.h.d/vfmt.c
index 5b0c1e1..5148784 100644
--- a/src/u8c/fmt.h.d/vfmt.c
+++ b/src/u8c/fmt.h.d/vfmt.c
@@ -16,11 +16,18 @@
# include <stdarg.h>
# include <stdbool.h>
# include <u8c/fmt.h>
-# include <u8c/u32.h>
+# include <u8c/str.h>
# include <uchar.h>
# 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,[[maybe_unused]] va_list _args) {
- return u8c_u32cp(_sz,_out,_in);
+struct u8c_vfmt_tuple u8c_vfmt(char32_t const * const restrict _in,[[maybe_unused]] va_list _args) {
+ struct u8c_vfmt_tuple ret = {
+ .stat = false,
+ };
+ struct u8c_strcp_tuple const tuple = u8c_strcp(_in);
+ ret.stat = tuple.stat;
+ ret.str = tuple.str;
+ ret.strsz = tuple.strsz;
+ return ret;
}
diff --git a/src/u8c/fmt.h.d/vprint.c b/src/u8c/fmt.h.d/vprint.c
index 8d824a8..cfcb850 100644
--- a/src/u8c/fmt.h.d/vprint.c
+++ b/src/u8c/fmt.h.d/vprint.c
@@ -13,7 +13,6 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-# include <assert.h>
# include <stdarg.h>
# include <stdbool.h>
# include <stdint.h>
@@ -23,20 +22,24 @@
# include <u8c/err.h>
# include <u8c/fmt.h>
# include <u8c/intern.h>
-# include <u8c/u32.h>
+# include <u8c/str.h>
# include <u8c/u8.h>
# include <uchar.h>
# if defined(u8c_bethrdsafe)
# include <threads.h>
# endif
-bool u8c_vprint(FILE * _fp,char32_t const * const _msg,va_list _args) {
- assert(_msg != NULL);
- char32_t const * str0 = NULL;
- u8c_vfmt(NULL,&str0,_msg,_args);
+struct u8c_vprint_tuple u8c_vprint(FILE * restrict _fp,char32_t const * const restrict _msg,va_list _args) {
+ struct u8c_vprint_tuple ret = {
+ .stat = false,
+ };
+ char32_t const * str0 = u8c_vfmt(_msg,_args).str;
size_t str1sz = SIZE_C(0x0);
unsigned char const * str1 = NULL;
- u8c_u8enc(&str1sz,&str1,str0);
- assert(str1sz > SIZE_C(0x0));
+ {
+ struct u8c_u8enc_tuple const tuple = u8c_u8enc(str0);
+ str1 = tuple.u8;
+ str1sz = tuple.u8sz;
+ }
# if defined(u8c_bethrdsafe)
mtx_lock(&u8c_dat.outlock);
# endif
@@ -46,11 +49,12 @@ bool u8c_vprint(FILE * _fp,char32_t const * const _msg,va_list _args) {
mtx_unlock(&u8c_dat.outlock);
# endif
if(val < str1sz - SIZE_C(0x1)) {
- u8c_seterr(U"u8c_vprint: fwrite: Unable to write to stdout.",u8c_errtyp_badio);
- return true;
+ u8c_seterr(u8c_errtyp_badio,U"u8c_vprint: Unable to write to stdout.");
+ ret.stat = true;
+ return ret;
}
}
- u8c_u32free(&str0);
- u8c_u8free(&str1);
- return false;
+ u8c_strfree(str0);
+ u8c_u8free(str1);
+ return ret;
}