]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
More 'standard conformant blurb' nonsense.
[lyx.git] / src / buffer.C
index efb8945115ba09e442ce90402a205a4cbf607547..9c19e1bb73aaa589a8759f82a67af12122afe2ac 100644 (file)
@@ -55,6 +55,7 @@
 
 #include "graphics/Previews.h"
 
+#include "support/LAssert.h"
 #include "support/textutils.h"
 #include "support/filetools.h"
 #include "support/path.h"
@@ -64,6 +65,7 @@
 #include "support/FileInfo.h"
 #include "support/lyxmanip.h"
 #include "support/lyxtime.h"
+#include "support/gzstream.h"
 
 #include <boost/bind.hpp>
 #include <boost/tuple/tuple.hpp>
@@ -114,7 +116,7 @@ extern BufferList bufferlist;
 
 namespace {
 
-const int LYX_FORMAT = 224;
+const int LYX_FORMAT = 225;
 
 bool openFileWrite(ofstream & ofs, string const & fname)
 {
@@ -244,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
@@ -293,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;
@@ -327,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;
                }
@@ -346,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;
@@ -438,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
@@ -472,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;
@@ -485,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
@@ -511,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 << '\''
@@ -635,9 +648,30 @@ bool Buffer::writeFile(string const & fname) const
                return false;
        }
 
-       ofstream ofs(fname.c_str());
-       if (!ofs)
-               return false;
+       bool retval;
+
+       if (params.compressed) {
+               gz::ogzstream ofs(fname.c_str());
+
+               if (!ofs)
+                       return false;
+
+               retval = do_writeFile(ofs);
+
+       } else {
+               ofstream ofs(fname.c_str());
+               if (!ofs)
+                       return false;
+
+               retval = do_writeFile(ofs);
+       }
+
+       return retval;
+}
+
+
+bool Buffer::do_writeFile(ostream & ofs) const
+{
 
 #ifdef HAVE_LOCALE
        // Use the standard "C" locale for file output.
@@ -647,7 +681,7 @@ bool Buffer::writeFile(string const & fname) const
        // The top of the file should not be written by params.
 
        // write out a comment in the top of the file
-       ofs << '#' << lyx_docversion
+       ofs << "#LyX " << lyx_version
            << " created this file. For more info see http://www.lyx.org/\n"
            << "\\lyxformat " << LYX_FORMAT << "\n";
 
@@ -666,9 +700,10 @@ bool Buffer::writeFile(string const & fname) const
                pit->write(this, ofs, params, depth);
 
        // Write marker that shows file is complete
-       ofs << "\n\\the_end" << endl;
+       ofs << "\n\\end_document" << endl;
 
-       ofs.close();
+       // Shouldn't really be needed....
+       //ofs.close();
 
        // how to check if close went ok?
        // Following is an attempt... (BE 20001011)
@@ -948,7 +983,7 @@ void Buffer::makeLaTeXFile(ostream & os,
        texrow.start(paragraphs.begin()->id(), 0);
 
        if (output_preamble && runparams.nice) {
-               os << "%% " << lyx_docversion << " created this file.  "
+               os << "%% LyX " << lyx_version << " created this file.  "
                        "For more info, see http://www.lyx.org/.\n"
                        "%% Do not edit unless you really know what "
                        "you are doing.\n";
@@ -1111,7 +1146,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
                }
        }
 
-       ofs << "<!-- "  << lyx_docversion
+       ofs << "<!-- LyX "  << lyx_version
            << " created this file. For more info see http://www.lyx.org/"
            << " -->\n";
 
@@ -1542,7 +1577,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
        }
        sgml::openTag(ofs, 0, false, top);
 
-       ofs << "<!-- DocBook file was created by " << lyx_docversion
+       ofs << "<!-- DocBook file was created by LyX " << lyx_version
            << "\n  See http://www.lyx.org/ for more information -->\n";
 
        vector<string> environment_stack(10);