/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by John E. Lloyd.			    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

/*=~=~=~=~ McGill-Computer-Vision-and-Robotics-Laboratory--C-Module ~=~=~=~=
 *		
 * MODULE NAME:	error
 *
 * DESCRIPTION:	functions for storing (and later printing) error messages.
 * 
 * AUTHOR/DATE:	John Lloyd, Summer 1987
 *
 *~=~=~=~=~=~= McGill-Computer-Vision-and-Robotics-Laboratory ~=~=~=~=~=~=*/

#include <stdio.h>
#include <varargs.h>
#include "error.h"

static ERROR_BUF errors[NUM_ERROR_BUFS];
static int errorNum = 0;

print_errors ()
{
	int i;

	for (i=0; i<errorNum; i++)
	 { printOut ("%s", i==0 ? "ERROR:  " : "        " );
	   printOut ("%s", errors[i].msg);
	 }
}

clear_errors ()
{
	errorNum = 0;
}

error (va_alist)
va_dcl
{
	va_list ap;
	char *fmt;

	va_start(ap);
	errors[errorNum].code = va_arg(ap, int);
	fmt = va_arg(ap, char*);

	vsnprintf (errors[errorNum].msg, ERROR_MSG_SIZE, fmt, ap);
	errorNum++;

	va_end(ap);
}

num_errors ()
{
	return (errorNum);
}
