]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
More 'standard conformant blurb' nonsense.
[lyx.git] / src / buffer.C
index 6ffdecd0563907d9a8209f79d783bc135e90bd10..9c19e1bb73aaa589a8759f82a67af12122afe2ac 100644 (file)
@@ -246,7 +246,7 @@ void unknownClass(string const & unknown)
 {
        Alert::warning(_("Unknown document class"),
                bformat(_("Using the default document class, because the "
-                       " class %1$s is unknown."), unknown));
+                       "class %1$s is unknown."), unknown));
 }
 
 } // anon
@@ -295,7 +295,7 @@ int Buffer::readHeader(LyXLex & lex)
 // changed to be public and have one parameter
 // if par = 0 normal behavior
 // else insert behavior
-// Returns false if "\the_end" is not read (Asger)
+// Returns false if "\end_document" is not read (Asger)
 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
 {
        Paragraph::depth_type depth = 0;
@@ -329,7 +329,7 @@ bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
                lyxerr[Debug::PARSER] << "Handling token: `"
                                      << token << '\'' << endl;
 
-               if (token == "\\the_end") {
+               if (token == "\\end_document") {
                        the_end_read = true;
                        continue;
                }
@@ -348,7 +348,7 @@ int Buffer::readParagraph(LyXLex & lex, string const & token,
        static Change current_change;
        int unknown = 0;
 
-       if (token == "\\layout") {
+       if (token == "\\begin_layout") {
                lex.pushToken(token);
 
                Paragraph par;
@@ -440,8 +440,17 @@ void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
 }
 
 
-bool Buffer::readFile(LyXLex & lex, string const & filename)
+bool Buffer::readFile(string const & filename)
 {
+       // Check if the file is compressed.
+       string const format = getExtFromContents(filename);
+       if (format == "gzip" || format == "zip" || format == "compress") {
+               params.compressed = true;
+       }
+
+       LyXLex lex(0, 0);
+       lex.setFile(filename);
+
        bool ret = readFile(lex, filename, paragraphs.begin());
 
        // After we have read a file, we must ensure that the buffer
@@ -474,6 +483,8 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
 
        // the first token _must_ be...
        if (token != "\\lyxformat") {
+               lyxerr << "Token: " << token << endl;
+
                Alert::error(_("Document format failure"),
                        _("The specified document is not a LyX document."));
                return false;
@@ -487,7 +498,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
        //lyxerr << "           dot found at " << dot << endl;
        if (dot != string::npos)
                        tmp_format.erase(dot, 1);
-       file_format = strToInt(tmp_format);
+       int file_format = strToInt(tmp_format);
        //lyxerr << "format: " << file_format << endl;
        if (file_format == LYX_FORMAT) {
                // current format
@@ -513,7 +524,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename,
                                return false;
                        }
                        command += " -t"
-                               +tostr(LYX_FORMAT) + ' '
+                               + tostr(LYX_FORMAT) + ' '
                                + QuoteName(filename);
                        lyxerr[Debug::INFO] << "Running '"
                                            << command << '\''
@@ -637,23 +648,25 @@ bool Buffer::writeFile(string const & fname) const
                return false;
        }
 
-       bool const compressed = (fname.substr(fname.size() - 3, 3) == ".gz");
+       bool retval;
 
-       if (compressed) {
+       if (params.compressed) {
                gz::ogzstream ofs(fname.c_str());
 
                if (!ofs)
                        return false;
 
-               return do_writeFile(ofs);
+               retval = do_writeFile(ofs);
 
-       }
+       } else {
+               ofstream ofs(fname.c_str());
+               if (!ofs)
+                       return false;
 
-       ofstream ofs(fname.c_str());
-       if (!ofs)
-               return false;
+               retval = do_writeFile(ofs);
+       }
 
-       return do_writeFile(ofs);
+       return retval;
 }
 
 
@@ -687,7 +700,7 @@ bool Buffer::do_writeFile(ostream & ofs) const
                pit->write(this, ofs, params, depth);
 
        // Write marker that shows file is complete
-       ofs << "\n\\the_end" << endl;
+       ofs << "\n\\end_document" << endl;
 
        // Shouldn't really be needed....
        //ofs.close();