Subversion Repositories Kolibri OS

Rev

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