]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libtextstyle: Add accessor functions.
authorBruno Haible <bruno@clisp.org>
Tue, 15 Dec 2020 20:03:50 +0000 (21:03 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 15 Dec 2020 20:07:57 +0000 (21:07 +0100)
* 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.

22 files changed:
libtextstyle/.gitignore
libtextstyle/NEWS
libtextstyle/doc/libtextstyle.texi
libtextstyle/gnulib-local/lib/fd-ostream.oo.c
libtextstyle/gnulib-local/lib/fd-ostream.oo.h
libtextstyle/gnulib-local/lib/file-ostream.oo.c
libtextstyle/gnulib-local/lib/file-ostream.oo.h
libtextstyle/gnulib-local/lib/html-ostream.oo.c
libtextstyle/gnulib-local/lib/html-ostream.oo.h
libtextstyle/gnulib-local/lib/html-styled-ostream.oo.c
libtextstyle/gnulib-local/lib/html-styled-ostream.oo.h
libtextstyle/gnulib-local/lib/iconv-ostream.oo.c
libtextstyle/gnulib-local/lib/iconv-ostream.oo.h
libtextstyle/gnulib-local/lib/noop-styled-ostream.oo.c
libtextstyle/gnulib-local/lib/noop-styled-ostream.oo.h
libtextstyle/gnulib-local/lib/term-ostream.oo.c
libtextstyle/gnulib-local/lib/term-ostream.oo.h
libtextstyle/gnulib-local/lib/term-styled-ostream.oo.c
libtextstyle/gnulib-local/lib/term-styled-ostream.oo.h
libtextstyle/lib/textstyle.h
libtextstyle/tests/Makefile.am
libtextstyle/tests/test-accessors.c [new file with mode: 0644]

index 9666781ba79c065fe9ad0a390d5db7bd79c182ed..8acc5a615bd909fbe037067869b1cc8da495c215 100644 (file)
 /lib/xvasprintf.h
 /tests/
 !/tests/Makefile.am
+!/tests/test-accessors.c
 !/tests/test-instanceof.c
 
 # Files brought in by "automake --add-missing --copy":
index 953c7ab54901207b256336715fc82f9ea57f5e67..90e3ac1129b5079c04579f6163b501ffff553a70 100644 (file)
@@ -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.
index d45aeb736b6f79ed708b4a500cc6f86f62c8d042..356903b98fcfb8730b25703de2bccaf013dda01e 100644 (file)
@@ -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
 
index f5aa13495819138781272f3c98527ae177062c58..3bf0c2070eea684b5e8855f2a3d1a2f2050a6a4a 100644 (file)
@@ -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
index 71b82100e76f57ac84053ac789a558f301f67590..e95d0dbe838aedde28a3d65338f47b8f6440d617 100644 (file)
 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);
 };
 
 
index 0937191b60a5c09a03baef6b5281812eb38598f3..95fcec9c9b1ec29fbf06c330041b66975f9ea466 100644 (file)
@@ -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
index cbc7da611fc6adba11fb9cb65264c37e47fed48d..a5ecfaf797a3ffac696fa6fe79903025220a30b4 100644 (file)
@@ -27,6 +27,8 @@
 struct file_ostream : struct ostream
 {
 methods:
+  /* Accessors.  */
+  FILE * get_stdio_stream (file_ostream_t stream);
 };
 
 
index 9a613e33c0ebc68a7afb49e530564584df11fb51..ea00ba563b8d2acab5071a8504e13e2d269e2465 100644 (file)
@@ -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
index 987fbb2719547681e16ffd92d9e18b228547f6b2..58270d3c6d3de49aed238cec80d0386596dffb50 100644 (file)
@@ -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);
 };
 
 
index a78740ab605db8841899387bf6c8331dee6c0390..562fc5661ba38bb2a6f47d31133478234168905f 100644 (file)
@@ -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
index 74fe376ad57edc4f698b46e23f2d81f1fe7f3e43..5fcd239f749769d8297974b108efe013fe056ab6 100644 (file)
 #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);
 };
 
 
index 3e9f7a59e0db25ad867ce5e0f6ef8828986cc7a7..70e1f7d26c4ece7acbda8b7cdd6b2d4e5ce61ccc 100644 (file)
@@ -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
index a2a87057307af0e295cfb82215f0c7118f59fe69..90b6e43a2db1e64ebb68274bfd31fe11e779b4f4 100644 (file)
 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);
 };
 
 
index 7ef0f5d64d3a3e7a77d1a320e4cc39a64784dfb1..4a57566956f4248767150ab6fc77ca58d3deacf9 100644 (file)
@@ -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
index 4a57e54626d2fa21542f9191f9e142bc46461452..a93d886523c81bd49201dafb6dc45682378f5096 100644 (file)
@@ -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);
 };
 
 
index 02e873eac3d5ec0c5dac02ca86e4f30c6bc628d0..7d91650126dcc1d9aa013552ec812dfe96ea462f 100644 (file)
@@ -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
index 949649f045077e5bdfe222faf15fc0feff283d6a..81c1a5408127d2f8d7bd6b2e53ab0c8cc14cf57b 100644 (file)
@@ -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
index 3ed00d1d6d8c490e67f7c470ff30f58d6998f09a..c23ed773c99b5fa535d86abd99412e0d3ca83a7a 100644 (file)
@@ -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
index 59f441ec0211cb6983c157d841d7e184e2d88316..5bd278045b748c8baf5d20cb6efd02c8bc8d1c4f 100644 (file)
@@ -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);
 };
 
 
index 2cf56b1c54ad6d5bc008fb80a0e9d49dbc579c55..4ab09fdcfbd552705dae2afe4e2f0b3c9f414394 100644 (file)
@@ -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
index dd3ad6f90830c7ea58548a96f62ff6777b4bd693..853d8f785996bb3329e02360934438b0e69d4b78 100644 (file)
@@ -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)/\"
 
 
diff --git a/libtextstyle/tests/test-accessors.c b/libtextstyle/tests/test-accessors.c
new file mode 100644 (file)
index 0000000..131da0c
--- /dev/null
@@ -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;
+}