38 typedef void (*
putcf)(
void *, char);
42 #ifdef PRINTF_LONG_SUPPORT 44 static void uli2a(
unsigned long int num,
unsigned int base,
int uc,
char *bf)
48 while (num / d >= base) d *= base;
54 if (n || dgt > 0 || d == 0)
56 *bf++ = dgt + (dgt < 10 ?
'0' : (uc ?
'A' :
'a') - 10);
63 static void li2a(
long num,
char *bf)
70 uli2a(num, 10, 0, bf);
75 static void ui2a(
unsigned int num,
unsigned int base,
int uc,
char *bf)
79 #pragma GCC diagnostic push 80 #pragma GCC diagnostic ignored "-Wstrict-overflow" 81 while (num / d >= base)
82 #pragma GCC diagnostic pop 89 if (n || dgt > 0 || d == 0)
91 *bf++ = dgt + (dgt < 10 ?
'0' : (uc ?
'A' :
'a') - 10);
98 static void i2a(
int num,
char *bf)
105 ui2a(num, 10, 0, bf);
110 if (ch >=
'0' && ch <=
'9')
112 else if (ch >=
'a' && ch <=
'f')
113 return ch -
'a' + 10;
114 else if (ch >=
'A' && ch <=
'F')
115 return ch -
'A' + 10;
120 static char a2i(
char ch,
char **src,
int base,
int *nump)
125 while ((digit =
a2d(ch)) >= 0)
129 num = num * base + digit;
137 static void putchw(
void *putp,
putcf putf,
int n,
char z,
char *bf)
139 char fc = z ?
'0' :
' ';
142 while (*p++ && n != 0) n--;
143 while (n-- != 0) putf(putp, fc);
144 while ((ch = *bf++)) putf(putp, ch);
153 while ((ch = *(fmt++)))
160 #ifdef PRINTF_LONG_SUPPORT 170 if (ch >=
'0' && ch <=
'9')
172 ch =
a2i(ch, const_cast<char **>(&fmt), 10, &w);
174 #ifdef PRINTF_LONG_SUPPORT 187 #ifdef PRINTF_LONG_SUPPORT 189 uli2a(va_arg(va,
unsigned long int), 10, 0, bf);
192 ui2a(va_arg(va,
unsigned int), 10, 0, bf);
193 putchw(putp, putf, w, lz, bf);
198 #ifdef PRINTF_LONG_SUPPORT 200 li2a(va_arg(va,
unsigned long int), bf);
203 i2a(va_arg(va,
int), bf);
204 putchw(putp, putf, w, lz, bf);
209 #ifdef PRINTF_LONG_SUPPORT 211 uli2a(va_arg(va,
unsigned long int), 16, (ch ==
'X'), bf);
214 ui2a(va_arg(va,
unsigned int), 16, (ch ==
'X'), bf);
215 putchw(putp, putf, w, lz, bf);
218 putf(putp, static_cast<char>(va_arg(va,
int)));
221 putchw(putp, putf, w, 0, va_arg(va,
char *));
243 tfp_format(stdout_putp, stdout_putf, fmt, va);
249 *(*(
static_cast<char **
>(p)))++ = c;
void(* putcf)(void *, char)
static void uli2a(unsigned long int num, unsigned int base, int uc, char *bf)
static void li2a(long num, char *bf)
static void ui2a(unsigned int num, unsigned int base, int uc, char *bf)
void init_printf(void *putp, void(*putf)(void *, char))
static void i2a(int num, char *bf)
void tfp_format(void *putp, void(*putf)(void *, char), const char *fmt, va_list va)
static void putcp(void *p, char c)
static void * stdout_putp
static char a2i(char ch, char **src, int base, int *nump)
void tfp_sprintf(char *s, const char *fmt, va_list va)
void tfp_printf(const char *fmt,...)
static void putchw(void *putp, putcf putf, int n, char z, char *bf)