Subversion Repositories Kolibri OS

Rev

Rev 7878 | Rev 7945 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef INCLUDE_STRING_H
  2. #define INCLUDE_STRING_H
  3.  
  4. #ifndef INCLUDE_MEM_H
  5. #include "../lib/mem.h"
  6. #endif
  7.  
  8. //------------------------------------------------------------------------------
  9. // strspn(dword text1,text2) --- example: strspn("12 year","1234567890") -> return 2
  10. // strpbrk(dword text1,text2) --- example: strpbrk("this test", " ckfi") -> return "is test"
  11. // strcmp( ESI, EDI)
  12. // strlen( EDI)
  13. // utf8_strlen( ESI)
  14. // strcpy( EDI, ESI) --- 0 if ==
  15. // strlcpy(dword text1,text2,signed length)
  16. // strcat( EDI, ESI)
  17. // chrcat(ESI, BL)
  18. // strncat(dword text1,text2,signed length) --- pasting the text of a certain length
  19. // strchr( ESI,BL) --- find first BL
  20. // strrchr( ESI,BL) --- find last BL
  21. // strstr( EBX, EDX)
  22. // itoa(signed long number) --- convert the number as a string
  23. // atoi(dword text) --- convert a string as a number
  24. // strupr( ESI)
  25. // strlwr( ESI) --- Cyrillic symbols may not work
  26. // strttl( EDX)
  27. // strtok( ESI)
  28. // strltrim(dword text) --- removes "blank" characters on the left (\r, \n and space)
  29. // strrtrim(dword text) --- removes "blank" characters on the right (\r, \n and space)
  30. // strtrim(dword text) --- delete "empty" characters (\ r \ n and space) on both sides
  31. // chrnum(dword searchin, char symbol)
  32. // strcpyb(dword searchin, copyin, startstr, endstr) --- copy string between strings
  33. // strnumb(dword searchin, startstr, endstr) --- get number between strings
  34. // strdup(dword text) --- allocation under the text
  35. //------------------------------------------------------------------------------
  36.  
  37. /*
  38. inline fastcall signed int strcmp( ESI, EDI)
  39. {
  40.     loop()
  41.     {
  42.         IF (DSBYTE[ESI]<DSBYTE[EDI]) RETURN -1;
  43.         IF (DSBYTE[ESI]>DSBYTE[EDI]) RETURN 1;
  44.         IF (DSBYTE[ESI]=='\0') RETURN 0;
  45.         ESI++;
  46.         EDI++;
  47.     }
  48. }
  49. */
  50.  
  51.  
  52.  
  53. inline int strspn(dword text1,text2)
  54. {
  55.         dword beg;
  56.         char s1,s2;
  57.         int ret;
  58.         ret = 0;
  59.         beg = text2;
  60.         do {
  61.                 s1 = ESBYTE[text1];
  62.                 text2 = beg;
  63.                 do {
  64.                         s2 = ESBYTE[text2];
  65.                         if(s1==s2)
  66.                         {
  67.                                 if(!s2)break;
  68.                                 $inc ret
  69.                                 break;
  70.                         }
  71.                         else $inc text2
  72.                 } while(s2);
  73.                 $inc text1
  74.         } while(s1);
  75.         return ret;
  76. }
  77.  
  78. inline dword strpbrk(dword text1,text2)
  79. {
  80.         char s,ss;
  81.         dword beg;
  82.         beg = text2;
  83.         do {
  84.                 s = ESBYTE[text1];
  85.                 text2 = beg;
  86.                 do {
  87.                         ss = ESBYTE[text2];
  88.                         if(ss==s) return text1;
  89.                         $inc text2
  90.                 } while(ss);
  91.                 $inc text1
  92.         } while(s);
  93.         return text1;
  94. }
  95.  
  96. inline fastcall signed int strncmp( ESI, EDI, ECX)
  97. {
  98.   asm {
  99.     MOV EBX, EDI
  100.     XOR EAX, EAX
  101.     MOV EDX, ECX
  102.     OR ECX, ECX
  103.     JE L1
  104.     REPNE SCASB
  105.     SUB EDX, ECX
  106.     MOV ECX, EDX
  107.     MOV EDI, EBX
  108.     XOR EBX, EBX
  109.     REPE CMPSB
  110.     MOV AL, DSBYTE[ ESI-1]
  111.     MOV BL, DSBYTE[ EDI-1]
  112.     SUB EAX, EBX
  113. L1:
  114.   }
  115. }
  116.  
  117. /*
  118. signed int strncmp(dword s1, s2, signed n)
  119. unsigned char _s1,_s2;
  120. {
  121.         if (n == 0)
  122.                 return 0;
  123.         do {
  124.                 _s1 = DSBYTE[s1];
  125.                 _s2 = DSBYTE[s2];
  126.                 if (_s1 != _s2)
  127.                 {
  128.                         $dec s2
  129.                         return _s1 - _s2;
  130.                 }
  131.                 $inc s2
  132.                 if (_s1 == 0)
  133.                         break;
  134.                 $inc s1
  135.                 $dec n
  136.         } while (n);
  137.         return 0;
  138. }
  139. */
  140.  
  141. /*
  142. inline signed int strncmp(dword text1,text2,len)
  143. {
  144.        
  145.         loop()
  146.         {
  147.                 if(DSBYTE[text1]!=DSBYTE[text2])return text1-text2;
  148.                 $dec len
  149.                 if(!len)return 0;
  150.         }
  151. }
  152. */
  153. inline fastcall unsigned int strlen( EDI)
  154. {
  155.         $xor eax, eax
  156.         $mov ecx, -1
  157.         $REPNE $SCASB
  158.         EAX-=2+ECX;
  159. }
  160.  
  161. inline dword strnlen(dword str, dword maxlen)
  162. {
  163.         dword cp;
  164.         for (cp = str; (maxlen != 0) && (DSBYTE[cp] != '\0'); cp++, maxlen--);
  165.         return cp - str;
  166. }
  167.  
  168. inline fastcall unsigned int utf8_strlen( ESI)
  169. {
  170.  $xor  ecx, ecx
  171.   _loop:
  172.  $lodsb
  173.  $test  al, al
  174.  $jz  _done
  175.  $and al, 0xc0
  176.  $cmp al, 0x80
  177.  $jz  _loop
  178.  $inc ecx
  179.  $jmp _loop
  180.  
  181.   _done:
  182.  return ECX;
  183. }
  184.  
  185. inline signed int strcmp(dword text1, text2)
  186. {
  187.         char s1,s2;
  188.         dword p1,p2;
  189.         p1 = text1;
  190.         p2 = text2;
  191.         loop()
  192.         {
  193.                 s1 = DSBYTE[text1];
  194.                 s2 = DSBYTE[text2];
  195.                 if(s1==s2)
  196.                 {
  197.                         if(s1==0) return 0;
  198.                 }
  199.                 else {
  200.                         return s1-s2;
  201.                 }
  202.                 $inc text1
  203.                 $inc text2
  204.         }
  205.         return 0;
  206. }
  207.  
  208.  
  209. inline fastcall streq(ESI, EDI)
  210. {
  211.         loop()
  212.         {
  213.                 if(DSBYTE[ESI]==DSBYTE[EDI])
  214.                 {
  215.                         if(DSBYTE[ESI]==0) return true;
  216.                 }
  217.                 else {
  218.                         return false;
  219.                 }
  220.                 ESI++;
  221.                 EDI++;
  222.         }
  223.         return true;
  224. }
  225.  
  226. inline fastcall void strcpy( EDI, ESI)
  227. {
  228.     $cld
  229. L2:
  230.     $lodsb
  231.     $stosb
  232.     $test al,al
  233.     $jnz L2
  234. }
  235.  
  236. inline fastcall int strlcpy(dword ESI, EDI, EBX)
  237. {
  238.     if (EBX<0) return -1;
  239.     EDX=0;
  240.     do {
  241.         DSBYTE[ESI]=DSBYTE[EDI];
  242.         ESI++;
  243.         EDI++;
  244.         EDX++;
  245.         if (EDX==EBX) { DSBYTE[ESI]='\0'; return -1;}
  246.     } while(DSBYTE[EDI-1]!='\0');
  247.     return 0;
  248. }
  249.  
  250. :void strncpy(dword dst, src, len)
  251. {
  252.         while (len) && (ESBYTE[src])
  253.         {
  254.                 ESBYTE[dst] = ESBYTE[src];
  255.                 dst++;
  256.                 src++;
  257.                 len--;
  258.         }
  259.         ESBYTE[dst]=0;
  260. }
  261.  
  262. /*
  263. inline fastcall void strtrim( ESI)
  264. {
  265.     EDI = ESI;
  266.     do{
  267.         AL=DSBYTE[EDI];
  268.         if (AL != '\32') && (AL != '\13') && (AL != '\10')
  269.         {
  270.             DSBYTE[ESI]=AL;
  271.             $inc ESI
  272.         }
  273.          $inc EDI
  274.     }while(AL!=0);
  275.     DSBYTE[ESI] = '\0';
  276. }
  277. */
  278.  
  279. inline byte __isWhite(int s){ if (s==13)||(s==32)||(s==10)||(s==9) return true; return false; }
  280. inline void strltrim(dword text){
  281.         int s;
  282.         dword back_text;
  283.         back_text = text;
  284.         s = ESBYTE[text];
  285.         while(__isWhite(s))
  286.         {
  287.                 $inc text
  288.                 s = ESBYTE[text];
  289.         }
  290.         loop()
  291.         {
  292.                 ESBYTE[back_text] = s;
  293.                 $inc back_text
  294.                 if(!s) break;
  295.                 $inc text
  296.                 s = ESBYTE[text];
  297.         };
  298. }
  299.  
  300. inline void strrtrim(dword text)
  301. {
  302.         int s;
  303.         dword p;
  304.         do {
  305.                 s = ESBYTE[text];
  306.                 if(__isWhite(s))
  307.                 {
  308.                         p = text;
  309.                         while(__isWhite(s))
  310.                         {
  311.                                 $inc text;
  312.                                 s = ESBYTE[text];
  313.                         }
  314.                 }
  315.                 else $inc text
  316.         } while(s);
  317.         $dec text
  318.         s = ESBYTE[text];
  319.         if(__isWhite(s)) ESBYTE[p] = 0;
  320. }
  321.  
  322. inline void strtrim(dword text){
  323.         int s;
  324.         dword p,back_text;
  325.         back_text = text;
  326.         s = ESBYTE[text];
  327.         while(__isWhite(s))
  328.         {
  329.                 $inc text
  330.                 s = ESBYTE[text];
  331.         }
  332.         do {
  333.                 s = ESBYTE[text];
  334.                 if(__isWhite(s))
  335.                 {
  336.                         p = back_text;
  337.                         while(__isWhite(s))
  338.                         {
  339.                                 ESBYTE[back_text] = s;
  340.                                 $inc back_text
  341.                                 $inc text;
  342.                                 s = ESBYTE[text];
  343.                         }
  344.                 }
  345.                 else {
  346.                         ESBYTE[back_text] = s;
  347.                         $inc back_text
  348.                         $inc text
  349.                 }
  350.         } while(s);
  351.         $dec text
  352.         s = ESBYTE[text];
  353.         if(__isWhite(s)) ESBYTE[p] = 0;
  354. }
  355.  
  356. inline fastcall void strcat( EDI, ESI)
  357. {
  358.   asm {
  359.     mov ebx, edi
  360.     xor ecx, ecx
  361.     xor eax, eax
  362.     dec ecx
  363.     repne scasb
  364.     dec edi
  365.     mov edx, edi
  366.     mov edi, esi
  367.     xor ecx, ecx
  368.     xor eax, eax
  369.     dec ecx
  370.     repne scasb
  371.     xor ecx, 0ffffffffh
  372.     mov edi, edx
  373.     mov edx, ecx
  374.     mov eax, edi
  375.     shr ecx, 2
  376.     rep movsd
  377.     mov ecx, edx
  378.     and ecx, 3
  379.     rep movsb
  380.     mov eax, ebx
  381.     }
  382. }
  383.  
  384. :void strncat(dword dst, src, len)
  385. {
  386.         while (ESBYTE[dst]) && (len) {
  387.                 dst++;
  388.                 len--;
  389.         }
  390.         while (ESBYTE[src]) && (len>1) {
  391.                 ESBYTE[dst] = ESBYTE[src];
  392.                 dst++;
  393.                 src++;
  394.                 len--;
  395.         }
  396.         ESBYTE[dst] = 0;
  397. }
  398.  
  399. :void chrncat(dword dst, unsigned char s, dword len)
  400. {
  401.         while (ESBYTE[dst]) && (len) {
  402.                 dst++;
  403.                 len--;
  404.         }
  405.         if (len>1) {
  406.                 ESBYTE[dst] = s;
  407.                 ESBYTE[dst+1] = 0;
  408.         }
  409. }
  410.  
  411. inline fastcall void chrcat(ESI, DI)
  412. {
  413.     while (ESBYTE[ESI]) ESI++;
  414.     ESBYTE[ESI] = DI;
  415.     ESI++;
  416.     ESBYTE[ESI] = 0;
  417. }
  418.  
  419. inline dword strchr(dword shb;char s)
  420. {
  421.         char ss;
  422.         loop()
  423.         {
  424.                 ss = DSBYTE[shb];
  425.                 if(!ss)return 0;
  426.                 if(ss==s)return shb;
  427.                 shb++;
  428.         }
  429. }
  430.  
  431. inline fastcall signed int strrchr( ESI,BL)
  432. {
  433.     int jj=0, last=0;
  434.     do{
  435.         jj++;
  436.         $lodsb
  437.         IF(AL==BL) last=jj;
  438.     } while(AL!=0);
  439.     return last;
  440. }
  441.  
  442.  
  443. inline fastcall unsigned int chrnum( ESI, BL)
  444. {
  445.     int num = 0;
  446.     while(DSBYTE[ESI])
  447.     {
  448.         if (DSBYTE[ESI] == BL) num++;
  449.         ESI++;
  450.     }
  451.     return num;
  452. }
  453.  
  454.  
  455. inline fastcall signed int strstr( EBX, EDX)
  456. {
  457.   asm {
  458.     MOV EDI, EDX
  459.     XOR ECX, ECX
  460.     XOR EAX, EAX
  461.     DEC ECX
  462.     REPNE SCASB
  463.     NOT ECX
  464.     DEC ECX
  465.     JE LS2
  466.     MOV ESI, ECX
  467.     XOR ECX, ECX
  468.     MOV EDI, EBX
  469.     DEC ECX
  470.     REPNE SCASB
  471.     NOT ECX
  472.     SUB ECX, ESI
  473.     JBE LS2
  474.     MOV EDI, EBX
  475.     LEA EBX, DSDWORD[ ESI-1]
  476. LS1: MOV ESI, EDX
  477.     LODSB
  478.     REPNE SCASB
  479.     JNE LS2
  480.     MOV EAX, ECX
  481.     PUSH EDI
  482.     MOV ECX, EBX
  483.     REPE CMPSB
  484.     POP EDI
  485.     MOV ECX, EAX
  486.     JNE LS1
  487.     LEA EAX, DSDWORD[ EDI-1]
  488.     JMP SHORT LS3
  489. LS2: XOR EAX, EAX
  490. LS3:
  491.   }
  492. }
  493.  
  494. inline int strnum(dword haystack, needle)
  495. {
  496.         int count = 0;
  497.         int needle_len = strlen(needle);
  498.         loop() {
  499.                 if (! haystack = strstr(haystack, needle)) break;
  500.                 haystack+=needle_len;
  501.                 count++;
  502.         }
  503.         return count;
  504. }
  505.  
  506. inline signed int strcmpi(dword cmp1, cmp2)
  507. {
  508.     char si, ue;
  509.  
  510.     loop()
  511.     {
  512.         si = DSBYTE[cmp1];
  513.         ue = DSBYTE[cmp2];
  514.         if (si>='A') && (si<='Z') si +=32;
  515.         if (ue>='A') && (ue<='Z') ue +=32;
  516.         if (si != ue) return si-ue;
  517.         cmp1++;
  518.         cmp2++;
  519.         if ((DSBYTE[cmp1]=='\0') && (DSBYTE[cmp2]=='\0')) return 0;
  520.         if (DSBYTE[cmp1]=='\0') return -1;
  521.         if (DSBYTE[cmp2]=='\0') return 1;
  522.     }
  523. }
  524.  
  525. inline dword strstri(dword searchin, usestr_s)
  526. {
  527.     dword usestr_e = usestr_s;
  528.     char si, ue;
  529.  
  530.     while(DSBYTE[searchin])
  531.     {
  532.         si = DSBYTE[searchin];
  533.         ue = DSBYTE[usestr_e];
  534.         if (si>='A') && (si<='Z') si +=32;
  535.         if (ue>='A') && (ue<='Z') ue +=32;
  536.         if (si == ue) usestr_e++; else usestr_e = usestr_s;
  537.         searchin++;
  538.         if (DSBYTE[usestr_e]=='\0') return searchin;
  539.     }
  540.     return -1;
  541. }
  542.  
  543.  
  544. inline unsigned int strcpyb(dword search_in, copyin, startstr, endstr)
  545. {
  546.     dword startp, endp;
  547.     dword copyin_start_off = copyin;
  548.     if (startstr==0) startp = search_in; else startp = strstr(search_in, startstr) + strlen(startstr);
  549.     endp = strstri(startp, endstr);
  550.     if (endp==0) endp = startp+strlen(search_in);
  551.     //if (startp==endp) return 0;
  552.     do
  553.     {
  554.         DSBYTE[copyin] = DSBYTE[startp];
  555.         copyin++;
  556.         startp++;
  557.     }
  558.     while (startp<endp);
  559.     DSBYTE[copyin] = '\0';
  560.     return copyin_start_off;
  561. }
  562.  
  563.  
  564. /*void strcat(char *to, char *from)
  565. {
  566.     while(*to) to++;
  567.     while(*from)
  568.     {
  569.         *to = *from;
  570.         to++;
  571.         from++;
  572.     }
  573.     *to = '\0';
  574. }*/
  575.  
  576.  
  577. inline fastcall dword atoi( EDI)
  578. {
  579.     $push ebx
  580.     $push esi
  581.     ESI=EDI;
  582.     while (DSBYTE[ESI]==' ') ESI++;
  583.     if (DSBYTE[ESI]=='-') ESI++;
  584.     EAX=0;
  585.     while (DSBYTE[ESI]>='0') && (DSBYTE[ESI]<='9')
  586.     {
  587.         $xor ebx, ebx
  588.         EBX = DSBYTE[ESI]-'0';
  589.         EAX *= 10;
  590.         EAX += EBX;
  591.         ESI++;
  592.     }
  593.     IF (DSBYTE[EDI]=='-') -EAX;
  594.     $pop esi
  595.     $pop ebx
  596. }
  597.  
  598.  
  599.  
  600. inline fastcall strupr( ESI)
  601. {
  602.     do{
  603.         AL=DSBYTE[ESI];
  604.         IF(AL>='a')IF(AL<='z')DSBYTE[ESI]=AL&0x5f;
  605.         IF (AL>=160) && (AL<=175) DSBYTE[ESI] = AL - 32;    //à-ï
  606.         IF (AL>=224) && (AL<=239) DSBYTE[ESI] = AL - 80;    //à-ï
  607.          ESI++;
  608.     }while(AL!=0);
  609. }
  610.  
  611. inline fastcall strlwr( ESI)
  612. {
  613.     do{
  614.         $LODSB
  615.         IF(AL>='A')&&(AL<='Z'){
  616.             AL+=0x20;
  617.             DSBYTE[ESI-1]=AL;
  618.             CONTINUE;
  619.         }
  620.     }while(AL!=0);
  621. }
  622.  
  623. inline fastcall strttl( EDX)
  624. {
  625.     AL=DSBYTE[EDX];
  626.     IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f;
  627.     IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32;    //à-ï
  628.     IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80;    //à-ï
  629.     do{
  630.         EDX++;
  631.         AL=DSBYTE[EDX];
  632.         IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;}
  633.         IF(AL>='€')&&(AL<='')DSBYTE[EDX]=AL|0x20; // -¯
  634.         IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80;    //à-ï
  635.     }while(AL!=0);
  636. }
  637.  
  638. /*
  639. dword itoa( ESI)
  640. {
  641.     unsigned char buffer[11];
  642.     $pusha
  643.     EDI = #buffer;
  644.     ECX = 10;
  645.     if (ESI < 0)
  646.     {
  647.          $mov     al, '-'
  648.          $stosb
  649.          $neg     esi
  650.     }
  651.  
  652.     $mov     eax, esi
  653.     $push    -'0'
  654. F2:
  655.     $xor     edx, edx
  656.     $div     ecx
  657.     $push    edx
  658.     $test    eax, eax
  659.     $jnz     F2
  660. F3:
  661.     $pop     eax
  662.     $add     al, '0'
  663.     $stosb
  664.     $jnz     F3
  665.    
  666.     $mov     al, '\0'
  667.     $stosb
  668.  
  669.     $popa
  670.     return #buffer;
  671. }
  672. */
  673. :unsigned char BUF_ITOA[11];
  674. inline dword itoa(signed long number)
  675. {
  676.         dword ret,p;
  677.         byte cmd;
  678.         long mask,tmp;
  679.         mask = 1000000000;
  680.         cmd = true;
  681.         p = #BUF_ITOA;
  682.         if(!number){
  683.                 ESBYTE[p] = '0';
  684.                 ESBYTE[p+1] = 0;
  685.                 return p;
  686.         }
  687.         ret = p;
  688.         if(number<0)
  689.         {
  690.                 $neg number
  691.                 ESBYTE[p] = '-';
  692.                 $inc p
  693.         }
  694.         while(mask)
  695.         {
  696.                 tmp = number / mask;
  697.                 tmp = tmp%10;
  698.                
  699.                 if(cmd){
  700.                         if(tmp){
  701.                                 ESBYTE[p] = tmp + '0';
  702.                                 $inc p
  703.                                 cmd = false;
  704.                         }
  705.                 }
  706.                 else {
  707.                         ESBYTE[p] = tmp + '0';
  708.                         $inc p
  709.                 }
  710.                 mask /= 10;
  711.         }
  712.         ESBYTE[p] = 0;
  713.         return ret;
  714. }
  715.  
  716. inline fastcall itoa_(signed int EDI, ESI)
  717. {
  718.     $pusha
  719.     EBX = EDI;
  720.     ECX = 10;
  721.     if (ESI > 90073741824)
  722.     {
  723.          $mov     al, '-'
  724.          $stosb
  725.          $neg     esi
  726.     }
  727.  
  728.     $mov     eax, esi
  729.     $push    -'0'
  730. F2:
  731.     $xor     edx, edx
  732.     $div     ecx
  733.     $push    edx
  734.     $test    eax, eax
  735.     $jnz     F2
  736. F3:
  737.     $pop     eax
  738.     $add     al, '0'
  739.     $stosb
  740.     $jnz     F3
  741.    
  742.     $mov     al, '\0'
  743.     $stosb
  744.  
  745.     $popa
  746.     return EBX;
  747. }
  748.  
  749. inline dword memchr(dword s,int c,signed len)
  750. {
  751.         if(!len) return NULL;
  752.         do {
  753.                 if(DSBYTE[s] == c) return s;
  754.                 $inc s
  755.                 $dec len
  756.         } while(len);
  757.         return NULL;
  758. }
  759.  
  760. inline dword strdup(dword text)
  761. {
  762.     dword l = strlen(text);
  763.     dword ret = malloc(l+1);
  764.         if(!ret) return NULL;
  765.     strlcpy(ret,text,l);
  766.     return ret;
  767. }
  768.  
  769. inline dword strndup(dword str, signed maxlen)
  770. {
  771.         dword copy,len;
  772.  
  773.         len = strnlen(str, maxlen);
  774.         copy = malloc(len + 1);
  775.         if (copy != NULL)
  776.         {
  777.                 strlcpy(copy, str, len);
  778.                 DSBYTE[len+copy] = '\0';
  779.         }
  780.         return copy;
  781. }
  782.  
  783. inline dword hexdec(dword text)
  784. {
  785.         char s;
  786.         dword ret,l;
  787.         ret = 0;
  788.         s = DSBYTE[text];
  789.         while(s)
  790.         {      
  791.                 ret <<= 4;
  792.                 if(s>='A')&&(s<='F')ret |= s-'A'+10;
  793.                 else if(s>='a')&&(s<='f')ret |= s-'a'+10;
  794.                 else if(s>='0')&&(s<='9')ret |= s-'0';
  795.                 text++;
  796.                 s = DSBYTE[text];
  797.         }
  798.         return ret;
  799. }
  800.  
  801. inline signed csshexdec(dword text)
  802. {
  803.         char s;
  804.         dword ret,l;
  805.         byte tmp;
  806.         l = strlen(text);
  807.         ret = 0;
  808.         s = DSBYTE[text];
  809.         tmp = 0;
  810.         if(l==6) while(s)
  811.         {      
  812.                 ret <<= 4;
  813.                 if(s>='A')&&(s<='F')ret |= s-'A'+10;
  814.                 else if(s>='a')&&(s<='f')ret |= s-'a'+10;
  815.                 else if(s>='0')&&(s<='9')ret |= s-'0';
  816.                 text++;
  817.                 s = DSBYTE[text];
  818.         }
  819.         else if(l==3) while(s)
  820.         {      
  821.                 ret |= tmp;
  822.                 ret <<= 4;
  823.                 ret |= tmp;
  824.                 ret <<= 4;
  825.                 if(s>='A')&&(s<='F')tmp = s-'A'+10;
  826.                 else if(s>='a')&&(s<='f')tmp = s-'a'+10;
  827.                 else if(s>='0')&&(s<='9')tmp = s-'0';
  828.                 text++;
  829.                 s = DSBYTE[text];
  830.         }
  831.         return ret;
  832. }
  833.  
  834. inline cdecl int sprintf(dword buf, format,...)
  835. {
  836.         #define END_ARGS 0xFF00FF //ARGS FUNCTION
  837.         byte s;
  838.         char X[10];
  839.         dword ret, tmp, l;
  840.         dword arg = #format;
  841.         ret = buf;
  842.         s = DSBYTE[format];
  843.         while(s){
  844.                 if(s=='%'){
  845.                         arg+=4;
  846.                         tmp = DSDWORD[arg];
  847.                         if(tmp==END_ARGS)goto END_FUNC_SPRINTF;
  848.                         $inc format
  849.                         s = DSBYTE[format];
  850.                         if(!s)goto END_FUNC_SPRINTF;
  851.                         switch(s)
  852.                         {
  853.                                 case 's':
  854.                                         l = tmp;
  855.                                         s = DSBYTE[tmp];
  856.                                         while(s)
  857.                                         {
  858.                                                 DSBYTE[buf] = s;
  859.                                                 $inc tmp
  860.                                                 $inc buf
  861.                                                 s = DSBYTE[tmp];
  862.                                         }
  863.                                 break;
  864.                                 case 'c':
  865.                                         DSBYTE[buf] = tmp;
  866.                                         $inc buf
  867.                                 break;
  868.                                 case 'u': //if(tmp<0)return ret;
  869.                                 case 'd':
  870.                                 case 'i':
  871.                                         tmp = itoa(tmp);
  872.                                         if(!DSBYTE[tmp])goto END_FUNC_SPRINTF;
  873.                                         l = strlen(tmp);
  874.                                         strlcpy(buf,tmp,l);
  875.                                         buf += l;
  876.                                 break;
  877.                                 case 'a':
  878.                                 case 'A':
  879.                                         strlcpy(buf,"0x00000000",10);
  880.                                         buf+=10;
  881.                                         l=buf;
  882.                                         while(tmp)
  883.                                         {
  884.                                                 $dec buf
  885.                                                 s=tmp&0xF;
  886.                                                 if(s>9)DSBYTE[buf]='A'+s-10;
  887.                                                 else DSBYTE[buf]='0'+s;
  888.                                                 tmp>>=4;
  889.                                         }
  890.                                         buf=l;
  891.                                 break;
  892.                                 case 'p':
  893.                                         tmp = itoa(#tmp);
  894.                                         if(!DSBYTE[tmp])goto END_FUNC_SPRINTF;
  895.                                         l = strlen(tmp);
  896.                                         strlcpy(buf,tmp,l);
  897.                                         buf += l;
  898.                                 break;
  899.                                 case '%':
  900.                                         DSBYTE[buf] = '%';
  901.                                         $inc buf
  902.                                 break;
  903.                                 default:
  904.                                 goto END_FUNC_SPRINTF;
  905.                         }
  906.                 }
  907.                 else {
  908.                         DSBYTE[buf] = s;
  909.                         $inc buf
  910.                 }
  911.                 $inc format
  912.                 s = DSBYTE[format];
  913.         }
  914.         END_FUNC_SPRINTF:
  915.         DSBYTE[buf] = 0;
  916.         return ret;
  917. }
  918.  
  919. inline signed strcoll(dword text1,text2)
  920. {
  921.         char s,ss;
  922.         loop()
  923.         {
  924.                 s = DSBYTE[text2];
  925.                 ss=strchr(text1,s);
  926.                 if(ss)return ss;
  927.                 text2++;
  928.         }
  929.         return 0;
  930. }
  931.  
  932. // void * memset( ptr, value, num );
  933. // fills the memory with a dword
  934. // example: memset(str,'-', sizeof(str));
  935. inline void MEMSETD(EDI,ECX,EAX)
  936. {
  937.         $REP
  938.         $STOSD
  939. }
  940.  
  941. :replace_char(dword in_str, char from_char, to_char, int length) {
  942.         dword max = in_str + length;
  943.         while (in_str < max) {
  944.                 if (ESBYTE[in_str] == from_char) ESBYTE[in_str] = to_char;
  945.                 in_str++;
  946.         }
  947. }
  948.  
  949. #endif