Subversion Repositories Kolibri OS

Rev

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