1 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 #line 1 "html-styled-ostream.oo.c"
4 /* Output stream for CSS styled text, producing HTML output.
5 Copyright (C) 2006-2007, 2015 Free Software Foundation, Inc.
6 Written by Bruno Haible <bruno@clisp.org>, 2006.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "html-styled-ostream.h"
31 #include "html-ostream.h"
33 #include "binary-io.h"
39 #include "safe-read.h"
43 #define _(str) gettext (str)
46 #line 47 "html-styled-ostream.c"
48 #define html_styled_ostream_representation any_ostream_representation
50 #include "html_styled_ostream.priv.h"
52 const typeinfo_t html_styled_ostream_typeinfo = { "html_styled_ostream" };
54 static const typeinfo_t * const html_styled_ostream_superclasses[] =
55 { html_styled_ostream_SUPERCLASSES };
57 #define super styled_ostream_vtable
59 #line 51 "html-styled-ostream.oo.c"
61 /* Implementation of ostream_t methods. */
64 html_styled_ostream__write_mem (html_styled_ostream_t stream,
65 const void *data, size_t len)
67 html_ostream_write_mem (stream->html_destination, data, len);
71 html_styled_ostream__flush (html_styled_ostream_t stream)
73 html_ostream_flush (stream->html_destination);
77 html_styled_ostream__free (html_styled_ostream_t stream)
79 html_ostream_free (stream->html_destination);
80 ostream_write_str (stream->destination, "</body>\n");
81 ostream_write_str (stream->destination, "</html>\n");
84 /* Implementation of styled_ostream_t methods. */
87 html_styled_ostream__begin_use_class (html_styled_ostream_t stream,
88 const char *classname)
90 html_ostream_begin_span (stream->html_destination, classname);
94 html_styled_ostream__end_use_class (html_styled_ostream_t stream,
95 const char *classname)
97 html_ostream_end_span (stream->html_destination, classname);
102 html_styled_ostream_t
103 html_styled_ostream_create (ostream_t destination, const char *css_filename)
105 html_styled_ostream_t stream =
106 XMALLOC (struct html_styled_ostream_representation);
108 stream->base.base.vtable = &html_styled_ostream_vtable;
109 stream->destination = destination;
110 stream->html_destination = html_ostream_create (destination);
112 ostream_write_str (stream->destination, "<?xml version=\"1.0\"?>\n");
113 /* HTML 4.01 or XHTML 1.0?
114 Use HTML 4.01. This is conservative. Before switching to XHTML 1.0,
115 verify that in the output
116 - all HTML element names are in lowercase,
117 - all empty elements are denoted like <br/> or <p></p>,
118 - every attribute specification is in assignment form, like
120 - every <a name="..."> element also has an 'id' attribute,
121 - special characters like < > & " are escaped in the <style> and
122 <script> elements. */
123 ostream_write_str (stream->destination,
124 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n");
125 ostream_write_str (stream->destination, "<html>\n");
126 ostream_write_str (stream->destination, "<head>\n");
127 if (css_filename != NULL)
129 ostream_write_str (stream->destination, "<style type=\"text/css\">\n"
132 /* Include the contents of CSS_FILENAME literally. */
137 fd = open (css_filename, O_RDONLY | O_TEXT);
139 error (EXIT_FAILURE, errno,
140 _("error while opening \"%s\" for reading"),
145 size_t n_read = safe_read (fd, buf, sizeof (buf));
146 if (n_read == SAFE_READ_ERROR)
147 error (EXIT_FAILURE, errno, _("error reading \"%s\""),
152 ostream_write_mem (stream->destination, buf, n_read);
156 error (EXIT_FAILURE, errno, _("error after reading \"%s\""),
160 ostream_write_str (stream->destination, "-->\n"
163 ostream_write_str (stream->destination, "</head>\n");
164 ostream_write_str (stream->destination, "<body>\n");
169 #line 170 "html-styled-ostream.c"
171 const struct html_styled_ostream_implementation html_styled_ostream_vtable =
173 html_styled_ostream_superclasses,
174 sizeof (html_styled_ostream_superclasses) / sizeof (html_styled_ostream_superclasses[0]),
175 sizeof (struct html_styled_ostream_representation),
176 html_styled_ostream__write_mem,
177 html_styled_ostream__flush,
178 html_styled_ostream__free,
179 html_styled_ostream__begin_use_class,
180 html_styled_ostream__end_use_class,
185 /* Define the functions that invoke the methods. */
188 html_styled_ostream_write_mem (html_styled_ostream_t first_arg, const void *data, size_t len)
190 const struct html_styled_ostream_implementation *vtable =
191 ((struct html_styled_ostream_representation_header *) (struct html_styled_ostream_representation *) first_arg)->vtable;
192 vtable->write_mem (first_arg,data,len);
196 html_styled_ostream_flush (html_styled_ostream_t first_arg)
198 const struct html_styled_ostream_implementation *vtable =
199 ((struct html_styled_ostream_representation_header *) (struct html_styled_ostream_representation *) first_arg)->vtable;
200 vtable->flush (first_arg);
204 html_styled_ostream_free (html_styled_ostream_t first_arg)
206 const struct html_styled_ostream_implementation *vtable =
207 ((struct html_styled_ostream_representation_header *) (struct html_styled_ostream_representation *) first_arg)->vtable;
208 vtable->free (first_arg);
212 html_styled_ostream_begin_use_class (html_styled_ostream_t first_arg, const char *classname)
214 const struct html_styled_ostream_implementation *vtable =
215 ((struct html_styled_ostream_representation_header *) (struct html_styled_ostream_representation *) first_arg)->vtable;
216 vtable->begin_use_class (first_arg,classname);
220 html_styled_ostream_end_use_class (html_styled_ostream_t first_arg, const char *classname)
222 const struct html_styled_ostream_implementation *vtable =
223 ((struct html_styled_ostream_representation_header *) (struct html_styled_ostream_representation *) first_arg)->vtable;
224 vtable->end_use_class (first_arg,classname);