From 2e3d90aedd6571cba0b385a92996550bf89997de Mon Sep 17 00:00:00 2001 From: pavelyakov Date: Fri, 5 Oct 2018 09:34:50 +0000 Subject: [PATCH] Update function sprintf, fixed bugs git-svn-id: svn://kolibrios.org@7435 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/lib/strings.h | 81 ++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/programs/cmm/lib/strings.h b/programs/cmm/lib/strings.h index 3a7dece780..f4787fddd2 100644 --- a/programs/cmm/lib/strings.h +++ b/programs/cmm/lib/strings.h @@ -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; }