Demonstration of groff .psbb request handling code, for EPS and PDF input files
修訂 | 3e32dddbcfcf22faac2d870780f57b870b6e8001 (tree) |
---|---|
時間 | 2017-10-07 18:53:40 |
作者 | Keith Marshall <keithmarshall@user...> |
Commiter | Keith Marshall |
Add a printf-alike API entry for libgroff error reporting.
* libgroff/error.h (errprintf): New function; add prototype.
* libgroff/error.cpp (do_error_with_file_and_line): Factor out...
(report_file_and_line, end_error_with_file_and_line): ...this pair of
initial and final fragments, respectively; incorporate them with...
(do_printf_with_file_and_line): ...this new function; hence...
(do_printf, errprintf): ...implement these.
@@ -1,5 +1,5 @@ | ||
1 | 1 | // -*- C++ -*- |
2 | -/* Copyright (C) 1989-2014 Free Software Foundation, Inc. | |
2 | +/* Copyright (C) 1989-2014, 2017, Free Software Foundation, Inc. | |
3 | 3 | Written by James Clark (jjc@jclark.com) |
4 | 4 | |
5 | 5 | This file is part of groff. |
@@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License | ||
18 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
19 | 19 | |
20 | 20 | #include <stdio.h> |
21 | +#include <stdarg.h> | |
21 | 22 | #include <stdlib.h> |
22 | 23 | #include <string.h> |
23 | 24 | #include "errarg.h" |
@@ -27,14 +28,10 @@ extern void fatal_error_exit(); | ||
27 | 28 | |
28 | 29 | enum error_type { WARNING, ERROR, FATAL }; |
29 | 30 | |
30 | -static void do_error_with_file_and_line(const char *filename, | |
31 | - const char *source_filename, | |
32 | - int lineno, | |
33 | - error_type type, | |
34 | - const char *format, | |
35 | - const errarg &arg1, | |
36 | - const errarg &arg2, | |
37 | - const errarg &arg3) | |
31 | +static void report_file_and_line(const char *filename, | |
32 | + const char *source_filename, | |
33 | + int lineno, | |
34 | + error_type type) | |
38 | 35 | { |
39 | 36 | int need_space = 0; |
40 | 37 | if (program_name) { |
@@ -64,16 +61,33 @@ static void do_error_with_file_and_line(const char *filename, | ||
64 | 61 | } |
65 | 62 | if (need_space) |
66 | 63 | fputc(' ', stderr); |
67 | - errprint(format, arg1, arg2, arg3); | |
64 | +} | |
65 | + | |
66 | +static void end_error_with_file_and_line(error_type type) | |
67 | +{ | |
68 | 68 | fputc('\n', stderr); |
69 | 69 | fflush(stderr); |
70 | 70 | if (type == FATAL) |
71 | 71 | fatal_error_exit(); |
72 | 72 | } |
73 | - | |
74 | 73 | |
75 | -static void do_error(error_type type, | |
76 | - const char *format, | |
74 | +static void do_error_with_file_and_line(const char *filename, | |
75 | + const char *source_filename, | |
76 | + int lineno, | |
77 | + error_type type, | |
78 | + const char *format, | |
79 | + const errarg &arg1, | |
80 | + const errarg &arg2, | |
81 | + const errarg &arg3) | |
82 | +{ | |
83 | + report_file_and_line(filename, source_filename, lineno, type); | |
84 | + errprint(format, arg1, arg2, arg3); | |
85 | + end_error_with_file_and_line(type); | |
86 | +} | |
87 | + | |
88 | + | |
89 | +static void do_error(error_type type, | |
90 | + const char *format, | |
77 | 91 | const errarg &arg1, |
78 | 92 | const errarg &arg2, |
79 | 93 | const errarg &arg3) |
@@ -82,8 +96,27 @@ static void do_error(error_type type, | ||
82 | 96 | current_lineno, type, format, arg1, arg2, arg3); |
83 | 97 | } |
84 | 98 | |
99 | +static void do_printf_with_file_and_line(const char *filename, | |
100 | + const char *source_filename, | |
101 | + int lineno, | |
102 | + error_type type, | |
103 | + const char *format, | |
104 | + va_list argv) | |
105 | +{ | |
106 | + report_file_and_line(filename, source_filename, lineno, type); | |
107 | + vfprintf(stderr, format, argv); | |
108 | +} | |
85 | 109 | |
86 | -void error(const char *format, | |
110 | +static void do_printf(error_type type, | |
111 | + const char *format, | |
112 | + va_list argv) | |
113 | +{ | |
114 | + do_printf_with_file_and_line(current_filename, current_source_filename, | |
115 | + current_lineno, type, format, argv); | |
116 | +} | |
117 | + | |
118 | + | |
119 | +void error(const char *format, | |
87 | 120 | const errarg &arg1, |
88 | 121 | const errarg &arg2, |
89 | 122 | const errarg &arg3) |
@@ -91,7 +124,7 @@ void error(const char *format, | ||
91 | 124 | do_error(ERROR, format, arg1, arg2, arg3); |
92 | 125 | } |
93 | 126 | |
94 | -void warning(const char *format, | |
127 | +void warning(const char *format, | |
95 | 128 | const errarg &arg1, |
96 | 129 | const errarg &arg2, |
97 | 130 | const errarg &arg3) |
@@ -99,7 +132,7 @@ void warning(const char *format, | ||
99 | 132 | do_error(WARNING, format, arg1, arg2, arg3); |
100 | 133 | } |
101 | 134 | |
102 | -void fatal(const char *format, | |
135 | +void fatal(const char *format, | |
103 | 136 | const errarg &arg1, |
104 | 137 | const errarg &arg2, |
105 | 138 | const errarg &arg3) |
@@ -109,33 +142,42 @@ void fatal(const char *format, | ||
109 | 142 | |
110 | 143 | void error_with_file_and_line(const char *filename, |
111 | 144 | int lineno, |
112 | - const char *format, | |
145 | + const char *format, | |
113 | 146 | const errarg &arg1, |
114 | 147 | const errarg &arg2, |
115 | 148 | const errarg &arg3) |
116 | 149 | { |
117 | - do_error_with_file_and_line(filename, 0, lineno, | |
150 | + do_error_with_file_and_line(filename, 0, lineno, | |
118 | 151 | ERROR, format, arg1, arg2, arg3); |
119 | 152 | } |
120 | 153 | |
121 | 154 | void warning_with_file_and_line(const char *filename, |
122 | 155 | int lineno, |
123 | - const char *format, | |
156 | + const char *format, | |
124 | 157 | const errarg &arg1, |
125 | 158 | const errarg &arg2, |
126 | 159 | const errarg &arg3) |
127 | 160 | { |
128 | - do_error_with_file_and_line(filename, 0, lineno, | |
161 | + do_error_with_file_and_line(filename, 0, lineno, | |
129 | 162 | WARNING, format, arg1, arg2, arg3); |
130 | 163 | } |
131 | 164 | |
132 | 165 | void fatal_with_file_and_line(const char *filename, |
133 | 166 | int lineno, |
134 | - const char *format, | |
167 | + const char *format, | |
135 | 168 | const errarg &arg1, |
136 | 169 | const errarg &arg2, |
137 | 170 | const errarg &arg3) |
138 | 171 | { |
139 | - do_error_with_file_and_line(filename, 0, lineno, | |
172 | + do_error_with_file_and_line(filename, 0, lineno, | |
140 | 173 | FATAL, format, arg1, arg2, arg3); |
141 | 174 | } |
175 | + | |
176 | +void errprintf(const char *format, ...) | |
177 | +{ | |
178 | + va_list argv; | |
179 | + va_start(argv, format); | |
180 | + do_printf(ERROR, format, argv); | |
181 | + va_end(argv); | |
182 | + end_error_with_file_and_line(ERROR); | |
183 | +} |
@@ -50,6 +50,7 @@ extern void warning(const char *, | ||
50 | 50 | const errarg &arg2 = empty_errarg, |
51 | 51 | const errarg &arg3 = empty_errarg); |
52 | 52 | |
53 | +extern "C" void errprintf(const char *, ...); | |
53 | 54 | |
54 | 55 | extern "C" const char *program_name; |
55 | 56 | extern int current_lineno; |