• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Demonstration of groff .psbb request handling code, for EPS and PDF input files


Commit MetaInfo

Revision3e32dddbcfcf22faac2d870780f57b870b6e8001 (tree)
Zeit2017-10-07 18:53:40
AutorKeith Marshall <keithmarshall@user...>
CommiterKeith Marshall

Log Message

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.

Ändern Zusammenfassung

Diff

--- a/libgroff/error.cpp
+++ b/libgroff/error.cpp
@@ -1,5 +1,5 @@
11 // -*- C++ -*-
2-/* Copyright (C) 1989-2014 Free Software Foundation, Inc.
2+/* Copyright (C) 1989-2014, 2017, Free Software Foundation, Inc.
33 Written by James Clark (jjc@jclark.com)
44
55 This file is part of groff.
@@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
1818 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1919
2020 #include <stdio.h>
21+#include <stdarg.h>
2122 #include <stdlib.h>
2223 #include <string.h>
2324 #include "errarg.h"
@@ -27,14 +28,10 @@ extern void fatal_error_exit();
2728
2829 enum error_type { WARNING, ERROR, FATAL };
2930
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)
3835 {
3936 int need_space = 0;
4037 if (program_name) {
@@ -64,16 +61,33 @@ static void do_error_with_file_and_line(const char *filename,
6461 }
6562 if (need_space)
6663 fputc(' ', stderr);
67- errprint(format, arg1, arg2, arg3);
64+}
65+
66+static void end_error_with_file_and_line(error_type type)
67+{
6868 fputc('\n', stderr);
6969 fflush(stderr);
7070 if (type == FATAL)
7171 fatal_error_exit();
7272 }
73-
7473
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,
7791 const errarg &arg1,
7892 const errarg &arg2,
7993 const errarg &arg3)
@@ -82,8 +96,27 @@ static void do_error(error_type type,
8296 current_lineno, type, format, arg1, arg2, arg3);
8397 }
8498
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+}
85109
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,
87120 const errarg &arg1,
88121 const errarg &arg2,
89122 const errarg &arg3)
@@ -91,7 +124,7 @@ void error(const char *format,
91124 do_error(ERROR, format, arg1, arg2, arg3);
92125 }
93126
94-void warning(const char *format,
127+void warning(const char *format,
95128 const errarg &arg1,
96129 const errarg &arg2,
97130 const errarg &arg3)
@@ -99,7 +132,7 @@ void warning(const char *format,
99132 do_error(WARNING, format, arg1, arg2, arg3);
100133 }
101134
102-void fatal(const char *format,
135+void fatal(const char *format,
103136 const errarg &arg1,
104137 const errarg &arg2,
105138 const errarg &arg3)
@@ -109,33 +142,42 @@ void fatal(const char *format,
109142
110143 void error_with_file_and_line(const char *filename,
111144 int lineno,
112- const char *format,
145+ const char *format,
113146 const errarg &arg1,
114147 const errarg &arg2,
115148 const errarg &arg3)
116149 {
117- do_error_with_file_and_line(filename, 0, lineno,
150+ do_error_with_file_and_line(filename, 0, lineno,
118151 ERROR, format, arg1, arg2, arg3);
119152 }
120153
121154 void warning_with_file_and_line(const char *filename,
122155 int lineno,
123- const char *format,
156+ const char *format,
124157 const errarg &arg1,
125158 const errarg &arg2,
126159 const errarg &arg3)
127160 {
128- do_error_with_file_and_line(filename, 0, lineno,
161+ do_error_with_file_and_line(filename, 0, lineno,
129162 WARNING, format, arg1, arg2, arg3);
130163 }
131164
132165 void fatal_with_file_and_line(const char *filename,
133166 int lineno,
134- const char *format,
167+ const char *format,
135168 const errarg &arg1,
136169 const errarg &arg2,
137170 const errarg &arg3)
138171 {
139- do_error_with_file_and_line(filename, 0, lineno,
172+ do_error_with_file_and_line(filename, 0, lineno,
140173 FATAL, format, arg1, arg2, arg3);
141174 }
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+}
--- a/libgroff/error.h
+++ b/libgroff/error.h
@@ -50,6 +50,7 @@ extern void warning(const char *,
5050 const errarg &arg2 = empty_errarg,
5151 const errarg &arg3 = empty_errarg);
5252
53+extern "C" void errprintf(const char *, ...);
5354
5455 extern "C" const char *program_name;
5556 extern int current_lineno;