head	1.1;
access;
symbols;
locks; strict;
comment	@ * @;


1.1
date	94.03.26.11.34.21;	author peteric;	state Exp;
branches;
next	;


desc
@Error handling routines extracted from main.c
@


1.1
log
@Initial revision
@
text
@/*************************************************************************
 *
 * 	$RSCFile$
 *
 *	$Author$
 *
 *	$Date$
 *
 *	$Revision$
 *
 *	Purpose:	Error handling routines
 *			
 *	$Log$
 *	
 *
 *************************************************************************/

#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

#include "ftree.h"

int reading_file = FALSE;		/* true when reading input file */
int errors = 0;						/* # errors so far */
char *current_filename = NULL;		/* current filename pointer */
int lineno = 0;						/* current linenumber */

void errmsg(const char *str, ...)
{
	va_list ap;

	va_start(ap, str);
	if (reading_file)
		fprintf(stderr, "%s: %d: ", current_filename, lineno);
	fprintf(stderr, "error: ");
	vfprintf(stderr, str, ap);
	va_end(ap);
	
	if (++errors > 5)
	{
		fprintf(stderr, "ftree: error: too many errors; exiting.\n");
		exit(1);
	}
}

void warnmsg(const char *str, ...)
{
	va_list ap;

	va_start(ap, str);
	if (reading_file)
		fprintf(stderr, "%s: %d: ", current_filename, lineno);
	fprintf(stderr, "warning: ");
	vfprintf(stderr, str, ap);
	va_end(ap);
}
@
