/*
 * $Source: /afs/athena.mit.edu/user/j/jik/sipbsrc/src/newwebster/lib/RCS/errors.c,v $
 * $Author: jik $
 */

#if (!defined(lint) && !defined(SABER))
     static char rcsid_errors_c[] = "$Header: /afs/athena.mit.edu/user/j/jik/sipbsrc/src/newwebster/lib/RCS/errors.c,v 1.5 90/09/10 04:36:44 jik Exp Locker: jik $";
#endif

#include <varargs.h>
#include <com_err.h>
#include <stdio.h>
#include "dict_errs.h"
#include "mit-copyright.h"

char *whoami;
int dict_error_reported = 1;
int dict_error_occurred = 0;
int dict_report_errors = 1;
int dict_error_code = 0;
char *dict_error_string = NULL;
char *dict_error_file = NULL;
int dict_error_line = 0;

/*
 * Proper use of this procedure requires strict adherance to the way
 * it is supposed to be used by all procedures in a program.  Whenever
 * there is an error, dict_set_error must be called with the error
 * value.  Then, either the procedure that detects the error must call
 * dict_error(), or it must pass the error up to its parent for the
 * parent to report.
 */


void dict_error(str)
char *str;
{
     if (dict_report_errors && (! dict_error_reported)) {
	  fprintf(stderr, "%s: ", whoami);
	  if (dict_error_file)
	       fprintf(stderr, "file %s, line %d: ", dict_error_file,
		       dict_error_line);
	  if (*str)
	       fprintf(stderr, "%s: ", str);
	  if (dict_error_string)
	       fprintf(stderr, "%s: ", dict_error_string);
	  fprintf(stderr, "%s\n", error_message(dict_error_code));
     }
     dict_error_reported = 1;
     dict_error_string = NULL;
}
