| 416 | #endif |
| 417 | |
| 418 | static int ee_vsprintf(char *buf, const char *fmt, va_list args) |
| 419 | { |
| 420 | int len; |
| 421 | unsigned long num; |
| 422 | int i, base; |
| 423 | char *str; |
| 424 | char *s; |
| 425 | |
| 426 | int flags; // Flags to number() |
| 427 | |
| 428 | int field_width; // Width of output field |
| 429 | int precision; // Min. # of digits for integers; max number of chars for from string |
| 430 | int qualifier; // 'h', 'l', or 'L' for integer fields |
| 431 | |
| 432 | for (str = buf; *fmt; fmt++) |
| 433 | { |
| 434 | if (*fmt != '%') |
| 435 | { |
| 436 | *str++ = *fmt; |
| 437 | continue; |
| 438 | } |
| 439 | |
| 440 | // Process flags |
| 441 | flags = 0; |
| 442 | repeat: |
| 443 | fmt++; // This also skips first '%' |
| 444 | switch (*fmt) |
| 445 | { |
| 446 | case '-': flags |= LEFT; goto repeat; |
| 447 | case '+': flags |= PLUS; goto repeat; |
| 448 | case ' ': flags |= SPACE; goto repeat; |
| 449 | case '#': flags |= HEX_PREP; goto repeat; |
| 450 | case '0': flags |= ZEROPAD; goto repeat; |
| 451 | } |
| 452 | |
| 453 | // Get field width |
| 454 | field_width = -1; |
| 455 | if (is_digit(*fmt)) |
| 456 | field_width = skip_atoi(&fmt); |
| 457 | else if (*fmt == '*') |
| 458 | { |
| 459 | fmt++; |
| 460 | field_width = va_arg(args, int); |
| 461 | if (field_width < 0) |
| 462 | { |
| 463 | field_width = -field_width; |
| 464 | flags |= LEFT; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | // Get the precision |
| 469 | precision = -1; |
| 470 | if (*fmt == '.') |
| 471 | { |
| 472 | ++fmt; |
| 473 | if (is_digit(*fmt)) |
| 474 | precision = skip_atoi(&fmt); |
| 475 | else if (*fmt == '*') |