Update function sprintf, fixed bugs

git-svn-id: svn://kolibrios.org@7435 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
pavelyakov 2018-10-05 09:34:50 +00:00
parent 8bd9dd2363
commit 2e3d90aedd

View File

@ -830,87 +830,100 @@ inline signed csshexdec(dword text)
return ret;
}
inline cdecl int sprintf(dword buf, format,...)
:dword stdcall sprintf(dword buf, format,...)
{
#define END_ARGS 0xFF00FF //ARGS FUNCTION
byte s;
char X[10];
dword ret, tmp, l;
dword arg = #format;
ret = buf;
s = DSBYTE[format];
while(s){
if(s=='%'){
arg+=4;
while(s)
{
if(s == '%')
{
arg += 4;
tmp = DSDWORD[arg];
if(tmp==END_ARGS)goto END_FUNC_SPRINTF;
$inc format
format++;
s = DSBYTE[format];
if(!s)goto END_FUNC_SPRINTF;
IF (!s)
{
DSBYTE[buf] = 0;
return ret;
}
switch(s)
{
case 's':
l = tmp;
s = DSBYTE[tmp];
while(s)
WHILE(DSBYTE[tmp])
{
DSBYTE[buf] = s;
$inc tmp
$inc buf
s = DSBYTE[tmp];
DSBYTE[buf] = DSBYTE[tmp];
tmp++;
buf++;
}
break;
case 'c':
DSBYTE[buf] = tmp;
$inc buf
buf++;
break;
case 'u': //if(tmp<0)return ret;
case 'd':
case 'i':
tmp = itoa(tmp);
if(!DSBYTE[tmp])goto END_FUNC_SPRINTF;
IF (!DSBYTE[tmp])
{
DSBYTE[buf] = 0;
return ret;
}
l = strlen(tmp);
strlcpy(buf,tmp,l);
buf += l;
break;
case 'a':
case 'A':
strlcpy(buf,"0x00000000",10);
buf+=10;
l=buf;
while(tmp)
strlcpy(buf, "0x00000000", 10);
buf += 10;
l = buf;
WHILE(tmp)
{
$dec buf
s=tmp&0xF;
if(s>9)DSBYTE[buf]='A'+s-10;
else DSBYTE[buf]='0'+s;
tmp>>=4;
buf--;
s = tmp & 0xF;
IF (s > 9) DSBYTE[buf] = 'A' - 10 + s;
ELSE DSBYTE[buf] = '0' + s;
tmp >>= 4;
}
buf=l;
buf = l;
break;
case 'p':
tmp = itoa(#tmp);
if(!DSBYTE[tmp])goto END_FUNC_SPRINTF;
IF (!DSBYTE[tmp])
{
DSBYTE[buf] = 0;
return ret;
}
l = strlen(tmp);
strlcpy(buf,tmp,l);
buf += l;
break;
case '%':
DSBYTE[buf] = '%';
$inc buf
buf++;
break;
default:
goto END_FUNC_SPRINTF;
{
DSBYTE[buf] = 0;
return ret;
}
}
}
else {
else
{
DSBYTE[buf] = s;
$inc buf
buf++;
}
$inc format
format++;
s = DSBYTE[format];
}
END_FUNC_SPRINTF:
DSBYTE[buf] = 0;
return ret;
}