Subversion Repositories Kolibri OS

Rev

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