#include "support/types.h"
#include "support/FileZipListDir.h"
-#if !defined (HAVE_FORK)
-# define fork() -1
-#endif
-
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
namespace {
-int const LYX_FORMAT = 310; // Bernhard Reiter: support for \nocite{*}
+int const LYX_FORMAT = 313; // Richard Heck: conversion of module representations
} // namespace anon
map<string, ErrorList> errorLists;
/// all embedded files of this buffer
- EmbeddedFiles embedded_files;
+ EmbeddedFileList embedded_files;
/// timestamp and checksum used to test if the file has been externally
/// modified. (Used to properly enable 'File->Revert to saved', bug 4114).
/// A cache for the bibfiles (including bibfiles of loaded child
/// documents), needed for appropriate update of natbib labels.
- mutable FileNameList bibfilesCache_;
+ mutable EmbeddedFileList bibfilesCache_;
};
/// Creates the per buffer temporary directory
: parent_buffer(0), lyx_clean(true), bak_clean(true), unnamed(false),
read_only(readonly_), filename(file), file_fully_loaded(false),
inset(params), toc_backend(&parent), macro_lock(false),
- embedded_files(&parent), timestamp_(0), checksum_(0), wa_(0),
+ embedded_files(), timestamp_(0), checksum_(0), wa_(0),
undo_(parent)
{
temppath = createBufferTmpDir();
}
-EmbeddedFiles & Buffer::embeddedFiles()
+EmbeddedFileList & Buffer::embeddedFiles()
{
return d->embedded_files;
}
-EmbeddedFiles const & Buffer::embeddedFiles() const
+EmbeddedFileList const & Buffer::embeddedFiles() const
{
return d->embedded_files;
}
+bool Buffer::embedded() const
+{
+ return params().embedded;
+}
+
+
Undo & Buffer::undo()
{
return d->undo_;
errorList.push_back(ErrorItem(_("Document header error"),
s, -1, 0, 0));
}
+
+ params().makeTextClass();
return unknown_tokens;
}
BOOST_ASSERT(paragraphs().empty());
readHeader(lex);
- TextClass const & baseClass = textclasslist[params().getBaseClass()];
- if (!baseClass.load(filePath())) {
- string theclass = baseClass.name();
- Alert::error(_("Can't load document class"), bformat(
- _("Using the default document class, because the "
- "class %1$s could not be loaded."), from_utf8(theclass)));
- params().setBaseClass(defaultTextclass());
- }
if (params().outputChanges) {
bool dvipost = LaTeXFeatures::isAvailable("dvipost");
FileName lyxfile(addName(temppath(), "content.lyx"));
// if both manifest.txt and file.lyx exist, this is am embedded file
if (lyxfile.exists()) {
+ // if in bundled format, save checksum of the compressed file, not content.lyx
+ saveCheckSum(filename);
params().embedded = true;
fname = lyxfile;
}
}
removeAutosaveFile(d->filename.absFilename());
+
+ if (params().embedded) {
+ message(str + _(" writing embedded files!."));
+ // if embedding is enabled, write file.lyx and all the embedded files
+ // to the zip file fname.
+ if (!d->embedded_files.writeFile(fname, *this)) {
+ message(str + _(" could not write embedded files!."));
+ return false;
+ }
+ }
saveCheckSum(d->filename);
message(str + _(" done."));
- if (!params().embedded)
- return true;
-
- message(str + _(" writing embedded files!."));
- // if embedding is enabled, write file.lyx and all the embedded files
- // to the zip file fname.
- if (!d->embedded_files.writeFile(fname)) {
- message(str + _(" could not write embedded files!."));
- return false;
- }
- message(str + _(" error while writing embedded files."));
return true;
}
<< "\\lyxformat " << LYX_FORMAT << "\n"
<< "\\begin_document\n";
-
/// For each author, set 'used' to true if there is a change
/// by this author in the document; otherwise set it to 'false'.
AuthorList::Authors::const_iterator a_it = params().authors().begin();
for (; a_it != a_end; ++a_it)
a_it->second.setUsed(false);
- ParIterator const end = par_iterator_end();
- ParIterator it = par_iterator_begin();
+ ParIterator const end = const_cast<Buffer *>(this)->par_iterator_end();
+ ParIterator it = const_cast<Buffer *>(this)->par_iterator_begin();
for ( ; it != end; ++it)
it->checkAuthors(params().authors());
if (it->lyxCode() == BIBTEX_CODE) {
InsetBibtex const & inset =
static_cast<InsetBibtex const &>(*it);
- FileNameList const bibfiles = inset.getFiles(*this);
+ EmbeddedFileList const bibfiles = inset.getFiles(*this);
d->bibfilesCache_.insert(d->bibfilesCache_.end(),
bibfiles.begin(),
bibfiles.end());
InsetInclude & inset =
static_cast<InsetInclude &>(*it);
inset.updateBibfilesCache(*this);
- FileNameList const & bibfiles =
+ EmbeddedFileList const & bibfiles =
inset.getBibfilesCache(*this);
d->bibfilesCache_.insert(d->bibfilesCache_.end(),
bibfiles.begin(),
}
-FileNameList const & Buffer::getBibfilesCache() const
+EmbeddedFileList const & Buffer::getBibfilesCache() const
{
// if this is a child document and the parent is already loaded
// use the parent's cache instead
}
-ParIterator Buffer::getParFromID(int const id) const
+ParConstIterator Buffer::getParFromID(int const id) const
{
ParConstIterator it = par_iterator_begin();
ParConstIterator const end = par_iterator_end();
}
+ParIterator Buffer::getParFromID(int const id)
+{
+ ParIterator it = par_iterator_begin();
+ ParIterator const end = par_iterator_end();
+
+ if (id < 0) {
+ // John says this is called with id == -1 from undo
+ lyxerr << "getParFromID(), id: " << id << endl;
+ return end;
+ }
+
+ for (; it != end; ++it)
+ if (it->id() == id)
+ return it;
+
+ return end;
+}
+
+
bool Buffer::hasParWithID(int const id) const
{
ParConstIterator const it = getParFromID(id);
void Buffer::updateMacroInstances() const
{
- LYXERR(Debug::MACROS, "updateMacroInstances for " << d->filename.onlyFileName());
- ParIterator it = par_iterator_begin();
- ParIterator end = par_iterator_end();
+ LYXERR(Debug::MACROS, "updateMacroInstances for "
+ << d->filename.onlyFileName());
+ ParConstIterator it = par_iterator_begin();
+ ParConstIterator end = par_iterator_end();
for (; it != end; it.forwardPos()) {
// look for MathData cells in InsetMathNest insets
Inset * inset = it.nextInset();
MacroData const * data =
d->parent_buffer->getMacro(*it, *this, false);
if (data)
- data->write(os, true);
+ data->write(os, true);
}
}
};
-#if !defined (HAVE_FORK)
-# define fork() -1
-#endif
-
int AutoSaveBuffer::generateChild()
{
// tmp_ret will be located (usually) in /tmp
// will that be a problem?
+ // Note that this calls ForkedCalls::fork(), so it's
+ // ok cross-platform.
pid_t const pid = fork();
// If you want to debug the autosave
// you should set pid to -1, and comment out the fork.
- if (pid == 0 || pid == -1) {
- // pid = -1 signifies that lyx was unable
- // to fork. But we will do the save
- // anyway.
- bool failed = false;
-
- FileName const tmp_ret = FileName::tempName("lyxauto");
- if (!tmp_ret.empty()) {
- buffer_.writeFile(tmp_ret);
- // assume successful write of tmp_ret
- if (!tmp_ret.moveTo(fname_)) {
- failed = true;
- // most likely couldn't move between
- // filesystems unless write of tmp_ret
- // failed so remove tmp file (if it
- // exists)
- tmp_ret.removeFile();
- }
- } else {
+ if (pid != 0 && pid != -1)
+ return pid;
+
+ // pid = -1 signifies that lyx was unable
+ // to fork. But we will do the save
+ // anyway.
+ bool failed = false;
+ FileName const tmp_ret = FileName::tempName("lyxauto");
+ if (!tmp_ret.empty()) {
+ buffer_.writeFile(tmp_ret);
+ // assume successful write of tmp_ret
+ if (!tmp_ret.moveTo(fname_))
failed = true;
- }
-
- if (failed) {
- // failed to write/rename tmp_ret so try writing direct
- if (!buffer_.writeFile(fname_)) {
- // It is dangerous to do this in the child,
- // but safe in the parent, so...
- if (pid == -1) // emit message signal.
- buffer_.message(_("Autosave failed!"));
- }
- }
- if (pid == 0) { // we are the child so...
- _exit(0);
+ } else
+ failed = true;
+
+ if (failed) {
+ // failed to write/rename tmp_ret so try writing direct
+ if (!buffer_.writeFile(fname_)) {
+ // It is dangerous to do this in the child,
+ // but safe in the parent, so...
+ if (pid == -1) // emit message signal.
+ buffer_.message(_("Autosave failed!"));
}
}
+
+ if (pid == 0) // we are the child so...
+ _exit(0);
+
return pid;
}
if (!success)
return false;
- if (put_in_tempdir)
+ if (put_in_tempdir) {
result_file = tmp_result_file.absFilename();
- else {
- result_file = changeExtension(absFileName(), ext);
- // We need to copy referenced files (e. g. included graphics
- // if format == "dvi") to the result dir.
- vector<ExportedFile> const files =
- runparams.exportdata->externalFiles(format);
- string const dest = onlyPath(result_file);
- CopyStatus status = SUCCESS;
- for (vector<ExportedFile>::const_iterator it = files.begin();
- it != files.end() && status != CANCEL; ++it) {
- string const fmt =
- formats.getFormatFromFile(it->sourceName);
- status = copyFile(fmt, it->sourceName,
- makeAbsPath(it->exportName, dest),
- it->exportName, status == FORCE);
- }
- if (status == CANCEL) {
- message(_("Document export cancelled."));
- } else if (tmp_result_file.exists()) {
- // Finally copy the main file
- status = copyFile(format, tmp_result_file,
- FileName(result_file), result_file,
- status == FORCE);
- message(bformat(_("Document exported as %1$s "
- "to file `%2$s'"),
- formats.prettyName(format),
- makeDisplayPath(result_file)));
- } else {
- // This must be a dummy converter like fax (bug 1888)
- message(bformat(_("Document exported as %1$s"),
- formats.prettyName(format)));
- }
+ return true;
+ }
+
+ result_file = changeExtension(absFileName(), ext);
+ // We need to copy referenced files (e. g. included graphics
+ // if format == "dvi") to the result dir.
+ vector<ExportedFile> const files =
+ runparams.exportdata->externalFiles(format);
+ string const dest = onlyPath(result_file);
+ CopyStatus status = SUCCESS;
+ for (vector<ExportedFile>::const_iterator it = files.begin();
+ it != files.end() && status != CANCEL; ++it) {
+ string const fmt = formats.getFormatFromFile(it->sourceName);
+ status = copyFile(fmt, it->sourceName,
+ makeAbsPath(it->exportName, dest),
+ it->exportName, status == FORCE);
+ }
+ if (status == CANCEL) {
+ message(_("Document export cancelled."));
+ } else if (tmp_result_file.exists()) {
+ // Finally copy the main file
+ status = copyFile(format, tmp_result_file,
+ FileName(result_file), result_file,
+ status == FORCE);
+ message(bformat(_("Document exported as %1$s "
+ "to file `%2$s'"),
+ formats.prettyName(format),
+ makeDisplayPath(result_file)));
+ } else {
+ // This must be a dummy converter like fax (bug 1888)
+ message(bformat(_("Document exported as %1$s"),
+ formats.prettyName(format)));
}
return true;