Advertisement
ZoriaRPG

Parser bugs

Nov 13th, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. void print(int s, int v1, int v2) //what if we use an array literal for the inputs?. No, then we still don't have overloaded strings
  2. {
  3.     int main_buf[2048];
  4.     int buffer_pos; int string_pos; int q;
  5.     for ( ; s[string_pos] != '%'; ++string_pos )
  6.     {
  7.         main_buf[buffer_pos] = s[string_pos];
  8.         ++buffer_pos;
  9.     }
  10.    
  11.     int values[]={v1,v2};
  12.     int val_index = 0;
  13.     do
  14.     {
  15.         TraceS("Val index is: "); Trace(values[val_index]); TraceNL();
  16.         switch(s[string_pos+1])
  17.         {
  18.             case 'S':
  19.             case 's':
  20.             {
  21.                 int ptr = values[val_index];
  22.                 //for ( q = 0; (values[val_index[q]]); ++q ) //until we reach NULL
  23.                 for ( q = 0; ptr[q]; ++q ) //until we reach NULL
  24.                 {
  25.                     main_buf[buffer_pos] = values[val_index[q]];    //copy the string passed as a param
  26.                                     //over to the buffer
  27.                     ++buffer_pos;
  28.                    
  29.                 }
  30.                 ++string_pos;
  31.                 ++string_pos;
  32.                 break;
  33.                    
  34.             }
  35.             case 'F':
  36.             case 'f':
  37.             {
  38.                 int i_val[12];
  39.                 ftoa(i_val,values[val_index]);
  40.                 for ( q = 0; (i_val[q]); ++q ) //until we reach NULL
  41.                 {
  42.                     main_buf[buffer_pos] = i_val[q];
  43.                     ++buffer_pos;
  44.                 }
  45.                 ++string_pos;
  46.                 ++string_pos;
  47.                 break;
  48.  
  49.             }
  50.             case 'D':
  51.             case 'd':
  52.             {
  53.                 int f_val[12];
  54.                 itoa(f_val,values[val_index]);
  55.                 for ( q = 0; (f_val[q]); ++q )
  56.                 {
  57.                     main_buf[buffer_pos] = f_val[q];
  58.                     ++buffer_pos;
  59.                 }
  60.                 TraceS(f_val);
  61.                 ++string_pos;
  62.                 ++string_pos;
  63.            
  64.                 break;
  65.  
  66.             }
  67.             default: ++buffer_pos; break;
  68.         }
  69.         //we copied the insertion, so, resume the rest o the string:
  70.         for ( ; s[string_pos] != '%'; ++string_pos ) //Until we reach NULL
  71.         {
  72.             //copy the rest of the string:
  73.             main_buf[buffer_pos] = s[string_pos];
  74.             ++buffer_pos;
  75.         }
  76.         //for some reason, placing this here, val_index == 5 ?!
  77.         ++val_index; //increase for overloads
  78.        
  79.     }while(false);
  80.     //while((s[string_pos])); //until we reach null in the main buffer
  81.    
  82.         TraceS(main_buf); //TraceNL();
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement