diff --git a/programs/cmm/example/example.c b/programs/cmm/example/example.c index a96987b380..d2e9415f60 100644 --- a/programs/cmm/example/example.c +++ b/programs/cmm/example/example.c @@ -7,7 +7,7 @@ void main() int id, key, i; dword file; mem_Init(); - io.dir_buffer("/sys/",DIR_ONLYREAL); + io.dir_buffer("",DIR_ONLYREAL); loop() { switch(WaitEvent()) @@ -21,8 +21,7 @@ void main() key = GetKey(); if (key==013){ //Enter draw_window(); - WriteText(50,90,0x80,0xFF00FF,io.dir_position(i)); - if(i=1073741824) strncpy(#size_nm, __T__GB,2); - else if (bytes>=1048576) strncpy(#size_nm, __T__MB,2); - else if (bytes>=1024) strncpy(#size_nm, __T__KB,2); - else strncpy(#size_nm, __T___B,1); + if (bytes>=1073741824) strlcpy(#size_nm, __T__GB,2); + else if (bytes>=1048576) strlcpy(#size_nm, __T__MB,2); + else if (bytes>=1024) strlcpy(#size_nm, __T__KB,2); + else strlcpy(#size_nm, __T___B,1); while (bytes>1023) bytes/=1024; sprintf(#__ConvertSize_size_prefix,"%d %s",bytes,#size_nm); return #__ConvertSize_size_prefix; @@ -282,7 +274,7 @@ __file_F70.param4 = __file_F70.rezerv = 0; __file_F70.param2 = rparam; - __file_F70.name = rpath; + __file_F70.name = path.path(rpath); $mov eax,70 $mov ebx,#__file_F70.func $int 0x40 @@ -297,10 +289,7 @@ } return -1; } -:dword IO::dir_position(dword pos) -{ - return pos*304+dir.buffer+72; -} + :dword IO::dir_buffer(dword PATH;byte options) { count(PATH); diff --git a/programs/cmm/lib/kolibri.h b/programs/cmm/lib/kolibri.h index c2549051ab..b7b5a8f984 100644 --- a/programs/cmm/lib/kolibri.h +++ b/programs/cmm/lib/kolibri.h @@ -904,15 +904,51 @@ inline fastcall dword GetStartTime() //WriteText(x, y, 0x80, 0x000000, #text); } +:void __path_name__(dword BUF,PATH) +{ + dword beg = PATH; + dword pos = PATH; + dword sav = PATH; + dword i; + while(DSBYTE[pos]) + { + if(DSBYTE[pos]=='/')sav = pos; + pos++; + } + i = sav-beg; + while(i) + { + DSBYTE[BUF] = DSBYTE[beg]; + beg++; + BUF++; + i--; + } + /*while(DSBYTE[beg]) + { + DSBYTE[BUF1] = DSBYTE[beg]; + beg++; + BUF1++; + }*/ + //DSBYTE[BUF1] = 0; + DSBYTE[BUF] = 0; +} + dword __generator; // random number generator - для генерации случайных чисел :dword program_path_length; +char __BUF_DIR__[4096]; + +dword __DIR__; + //The initialization of the initial data before running void load_init_main() { - SKIN.height = GetSkinHeight(); + __DIR__ = #__BUF_DIR__; + __path_name__(__DIR__,I_Path); + + SKIN.height = GetSkinHeight(); screen.width = GetScreenWidth(); screen.height = GetScreenHeight(); diff --git a/programs/cmm/lib/strings.h b/programs/cmm/lib/strings.h index 4c0bb50c75..1a0df17a5f 100644 --- a/programs/cmm/lib/strings.h +++ b/programs/cmm/lib/strings.h @@ -849,12 +849,12 @@ inline cdecl int sprintf(dword buf, format,...) tmp = itoa(tmp); if(!DSBYTE[tmp])goto END_FUNC_SPRINTF; l = strlen(tmp); - strncpy(buf,tmp,l); + strlcpy(buf,tmp,l); buf += l; break; case 'a': case 'A': - strncpy(buf,"0x00000000",10); + strlcpy(buf,"0x00000000",10); buf+=10; l=buf; while(tmp) @@ -871,7 +871,7 @@ inline cdecl int sprintf(dword buf, format,...) tmp = itoa(#tmp); if(!DSBYTE[tmp])goto END_FUNC_SPRINTF; l = strlen(tmp); - strncpy(buf,tmp,l); + strlcpy(buf,tmp,l); buf += l; break; case '%':