Subversion Repositories Kolibri OS

Rev

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