Subversion Repositories Kolibri OS

Rev

Rev 7749 | Rev 7752 | 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]) dst++;
  401.         while (ESBYTE[src]) && (len) {
  402.                 ESBYTE[dst] = ESBYTE[src];
  403.                 dst++;
  404.                 src++;
  405.                 len--;
  406.         }
  407. }
  408.  
  409. inline fastcall void chrcat(ESI, DI)
  410. {
  411.     while (ESBYTE[ESI]) ESI++;
  412.     ESBYTE[ESI] = DI;
  413.     ESI++;
  414.     ESBYTE[ESI] = 0;
  415. }
  416.  
  417. inline dword strchr(dword shb;char s)
  418. {
  419.         char ss;
  420.         loop()
  421.         {
  422.                 ss = DSBYTE[shb];
  423.                 if(!ss)return 0;
  424.                 if(ss==s)return shb;
  425.                 shb++;
  426.         }
  427. }
  428.  
  429. inline fastcall signed int strrchr( ESI,BL)
  430. {
  431.     int jj=0, last=0;
  432.     do{
  433.         jj++;
  434.         $lodsb
  435.         IF(AL==BL) last=jj;
  436.     } while(AL!=0);
  437.     return last;
  438. }
  439.  
  440.  
  441. inline fastcall unsigned int chrnum( ESI, BL)
  442. {
  443.     int num = 0;
  444.     while(DSBYTE[ESI])
  445.     {
  446.         if (DSBYTE[ESI] == BL) num++;
  447.         ESI++;
  448.     }
  449.     return num;
  450. }
  451.  
  452.  
  453. inline fastcall signed int strstr( EBX, EDX)
  454. {
  455.   asm {
  456.     MOV EDI, EDX
  457.     XOR ECX, ECX
  458.     XOR EAX, EAX
  459.     DEC ECX
  460.     REPNE SCASB
  461.     NOT ECX
  462.     DEC ECX
  463.     JE LS2
  464.     MOV ESI, ECX
  465.     XOR ECX, ECX
  466.     MOV EDI, EBX
  467.     DEC ECX
  468.     REPNE SCASB
  469.     NOT ECX
  470.     SUB ECX, ESI
  471.     JBE LS2
  472.     MOV EDI, EBX
  473.     LEA EBX, DSDWORD[ ESI-1]
  474. LS1: MOV ESI, EDX
  475.     LODSB
  476.     REPNE SCASB
  477.     JNE LS2
  478.     MOV EAX, ECX
  479.     PUSH EDI
  480.     MOV ECX, EBX
  481.     REPE CMPSB
  482.     POP EDI
  483.     MOV ECX, EAX
  484.     JNE LS1
  485.     LEA EAX, DSDWORD[ EDI-1]
  486.     JMP SHORT LS3
  487. LS2: XOR EAX, EAX
  488. LS3:
  489.   }
  490. }
  491.  
  492. inline dword strcmpi(dword cmp1, cmp2)
  493. {
  494.     char si, ue;
  495.  
  496.     loop()
  497.     {
  498.         si = DSBYTE[cmp1];
  499.         ue = DSBYTE[cmp2];
  500.         if (si>='A') && (si<='Z') si +=32;
  501.         if (ue>='A') && (ue<='Z') ue +=32;
  502.         if (si != ue) return -1;
  503.         cmp1++;
  504.         cmp2++;
  505.         if ((DSBYTE[cmp1]=='\0') && (DSBYTE[cmp2]=='\0')) return 0;
  506.         if (DSBYTE[cmp1]=='\0') return -1;
  507.         if (DSBYTE[cmp2]=='\0') return 1;
  508.     }
  509. }
  510.  
  511. inline dword strstri(dword searchin, usestr_s)
  512. {
  513.     dword usestr_e = usestr_s;
  514.     char si, ue;
  515.  
  516.     while(DSBYTE[searchin])
  517.     {
  518.         si = DSBYTE[searchin];
  519.         ue = DSBYTE[usestr_e];
  520.         if (si>='A') && (si<='Z') si +=32;
  521.         if (ue>='A') && (ue<='Z') ue +=32;
  522.         if (si == ue) usestr_e++; else usestr_e = usestr_s;
  523.         searchin++;
  524.         if (DSBYTE[usestr_e]=='\0') return searchin;
  525.     }
  526.     return -1;
  527. }
  528.  
  529.  
  530. inline unsigned int strcpyb(dword search_in, copyin, startstr, endstr)
  531. {
  532.     dword startp, endp;
  533.     dword copyin_start_off = copyin;
  534.     if (startstr==0) startp = search_in; else startp = strstr(search_in, startstr) + strlen(startstr);
  535.     endp = strstri(startp, endstr);
  536.     if (endp==0) endp = startp+strlen(search_in);
  537.     //if (startp==endp) return 0;
  538.     do
  539.     {
  540.         DSBYTE[copyin] = DSBYTE[startp];
  541.         copyin++;
  542.         startp++;
  543.     }
  544.     while (startp<endp);
  545.     DSBYTE[copyin] = '\0';
  546.     return copyin_start_off;
  547. }
  548.  
  549.  
  550. /*void strcat(char *to, char *from)
  551. {
  552.     while(*to) to++;
  553.     while(*from)
  554.     {
  555.         *to = *from;
  556.         to++;
  557.         from++;
  558.     }
  559.     *to = '\0';
  560. }*/
  561.  
  562.  
  563. inline fastcall dword atoi( EDI)
  564. {
  565.     $push ebx
  566.     $push esi
  567.     ESI=EDI;
  568.     while (DSBYTE[ESI]==' ') ESI++;
  569.     if (DSBYTE[ESI]=='-') ESI++;
  570.     EAX=0;
  571.     while (DSBYTE[ESI]>='0') && (DSBYTE[ESI]<='9')
  572.     {
  573.         $xor ebx, ebx
  574.         EBX = DSBYTE[ESI]-'0';
  575.         EAX *= 10;
  576.         EAX += EBX;
  577.         ESI++;
  578.     }
  579.     IF (DSBYTE[EDI]=='-') -EAX;
  580.     $pop esi
  581.     $pop ebx
  582. }
  583.  
  584.  
  585.  
  586. inline fastcall strupr( ESI)
  587. {
  588.     do{
  589.         AL=DSBYTE[ESI];
  590.         IF(AL>='a')IF(AL<='z')DSBYTE[ESI]=AL&0x5f;
  591.         IF (AL>=160) && (AL<=175) DSBYTE[ESI] = AL - 32;    //à-ï
  592.         IF (AL>=224) && (AL<=239) DSBYTE[ESI] = AL - 80;    //à-ï
  593.          ESI++;
  594.     }while(AL!=0);
  595. }
  596.  
  597. inline fastcall strlwr( ESI)
  598. {
  599.     do{
  600.         $LODSB
  601.         IF(AL>='A')&&(AL<='Z'){
  602.             AL+=0x20;
  603.             DSBYTE[ESI-1]=AL;
  604.             CONTINUE;
  605.         }
  606.     }while(AL!=0);
  607. }
  608.  
  609. inline fastcall strttl( EDX)
  610. {
  611.     AL=DSBYTE[EDX];
  612.     IF(AL>='a')&&(AL<='z')DSBYTE[EDX]=AL&0x5f;
  613.     IF (AL>=160) && (AL<=175) DSBYTE[EDX] = AL - 32;    //à-ï
  614.     IF (AL>=224) && (AL<=239) DSBYTE[EDX] = AL - 80;    //à-ï
  615.     do{
  616.         EDX++;
  617.         AL=DSBYTE[EDX];
  618.         IF(AL>='A')&&(AL<='Z'){DSBYTE[EDX]=AL|0x20; CONTINUE;}
  619.         IF(AL>='€')&&(AL<='')DSBYTE[EDX]=AL|0x20; // -¯
  620.         IF (AL>=144) && (AL<=159) DSBYTE[EDX] = AL + 80;    //à-ï
  621.     }while(AL!=0);
  622. }
  623.  
  624. /*
  625. dword itoa( ESI)
  626. {
  627.     unsigned char buffer[11];
  628.     $pusha
  629.     EDI = #buffer;
  630.     ECX = 10;
  631.     if (ESI < 0)
  632.     {
  633.          $mov     al, '-'
  634.          $stosb
  635.          $neg     esi
  636.     }
  637.  
  638.     $mov     eax, esi
  639.     $push    -'0'
  640. F2:
  641.     $xor     edx, edx
  642.     $div     ecx
  643.     $push    edx
  644.     $test    eax, eax
  645.     $jnz     F2
  646. F3:
  647.     $pop     eax
  648.     $add     al, '0'
  649.     $stosb
  650.     $jnz     F3
  651.    
  652.     $mov     al, '\0'
  653.     $stosb
  654.  
  655.     $popa
  656.     return #buffer;
  657. }
  658. */
  659. :unsigned char BUF_ITOA[11];
  660. inline dword itoa(signed long number)
  661. {
  662.         dword ret,p;
  663.         byte cmd;
  664.         long mask,tmp;
  665.         mask = 1000000000;
  666.         cmd = true;
  667.         p = #BUF_ITOA;
  668.         if(!number){
  669.                 ESBYTE[p] = '0';
  670.                 ESBYTE[p+1] = 0;
  671.                 return p;
  672.         }
  673.         ret = p;
  674.         if(number<0)
  675.         {
  676.                 $neg number
  677.                 ESBYTE[p] = '-';
  678.                 $inc p
  679.         }
  680.         while(mask)
  681.         {
  682.                 tmp = number / mask;
  683.                 tmp = tmp%10;
  684.                
  685.                 if(cmd){
  686.                         if(tmp){
  687.                                 ESBYTE[p] = tmp + '0';
  688.                                 $inc p
  689.                                 cmd = false;
  690.                         }
  691.                 }
  692.                 else {
  693.                         ESBYTE[p] = tmp + '0';
  694.                         $inc p
  695.                 }
  696.                 mask /= 10;
  697.         }
  698.         ESBYTE[p] = 0;
  699.         return ret;
  700. }
  701.  
  702. inline fastcall itoa_(signed int EDI, ESI)
  703. {
  704.     $pusha
  705.     EBX = EDI;
  706.     ECX = 10;
  707.     if (ESI > 90073741824)
  708.     {
  709.          $mov     al, '-'
  710.          $stosb
  711.          $neg     esi
  712.     }
  713.  
  714.     $mov     eax, esi
  715.     $push    -'0'
  716. F2:
  717.     $xor     edx, edx
  718.     $div     ecx
  719.     $push    edx
  720.     $test    eax, eax
  721.     $jnz     F2
  722. F3:
  723.     $pop     eax
  724.     $add     al, '0'
  725.     $stosb
  726.     $jnz     F3
  727.    
  728.     $mov     al, '\0'
  729.     $stosb
  730.  
  731.     $popa
  732.     return EBX;
  733. }
  734.  
  735. inline dword memchr(dword s,int c,signed len)
  736. {
  737.         if(!len) return NULL;
  738.         do {
  739.                 if(DSBYTE[s] == c) return s;
  740.                 $inc s
  741.                 $dec len
  742.         } while(len);
  743.         return NULL;
  744. }
  745.  
  746. inline dword strdup(dword text)
  747. {
  748.     dword l = strlen(text);
  749.     dword ret = malloc(l+1);
  750.         if(!ret) return NULL;
  751.     strlcpy(ret,text,l);
  752.     return ret;
  753. }
  754.  
  755. inline dword strndup(dword str, signed maxlen)
  756. {
  757.         dword copy,len;
  758.  
  759.         len = strnlen(str, maxlen);
  760.         copy = malloc(len + 1);
  761.         if (copy != NULL)
  762.         {
  763.                 strlcpy(copy, str, len);
  764.                 DSBYTE[len+copy] = '\0';
  765.         }
  766.         return copy;
  767. }
  768.  
  769. inline dword hexdec(dword text)
  770. {
  771.         char s;
  772.         dword ret,l;
  773.         ret = 0;
  774.         s = DSBYTE[text];
  775.         while(s)
  776.         {      
  777.                 ret <<= 4;
  778.                 if(s>='A')&&(s<='F')ret |= s-'A'+10;
  779.                 else if(s>='a')&&(s<='f')ret |= s-'a'+10;
  780.                 else if(s>='0')&&(s<='9')ret |= s-'0';
  781.                 text++;
  782.                 s = DSBYTE[text];
  783.         }
  784.         return ret;
  785. }
  786.  
  787. inline signed csshexdec(dword text)
  788. {
  789.         char s;
  790.         dword ret,l;
  791.         byte tmp;
  792.         l = strlen(text);
  793.         ret = 0;
  794.         s = DSBYTE[text];
  795.         tmp = 0;
  796.         if(l==6) while(s)
  797.         {      
  798.                 ret <<= 4;
  799.                 if(s>='A')&&(s<='F')ret |= s-'A'+10;
  800.                 else if(s>='a')&&(s<='f')ret |= s-'a'+10;
  801.                 else if(s>='0')&&(s<='9')ret |= s-'0';
  802.                 text++;
  803.                 s = DSBYTE[text];
  804.         }
  805.         else if(l==3) while(s)
  806.         {      
  807.                 ret |= tmp;
  808.                 ret <<= 4;
  809.                 ret |= tmp;
  810.                 ret <<= 4;
  811.                 if(s>='A')&&(s<='F')tmp = s-'A'+10;
  812.                 else if(s>='a')&&(s<='f')tmp = s-'a'+10;
  813.                 else if(s>='0')&&(s<='9')tmp = s-'0';
  814.                 text++;
  815.                 s = DSBYTE[text];
  816.         }
  817.         return ret;
  818. }
  819.  
  820. inline cdecl int sprintf(dword buf, format,...)
  821. {
  822.         #define END_ARGS 0xFF00FF //ARGS FUNCTION
  823.         byte s;
  824.         char X[10];
  825.         dword ret, tmp, l;
  826.         dword arg = #format;
  827.         ret = buf;
  828.         s = DSBYTE[format];
  829.         while(s){
  830.                 if(s=='%'){
  831.                         arg+=4;
  832.                         tmp = DSDWORD[arg];
  833.                         if(tmp==END_ARGS)goto END_FUNC_SPRINTF;
  834.                         $inc format
  835.                         s = DSBYTE[format];
  836.                         if(!s)goto END_FUNC_SPRINTF;
  837.                         switch(s)
  838.                         {
  839.                                 case 's':
  840.                                         l = tmp;
  841.                                         s = DSBYTE[tmp];
  842.                                         while(s)
  843.                                         {
  844.                                                 DSBYTE[buf] = s;
  845.                                                 $inc tmp
  846.                                                 $inc buf
  847.                                                 s = DSBYTE[tmp];
  848.                                         }
  849.                                 break;
  850.                                 case 'c':
  851.                                         DSBYTE[buf] = tmp;
  852.                                         $inc buf
  853.                                 break;
  854.                                 case 'u': //if(tmp<0)return ret;
  855.                                 case 'd':
  856.                                 case 'i':
  857.                                         tmp = itoa(tmp);
  858.                                         if(!DSBYTE[tmp])goto END_FUNC_SPRINTF;
  859.                                         l = strlen(tmp);
  860.                                         strlcpy(buf,tmp,l);
  861.                                         buf += l;
  862.                                 break;
  863.                                 case 'a':
  864.                                 case 'A':
  865.                                         strlcpy(buf,"0x00000000",10);
  866.                                         buf+=10;
  867.                                         l=buf;
  868.                                         while(tmp)
  869.                                         {
  870.                                                 $dec buf
  871.                                                 s=tmp&0xF;
  872.                                                 if(s>9)DSBYTE[buf]='A'+s-10;
  873.                                                 else DSBYTE[buf]='0'+s;
  874.                                                 tmp>>=4;
  875.                                         }
  876.                                         buf=l;
  877.                                 break;
  878.                                 case 'p':
  879.                                         tmp = itoa(#tmp);
  880.                                         if(!DSBYTE[tmp])goto END_FUNC_SPRINTF;
  881.                                         l = strlen(tmp);
  882.                                         strlcpy(buf,tmp,l);
  883.                                         buf += l;
  884.                                 break;
  885.                                 case '%':
  886.                                         DSBYTE[buf] = '%';
  887.                                         $inc buf
  888.                                 break;
  889.                                 default:
  890.                                 goto END_FUNC_SPRINTF;
  891.                         }
  892.                 }
  893.                 else {
  894.                         DSBYTE[buf] = s;
  895.                         $inc buf
  896.                 }
  897.                 $inc format
  898.                 s = DSBYTE[format];
  899.         }
  900.         END_FUNC_SPRINTF:
  901.         DSBYTE[buf] = 0;
  902.         return ret;
  903. }
  904.  
  905. inline signed strcoll(dword text1,text2)
  906. {
  907.         char s,ss;
  908.         loop()
  909.         {
  910.                 s = DSBYTE[text2];
  911.                 ss=strchr(text1,s);
  912.                 if(ss)return ss;
  913.                 text2++;
  914.         }
  915.         return 0;
  916. }
  917.  
  918. :replace_char(dword in_str, char from_char, to_char, int length) {
  919.         int i;
  920.         for (i=0; i<length; i++) {
  921.                 if (ESBYTE[in_str+i] == from_char) ESBYTE[in_str+i] = to_char;
  922.         }
  923.         ESBYTE[in_str+length]=0;
  924. }
  925.  
  926. #endif