36 #define FLOAT_PRECISION 9 38 static char *long_to_string_with_divisor(
char *p,
61 }
while ((ll /= radix) != 0);
63 i = (int)(p + MAX_FILLER - q);
71 static char *ch_ltoa(
char *p,
long num,
unsigned radix) {
73 return long_to_string_with_divisor(p, num, radix, 0);
76 #if CHPRINTF_USE_FLOAT 77 static const long pow10[FLOAT_PRECISION] = {
78 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
81 static char *ftoa(
char *p,
double num,
unsigned long precision) {
84 if ((precision == 0) || (precision > FLOAT_PRECISION))
85 precision = FLOAT_PRECISION;
86 precision = pow10[precision - 1];
89 p = long_to_string_with_divisor(p, l, 10, 0);
91 l = (long)((num - l) * precision);
92 return long_to_string_with_divisor(p, l, 10, precision / 10);
123 char *p, *s, c, filler;
124 int i, precision, width;
126 bool is_long, left_align;
128 #if CHPRINTF_USE_FLOAT 130 char tmpbuf[2*MAX_FILLER + 1];
132 char tmpbuf[MAX_FILLER + 1];
159 if (c >=
'0' && c <=
'9')
165 width = width * 10 + c;
171 if (c >=
'0' && c <=
'9')
182 if (c ==
'l' || c ==
'L') {
188 is_long = (c >=
'A') && (c <=
'Z');
194 *p++ = va_arg(ap,
int);
198 if ((s = va_arg(ap,
char *)) == 0)
202 for (p = s; *p && (--precision >= 0); p++)
210 l = va_arg(ap,
long);
217 p = ch_ltoa(p, l, 10);
219 #if CHPRINTF_USE_FLOAT 221 f = (float) va_arg(ap,
double);
226 p = ftoa(p, f, precision);
232 goto unsigned_common;
236 goto unsigned_common;
242 l = va_arg(ap,
unsigned long);
244 l = va_arg(ap,
unsigned int);
245 p = ch_ltoa(p, l, c);
252 if ((width -= i) < 0)
254 if (left_align == FALSE)
257 if (*s ==
'-' && filler ==
'0') {
265 }
while (++width != 0);
310 formatted_bytes =
chvprintf(chp, fmt, ap);
313 return formatted_bytes;
343 int chsnprintf(
char *str,
size_t size,
const char *fmt, ...) {
384 int chvsnprintf(
char *str,
size_t size,
const char *fmt, va_list ap) {
391 size_wo_nul = size - 1;
#define streamPut(ip, b)
Sequential Stream blocking byte write.
void msObjectInit(MemoryStream *msp, uint8_t *buffer, size_t size, size_t eos)
Memory stream object initialization.
int chsnprintf(char *str, size_t size, const char *fmt,...)
System formatted output function.
Mini printf-like functionality.
int chvsnprintf(char *str, size_t size, const char *fmt, va_list ap)
System formatted output function.
Memory streams structures and macros.
int chprintf(BaseSequentialStream *chp, const char *fmt,...)
System formatted output function.
int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap)
System formatted output function.