changeset 451:db45d6d2e576

Expose some of the internal vprintf() implementation helper functions.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 25 Oct 2017 22:20:21 +0300
parents 051226a06f70
children 4471eadea472
files th_printf1.c th_string.c th_string.h
diffstat 3 files changed, 42 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/th_printf1.c	Wed Oct 25 22:13:09 2017 +0300
+++ b/th_printf1.c	Wed Oct 25 22:20:21 2017 +0300
@@ -6,9 +6,13 @@
  * Please read file 'COPYING' for information on license and distribution.
  */
 
-static int TH_PFUNC_NAME (char *buf, const int len, int *pos,
+
+int TH_PFUNC_NAME (char *buf, const int len, int *pos,
     TH_PFUNC_TYPE_S pval, const int f_radix, const BOOL f_upcase,
     const BOOL f_unsig, BOOL *f_neg)
+#ifdef TH_PFUNC_HEADER
+;
+#else
 {
     if (f_radix > 16)
         return EOF;
@@ -45,9 +49,11 @@
 
     return (val > 0) ? EOF : 1;
 }
+#endif
 
 
 #undef TH_PFUNC_NAME
 #undef TH_PFUNC_SIGNED
 #undef TH_PFUNC_TYPE_S
 #undef TH_PFUNC_TYPE_U
+#undef TH_PFUNC_HEADER
--- a/th_string.c	Wed Oct 25 22:13:09 2017 +0300
+++ b/th_string.c	Wed Oct 25 22:20:21 2017 +0300
@@ -198,7 +198,7 @@
 #endif
 
 
-static int th_vprintf_put_int_format(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
+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))
 {
@@ -295,7 +295,7 @@
 }
 
 
-static int th_vprintf_put_int(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
+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))
 {
@@ -321,7 +321,7 @@
 }
 
 
-static int th_vprintf_put_str(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
+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 nwidth, f_len, ret = 0;
@@ -352,7 +352,7 @@
 
 
 #ifdef WIP_FLOAT_SUPPORT
-static int th_vprintf_put_float(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
+int th_vprintf_put_float(th_vprintf_ctx *ctx, th_vprintf_putch vputch,
     va_list ap, int f_flags, int f_width, int f_prec)
 {
     double pval = va_arg(ap, double);   // This needs to be double for type promotion to occur
@@ -373,7 +373,7 @@
 #endif
 
 
-static char * th_vprintf_altfmt_oct(const char *buf, const size_t len, const int vret, const int flags)
+char * th_vprintf_altfmt_oct(const char *buf, const size_t len, const int vret, const int flags)
 {
     (void) vret;
     (void) flags;
@@ -382,7 +382,7 @@
 }
 
 
-static char * th_vprintf_altfmt_hex(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)
 {
     (void) buf;
     (void) vret;
--- a/th_string.h	Wed Oct 25 22:13:09 2017 +0300
+++ b/th_string.h	Wed Oct 25 22:20:21 2017 +0300
@@ -100,7 +100,6 @@
 char    *th_strrcasecmp(char *haystack, const char *needle);
 void    th_strip_ctrlchars(char *str);
 
-int     th_vprintf_do(th_vprintf_ctx *ctx, th_vprintf_putch vputch, const char *fmt, va_list ap);
 int     th_vsnprintf(char *buf, size_t size, const char *fmt, va_list ap);
 int     th_snprintf(char *buf, size_t size, const char *fmt, ...);
 int     th_vfprintf(FILE *fh, const char *fmt, va_list ap);
@@ -117,6 +116,35 @@
 int     th_pstr_cat(char **pdst, const char *src);
 
 
+/* Internal printf() implementation. NOTICE! This API may be unstable.
+ */
+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,
+        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));
+
+char *  th_printf_altfmt_oct(const char *buf, const size_t len, const int vret, const int flags);
+char *  th_printf_altfmt_hex(const char *buf, const size_t len, const int vret, const int flags);
+
+#define TH_PFUNC_NAME th_vprintf_buf_int
+#define TH_PFUNC_TYPE_S int
+#define TH_PFUNC_TYPE_U unsigned int
+#define TH_PFUNC_HEADER 1
+#include "th_printf1.c"
+
+
+#define TH_PFUNC_NAME th_vprintf_buf_int64
+#define TH_PFUNC_TYPE_S int64_t
+#define TH_PFUNC_TYPE_U uint64_t
+#define TH_PFUNC_HEADER 1
+#include "th_printf1.c"
+
+
 /* Parsing, matching
  */
 const char    *th_findnext(const char *, size_t *);