File: error.cc

package info (click to toggle)
plotutils 2.4.1-15
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,072 kB
  • ctags: 6,952
  • sloc: ansic: 76,305; cpp: 12,402; sh: 8,475; yacc: 2,604; makefile: 894; lex: 144
file content (128 lines) | stat: -rw-r--r-- 2,751 bytes parent folder | download | duplicates (13)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// -*- C++ -*-
/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
     Written by James Clark (jjc@jclark.com) */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "errarg.h"
#include "error.h"

extern void fatal_error_exit();

enum error_type { WARNING, ERROR, FATAL };

static void 
do_error_with_file_and_line(const char *filename, int lineno,
			    error_type type, 
			    const char *format, 
			    const errarg &arg1,
			    const errarg &arg2,
			    const errarg &arg3)
{
  int need_space = 0;

  if (program_name) 
    {
      fprintf(stderr, "%s:", program_name);
      need_space = 1;
    }
  if (lineno >= 0 && filename != 0) 
    {
      if (strcmp(filename, "-") == 0)
	filename = "<standard input>";
      fprintf(stderr, "%s:%d:", filename, lineno);
      need_space = 1;
    }
  switch (type) 
    {
    case FATAL:
      fputs("fatal error:", stderr);
      need_space = 1;
      break;
    case ERROR:
      break;
    case WARNING:
      fputs("warning:", stderr);
      need_space = 1;
      break;
    }
  if (need_space)
    fputc(' ', stderr);
  errprint(format, arg1, arg2, arg3);
  fputc('\n', stderr);
  fflush(stderr);
  if (type == FATAL)
    fatal_error_exit();
}
      
static void 
do_error (error_type type, const char *format, 
	  const errarg &arg1, const errarg &arg2, const errarg &arg3)
{
  do_error_with_file_and_line(current_filename, current_lineno,
			      type, format, arg1, arg2, arg3);
}

void
error(const char *format, 
      const errarg &arg1,
      const errarg &arg2,
      const errarg &arg3)
{
  do_error(ERROR, format, arg1, arg2, arg3);
}

void 
warning(const char *format, 
	const errarg &arg1,
	const errarg &arg2,
	const errarg &arg3)
{
  do_error(WARNING, format, arg1, arg2, arg3);
}

void 
fatal(const char *format, 
      const errarg &arg1,
      const errarg &arg2,
      const errarg &arg3)
{
  do_error(FATAL, format, arg1, arg2, arg3);
}

void 
error_with_file_and_line(const char *filename,
			 int lineno,
			 const char *format, 
			 const errarg &arg1,
			 const errarg &arg2,
			 const errarg &arg3)
{
  do_error_with_file_and_line(filename, lineno, 
			      ERROR, format, arg1, arg2, arg3);
}

void 
warning_with_file_and_line(const char *filename,
			   int lineno,
			   const char *format, 
			   const errarg &arg1,
			   const errarg &arg2,
			   const errarg &arg3)
{
  do_error_with_file_and_line(filename, lineno, 
			      WARNING, format, arg1, arg2, arg3);
}

void 
fatal_with_file_and_line(const char *filename,
			 int lineno,
			 const char *format, 
			 const errarg &arg1,
			 const errarg &arg2,
			 const errarg &arg3)
{
  do_error_with_file_and_line(filename, lineno, 
			      FATAL, format, arg1, arg2, arg3);
}