/*----------------------------------------------------------------------------*-
					==============================
					Y Sever Includes - Debug Setup
					==============================
Description:
	Ensures debug levels are set and defines debug functions.
	
	General debug levels:
	
	0 - No debug information.
	1 - Callbacks start and finish.
	2 - Major functions called.
	3 - Major control flow.
	4 - Minor control flow/functions.
	5 - Code steps.
Legal:
	Copyright (C) 2007 Alex "Y_Less" Cole

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
	MA 02110-1301, USA.
Version:
	0.1
Changelog:
	15/04/07:
		First version.
Functions:
	Public:
		-
	Core:
		-
	Stock:
		-
	Static:
		-
	Inline:
		Debug_Code - Runs defined code if a certain level is active.
		Debug_Print - Prints the formatted string provided at the given level.
	API:
		-
Callbacks:
	-
Definitions:
	DBGP - Simple Debug_Print_ wrapper.
	DBGC - Simple Debug_Code_ wrapper.
Enums:
	-
Macros:
	-
Tags:
	-
Variables:
	Global:
		-
	Static:
		-
Commands:
	-
Compile options:
	_DEBUG - Debugging level to use.
Operators:
	-
-*----------------------------------------------------------------------------*/

#if !defined _DEBUG
	#define _DEBUG 0
#endif

/*----------------------------------------------------------------------------*-
Function:
	Debug_Code
Params:
	level - Debug level to run the code at.
	code - Code to run.
Return:
	-
Notes:
	Code is not a variable, it's a code chunk and may be written as so:
	
	Debug_Code_1(if (bla == 2) { bla++; printf("%d", bla); });
	
	The code must all be on one line to avoid errors.
	This isn't really a function as the first parameter is part of the name.
-*----------------------------------------------------------------------------*/

#define DBGC1 Debug_Code_1
#define DBGC2 Debug_Code_2
#define DBGC3 Debug_Code_3
#define DBGC4 Debug_Code_4
#define DBGC5 Debug_Code_5

#if _DEBUG >= 1
	#define Debug_Code_1(%1); \
		%1
#else
	#define Debug_Code_1(%1);
#endif

#if _DEBUG >= 2
	#define Debug_Code_2(%1); \
		%1
#else
	#define Debug_Code_2(%1);
#endif

#if _DEBUG >= 3
	#define Debug_Code_3(%1); \
		%1
#else
	#define Debug_Code_3(%1);
#endif

#if _DEBUG >= 4
	#define Debug_Code_4(%1); \
		%1
#else
	#define Debug_Code_4(%1);
#endif

#if _DEBUG >= 5
	#define Debug_Code_5(%1); \
		%1
#else
	#define Debug_Code_5(%1);
#endif

/*----------------------------------------------------------------------------*-
Function:
	Debug_Print
Params:
	level - Debug level to print at.
	format[] - Format.
	...
Return:
	-
Notes:
	This isn't really a function as the first parameter is part of the name:
	
	Debug_Print_4("variables: %d, %d", i, j);
-*----------------------------------------------------------------------------*/

#define DBGP1 Debug_Print_1
#define DBGP2 Debug_Print_2
#define DBGP3 Debug_Print_3
#define DBGP4 Debug_Print_4
#define DBGP5 Debug_Print_5

#if _DEBUG >= 1
	#define Debug_Print_1(%1); \
		printf(%1);
#else
	#define Debug_Print_1(%1);
#endif

#if _DEBUG >= 2
	#define Debug_Print_2(%1); \
		printf(%1);
#else
	#define Debug_Print_2(%1);
#endif

#if _DEBUG >= 3
	#define Debug_Print_3(%1); \
		printf(%1);
#else
	#define Debug_Print_3(%1);
#endif

#if _DEBUG >= 4
	#define Debug_Print_4(%1); \
		printf(%1);
#else
	#define Debug_Print_4(%1);
#endif

#if _DEBUG >= 5
	#define Debug_Print_5(%1); \
		printf(%1);
#else
	#define Debug_Print_5(%1);
#endif
