# HG changeset patch # User Matti Hamalainen # Date 1577762351 -7200 # Node ID edfe8ac12408e439c0399370dfa4a1f7bfeece14 # Parent 4d2e9c806b98ecab85d5abb05a89920d2f673879 Add function typedef th_vprintf_altfmt_func and #define TH_VPRINTF_ALTFMT_FUNC macro for defining printf altfmt helpers and use them. This breaks the API. diff -r 4d2e9c806b98 -r edfe8ac12408 th_printf.c --- a/th_printf.c Tue Dec 31 05:16:58 2019 +0200 +++ b/th_printf.c Tue Dec 31 05:19:11 2019 +0200 @@ -114,7 +114,7 @@ #include "th_printf1.c" -char * th_vprintf_altfmt_oct(const char *buf, const size_t len, const int vret, const int flags) +TH_VPRINTF_ALTFMT_FUNC(th_vprintf_altfmt_oct) { (void) vret; (void) flags; @@ -123,7 +123,7 @@ } -char * th_vprintf_altfmt_hex(const char *buf, const size_t len, const int vret, const int flags) +TH_VPRINTF_ALTFMT_FUNC(th_vprintf_altfmt_hex) { (void) buf; (void) len; @@ -137,7 +137,7 @@ int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch, char *buf, int f_flags, int f_width, int f_prec, int f_len, int vret, - BOOL f_neg, BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) + BOOL f_neg, BOOL f_unsig, th_vprintf_altfmt_func f_alt) { int ret = 0, nspacepad, nzeropad; char f_sign, *f_altstr; @@ -237,7 +237,7 @@ int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, - const BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)) + const BOOL f_unsig, th_vprintf_altfmt_func f_alt) { char buf[32]; int f_len = 0, vret; diff -r 4d2e9c806b98 -r edfe8ac12408 th_string.h --- a/th_string.h Tue Dec 31 05:16:58 2019 +0200 +++ b/th_string.h Tue Dec 31 05:19:11 2019 +0200 @@ -121,18 +121,28 @@ /* Internal printf() implementation. NOTICE! This API may be unstable. */ +#define TH_VPRINTF_ALTFMT_FUNC(fname) char * fname ( \ + const char *buf, const size_t len, const int vret, const int flags) + +typedef char * (*th_vprintf_altfmt_func)( + const char *buf, const size_t len, const int vret, const int flags); + + int th_vprintf_do(th_vprintf_ctx *ctx, th_vprintf_putch vputch, const char *fmt, va_list ap); int th_vprintf_put_str(th_vprintf_ctx *ctx, th_vprintf_putch vputch, const char *str, int f_flags, const int f_width, const int f_prec); + int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch, va_list ap, const int f_radix, int f_flags, int f_width, int f_prec, - const BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)); -int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch, + const BOOL f_unsig, th_vprintf_altfmt_func f_alt); + +int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch, char *buf, int f_flags, int f_width, int f_prec, int f_len, int vret, - BOOL f_neg, BOOL f_unsig, char *(f_alt)(const char *buf, const size_t blen, const int vret, const int flags)); + BOOL f_neg, BOOL f_unsig, th_vprintf_altfmt_func f_alt); + -char * th_vprintf_altfmt_oct(const char *buf, const size_t len, const int vret, const int flags); -char * th_vprintf_altfmt_hex(const char *buf, const size_t len, const int vret, const int flags); +TH_VPRINTF_ALTFMT_FUNC(th_vprintf_altfmt_oct); +TH_VPRINTF_ALTFMT_FUNC(th_vprintf_altfmt_hex); #define TH_PFUNC_NAME th_vprintf_buf_int