Subversion Repositories Kolibri OS

Rev

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