//////////////////////////////////////////////////////////////////////
//
//                             Pixie
//
// Copyright © 1999 - 2003, Okan Arikan
//
// Contact: okan@cs.berkeley.edu
//
// This library 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 library 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 library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
//
//  File				:	error.cpp
//  Classes				:	-
//  Description			:	The error display functions
//
////////////////////////////////////////////////////////////////////////
#include <stdarg.h>

#include "common/os.h"
#include "error.h"
#include "ri.h"
#include "riInterface.h"

///////////////////////////////////////////////////////////////////////
// Function				:	translate
// Description			:	Translate an error code
// Return Value			:
// Comments				:
// Date last edited		:	6/10/2003
static	int	translate(EErrorCode c) {
	int	code;

	switch(c) {
	case CODE_NOERROR:
		code	=	RIE_NOERROR;
		break;
	case CODE_NOMEM:
		code	=	RIE_NOMEM;
		break;
	case CODE_SYSTEM:
		code	=	RIE_SYSTEM;
		break;
	case CODE_NOFILE:
		code	=	RIE_NOFILE;
		break;
	case CODE_BADFILE:
		code	=	RIE_BADFILE;
		break;
	case CODE_VERSION:
		code	=	RIE_VERSION;
		break;
	case CODE_INCAPABLE:
		code	=	RIE_INCAPABLE;
		break;
	case CODE_OPTIONAL:
		code	=	RIE_OPTIONAL;
		break;
	case CODE_UNIMPLEMENT:
		code	=	RIE_UNIMPLEMENT;
		break;
	case CODE_LIMIT:
		code	=	RIE_LIMIT;
		break;
	case CODE_BUG:
		code	=	RIE_BUG;
		break;
	case CODE_NOTSTARTED:
		code	=	RIE_NOTSTARTED;
		break;
	case CODE_NESTING:
		code	=	RIE_NESTING;
		break;
	case CODE_NOTOPTIONS:
		code	=	RIE_NOTOPTIONS;
		break;
	case CODE_NOTATTRIBS:
		code	=	RIE_NOTATTRIBS;
		break;
	case CODE_NOTPRIMS:
		code	=	RIE_NOTPRIMS;
		break;
	case CODE_ILLSTATE:
		code	=	RIE_ILLSTATE;
		break;
	case CODE_BADMOTION:
		code	=	RIE_BADMOTION;
		break;
	case CODE_BADSOLID:
		code	=	RIE_BADSOLID;
		break;
	case CODE_BADTOKEN:
		code	=	RIE_BADTOKEN;
		break;
	case CODE_RANGE:
		code	=	RIE_RANGE;
		break;
	case CODE_CONSISTENCY:
		code	=	RIE_CONSISTENCY;
		break;
	case CODE_BADHANDLE:
		code	=	RIE_BADHANDLE;
		break;
	case CODE_NOSHADER:
		code	=	RIE_NOSHADER;
		break;
	case CODE_MISSINGDATA:
		code	=	RIE_MISSINGDATA;
		break;
	case CODE_SYNTAX:
		code	=	RIE_SYNTAX;
		break;
	case CODE_MATH:
		code	=	RIE_MATH;
		break;
	case CODE_LOG:
		code	=	RIE_LOG;
		break;
	case CODE_SCRIPT:
		code	=	RIE_SCRIPT;
		break;
	case CODE_PRINTF:
		code	=	RIE_PRINTF;
		break;
	case CODE_RESOLUTION:
		code	=	RIE_LOG;
		break;
	case CODE_STATS:
		code	=	RIE_STATS;
		break;
	case CODE_PROGRESS:
		code	=	RIE_PROGRESS;
		break;
	}

	return code;
}

///////////////////////////////////////////////////////////////////////
// Function				:	error
// Description			:	Generate an error message
// Return Value			:
// Comments				:
// Date last edited		:	6/10/2003
void	error(EErrorCode code,char *mes,...) {
	char	tmp[OS_MAX_PATH_LENGTH];
	va_list	args;

	va_start(args,mes);
	vsprintf(tmp,mes,args);

	renderMan->RiError(RIE_ERROR,translate(code),tmp);
	va_end(args);
}

///////////////////////////////////////////////////////////////////////
// Function				:	warning
// Description			:	Generate a warning message
// Return Value			:
// Comments				:
// Date last edited		:	6/10/2003
void	warning(EErrorCode code,char *mes,...) {
	char	tmp[OS_MAX_PATH_LENGTH];
	va_list	args;

	va_start(args,mes);
	vsprintf(tmp,mes,args);

	renderMan->RiError(RIE_WARNING,translate(code),tmp);
	va_end(args);
}

///////////////////////////////////////////////////////////////////////
// Function				:	fatal
// Description			:	Generate a fatal message
// Return Value			:
// Comments				:
// Date last edited		:	6/10/2003
void	fatal(EErrorCode code,char *mes,...) {
	char	tmp[OS_MAX_PATH_LENGTH];
	va_list	args;

	va_start(args,mes);
	vsprintf(tmp,mes,args);

	renderMan->RiError(RIE_SEVERE,translate(code),tmp);
	va_end(args);
}


///////////////////////////////////////////////////////////////////////
// Function				:	info
// Description			:	Generate an info message
// Return Value			:
// Comments				:
// Date last edited		:	6/10/2003
void	info(EErrorCode code,char *mes,...) {
	char	tmp[OS_MAX_PATH_LENGTH];
	va_list	args;

	va_start(args,mes);
	vsprintf(tmp,mes,args);

	renderMan->RiError(RIE_INFO,translate(code),tmp);
	va_end(args);
}








