]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
zlib stuff
[lyx.git] / src / buffer.C
index e3bb16dc57b3f8d1f47b49d42f7275d937e8f913..d242264a1f2a8156b4613febfdeee4c22dde0df5 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)
 {
@@ -635,10 +637,29 @@ bool Buffer::writeFile(string const & fname) const
                return false;
        }
 
+       bool const compressed = (fname.substr(fname.size() - 3, 3) == ".gz");
+
+       if (compressed) {
+               gz::ogzstream ofs(fname.c_str());
+
+               if (!ofs)
+                       return false;
+
+               return do_writeFile(ofs);
+
+       }
+
        ofstream ofs(fname.c_str());
        if (!ofs)
                return false;
 
+       return do_writeFile(ofs);
+}
+
+
+bool Buffer::do_writeFile(ostream & ofs) const
+{
+
 #ifdef HAVE_LOCALE
        // Use the standard "C" locale for file output.
        ofs.imbue(std::locale::classic());
@@ -668,7 +689,8 @@ bool Buffer::writeFile(string const & fname) const
        // Write marker that shows file is complete
        ofs << "\n\\the_end" << endl;
 
-       ofs.close();
+       // Shouldn't really be needed....
+       //ofs.close();
 
        // how to check if close went ok?
        // Following is an attempt... (BE 20001011)
@@ -910,7 +932,7 @@ void Buffer::writeFileAscii(ostream & os, int linelen)
 void Buffer::makeLaTeXFile(string const & fname,
                           string const & original_path,
                           LatexRunParams const & runparams,
-                          bool only_body, bool only_preamble)
+                          bool output_preamble, bool output_body)
 {
        lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
 
@@ -919,7 +941,7 @@ void Buffer::makeLaTeXFile(string const & fname,
                return;
 
        makeLaTeXFile(ofs, original_path,
-                     runparams, only_body, only_preamble);
+                     runparams, output_preamble, output_body);
 
        ofs.close();
        if (ofs.fail()) {
@@ -931,7 +953,7 @@ void Buffer::makeLaTeXFile(string const & fname,
 void Buffer::makeLaTeXFile(ostream & os,
                           string const & original_path,
                           LatexRunParams const & runparams_in,
-                          bool only_body, bool only_preamble)
+                          bool output_preamble, bool output_body)
 {
        LatexRunParams runparams = runparams_in;
        niceFile = runparams.nice; // this will be used by Insetincludes.
@@ -947,7 +969,7 @@ void Buffer::makeLaTeXFile(ostream & os,
        // first paragraph of the document. (Asger)
        texrow.start(paragraphs.begin()->id(), 0);
 
-       if (!only_body && runparams.nice) {
+       if (output_preamble && runparams.nice) {
                os << "%% " << lyx_docversion << " created this file.  "
                        "For more info, see http://www.lyx.org/.\n"
                        "%% Do not edit unless you really know what "
@@ -963,7 +985,7 @@ void Buffer::makeLaTeXFile(ostream & os,
        // input@path is set when the actual parameter
        // original_path is set. This is done for usual tex-file, but not
        // for nice-latex-file. (Matthias 250696)
-       if (!only_body) {
+       if (output_preamble) {
                if (!runparams.nice) {
                        // code for usual, NOT nice-latex-file
                        os << "\\batchmode\n"; // changed
@@ -985,13 +1007,13 @@ void Buffer::makeLaTeXFile(ostream & os,
                // Write the preamble
                runparams.use_babel = params.writeLaTeX(os, features, texrow);
 
-               if (only_preamble)
+               if (!output_body)
                        return;
 
                // make the body.
                os << "\\begin{document}\n";
                texrow.newline();
-       } // only_body
+       } // output_preamble
        lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
 
        if (!lyxrc.language_auto_begin) {
@@ -1014,7 +1036,7 @@ void Buffer::makeLaTeXFile(ostream & os,
                texrow.newline();
        }
 
-       if (!only_body) {
+       if (output_preamble) {
                os << "\\end{document}\n";
                texrow.newline();