stock sscanf(string[], format[], {Float,_}:...)
{
new
formatPos = 0,
stringPos = 0,
paramPos = 2,
paramCount = numargs();
while (paramPos < paramCount && string[stringPos])
{
switch (format[formatPos++])
{
case '\0':
{
return 0;
}
case 'i', 'd':
{
new
neg = 1,
num = 0,
aa = string[stringPos];
if (aa == '-')
{
neg = -1;
aa = string[++stringPos];
}
do
{
stringPos++;
if (aa >= '0' && aa <= '9')
{
num = (num * 10) + (aa - '0');
}
else
{
return 1;
}
}
while ((aa = string[stringPos]) && aa != ' ');
setarg(paramPos, 0, num * neg);
}
case 'h', 'x':
{
new
aa,
num = 0;
while ((aa = string[stringPos++]))
{
switch (aa)
{
case 'x', 'X':
{
num = 0;
continue;
}
case '0' .. '9':
{
num = (num << 4) | (aa - '0');
}
case 'a' .. 'f':
{
num = (num << 4) | (aa - ('a' - 10));
}
case 'A' .. 'F':
{
num = (num << 4) | (aa - ('A' - 10));
}
case ' ':
{
break;
}
default:
{
return 1;
}
}
}
setarg(paramPos, 0, num);
}
case 'c':
{
setarg(paramPos, 0, string[stringPos++]);
}
case 'f':
{
new tmp[25];
strmid(tmp, string, stringPos, stringPos+sizeof(tmp)-2);
setarg(paramPos, 0, _:floatstr(tmp));
}
case 's', 'z':
{
new
i = 0,
aa;
if (format[formatPos])
{
while ((aa = string[stringPos++]) && aa != ' ')
{
setarg(paramPos, i++, aa);
}
if (!i) return 1;
}
else
{
while ((aa = string[stringPos++]))
{
setarg(paramPos, i++, aa);
}
}
stringPos--;
setarg(paramPos, i, '\0');
}
default:
{
continue;
}
}
while (string[stringPos] && string[stringPos] != ' ')
{
stringPos++;
}
while (string[stringPos] == ' ')
{
stringPos++;
}
paramPos++;
}
while (format[formatPos] == 'z') formatPos++;
return format[formatPos];
}
meintest du des paint? des hat nur 130 zeilen