1/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
2/* Dummy replacement for part of the public API of the libtextstyle library.
3 Copyright (C) 2006-2007, 2019 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18/* Written by Bruno Haible <bruno@clisp.org>, 2019. */
19
20/* This file is used as replacement when libtextstyle with its include file
21 <textstyle.h> is not found.
22 It supports the essential API and implements it in a way that does not
23 provide text styling. That is, it produces plain text output via <stdio.h>
24 FILE objects.
25 Thus, it allows a package to be build with or without a dependency to
26 libtextstyle, with very few occurrences of '#if HAVE_LIBTEXTSTYLE'.
27
28 Restriction:
29 It assumes that freopen() is not being called on stdout and stderr. */
30
31#ifndef _TEXTSTYLE_H
32#define _TEXTSTYLE_H
33
34#include <errno.h>
35#include <stdbool.h>
36#include <stddef.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#include <unistd.h>
41#if HAVE_TCDRAIN
42# include <termios.h>
43#endif
44
45/* ----------------------------- From ostream.h ----------------------------- */
46
47/* Describes the scope of a flush operation. */
48typedef enum
49{
50 /* Flushes buffers in this ostream_t.
51 Use this value if you want to write to the underlying ostream_t. */
52 FLUSH_THIS_STREAM = 0,
53 /* Flushes all buffers in the current process.
54 Use this value if you want to write to the same target through a
55 different file descriptor or a FILE stream. */
56 FLUSH_THIS_PROCESS = 1,
57 /* Flushes buffers in the current process and attempts to flush the buffers
58 in the kernel.
59 Use this value so that some other process (or the kernel itself)
60 may write to the same target. */
61 FLUSH_ALL = 2
62} ostream_flush_scope_t;
63
64
65/* An output stream is an object to which one can feed a sequence of bytes. */
66
67typedef FILE * ostream_t;
68
69static inline void
70ostream_write_mem (ostream_t stream, const void *data, size_t len)
71{
72 if (len > 0)
73 fwrite (data, 1, len, stream);
74}
75
76static inline void
77ostream_flush (ostream_t stream, ostream_flush_scope_t scope)
78{
79 fflush (stream);
80 if (scope == FLUSH_ALL)
81 {
82 int fd = fileno (stream);
83 if (fd >= 0)
84 {
85 /* For streams connected to a disk file: */
86 fsync (fd);
87 #if HAVE_TCDRAIN
88 /* For streams connected to a terminal: */
89 {
90 int retval;
91
92 do
93 retval = tcdrain (fd);
94 while (retval < 0 && errno == EINTR);
95 }
96 #endif
97 }
98 }
99}
100
101static inline void
102ostream_free (ostream_t stream)
103{
104 if (stream == stdin || stream == stderr)
105 fflush (stream);
106 else
107 fclose (stream);
108}
109
110static inline void
111ostream_write_str (ostream_t stream, const char *string)
112{
113 ostream_write_mem (stream, string, strlen (string));
114}
115
116/* ------------------------- From styled-ostream.h ------------------------- */
117
118typedef ostream_t styled_ostream_t;
119
120#define styled_ostream_write_mem ostream_write_mem
121#define styled_ostream_flush ostream_flush
122#define styled_ostream_free ostream_free
123
124static inline void
125styled_ostream_begin_use_class (styled_ostream_t stream _GL_UNUSED,
126 const char *classname _GL_UNUSED)
127{
128}
129
130static inline void
131styled_ostream_end_use_class (styled_ostream_t stream _GL_UNUSED,
132 const char *classname _GL_UNUSED)
133{
134}
135
136static inline void
137styled_ostream_flush_to_current_style (styled_ostream_t stream _GL_UNUSED)
138{
139}
140
141/* -------------------------- From file-ostream.h -------------------------- */
142
143typedef ostream_t file_ostream_t;
144
145#define file_ostream_write_mem ostream_write_mem
146#define file_ostream_flush ostream_flush
147#define file_ostream_free ostream_free
148
149static inline file_ostream_t
150file_ostream_create (FILE *fp)
151{
152 return fp;
153}
154
155/* --------------------------- From fd-ostream.h --------------------------- */
156
157typedef ostream_t fd_ostream_t;
158
159#define fd_ostream_write_mem ostream_write_mem
160#define fd_ostream_flush ostream_flush
161#define fd_ostream_free ostream_free
162
163static inline fd_ostream_t
164fd_ostream_create (int fd, const char *filename _GL_UNUSED,
165 bool buffered _GL_UNUSED)
166{
167 if (fd == 1)
168 return stdout;
169 else if (fd == 2)
170 return stderr;
171 else
172 return fdopen (fd, "w");
173}
174
175/* -------------------------- From term-ostream.h -------------------------- */
176
177typedef int term_color_t;
178enum
179{
180 COLOR_DEFAULT = -1 /* unknown */
181};
182
183typedef enum
184{
185 WEIGHT_NORMAL = 0,
186 WEIGHT_BOLD,
187 WEIGHT_DEFAULT = WEIGHT_NORMAL
188} term_weight_t;
189
190typedef enum
191{
192 POSTURE_NORMAL = 0,
193 POSTURE_ITALIC, /* same as oblique */
194 POSTURE_DEFAULT = POSTURE_NORMAL
195} term_posture_t;
196
197typedef enum
198{
199 UNDERLINE_OFF = 0,
200 UNDERLINE_ON,
201 UNDERLINE_DEFAULT = UNDERLINE_OFF
202} term_underline_t;
203
204typedef ostream_t term_ostream_t;
205
206#define term_ostream_write_mem ostream_write_mem
207#define term_ostream_flush ostream_flush
208#define term_ostream_free ostream_free
209
210static inline term_color_t
211term_ostream_get_color (term_ostream_t stream _GL_UNUSED)
212{
213 return COLOR_DEFAULT;
214}
215
216static inline void
217term_ostream_set_color (term_ostream_t stream _GL_UNUSED,
218 term_color_t color _GL_UNUSED)
219{
220}
221
222static inline term_color_t
223term_ostream_get_bgcolor (term_ostream_t stream _GL_UNUSED)
224{
225 return COLOR_DEFAULT;
226}
227
228static inline void
229term_ostream_set_bgcolor (term_ostream_t stream _GL_UNUSED,
230 term_color_t color _GL_UNUSED)
231{
232}
233
234static inline term_weight_t
235term_ostream_get_weight (term_ostream_t stream _GL_UNUSED)
236{
237 return WEIGHT_DEFAULT;
238}
239
240static inline void
241term_ostream_set_weight (term_ostream_t stream _GL_UNUSED,
242 term_weight_t weight _GL_UNUSED)
243{
244}
245
246static inline term_posture_t
247term_ostream_get_posture (term_ostream_t stream _GL_UNUSED)
248{
249 return POSTURE_DEFAULT;
250}
251
252static inline void
253term_ostream_set_posture (term_ostream_t stream _GL_UNUSED,
254 term_posture_t posture _GL_UNUSED)
255{
256}
257
258static inline term_underline_t
259term_ostream_get_underline (term_ostream_t stream _GL_UNUSED)
260{
261 return UNDERLINE_DEFAULT;
262}
263
264static inline void
265term_ostream_set_underline (term_ostream_t stream _GL_UNUSED,
266 term_underline_t underline _GL_UNUSED)
267{
268}
269
270static inline void
271term_ostream_flush_to_current_style (term_ostream_t stream)
272{
273 fflush (stream);
274}
275
276typedef enum
277{
278 TTYCTL_AUTO = 0, /* Automatic best-possible choice. */
279 TTYCTL_NONE, /* No control.
280 Result: Garbled output can occur, and the terminal can
281 be left in any state when the program is interrupted. */
282 TTYCTL_PARTIAL, /* Signal handling.
283 Result: Garbled output can occur, but the terminal will
284 be left in the default state when the program is
285 interrupted. */
286 TTYCTL_FULL /* Signal handling and disabling echo and flush-upon-signal.
287 Result: No garbled output, and the the terminal will
288 be left in the default state when the program is
289 interrupted. */
290} ttyctl_t;
291
292static inline term_ostream_t
293term_ostream_create (int fd, const char *filename,
294 ttyctl_t tty_control _GL_UNUSED)
295{
296 return fd_ostream_create (fd, filename, true);
297}
298
299/* ----------------------- From term-styled-ostream.h ----------------------- */
300
301typedef styled_ostream_t term_styled_ostream_t;
302
303#define term_styled_ostream_write_mem ostream_write_mem
304#define term_styled_ostream_flush ostream_flush
305#define term_styled_ostream_free ostream_free
306#define term_styled_ostream_begin_use_class styled_ostream_begin_use_class
307#define term_styled_ostream_end_use_class styled_ostream_end_use_class
308#define term_styled_ostream_flush_to_current_style styled_ostream_flush_to_current_style
309
310static inline term_styled_ostream_t
311term_styled_ostream_create (int fd, const char *filename,
312 ttyctl_t tty_control _GL_UNUSED,
313 const char *css_filename _GL_UNUSED)
314{
315 return fd_ostream_create (fd, filename, true);
316}
317
318/* ----------------------- From html-styled-ostream.h ----------------------- */
319
320typedef styled_ostream_t html_styled_ostream_t;
321
322static inline html_styled_ostream_t
323html_styled_ostream_create (ostream_t destination _GL_UNUSED,
324 const char *css_filename _GL_UNUSED)
325{
326 abort ();
327 return NULL;
328}
329
330/* ------------------------------ From color.h ------------------------------ */
331
332#define color_test_mode false
333
334enum color_option { color_no, color_tty, color_yes, color_html };
335#define color_mode color_no
336
337#define style_file_name NULL
338
339static inline bool
340handle_color_option (const char *option _GL_UNUSED)
341{
342 return false;
343}
344
345static inline void
346handle_style_option (const char *option _GL_UNUSED)
347{
348}
349
350static inline void
351print_color_test (void)
352{
353 abort ();
354}
355
356static inline void
357style_file_prepare (const char *style_file_envvar _GL_UNUSED,
358 const char *stylesdir_envvar _GL_UNUSED,
359 const char *stylesdir_after_install _GL_UNUSED,
360 const char *default_style_file _GL_UNUSED)
361{
362}
363
364/* ------------------------------ From misc.h ------------------------------ */
365
366static inline styled_ostream_t
367styled_ostream_create (int fd, const char *filename,
368 ttyctl_t tty_control _GL_UNUSED,
369 const char *css_filename _GL_UNUSED)
370{
371 return fd_ostream_create (fd, filename, true);
372}
373
374static inline void
375libtextstyle_set_failure_exit_code (int exit_code _GL_UNUSED)
376{
377}
378
379#endif /* _TEXTSTYLE_H */
380