Sync-to-go: update copyright for 2015
[s-roff.git] / src / lib-roff / error.cpp
blob739d573d3ecb64ae3f476c63bee9a86f76e0fe47
1 /*@
2 * Copyright (c) 2014 - 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
4 * Copyright (C) 1989 - 1992, 2003 Free Software Foundation, Inc.
5 * Written by James Clark (jjc@jclark.com)
7 * This 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 * This 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.
22 #include "config.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include "errarg.h"
29 #include "error.h"
31 extern void fatal_error_exit(); // FIXME
33 enum error_type { WARNING, ERROR, FATAL };
35 static void do_error_with_file_and_line(const char *filename,
36 const char *source_filename,
37 int lineno,
38 error_type type,
39 const char *format,
40 const errarg &arg1,
41 const errarg &arg2,
42 const errarg &arg3)
44 int need_space = 0;
45 if (program_name) {
46 fprintf(stderr, "%s:", program_name);
47 need_space = 1;
49 if (lineno >= 0 && filename != 0) {
50 if (strcmp(filename, "-") == 0)
51 filename = "<standard input>";
52 if (source_filename != 0)
53 fprintf(stderr, "%s (%s):%d:", filename, source_filename, lineno);
54 else
55 fprintf(stderr, "%s:%d:", filename, lineno);
56 need_space = 1;
58 switch (type) {
59 case FATAL:
60 fputs("fatal error:", stderr);
61 need_space = 1;
62 break;
63 case ERROR:
64 break;
65 case WARNING:
66 fputs("warning:", stderr);
67 need_space = 1;
68 break;
70 if (need_space)
71 fputc(' ', stderr);
72 errprint(format, arg1, arg2, arg3);
73 fputc('\n', stderr);
74 fflush(stderr);
75 if (type == FATAL)
76 fatal_error_exit();
79 static void do_error(error_type type,
80 const char *format,
81 const errarg &arg1,
82 const errarg &arg2,
83 const errarg &arg3)
85 do_error_with_file_and_line(current_filename, current_source_filename,
86 current_lineno, type, format, arg1, arg2, arg3);
89 void error(const char *format,
90 const errarg &arg1,
91 const errarg &arg2,
92 const errarg &arg3)
94 do_error(ERROR, format, arg1, arg2, arg3);
97 void warning(const char *format,
98 const errarg &arg1,
99 const errarg &arg2,
100 const errarg &arg3)
102 do_error(WARNING, format, arg1, arg2, arg3);
105 void fatal(const char *format,
106 const errarg &arg1,
107 const errarg &arg2,
108 const errarg &arg3)
110 do_error(FATAL, format, arg1, arg2, arg3);
113 void error_with_file_and_line(const char *filename,
114 int lineno,
115 const char *format,
116 const errarg &arg1,
117 const errarg &arg2,
118 const errarg &arg3)
120 do_error_with_file_and_line(filename, 0, lineno,
121 ERROR, format, arg1, arg2, arg3);
124 void warning_with_file_and_line(const char *filename,
125 int lineno,
126 const char *format,
127 const errarg &arg1,
128 const errarg &arg2,
129 const errarg &arg3)
131 do_error_with_file_and_line(filename, 0, lineno,
132 WARNING, format, arg1, arg2, arg3);
135 void fatal_with_file_and_line(const char *filename,
136 int lineno,
137 const char *format,
138 const errarg &arg1,
139 const errarg &arg2,
140 const errarg &arg3)
142 do_error_with_file_and_line(filename, 0, lineno,
143 FATAL, format, arg1, arg2, arg3);
146 // s-it2-mode