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