groff before CVS: release 1.06
[s-roff.git] / libgroff / error.cc
blobf0c69980a51f78916e596d49f471ff8469cbde12
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.com)
5 This file is part of groff.
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file COPYING. If not, write to the Free Software
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include "errarg.h"
25 #include "error.h"
27 extern void fatal_error_exit();
29 enum error_type { WARNING, ERROR, FATAL };
31 static void do_error_with_file_and_line(const char *filename, int lineno,
32 error_type type,
33 const char *format,
34 const errarg &arg1,
35 const errarg &arg2,
36 const errarg &arg3)
38 int need_space = 0;
39 if (program_name) {
40 fprintf(stderr, "%s:", program_name);
41 need_space = 1;
43 if (lineno >= 0 && filename != 0) {
44 if (strcmp(filename, "-") == 0)
45 filename = "<standard input>";
46 fprintf(stderr, "%s:%d:", filename, lineno);
47 need_space = 1;
49 switch (type) {
50 case FATAL:
51 fputs("fatal error:", stderr);
52 need_space = 1;
53 break;
54 case ERROR:
55 break;
56 case WARNING:
57 fputs("warning:", stderr);
58 need_space = 1;
59 break;
61 if (need_space)
62 fputc(' ', stderr);
63 errprint(format, arg1, arg2, arg3);
64 fputc('\n', stderr);
65 fflush(stderr);
66 if (type == FATAL)
67 fatal_error_exit();
71 static void do_error(error_type type,
72 const char *format,
73 const errarg &arg1,
74 const errarg &arg2,
75 const errarg &arg3)
77 do_error_with_file_and_line(current_filename, current_lineno,
78 type, format, arg1, arg2, arg3);
82 void error(const char *format,
83 const errarg &arg1,
84 const errarg &arg2,
85 const errarg &arg3)
87 do_error(ERROR, format, arg1, arg2, arg3);
90 void warning(const char *format,
91 const errarg &arg1,
92 const errarg &arg2,
93 const errarg &arg3)
95 do_error(WARNING, format, arg1, arg2, arg3);
98 void fatal(const char *format,
99 const errarg &arg1,
100 const errarg &arg2,
101 const errarg &arg3)
103 do_error(FATAL, format, arg1, arg2, arg3);
106 void error_with_file_and_line(const char *filename,
107 int lineno,
108 const char *format,
109 const errarg &arg1,
110 const errarg &arg2,
111 const errarg &arg3)
113 do_error_with_file_and_line(filename, lineno,
114 ERROR, format, arg1, arg2, arg3);
117 void warning_with_file_and_line(const char *filename,
118 int lineno,
119 const char *format,
120 const errarg &arg1,
121 const errarg &arg2,
122 const errarg &arg3)
124 do_error_with_file_and_line(filename, lineno,
125 WARNING, format, arg1, arg2, arg3);
128 void fatal_with_file_and_line(const char *filename,
129 int lineno,
130 const char *format,
131 const errarg &arg1,
132 const errarg &arg2,
133 const errarg &arg3)
135 do_error_with_file_and_line(filename, lineno,
136 FATAL, format, arg1, arg2, arg3);