34 #define PRINTF_FLOAT_DECIMALS 3 38 typedef void (*
putcf) (
void*,char);
42 static double abs(
double a)
50 static void uli2a(
unsigned long int num,
unsigned int base,
int uc,
char * bf)
60 if (n || dgt>0|| d==0) {
61 *bf++ = dgt+(dgt<10 ?
'0' : (uc ?
'A' :
'a')-10);
68 static void li2a (
long num,
char * bf)
78 static void ui2a(
unsigned int num,
unsigned int base,
int uc,
char * bf)
88 if (n || dgt>0 || d==0) {
89 *bf++ = dgt+(dgt<10 ?
'0' : (uc ?
'A' :
'a')-10);
96 static void i2a (
int num,
char * bf)
107 if (ch>=
'0' && ch<=
'9')
109 else if (ch>=
'a' && ch<=
'f')
111 else if (ch>=
'A' && ch<=
'F')
116 static char a2i(
char ch,
char** src,
int base,
int* nump)
121 while ((digit=
a2d(ch))>=0) {
122 if (digit>base)
break;
131 static void f2a(
float num,
int whitespace,
int decimals,
char * bf)
134 for (
int i = 0;
i < decimals;
i++)
139 int dec = (int)(num * mult) % mult;
174 char fc=z?
'0' :
' ';
177 while (*p++ && n > 0)
192 while ((ch=*(fmt++))) {
205 if (ch>=
'0' && ch<=
'9') {
206 ch=
a2i(ch, (
char **)&fmt, 10, &w);
214 ch=
a2i(ch, (
char **)&fmt, 10, &f);
220 f2a(va_arg(va,
double), w, f, bf);
221 putchw(putp,putf,w,lz,bf);
226 uli2a(va_arg(va,
unsigned long int),10,0,bf);
228 ui2a(va_arg(va,
unsigned int),10,0,bf);
229 putchw(putp,putf,w,lz,bf);
234 li2a(va_arg(va,
unsigned long int),bf);
236 i2a(va_arg(va,
int),bf);
237 putchw(putp,putf,w,lz,bf);
242 uli2a(va_arg(va,
unsigned long int),16,(ch==
'X'),bf);
244 ui2a(va_arg(va,
unsigned int),16,(ch==
'X'),bf);
245 putchw(putp,putf,w,lz,bf);
248 putf(putp,(
char)(va_arg(va,
int)));
251 putchw(putp,putf,w,0,va_arg(va,
char*));
280 *(*((
char**)p))++ = c;
static void uli2a(unsigned long int num, unsigned int base, int uc, char *bf)
static void putchw(void *putp, putcf putf, int n, char z, char *bf)
static void li2a(long num, char *bf)
static double abs(double a)
static void i2a(int num, char *bf)
static char a2i(char ch, char **src, int base, int *nump)
void(* putcf)(void *, char)
static void putcp(void *p, char c)
static void * stdout_putp
void tfp_format(void *putp, putcf putf, const char *fmt, va_list va)
static void f2a(float num, int whitespace, int decimals, char *bf)
static void ui2a(unsigned int num, unsigned int base, int uc, char *bf)
#define PRINTF_FLOAT_DECIMALS
void tfp_printf(const char *fmt,...)
void init_printf(void *putp, void(*putf)(void *, char))
void tfp_sprintf(char *s, const char *fmt,...)