Mercurial > hg > th-libs
changeset 546:edfe8ac12408
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.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 31 Dec 2019 05:19:11 +0200 |
parents | 4d2e9c806b98 |
children | c21051972015 |
files | th_printf.c th_string.h |
diffstat | 2 files changed, 19 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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