Subversion Repositories Kolibri OS

Rev

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