////////////////////////////////////////////////////////////////////////
//
// Name:	CA_errno.C
//
// Purpose:	Copycat of the features of the standard "errno" utilities.
//
////////////////////////////////////////////////////////////////////////

#include <stdlib.h>
#include <iostream.h>
#include "CA_errno.h"


//
// These must map 1-1 to the macros in CA_errno.h
//
static char *CA_error[] = {
	"Unknown error",
	"Missing required model parameter",
	"Invalid iteration parameter",
	"Invalid column parameter",
	"Invalid row parameter",
	"Invalid model parameter",
};



// Initialize the CA_errno
int CA_errno = CUNKNWN;




//////////////////////////////////////////////////////////////////
//			CA_strerror()
//
//  Return pointer to implementation-defined string corresponding
//  to CA error n.
//
//  INPUT PARAMETERS:
//	n		implementation-defined CA error number
//	
//  OUTPUT PARAMETERS:
//	None
//
//  RETURN VALUE:
//	pointer to implementation-defined string
//
//////////////////////////////////////////////////////////////////
char *
CA_strerror(
const int	n)	//	IN
{
	if (n>=0 && n<CECOUNT) {
		return CA_error[n];
	} else {
		return CA_error[CUNKNWN];
	}
}



//////////////////////////////////////////////////////////////////
//			CA_perror()
//
//  Prints s and an implementation-defined error message
//  corresponding to the integer in CA_errno to stderr.
//
//  INPUT PARAMETERS:
//	s		string prepended to error message
//	
//  OUTPUT PARAMETERS:
//	None
//
//  RETURN VALUE:
//	void
//
//////////////////////////////////////////////////////////////////
void
CA_perror(
const char	*s)	//	IN
{
	cerr << s << ": " << CA_strerror(CA_errno) << endl;
}
