#include "onerror.hpp"


//------------------------- ERROR Module ------------------------//
//						  v 05 . 03 .  2007						 //
//																 //
//								MT								 //
//---------------------------------------------------------------//


	// --- CError :: OnError ---
void CError :: OnError(char *s, int num, bool _continue)  {
  
	last_error_text = strdup(s);
	number = num;

	printf("\n\n~Error: %s :: %d", s, num);
	
		if (_continue) return;

	printf("\n~Try to continue (may be errors)? [y/n]");
	if ( getchar() != 'y') exit(number);
};


void CError :: OnQuietError(int num)  {
  
	last_error_text = strdup("QUIET");
	number = num;
};



void CError :: OnError(char *s1, const char *s2, int num)
{
	char *res = new char [strlen(s1) + strlen(s2)+1];
		strcpy(res, s1);
		strcat(res, s2);
	delete [] res;
	
	OnError(res, num);
};


void CError :: Gum(const char *s)
{
	char *res = new char [strlen(last_error_text) + strlen(s)+1];
		strcpy(res, last_error_text);
		strcat(res, s);
		last_error_text = strdup(res);
	delete [] res;
};


void CError :: ClearLastText()
{
	free(last_error_text);
	last_error_text = (char*) malloc (1);
	(*last_error_text) = '\0';
};


void CError :: OnErrorSpit(int num, bool _continue)
{
	OnError(last_error_text, num, _continue);
};



