34 #define PRINTF_FLOAT_DECIMALS 3 36 typedef void (*
putcf) (
void*,char);
40 static double abs(
double a)
48 static void uli2a(
unsigned long int num,
unsigned int base,
int uc,
char * bf)
58 if (n || dgt>0|| d==0) {
59 *bf++ = dgt+(dgt<10 ?
'0' : (uc ?
'A' :
'a')-10);
66 static void li2a (
long num,
char * bf)
76 static void ui2a(
unsigned int num,
unsigned int base,
int uc,
char * bf)
86 if (n || dgt>0 || d==0) {
87 *bf++ = dgt+(dgt<10 ?
'0' : (uc ?
'A' :
'a')-10);
94 static void i2a (
int num,
char * bf)
105 if (ch>=
'0' && ch<=
'9')
107 else if (ch>=
'a' && ch<=
'f')
109 else if (ch>=
'A' && ch<=
'F')
114 static char a2i(
char ch,
char** src,
int base,
int* nump)
119 while ((digit=
a2d(ch))>=0) {
120 if (digit>base)
break;
129 static void f2a(
float num,
int whitespace,
int decimals,
char * bf)
132 for (
int i = 0;
i < decimals;
i++)
137 int dec = (int)(num * mult) % mult;
172 char fc=z?
'0' :
' ';
175 while (*p++ && n > 0)
190 while ((ch=*(fmt++))) {
203 if (ch>=
'0' && ch<=
'9') {
204 ch=
a2i(ch, (
char **)&fmt, 10, &w);
212 ch=
a2i(ch, (
char **)&fmt, 10, &f);
218 f2a(va_arg(va,
double), w, f, bf);
219 putchw(putp,putf,w,lz,bf);
224 uli2a(va_arg(va,
unsigned long int),10,0,bf);
226 ui2a(va_arg(va,
unsigned int),10,0,bf);
227 putchw(putp,putf,w,lz,bf);
232 li2a(va_arg(va,
unsigned long int),bf);
234 i2a(va_arg(va,
int),bf);
235 putchw(putp,putf,w,lz,bf);
240 uli2a(va_arg(va,
unsigned long int),16,(ch==
'X'),bf);
242 ui2a(va_arg(va,
unsigned int),16,(ch==
'X'),bf);
243 putchw(putp,putf,w,lz,bf);
246 putf(putp,(
char)(va_arg(va,
int)));
249 putchw(putp,putf,w,0,va_arg(va,
char*));
278 *(*((
char**)p))++ = c;
void tfp_sprintf(char *s, const char *fmt,...)
static void i2a(int num, char *bf)
static void putchw(void *putp, putcf putf, int n, char z, char *bf)
void(* putcf)(void *, char)
static void * stdout_putp
static char a2i(char ch, char **src, int base, int *nump)
void tfp_printf(const char *fmt,...)
static void f2a(float num, int whitespace, int decimals, char *bf)
static void li2a(long num, char *bf)
void tfp_format(void *putp, putcf putf, const char *fmt, va_list va)
static void putcp(void *p, char c)
void init_printf(void *putp, void(*putf)(void *, char))
static void ui2a(unsigned int num, unsigned int base, int uc, char *bf)
static void uli2a(unsigned long int num, unsigned int base, int uc, char *bf)
#define PRINTF_FLOAT_DECIMALS
static double abs(double a)