]> git.lyx.org Git - lyx.git/commitdiff
factorize some code
authorAlfredo Braunstein <abraunst@lyx.org>
Sat, 26 Jul 2003 20:09:56 +0000 (20:09 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Sat, 26 Jul 2003 20:09:56 +0000 (20:09 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7367 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/buffer.C

index 1389357193510ab0fe44eddeae6f716fa26b62b1..38447aae55cb78b1073d321c7be9c8a424a2c673 100644 (file)
@@ -1,3 +1,7 @@
+2003-07.26  Alfredo Braunstein  <abraunst@libero.it>
+
+       * buffer.C (openFileWrite): factorize some code 
+
 2003-07-26  Angus Leeming  <leeming@lyx.org>
 
        * lyx_cb.C:
index a14548c6fbd9d13695141791af5f73638e19237d..e3bb16dc57b3f8d1f47b49d42f7275d937e8f913 100644 (file)
@@ -116,6 +116,20 @@ namespace {
 
 const int LYX_FORMAT = 224;
 
+bool openFileWrite(ofstream & ofs, string const & fname)
+{
+       ofs.open(fname.c_str());
+       if (!ofs) {
+               string const file = MakeDisplayPath(fname, 50);
+               string text = bformat(_("Could not open the specified "
+                                       "document\n%1$s."), file);
+               Alert::error(_("Could not open file"), text);
+               return false;
+       }
+       return true;
+}
+
+
 } // namespace anon
 
 Buffer::Buffer(string const & file, bool ronly)
@@ -622,9 +636,8 @@ bool Buffer::writeFile(string const & fname) const
        }
 
        ofstream ofs(fname.c_str());
-       if (!ofs) {
+       if (!ofs)
                return false;
-       }
 
 #ifdef HAVE_LOCALE
        // Use the standard "C" locale for file output.
@@ -875,13 +888,9 @@ string const Buffer::asciiParagraph(Paragraph const & par,
 
 void Buffer::writeFileAscii(string const & fname, int linelen)
 {
-       ofstream ofs(fname.c_str());
-       if (!ofs) {
-               string const file = MakeDisplayPath(fname, 50);
-               string text = bformat(_("Could not save the document\n%1$s."), file);
-               Alert::error(_("Could not save document"), text);
+       ofstream ofs;
+       if (!::openFileWrite(ofs, fname))
                return;
-       }
        writeFileAscii(ofs, linelen);
 }
 
@@ -898,7 +907,6 @@ void Buffer::writeFileAscii(ostream & os, int linelen)
 }
 
 
-
 void Buffer::makeLaTeXFile(string const & fname,
                           string const & original_path,
                           LatexRunParams const & runparams,
@@ -906,14 +914,9 @@ void Buffer::makeLaTeXFile(string const & fname,
 {
        lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
 
-       ofstream ofs(fname.c_str());
-       if (!ofs) {
-               string const file = MakeDisplayPath(fname, 50);
-               string text = bformat(_("Could not open the specified document\n%1$s."),
-                       file);
-               Alert::error(_("Could not open file"), text);
+       ofstream ofs;
+       if (!::openFileWrite(ofs, fname))
                return;
-       }
 
        makeLaTeXFile(ofs, original_path,
                      runparams, only_body, only_preamble);
@@ -1068,15 +1071,9 @@ bool Buffer::isSGML() const
 
 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
 {
-       ofstream ofs(fname.c_str());
-
-       if (!ofs) {
-               string const file = MakeDisplayPath(fname, 50);
-               string text = bformat(_("Could not save the specified document\n%1$s.\n"),
-                       file);
-               Alert::error(_("Could not save document"), text);
+       ofstream ofs;
+       if (!::openFileWrite(ofs, fname))
                return;
-       }
 
        niceFile = nice; // this will be used by included files.
 
@@ -1504,14 +1501,9 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
 
 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
 {
-       ofstream ofs(fname.c_str());
-       if (!ofs) {
-               string const file = MakeDisplayPath(fname, 50);
-               string text = bformat(_("Could not save the specified document\n%1$s.\n"),
-                       file);
-               Alert::error(_("Could not save document"), text);
+       ofstream ofs;
+       if (!::openFileWrite(ofs, fname))
                return;
-       }
 
        niceFile = nice; // this will be used by Insetincludes.