Jump to content

Photo

Logging Header


  • Please log in to reply
No replies to this topic

#1 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 13 November 2018 - 07:32 PM

Here's a little logging header for script debugging:
 
/////////////////////////////
/// ZScript Error Logging ///
/// and Debugging -- v0.4 ///
/// 13th November, 2018   ///
/// By: ZoriaRPG          ///
/////////////////////////////

script typedef ffc namespace;

namespace script log
{
	void run()
	{
		print("Testing %s\n","log.print()");
		print("Test Number: %d\n",1);
		
		print("Testing %s, %s \n","log.print()","with iteration.");
		print("Test %s %d \n","Number: ",2);
		
	}

void print(int s, int v) //what if we use an array literal for the inputs?. No, then we still don't have overloaded strings
{
	int main_buf[2048];
	int buffer_pos; int string_pos; int q;
	for ( ; s[string_pos] != '%'; ++string_pos )
	{
		main_buf[buffer_pos] = s[string_pos]; //copy until we reach %
		++buffer_pos; //we increment both iterators
	}
	//Now, we found an insertion token, so insert it
	
		//if ( s[string_pos] != '%' ) //copy the buffer text over to the buffer, until we find our token
		//{
		//	main_buf[buffer_pos] = s[string_pos];
		//	++buffer_pos; 
		//}
		//else //found a special token
		//{
	switch(s[string_pos+1]) //read ahead, one vhar beyond '%'
	{
		case 'S':
		case 's':
		{
			//++buffer_pos; //skip over the token
			//main_buf[buffer_pos+q+1] = ' '; //add a trailing space
			for ( q = 0; v[q]; ++q ) //until we reach NULL, imnsert the substring
			{
				main_buf[buffer_pos] = v[q]; 	//copy the string passed as a param
								//over to the buffer
				++buffer_pos; 
			}
			
			//main_buf[buffer_pos+q+1] = ' '; //add a trailing space
			//++buffer_pos; //set up the buffer for the next char
			++string_pos;
			++string_pos;
			break;
				
		}
		case 'F':
		case 'f':
		{
			//++buffer_pos; //skip over the token
			//main_buf[buffer_pos+q+1] = ' '; //add a trailing space
			int i_val[12];
			ftoa(i_val,v);
			for ( q = 0; i_val[q]; ++q )
			{
				main_buf[buffer_pos] = i_val[q];
				++buffer_pos;
			}
			//main_buf[buffer_pos+q+1] = ' '; //add a trailing space
			//++buffer_pos; //set up the buffer for the next char
			++string_pos;
			++string_pos;
			break;

		}
		case 'D':
		case 'd':
		{
			//++buffer_pos; 
			//main_buf[buffer_pos+q+1] = ' '; //add a trailing space
			int f_val[12];
			itoa(f_val,v);
			for ( q = 0; f_val[q] != 0; ++q )
			{
				main_buf[buffer_pos] = f_val[q];
				++buffer_pos;
			}
			//main_buf[buffer_pos+q+1] = ' '; //add a trailing space
			//++buffer_pos; //set up the buffer for the next char
			++string_pos;
			++string_pos;
			break;

		}
		default: ++buffer_pos; break;
	}
	//we copied the insertion, so, resume the rest o the string:
	for ( ; s[string_pos]; ++string_pos ) //Until we reach NULL
	{
		//copy the rest of the string:
		main_buf[buffer_pos] = s[string_pos];
		++buffer_pos;
	}
	//main_buf[buffer_pos+1] = '\n'; Put this in the string!
        TraceS(main_buf); //TraceNL();
}
    
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
{
	int main_buf[2048];
	int buffer_pos; int string_pos; int q;
	for ( ; s[string_pos] != '%'; ++string_pos )
	{
		main_buf[buffer_pos] = s[string_pos];
		++buffer_pos;
	}
	
	int values[]={v1,v2};
	int sz = 2;
	int val_index = 0;
	
	do 
	{
		++string_pos;
		//TraceS("Val index is: "); Trace(val_index); TraceNL();
		//Trace(s[string_pos]);
		switch(s[string_pos])
		{
			case 'S':
			case 's':
			{
				int ptr = values[val_index];
				//for ( q = 0; (values[val_index[q]]); ++q ) //until we reach NULL
				for ( q = 0; ptr[q]; ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = ptr[q];
					//values[val_index[q]]; 	//copy the string passed as a param
									//over to the buffer
					++buffer_pos;
					
				}
				++string_pos;
				++string_pos;
				break;
					
			}
			case 'F':
			case 'f':
			{
				int i_val[12];
				ftoa(i_val,values[val_index]);
				for ( q = 0; (i_val[q]); ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = i_val[q];
					++buffer_pos;
				}
				++string_pos;
				++string_pos;
				break;

			}
			case 'D':
			case 'd':
			{
				int f_val[12];
				itoa(f_val,values[val_index]);
				for ( q = 0; (f_val[q]); ++q )
				{
					main_buf[buffer_pos] = f_val[q];
					++buffer_pos;
				}
				//TraceS(f_val);
				++string_pos;
				++string_pos;
				
				break;

			}
			default: return;
		}
		//we copied the insertion, so, resume the rest o the string:
		for ( ; s[string_pos] != '%'; ++string_pos ) //Until we reach NULL
		{
			if (!(s[string_pos])) break;
			//copy the rest of the string:
			main_buf[buffer_pos] = s[string_pos];
			++buffer_pos;
		}
		//Trace(s[string_pos]);
		++val_index; //increase for overloads
		//we are on a token of %
		//++string_pos; //stop forward to the char after %
		
	}while(val_index < sz);
	//}while((s[string_pos])); //until we reach null in the main buffer
	
        TraceS(main_buf); //TraceNL();
}
        
void print(int s, int v1, int v2, int v3) //what if we use an array literal for the inputs?. No, then we still don't have overloaded strings
{
	int main_buf[2048];
	int buffer_pos; int string_pos; int q;
	for ( ; s[string_pos] != '%'; ++string_pos )
	{
		main_buf[buffer_pos] = s[string_pos];
		++buffer_pos;
	}
	
	int values[]={v1,v2,v3};
	int sz = 3;
	int val_index = 0;
	
	do 
	{
		++string_pos;
		switch(s[string_pos])
		{
			case 'S':
			case 's':
			{
				int ptr = values[val_index];
				//for ( q = 0; (values[val_index[q]]); ++q ) //until we reach NULL
				for ( q = 0; ptr[q]; ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = ptr[q];
					//values[val_index[q]]; 	//copy the string passed as a param
									//over to the buffer
					++buffer_pos;
					
				}
				++string_pos;
				++string_pos;
				break;
					
			}
			case 'F':
			case 'f':
			{
				int i_val[12];
				ftoa(i_val,values[val_index]);
				for ( q = 0; (i_val[q]); ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = i_val[q];
					++buffer_pos;
				}
				++string_pos;
				++string_pos;
				break;

			}
			case 'D':
			case 'd':
			{
				int f_val[12];
				itoa(f_val,values[val_index]);
				for ( q = 0; (f_val[q]); ++q )
				{
					main_buf[buffer_pos] = f_val[q];
					++buffer_pos;
				}
				//TraceS(f_val);
				++string_pos;
				++string_pos;
				
				break;

			}
			default: return;
		}
		//we copied the insertion, so, resume the rest o the string:
		for ( ; s[string_pos] != '%'; ++string_pos ) //Until we reach NULL
		{
			if (!(s[string_pos])) break;
			//copy the rest of the string:
			main_buf[buffer_pos] = s[string_pos];
			++buffer_pos;
		}
		++val_index; //increase for overloads
		//we are on a token of %
		
	}while(val_index < sz);
        TraceS(main_buf); //TraceNL();
}
            
void print(int s, int v1, int v2, int v3, int v4) //what if we use an array literal for the inputs?. No, then we still don't have overloaded strings
{
	int main_buf[2048];
	int buffer_pos; int string_pos; int q;
	for ( ; s[string_pos] != '%'; ++string_pos )
	{
		main_buf[buffer_pos] = s[string_pos];
		++buffer_pos;
	}
	
	int values[]={v1,v2,v3,v4};
	int sz = 4;
	int val_index = 0;
	
	do 
	{
		++string_pos;
		switch(s[string_pos])
		{
			case 'S':
			case 's':
			{
				int ptr = values[val_index];
				//for ( q = 0; (values[val_index[q]]); ++q ) //until we reach NULL
				for ( q = 0; ptr[q]; ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = ptr[q];
					//values[val_index[q]]; 	//copy the string passed as a param
									//over to the buffer
					++buffer_pos;
					
				}
				++string_pos;
				++string_pos;
				break;
					
			}
			case 'F':
			case 'f':
			{
				int i_val[12];
				ftoa(i_val,values[val_index]);
				for ( q = 0; (i_val[q]); ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = i_val[q];
					++buffer_pos;
				}
				++string_pos;
				++string_pos;
				break;

			}
			case 'D':
			case 'd':
			{
				int f_val[12];
				itoa(f_val,values[val_index]);
				for ( q = 0; (f_val[q]); ++q )
				{
					main_buf[buffer_pos] = f_val[q];
					++buffer_pos;
				}
				//TraceS(f_val);
				++string_pos;
				++string_pos;
				
				break;

			}
			default: return;
		}
		//we copied the insertion, so, resume the rest o the string:
		for ( ; s[string_pos] != '%'; ++string_pos ) //Until we reach NULL
		{
			if (!(s[string_pos])) break;
			//copy the rest of the string:
			main_buf[buffer_pos] = s[string_pos];
			++buffer_pos;
		}
		++val_index; //increase for overloads
		//we are on a token of %
		
	}while(val_index < sz);
        TraceS(main_buf); //TraceNL();
}
                
void print(int s, int v1, int v2, int v3, int v4, int v5) //what if we use an array literal for the inputs?. No, then we still don't have overloaded strings
{
	int main_buf[2048];
	int buffer_pos; int string_pos; int q;
	for ( ; s[string_pos] != '%'; ++string_pos )
	{
		main_buf[buffer_pos] = s[string_pos];
		++buffer_pos;
	}
	
	int values[]={v1,v2,v3,v4,v5};
	int sz = 5;
	int val_index = 0;
	
	do 
	{
		++string_pos;
		switch(s[string_pos])
		{
			case 'S':
			case 's':
			{
				int ptr = values[val_index];
				//for ( q = 0; (values[val_index[q]]); ++q ) //until we reach NULL
				for ( q = 0; ptr[q]; ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = ptr[q];
					//values[val_index[q]]; 	//copy the string passed as a param
									//over to the buffer
					++buffer_pos;
					
				}
				++string_pos;
				++string_pos;
				break;
					
			}
			case 'F':
			case 'f':
			{
				int i_val[12];
				ftoa(i_val,values[val_index]);
				for ( q = 0; (i_val[q]); ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = i_val[q];
					++buffer_pos;
				}
				++string_pos;
				++string_pos;
				break;

			}
			case 'D':
			case 'd':
			{
				int f_val[12];
				itoa(f_val,values[val_index]);
				for ( q = 0; (f_val[q]); ++q )
				{
					main_buf[buffer_pos] = f_val[q];
					++buffer_pos;
				}
				//TraceS(f_val);
				++string_pos;
				++string_pos;
				
				break;

			}
			default: return;
		}
		//we copied the insertion, so, resume the rest o the string:
		for ( ; s[string_pos] != '%'; ++string_pos ) //Until we reach NULL
		{
			if (!(s[string_pos])) break;
			//copy the rest of the string:
			main_buf[buffer_pos] = s[string_pos];
			++buffer_pos;
		}
		++val_index; //increase for overloads
		//we are on a token of %
		
	}while(val_index < sz);
        TraceS(main_buf); //TraceNL();
}
                    
void print(int s, int v1, int v2, int v3, int v4, int v5, int v6) //what if we use an array literal for the inputs?. No, then we still don't have overloaded strings
{
	int main_buf[2048];
	int buffer_pos; int string_pos; int q;
	for ( ; s[string_pos] != '%'; ++string_pos )
	{
		main_buf[buffer_pos] = s[string_pos];
		++buffer_pos;
	}
	
	int values[]={v1,v2,v3,v4,v5,v6};
	int sz = 6;
	int val_index = 0;
	
	do 
	{
		++string_pos;
		switch(s[string_pos])
		{
			case 'S':
			case 's':
			{
				int ptr = values[val_index];
				//for ( q = 0; (values[val_index[q]]); ++q ) //until we reach NULL
				for ( q = 0; ptr[q]; ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = ptr[q];
					//values[val_index[q]]; 	//copy the string passed as a param
									//over to the buffer
					++buffer_pos;
					
				}
				++string_pos;
				++string_pos;
				break;
					
			}
			case 'F':
			case 'f':
			{
				int i_val[12];
				ftoa(i_val,values[val_index]);
				for ( q = 0; (i_val[q]); ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = i_val[q];
					++buffer_pos;
				}
				++string_pos;
				++string_pos;
				break;

			}
			case 'D':
			case 'd':
			{
				int f_val[12];
				itoa(f_val,values[val_index]);
				for ( q = 0; (f_val[q]); ++q )
				{
					main_buf[buffer_pos] = f_val[q];
					++buffer_pos;
				}
				//TraceS(f_val);
				++string_pos;
				++string_pos;
				
				break;

			}
			default: return;
		}
		//we copied the insertion, so, resume the rest o the string:
		for ( ; s[string_pos] != '%'; ++string_pos ) //Until we reach NULL
		{
			if (!(s[string_pos])) break;
			//copy the rest of the string:
			main_buf[buffer_pos] = s[string_pos];
			++buffer_pos;
		}
		++val_index; //increase for overloads
		//we are on a token of %
		
	}while(val_index < sz);
        TraceS(main_buf); //TraceNL();
}
                        
void print(int s, int v1, int v2, int v3, int v4, int v5, int v6, int v7) //what if we use an array literal for the inputs?. No, then we still don't have overloaded strings
{
	int main_buf[2048];
	int buffer_pos; int string_pos; int q;
	for ( ; s[string_pos] != '%'; ++string_pos )
	{
		main_buf[buffer_pos] = s[string_pos];
		++buffer_pos;
	}
	
	int values[]={v1,v2,v3,v4,v5,v6,v7};
	int sz = 7;
	int val_index = 0;
	
	do 
	{
		++string_pos;
		switch(s[string_pos])
		{
			case 'S':
			case 's':
			{
				int ptr = values[val_index];
				//for ( q = 0; (values[val_index[q]]); ++q ) //until we reach NULL
				for ( q = 0; ptr[q]; ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = ptr[q];
					//values[val_index[q]]; 	//copy the string passed as a param
									//over to the buffer
					++buffer_pos;
					
				}
				++string_pos;
				++string_pos;
				break;
					
			}
			case 'F':
			case 'f':
			{
				int i_val[12];
				ftoa(i_val,values[val_index]);
				for ( q = 0; (i_val[q]); ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = i_val[q];
					++buffer_pos;
				}
				++string_pos;
				++string_pos;
				break;

			}
			case 'D':
			case 'd':
			{
				int f_val[12];
				itoa(f_val,values[val_index]);
				for ( q = 0; (f_val[q]); ++q )
				{
					main_buf[buffer_pos] = f_val[q];
					++buffer_pos;
				}
				//TraceS(f_val);
				++string_pos;
				++string_pos;
				
				break;

			}
			default: return;
		}
		//we copied the insertion, so, resume the rest o the string:
		for ( ; s[string_pos] != '%'; ++string_pos ) //Until we reach NULL
		{
			if (!(s[string_pos])) break;
			//copy the rest of the string:
			main_buf[buffer_pos] = s[string_pos];
			++buffer_pos;
		}
		++val_index; //increase for overloads
		//we are on a token of %
		
	}while(val_index < sz);
        TraceS(main_buf); //TraceNL();
}
                            
void print(int s, int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8) //what if we use an array literal for the inputs?. No, then we still don't have overloaded strings
{
	int main_buf[2048];
	int buffer_pos; int string_pos; int q;
	for ( ; s[string_pos] != '%'; ++string_pos )
	{
		main_buf[buffer_pos] = s[string_pos];
		++buffer_pos;
	}
	
	int values[]={v1,v2,v3,v4,v5,v6,v7,v8};
	int sz = 8;
	int val_index = 0;
	
	do 
	{
		++string_pos;
		switch(s[string_pos])
		{
			case 'S':
			case 's':
			{
				int ptr = values[val_index];
				//for ( q = 0; (values[val_index[q]]); ++q ) //until we reach NULL
				for ( q = 0; ptr[q]; ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = ptr[q];
					//values[val_index[q]]; 	//copy the string passed as a param
									//over to the buffer
					++buffer_pos;
					
				}
				++string_pos;
				++string_pos;
				break;
					
			}
			case 'F':
			case 'f':
			{
				int i_val[12];
				ftoa(i_val,values[val_index]);
				for ( q = 0; (i_val[q]); ++q ) //until we reach NULL
				{
					main_buf[buffer_pos] = i_val[q];
					++buffer_pos;
				}
				++string_pos;
				++string_pos;
				break;

			}
			case 'D':
			case 'd':
			{
				int f_val[12];
				itoa(f_val,values[val_index]);
				for ( q = 0; (f_val[q]); ++q )
				{
					main_buf[buffer_pos] = f_val[q];
					++buffer_pos;
				}
				//TraceS(f_val);
				++string_pos;
				++string_pos;
				
				break;

			}
			default: return;
		}
		//we copied the insertion, so, resume the rest o the string:
		for ( ; s[string_pos] != '%'; ++string_pos ) //Until we reach NULL
		{
			if (!(s[string_pos])) break;
			//copy the rest of the string:
			main_buf[buffer_pos] = s[string_pos];
			++buffer_pos;
		}
		++val_index; //increase for overloads
		//we are on a token of %
		
	}while(val_index < sz);
        TraceS(main_buf); //TraceNL();
}

}//end namespace



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users