Advertisement
ZoriaRPG

TraceError() with printf style insertions

Nov 13th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. void TraceError(int s, int v)
  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.     }
  9.     //Now, we found an insertion token, so insert it
  10.    
  11.         //if ( s[string_pos] != '%' ) //copy the buffer text over to the buffer, until we find our token
  12.         //{
  13.         //  main_buf[buffer_pos] = s[string_pos];
  14.         //  ++buffer_pos;
  15.         //}
  16.         //else //found a special token
  17.         //{
  18.     switch(s[string_pos+1])
  19.     {
  20.         case s:
  21.         {
  22.             ++buffer_pos;
  23.             main_buf[buffer_pos+q+1] = ' '; //add a trailing space
  24.             for ( q = 0; v[q]; ++q ) //until we reach NULL
  25.             {
  26.                 main_buf[buffer_pos+q] = v[q];  //copy the string passed as a param
  27.                                 //over to the buffer
  28.             }
  29.             ++buffer_pos;
  30.             main_buf[buffer_pos+q+1] = ' '; //add a trailing space
  31.             ++buffer_pos; //set up the buffer for the next char
  32.             break;
  33.                
  34.         }
  35.         case f:
  36.         {
  37.             ++buffer_pos;
  38.             main_buf[buffer_pos+q+1] = ' '; //add a trailing space
  39.             int i_val[12];
  40.             ftoa(i_val,v);
  41.             for ( q = 0; i_val[q]; ++q )
  42.             {
  43.                 main_buf[buffer_pos+q] = i_val[q];
  44.             }
  45.             main_buf[buffer_pos+q+1] = ' '; //add a trailing space
  46.             ++buffer_pos; //set up the buffer for the next char
  47.             break;
  48.  
  49.         }
  50.         case d:
  51.         {
  52.             ++buffer_pos;
  53.             main_buf[buffer_pos+q+1] = ' '; //add a trailing space
  54.             int f_val[12];
  55.             itoa(f_val,v);
  56.             for ( q = 0; f_val[q] ; ++q )
  57.             {
  58.                 main_buf[buffer_pos+q] = f_val[q];
  59.             }
  60.             main_buf[buffer_pos+q+1] = ' '; //add a trailing space
  61.             ++buffer_pos; //set up the buffer for the next char
  62.             break;
  63.  
  64.         }
  65.         default: ++buffer_pos; break;
  66.     }
  67.     //we copied the insertion, so, resume the rest o the string:
  68.     for ( ; s[string_pos]; ++string_pos ) //Until we reach NULL
  69.     {
  70.         //copy the rest of the string:
  71.         main_buf[buffer_pos] = s[string_pos];
  72.     }
  73.         TraceS(main_buf); TraceNL();
  74.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement