static int
p4sprintf (char* s)
{
p4char formbuf[255];
p4char* formed;
p4char* format;
int format_n;
int argn = 0;
p4cell argv[16];
formed = formbuf;
format = (void*)FX_POP;
format_n = *format++;
while (format_n > 0)
{
if (*format=='%' ) {
*formed++ = *format++; format_n--;
if (*format == '%' ) {
*formed++ = *format++; format_n--;
continue;
}
if (*format == 's' ) {
*formed++ = '%' ;
format++; format_n--;
FX_DROP;
continue;
}
argv [argn++] = FX_POP;
while (format_n > 0)
{
if (argn >= 15) goto printnow;
if (format[0] == '.' && format[1] == '*' ) {
argv [argn++] = FX_POP;
*formed++ = *format++; format_n--;
*formed++ = *format++; format_n--;
continue;
}
if (format[0] == '#' && format[1] == 's' ) {
p4char* p = (void*) argv [argn-1];
argv [argn-1] = *p; argv [argn++] = (p4cell)(p+1);
*formed++ = '.' ;
*formed++ = '*' ;
*formed++ = 's' ;
format+=2; format_n-=2;
break;
}
if (isalpha(*format))
break;
*formed++ = *format++; format_n--;
}
continue;
}
*formed++ = *format++; format_n--;
}
printnow:
{
int printed;
*formed='\0' ;
if (argn <= 8)
{
printed = sprintf (s, formbuf,
argv[0], argv[1], argv[2], argv[3],
argv[4], argv[5], argv[6], argv[7]);
}else{
# ifdef P4_UPPER_REGS
P4_CALLER_MKSAVED
# endif
printed = sprintf (s, formbuf,
argv[0], argv[1], argv[2], argv[3],
argv[4], argv[5], argv[6], argv[7],
argv[8], argv[9], argv[10], argv[11],
argv[12], argv[13], argv[14], argv[15]);
# ifdef P4_UPPER_REGS
P4_CALLER_RESTORE
# endif
if (argn > 13)
{ P4_warn1 ("quite many args for a printf (%i)" , argn); }
}
if (printed > 255)
{ P4_warn1 ("printf long string (%i chars)" , printed); }
return printed;
}
} |