36#define FLOAT_PRECISION 9
62 }
while ((ll /= radix) != 0);
72static char *
ch_ltoa(
char *p,
long num,
unsigned radix) {
78static char *ftoa(
char *p,
double num,
unsigned long precision) {
80 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
87 precision = chpow10[precision - 1];
92 l = (long)((num - l) * precision);
125 char *p, *s, c, filler;
126 int i, precision, width;
128 bool is_long, left_align, do_sign;
130#if CHPRINTF_USE_FLOAT
175 width = va_arg(ap,
int);
186 if (c >=
'0' && c <=
'9') {
188 width = width * 10 + c;
204 precision = va_arg(ap,
int);
208 while (c >=
'0' && c <=
'9') {
210 precision = precision * 10 + c;
220 if (c ==
'l' || c ==
'L') {
228 is_long = (c >=
'A') && (c <=
'Z');
235 *p++ = va_arg(ap,
int);
239 if ((s = va_arg(ap,
char *)) == 0) {
242 if (precision == 0) {
245 for (p = s; *p && (--precision >= 0); p++)
253 l = va_arg(ap,
long);
268#if CHPRINTF_USE_FLOAT
270 f = (float) va_arg(ap,
double);
280 p = ftoa(p, f, precision);
288 goto unsigned_common;
292 goto unsigned_common;
298 l = va_arg(ap,
unsigned long);
301 l = va_arg(ap,
unsigned int);
310 if ((width -= i) < 0) {
313 if (left_align ==
false) {
317 if ((*s ==
'-' || *s ==
'+') && filler ==
'0') {
325 }
while (++width != 0);
370 formatted_bytes =
chvprintf(chp, fmt, ap);
373 return formatted_bytes;
403int chsnprintf(
char *str,
size_t size,
const char *fmt, ...) {
444int chvsnprintf(
char *str,
size_t size,
const char *fmt, va_list ap) {
451 size_wo_nul = size - 1;
Mini printf-like functionality.
int chsnprintf(char *str, size_t size, const char *fmt,...)
System formatted output function.
int chprintf(BaseSequentialStream *chp, const char *fmt,...)
System formatted output function.
static char * long_to_string_with_divisor(char *p, long num, unsigned radix, long divisor)
static char * ch_ltoa(char *p, long num, unsigned radix)
int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap)
System formatted output function.
int chvsnprintf(char *str, size_t size, const char *fmt, va_list ap)
System formatted output function.
void msObjectInit(MemoryStream *msp, uint8_t *buffer, size_t size, size_t eos)
Memory stream object initialization.
#define streamPut(ip, b)
Sequential Stream blocking byte write.
Memory streams structures and macros.