#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
p++;
char c = *p;
int left_p = 0;
- int precision_p = 0;
+ int precision = -1;
int width = -1;
if (c == 'l')
c = *++p;
left_p = 1;
c = *++p;
}
- if (c == '.')
- {
- precision_p = 1;
- c = *++p;
- }
char pad = ' ';
if (c == '0')
{
width = va_arg (ap, int);
c = *++p;
}
+ if (c == '.')
+ {
+ c = *++p;
+ if (c >= '0' && c <= '9')
+ {
+ precision = abtoi (&p, 10);
+ c = *p;
+ }
+ else if (c == '*')
+ {
+ precision = va_arg (ap, int);
+ c = *++p;
+ }
+ }
if (c == 'l')
c = *++p;
switch (c)
char const *s = number_to_ascii (d, base, c != 'u' && c != 'x' && c != 'X');
if (c == 'X')
strupr (s);
- if (!precision_p && width >= 0)
- width = width - strlen (s);
- if (!left_p && !precision_p)
- while (!precision_p && width-- > 0)
- {
- fputc (pad, f);
- count++;
- }
+ int length = strlen (s);
+ if (precision == -1)
+ precision = length;
+ if (!left_p)
+ {
+ while (width-- > precision)
+ {
+ fputc (pad, f);
+ count++;
+ }
+ while (precision > length)
+ {
+ fputc ('0', f);
+ precision--;
+ width--;
+ count++;
+ }
+ }
while (*s)
{
- if (precision_p && width-- == 0)
+ if (precision-- <= 0)
break;
+ width--;
fputc (*s++, f);
count++;
}
- while (!precision_p && width-- > 0)
+ while (width > 0)
{
+ width--;
fputc (pad, f);
count++;
}
case 's':
{
char *s = va_arg (ap, char *);
- if (!precision_p && width >= 0)
- width = width - strlen (s);
- if (!left_p && !precision_p)
- while (!precision_p && width-- > 0)
- {
- fputc (pad, f);
- count++;
- }
+ int length = strlen (s);
+ if (precision == -1)
+ precision = length;
+ if (!left_p)
+ {
+ while (width-- > precision)
+ {
+ fputc (pad, f);
+ count++;
+ }
+ while (precision > length)
+ {
+ fputc (' ', f);
+ precision--;
+ width--;
+ count++;
+ }
+ }
while (*s)
{
- if (precision_p && width-- == 0)
+ if (precision-- <= 0)
break;
+ width--;
fputc (*s++, f);
count++;
}
- while (!precision_p && width-- > 0)
+ while (width > 0)
{
+ width--;
fputc (pad, f);
count++;
}
}
default:
{
- eputs ("vfprintf: not supported: %");
+ eputs ("vfprintf: not supported: %:");
eputc (c);
eputs ("\n");
p++;
}
default:
{
- eputs ("vsscanf: not supported: %");
+ eputs ("vsscanf: not supported: %:");
eputc (c);
eputs ("\n");
t++;
p++;
char c = *p;
int left_p = 0;
- int precision_p = 0;
+ int precision = -1;
int width = -1;
if (c == 'l')
c = *++p;
left_p = 1;
c = *++p;
}
- if (c == '.')
- {
- precision_p = 1;
- c = *++p;
- }
char pad = ' ';
if (c == '0')
{
width = va_arg (ap, int);
c = *++p;
}
+ if (c == '.')
+ {
+ c = *++p;
+ if (c >= '0' && c <= '9')
+ {
+ precision = abtoi (&p, 10);
+ c = *p;
+ }
+ else if (c == '*')
+ {
+ precision = va_arg (ap, int);
+ c = *++p;
+ }
+ }
if (c == 'l')
c = *++p;
switch (c)
char const *s = number_to_ascii (d, base, c != 'u' && c != 'x' && c != 'X');
if (c == 'X')
strupr (s);
- if (!precision_p && width >= 0)
- width = width - strlen (s);
- if (!left_p && !precision_p)
- while (!precision_p && width-- > 0)
- {
- *str++ = pad;
- count++;
- }
+ int length = strlen (s);
+ if (precision == -1)
+ precision = length;
+ if (!left_p)
+ {
+ while (width-- > precision)
+ {
+ *str++ = pad;
+ count++;
+ }
+ while (precision > length)
+ {
+ *str++ = '0';
+ precision--;
+ width--;
+ count++;
+ }
+ }
while (*s)
{
- if (precision_p && width-- == 0)
+ if (precision-- <= 0)
break;
+ width--;
*str++ = *s++;
count++;
}
- while (!precision_p && width-- > 0)
+ while (width > 0)
{
+ width--;
*str++ = pad;
count++;
}
case 's':
{
char *s = va_arg (ap, char *);
- if (!precision_p && width >= 0)
- width = width - strlen (s);
- if (!left_p && !precision_p)
- while (!precision_p && width-- > 0)
- {
- *str++ = pad;
- count++;
- }
+ int length = strlen (s);
+ if (precision == -1)
+ precision = length;
+ if (!left_p)
+ {
+ while (width-- > precision)
+ {
+ *str++ = pad;
+ count++;
+ }
+ while (width > length)
+ {
+ *str++ = ' ';
+ precision--;
+ width--;
+ count++;
+ }
+ }
while (*s)
{
- if (precision_p && width-- == 0)
+ if (precision-- <= 0)
break;
+ width--;
*str++ = *s++;
count++;
}
- while (!precision_p && width-- > 0)
+ while (width > 0)
{
+ width--;
*str++ = pad;
count++;
}
}
default:
{
- eputs ("vsprintf: not supported: %");
+ eputs ("vsprintf: not supported: %:");
eputc (c);
eputs ("\n");
p++;