From e666ff0ed68dfc1ff6543a89d7000cb699dca170 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 9 Feb 2019 19:16:53 +0100 Subject: [PATCH] gnulib-local: New module 'fd-styled-ostream'. * gnulib-local/lib/fd-styled-ostream.oo.h: New file. * gnulib-local/lib/fd-styled-ostream.oo.c: New file. * gnulib-local/modules/fd-styled-ostream: New file. * gnulib-local/Makefile.am (EXTRA_DIST): Add them. --- gnulib-local/Makefile.am | 3 + gnulib-local/lib/fd-styled-ostream.oo.c | 83 +++++++++++++++++++++++++ gnulib-local/lib/fd-styled-ostream.oo.h | 47 ++++++++++++++ gnulib-local/modules/fd-styled-ostream | 49 +++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 gnulib-local/lib/fd-styled-ostream.oo.c create mode 100644 gnulib-local/lib/fd-styled-ostream.oo.h create mode 100644 gnulib-local/modules/fd-styled-ostream diff --git a/gnulib-local/Makefile.am b/gnulib-local/Makefile.am index 45dab7856..ddab7032b 100644 --- a/gnulib-local/Makefile.am +++ b/gnulib-local/Makefile.am @@ -37,6 +37,8 @@ lib/error-progname.h \ lib/exitfail.h.diff \ lib/fd-ostream.oo.c \ lib/fd-ostream.oo.h \ +lib/fd-styled-ostream.oo.c \ +lib/fd-styled-ostream.oo.h \ lib/file-ostream.oo.c \ lib/file-ostream.oo.h \ lib/fnmatch.c.diff \ @@ -268,6 +270,7 @@ modules/basename \ modules/closeout \ modules/error-progname \ modules/fd-ostream \ +modules/fd-styled-ostream \ modules/file-ostream \ modules/fnmatch.diff \ modules/gettext-runtime-misc \ diff --git a/gnulib-local/lib/fd-styled-ostream.oo.c b/gnulib-local/lib/fd-styled-ostream.oo.c new file mode 100644 index 000000000..f709cfa60 --- /dev/null +++ b/gnulib-local/lib/fd-styled-ostream.oo.c @@ -0,0 +1,83 @@ +/* Output stream with no-op styling, referring to a file descriptor. + Copyright (C) 2006, 2019 Free Software Foundation, Inc. + Written by Bruno Haible , 2019. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include "fd-styled-ostream.h" + +#include "fd-ostream.h" + +#include "xalloc.h" + + +struct fd_styled_ostream : struct styled_ostream +{ +fields: + /* The destination stream. */ + fd_ostream_t destination; +}; + +/* Implementation of ostream_t methods. */ + +static void +fd_styled_ostream::write_mem (fd_styled_ostream_t stream, + const void *data, size_t len) +{ + fd_ostream_write_mem (stream->destination, data, len); +} + +static void +fd_styled_ostream::flush (fd_styled_ostream_t stream) +{ + fd_ostream_flush (stream->destination); +} + +static void +fd_styled_ostream::free (fd_styled_ostream_t stream) +{ + fd_ostream_free (stream->destination); + free (stream); +} + +/* Implementation of styled_ostream_t methods. */ + +static void +fd_styled_ostream::begin_use_class (fd_styled_ostream_t stream, + const char *classname) +{ +} + +static void +fd_styled_ostream::end_use_class (fd_styled_ostream_t stream, + const char *classname) +{ +} + +/* Constructor. */ + +fd_styled_ostream_t +fd_styled_ostream_create (int fd, const char *filename) +{ + fd_styled_ostream_t stream = + XMALLOC (struct fd_styled_ostream_representation); + + stream->base.base.vtable = &fd_styled_ostream_vtable; + stream->destination = fd_ostream_create (fd, filename, true); + + return stream; +} diff --git a/gnulib-local/lib/fd-styled-ostream.oo.h b/gnulib-local/lib/fd-styled-ostream.oo.h new file mode 100644 index 000000000..04eaaff5d --- /dev/null +++ b/gnulib-local/lib/fd-styled-ostream.oo.h @@ -0,0 +1,47 @@ +/* Output stream with no-op styling, referring to a file descriptor. + Copyright (C) 2006, 2019 Free Software Foundation, Inc. + Written by Bruno Haible , 2019. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef _FD_STYLED_OSTREAM_H +#define _FD_STYLED_OSTREAM_H + +#include "styled-ostream.h" + + +struct fd_styled_ostream : struct styled_ostream +{ +methods: +}; + + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Create an output stream referring to the file descriptor FD, that supports + the styling operations as no-ops. + FILENAME is used only for error messages. + Note that the resulting stream must be closed before FD can be closed. */ +extern fd_styled_ostream_t + fd_styled_ostream_create (int fd, const char *filename); + + +#ifdef __cplusplus +} +#endif + +#endif /* _FD_STYLED_OSTREAM_H */ diff --git a/gnulib-local/modules/fd-styled-ostream b/gnulib-local/modules/fd-styled-ostream new file mode 100644 index 000000000..022eaa421 --- /dev/null +++ b/gnulib-local/modules/fd-styled-ostream @@ -0,0 +1,49 @@ +Description: +Output stream with no-op styling, referring to a file descriptor. + +Files: +lib/fd-styled-ostream.oo.h +lib/fd-styled-ostream.oo.c + +Depends-on: +styled-ostream +fd-ostream +xalloc + +configure.ac: + +Makefile.am: +if !WOE32DLL +lib_SOURCES += fd-styled-ostream.c +else +lib_SOURCES += ../woe32dll/c++fd-styled-ostream.cc +endif +# This is a Makefile rule that generates multiple files at once; see the +# automake documentation, node "Multiple Outputs", for details. +fd-styled-ostream.h : $(top_srcdir)/build-aux/moopp fd-styled-ostream.oo.h fd-styled-ostream.oo.c styled-ostream.oo.h ostream.oo.h + $(top_srcdir)/build-aux/moopp $(MOOPPFLAGS) $(srcdir)/fd-styled-ostream.oo.c $(srcdir)/fd-styled-ostream.oo.h $(srcdir)/styled-ostream.oo.h $(srcdir)/ostream.oo.h +fd-styled-ostream.c fd_styled_ostream.priv.h fd_styled_ostream.vt.h : fd-styled-ostream.h + @test -f $@ || { \ + trap 'rm -rf fd-styled-ostream.lock' 1 2 13 15; \ + if mkdir fd-styled-ostream.lock 2>/dev/null; then \ + echo "$(top_srcdir)/build-aux/moopp $(MOOPPFLAGS) $(srcdir)/fd-styled-ostream.oo.c $(srcdir)/fd-styled-ostream.oo.h $(srcdir)/styled-ostream.oo.h $(srcdir)/ostream.oo.h"; \ + $(top_srcdir)/build-aux/moopp $(MOOPPFLAGS) $(srcdir)/fd-styled-ostream.oo.c $(srcdir)/fd-styled-ostream.oo.h $(srcdir)/styled-ostream.oo.h $(srcdir)/ostream.oo.h; \ + result=$$?; rm -rf fd-styled-ostream.lock; exit $$result; \ + else \ + while test -d fd-styled-ostream.lock; do sleep 1; done; \ + test -f $(srcdir)/fd-styled-ostream.h; \ + fi; \ + } +BUILT_SOURCES += fd-styled-ostream.h fd-styled-ostream.c fd_styled_ostream.priv.h fd_styled_ostream.vt.h +MAINTAINERCLEANFILES += fd-styled-ostream.h fd-styled-ostream.c fd_styled_ostream.priv.h fd_styled_ostream.vt.h +EXTRA_DIST += fd-styled-ostream.h fd-styled-ostream.c fd_styled_ostream.priv.h fd_styled_ostream.vt.h + +Include: +"fd-styled-ostream.h" + +License: +GPL + +Maintainer: +Bruno Haible + -- 2.47.2