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)
}
ofstream ofs(fname.c_str());
- if (!ofs) {
+ if (!ofs)
return false;
- }
#ifdef HAVE_LOCALE
// Use the standard "C" locale for file output.
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);
}
}
-
void Buffer::makeLaTeXFile(string const & fname,
string const & original_path,
LatexRunParams const & runparams,
{
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);
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.
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.