* All affected files: Update postal address of FSF.
[s-roff.git] / src / libs / libgroff / error.cpp
blob8aea0c0d8f8d6edc31d1eefecb79b4d3f409701d
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992, 2003 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, 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,
32 const char *source_filename,
33 int lineno,
34 error_type type,
35 const char *format,
36 const errarg &arg1,
37 const errarg &arg2,
38 const errarg &arg3)
40 int need_space = 0;
41 if (program_name) {
42 fprintf(stderr, "%s:", program_name);
43 need_space = 1;
45 if (lineno >= 0 && filename != 0) {
46 if (strcmp(filename, "-") == 0)
47 filename = "<standard input>";
48 if (source_filename != 0)
49 fprintf(stderr, "%s (%s):%d:", filename, source_filename, lineno);
50 else
51 fprintf(stderr, "%s:%d:", filename, lineno);
52 need_space = 1;
54 switch (type) {
55 case FATAL:
56 fputs("fatal error:", stderr);
57 need_space = 1;
58 break;
59 case ERROR:
60 break;
61 case WARNING:
62 fputs("warning:", stderr);
63 need_space = 1;
64 break;
66 if (need_space)
67 fputc(' ', stderr);
68 errprint(format, arg1, arg2, arg3);
69 fputc('\n', stderr);
70 fflush(stderr);
71 if (type == FATAL)
72 fatal_error_exit();
76 static void do_error(error_type type,
77 const char *format,
78 const errarg &arg1,
79 const errarg &arg2,
80 const errarg &arg3)
82 do_error_with_file_and_line(current_filename, current_source_filename,
83 current_lineno, type, format, arg1, arg2, arg3);
87 void error(const char *format,
88 const errarg &arg1,
89 const errarg &arg2,
90 const errarg &arg3)
92 do_error(ERROR, format, arg1, arg2, arg3);
95 void warning(const char *format,
96 const errarg &arg1,
97 const errarg &arg2,
98 const errarg &arg3)
100 do_error(WARNING, format, arg1, arg2, arg3);
103 void fatal(const char *format,
104 const errarg &arg1,
105 const errarg &arg2,
106 const errarg &arg3)
108 do_error(FATAL, format, arg1, arg2, arg3);
111 void error_with_file_and_line(const char *filename,
112 int lineno,
113 const char *format,
114 const errarg &arg1,
115 const errarg &arg2,
116 const errarg &arg3)
118 do_error_with_file_and_line(filename, 0, lineno,
119 ERROR, format, arg1, arg2, arg3);
122 void warning_with_file_and_line(const char *filename,
123 int lineno,
124 const char *format,
125 const errarg &arg1,
126 const errarg &arg2,
127 const errarg &arg3)
129 do_error_with_file_and_line(filename, 0, lineno,
130 WARNING, format, arg1, arg2, arg3);
133 void fatal_with_file_and_line(const char *filename,
134 int lineno,
135 const char *format,
136 const errarg &arg1,
137 const errarg &arg2,
138 const errarg &arg3)
140 do_error_with_file_and_line(filename, 0, lineno,
141 FATAL, format, arg1, arg2, arg3);