]> git.lyx.org Git - features.git/commitdiff
Replace gzstream by boost::iostreams::gzip_(de)compressor: by Bo Peng (ben.bob@gmail...
authorBo Peng <bpeng@lyx.org>
Fri, 21 Apr 2006 06:42:17 +0000 (06:42 +0000)
committerBo Peng <bpeng@lyx.org>
Fri, 21 Apr 2006 06:42:17 +0000 (06:42 +0000)
* src/buffer.C, use filtering_ostream
* src/lyxlex_pimpl.h, .C, use filtering_istreambuf
* src/Makefile.am,  src/support/Makefile.am, src/tex2lyx/Makefile.am, use BOOST_IOSTREAMS
* remove src/support/gzstream.h, .C
* add needed boost files boost/boost/iostreams/device/file_descriptor.hpp,
     device/mapped_file.hpp, detail/system_failure.hpp,
 detail/config/windows_posix.hpp

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13706 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
boost/boost/iostreams/detail/config/windows_posix.hpp [new file with mode: 0644]
boost/boost/iostreams/detail/system_failure.hpp [new file with mode: 0644]
boost/boost/iostreams/device/file_descriptor.hpp [new file with mode: 0644]
boost/boost/iostreams/device/mapped_file.hpp [new file with mode: 0644]
src/Makefile.am
src/buffer.C
src/lyxlex_pimpl.C
src/lyxlex_pimpl.h
src/support/Makefile.am
src/support/gzstream.C [deleted file]
src/support/gzstream.h [deleted file]
src/tex2lyx/Makefile.am

diff --git a/boost/boost/iostreams/detail/config/windows_posix.hpp b/boost/boost/iostreams/detail/config/windows_posix.hpp
new file mode 100644 (file)
index 0000000..0bc094f
--- /dev/null
@@ -0,0 +1,25 @@
+// (C) Copyright 2002, 2003 Beman Dawes   Boost.Filesystem
+// (C) Copyright Jonathan Turkanis 2004.
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+
+// See http://www.boost.org/libs/iostreams for documentation.
+
+#ifndef BOOST_IOSTREAMS_DETAIL_CONFIG_WINDOWS_POSIX_HPP_INCLUDED
+#define BOOST_IOSTREAMS_DETAIL_CONFIG_WINDOWS_POSIX_HPP_INCLUDED
+
+//------------------From boost/libs/filesystem/src/path_posix_windows.cpp-----//
+
+// BOOST_IOSTREAMS_POSIX or BOOST_IOSTREAMS_WINDOWS specify which API to use.
+#if !defined( BOOST_IOSTREAMS_WINDOWS ) && !defined( BOOST_IOSTREAMS_POSIX )
+# if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && \
+     !defined(__CYGWIN__) \
+     /**/
+#  define BOOST_IOSTREAMS_WINDOWS
+# else
+#  define BOOST_IOSTREAMS_POSIX
+# endif
+#endif
+
+#endif // #ifndef BOOST_IOSTREAMS_DETAIL_CONFIG_WINDOWS_POSIX_HPP_INCLUDED
diff --git a/boost/boost/iostreams/detail/system_failure.hpp b/boost/boost/iostreams/detail/system_failure.hpp
new file mode 100644 (file)
index 0000000..a4cf427
--- /dev/null
@@ -0,0 +1,76 @@
+// (C) Copyright Jonathan Graehl 2004.
+// (C) Copyright Jonathan Turkanis 2005.
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+
+// See http://www.boost.org/libs/iostreams for documentation.
+
+// Used by mapped_file.cpp.
+
+#ifndef BOOST_IOSTREAMS_DETAIL_SYSTEM_FAILURE_HPP_INCLUDED
+#define BOOST_IOSTREAMS_DETAIL_SYSTEM_FAILURE_HPP_INCLUDED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <cstring>
+#include <string>
+#include <boost/config.hpp>
+#include <boost/iostreams/detail/config/windows_posix.hpp>
+#include <boost/iostreams/detail/ios.hpp>  // failure.
+
+#if defined(BOOST_NO_STDC_NAMESPACE) && !defined(__LIBCOMO__)
+namespace std { using ::strlen; }
+#endif
+
+#ifdef BOOST_IOSTREAMS_WINDOWS
+# define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
+# include <windows.h>
+#else
+# include <errno.h>
+# include <string.h>
+#endif
+
+namespace boost { namespace iostreams { namespace detail {
+
+inline BOOST_IOSTREAMS_FAILURE system_failure(const char* msg)
+{
+    std::string result;
+#ifdef BOOST_IOSTREAMS_WINDOWS
+    DWORD err;
+    LPVOID lpMsgBuf;
+    if ( (err = ::GetLastError()) != NO_ERROR &&
+         ::FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                           FORMAT_MESSAGE_FROM_SYSTEM,
+                           NULL,
+                           err,
+                           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                           (LPSTR) &lpMsgBuf,
+                           0,
+                           NULL ) != 0 )
+    {
+        result.reserve(std::strlen(msg) + 2 + std::strlen((LPSTR)lpMsgBuf));
+        result.append(msg);
+        result.append(": ");
+        result.append((LPSTR) lpMsgBuf);
+        ::LocalFree(lpMsgBuf);
+    } else {
+        result += msg;
+    }
+#else
+    const char* system_msg = errno ? strerror(errno) : "";
+    result.reserve(std::strlen(msg) + 2 + std::strlen(system_msg));
+    result.append(msg);
+    result.append(": ");
+    result.append(system_msg);
+#endif
+    return BOOST_IOSTREAMS_FAILURE(result);
+}
+
+inline void throw_system_failure(const char* msg)
+{ throw system_failure(msg); }
+
+} } } // End namespaces detail, iostreams, boost.
+
+#endif // #ifndef BOOST_IOSTREAMS_DETAIL_SYSTEM_FAILURE_HPP_INCLUDED
diff --git a/boost/boost/iostreams/device/file_descriptor.hpp b/boost/boost/iostreams/device/file_descriptor.hpp
new file mode 100644 (file)
index 0000000..13e1c68
--- /dev/null
@@ -0,0 +1,156 @@
+// (C) Copyright Jonathan Turkanis 2003.
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+
+// See http://www.boost.org/libs/iostreams for documentation.
+
+// Inspired by fdstream.hpp, (C) Copyright Nicolai M. Josuttis 2001,
+// available at http://www.josuttis.com/cppcode/fdstream.html.
+
+#ifndef BOOST_IOSTREAMS_FILE_DESCRIPTOR_HPP_INCLUDED
+#define BOOST_IOSTREAMS_FILE_DESCRIPTOR_HPP_INCLUDED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <string>                          // file pathnames.
+#include <boost/cstdint.hpp>               // intmax_t.
+#include <boost/iostreams/categories.hpp>  // tags.
+#include <boost/iostreams/detail/config/auto_link.hpp>
+#include <boost/iostreams/detail/config/dyn_link.hpp>
+#include <boost/iostreams/detail/config/windows_posix.hpp>
+#include <boost/iostreams/detail/ios.hpp>  // openmode, seekdir, int types.
+#include <boost/iostreams/positioning.hpp>
+#include <boost/shared_ptr.hpp>
+
+// Must come last.
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost { namespace iostreams {
+
+class BOOST_IOSTREAMS_DECL file_descriptor {
+public:
+#ifdef BOOST_IOSTREAMS_WINDOWS
+    typedef void*  handle_type;
+#endif
+    typedef char   char_type;
+    struct category
+        : seekable_device_tag,
+          closable_tag
+        { };
+    file_descriptor() : pimpl_(new impl) { }
+    explicit file_descriptor(int fd, bool close_on_exit = false)
+        : pimpl_(new impl(fd, close_on_exit))
+        { }
+#ifdef BOOST_IOSTREAMS_WINDOWS
+    explicit file_descriptor(handle_type handle, bool close_on_exit = false)
+        : pimpl_(new impl(handle, close_on_exit))
+        { }
+#endif
+    explicit file_descriptor( const std::string& path,
+                              BOOST_IOS::openmode mode =
+                                  BOOST_IOS::in | BOOST_IOS::out,
+                              BOOST_IOS::openmode base_mode =
+                                  BOOST_IOS::in | BOOST_IOS::out )
+        : pimpl_(new impl)
+    { open(path, mode, base_mode); }
+    void open( const std::string& path,
+               BOOST_IOS::openmode =
+                   BOOST_IOS::in | BOOST_IOS::out,
+               BOOST_IOS::openmode base_mode =
+                   BOOST_IOS::in | BOOST_IOS::out );
+    bool is_open() const { return pimpl_->flags_ != 0; }
+    std::streamsize read(char_type* s, std::streamsize n);
+    std::streamsize write(const char_type* s, std::streamsize n);
+    std::streampos seek(stream_offset off, BOOST_IOS::seekdir way);
+    void close();
+private:
+    struct impl {
+        impl() : fd_(-1), flags_(0) { }
+        impl(int fd, bool close_on_exit)
+            : fd_(fd), flags_(0)
+        { if (close_on_exit) flags_ |= impl::close_on_exit; }
+    #ifdef BOOST_IOSTREAMS_WINDOWS
+        impl(handle_type handle, bool close_on_exit)
+            : handle_(handle), flags_(has_handle)
+        { if (close_on_exit) flags_ |= impl::close_on_exit; }
+    #endif
+        ~impl() {
+            if (flags_ & close_on_exit) close_impl(*this);
+        }
+        enum flags {
+            close_on_exit = 1,
+            has_handle = 2,
+            append = 4
+        };
+        int          fd_;
+    #ifdef BOOST_IOSTREAMS_WINDOWS
+        handle_type  handle_;
+    #endif
+        int          flags_;
+    };
+    friend struct impl;
+
+    static void close_impl(impl&);
+
+    shared_ptr<impl> pimpl_;
+};
+
+struct file_descriptor_source : private file_descriptor {
+#ifdef BOOST_IOSTREAMS_WINDOWS
+    typedef void*  handle_type;
+#endif
+    typedef char   char_type;
+    struct category : public source_tag, closable_tag { };
+    using file_descriptor::read;
+    using file_descriptor::open;
+    using file_descriptor::is_open;
+    using file_descriptor::close;
+    file_descriptor_source() { }
+    explicit file_descriptor_source(int fd, bool close_on_exit = false)
+        : file_descriptor(fd, close_on_exit)
+        { }
+#ifdef BOOST_IOSTREAMS_WINDOWS
+    explicit file_descriptor_source( handle_type handle,
+                                     bool close_on_exit = false )
+        : file_descriptor(handle, close_on_exit)
+        { }
+#endif
+    explicit file_descriptor_source( const std::string& path,
+                                     BOOST_IOS::openmode m = BOOST_IOS::in )
+        : file_descriptor(path, m & ~BOOST_IOS::out, BOOST_IOS::in)
+        { }
+};
+
+struct file_descriptor_sink : private file_descriptor {
+#ifdef BOOST_IOSTREAMS_WINDOWS
+    typedef void*  handle_type;
+#endif
+    typedef char   char_type;
+    struct category : public sink_tag, closable_tag { };
+    using file_descriptor::write;
+    using file_descriptor::open;
+    using file_descriptor::is_open;
+    using file_descriptor::close;
+    file_descriptor_sink() { }
+    explicit file_descriptor_sink(int fd, bool close_on_exit = false)
+        : file_descriptor(fd, close_on_exit)
+        { }
+#ifdef BOOST_IOSTREAMS_WINDOWS
+    explicit file_descriptor_sink( handle_type handle,
+                                   bool close_on_exit = false )
+        : file_descriptor(handle, close_on_exit)
+        { }
+#endif
+    explicit file_descriptor_sink( const std::string& path,
+                                   BOOST_IOS::openmode m = BOOST_IOS::out )
+        : file_descriptor(path, m & ~BOOST_IOS::in, BOOST_IOS::out)
+        { }
+};
+
+} } // End namespaces iostreams, boost.
+
+#include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
+
+#endif // #ifndef BOOST_IOSTREAMS_FILE_DESCRIPTOR_HPP_INCLUDED
diff --git a/boost/boost/iostreams/device/mapped_file.hpp b/boost/boost/iostreams/device/mapped_file.hpp
new file mode 100644 (file)
index 0000000..38046f9
--- /dev/null
@@ -0,0 +1,270 @@
+// (C) Copyright Jonathan Turkanis 2003.
+// (C) Copyright Craig Henderson 2002.   'boost/memmap.hpp' from sandbox
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
+
+// See http://www.boost.org/libs/iostreams for documentation.
+
+//
+// This header and its accompanying source file libs/iostreams/memmap.cpp are
+// an adaptation of Craig Henderson's memmory mapped file library. The
+// interface has been revised significantly, but the underlying OS-specific
+// code is essentially the same, with some code from Boost.Filesystem
+// mixed in. (See notations in source.)
+//
+// The following changes have been made:
+//
+// 1. OS-specific code put in a .cpp file.
+// 2. Name of main class changed to mapped_file.
+// 3. mapped_file given an interface similar to std::fstream (open(),
+//    is_open(), close()) and std::string (data(), size(), begin(), end()).
+// 4. An additional class readonly_mapped_file has been provided as a
+//    convenience.
+// 5. [Obsolete: Error states are reported using filesystem::error_code.]
+// 6. Read-only or read-write states are specified using ios_base::openmode.
+// 7. Access to the underlying file handles and to security parameters
+//    has been removed.
+//
+
+#ifndef BOOST_IOSTREAMS_MAPPED_FILE_HPP_INCLUDED
+#define BOOST_IOSTREAMS_MAPPED_FILE_HPP_INCLUDED
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+#include <boost/config.hpp>                   // make sure size_t is in std.
+#include <cstddef>                            // size_t.
+#include <string>                             // pathnames.
+#include <utility>                            // pair.
+#include <boost/config.hpp>                   // BOOST_MSVC.
+#include <boost/detail/workaround.hpp>
+#include <boost/iostreams/close.hpp>
+#include <boost/iostreams/concepts.hpp>
+#include <boost/iostreams/detail/config/auto_link.hpp>
+#include <boost/iostreams/detail/config/dyn_link.hpp>
+#include <boost/iostreams/detail/ios.hpp>     // openmode.
+#include <boost/iostreams/operations_fwd.hpp>
+#include <boost/iostreams/positioning.hpp>
+#include <boost/shared_ptr.hpp>
+
+// Must come last.
+#include <boost/iostreams/detail/config/disable_warnings.hpp>
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost { namespace iostreams {
+
+namespace detail {
+
+struct mapped_file_impl;
+
+} // End namespace detail.
+
+struct mapped_file_params {
+    explicit mapped_file_params()
+        : mode(), offset(0), length(static_cast<std::size_t>(-1)),
+          new_file_size(0), hint(0)
+        { }
+    explicit mapped_file_params(const std::string& path)
+        : path(path), mode(), offset(0),
+          length(static_cast<std::size_t>(-1)),
+          new_file_size(0), hint(0)
+        { }
+    std::string          path;
+    BOOST_IOS::openmode  mode;
+    stream_offset        offset;
+    std::size_t          length;
+    stream_offset        new_file_size;
+    const char*          hint;
+};
+
+//------------------Definition of mapped_file_source--------------------------//
+
+class BOOST_IOSTREAMS_DECL mapped_file_source {
+private:
+    struct safe_bool_helper { int x; };         // From Bronek Kozicki.
+    typedef int safe_bool_helper::* safe_bool;
+    friend struct operations<mapped_file_source>;
+public:
+    typedef char               char_type;
+    struct category
+        : public source_tag,
+          public direct_tag,
+          public closable_tag
+        { };
+    typedef std::size_t        size_type;
+    typedef const char*        iterator;
+    BOOST_STATIC_CONSTANT(size_type, max_length = static_cast<size_type>(-1));
+
+    mapped_file_source() { }
+    explicit mapped_file_source(mapped_file_params);
+    explicit mapped_file_source( const std::string& path,
+                                 size_type length = max_length,
+                                 boost::intmax_t offset = 0 );
+
+    //--------------Stream interface------------------------------------------//
+
+    void open(mapped_file_params params);
+    void open( const std::string& path,
+               size_type length = max_length,
+               boost::intmax_t offset = 0 );
+    bool is_open() const;
+    void close();
+
+    operator safe_bool() const;
+    bool operator!() const;
+    BOOST_IOS::openmode mode() const;
+
+    //--------------Container interface---------------------------------------//
+
+    size_type size() const;
+    const char* data() const;
+    iterator begin() const;
+    iterator end() const;
+
+    //--------------Query admissible offsets----------------------------------//
+
+    // Returns the allocation granularity for virtual memory. Values passed
+    // as offsets must be multiples of this value.
+    static int alignment();
+private:
+    friend class mapped_file;
+    typedef detail::mapped_file_impl impl_type;
+    void open_impl(mapped_file_params);
+
+    boost::shared_ptr<impl_type> pimpl_;
+};
+
+//------------------Definition of mapped_file---------------------------------//
+
+class BOOST_IOSTREAMS_DECL mapped_file {
+private:
+    typedef mapped_file_source delegate_type;
+    delegate_type delegate_;
+    friend struct operations<mapped_file>;
+public:
+    typedef char                           char_type;
+    struct category
+        : public seekable_device_tag,
+          public direct_tag,
+          public closable_tag
+        { };
+    typedef mapped_file_source::size_type  size_type;
+    typedef char*                          iterator;
+    typedef const char*                    const_iterator;
+    BOOST_STATIC_CONSTANT(size_type, max_length = delegate_type::max_length);
+    mapped_file() { }
+    explicit mapped_file(mapped_file_params p);
+    explicit mapped_file( const std::string& path,
+                          BOOST_IOS::openmode mode =
+                              BOOST_IOS::in | BOOST_IOS::out,
+                          size_type length = max_length,
+                          stream_offset offset = 0 );
+
+    //--------------Conversion to readonly_mapped_file------------------------//
+
+    operator mapped_file_source&() { return delegate_; }
+    operator const mapped_file_source&() const { return delegate_; }
+
+    //--------------Stream interface------------------------------------------//
+
+    void open(mapped_file_params p);
+    void open( const std::string& path,
+               BOOST_IOS::openmode mode =
+                   BOOST_IOS::in | BOOST_IOS::out,
+               size_type length = max_length,
+               stream_offset offset = 0 );
+    bool is_open() const { return delegate_.is_open(); }
+    void close() { delegate_.close(); }
+    operator delegate_type::safe_bool() const { return delegate_; }
+    bool operator!() const { return !is_open(); }
+    BOOST_IOS::openmode mode() const { return delegate_.mode(); }
+
+    //--------------Container interface---------------------------------------//
+
+    size_type size() const { return delegate_.size(); }
+    char* data() const 
+    { 
+        return (mode() & BOOST_IOS::out) ?
+            const_cast<char*>(delegate_.data()) :
+            0;
+    }
+    const char* const_data() const { return delegate_.data(); }
+    iterator begin() const { return data(); }
+    const_iterator const_begin() const { return data(); }
+    iterator end() const { return data() + size(); }
+    const_iterator const_end() const { return data() + size(); }
+
+    //--------------Query admissible offsets----------------------------------//
+
+    // Returns the allocation granularity for virtual memory. Values passed
+    // as offsets must be multiples of this value.
+    static int alignment() { return mapped_file_source::alignment(); }
+};
+
+struct BOOST_IOSTREAMS_DECL mapped_file_sink : private mapped_file {
+    friend struct operations<mapped_file_sink>;
+    typedef char char_type;
+    struct category
+        : public sink_tag,
+          public direct_tag,
+          public closable_tag
+        { };
+    using mapped_file::close;
+    explicit mapped_file_sink(mapped_file_params p);
+    explicit mapped_file_sink( const std::string& path,
+                               size_type length = max_length,
+                               boost::intmax_t offset = 0 );
+    void open(mapped_file_params p);
+    void open( const std::string& path,
+               size_type length = max_length,
+               boost::intmax_t offset = 0 );
+};
+
+//------------------Specialization of direct_impl-----------------------------//
+
+template<>
+struct operations<boost::iostreams::mapped_file_source>
+    : detail::close_impl<closable_tag>
+{
+    static std::pair<char*, char*>
+    input_sequence(boost::iostreams::mapped_file_source& src)
+    {
+        return std::make_pair( const_cast<char*>(src.begin()),
+                               const_cast<char*>(src.end()) );
+    }
+};
+
+template<>
+struct operations<boost::iostreams::mapped_file_sink>
+    : detail::close_impl<closable_tag>
+{
+    static std::pair<char*, char*>
+    output_sequence(boost::iostreams::mapped_file_sink& sink)
+    { 
+        return std::make_pair(sink.begin(), sink.end()); 
+    }
+};
+
+template<>
+struct operations<boost::iostreams::mapped_file>
+    : detail::close_impl<closable_tag>
+{
+    static std::pair<char*, char*>
+    input_sequence(boost::iostreams::mapped_file& file)
+    { 
+        return std::make_pair(file.begin(), file.end()); 
+    }
+    static std::pair<char*, char*>
+    output_sequence(boost::iostreams::mapped_file& file)
+    { 
+        return std::make_pair(file.begin(), file.end()); 
+    }
+};
+
+} } // End namespaces iostreams, boost.
+
+#include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
+#include <boost/iostreams/detail/config/enable_warnings.hpp> // MSVC.
+
+#endif // #ifndef BOOST_IOSTREAMS_MAPPED_FILE_HPP_INCLUDED
index 4ed39157ff4564d24181fa7b0cd9fcbc80fa3155..76d8526de3bbff75ba0e1eadf9c771f22aa4c37f 100644 (file)
@@ -25,7 +25,7 @@ LYX_POST_LIBS = frontends/controllers/libcontrollers.la \
        graphics/libgraphics.la \
        support/libsupport.la
 
-BOOST_LIBS = $(BOOST_REGEX) $(BOOST_SIGNALS) $(BOOST_FILESYSTEM)
+BOOST_LIBS = $(BOOST_REGEX) $(BOOST_SIGNALS) $(BOOST_FILESYSTEM) $(BOOST_IOSTREAMS)
 
 OTHERLIBS = $(BOOST_LIBS) $(INTLLIBS) $(AIKSAURUS_LIBS) @LIBS@ $(SOCKET_LIBS)
 
index 3cf471a702c4da24398b08fd7c1c9a12453f5135..13a1b7dbd6ff182a29ea1665ae70155e30073933 100644 (file)
 #include "support/filetools.h"
 #include "support/fs_extras.h"
 #ifdef USE_COMPRESSION
-# include "support/gzstream.h"
+# include <boost/iostreams/filtering_stream.hpp>
+# include <boost/iostreams/filter/gzip.hpp>
+# include <boost/iostreams/device/file.hpp>
+namespace io = boost::iostreams;
 #endif
 #include "support/lyxlib.h"
 #include "support/os.h"
@@ -735,7 +738,7 @@ bool Buffer::writeFile(string const & fname) const
 
        if (params().compressed) {
 #ifdef USE_COMPRESSION
-               gz::ogzstream ofs(fname.c_str(), ios::out|ios::trunc);
+               io::filtering_ostream ofs(io::gzip_compressor() | io::file_sink(fname));
                if (!ofs)
                        return false;
 
index e8e9e06befcc3f217ca7525526c4d1664941f5c2..853b007f829106bc3db53bf506aa8cce8b2eb021 100644 (file)
@@ -144,14 +144,15 @@ bool LyXLex::Pimpl::setFile(string const & filename)
                // The check only outputs a debug message, because it triggers
                // a bug in compaq cxx 6.2, where is_open() returns 'true' for
                // a fresh new filebuf.  (JMarc)
-               if (gz_.is_open() || istream::off_type(is.tellg()) > -1)
+               if (!gz_.empty() || istream::off_type(is.tellg()) > -1)
                        lyxerr[Debug::LYXLEX] << "Error in LyXLex::setFile: "
                                "file or stream already set." << endl;
-               gz_.open(filename.c_str(), ios::in);
+               gz_.push(io::gzip_decompressor());
+               gz_.push(io::file_source(filename));
                is.rdbuf(&gz_);
                name = filename;
                lineno = 0;
-               return gz_.is_open() && is.good();
+               return gz_.component<io::file_source>(1)->is_open() && is.good();
 #else
                return false;
 #endif
index 79f4393acef51621bf74b71f86cf0513b947fc12..e449c8b08ec5b34695489b15c11e846ca1546871 100644 (file)
 #include "lyxlex.h"
 
 #ifdef USE_COMPRESSION
-# include "support/gzstream.h"
+# include <boost/iostreams/filtering_streambuf.hpp>
+# include <boost/iostreams/filter/gzip.hpp>
+# include <boost/iostreams/device/file.hpp>
+namespace io = boost::iostreams;
 #endif
 
 #include <boost/utility.hpp>
@@ -63,7 +66,7 @@ public:
 
 #ifdef USE_COMPRESSION
        /// gz_ is only used to open files, the stream is accessed through is.
-       gz::gzstreambuf gz_;
+       io::filtering_istreambuf gz_;
 #endif
 
        /// the stream that we use.
index 8538ac9186da6fdab05b91096636f6b0526e0de1..03896e41dedebdf32970d111bdc5e0d2d7aef597 100644 (file)
@@ -9,10 +9,6 @@ EXTRA_DIST = package.C.in pch.h \
 
 noinst_LTLIBRARIES = libsupport.la
 
-if USE_COMPRESSION
-COMPRESSION = gzstream.C gzstream.h
-endif
-
 BUILT_SOURCES = $(PCH_FILE) package.C
 
 AM_CPPFLAGS += $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES)
@@ -46,7 +42,7 @@ libsupport_la_SOURCES = \
        fs_extras.C \
        fs_extras.h \
        getcwd.C \
-       $(COMPRESSION) kill.C \
+       kill.C \
        limited_stack.h \
        lstrings.C \
        lstrings.h \
diff --git a/src/support/gzstream.C b/src/support/gzstream.C
deleted file mode 100644 (file)
index e1fcf5a..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-// ============================================================================
-// gzstream, C++ iostream classes wrapping the zlib compression library.
-// Copyright (C) 2001  Deepak Bandyopadhyay, Lutz Kettner
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library 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
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-// ============================================================================
-//
-// File          : gzstream.C
-// Revision      : $Revision: 1.4 $
-// Revision_date : $Date: 2005/04/26 10:30:24 $
-// Author(s)     : Deepak Bandyopadhyay, Lutz Kettner
-//
-// Standard streambuf implementation following Nicolai Josuttis, "The
-// Standard C++ Library".
-// ============================================================================
-
-#include <config.h>
-
-#include "gzstream.h"
-#include <iostream>
-#ifdef HAVE_STRING_H
-# include <string.h> // for memcpy
-#endif
-
-#ifdef GZSTREAM_NAMESPACE
-namespace GZSTREAM_NAMESPACE {
-#endif
-
-// ----------------------------------------------------------------------------
-// Internal classes to implement gzstream. See header file for user classes.
-// ----------------------------------------------------------------------------
-
-// --------------------------------------
-// class gzstreambuf:
-// --------------------------------------
-
-gzstreambuf* gzstreambuf::open( const char* name, int open_mode) {
-    if ( is_open())
-       return (gzstreambuf*)0;
-    mode = open_mode;
-    // no append nor read/write mode
-    if ((mode & std::ios::ate) || (mode & std::ios::app)
-       || ((mode & std::ios::in) && (mode & std::ios::out)))
-       return (gzstreambuf*)0;
-    char  fmode[10];
-    char* fmodeptr = fmode;
-    if ( mode & std::ios::in)
-       *fmodeptr++ = 'r';
-    else if ( mode & std::ios::out)
-       *fmodeptr++ = 'w';
-    *fmodeptr++ = 'b';
-    *fmodeptr = '\0';
-    file = gzopen( name, fmode);
-    if (file == 0)
-       return (gzstreambuf*)0;
-    opened = 1;
-    return this;
-}
-
-gzstreambuf * gzstreambuf::close() {
-    if ( is_open()) {
-       sync();
-       opened = 0;
-       if ( gzclose( file) == Z_OK)
-           return this;
-    }
-    return (gzstreambuf*)0;
-}
-
-int gzstreambuf::underflow() { // used for input buffer only
-    if ( gptr() && ( gptr() < egptr()))
-       return * reinterpret_cast<unsigned char *>( gptr());
-
-    if ( ! (mode & std::ios::in) || ! opened)
-       return EOF;
-    // Josuttis' implementation of inbuf
-    int n_putback = gptr() - eback();
-    if ( n_putback > 4)
-       n_putback = 4;
-    memcpy( buffer + (4 - n_putback), gptr() - n_putback, n_putback);
-
-    int num = gzread( file, buffer+4, bufferSize-4);
-    if (num <= 0) // ERROR or EOF
-       return EOF;
-
-    // reset buffer pointers
-    setg( buffer + (4 - n_putback),   // beginning of putback area
-         buffer + 4,                 // read position
-         buffer + 4 + num);          // end of buffer
-
-    // return next character
-    return * reinterpret_cast<unsigned char *>( gptr());
-}
-
-int gzstreambuf::flush_buffer() {
-    // Separate the writing of the buffer from overflow() and
-    // sync() operation.
-    int w = pptr() - pbase();
-    if ( gzwrite( file, pbase(), w) != w)
-       return EOF;
-    pbump( -w);
-    return w;
-}
-
-int gzstreambuf::overflow( int c) { // used for output buffer only
-    if ( ! ( mode & std::ios::out) || ! opened)
-       return EOF;
-    if (c != EOF) {
-       *pptr() = c;
-       pbump(1);
-    }
-    if ( flush_buffer() == EOF)
-       return EOF;
-    return c;
-}
-
-int gzstreambuf::sync() {
-    // Changed to use flush_buffer() instead of overflow( EOF)
-    // which caused improper behavior with std::endl and flush(),
-    // bug reported by Vincent Ricard.
-    if ( pptr() && pptr() > pbase()) {
-       if ( flush_buffer() == EOF)
-           return -1;
-    }
-    return 0;
-}
-
-// --------------------------------------
-// class gzstreambase:
-// --------------------------------------
-
-gzstreambase::gzstreambase( const char* name, int mode) {
-    init( &buf);
-    open( name, mode);
-}
-
-gzstreambase::~gzstreambase() {
-    buf.close();
-}
-
-void gzstreambase::open( const char* name, int open_mode) {
-    if ( ! buf.open( name, open_mode))
-       clear( rdstate() | std::ios::badbit);
-}
-
-void gzstreambase::close() {
-    if ( buf.is_open())
-       if ( ! buf.close())
-           clear( rdstate() | std::ios::badbit);
-}
-
-#ifdef GZSTREAM_NAMESPACE
-} // namespace GZSTREAM_NAMESPACE
-#endif
-
-// ============================================================================
-// EOF //
diff --git a/src/support/gzstream.h b/src/support/gzstream.h
deleted file mode 100644 (file)
index 3c4568d..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-// ============================================================================
-// gzstream, C++ iostream classes wrapping the zlib compression library.
-// Copyright (C) 2001  Deepak Bandyopadhyay, Lutz Kettner
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library 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
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-// ============================================================================
-//
-// File          : gzstream.h
-// Revision      : $Revision: 1.2 $
-// Revision_date : $Date: 2005/04/26 10:30:24 $
-// Author(s)     : Deepak Bandyopadhyay, Lutz Kettner
-//
-// Standard streambuf implementation following Nicolai Josuttis, "The
-// Standard C++ Library".
-// ============================================================================
-
-#ifndef GZSTREAM_H
-#define GZSTREAM_H 1
-
-// standard C++ with new header file names and std:: namespace
-#include <iostream>
-#include <fstream>
-#ifdef HAVE_ZLIB_H
-# include <zlib.h>
-#endif
-
-// For LyX
-#define GZSTREAM_NAMESPACE gz
-
-#ifdef GZSTREAM_NAMESPACE
-namespace GZSTREAM_NAMESPACE {
-#endif
-
-// ----------------------------------------------------------------------------
-// Internal classes to implement gzstream. See below for user classes.
-// ----------------------------------------------------------------------------
-
-class gzstreambuf : public std::streambuf {
-private:
-    static const int bufferSize = 47+256;    // size of data buff
-    // totals 512 bytes under g++ for igzstream at the end.
-
-    gzFile           file;               // file handle for compressed file
-    char             buffer[bufferSize]; // data buffer
-    char             opened;             // open/close state of stream
-    int              mode;               // I/O mode
-
-    int flush_buffer();
-public:
-    gzstreambuf() : opened(0) {
-       setp( buffer, buffer + (bufferSize-1));
-       setg( buffer + 4,     // beginning of putback area
-             buffer + 4,     // read position
-             buffer + 4);    // end position
-       // ASSERT: both input & output capabilities will not be used together
-    }
-    int is_open() { return opened; }
-    gzstreambuf* open( const char* name, int open_mode);
-    gzstreambuf* close();
-    ~gzstreambuf() { close(); }
-
-    virtual int     overflow( int c = EOF);
-    virtual int     underflow();
-    virtual int     sync();
-};
-
-class gzstreambase : virtual public std::ios {
-protected:
-    gzstreambuf buf;
-public:
-    gzstreambase() { init(&buf); }
-    gzstreambase( const char* name, int open_mode);
-    ~gzstreambase();
-    void open( const char* name, int open_mode);
-    void close();
-    gzstreambuf* rdbuf() { return &buf; }
-};
-
-// ----------------------------------------------------------------------------
-// User classes. Use igzstream and ogzstream analogously to ifstream and
-// ofstream respectively. They read and write files based on the gz*
-// function interface of the zlib. Files are compatible with gzip compression.
-// ----------------------------------------------------------------------------
-
-class igzstream : public gzstreambase, public std::istream {
-public:
-    igzstream() : std::istream( &buf) {}
-    igzstream( const char* name, int open_mode = std::ios::in)
-       : gzstreambase( name, open_mode), std::istream( &buf) {}
-    gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
-    void open( const char* name, int open_mode = std::ios::in) {
-       gzstreambase::open( name, open_mode);
-    }
-};
-
-class ogzstream : public gzstreambase, public std::ostream {
-public:
-    ogzstream() : std::ostream( &buf) {}
-    ogzstream( const char* name, int mode = std::ios::out)
-       : gzstreambase( name, mode), std::ostream( &buf) {}
-    gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
-    void open( const char* name, int open_mode = std::ios::out) {
-       gzstreambase::open( name, open_mode);
-    }
-};
-
-#ifdef GZSTREAM_NAMESPACE
-} // namespace GZSTREAM_NAMESPACE
-#endif
-
-#endif // GZSTREAM_H
-// ============================================================================
-// EOF //
index 49dcdd4495eeba64e06b777616801d19c4e58ff3..f54094cb79762c5876803fb7fa5412c48c58228b 100644 (file)
@@ -18,7 +18,7 @@ bin_PROGRAMS = tex2lyx
 
 AM_CPPFLAGS += $(PCH_FLAGS) -I$(srcdir)/.. $(BOOST_INCLUDES)
 
-BOOST_LIBS = $(BOOST_REGEX) $(BOOST_FILESYSTEM)
+BOOST_LIBS = $(BOOST_REGEX) $(BOOST_FILESYSTEM) $(BOOST_IOSTREAMS)
 
 if USE_COMPRESSION
 COMPRESSIONLIB = -lz