From d891a896f47df2d7f048ad7e4498f2fd4f3c5d3b Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 25 Feb 2004 12:00:53 +0000 Subject: [PATCH] Georg Baum\'s no-tempdir patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8458 a592a061-630c-0410-9148-cb99ea01b6c8 --- po/POTFILES.in | 4 - src/ChangeLog | 12 +++ src/buffer.C | 41 ++++++---- src/buffer.h | 4 +- src/cursor.C | 2 +- src/cursor.h | 2 +- src/exporter.C | 3 +- src/frontends/controllers/ChangeLog | 5 ++ src/frontends/controllers/ControlPrint.C | 5 +- src/frontends/controllers/ControlSendto.C | 6 +- src/frontends/qt2/ChangeLog | 5 ++ src/frontends/qt2/QPrefs.C | 2 - src/frontends/qt2/QPrefsDialog.C | 1 - src/frontends/qt2/ui/QPrefPathsModule.ui | 25 ++---- src/frontends/xforms/ChangeLog | 4 + src/frontends/xforms/FormPreferences.C | 29 +------ .../xforms/forms/form_preferences.fd | 23 +----- src/graphics/ChangeLog | 7 ++ src/graphics/GraphicsCacheItem.C | 17 +++- src/graphics/PreviewLoader.C | 9 +- src/insets/ChangeLog | 10 +++ src/insets/insetexternal.C | 4 +- src/insets/insetgraphics.C | 35 ++------ src/insets/insetinclude.C | 82 +++++++++---------- src/lyx_main.C | 18 +++- src/lyxlex.h | 2 +- src/lyxrc.C | 12 +-- src/lyxrc.h | 2 - src/lyxvc.C | 5 ++ src/paragraph.C | 2 +- src/paragraph.h | 2 +- src/support/ChangeLog | 10 +++ src/support/filename.h | 2 +- src/support/filetools.C | 43 ++++++---- src/support/filetools.h | 26 ++++-- 35 files changed, 246 insertions(+), 215 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 9f0e10e39f..49d141d484 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -5,12 +5,10 @@ src/Chktex.C src/LColor.C src/LaTeX.C src/MenuBackend.C -src/ParagraphParameters.C src/buffer.C src/buffer_funcs.C src/bufferlist.C src/bufferparams.C -src/bufferview_funcs.C src/converter.C src/debug.C src/exporter.C @@ -195,8 +193,6 @@ src/paragraph.C src/paragraph_funcs.C src/rowpainter.C src/support/globbing.C -src/support/path_defines.C -src/tex2lyx/lengthcommon.C src/text.C src/text2.C src/text3.C diff --git a/src/ChangeLog b/src/ChangeLog index 0179a4656a..b93255d5a2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2004-02-21 Georg Baum + + * lyxrc.C, buffer.C, exporter.C: use always a temp dir, ignore + use_tempdir in preferences + * buffer.C (readFile), lyxvc.C (getLogFile): check success of + tempfile creation + * lyx_main.C: ensure that tempdir is valid + * lyxlex.h: correct typo + * buffer.[Ch] (isMultiLingual), (isUnnamed): make const + * paragraph.[Ch] (isMultiLingual): make const + * cursor.[Ch] (openable): make const + 2004-02-20 Jürgen Spitzmüller * text3.C: fixed LFUN_QUOTE and add lfun arguments single/double. diff --git a/src/buffer.C b/src/buffer.C index 109ce4ee12..ca80561974 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -34,6 +34,7 @@ #include "lyxtext.h" #include "lyxrc.h" #include "lyxvc.h" +#include "lyx_main.h" #include "messages.h" #include "output.h" #include "output_docbook.h" @@ -85,7 +86,7 @@ using lyx::support::atoi; using lyx::support::bformat; using lyx::support::ChangeExtension; using lyx::support::cmd_ret; -using lyx::support::CreateBufferTmpDir; +using lyx::support::createBufferTmpDir; using lyx::support::destroyDir; using lyx::support::FileInfo; using lyx::support::FileInfo; @@ -190,8 +191,10 @@ Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_) text(0, 0) { lyxvc.buffer(&parent); - if (readonly_ || lyxrc.use_tempdir) - temppath = CreateBufferTmpDir(); + temppath = createBufferTmpDir(); + // FIXME: And now do something if temppath == string(), because we + // assume from now on that temppath points to a valid temp dir. + // See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg67406.html } @@ -318,10 +321,7 @@ pair const Buffer::getLogName() const if (filename.empty()) return make_pair(Buffer::latexlog, string()); - string path = OnlyPath(filename); - - if (lyxrc.use_tempdir || !IsDirWriteable(path)) - path = temppath(); + string const path = temppath(); string const fname = AddName(path, OnlyFilename(ChangeExtension(filename, @@ -596,6 +596,15 @@ bool Buffer::readFile(LyXLex & lex, string const & filename, filename)); } else if (file_format < LYX_FORMAT) { string const tmpfile = tempName(); + if (tmpfile.empty()) { + Alert::error(_("Conversion failed"), + bformat(_("%1$s is from an earlier" + " version of LyX, but a temporary" + " file for converting it could" + " not be created."), + filename)); + return false; + } string command = LibFileSearch("lyx2lyx", "lyx2lyx"); if (command.empty()) { Alert::error(_("Conversion script not found"), @@ -953,7 +962,7 @@ bool Buffer::isSGML() const void Buffer::makeLinuxDocFile(string const & fname, OutputParams const & runparams, - bool body_only ) + bool body_only) { ofstream ofs; if (!openFileWrite(ofs, fname)) @@ -1074,12 +1083,8 @@ int Buffer::runChktex() // get LaTeX-Filename string const name = getLatexName(); - string path = filePath(); - - string const org_path = path; - if (lyxrc.use_tempdir || !IsDirWriteable(path)) { - path = temppath(); - } + string const path = temppath(); + string const org_path = filePath(); Path p(path); // path to LaTeX file message(_("Running chktex...")); @@ -1272,10 +1277,10 @@ void Buffer::updateDocLang(Language const * nlang) } -bool Buffer::isMultiLingual() +bool Buffer::isMultiLingual() const { - ParIterator end = par_iterator_end(); - for (ParIterator it = par_iterator_begin(); it != end; ++it) + ParConstIterator end = par_iterator_end(); + for (ParConstIterator it = par_iterator_begin(); it != end; ++it) if (it->isMultiLingual(params())) return true; @@ -1424,7 +1429,7 @@ void Buffer::setUnnamed(bool flag) } -bool Buffer::isUnnamed() +bool Buffer::isUnnamed() const { return pimpl_->unnamed; } diff --git a/src/buffer.h b/src/buffer.h index 431725bb37..ccff3086d4 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -181,7 +181,7 @@ public: void setUnnamed(bool flag = true); /// - bool isUnnamed(); + bool isUnnamed() const; /// Mark this buffer as dirty. void markDirty(); @@ -248,7 +248,7 @@ public: void updateDocLang(Language const * nlang); /// - bool isMultiLingual(); + bool isMultiLingual() const; /// Does this mean that this is buffer local? limited_stack & undostack(); diff --git a/src/cursor.C b/src/cursor.C index 99119245a5..6999d9ad00 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -894,7 +894,7 @@ bool LCursor::isInside(InsetBase const * p) } -bool LCursor::openable(MathAtom const & t) +bool LCursor::openable(MathAtom const & t) const { if (!t->isActive()) return false; diff --git a/src/cursor.h b/src/cursor.h index 9fc092b126..54ffb3400b 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -471,7 +471,7 @@ private: /// where in the curent cell does the macro name start? int macroNamePos(); /// can we enter the inset? - bool openable(MathAtom const &); + bool openable(MathAtom const &) const; }; #endif // LYXCURSOR_H diff --git a/src/exporter.C b/src/exporter.C index a58c23e6a1..a40fb40fb7 100644 --- a/src/exporter.C +++ b/src/exporter.C @@ -85,8 +85,7 @@ bool Exporter::Export(Buffer * buffer, string const & format, backend_format = format; string filename = buffer->getLatexName(false); - if (!buffer->temppath().empty()) - filename = AddName(buffer->temppath(), filename); + filename = AddName(buffer->temppath(), filename); filename = ChangeExtension(filename, formats.extension(backend_format)); diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index b6f08b2fca..8f6a66fdd4 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2004-02-21 Georg Baum + + * ControlPrint.C, ControlSendto.C: use always a temp dir + * ControlSendto.C: check return value of buffer()->writeFile() + 2004-02-01 Lars Gullik Bjonnes * biblio.C (parseBibTeX): "=" -> '=' diff --git a/src/frontends/controllers/ControlPrint.C b/src/frontends/controllers/ControlPrint.C index 8c3fb6c829..da85afa9c0 100644 --- a/src/frontends/controllers/ControlPrint.C +++ b/src/frontends/controllers/ControlPrint.C @@ -170,10 +170,7 @@ void ControlPrint::apply() } // Push directory path. - string path = buffer()->filePath(); - if (lyxrc.use_tempdir || !IsDirWriteable(path)) { - path = buffer()->temppath(); - } + string const path = buffer()->temppath(); Path p(path); // there are three cases here: diff --git a/src/frontends/controllers/ControlSendto.C b/src/frontends/controllers/ControlSendto.C index 7f53533d2e..3216d101db 100644 --- a/src/frontends/controllers/ControlSendto.C +++ b/src/frontends/controllers/ControlSendto.C @@ -120,10 +120,10 @@ void ControlSendto::apply() if (format_->name() == "lyx") { filename = ChangeExtension(buffer()->getLatexName(false), format_->extension()); - if (!buffer()->temppath().empty()) - filename = AddName(buffer()->temppath(), filename); + filename = AddName(buffer()->temppath(), filename); - buffer()->writeFile(filename); + if (!buffer()->writeFile(filename)) + return; } else { Exporter::Export(buffer(), format_->name(), true, filename); diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 9f037d2905..1f7458e033 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2004-02-21 Georg Baum + + * QPrefs.C, QPrefsDialog.C, ui/QPrefPathsModule.ui: remove + use_tempdir + 2004-02-20 Jürgen Spitzmüller * QDocument.C: diff --git a/src/frontends/qt2/QPrefs.C b/src/frontends/qt2/QPrefs.C index 19d53f58b3..3c8c1072e4 100644 --- a/src/frontends/qt2/QPrefs.C +++ b/src/frontends/qt2/QPrefs.C @@ -195,7 +195,6 @@ void QPrefs::apply() rc.document_path = fromqstr(pathsmod->workingDirED->text()); rc.template_path = fromqstr(pathsmod->templateDirED->text()); rc.backupdir_path = fromqstr(pathsmod->backupDirED->text()); - rc.use_tempdir = pathsmod->tempDirCB->isChecked(); rc.tempdir_path = fromqstr(pathsmod->tempDirED->text()); // FIXME: should be a checkbox only rc.lyxpipes = fromqstr(pathsmod->lyxserverDirED->text()); @@ -499,7 +498,6 @@ void QPrefs::update_contents() pathsmod->workingDirED->setText(toqstr(rc.document_path)); pathsmod->templateDirED->setText(toqstr(rc.template_path)); pathsmod->backupDirED->setText(toqstr(rc.backupdir_path)); - pathsmod->tempDirCB->setChecked(rc.use_tempdir); pathsmod->tempDirED->setText(toqstr(rc.tempdir_path)); // FIXME: should be a checkbox only pathsmod->lyxserverDirED->setText(toqstr(rc.lyxpipes)); diff --git a/src/frontends/qt2/QPrefsDialog.C b/src/frontends/qt2/QPrefsDialog.C index f0532564a5..169c9afb9d 100644 --- a/src/frontends/qt2/QPrefsDialog.C +++ b/src/frontends/qt2/QPrefsDialog.C @@ -210,7 +210,6 @@ QPrefsDialog::QPrefsDialog(QPrefs * form) connect(pathsModule->workingDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); connect(pathsModule->templateDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); connect(pathsModule->backupDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); - connect(pathsModule->tempDirCB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor())); connect(pathsModule->tempDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); connect(pathsModule->lyxserverDirED, SIGNAL(textChanged(const QString&)), this, SLOT(change_adaptor())); connect(spellcheckerModule->spellCommandCO, SIGNAL(activated(int)), this, SLOT(change_adaptor())); diff --git a/src/frontends/qt2/ui/QPrefPathsModule.ui b/src/frontends/qt2/ui/QPrefPathsModule.ui index 19c26fe4b5..dda3befe4c 100644 --- a/src/frontends/qt2/ui/QPrefPathsModule.ui +++ b/src/frontends/qt2/ui/QPrefPathsModule.ui @@ -142,14 +142,18 @@ - QCheckBox + QLabel name - tempDirCB + tempDirLA text - &Use temporary directory + &Temporary directory: + + + buddy + tempDirED @@ -251,20 +255,6 @@ - - - tempDirCB - toggled(bool) - tempDirED - setEnabled(bool) - - - tempDirCB - toggled(bool) - tempDirPB - setEnabled(bool) - - workingDirED workingDirPB @@ -274,7 +264,6 @@ backupDirPB lyxserverDirED lyxserverDirPB - tempDirCB tempDirED tempDirPB diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 612e492e1a..6af2e99524 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,7 @@ +2004-02-21 Georg Baum + + * FormPreferences.C, forms/form_preferences.fd: remove use_tempdir + 2004-02-20 Jürgen Spitzmüller * FormDocument.C: diff --git a/src/frontends/xforms/FormPreferences.C b/src/frontends/xforms/FormPreferences.C index 3833d512e4..db10c7371e 100644 --- a/src/frontends/xforms/FormPreferences.C +++ b/src/frontends/xforms/FormPreferences.C @@ -1825,17 +1825,10 @@ void FormPreferences::Paths::apply(LyXRC & rc) { rc.document_path = fl_get_input(dialog_->input_default_path); rc.template_path = fl_get_input(dialog_->input_template_path); + rc.tempdir_path = fl_get_input(dialog_->input_temp_dir); - int button = fl_get_button(dialog_->check_use_temp_dir); - string str = fl_get_input(dialog_->input_temp_dir); - if (!button) - str.erase(); - - rc.use_tempdir = button; - rc.tempdir_path = str; - - button = fl_get_button(dialog_->check_last_files); - str = fl_get_input(dialog_->input_lastfiles); + int button = fl_get_button(dialog_->check_last_files); + string str = fl_get_input(dialog_->input_lastfiles); if (!button) str.erase(); rc.check_lastfiles = button; @@ -1880,7 +1873,6 @@ void FormPreferences::Paths::build() setPrehandler(dialog_->input_backup_path); setPrehandler(dialog_->input_serverpipe); setPrehandler(dialog_->input_temp_dir); - setPrehandler(dialog_->check_use_temp_dir); } @@ -1891,8 +1883,6 @@ FormPreferences::Paths::feedback(FL_OBJECT const * const ob) const return LyXRC::getDescription(LyXRC::RC_DOCUMENTPATH); if (ob == dialog_->input_template_path) return LyXRC::getDescription(LyXRC::RC_TEMPLATEPATH); - if (ob == dialog_->check_use_temp_dir) - return LyXRC::getDescription(LyXRC::RC_USETEMPDIR); if (ob == dialog_->input_temp_dir) return LyXRC::getDescription(LyXRC::RC_TEMPDIRPATH); if (ob == dialog_->check_last_files) @@ -1918,11 +1908,6 @@ bool FormPreferences::Paths::input(FL_OBJECT const * const ob) // !ob if function is called from Paths::update() to de/activate // objects, // otherwise the function is called by an xforms CB via input(). - if (!ob || ob == dialog_->check_use_temp_dir) { - bool const enable = fl_get_button(dialog_->check_use_temp_dir); - setEnabled(dialog_->input_temp_dir, enable); - } - if (!ob || ob == dialog_->check_last_files) { bool const enable = fl_get_button(dialog_->check_last_files); setEnabled(dialog_->input_lastfiles, enable); @@ -2046,13 +2031,7 @@ void FormPreferences::Paths::update(LyXRC const & rc) rc.make_backup); fl_set_input(dialog_->input_backup_path, str.c_str()); - str.erase(); - if (rc.use_tempdir) - str = rc.tempdir_path; - - fl_set_button(dialog_->check_use_temp_dir, - rc.use_tempdir); - fl_set_input(dialog_->input_temp_dir, str.c_str()); + fl_set_input(dialog_->input_temp_dir, rc.tempdir_path.c_str()); str.erase(); if (rc.check_lastfiles) diff --git a/src/frontends/xforms/forms/form_preferences.fd b/src/frontends/xforms/forms/form_preferences.fd index eea380d9d8..a4c47e7a87 100644 --- a/src/frontends/xforms/forms/form_preferences.fd +++ b/src/frontends/xforms/forms/form_preferences.fd @@ -2024,7 +2024,7 @@ argument: 0 Name: form_preferences_paths Width: 450 Height: 350 -Number of Objects: 17 +Number of Objects: 16 -------------------- class: FL_BOX @@ -2116,25 +2116,6 @@ name: button_template_path_browse callback: C_FormBaseInputCB argument: 0 --------------------- -class: FL_CHECKBUTTON -type: PUSH_BUTTON -box: 140 80 30 30 -boxtype: FL_NO_BOX -colors: FL_COL1 FL_YELLOW -alignment: FL_ALIGN_LEFT -style: FL_NORMAL_STYLE -size: FL_NORMAL_SIZE -lcol: FL_BLACK -label: Temp dir:|#d -shortcut: -resize: FL_RESIZE_ALL -gravity: FL_NoGravity FL_NoGravity -name: check_use_temp_dir -callback: C_FormBaseInputCB -argument: 0 - value: 1 - -------------------- class: FL_INPUT type: NORMAL_INPUT @@ -2145,7 +2126,7 @@ alignment: FL_ALIGN_LEFT style: FL_NORMAL_STYLE size: FL_NORMAL_SIZE lcol: FL_BLACK -label: +label: Temp dir:|#d shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 0a18e061b2..b4d02c4208 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,10 @@ +2004-02-21 Georg Baum + + * GraphicsCacheItem.C (convertToDisplayFormat): unzip zipped files + to a temporary file + * PreviewLoader.C: use always a temp dir + * PreviewLoader.C: check successfull creation of LaTeX file + 2004-01-31 Lars Gullik Bjonnes * PreviewLoader.C (FindFirst): inherit from std::unary_function diff --git a/src/graphics/GraphicsCacheItem.C b/src/graphics/GraphicsCacheItem.C index c2e9350947..59973327d4 100644 --- a/src/graphics/GraphicsCacheItem.C +++ b/src/graphics/GraphicsCacheItem.C @@ -36,6 +36,7 @@ using support::getExtFromContents; using support::tempName; using support::unlink; using support::unzipFile; +using support::unzippedFileName; using support::zippedFile; using std::endl; @@ -381,8 +382,19 @@ void CacheItem::Impl::convertToDisplayFormat() } // Make a local copy in case we unzip it - string const filename = zippedFile(filename_) ? - unzipFile(filename_) : filename_; + string filename; + if ((zipped_ = zippedFile(filename_))) { + unzipped_filename_ = tempName(string(), filename_); + if (unzipped_filename_.empty()) { + setStatus(ErrorConverting); + lyxerr[Debug::GRAPHICS] + << "\tCould not create temporary file." << endl; + return; + } + filename = unzipFile(filename_, unzipped_filename_); + } else + filename = filename_; + string const displayed_filename = MakeDisplayPath(filename_); lyxerr[Debug::GRAPHICS] << "[GrahicsCacheItem::convertToDisplayFormat]\n" << "\tAttempting to convert image file: " << filename @@ -412,6 +424,7 @@ void CacheItem::Impl::convertToDisplayFormat() remove_loaded_file_ = true; // Remove the temp file, we only want the name... + // FIXME: This is unsafe! unlink(to_file_base); // Connect a signal to this->imageConverted and pass this signal to diff --git a/src/graphics/PreviewLoader.C b/src/graphics/PreviewLoader.C index 7e2b3ae3db..71ada4dba2 100644 --- a/src/graphics/PreviewLoader.C +++ b/src/graphics/PreviewLoader.C @@ -461,8 +461,7 @@ void PreviewLoader::Impl::startLoading() lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()" << endl; // As used by the LaTeX file and by the resulting image files - string const directory = buffer_.temppath().empty() ? - buffer_.filePath() : buffer_.temppath(); + string const directory = buffer_.temppath(); string const filename_base(unique_filename(directory)); @@ -477,6 +476,12 @@ void PreviewLoader::Impl::startLoading() string const latexfile = filename_base + ".tex"; ofstream of(latexfile.c_str()); + if (!of) { + lyxerr[Debug::GRAPHICS] << "PreviewLoader::startLoading()\n" + << "Unable to create LaTeX file\n" + << latexfile << endl; + return; + } of << "\\batchmode\n"; dumpPreamble(of); of << "\n\\begin{document}\n"; diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 655e9e264e..953a9575d6 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,13 @@ +2004-02-21 Georg Baum + + * insetexternal.C, insetgraphics.C, insetinclude.C: use always a + temp dir + * insetinclude.C (latex): show a GUI warning if textclasses don't + match + * insetinclude.C: use mangledFilename() for temp files + * insetgraphics.C (readInsetGraphics): remove version check, since + the graphics inset has no own fileformat number anymore + 2004-02-20 Jürgen Spitzmüller * insetquotes.[Ch]: added new member that allows direct access diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 3c5d14ea65..9e27a11dfb 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -77,6 +77,7 @@ namespace external { TempName::TempName() { tempname_ = support::tempName(string(), "lyxext"); + // FIXME: This is unsafe support::unlink(tempname_); // must have an extension for the converter code to work correctly. tempname_ += ".tmp"; @@ -685,8 +686,7 @@ int InsetExternal::latex(Buffer const & buf, ostream & os, // run through the LaTeX compiler. // If we're running through the LaTeX compiler, we should write the // generated files in the bufer's temporary directory. - bool const external_in_tmpdir = - lyxrc.use_tempdir && !buf.temppath().empty() && !runparams.nice; + bool const external_in_tmpdir = !runparams.nice; // If the template has specified a PDFLaTeX output, then we try and // use that. diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index bb4a0cdfd0..6b12a172c8 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -29,9 +29,6 @@ TODO /* NOTES: * Fileformat: - * Current version is 1 (inset file format version), when changing it - * it should be changed in the Write() function when writing in one place - * and when reading one should change the version check and the error message. * The filename is kept in the lyx file in a relative way, so as to allow * moving the document file and its images with no problem. * @@ -281,18 +278,7 @@ void InsetGraphics::readInsetGraphics(LyXLex & lex, string const & bufpath) continue; } else if (token == "\\end_inset") { finished = true; - } else if (token == "FormatVersion") { - lex.next(); - int version = lex.getInteger(); - if (version > VersionNumber) - lyxerr - << "This document was created with a newer Graphics widget" - ", You should use a newer version of LyX to read this" - " file." - << endl; - // TODO: Possibly open up a dialog? - } - else { + } else { if (!params_.Read(lex, token, bufpath)) lyxerr << "Unknown token, " << token << ", skipping." << std::endl; @@ -469,9 +455,6 @@ string const InsetGraphics::prepareFile(Buffer const & buf, lyxerr[Debug::GRAPHICS] << "\t we have: from " << from << " to " << to << '\n'; - if (from == to && !lyxrc.use_tempdir) - return stripExtensionIfPossible(orig_file, to); - // We're going to be running the exported buffer through the LaTeX // compiler, so must ensure that LaTeX can cope with the graphics // file format. @@ -480,16 +463,14 @@ string const InsetGraphics::prepareFile(Buffer const & buf, << "\tthe orig file is: " << orig_file << endl; bool conversion_needed = true; - if (lyxrc.use_tempdir) { - CopyStatus status; - boost::tie(status, temp_file) = + CopyStatus status; + boost::tie(status, temp_file) = copyToDirIfNeeded(orig_file, buf.temppath()); - if (status == FAILURE) - return orig_file; - else if (status == IDENTICAL_CONTENTS) - conversion_needed = false; - } + if (status == FAILURE) + return orig_file; + else if (status == IDENTICAL_CONTENTS) + conversion_needed = false; if (from == to) return stripExtensionIfPossible(temp_file, to); @@ -515,7 +496,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf, << "\tto_file_base = " << to_file_base << '\n' << "\t from " << from << " to " << to << '\n'; - // if no special converter defined, than we take the default one + // if no special converter defined, then we take the default one // from ImageMagic: convert from:inname.from to:outname.to if (!converters.convert(&buf, temp_file, to_file_base, from, to)) { string const command = diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index ca9155c5d0..adc479b396 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -28,6 +28,7 @@ #include "metricsinfo.h" #include "outputparams.h" +#include "frontends/Alert.h" #include "frontends/LyXView.h" #include "frontends/Painter.h" @@ -36,6 +37,7 @@ #include "insets/render_preview.h" #include "support/FileInfo.h" +#include "support/filename.h" #include "support/filetools.h" #include "support/lstrings.h" // contains #include "support/tostr.h" @@ -46,9 +48,11 @@ #include "support/std_sstream.h" using lyx::support::AddName; +using lyx::support::bformat; using lyx::support::ChangeExtension; using lyx::support::contains; using lyx::support::FileInfo; +using lyx::support::FileName; using lyx::support::GetFileContents; using lyx::support::IsFileReadable; using lyx::support::IsLyXFilename; @@ -307,30 +311,25 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os, if (loadIfNeeded(buffer, params_)) { Buffer * tmp = bufferlist.getBuffer(included_file); - // FIXME: this should be a GUI warning if (tmp->params().textclass != buffer.params().textclass) { - lyxerr << "WARNING: Included file `" - << MakeDisplayPath(included_file) - << "' has textclass `" - << tmp->params().getLyXTextClass().name() - << "' while parent file has textclass `" - << buffer.params().getLyXTextClass().name() - << "'." << endl; + string text = bformat(_("Included file `%1$s'\n" + "has textclass `%2$s'\n" + "while parent file has textclass `%3$s'."), + MakeDisplayPath(included_file), + tmp->params().getLyXTextClass().name(), + buffer.params().getLyXTextClass().name()); + Alert::warning(_("Different textclasses"), text); //return 0; } // write it to a file (so far the complete file) string writefile = ChangeExtension(included_file, ".tex"); - if (!buffer.temppath().empty() && !runparams.nice) { - incfile = subst(incfile, '/','@'); -#ifdef __EMX__ - incfile = subst(incfile, ':', '$'); -#endif - writefile = AddName(buffer.temppath(), incfile); - } else - writefile = included_file; - writefile = ChangeExtension(writefile, ".tex"); + if (!runparams.nice) { + incfile = FileName(writefile).mangledFilename(); + writefile = MakeAbsPath(incfile, buffer.temppath()); + } + lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; @@ -388,15 +387,16 @@ int InsetInclude::linuxdoc(Buffer const & buffer, ostream & os, Buffer * tmp = bufferlist.getBuffer(included_file); // write it to a file (so far the complete file) - string writefile = ChangeExtension(included_file, ".sgml"); - if (!buffer.temppath().empty() && !runparams.nice) { - incfile = subst(incfile, '/','@'); - writefile = AddName(buffer.temppath(), incfile); - } else + string writefile; + if (IsLyXFilename(included_file)) + writefile = ChangeExtension(included_file, ".sgml"); + else writefile = included_file; - if (IsLyXFilename(included_file)) - writefile = ChangeExtension(writefile, ".sgml"); + if (!runparams.nice) { + incfile = FileName(writefile).mangledFilename(); + writefile = MakeAbsPath(incfile, buffer.temppath()); + } lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; @@ -431,14 +431,16 @@ int InsetInclude::docbook(Buffer const & buffer, ostream & os, Buffer * tmp = bufferlist.getBuffer(included_file); // write it to a file (so far the complete file) - string writefile = ChangeExtension(included_file, ".sgml"); - if (!buffer.temppath().empty() && !runparams.nice) { - incfile = subst(incfile, '/','@'); - writefile = AddName(buffer.temppath(), incfile); - } else - writefile = included_file; + string writefile; if (IsLyXFilename(included_file)) - writefile = ChangeExtension(writefile, ".sgml"); + writefile = ChangeExtension(included_file, ".sgml"); + else + writefile = included_file; + + if (!runparams.nice) { + incfile = FileName(writefile).mangledFilename(); + writefile = MakeAbsPath(incfile, buffer.temppath()); + } lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; @@ -468,19 +470,15 @@ void InsetInclude::validate(LaTeXFeatures & features) const string const included_file = includedFilename(buffer, params_); if (IsLyXFilename(included_file)) - writefile = ChangeExtension(writefile, ".sgml"); - else if (!buffer.temppath().empty() && - !features.nice() && - !isVerbatim(params_)) { - incfile = subst(incfile, '/','@'); -#ifdef __EMX__ -// FIXME: It seems that the following is necessary (see latex() above) -// incfile = subst(incfile, ':', '$'); -#endif - writefile = AddName(buffer.temppath(), incfile); - } else + writefile = ChangeExtension(included_file, ".sgml"); + else writefile = included_file; + if (!features.nice() && !isVerbatim(params_)) { + incfile = FileName(writefile).mangledFilename(); + writefile = MakeAbsPath(incfile, buffer.temppath()); + } + features.includeFile(include_label, writefile); if (isVerbatim(params_)) diff --git a/src/lyx_main.C b/src/lyx_main.C index 53f614750e..7608131af2 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -58,7 +58,7 @@ using lyx::support::AddName; using lyx::support::AddPath; using lyx::support::bformat; using lyx::support::createDirectory; -using lyx::support::CreateLyXTmpDir; +using lyx::support::createLyXTmpDir; using lyx::support::FileInfo; using lyx::support::FileSearch; using lyx::support::GetEnv; @@ -390,7 +390,21 @@ void LyX::init(bool gui) if (lyxerr.debugging(Debug::LYXRC)) lyxrc.print(); - os::setTmpDir(CreateLyXTmpDir(lyxrc.tempdir_path)); + os::setTmpDir(createLyXTmpDir(lyxrc.tempdir_path)); + if (os::getTmpDir().empty()) { + Alert::error(_("Could not create temporary directory"), + bformat(_("Could not create a temporary directory in\n" + "%1$s. Make sure that this\n" + "path exists and is writable and try again."), + lyxrc.tempdir_path)); + // createLyXTmpDir() tries sufficiently hard to create a + // usable temp dir, so the probability to come here is + // close to zero. We therefore don't try to overcome this + // problem with e.g. asking the user for a new path and + // trying again but simply exit. + exit(EXIT_FAILURE); + } + if (lyxerr.debugging(Debug::INIT)) { lyxerr << "LyX tmp dir: `" << os::getTmpDir() << '\'' << endl; } diff --git a/src/lyxlex.h b/src/lyxlex.h index 41da529789..8feb0094a6 100644 --- a/src/lyxlex.h +++ b/src/lyxlex.h @@ -155,7 +155,7 @@ private: This is needed to ensure that the pop is done upon exit from methods with more than one exit point or that can return as a response to exceptions. - @autor Lgb + @author Lgb */ struct pushpophelper { /// diff --git a/src/lyxrc.C b/src/lyxrc.C index 24c940267b..13911fdc68 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -156,6 +156,7 @@ keyword_item lyxrcTags[] = { // compatibility with versions older than 1.4.0 only { "\\use_pspell", LyXRC::RC_USE_SPELL_LIB }, { "\\use_spell_lib", LyXRC::RC_USE_SPELL_LIB }, + // compatibility with versions older than 1.4.0 only { "\\use_tempdir", LyXRC::RC_USETEMPDIR }, { "\\user_email", LyXRC::RC_USER_EMAIL }, { "\\user_name", LyXRC::RC_USER_NAME }, @@ -197,7 +198,6 @@ void LyXRC::setDefaults() { print_paper_dimension_flag = "-T"; document_path.erase(); tempdir_path = "/tmp"; - use_tempdir = true; ps_command = "gs"; view_dvi_paper_option.erase(); default_papersize = PAPER_USLETTER; @@ -657,7 +657,7 @@ int LyXRC::read(string const & filename) case RC_USETEMPDIR: if (lexrc.next()) { - use_tempdir = lexrc.getBool(); + lyxerr << "Ignoring obsolete use_tempdir flag." << endl; } break; @@ -1524,9 +1524,7 @@ void LyXRC::output(ostream & os) const os << "\\tempdir_path \"" << tempdir_path << "\"\n"; } case RC_USETEMPDIR: - if (use_tempdir != system_lyxrc.use_tempdir) { - os << "\\use_tempdir " << tostr(use_tempdir) << '\n'; - } + // Ignore it case RC_ASCII_LINELEN: if (ascii_linelen != system_lyxrc.ascii_linelen) { os << "\\ascii_linelen " << ascii_linelen << '\n'; @@ -1904,10 +1902,6 @@ string const LyXRC::getDescription(LyXRCTags tag) str = _("LyX will place its temporary directories in this path. They will be deleted when you quit LyX."); break; - case RC_USETEMPDIR: - str = _("Select if you wish to use a temporary directory structure to store temporary TeX output."); - break; - case RC_LASTFILES: str = _("The file where the last-files information should be stored."); break; diff --git a/src/lyxrc.h b/src/lyxrc.h index d924039253..019aa61a90 100644 --- a/src/lyxrc.h +++ b/src/lyxrc.h @@ -206,8 +206,6 @@ enum LyXRCTags { /// std::string tempdir_path; /// - bool use_tempdir; - /// bool auto_region_delete; /// flag telling whether lastfiles should be checked for existance bool auto_reset_options; diff --git a/src/lyxvc.C b/src/lyxvc.C index 21c934f102..039e455435 100644 --- a/src/lyxvc.C +++ b/src/lyxvc.C @@ -223,6 +223,11 @@ string const LyXVC::getLogFile() const return string(); string tmpf = tempName(string(), "lyxvclog"); + if (tmpf.empty()) { + lyxerr[Debug::LYXVC] << "Could not generate logfile " + << tmpf << endl; + return string(); + } lyxerr[Debug::LYXVC] << "Generating logfile " << tmpf << endl; vcs->getLog(tmpf); return tmpf; diff --git a/src/paragraph.C b/src/paragraph.C index b46a5a2384..71df78078a 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1556,7 +1556,7 @@ void Paragraph::changeLanguage(BufferParams const & bparams, } -bool Paragraph::isMultiLingual(BufferParams const & bparams) +bool Paragraph::isMultiLingual(BufferParams const & bparams) const { Language const * doc_language = bparams.language; Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin(); diff --git a/src/paragraph.h b/src/paragraph.h index b7324920c7..28067bd2c2 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -80,7 +80,7 @@ public: void changeLanguage(BufferParams const & bparams, Language const * from, Language const * to); /// - bool isMultiLingual(BufferParams const &); + bool isMultiLingual(BufferParams const &) const; /// std::string const asString(Buffer const &, diff --git a/src/support/ChangeLog b/src/support/ChangeLog index 1047ccd03d..afa4bc3153 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,13 @@ +2004-02-21 Georg Baum + + * filetools.[Ch] (CreateBufferTmpDir): rename to createBufferTmpDir, + remove pathfor argument + * filetools.[Ch] (CreateLyXTmpDir): rename to createLyXTmpDir, try + harder to create a usable temp dir + * filetools.C (CreateTmpDir): rename to createTmpDir + filetools.[Ch] (unzipFile): add argument for output filename + * filename.h: fix doxygen warning + 2004-02-01 Lars Gullik Bjonnes * lstrings.h (contains_functor): delete diff --git a/src/support/filename.h b/src/support/filename.h index 4085c51fef..f019fde922 100644 --- a/src/support/filename.h +++ b/src/support/filename.h @@ -22,7 +22,7 @@ namespace support { class FileName { public: FileName(); - /** \param filename the file in question. Must have an absolute path. + /** \param abs_filename the file in question. Must have an absolute path. * \param save_abs_path how is the file to be output to file? */ FileName(std::string const & abs_filename, bool save_abs_path = true); diff --git a/src/support/filetools.C b/src/support/filetools.C index a30d50db13..ccf6d560ce 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -440,11 +440,11 @@ int DeleteAllFilesInDir(string const & path) } -string const CreateTmpDir(string const & tempdir, string const & mask) +string const createTmpDir(string const & tempdir, string const & mask) { lyxerr[Debug::FILES] - << "CreateTmpDir: tempdir=`" << tempdir << "'\n" - << "CreateTmpDir: mask=`" << mask << '\'' << endl; + << "createTmpDir: tempdir=`" << tempdir << "'\n" + << "createTmpDir: mask=`" << mask << '\'' << endl; string const tmpfl(tempName(tempdir, mask)); // lyx::tempName actually creates a file to make sure that it @@ -453,8 +453,11 @@ string const CreateTmpDir(string const & tempdir, string const & mask) // safe because of the gap between unlink and mkdir. (Lgb) unlink(tmpfl); - if (tmpfl.empty() || mkdir(tmpfl, 0700)) + if (tmpfl.empty() || mkdir(tmpfl, 0700)) { + lyxerr << "LyX could not create the temporary directory '" + << tmpfl << "'" << endl; return string(); + } return MakeAbsPath(tmpfl); } @@ -477,36 +480,47 @@ int destroyDir(string const & tmpdir) } -string const CreateBufferTmpDir(string const & pathfor) +string const createBufferTmpDir() { static int count; - static string const tmpdir(pathfor.empty() ? os::getTmpDir() : pathfor); // We are in our own directory. Why bother to mangle name? // In fact I wrote this code to circumvent a problematic behaviour (bug?) // of EMX mkstemp(). - string const tmpfl = tmpdir + "/lyx_tmpbuf" + tostr(count++); + string const tmpfl = os::getTmpDir() + "/lyx_tmpbuf" + tostr(count++); if (mkdir(tmpfl, 0777)) { + lyxerr << "LyX could not create the temporary directory '" + << tmpfl << "'" << endl; return string(); } return tmpfl; } -string const CreateLyXTmpDir(string const & deflt) +string const createLyXTmpDir(string const & deflt) { - if ((!deflt.empty()) && (deflt != "/tmp")) { + if (!deflt.empty() && deflt != "/tmp") { if (mkdir(deflt, 0777)) { + if (IsDirWriteable(deflt)) + // deflt could not be created because it + // did exist already, so let's create our own + // dir inside deflt. #ifdef __EMX__ - Path p(user_lyxdir()); + Path p(user_lyxdir()); +#endif + return createTmpDir(deflt, "lyx_tmpdir"); + else + // some other error occured. +#ifdef __EMX__ + Path p(user_lyxdir()); #endif - return CreateTmpDir(deflt, "lyx_tmpdir"); + return createTmpDir("/tmp", "lyx_tmpdir"); } else return deflt; } else { #ifdef __EMX__ Path p(user_lyxdir()); #endif - return CreateTmpDir("/tmp", "lyx_tmpdir"); + return createTmpDir("/tmp", "lyx_tmpdir"); } } @@ -1080,9 +1094,10 @@ string const unzippedFileName(string const & zipped_file) } -string const unzipFile(string const & zipped_file) +string const unzipFile(string const & zipped_file, string const & unzipped_file) { - string const tempfile = unzippedFileName(zipped_file); + string const tempfile = unzipped_file.empty() ? + unzippedFileName(zipped_file) : unzipped_file; // Run gunzip string const command = "gunzip -c " + zipped_file + " > " + tempfile; Systemcall one; diff --git a/src/support/filetools.h b/src/support/filetools.h index 1a9e5217b7..b145082dd0 100644 --- a/src/support/filetools.h +++ b/src/support/filetools.h @@ -22,14 +22,19 @@ namespace support { /// remove directory and all contents, returns 0 on success int destroyDir(std::string const & tmpdir); -/// -std::string const CreateBufferTmpDir(std::string const & pathfor = std::string()); +/// Creates the per buffer temporary directory +std::string const createBufferTmpDir(); /// Creates directory. Returns true on success bool createDirectory(std::string const & name, int permissions); -/// -std::string const CreateLyXTmpDir(std::string const & deflt); +/** Creates the global LyX temp dir. + \p deflt can be an existing directory name. In this case a new directory + inside \p deflt is created. If \p deflt does not exist yet, \p deflt is + created and used as the temporary directory. + \return the tmp dir name or string() if something went wrong. + */ +std::string const createLyXTmpDir(std::string const & deflt); /** Find file by searching several directories. Uses a string of paths separated by ";"s to find a file to open. @@ -141,11 +146,18 @@ std::string const getExtFromContents(std::string const & name); /// check for zipped file bool zippedFile(std::string const & name); -/// \return the name that LyX will give to the unzipped file. +/** \return the name that LyX will give to the unzipped file \p zipped_file + if the second argument of unzipFile() is empty. + */ std::string const unzippedFileName(std::string const & zipped_file); -/// unzip a file -std::string const unzipFile(std::string const & zipped_file); +/** Unzip \p zipped_file. + The unzipped file is named \p unzipped_file if \p unzipped_file is not + empty, and unzippedFileName(\p zipped_file) otherwise. + Will overwrite an already existing unzipped file without warning. + */ +std::string const unzipFile(std::string const & zipped_file, + std::string const & unzipped_file = std::string()); /// Returns true is path is absolute bool AbsolutePath(std::string const & path); -- 2.39.2