Advertisement
garfield

[COD]: SuYaNw's SCANF (developing)

Oct 14th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.05 KB | None | 0 0
  1. #define unformat(%0) strdel(%0, 0, strfind(%0, " ") + 1)
  2. stock scanf(string[], formatype[], {Float,_}:...){
  3.  
  4.  
  5.     if(string[0] == EOS || formatype[0] == EOS)
  6.         return true;
  7.  
  8.  
  9.     #if !defined int
  10.         #define int::<%0> static %0; %0 = 0
  11.         #define char::<%0><%1> static %0[%1]; %0[0] = '\0'
  12.         #define RESETSTR(%0) %0[0] = '\0'
  13.     #endif
  14.  
  15.  
  16.     #define idx      (0)
  17.  
  18.  
  19.     int::<_per>;
  20.     int::<_arg>;
  21.    
  22.     char::<_sval><128>;
  23.    
  24.    
  25.     for(_per = -1, _arg = 2; (formatype[++_per] ^ '\0'); ){
  26.  
  27.         _arg = (!_per) ? ( 2 ) : (_arg + 1);
  28.         switch(formatype[_per]){
  29.  
  30.             case 'i', 'd':
  31.             {
  32.                 new _finded = strfind(string, " ");
  33.                
  34.  
  35.                 if(_finded != -1){
  36.                
  37.                     strmid(_sval, string, 0, _finded);
  38.  
  39.  
  40.  
  41.                     strdel(string, 0, _finded + 1);
  42.                 }else{
  43.                     format(_sval, 128, string);
  44.                 }
  45.                
  46.                 setarg(_arg, idx, strval(_sval));
  47.             }
  48.  
  49.             case 's': // strings textos
  50.             {
  51.                 for(new i; string[i]; ++i){
  52.                     setarg(_arg, i, string[i]);
  53.                 }
  54.             }
  55.         }
  56.     }
  57.     return false;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement