]> git.lyx.org Git - features.git/commitdiff
gzstream is able to read uncompressed files too
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 24 Nov 2021 10:44:53 +0000 (11:44 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 24 Nov 2021 10:44:53 +0000 (11:44 +0100)
This allows to simplify the code in Lexer and to remove the dependency
on Formats class.

As a consequence, a pair of dummy definitions of isZippedFile can be removed.

src/Lexer.cpp
src/tests/check_layout.cpp
src/tex2lyx/dummy_impl.cpp

index 17cc161d19ccab690f571c75b288fa9be9e5de45..c6402aec6f39f69e966b6afe17710d44aebeb5e8 100644 (file)
@@ -14,7 +14,6 @@
 #include <config.h>
 
 #include "Lexer.h"
 #include <config.h>
 
 #include "Lexer.h"
-#include "Format.h"
 
 #include "support/convert.h"
 #include "support/debug.h"
 
 #include "support/convert.h"
 #include "support/debug.h"
@@ -81,9 +80,6 @@ public:
        bool inputAvailable();
        ///
        void pushToken(string const &);
        bool inputAvailable();
        ///
        void pushToken(string const &);
-       /// fb_ is only used to open files, the stream is accessed through is.
-       filebuf fb_;
-
        /// gz_ is only used to open files, the stream is accessed through is.
        gz::gzstreambuf gz_;
 
        /// gz_ is only used to open files, the stream is accessed through is.
        gz::gzstreambuf gz_;
 
@@ -149,7 +145,7 @@ bool compareTags(LexerKeyword const & a, LexerKeyword const & b)
 
 
 Lexer::Pimpl::Pimpl(LexerKeyword * tab, int num)
 
 
 Lexer::Pimpl::Pimpl(LexerKeyword * tab, int num)
-       : is(&fb_), table(tab), no_items(num),
+       : is(&gz_), table(tab), no_items(num),
          status(0), lineno(0), commentChar('#')
 {
        verifyTable();
          status(0), lineno(0), commentChar('#')
 {
        verifyTable();
@@ -235,38 +231,14 @@ void Lexer::Pimpl::popTable()
 
 bool Lexer::Pimpl::setFile(FileName const & filename)
 {
 
 bool Lexer::Pimpl::setFile(FileName const & filename)
 {
-       // Check the format of the file.
-       if (theFormats().isZippedFile(filename)) {
-               LYXERR(Debug::LYXLEX, "lyxlex: compressed");
-               // 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_.is_open() || istream::off_type(is.tellg()) > -1)
-                       LYXERR(Debug::LYXLEX, "Error in LyXLex::setFile: "
-                               "file or stream already set.");
+                       LYXERR0("Error in LyXLex::setFile: file or stream already set.");
                gz_.open(filename.toFilesystemEncoding().c_str(), ios::in);
                is.rdbuf(&gz_);
                name = filename.absFileName();
                lineno = 0;
                if (!gz_.is_open() || !is.good())
                        return false;
                gz_.open(filename.toFilesystemEncoding().c_str(), ios::in);
                is.rdbuf(&gz_);
                name = filename.absFileName();
                lineno = 0;
                if (!gz_.is_open() || !is.good())
                        return false;
-       } else {
-               LYXERR(Debug::LYXLEX, "lyxlex: UNcompressed");
-
-               // 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 (fb_.is_open() || istream::off_type(is.tellg()) > 0) {
-                       LYXERR(Debug::LYXLEX, "Error in Lexer::setFile: "
-                               "file or stream already set.");
-               }
-               fb_.open(filename.toSafeFilesystemEncoding().c_str(), ios::in);
-               is.rdbuf(&fb_);
-               name = filename.absFileName();
-               lineno = 0;
-               if (!fb_.is_open() || !is.good())
-                       return false;
-       }
 
        // Skip byte order mark.
        if (is.peek() == 0xef) {
 
        // Skip byte order mark.
        if (is.peek() == 0xef) {
@@ -284,10 +256,8 @@ bool Lexer::Pimpl::setFile(FileName const & filename)
 
 void Lexer::Pimpl::setStream(istream & i)
 {
 
 void Lexer::Pimpl::setStream(istream & i)
 {
-       if (fb_.is_open() || istream::off_type(is.tellg()) > 0) {
-               LYXERR(Debug::LYXLEX, "Error in Lexer::setStream: "
-                       "file or stream already set.");
-       }
+       if (gz_.is_open() || istream::off_type(is.tellg()) > 0)
+               LYXERR0("Error in Lexer::setStream: file or stream already set.");
        is.rdbuf(i.rdbuf());
        lineno = 0;
 }
        is.rdbuf(i.rdbuf());
        lineno = 0;
 }
index afdb66777dfc3b3abef6a1f7ff3214ea2f53c0a8..f92daa2250853148029c0cdd4294d4f02b60a5ea 100644 (file)
@@ -3,7 +3,6 @@
 #include "../support/debug.h"
 #include "../support/FileName.h"
 #include "../support/filetools.h"
 #include "../support/debug.h"
 #include "../support/FileName.h"
 #include "../support/filetools.h"
-#include "../Format.h"
 #include "../LayoutFile.h"
 #include "../LaTeXFeatures.h"
 #include "../Lexer.h"
 #include "../LayoutFile.h"
 #include "../LaTeXFeatures.h"
 #include "../Lexer.h"
@@ -34,11 +33,6 @@ bool LaTeXFeatures::isAvailable(std::string const &)
        return false;
 }
 
        return false;
 }
 
-Formats formats;
-bool Formats::isZippedFile(support::FileName const &) const
-{
-       return false;
-}
 } // namespace lyx
 
 
 } // namespace lyx
 
 
index eb445672d6f9d49ff8f7ae5fe8b00173f7959455..62436af5e67f112c158cb632742b82b7628db6cc 100644 (file)
@@ -18,7 +18,6 @@
 
 #include <config.h>
 
 
 #include <config.h>
 
-#include "Format.h"
 #include "LaTeXFeatures.h"
 #include "LyXRC.h"
 #include "output_xhtml.h"
 #include "LaTeXFeatures.h"
 #include "LyXRC.h"
 #include "output_xhtml.h"
@@ -73,23 +72,6 @@ Messages const & getGuiMessages()
 }
 
 
 }
 
 
-//
-// Dummy formats support (needed by Lexer)
-//
-
-
-Formats & theFormats()
-{
-       static Formats dummy_formats;
-       return dummy_formats;
-}
-
-bool Formats::isZippedFile(support::FileName const&) const
-{
-       return false;
-}
-
-
 //
 // Dummy features support (needed by ModuleList)
 //
 //
 // Dummy features support (needed by ModuleList)
 //