]> git.lyx.org Git - lyx.git/blobdiff - src/Lexer.cpp
* ca/Intro.lyx from Daniel
[lyx.git] / src / Lexer.cpp
index 2711db49e153e321733fd7c799b011b326791580..b964eab2c45856e72e04c0013fd22a315819de78 100644 (file)
@@ -14,7 +14,6 @@
 #include <config.h>
 
 #include "Lexer.h"
-#include "Format.h"
 
 #include "support/convert.h"
 #include "support/debug.h"
@@ -24,8 +23,8 @@
 #include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/lyxalgo.h"
-#include "support/types.h"
 
+#include <algorithm> // sort, lower_bound
 #include <functional>
 #include <fstream>
 #include <istream>
@@ -81,9 +80,6 @@ public:
        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_;
 
@@ -149,7 +145,7 @@ bool compareTags(LexerKeyword const & a, LexerKeyword const & b)
 
 
 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();
@@ -235,38 +231,14 @@ void Lexer::Pimpl::popTable()
 
 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)
-                       LYXERR(Debug::LYXLEX, "Error in LyXLex::setFile: "
-                               "file or stream already set.");
-               gz_.open(filename.toFilesystemEncoding().c_str(), ios::in);
+                       LYXERR0("Error in LyXLex::setFile: file or stream already set.");
+               gz_.open(filename.toSafeFilesystemEncoding().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) {
@@ -284,10 +256,8 @@ bool Lexer::Pimpl::setFile(FileName const & filename)
 
 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;
 }
@@ -330,7 +300,7 @@ bool Lexer::Pimpl::next(bool esc /* = false */)
                        string dummy;
                        getline(is, dummy);
 
-                       LYXERR(Debug::LYXLEX, "Comment read: `" << c << dummy << '\'');
+                       LYXERR(Debug::LYXLEX, "Comment read: `" << string(1, c) << dummy << '\'');
 #else
                        // unfortunately ignore is buggy (Lgb)
                        is.ignore(100, '\n');
@@ -720,6 +690,7 @@ docstring Lexer::getLongString(docstring const & endtoken)
        docstring str;
        docstring prefix;
        bool firstline = true;
+       bool foundend = false;
 
        while (pimpl_->is) { //< eatLine only reads from is, not from pushTok
                if (!eatLine())
@@ -731,8 +702,10 @@ docstring Lexer::getLongString(docstring const & endtoken)
                LYXERR(Debug::PARSER, "LongString: `" << tmpstr << '\'');
 
                // We do a case independent comparison, like searchKeyword does.
-               if (compare_no_case(token, endtoken) == 0)
+               if (compare_no_case(token, endtoken) == 0) {
+                       foundend = true;
                        break;
+               }
 
                if (firstline) {
                        size_t i = tmpstr.find_first_not_of(from_ascii(" \t"));
@@ -750,7 +723,7 @@ docstring Lexer::getLongString(docstring const & endtoken)
                str += tmpstr + '\n';
        }
 
-       if (!pimpl_->is)
+       if (!foundend)
                printError("Long string not ended by `" + to_utf8(endtoken) + '\'');
 
        return str;
@@ -945,9 +918,9 @@ bool Lexer::checkFor(char const * required)
 }
 
 
-void Lexer::setContext(std::string const & str)
+void Lexer::setContext(std::string const & functionName)
 {
-       pimpl_->context = str;
+       pimpl_->context = functionName;
 }