/*=~=~=~=~ McGill-Computer-Vision-and-Robotics-Laboratory--C-Module ~=~=~=~=
 *		
 * NAME:	fatalMsg, warnMsg, usageMsg -- library routines to print diagnistics
 *		   on stderr.
 *
 * SYNOPSIS:	fatalMsg (code, s, arg1, arg2, ...)
 *		   int code;
 *		   char *s;
 *		   args 1 to n (combined size not to exceed 32 bytes)
 *		   
 *		usageMsg (code, s, arg1, arg2, ...)
 *		   int code;
 *		   char *s;
 *		   args 1 to n (combined size not to exceed 32 bytes)
 * 
 *		warnMsg (s, arg1, arg2, ...)
 *		   char *s;
 *		   args 1 to n (combined size not to exceed 32 bytes)
 *
 * DESCRIPTION:	These routines print diagnostic messages on stderr. The usage
 *		for each routine is analogous to printf: a format string,
 *		followed by a list of arguments to be printed. The number of 
 *		arguments is currently limited such that combined size of 
 *		all the	arguments may not exceed 32 bytes. This was done so 
 *		that the software can be written machine independently.
 *
 *		'fatalMsg' prints the diagnostic preappended with the string
 *		"ERROR -- ", and then exits with the value 'code'.
 *
 *		'usageMsg' prints the diagnostic preappended with the string
 *		"USAGE: ", and then exits with the value 'code'. 
 *		It is used when interpreting argument strings.
 *
 *		'warnMsg' prints the diagnostic preappended with the string
 *		"WARNING -- ", but does not exit.
 * 
 * ARGUMENTS:	code ---	exit code
 *
 *		s ---		format string
 *
 *		arg1 ... argn	something the print
 *
 * NOTES:	
 *
 * AUTHOR/DATE:	John Lloyd, November 1986
 *
 * UPDATES:	
 *
 *~=~=~=~=~=~= McGill-Computer-Vision-and-Robotics-Laboratory ~=~=~=~=~=~=*/

#ifndef VXWORKS_CFG
#include <stdio.h>
#else
#include <vxWorks.h>
#include <stdioLib.h>
#endif
#include <varargs.h>

#ifdef VXWORKS_CFG
#define vfprintf(fp,f,a)	fioFormat(f,a,fileOutput,(int)fp)

#ifdef VXWORKS_V5
#define fioFormat fioFormatV
#endif

fileOutput(buf, size, arg)
char *buf;
int size;
int arg;
{
	FILE *fp;
	register int i;

	fp = (FILE*)arg;
	for (i=0; i<size; i++)
	 { fputc(buf[i], fp);
	 }
}
#endif

fatalMsg (va_alist)
va_dcl
{
	va_list ap;
	int code;
	char *fmt;

	va_start(ap);
	code = va_arg(ap, int);
	fmt = va_arg(ap, char *);
	fprintf (stderr, "ERROR -- ");
	vfprintf (stderr, fmt, ap);
	va_end (ap);
	exit (code);
}

usageMsg (va_alist)
va_dcl
{
	va_list ap;
	int code;
	char *fmt;

	va_start(ap);
	code = va_arg(ap, int);
	fmt = va_arg(ap, char *);
	fprintf (stderr, "USAGE: ");
	vfprintf (stderr, fmt, ap);
	va_end (ap);
	exit (code);
}

warnMsg (va_alist)
va_dcl
{
	va_list ap;
	int code;
	char *fmt;

	va_start(ap);
	code = va_arg(ap, int);
	fmt = va_arg(ap, char *);
	fprintf (stderr, "WARNING: ");
	vfprintf (stderr, fmt, ap);
	va_end (ap);
}
