1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/*++
/* NAME
/* error 3
/* SUMMARY
/* diagnostics
/* PACKAGE
/* unproto
/* SYNOPSIS
/* #include "error.h"
/*
/* int errcount;
/*
/* void error(text)
/* char *text;
/*
/* void error_where(path, line, text)
/* char *path;
/* int line;
/* char *text;
/*
/* void fatal(text)
/* char *text;
/* DESCRIPTION
/* The routines in this file print a diagnostic (text). Some also
/* terminate the program. Upon each error*() call, the errcount variable
/* is incremented.
/*
/* error() provides a default context, i.e. the source-file
/* coordinate of the last read token.
/*
/* error_where() allows the caller to explicitly specify context: path
/* is a source-file name, and line is a line number.
/*
/* fatal() is like error() but terminates the program with a non-zero
/* exit status.
/*
/* context is ignored if the line number is zero or if the path
/* is an empty string.
/* AUTHOR(S)
/* Wietse Venema
/* Eindhoven University of Technology
/* Department of Mathematics and Computer Science
/* Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
/* LAST MODIFICATION
/* 92/01/15 21:53:10
/* VERSION/RELEASE
/* 1.2
/*--*/
static char error_sccsid[] = "@(#) error.c 1.2 92/01/15 21:53:10";
/* C library */
#include <stdio.h>
extern void exit();
/* Application-specific stuff */
#include "token.h"
#include "error.h"
int errcount = 0; /* error counter */
/* error - report problem (implicit context) */
void error(text)
char *text;
{
error_where(in_path, in_line, text);
}
/* error_where - report problem (explicit context) */
void error_where(path, line, text)
char *path;
int line;
char *text;
{
errcount++;
/* Suppress context info if there is none. */
if (line && path[0])
fprintf(stderr, "%s, line %d: ", path, line);
fprintf(stderr, "%s\n", text);
}
/* fatal - report problem and terminate unsuccessfully */
void fatal(text)
char *text;
{
error(text);
exit(1);
}
|