mirror of
https://https.git.savannah.gnu.org/git/gettext.git
synced 2026-01-26 15:39:11 +00:00
libtextstyle: Add accessor functions.
* libtextstyle/gnulib-local/lib/fd-ostream.oo.h (fd_ostream): New methods get_descriptor, get_filename, is_buffered. * libtextstyle/gnulib-local/lib/fd-ostream.oo.c (fd_ostream::get_descriptor, fd_ostream::get_filename, fd_ostream::is_buffered): New functions. * libtextstyle/gnulib-local/lib/file-ostream.oo.h (file_ostream): New method get_stdio_stream. * libtextstyle/gnulib-local/lib/file-ostream.oo.c (file_ostream::get_stdio_stream): New function. * libtextstyle/gnulib-local/lib/html-ostream.oo.h (html_ostream): New method get_destination. * libtextstyle/gnulib-local/lib/html-ostream.oo.c (html_ostream::get_destination): New function. * libtextstyle/gnulib-local/lib/html-styled-ostream.oo.h: Include html-ostream.h. (html_styled_ostream): New methods get_destination, get_html_destination, get_css_filename. * libtextstyle/gnulib-local/lib/html-styled-ostream.oo.c (html_styled_ostream): Add field 'css_filename'. (html_styled_ostream::free): Free it. (html_styled_ostream_create): Initialize it. (html_styled_ostream::get_destination, html_styled_ostream::get_html_destination, html_styled_ostream::get_css_filename): New functions. * libtextstyle/gnulib-local/lib/iconv-ostream.oo.h (iconv_ostream): New methods get_from_encoding, get_to_encoding, get_destination. * libtextstyle/gnulib-local/lib/iconv-ostream.oo.c (iconv_ostream::get_from_encoding, iconv_ostream::get_to_encoding, iconv_ostream::get_destination): New functions. * libtextstyle/gnulib-local/lib/noop-styled-ostream.oo.h (noop_styled_ostream): New methods get_destination, is_owning_destination. * libtextstyle/gnulib-local/lib/noop-styled-ostream.oo.c (noop_styled_ostream::get_destination, noop_styled_ostream::is_owning_destination): New functions. * libtextstyle/gnulib-local/lib/term-ostream.oo.h (term_ostream): New methods get_descriptor, get_filename, get_tty_control, get_effective_tty_control. * libtextstyle/gnulib-local/lib/term-ostream.oo.c (term_ostream): Add field 'tty_control'. (term_ostream_create): Initialize it. (term_ostream::get_descriptor, term_ostream::get_filename, term_ostream::get_tty_control, term_ostream::get_effective_tty_control): New functions. * libtextstyle/gnulib-local/lib/term-styled-ostream.oo.h (term_styled_ostream): New methods get_destination, get_css_filename. * libtextstyle/gnulib-local/lib/term-styled-ostream.oo.c (term_styled_ostream): Add field 'css_filename'. (term_styled_ostream::free): Free it. (term_styled_ostream_create): Initialize it. (term_styled_ostream::get_destination, term_styled_ostream::get_css_filename): New functions. * libtextstyle/lib/textstyle.h (file_ostream_get_stdio_stream, fd_ostream_get_descriptor, fd_ostream_get_filename, fd_ostream_is_buffered, term_ostream_get_descriptor, term_ostream_get_filename, term_ostream_get_tty_control, term_ostream_get_effective_tty_control, iconv_ostream_get_from_encoding, iconv_ostream_get_to_encoding, iconv_ostream_get_destination, html_ostream_get_destination, term_styled_ostream_get_destination, term_styled_ostream_get_css_filename, html_styled_ostream_get_destination, html_styled_ostream_get_html_destination, html_styled_ostream_get_css_filename, noop_styled_ostream_get_destination, noop_styled_ostream_is_owning_destination): New declarations. * libtextstyle/tests/test-accessors.c: New file. * libtextstyle/tests/Makefile.am: Arrange to compile it. * libtextstyle/doc/libtextstyle.texi (Accessors): New subsection. * libtextstyle/NEWS: Mention the new functions.
This commit is contained in:
parent
31a0933c61
commit
dbfe4daec9
1
libtextstyle/.gitignore
vendored
1
libtextstyle/.gitignore
vendored
@ -239,6 +239,7 @@
|
||||
/lib/xvasprintf.h
|
||||
/tests/
|
||||
!/tests/Makefile.am
|
||||
!/tests/test-accessors.c
|
||||
!/tests/test-instanceof.c
|
||||
|
||||
# Files brought in by "automake --add-missing --copy":
|
||||
|
||||
@ -11,6 +11,27 @@ New in 0.21.1:
|
||||
term_styled_ostream_t is_instance_of_term_styled_ostream
|
||||
html_styled_ostream_t is_instance_of_html_styled_ostream
|
||||
noop_styled_ostream_t is_instance_of_noop_styled_ostream
|
||||
* Added accessor functions:
|
||||
TYPE FUNCTION
|
||||
file_ostream_t file_ostream_get_stdio_stream
|
||||
fd_ostream_t fd_ostream_get_descriptor
|
||||
fd_ostream_t fd_ostream_get_filename
|
||||
fd_ostream_t fd_ostream_is_buffered
|
||||
term_ostream_t term_ostream_get_descriptor
|
||||
term_ostream_t term_ostream_get_filename
|
||||
term_ostream_t term_ostream_get_tty_control
|
||||
term_ostream_t term_ostream_get_effective_tty_control
|
||||
iconv_ostream_t iconv_ostream_get_from_encoding
|
||||
iconv_ostream_t iconv_ostream_get_to_encoding
|
||||
iconv_ostream_t iconv_ostream_get_destination
|
||||
html_ostream_t html_ostream_get_destination
|
||||
term_styled_ostream_t term_styled_ostream_get_destination
|
||||
term_styled_ostream_t term_styled_ostream_get_css_filename
|
||||
html_styled_ostream_t html_styled_ostream_get_destination
|
||||
html_styled_ostream_t html_styled_ostream_get_html_destination
|
||||
html_styled_ostream_t html_styled_ostream_get_css_filename
|
||||
noop_styled_ostream_t noop_styled_ostream_get_destination
|
||||
noop_styled_ostream_t noop_styled_ostream_is_owning_destination
|
||||
|
||||
New in 0.21:
|
||||
* Added support for emitting hyperlinks.
|
||||
|
||||
@ -848,6 +848,7 @@ compatible return type.
|
||||
* The styled_ostream class::
|
||||
* ostream subclasses without styling::
|
||||
* styled_ostream subclasses::
|
||||
* Accessors::
|
||||
@end menu
|
||||
|
||||
@node The ostream class
|
||||
@ -899,7 +900,7 @@ Ends a run of text belonging to @code{@var{classname}}. The
|
||||
@code{styled_ostream_end_use_class} calls must match properly.
|
||||
@end deftypefn
|
||||
|
||||
@deftypefn Function {const char *} styled_ostream_get_hyperlink_ref (styled_ostream_t@tie{}@var{stream})
|
||||
@deftypefn Function {const@tie{}char@tie{}*} styled_ostream_get_hyperlink_ref (styled_ostream_t@tie{}@var{stream})
|
||||
Returns the referred URL of the currently set hyperlink, or @code{NULL}
|
||||
if no hyperlink attribute is currently set.
|
||||
|
||||
@ -907,7 +908,7 @@ Note: The returned string is only valid up to the next invocation of
|
||||
@code{styled_ostream_set_hyperlink}.
|
||||
@end deftypefn
|
||||
|
||||
@deftypefn Function {const char *} styled_ostream_get_hyperlink_id (styled_ostream_t@tie{}@var{stream})
|
||||
@deftypefn Function {const@tie{}char@tie{}*} styled_ostream_get_hyperlink_id (styled_ostream_t@tie{}@var{stream})
|
||||
Returns the id of the currently set hyperlink, or @code{NULL} if no
|
||||
hyperlink attribute is currently set.
|
||||
|
||||
@ -1043,7 +1044,7 @@ Gets/sets the font posture.
|
||||
Gets/sets the text underline decoration.
|
||||
@end deftypefn
|
||||
|
||||
@deftypefn Function {const char *} term_ostream_get_hyperlink_ref (term_ostream_t@tie{}@var{stream})
|
||||
@deftypefn Function {const@tie{}char@tie{}*} term_ostream_get_hyperlink_ref (term_ostream_t@tie{}@var{stream})
|
||||
Returns the referred URL of the currently set hyperlink, or @code{NULL}
|
||||
if no hyperlink attribute is currently set.
|
||||
|
||||
@ -1051,7 +1052,7 @@ Note: The returned string is only valid up to the next invocation of
|
||||
@code{term_ostream_set_hyperlink}.
|
||||
@end deftypefn
|
||||
|
||||
@deftypefn Function {const char *} term_ostream_get_hyperlink_id (term_ostream_t@tie{}@var{stream})
|
||||
@deftypefn Function {const@tie{}char@tie{}*} term_ostream_get_hyperlink_id (term_ostream_t@tie{}@var{stream})
|
||||
Returns the id of the currently set hyperlink, or @code{NULL} if no
|
||||
hyperlink attribute is currently set.
|
||||
|
||||
@ -1121,7 +1122,7 @@ The @code{html_ostream_begin_span} / @code{html_ostream_end_span} calls
|
||||
must match properly.
|
||||
@end deftypefn
|
||||
|
||||
@deftypefn Function {const char *} html_ostream_get_hyperlink_ref (html_ostream_t@tie{}@var{stream})
|
||||
@deftypefn Function {const@tie{}char@tie{}*} html_ostream_get_hyperlink_ref (html_ostream_t@tie{}@var{stream})
|
||||
Returns the referred URL of the currently set hyperlink, or @code{NULL}
|
||||
if no hyperlink attribute is currently set.
|
||||
|
||||
@ -1282,6 +1283,80 @@ Note: If @code{@var{pass_ownership}} is @code{false}, the resulting stream
|
||||
must be closed before @code{@var{destination}} can be closed.
|
||||
@end deftypefn
|
||||
|
||||
@node Accessors
|
||||
@subsection Accessor functions
|
||||
|
||||
The various concrete stream classes have methods that allow you to retrieve
|
||||
the arguments passed to the respective constructor function.
|
||||
|
||||
Note: While these methods allow you to retrieve the underlying destination
|
||||
stream of various kinds of stream, it is not recommended to operate on both
|
||||
the stream and its underlying destination stream at the same time. Doing
|
||||
so can lead to undesired interactions between the two streams.
|
||||
|
||||
The @code{file_ostream} class has this accessor method:
|
||||
|
||||
@deftypefn Function {FILE@tie{}*} file_ostream_get_stdio_stream (file_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
|
||||
The @code{fd_ostream} class has these accessor methods:
|
||||
|
||||
@deftypefn Function int fd_ostream_get_descriptor (fd_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
@deftypefn Function {const@tie{}char@tie{}*} fd_ostream_get_filename (fd_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
@deftypefn Function bool fd_ostream_is_buffered (fd_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
|
||||
The @code{term_ostream} class has these accessor methods:
|
||||
|
||||
@deftypefn Function int term_ostream_get_descriptor (term_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
@deftypefn Function {const@tie{}char@tie{}*} term_ostream_get_filename (term_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
@deftypefn Function ttyctl_t term_ostream_get_tty_control (term_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
@deftypefn Function ttyctl_t term_ostream_get_effective_tty_control (term_ostream_t@tie{}@var{stream})
|
||||
Returns the effective tty control of the stream (not @code{TTYCTL_AUTO}).
|
||||
@end deftypefn
|
||||
|
||||
The @code{iconv_ostream} class has these accessor methods:
|
||||
|
||||
@deftypefn Function {const@tie{}char@tie{}*} iconv_ostream_get_from_encoding (iconv_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
@deftypefn Function {const@tie{}char@tie{}*} iconv_ostream_get_to_encoding (iconv_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
@deftypefn Function ostream_t iconv_ostream_get_destination (iconv_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
|
||||
The @code{html_ostream} class has this accessor method:
|
||||
|
||||
@deftypefn Function ostream_t html_ostream_get_destination (html_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
|
||||
The @code{term_styled_ostream} class has these accessor methods:
|
||||
|
||||
@deftypefn Function term_ostream_t term_styled_ostream_get_destination (term_styled_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
@deftypefn Function {const@tie{}char@tie{}*} term_styled_ostream_get_css_filename (term_styled_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
|
||||
The @code{html_styled_ostream} class has these accessor methods:
|
||||
|
||||
@deftypefn Function ostream_t html_styled_ostream_get_destination (html_styled_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
@deftypefn Function html_ostream_t html_styled_ostream_get_html_destination (html_styled_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
@deftypefn Function {const@tie{}char@tie{}*} html_styled_ostream_get_css_filename (html_styled_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
|
||||
The @code{noop_styled_ostream} class has these accessor methods:
|
||||
|
||||
@deftypefn Function ostream_t noop_styled_ostream_get_destination (noop_styled_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
@deftypefn Function bool noop_styled_ostream_is_owning_destination (noop_styled_ostream_t@tie{}@var{stream})
|
||||
@end deftypefn
|
||||
|
||||
@node Debugging the styling code
|
||||
@section Debugging the text styling support
|
||||
|
||||
|
||||
@ -200,6 +200,26 @@ fd_ostream_create (int fd, const char *filename, bool buffered)
|
||||
return stream;
|
||||
}
|
||||
|
||||
/* Accessors. */
|
||||
|
||||
static int
|
||||
fd_ostream::get_descriptor (fd_ostream_t stream)
|
||||
{
|
||||
return stream->fd;
|
||||
}
|
||||
|
||||
static const char *
|
||||
fd_ostream::get_filename (fd_ostream_t stream)
|
||||
{
|
||||
return stream->filename;
|
||||
}
|
||||
|
||||
static bool
|
||||
fd_ostream::is_buffered (fd_ostream_t stream)
|
||||
{
|
||||
return stream->buffer != NULL;
|
||||
}
|
||||
|
||||
/* Instanceof test. */
|
||||
|
||||
bool
|
||||
|
||||
@ -26,6 +26,10 @@
|
||||
struct fd_ostream : struct ostream
|
||||
{
|
||||
methods:
|
||||
/* Accessors. */
|
||||
int get_descriptor (fd_ostream_t stream);
|
||||
const char * get_filename (fd_ostream_t stream);
|
||||
bool is_buffered (fd_ostream_t stream);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -107,6 +107,14 @@ file_ostream_create (FILE *fp)
|
||||
return stream;
|
||||
}
|
||||
|
||||
/* Accessors. */
|
||||
|
||||
static FILE *
|
||||
file_ostream::get_stdio_stream (file_ostream_t stream)
|
||||
{
|
||||
return stream->fp;
|
||||
}
|
||||
|
||||
/* Instanceof test. */
|
||||
|
||||
bool
|
||||
|
||||
@ -27,6 +27,8 @@
|
||||
struct file_ostream : struct ostream
|
||||
{
|
||||
methods:
|
||||
/* Accessors. */
|
||||
FILE * get_stdio_stream (file_ostream_t stream);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -437,6 +437,14 @@ html_ostream_create (ostream_t destination)
|
||||
return stream;
|
||||
}
|
||||
|
||||
/* Accessors. */
|
||||
|
||||
static ostream_t
|
||||
html_ostream::get_destination (html_ostream_t stream)
|
||||
{
|
||||
return stream->destination;
|
||||
}
|
||||
|
||||
/* Instanceof test. */
|
||||
|
||||
bool
|
||||
|
||||
@ -47,6 +47,9 @@ methods:
|
||||
to the underlying stream, and they will be rendered like strings passed
|
||||
to 'ostream_write_mem', 'ostream_write_str', or 'ostream_write_printf'. */
|
||||
void flush_to_current_style (html_ostream_t stream);
|
||||
|
||||
/* Accessors. */
|
||||
ostream_t get_destination (html_ostream_t stream);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -45,6 +45,8 @@ struct html_styled_ostream : struct styled_ostream
|
||||
fields:
|
||||
/* The destination stream. */
|
||||
ostream_t destination;
|
||||
/* The CSS filename. */
|
||||
char *css_filename;
|
||||
/* A HTML aware wrapper around the destination stream. */
|
||||
html_ostream_t html_destination;
|
||||
/* The current hyperlink id. */
|
||||
@ -73,6 +75,7 @@ html_styled_ostream::free (html_styled_ostream_t stream)
|
||||
ostream_write_str (stream->destination, "</body>\n");
|
||||
ostream_write_str (stream->destination, "</html>\n");
|
||||
free (stream->hyperlink_id);
|
||||
free (stream->css_filename);
|
||||
free (stream);
|
||||
}
|
||||
|
||||
@ -131,6 +134,7 @@ html_styled_ostream_create (ostream_t destination, const char *css_filename)
|
||||
|
||||
stream->base.base.vtable = &html_styled_ostream_vtable;
|
||||
stream->destination = destination;
|
||||
stream->css_filename = xstrdup (css_filename);
|
||||
stream->html_destination = html_ostream_create (destination);
|
||||
stream->hyperlink_id = NULL;
|
||||
|
||||
@ -191,6 +195,26 @@ html_styled_ostream_create (ostream_t destination, const char *css_filename)
|
||||
return stream;
|
||||
}
|
||||
|
||||
/* Accessors. */
|
||||
|
||||
static ostream_t
|
||||
html_styled_ostream::get_destination (html_styled_ostream_t stream)
|
||||
{
|
||||
return stream->destination;
|
||||
}
|
||||
|
||||
static html_ostream_t
|
||||
html_styled_ostream::get_html_destination (html_styled_ostream_t stream)
|
||||
{
|
||||
return stream->html_destination;
|
||||
}
|
||||
|
||||
static const char *
|
||||
html_styled_ostream::get_css_filename (html_styled_ostream_t stream)
|
||||
{
|
||||
return stream->css_filename;
|
||||
}
|
||||
|
||||
/* Instanceof test. */
|
||||
|
||||
bool
|
||||
|
||||
@ -21,11 +21,16 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "styled-ostream.h"
|
||||
#include "html-ostream.h"
|
||||
|
||||
|
||||
struct html_styled_ostream : struct styled_ostream
|
||||
{
|
||||
methods:
|
||||
/* Accessors. */
|
||||
ostream_t get_destination (html_styled_ostream_t stream);
|
||||
html_ostream_t get_html_destination (html_styled_ostream_t stream);
|
||||
const char * get_css_filename (html_styled_ostream_t stream);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -222,6 +222,26 @@ iconv_ostream_create (const char *from_encoding, const char *to_encoding,
|
||||
return stream;
|
||||
}
|
||||
|
||||
/* Accessors. */
|
||||
|
||||
static const char *
|
||||
iconv_ostream::get_from_encoding (iconv_ostream_t stream)
|
||||
{
|
||||
return stream->from_encoding;
|
||||
}
|
||||
|
||||
static const char *
|
||||
iconv_ostream::get_to_encoding (iconv_ostream_t stream)
|
||||
{
|
||||
return stream->to_encoding;
|
||||
}
|
||||
|
||||
static ostream_t
|
||||
iconv_ostream::get_destination (iconv_ostream_t stream)
|
||||
{
|
||||
return stream->destination;
|
||||
}
|
||||
|
||||
/* Instanceof test. */
|
||||
|
||||
bool
|
||||
@ -250,6 +270,26 @@ iconv_ostream::free (iconv_ostream_t stream)
|
||||
abort ();
|
||||
}
|
||||
|
||||
/* Accessors. */
|
||||
|
||||
static const char *
|
||||
iconv_ostream::get_from_encoding (iconv_ostream_t stream)
|
||||
{
|
||||
abort ();
|
||||
}
|
||||
|
||||
static const char *
|
||||
iconv_ostream::get_to_encoding (iconv_ostream_t stream)
|
||||
{
|
||||
abort ();
|
||||
}
|
||||
|
||||
static ostream_t
|
||||
iconv_ostream::get_destination (iconv_ostream_t stream)
|
||||
{
|
||||
abort ();
|
||||
}
|
||||
|
||||
/* Instanceof test. */
|
||||
|
||||
bool
|
||||
|
||||
@ -29,6 +29,10 @@
|
||||
struct iconv_ostream : struct ostream
|
||||
{
|
||||
methods:
|
||||
/* Accessors. */
|
||||
const char * get_from_encoding (iconv_ostream_t stream);
|
||||
const char * get_to_encoding (iconv_ostream_t stream);
|
||||
ostream_t get_destination (iconv_ostream_t stream);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -122,6 +122,20 @@ noop_styled_ostream_create (ostream_t destination, bool pass_ownership)
|
||||
return stream;
|
||||
}
|
||||
|
||||
/* Accessors. */
|
||||
|
||||
static ostream_t
|
||||
noop_styled_ostream::get_destination (noop_styled_ostream_t stream)
|
||||
{
|
||||
return stream->destination;
|
||||
}
|
||||
|
||||
static bool
|
||||
noop_styled_ostream::is_owning_destination (noop_styled_ostream_t stream)
|
||||
{
|
||||
return stream->own_destination;
|
||||
}
|
||||
|
||||
/* Instanceof test. */
|
||||
|
||||
bool
|
||||
|
||||
@ -26,6 +26,9 @@
|
||||
struct noop_styled_ostream : struct styled_ostream
|
||||
{
|
||||
methods:
|
||||
/* Accessors. */
|
||||
ostream_t get_destination (noop_styled_ostream_t stream);
|
||||
bool is_owning_destination (noop_styled_ostream_t stream);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -1041,6 +1041,7 @@ fields:
|
||||
bool volatile is_windows_console;
|
||||
#endif
|
||||
char *filename;
|
||||
ttyctl_t tty_control;
|
||||
/* Values from the terminal type's terminfo/termcap description.
|
||||
See terminfo(5) for details. */
|
||||
/* terminfo termcap */
|
||||
@ -2422,6 +2423,7 @@ term_ostream_create (int fd, const char *filename, ttyctl_t tty_control)
|
||||
}
|
||||
#endif
|
||||
stream->filename = xstrdup (filename);
|
||||
stream->tty_control = tty_control;
|
||||
|
||||
/* Defaults. */
|
||||
stream->max_colors = -1;
|
||||
@ -2741,6 +2743,32 @@ term_ostream_create (int fd, const char *filename, ttyctl_t tty_control)
|
||||
return stream;
|
||||
}
|
||||
|
||||
/* Accessors. */
|
||||
|
||||
static int
|
||||
term_ostream::get_descriptor (term_ostream_t stream)
|
||||
{
|
||||
return stream->fd;
|
||||
}
|
||||
|
||||
static const char *
|
||||
term_ostream::get_filename (term_ostream_t stream)
|
||||
{
|
||||
return stream->filename;
|
||||
}
|
||||
|
||||
static ttyctl_t
|
||||
term_ostream::get_tty_control (term_ostream_t stream)
|
||||
{
|
||||
return stream->tty_control;
|
||||
}
|
||||
|
||||
static ttyctl_t
|
||||
term_ostream::get_effective_tty_control (term_ostream_t stream)
|
||||
{
|
||||
return stream->control_data.tty_control;
|
||||
}
|
||||
|
||||
/* Instanceof test. */
|
||||
|
||||
bool
|
||||
|
||||
@ -60,6 +60,10 @@ typedef enum
|
||||
UNDERLINE_DEFAULT = UNDERLINE_OFF
|
||||
} term_underline_t;
|
||||
|
||||
/* Get ttyctl_t. */
|
||||
#define term_style_user_data term_ostream_representation
|
||||
#include "term-style-control.h"
|
||||
|
||||
struct term_ostream : struct ostream
|
||||
{
|
||||
methods:
|
||||
@ -104,11 +108,13 @@ methods:
|
||||
passed to 'ostream_write_mem', 'ostream_write_str', or
|
||||
'ostream_write_printf'. */
|
||||
void flush_to_current_style (term_ostream_t stream);
|
||||
};
|
||||
|
||||
/* Get ttyctl_t. */
|
||||
#define term_style_user_data term_ostream_representation
|
||||
#include "term-style-control.h"
|
||||
/* Accessors. */
|
||||
int get_descriptor (term_ostream_t stream);
|
||||
const char * get_filename (term_ostream_t stream);
|
||||
ttyctl_t get_tty_control (term_ostream_t stream);
|
||||
ttyctl_t get_effective_tty_control (term_ostream_t stream);
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -64,6 +64,8 @@ struct term_styled_ostream : struct styled_ostream
|
||||
fields:
|
||||
/* The destination stream. */
|
||||
term_ostream_t destination;
|
||||
/* The CSS filename. */
|
||||
char *css_filename;
|
||||
/* The CSS document. */
|
||||
CRCascade *css_document;
|
||||
/* The CSS matching engine. */
|
||||
@ -104,6 +106,7 @@ term_styled_ostream::flush (term_styled_ostream_t stream, ostream_flush_scope_t
|
||||
static void
|
||||
term_styled_ostream::free (term_styled_ostream_t stream)
|
||||
{
|
||||
free (stream->css_filename);
|
||||
term_ostream_free (stream->destination);
|
||||
cr_cascade_destroy (stream->css_document);
|
||||
cr_sel_eng_destroy (stream->css_engine);
|
||||
@ -645,11 +648,13 @@ term_styled_ostream_create (int fd, const char *filename, ttyctl_t tty_control,
|
||||
|
||||
stream->base.base.vtable = &term_styled_ostream_vtable;
|
||||
stream->destination = term_ostream_create (fd, filename, tty_control);
|
||||
stream->css_filename = xstrdup (css_filename);
|
||||
|
||||
if (cr_om_parser_simply_parse_file ((const guchar *) css_filename,
|
||||
CR_UTF_8, /* CR_AUTO is not supported */
|
||||
&css_file_contents) != CR_OK)
|
||||
{
|
||||
free (stream->css_filename);
|
||||
term_ostream_free (stream->destination);
|
||||
free (stream);
|
||||
return NULL;
|
||||
@ -668,6 +673,20 @@ term_styled_ostream_create (int fd, const char *filename, ttyctl_t tty_control,
|
||||
return stream;
|
||||
}
|
||||
|
||||
/* Accessors. */
|
||||
|
||||
static term_ostream_t
|
||||
term_styled_ostream::get_destination (term_styled_ostream_t stream)
|
||||
{
|
||||
return stream->destination;
|
||||
}
|
||||
|
||||
static const char *
|
||||
term_styled_ostream::get_css_filename (term_styled_ostream_t stream)
|
||||
{
|
||||
return stream->css_filename;
|
||||
}
|
||||
|
||||
/* Instanceof test. */
|
||||
|
||||
bool
|
||||
|
||||
@ -27,6 +27,9 @@
|
||||
struct term_styled_ostream : struct styled_ostream
|
||||
{
|
||||
methods:
|
||||
/* Accessors. */
|
||||
term_ostream_t get_destination (term_styled_ostream_t stream);
|
||||
const char * get_css_filename (term_styled_ostream_t stream);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -148,6 +148,8 @@ extern "C" {
|
||||
extern void file_ostream_write_mem (file_ostream_t first_arg, const void *data, size_t len);
|
||||
extern void file_ostream_flush (file_ostream_t first_arg, ostream_flush_scope_t scope);
|
||||
extern void file_ostream_free (file_ostream_t first_arg);
|
||||
/* Accessors. */
|
||||
extern FILE *file_ostream_get_stdio_stream (file_ostream_t stream);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -182,6 +184,10 @@ extern "C" {
|
||||
extern void fd_ostream_write_mem (fd_ostream_t first_arg, const void *data, size_t len);
|
||||
extern void fd_ostream_flush (fd_ostream_t first_arg, ostream_flush_scope_t scope);
|
||||
extern void fd_ostream_free (fd_ostream_t first_arg);
|
||||
/* Accessors. */
|
||||
extern int fd_ostream_get_descriptor (fd_ostream_t stream);
|
||||
extern const char *fd_ostream_get_filename (fd_ostream_t stream);
|
||||
extern bool fd_ostream_is_buffered (fd_ostream_t stream);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -245,6 +251,26 @@ typedef enum
|
||||
UNDERLINE_DEFAULT = UNDERLINE_OFF
|
||||
} term_underline_t;
|
||||
|
||||
/* The amount of control to take over the underlying tty in order to avoid
|
||||
garbled output on the screen, due to interleaved output of escape sequences
|
||||
and output from the kernel (such as when the kernel echoes user's input
|
||||
or when the kernel prints '^C' after the user pressed Ctrl-C). */
|
||||
typedef enum
|
||||
{
|
||||
TTYCTL_AUTO = 0, /* Automatic best-possible choice. */
|
||||
TTYCTL_NONE, /* No control.
|
||||
Result: Garbled output can occur, and the terminal can
|
||||
be left in any state when the program is interrupted. */
|
||||
TTYCTL_PARTIAL, /* Signal handling.
|
||||
Result: Garbled output can occur, but the terminal will
|
||||
be left in the default state when the program is
|
||||
interrupted. */
|
||||
TTYCTL_FULL /* Signal handling and disabling echo and flush-upon-signal.
|
||||
Result: No garbled output, and the the terminal will
|
||||
be left in the default state when the program is
|
||||
interrupted. */
|
||||
} ttyctl_t;
|
||||
|
||||
/* term_ostream_t is a subtype of ostream_t. */
|
||||
typedef ostream_t term_ostream_t;
|
||||
|
||||
@ -277,30 +303,15 @@ extern void term_ostream_set_hyperlink (term_ostream_t first_arg, const char *re
|
||||
passed to 'ostream_write_mem', 'ostream_write_str', or
|
||||
'ostream_write_printf'. */
|
||||
extern void term_ostream_flush_to_current_style (term_ostream_t first_arg);
|
||||
/* Accessors. */
|
||||
extern int term_ostream_get_descriptor (term_ostream_t stream);
|
||||
extern const char *term_ostream_get_filename (term_ostream_t stream);
|
||||
extern ttyctl_t term_ostream_get_tty_control (term_ostream_t stream);
|
||||
extern ttyctl_t term_ostream_get_effective_tty_control (term_ostream_t stream);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* The amount of control to take over the underlying tty in order to avoid
|
||||
garbled output on the screen, due to interleaved output of escape sequences
|
||||
and output from the kernel (such as when the kernel echoes user's input
|
||||
or when the kernel prints '^C' after the user pressed Ctrl-C). */
|
||||
typedef enum
|
||||
{
|
||||
TTYCTL_AUTO = 0, /* Automatic best-possible choice. */
|
||||
TTYCTL_NONE, /* No control.
|
||||
Result: Garbled output can occur, and the terminal can
|
||||
be left in any state when the program is interrupted. */
|
||||
TTYCTL_PARTIAL, /* Signal handling.
|
||||
Result: Garbled output can occur, but the terminal will
|
||||
be left in the default state when the program is
|
||||
interrupted. */
|
||||
TTYCTL_FULL /* Signal handling and disabling echo and flush-upon-signal.
|
||||
Result: No garbled output, and the the terminal will
|
||||
be left in the default state when the program is
|
||||
interrupted. */
|
||||
} ttyctl_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -371,6 +382,10 @@ extern "C" {
|
||||
extern void iconv_ostream_write_mem (iconv_ostream_t first_arg, const void *data, size_t len);
|
||||
extern void iconv_ostream_flush (iconv_ostream_t first_arg, ostream_flush_scope_t scope);
|
||||
extern void iconv_ostream_free (iconv_ostream_t first_arg);
|
||||
/* Accessors. */
|
||||
extern const char *iconv_ostream_get_from_encoding (iconv_ostream_t stream);
|
||||
extern const char *iconv_ostream_get_to_encoding (iconv_ostream_t stream);
|
||||
extern ostream_t iconv_ostream_get_destination (iconv_ostream_t stream);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -420,6 +435,8 @@ extern void html_ostream_set_hyperlink_ref (html_ostream_t first_arg, const char
|
||||
to the underlying stream, and they will be rendered like strings passed
|
||||
to 'ostream_write_mem', 'ostream_write_str', or 'ostream_write_printf'. */
|
||||
extern void html_ostream_flush_to_current_style (html_ostream_t stream);
|
||||
/* Accessors. */
|
||||
extern ostream_t html_ostream_get_destination (html_ostream_t stream);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -465,6 +482,9 @@ extern const char *term_styled_ostream_get_hyperlink_ref (term_styled_ostream_t
|
||||
extern const char *term_styled_ostream_get_hyperlink_id (term_styled_ostream_t first_arg);
|
||||
extern void term_styled_ostream_set_hyperlink (term_styled_ostream_t first_arg, const char *ref, const char *id);
|
||||
extern void term_styled_ostream_flush_to_current_style (term_styled_ostream_t first_arg);
|
||||
/* Accessors. */
|
||||
extern term_ostream_t term_styled_ostream_get_destination (term_styled_ostream_t stream);
|
||||
extern const char *term_styled_ostream_get_css_filename (term_styled_ostream_t stream);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -512,6 +532,10 @@ extern const char *html_styled_ostream_get_hyperlink_ref (html_styled_ostream_t
|
||||
extern const char *html_styled_ostream_get_hyperlink_id (html_styled_ostream_t first_arg);
|
||||
extern void html_styled_ostream_set_hyperlink (html_styled_ostream_t first_arg, const char *ref, const char *id);
|
||||
extern void html_styled_ostream_flush_to_current_style (html_styled_ostream_t first_arg);
|
||||
/* Accessors. */
|
||||
extern ostream_t html_styled_ostream_get_destination (html_styled_ostream_t stream);
|
||||
extern html_ostream_t html_styled_ostream_get_html_destination (html_styled_ostream_t stream);
|
||||
extern const char *html_styled_ostream_get_css_filename (html_styled_ostream_t stream);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -556,6 +580,9 @@ extern const char *noop_styled_ostream_get_hyperlink_ref (noop_styled_ostream_t
|
||||
extern const char *noop_styled_ostream_get_hyperlink_id (noop_styled_ostream_t first_arg);
|
||||
extern void noop_styled_ostream_set_hyperlink (noop_styled_ostream_t first_arg, const char *ref, const char *id);
|
||||
extern void noop_styled_ostream_flush_to_current_style (noop_styled_ostream_t first_arg);
|
||||
/* Accessors. */
|
||||
extern ostream_t noop_styled_ostream_get_destination (noop_styled_ostream_t stream);
|
||||
extern bool noop_styled_ostream_is_owning_destination (noop_styled_ostream_t stream);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -24,9 +24,15 @@ AUTOMAKE_OPTIONS += 1.13 subdir-objects color-tests
|
||||
# Ensure that ../lib/config.h is seen before ../config.h.
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/lib -I$(top_builddir)
|
||||
|
||||
TESTS += test-instanceof
|
||||
check_PROGRAMS += test-instanceof
|
||||
EXTRA_DIST += test-instanceof.c
|
||||
TESTS += \
|
||||
test-instanceof \
|
||||
test-accessors
|
||||
check_PROGRAMS += \
|
||||
test-instanceof \
|
||||
test-accessors
|
||||
EXTRA_DIST += \
|
||||
test-instanceof.c \
|
||||
test-accessors.c
|
||||
AM_CPPFLAGS += -DSRCDIR=\"$(srcdir)/\"
|
||||
|
||||
|
||||
|
||||
100
libtextstyle/tests/test-accessors.c
Normal file
100
libtextstyle/tests/test-accessors.c
Normal file
@ -0,0 +1,100 @@
|
||||
/* Test for the various accessor functions. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "textstyle.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define ASSERT(x) if (!(x)) abort ()
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
{
|
||||
ostream_t stream = file_ostream_create (stdout);
|
||||
|
||||
ASSERT (file_ostream_get_stdio_stream (stream) == stdout);
|
||||
|
||||
ostream_free (stream);
|
||||
}
|
||||
{
|
||||
ostream_t stream = fd_ostream_create (1, "(stdout)", false);
|
||||
|
||||
ASSERT (fd_ostream_get_descriptor (stream) == 1);
|
||||
ASSERT (strcmp (fd_ostream_get_filename (stream), "(stdout)") == 0);
|
||||
ASSERT (! fd_ostream_is_buffered (stream));
|
||||
|
||||
ostream_free (stream);
|
||||
}
|
||||
{
|
||||
ostream_t stream = term_ostream_create (1, "(stdout)", TTYCTL_AUTO);
|
||||
|
||||
ASSERT (term_ostream_get_descriptor (stream) == 1);
|
||||
ASSERT (strcmp (term_ostream_get_filename (stream), "(stdout)") == 0);
|
||||
ASSERT (term_ostream_get_tty_control (stream) == TTYCTL_AUTO);
|
||||
ASSERT (term_ostream_get_effective_tty_control (stream) == TTYCTL_FULL);
|
||||
|
||||
ostream_free (stream);
|
||||
}
|
||||
#if LIBTEXTSTYLE_USES_ICONV
|
||||
{
|
||||
ostream_t stream1 = file_ostream_create (stdout);
|
||||
ostream_t stream = iconv_ostream_create ("ISO-8859-1", "UTF-8", stream1);
|
||||
ASSERT (strcmp (iconv_ostream_get_from_encoding (stream), "ISO-8859-1") == 0);
|
||||
ASSERT (strcmp (iconv_ostream_get_to_encoding (stream), "UTF-8") == 0);
|
||||
ASSERT (iconv_ostream_get_destination (stream) == stream1);
|
||||
|
||||
ostream_free (stream);
|
||||
ostream_free (stream1);
|
||||
}
|
||||
#endif
|
||||
{
|
||||
ostream_t stream1 = file_ostream_create (stdout);
|
||||
ostream_t stream = html_ostream_create (stream1);
|
||||
|
||||
ASSERT (html_ostream_get_destination (stream) == stream1);
|
||||
|
||||
ostream_free (stream);
|
||||
ostream_free (stream1);
|
||||
}
|
||||
{
|
||||
ostream_t stream =
|
||||
term_styled_ostream_create (1, "(stdout)", TTYCTL_AUTO,
|
||||
SRCDIR "../adhoc-tests/hello-default.css");
|
||||
|
||||
ASSERT (is_instance_of_term_ostream (term_styled_ostream_get_destination (stream)));
|
||||
ASSERT (strcmp (term_styled_ostream_get_css_filename (stream),
|
||||
SRCDIR "../adhoc-tests/hello-default.css") == 0);
|
||||
|
||||
ostream_free (stream);
|
||||
}
|
||||
{
|
||||
ostream_t stream1 = file_ostream_create (stdout);
|
||||
ostream_t stream =
|
||||
html_styled_ostream_create (stream1,
|
||||
SRCDIR "../adhoc-tests/hello-default.css");
|
||||
|
||||
ASSERT (html_styled_ostream_get_destination (stream) == stream1);
|
||||
ASSERT (is_instance_of_html_ostream (html_styled_ostream_get_html_destination (stream)));
|
||||
ASSERT (strcmp (html_styled_ostream_get_css_filename (stream),
|
||||
SRCDIR "../adhoc-tests/hello-default.css") == 0);
|
||||
|
||||
ostream_free (stream);
|
||||
ostream_free (stream1);
|
||||
}
|
||||
{
|
||||
ostream_t stream1 = file_ostream_create (stdout);
|
||||
ostream_t stream = noop_styled_ostream_create (stream1, false);
|
||||
|
||||
ASSERT (noop_styled_ostream_get_destination (stream) == stream1);
|
||||
ASSERT (!noop_styled_ostream_is_owning_destination (stream));
|
||||
|
||||
ostream_free (stream);
|
||||
ostream_free (stream1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user