2003-03-29 09:48:03 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file buffer.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 16:55:34 +00:00
|
|
|
|
*
|
2003-03-29 09:48:03 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-03-29 09:48:03 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
2003-06-24 20:42:15 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "bufferlist.h"
|
1999-12-10 00:07:59 +00:00
|
|
|
|
#include "LyXAction.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "lyxlex.h"
|
|
|
|
|
#include "tex-strings.h"
|
|
|
|
|
#include "layout.h"
|
2000-04-12 14:20:08 +00:00
|
|
|
|
#include "bufferview_funcs.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "lyxfont.h"
|
1999-12-15 17:42:22 +00:00
|
|
|
|
#include "version.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "LaTeX.h"
|
|
|
|
|
#include "Chktex.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "language.h"
|
|
|
|
|
#include "exporter.h"
|
2003-05-20 16:51:31 +00:00
|
|
|
|
#include "errorlist.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "Lsstream.h"
|
2003-02-28 09:49:49 +00:00
|
|
|
|
#include "format.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
|
|
|
|
#include "iterators.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#include "lyxtextclasslist.h"
|
2002-08-09 00:42:12 +00:00
|
|
|
|
#include "sgml.h"
|
2002-08-20 19:41:13 +00:00
|
|
|
|
#include "paragraph_funcs.h"
|
2003-04-24 23:19:41 +00:00
|
|
|
|
#include "messages.h"
|
2003-02-08 19:18:01 +00:00
|
|
|
|
#include "author.h"
|
2002-08-20 19:41:13 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/LyXView.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "mathed/formulamacro.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "mathed/formula.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2003-02-21 09:20:18 +00:00
|
|
|
|
#include "insets/insetbibitem.h"
|
|
|
|
|
#include "insets/insetbibtex.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "insets/insetinclude.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
|
#include "insets/insettext.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
|
#include "frontends/Alert.h"
|
|
|
|
|
|
2002-07-05 21:24:15 +00:00
|
|
|
|
#include "graphics/Previews.h"
|
|
|
|
|
|
2003-07-26 23:04:39 +00:00
|
|
|
|
#include "support/LAssert.h"
|
2001-07-23 09:11:14 +00:00
|
|
|
|
#include "support/textutils.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/filetools.h"
|
1999-10-13 17:32:46 +00:00
|
|
|
|
#include "support/path.h"
|
2001-05-17 15:11:01 +00:00
|
|
|
|
#include "support/os.h"
|
2003-05-13 14:36:24 +00:00
|
|
|
|
#include "support/tostr.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
#include "support/FileInfo.h"
|
2000-10-11 21:06:43 +00:00
|
|
|
|
#include "support/lyxmanip.h"
|
2003-02-08 19:18:01 +00:00
|
|
|
|
#include "support/lyxtime.h"
|
2003-07-27 23:40:08 +00:00
|
|
|
|
#include "support/gzstream.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-08-14 22:15:18 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
#include <boost/tuple/tuple.hpp>
|
|
|
|
|
|
2001-12-08 14:20:11 +00:00
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <stack>
|
|
|
|
|
#include <list>
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include <algorithm>
|
2001-12-08 14:20:11 +00:00
|
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <utime.h>
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LOCALE
|
|
|
|
|
#include <locale>
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
using namespace lyx::support;
|
|
|
|
|
|
2002-06-10 07:57:39 +00:00
|
|
|
|
#ifndef CXX_GLOBAL_CSTD
|
|
|
|
|
using std::pow;
|
|
|
|
|
#endif
|
2001-12-08 14:20:11 +00:00
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::ofstream;
|
|
|
|
|
using std::ifstream;
|
|
|
|
|
using std::fstream;
|
|
|
|
|
using std::ios;
|
|
|
|
|
using std::setw;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::pair;
|
2001-02-09 15:54:30 +00:00
|
|
|
|
using std::make_pair;
|
2000-05-19 16:46:01 +00:00
|
|
|
|
using std::vector;
|
2001-03-12 08:52:37 +00:00
|
|
|
|
using std::map;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
using std::stack;
|
|
|
|
|
using std::list;
|
2002-08-14 22:15:18 +00:00
|
|
|
|
using std::for_each;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-11-27 10:34:16 +00:00
|
|
|
|
using lyx::pos_type;
|
2001-11-29 17:12:21 +00:00
|
|
|
|
using lyx::textclass_type;
|
2001-11-27 10:34:16 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// all these externs should eventually be removed.
|
|
|
|
|
extern BufferList bufferlist;
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2003-07-27 21:39:54 +00:00
|
|
|
|
const int LYX_FORMAT = 225;
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
2003-07-26 20:09:56 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
} // namespace anon
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
|
Buffer::Buffer(string const & file, bool ronly)
|
2002-08-12 00:15:19 +00:00
|
|
|
|
: niceFile(true), lyx_clean(true), bak_clean(true),
|
2003-02-09 00:27:52 +00:00
|
|
|
|
unnamed(false), read_only(ronly),
|
2003-07-10 12:26:40 +00:00
|
|
|
|
filename_(file)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
|
2002-01-14 23:31:23 +00:00
|
|
|
|
filepath_ = OnlyPath(file);
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxvc.buffer(this);
|
2002-01-13 00:33:21 +00:00
|
|
|
|
if (read_only || lyxrc.use_tempdir) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmppath = CreateBufferTmpDir();
|
2002-01-13 00:33:21 +00:00
|
|
|
|
} else {
|
|
|
|
|
tmppath.erase();
|
|
|
|
|
}
|
2003-02-08 19:18:01 +00:00
|
|
|
|
|
|
|
|
|
// set initial author
|
2003-03-12 02:39:12 +00:00
|
|
|
|
authors().record(Author(lyxrc.user_name, lyxrc.user_email));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::~Buffer()
|
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// here the buffer should take care that it is
|
|
|
|
|
// saved properly, before it goes into the void.
|
|
|
|
|
|
2003-07-11 12:21:31 +00:00
|
|
|
|
closing();
|
|
|
|
|
|
2003-03-29 09:02:08 +00:00
|
|
|
|
if (!tmppath.empty() && destroyDir(tmppath) != 0) {
|
2003-05-21 21:20:50 +00:00
|
|
|
|
Alert::warning(_("Could not remove temporary directory"),
|
2003-05-13 09:48:57 +00:00
|
|
|
|
bformat(_("Could not remove the temporary directory %1$s"), tmppath));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-08-12 00:15:19 +00:00
|
|
|
|
paragraphs.clear();
|
2002-07-05 21:24:15 +00:00
|
|
|
|
|
|
|
|
|
// Remove any previewed LaTeX snippets assocoated with this buffer.
|
2003-07-21 21:30:57 +00:00
|
|
|
|
lyx::graphics::Previews::get().removeLoader(this);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const Buffer::getLatexName(bool no_path) const
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2002-01-14 23:31:23 +00:00
|
|
|
|
string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
|
2003-05-19 17:03:12 +00:00
|
|
|
|
return no_path ? OnlyFilename(name) : name;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
pair<Buffer::LogType, string> const Buffer::getLogName() const
|
2001-02-06 17:41:42 +00:00
|
|
|
|
{
|
2001-03-14 14:54:30 +00:00
|
|
|
|
string const filename = getLatexName(false);
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
|
|
|
|
if (filename.empty())
|
2001-02-09 15:54:30 +00:00
|
|
|
|
return make_pair(Buffer::latexlog, string());
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
string path = OnlyPath(filename);
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
2001-08-01 10:08:53 +00:00
|
|
|
|
if (lyxrc.use_tempdir || !IsDirWriteable(path))
|
2001-02-09 15:54:30 +00:00
|
|
|
|
path = tmppath;
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
string const fname = AddName(path,
|
|
|
|
|
OnlyFilename(ChangeExtension(filename,
|
|
|
|
|
".log")));
|
|
|
|
|
string const bname =
|
|
|
|
|
AddName(path, OnlyFilename(
|
|
|
|
|
ChangeExtension(filename,
|
2001-07-30 11:56:00 +00:00
|
|
|
|
formats.extension("literate") + ".out")));
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
|
|
|
|
// If no Latex log or Build log is newer, show Build log
|
2001-02-09 15:54:30 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
FileInfo const f_fi(fname);
|
|
|
|
|
FileInfo const b_fi(bname);
|
2001-02-09 15:54:30 +00:00
|
|
|
|
|
2001-02-06 17:41:42 +00:00
|
|
|
|
if (b_fi.exist() &&
|
2001-03-14 14:54:30 +00:00
|
|
|
|
(!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
|
2003-01-06 14:02:24 +00:00
|
|
|
|
lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
|
2001-02-09 15:54:30 +00:00
|
|
|
|
return make_pair(Buffer::buildlog, bname);
|
|
|
|
|
}
|
2003-01-06 14:02:24 +00:00
|
|
|
|
lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
|
2001-02-09 15:54:30 +00:00
|
|
|
|
return make_pair(Buffer::latexlog, fname);
|
2001-02-06 17:41:42 +00:00
|
|
|
|
}
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
void Buffer::setReadonly(bool flag)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (read_only != flag) {
|
2002-03-21 16:55:34 +00:00
|
|
|
|
read_only = flag;
|
2003-07-10 12:26:40 +00:00
|
|
|
|
readonly(flag);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
AuthorList & Buffer::authors()
|
|
|
|
|
{
|
2003-03-12 02:39:12 +00:00
|
|
|
|
return params.authorlist;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-10-12 00:11:06 +00:00
|
|
|
|
void Buffer::setFileName(string const & newfile)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-01-14 23:31:23 +00:00
|
|
|
|
filename_ = MakeAbsPath(newfile);
|
|
|
|
|
filepath_ = OnlyPath(filename_);
|
|
|
|
|
setReadonly(IsFileWriteable(filename_) == 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
updateTitles();
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2001-07-09 23:12:04 +00:00
|
|
|
|
// We'll remove this later. (Lgb)
|
|
|
|
|
namespace {
|
|
|
|
|
|
2003-03-12 02:39:12 +00:00
|
|
|
|
void unknownClass(string const & unknown)
|
|
|
|
|
{
|
2003-05-21 21:20:50 +00:00
|
|
|
|
Alert::warning(_("Unknown document class"),
|
2003-05-13 09:48:57 +00:00
|
|
|
|
bformat(_("Using the default document class, because the "
|
|
|
|
|
" class %1$s is unknown."), unknown));
|
2003-03-12 02:39:12 +00:00
|
|
|
|
}
|
2001-07-09 23:12:04 +00:00
|
|
|
|
|
2001-08-30 07:13:15 +00:00
|
|
|
|
} // anon
|
|
|
|
|
|
2003-03-12 02:39:12 +00:00
|
|
|
|
int Buffer::readHeader(LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
int unknown_tokens = 0;
|
|
|
|
|
|
|
|
|
|
while (lex.isOK()) {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
|
|
|
|
|
if (token.empty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (token == "\\end_header")
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
lyxerr[Debug::PARSER] << "Handling header token: `"
|
|
|
|
|
<< token << '\'' << endl;
|
|
|
|
|
|
2003-06-22 18:08:49 +00:00
|
|
|
|
|
2003-03-12 02:39:12 +00:00
|
|
|
|
string unknown = params.readToken(lex, token);
|
|
|
|
|
if (!unknown.empty()) {
|
|
|
|
|
if (unknown[0] != '\\') {
|
|
|
|
|
unknownClass(unknown);
|
|
|
|
|
} else {
|
2003-03-29 10:29:38 +00:00
|
|
|
|
++unknown_tokens;
|
2003-06-20 23:03:43 +00:00
|
|
|
|
string const s = bformat(_("Unknown token: "
|
2003-06-28 01:23:11 +00:00
|
|
|
|
"%1$s %2$s\n"),
|
|
|
|
|
token,
|
2003-06-20 23:03:43 +00:00
|
|
|
|
lex.getString());
|
2003-07-25 17:11:25 +00:00
|
|
|
|
error(ErrorItem(_("Header error"), s,
|
2003-07-07 08:37:02 +00:00
|
|
|
|
-1, 0, 0));
|
2003-03-12 02:39:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return unknown_tokens;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-30 07:13:15 +00:00
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
// candidate for move to BufferView
|
|
|
|
|
// (at least some parts in the beginning of the func)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
//
|
|
|
|
|
// Uwe C. Schroeder
|
|
|
|
|
// changed to be public and have one parameter
|
1999-10-02 16:21:10 +00:00
|
|
|
|
// if par = 0 normal behavior
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// else insert behavior
|
2003-07-28 22:30:50 +00:00
|
|
|
|
// Returns false if "\end_document" is not read (Asger)
|
2003-03-12 05:46:35 +00:00
|
|
|
|
bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-03-21 16:55:34 +00:00
|
|
|
|
Paragraph::depth_type depth = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
bool the_end_read = false;
|
|
|
|
|
|
2003-03-12 05:46:35 +00:00
|
|
|
|
if (paragraphs.empty()) {
|
2003-06-22 18:08:49 +00:00
|
|
|
|
readHeader(lex);
|
2003-03-12 02:39:12 +00:00
|
|
|
|
if (!params.getLyXTextClass().load()) {
|
2003-03-29 09:48:03 +00:00
|
|
|
|
string theclass = params.getLyXTextClass().name();
|
2003-05-13 09:48:57 +00:00
|
|
|
|
Alert::error(_("Can't load document class"), bformat(
|
|
|
|
|
"Using the default document class, because the "
|
|
|
|
|
" class %1$s could not be loaded.", theclass));
|
2003-03-12 02:39:12 +00:00
|
|
|
|
params.textclass = 0;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
// We don't want to adopt the parameters from the
|
2003-03-12 02:39:12 +00:00
|
|
|
|
// document we insert, so read them into a temporary buffer
|
|
|
|
|
// and then discard it
|
|
|
|
|
|
|
|
|
|
Buffer tmpbuf("", false);
|
|
|
|
|
tmpbuf.readHeader(lex);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
|
while (lex.isOK()) {
|
2001-07-09 23:12:04 +00:00
|
|
|
|
lex.nextToken();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const token = lex.getString();
|
2001-07-09 23:12:04 +00:00
|
|
|
|
|
2003-03-12 02:39:12 +00:00
|
|
|
|
if (token.empty())
|
|
|
|
|
continue;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-09 23:12:04 +00:00
|
|
|
|
lyxerr[Debug::PARSER] << "Handling token: `"
|
2002-11-27 10:30:28 +00:00
|
|
|
|
<< token << '\'' << endl;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-07-28 22:30:50 +00:00
|
|
|
|
if (token == "\\end_document") {
|
2003-03-12 02:39:12 +00:00
|
|
|
|
the_end_read = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-20 23:03:43 +00:00
|
|
|
|
readParagraph(lex, token, paragraphs, pit, depth);
|
2001-11-25 17:58:05 +00:00
|
|
|
|
}
|
2001-07-16 14:11:35 +00:00
|
|
|
|
|
2000-03-01 14:13:21 +00:00
|
|
|
|
return the_end_read;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
int Buffer::readParagraph(LyXLex & lex, string const & token,
|
2003-06-20 23:03:43 +00:00
|
|
|
|
ParagraphList & pars, ParagraphList::iterator & pit,
|
|
|
|
|
Paragraph::depth_type & depth)
|
2000-03-01 14:13:21 +00:00
|
|
|
|
{
|
2003-03-12 02:59:56 +00:00
|
|
|
|
static Change current_change;
|
2003-03-12 02:39:12 +00:00
|
|
|
|
int unknown = 0;
|
2002-05-29 14:32:11 +00:00
|
|
|
|
|
2003-07-28 15:17:11 +00:00
|
|
|
|
if (token == "\\begin_layout") {
|
2003-03-12 11:52:23 +00:00
|
|
|
|
lex.pushToken(token);
|
2002-03-06 14:24:34 +00:00
|
|
|
|
|
2003-05-24 12:13:30 +00:00
|
|
|
|
Paragraph par;
|
|
|
|
|
par.params().depth(depth);
|
2003-03-12 11:52:23 +00:00
|
|
|
|
if (params.tracking_changes)
|
2003-05-24 12:13:30 +00:00
|
|
|
|
par.trackChanges();
|
2003-03-12 11:52:23 +00:00
|
|
|
|
LyXFont f(LyXFont::ALL_INHERIT, params.language);
|
2003-05-24 12:13:30 +00:00
|
|
|
|
par.setFont(0, f);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-03-12 11:52:23 +00:00
|
|
|
|
// insert after
|
|
|
|
|
if (pit != pars.end())
|
|
|
|
|
++pit;
|
2003-06-20 23:03:43 +00:00
|
|
|
|
|
2003-03-12 11:52:23 +00:00
|
|
|
|
pit = pars.insert(pit, par);
|
2003-06-20 23:03:43 +00:00
|
|
|
|
|
|
|
|
|
// FIXME: goddamn InsetTabular makes us pass a Buffer
|
|
|
|
|
// not BufferParams
|
|
|
|
|
::readParagraph(*this, *pit, lex);
|
|
|
|
|
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\begin_deeper") {
|
|
|
|
|
++depth;
|
|
|
|
|
} else if (token == "\\end_deeper") {
|
|
|
|
|
if (!depth) {
|
2003-03-12 11:52:23 +00:00
|
|
|
|
lex.printError("\\end_deeper: " "depth is already null");
|
|
|
|
|
} else {
|
2000-03-01 14:13:21 +00:00
|
|
|
|
--depth;
|
2003-03-12 11:52:23 +00:00
|
|
|
|
}
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else {
|
2003-03-12 02:39:12 +00:00
|
|
|
|
++unknown;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-03-12 02:39:12 +00:00
|
|
|
|
return unknown;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-24 15:20:31 +00:00
|
|
|
|
|
2001-07-23 09:11:14 +00:00
|
|
|
|
// needed to insert the selection
|
2003-04-16 08:12:22 +00:00
|
|
|
|
void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
|
2003-03-04 21:40:36 +00:00
|
|
|
|
LyXFont const & fn,string const & str)
|
2001-07-23 09:11:14 +00:00
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & layout = par->layout();
|
|
|
|
|
|
2001-10-22 09:45:31 +00:00
|
|
|
|
LyXFont font = fn;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
par->checkInsertChar(font);
|
2001-07-23 09:11:14 +00:00
|
|
|
|
// insert the string, don't insert doublespace
|
|
|
|
|
bool space_inserted = true;
|
2002-04-12 15:59:03 +00:00
|
|
|
|
bool autobreakrows = !par->inInset() ||
|
|
|
|
|
static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
for(string::const_iterator cit = str.begin();
|
2001-07-23 09:11:14 +00:00
|
|
|
|
cit != str.end(); ++cit) {
|
|
|
|
|
if (*cit == '\n') {
|
2003-06-07 17:45:43 +00:00
|
|
|
|
if (autobreakrows && (!par->empty() || par->allowEmpty())) {
|
2003-03-06 10:02:40 +00:00
|
|
|
|
breakParagraph(params, paragraphs, par, pos,
|
2002-08-20 19:41:13 +00:00
|
|
|
|
layout->isEnvironment());
|
2003-04-16 08:12:22 +00:00
|
|
|
|
++par;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
pos = 0;
|
|
|
|
|
space_inserted = true;
|
|
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// do not insert consecutive spaces if !free_spacing
|
2001-10-22 09:45:31 +00:00
|
|
|
|
} else if ((*cit == ' ' || *cit == '\t') &&
|
2003-06-07 17:45:43 +00:00
|
|
|
|
space_inserted && !par->isFreeSpacing()) {
|
2001-07-23 09:11:14 +00:00
|
|
|
|
continue;
|
|
|
|
|
} else if (*cit == '\t') {
|
2003-06-07 17:45:43 +00:00
|
|
|
|
if (!par->isFreeSpacing()) {
|
2001-07-23 09:11:14 +00:00
|
|
|
|
// tabs are like spaces here
|
2003-03-12 02:55:22 +00:00
|
|
|
|
par->insertChar(pos, ' ', font);
|
2001-07-23 09:11:14 +00:00
|
|
|
|
++pos;
|
|
|
|
|
space_inserted = true;
|
|
|
|
|
} else {
|
2001-11-27 10:34:16 +00:00
|
|
|
|
const pos_type nb = 8 - pos % 8;
|
|
|
|
|
for (pos_type a = 0; a < nb ; ++a) {
|
2003-03-12 02:55:22 +00:00
|
|
|
|
par->insertChar(pos, ' ', font);
|
2001-07-23 09:11:14 +00:00
|
|
|
|
++pos;
|
|
|
|
|
}
|
|
|
|
|
space_inserted = true;
|
|
|
|
|
}
|
|
|
|
|
} else if (!IsPrintable(*cit)) {
|
|
|
|
|
// Ignore unprintables
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
// just insert the character
|
|
|
|
|
par->insertChar(pos, *cit, font);
|
|
|
|
|
++pos;
|
|
|
|
|
space_inserted = (*cit == ' ');
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
}
|
2001-07-23 09:11:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
bool Buffer::readFile(string const & filename)
|
2003-03-12 05:46:35 +00:00
|
|
|
|
{
|
2003-07-28 14:40:29 +00:00
|
|
|
|
// Check if the file is compressed.
|
|
|
|
|
string const format = getExtFromContents(filename);
|
|
|
|
|
if (format == "gzip" || format == "zip" || format == "compress") {
|
|
|
|
|
params.compressed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LyXLex lex(0, 0);
|
|
|
|
|
lex.setFile(filename);
|
|
|
|
|
|
2003-04-24 23:19:41 +00:00
|
|
|
|
bool ret = readFile(lex, filename, paragraphs.begin());
|
|
|
|
|
|
|
|
|
|
// After we have read a file, we must ensure that the buffer
|
|
|
|
|
// language is set and used in the gui.
|
|
|
|
|
// If you know of a better place to put this, please tell me. (Lgb)
|
2003-04-25 01:54:04 +00:00
|
|
|
|
updateDocLang(params.language);
|
2003-04-28 21:58:53 +00:00
|
|
|
|
|
2003-04-24 23:19:41 +00:00
|
|
|
|
return ret;
|
2003-03-12 05:46:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-29 09:48:03 +00:00
|
|
|
|
// FIXME: all the below Alerts should give the filename..
|
2003-04-24 23:19:41 +00:00
|
|
|
|
bool Buffer::readFile(LyXLex & lex, string const & filename,
|
|
|
|
|
ParagraphList::iterator pit)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-03-29 11:34:53 +00:00
|
|
|
|
if (!lex.isOK()) {
|
|
|
|
|
Alert::error(_("Document could not be read"),
|
|
|
|
|
_("The specified document could not be read."));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lex.next();
|
|
|
|
|
string const token(lex.getString());
|
|
|
|
|
|
|
|
|
|
if (!lex.isOK()) {
|
|
|
|
|
Alert::error(_("Document could not be read"),
|
|
|
|
|
_("The specified document could not be read."));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2002-05-22 12:33:02 +00:00
|
|
|
|
|
2003-03-29 11:34:53 +00:00
|
|
|
|
// the first token _must_ be...
|
|
|
|
|
if (token != "\\lyxformat") {
|
|
|
|
|
Alert::error(_("Document format failure"),
|
|
|
|
|
_("The specified document is not a LyX document."));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lex.eatLine();
|
|
|
|
|
string tmp_format = lex.getString();
|
|
|
|
|
//lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
|
|
|
|
|
// if present remove ".," from string.
|
|
|
|
|
string::size_type dot = tmp_format.find_first_of(".,");
|
|
|
|
|
//lyxerr << " dot found at " << dot << endl;
|
|
|
|
|
if (dot != string::npos)
|
|
|
|
|
tmp_format.erase(dot, 1);
|
|
|
|
|
file_format = strToInt(tmp_format);
|
|
|
|
|
//lyxerr << "format: " << file_format << endl;
|
|
|
|
|
if (file_format == LYX_FORMAT) {
|
|
|
|
|
// current format
|
|
|
|
|
} else if (file_format > LYX_FORMAT) {
|
|
|
|
|
Alert::warning(_("Document format failure"),
|
|
|
|
|
_("This document was created with a newer version of "
|
|
|
|
|
"LyX. This is likely to cause problems."));
|
|
|
|
|
} else if (file_format < LYX_FORMAT) {
|
|
|
|
|
// old formats
|
|
|
|
|
if (file_format < 200) {
|
|
|
|
|
Alert::error(_("Document format failure"),
|
|
|
|
|
_("This LyX document is too old to be read "
|
|
|
|
|
"by this version of LyX. Try LyX 0.10."));
|
|
|
|
|
return false;
|
|
|
|
|
} else if (!filename.empty()) {
|
|
|
|
|
string command =
|
|
|
|
|
LibFileSearch("lyx2lyx", "lyx2lyx");
|
|
|
|
|
if (command.empty()) {
|
|
|
|
|
Alert::error(_("Conversion script not found"),
|
|
|
|
|
_("The document is from an earlier version "
|
|
|
|
|
"of LyX, but the conversion script lyx2lyx "
|
|
|
|
|
"could not be found."));
|
|
|
|
|
return false;
|
2001-11-26 10:19:58 +00:00
|
|
|
|
}
|
2003-03-29 11:34:53 +00:00
|
|
|
|
command += " -t"
|
|
|
|
|
+tostr(LYX_FORMAT) + ' '
|
|
|
|
|
+ QuoteName(filename);
|
|
|
|
|
lyxerr[Debug::INFO] << "Running '"
|
|
|
|
|
<< command << '\''
|
|
|
|
|
<< endl;
|
|
|
|
|
cmd_ret const ret = RunCommand(command);
|
|
|
|
|
if (ret.first) {
|
|
|
|
|
Alert::error(_("Conversion script failed"),
|
|
|
|
|
_("The document is from an earlier version "
|
|
|
|
|
"of LyX, but the lyx2lyx script failed "
|
|
|
|
|
"to convert it."));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
istringstream is(STRCONV(ret.second));
|
|
|
|
|
LyXLex tmplex(0, 0);
|
|
|
|
|
tmplex.setStream(is);
|
|
|
|
|
return readFile(tmplex, string(), pit);
|
2003-03-29 09:48:03 +00:00
|
|
|
|
} else {
|
2003-03-29 11:34:53 +00:00
|
|
|
|
// This code is reached if lyx2lyx failed (for
|
|
|
|
|
// some reason) to change the file format of
|
|
|
|
|
// the file.
|
2003-06-30 23:56:22 +00:00
|
|
|
|
Assert(false);
|
2003-03-29 11:34:53 +00:00
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-03-29 09:48:03 +00:00
|
|
|
|
}
|
2003-03-29 11:34:53 +00:00
|
|
|
|
bool the_end = readBody(lex, pit);
|
|
|
|
|
params.setPaperStuff();
|
|
|
|
|
|
|
|
|
|
if (!the_end) {
|
|
|
|
|
Alert::error(_("Document format failure"),
|
|
|
|
|
_("The document ended unexpectedly, which means "
|
|
|
|
|
"that it is probably corrupted."));
|
|
|
|
|
}
|
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Should probably be moved to somewhere else: BufferView? LyXView?
|
2000-03-20 14:49:54 +00:00
|
|
|
|
bool Buffer::save() const
|
2000-02-22 00:36:17 +00:00
|
|
|
|
{
|
|
|
|
|
// We don't need autosaves in the immediate future. (Asger)
|
|
|
|
|
resetAutosaveTimers();
|
|
|
|
|
|
|
|
|
|
// make a backup
|
2000-03-20 14:49:54 +00:00
|
|
|
|
string s;
|
|
|
|
|
if (lyxrc.make_backup) {
|
|
|
|
|
s = fileName() + '~';
|
|
|
|
|
if (!lyxrc.backupdir_path.empty())
|
|
|
|
|
s = AddName(lyxrc.backupdir_path,
|
2001-05-17 15:11:01 +00:00
|
|
|
|
subst(os::slashify_path(s),'/','!'));
|
2000-03-20 14:49:54 +00:00
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Rename is the wrong way of making a backup,
|
|
|
|
|
// this is the correct way.
|
|
|
|
|
/* truss cp fil fil2:
|
|
|
|
|
lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
|
|
|
|
|
stat("LyXVC.lyx", 0xEFFFF688) = 0
|
|
|
|
|
open("LyXVC.lyx", O_RDONLY) = 3
|
|
|
|
|
open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
|
|
|
|
|
fstat(4, 0xEFFFF508) = 0
|
|
|
|
|
fstat(3, 0xEFFFF508) = 0
|
|
|
|
|
read(3, " # T h i s f i l e w".., 8192) = 5579
|
|
|
|
|
write(4, " # T h i s f i l e w".., 5579) = 5579
|
|
|
|
|
read(3, 0xEFFFD4A0, 8192) = 0
|
|
|
|
|
close(4) = 0
|
|
|
|
|
close(3) = 0
|
|
|
|
|
chmod("LyXVC3.lyx", 0100644) = 0
|
|
|
|
|
lseek(0, 0, SEEK_CUR) = 46440
|
|
|
|
|
_exit(0)
|
|
|
|
|
*/
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// Should probably have some more error checking here.
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Doing it this way, also makes the inodes stay the same.
|
|
|
|
|
// This is still not a very good solution, in particular we
|
|
|
|
|
// might loose the owner of the backup.
|
|
|
|
|
FileInfo finfo(fileName());
|
|
|
|
|
if (finfo.exist()) {
|
|
|
|
|
mode_t fmode = finfo.getMode();
|
2000-03-28 02:18:55 +00:00
|
|
|
|
struct utimbuf times = {
|
|
|
|
|
finfo.getAccessTime(),
|
|
|
|
|
finfo.getModificationTime() };
|
2000-02-22 00:36:17 +00:00
|
|
|
|
|
|
|
|
|
ifstream ifs(fileName().c_str());
|
|
|
|
|
ofstream ofs(s.c_str(), ios::out|ios::trunc);
|
|
|
|
|
if (ifs && ofs) {
|
|
|
|
|
ofs << ifs.rdbuf();
|
|
|
|
|
ifs.close();
|
|
|
|
|
ofs.close();
|
|
|
|
|
::chmod(s.c_str(), fmode);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
if (::utime(s.c_str(), ×)) {
|
2000-02-22 00:36:17 +00:00
|
|
|
|
lyxerr << "utime error." << endl;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "LyX was not able to make "
|
2001-06-25 00:06:33 +00:00
|
|
|
|
"backup copy. Beware." << endl;
|
2000-02-22 00:36:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-08-01 22:26:30 +00:00
|
|
|
|
if (writeFile(fileName())) {
|
2002-08-04 23:11:50 +00:00
|
|
|
|
markClean();
|
2000-08-08 15:36:25 +00:00
|
|
|
|
removeAutosaveFile(fileName());
|
2000-02-22 00:36:17 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Saving failed, so backup is not backup
|
2000-03-20 14:49:54 +00:00
|
|
|
|
if (lyxrc.make_backup) {
|
2003-06-30 23:56:22 +00:00
|
|
|
|
rename(s, fileName());
|
2000-02-22 00:36:17 +00:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-01 22:26:30 +00:00
|
|
|
|
bool Buffer::writeFile(string const & fname) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-01-14 23:31:23 +00:00
|
|
|
|
if (read_only && (fname == fileName())) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
FileInfo finfo(fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (finfo.exist() && !finfo.writable()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
bool retval;
|
2003-07-27 23:40:08 +00:00
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
if (params.compressed) {
|
2003-07-27 23:40:08 +00:00
|
|
|
|
gz::ogzstream ofs(fname.c_str());
|
|
|
|
|
|
|
|
|
|
if (!ofs)
|
|
|
|
|
return false;
|
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
retval = do_writeFile(ofs);
|
2003-07-27 23:40:08 +00:00
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
} else {
|
|
|
|
|
ofstream ofs(fname.c_str());
|
|
|
|
|
if (!ofs)
|
|
|
|
|
return false;
|
2003-07-27 23:40:08 +00:00
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
retval = do_writeFile(ofs);
|
|
|
|
|
}
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
return retval;
|
2003-07-27 23:40:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::do_writeFile(ostream & ofs) const
|
|
|
|
|
{
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
#ifdef HAVE_LOCALE
|
|
|
|
|
// Use the standard "C" locale for file output.
|
2000-09-15 10:24:15 +00:00
|
|
|
|
ofs.imbue(std::locale::classic());
|
2000-09-14 17:53:12 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// The top of the file should not be written by params.
|
|
|
|
|
|
|
|
|
|
// write out a comment in the top of the file
|
2003-07-28 14:09:05 +00:00
|
|
|
|
ofs << "#LyX " << lyx_version
|
2001-02-14 19:22:41 +00:00
|
|
|
|
<< " created this file. For more info see http://www.lyx.org/\n"
|
|
|
|
|
<< "\\lyxformat " << LYX_FORMAT << "\n";
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
// now write out the buffer paramters.
|
|
|
|
|
params.writeFile(ofs);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-03-12 02:39:12 +00:00
|
|
|
|
ofs << "\\end_header\n";
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// this will write out all the paragraphs
|
|
|
|
|
// using recursive descent.
|
2003-05-27 22:41:04 +00:00
|
|
|
|
ParagraphList::const_iterator pit = paragraphs.begin();
|
|
|
|
|
ParagraphList::const_iterator pend = paragraphs.end();
|
2002-08-20 17:29:37 +00:00
|
|
|
|
for (; pit != pend; ++pit)
|
|
|
|
|
pit->write(this, ofs, params, depth);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Write marker that shows file is complete
|
2003-07-28 22:30:50 +00:00
|
|
|
|
ofs << "\n\\end_document" << endl;
|
2000-10-13 12:20:38 +00:00
|
|
|
|
|
2003-07-27 23:40:08 +00:00
|
|
|
|
// Shouldn't really be needed....
|
|
|
|
|
//ofs.close();
|
2000-10-13 12:20:38 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
// how to check if close went ok?
|
2000-10-13 12:20:38 +00:00
|
|
|
|
// Following is an attempt... (BE 20001011)
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-10-13 12:20:38 +00:00
|
|
|
|
// good() returns false if any error occured, including some
|
|
|
|
|
// formatting error.
|
|
|
|
|
// bad() returns true if something bad happened in the buffer,
|
|
|
|
|
// which should include file system full errors.
|
|
|
|
|
|
|
|
|
|
bool status = true;
|
|
|
|
|
if (!ofs.good()) {
|
|
|
|
|
status = false;
|
|
|
|
|
#if 0
|
|
|
|
|
if (ofs.bad()) {
|
|
|
|
|
lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-10-13 12:20:38 +00:00
|
|
|
|
return status;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-07 18:59:07 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
pair<int, string> const addDepth(int depth, int ldepth)
|
|
|
|
|
{
|
|
|
|
|
int d = depth * 2;
|
|
|
|
|
if (ldepth > depth)
|
|
|
|
|
d += (ldepth - depth) * 2;
|
|
|
|
|
return make_pair(d, string(d, ' '));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
string const Buffer::asciiParagraph(Paragraph const & par,
|
2002-03-21 16:55:34 +00:00
|
|
|
|
unsigned int linelen,
|
|
|
|
|
bool noparbreak) const
|
2000-09-26 15:25:14 +00:00
|
|
|
|
{
|
|
|
|
|
ostringstream buffer;
|
|
|
|
|
int ltype = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type ltype_depth = 0;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
bool ref_printed = false;
|
2003-06-10 14:39:45 +00:00
|
|
|
|
Paragraph::depth_type depth = par.params().depth();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
// First write the layout
|
2002-08-20 17:18:21 +00:00
|
|
|
|
string const & tmp = par.layout()->name();
|
2002-03-03 20:25:07 +00:00
|
|
|
|
if (compare_no_case(tmp, "itemize") == 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 1;
|
|
|
|
|
ltype_depth = depth + 1;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 2;
|
|
|
|
|
ltype_depth = depth + 1;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (contains(ascii_lowercase(tmp), "ection")) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 3;
|
|
|
|
|
ltype_depth = depth + 1;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (contains(ascii_lowercase(tmp), "aragraph")) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 4;
|
|
|
|
|
ltype_depth = depth + 1;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (compare_ascii_no_case(tmp, "description") == 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 5;
|
|
|
|
|
ltype_depth = depth + 1;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (compare_ascii_no_case(tmp, "abstract") == 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 6;
|
|
|
|
|
ltype_depth = 0;
|
2002-07-16 21:17:10 +00:00
|
|
|
|
} else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ltype = 7;
|
|
|
|
|
ltype_depth = 0;
|
|
|
|
|
} else {
|
|
|
|
|
ltype = 0;
|
|
|
|
|
ltype_depth = 0;
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
|
|
|
|
/* maybe some vertical spaces */
|
|
|
|
|
|
|
|
|
|
/* the labelwidthstring used in lists */
|
|
|
|
|
|
|
|
|
|
/* some lines? */
|
|
|
|
|
|
|
|
|
|
/* some pagebreaks? */
|
|
|
|
|
|
|
|
|
|
/* noindent ? */
|
|
|
|
|
|
|
|
|
|
/* what about the alignment */
|
2001-12-27 12:00:03 +00:00
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
// linelen <= 0 is special and means we don't have paragraph breaks
|
2002-03-07 18:59:07 +00:00
|
|
|
|
|
|
|
|
|
string::size_type currlinelen = 0;
|
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
if (!noparbreak) {
|
|
|
|
|
if (linelen > 0)
|
|
|
|
|
buffer << "\n\n";
|
2002-03-07 18:59:07 +00:00
|
|
|
|
|
|
|
|
|
buffer << string(depth * 2, ' ');
|
|
|
|
|
currlinelen += depth * 2;
|
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
//--
|
|
|
|
|
// we should probably change to the paragraph language in the
|
|
|
|
|
// gettext here (if possible) so that strings are outputted in
|
|
|
|
|
// the correct language! (20012712 Jug)
|
2002-03-21 16:55:34 +00:00
|
|
|
|
//--
|
2001-12-27 12:00:03 +00:00
|
|
|
|
switch (ltype) {
|
|
|
|
|
case 0: // Standard
|
|
|
|
|
case 4: // (Sub)Paragraph
|
|
|
|
|
case 5: // Description
|
|
|
|
|
break;
|
|
|
|
|
case 6: // Abstract
|
2002-03-07 18:59:07 +00:00
|
|
|
|
if (linelen > 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
buffer << _("Abstract") << "\n\n";
|
2002-03-07 18:59:07 +00:00
|
|
|
|
currlinelen = 0;
|
|
|
|
|
} else {
|
|
|
|
|
string const abst = _("Abstract: ");
|
2002-03-21 16:55:34 +00:00
|
|
|
|
buffer << abst;
|
2002-03-07 18:59:07 +00:00
|
|
|
|
currlinelen += abst.length();
|
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
break;
|
|
|
|
|
case 7: // Bibliography
|
|
|
|
|
if (!ref_printed) {
|
2002-03-07 18:59:07 +00:00
|
|
|
|
if (linelen > 0) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
buffer << _("References") << "\n\n";
|
2002-03-07 18:59:07 +00:00
|
|
|
|
currlinelen = 0;
|
|
|
|
|
} else {
|
|
|
|
|
string const refs = _("References: ");
|
|
|
|
|
buffer << refs;
|
|
|
|
|
currlinelen += refs.length();
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
ref_printed = true;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-03-07 18:59:07 +00:00
|
|
|
|
{
|
2002-08-20 17:18:21 +00:00
|
|
|
|
string const parlab = par.params().labelString();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
buffer << parlab << ' ';
|
2002-03-07 18:59:07 +00:00
|
|
|
|
currlinelen += parlab.length() + 1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-07 18:59:07 +00:00
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
if (!currlinelen) {
|
2002-03-07 18:59:07 +00:00
|
|
|
|
pair<int, string> p = addDepth(depth, ltype_depth);
|
|
|
|
|
buffer << p.second;
|
|
|
|
|
currlinelen += p.first;
|
2001-12-27 12:00:03 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-03-07 18:59:07 +00:00
|
|
|
|
// this is to change the linebreak to do it by word a bit more
|
|
|
|
|
// intelligent hopefully! (only in the case where we have a
|
2003-02-18 13:25:18 +00:00
|
|
|
|
// max linelength!) (Jug)
|
2002-03-07 18:59:07 +00:00
|
|
|
|
|
|
|
|
|
string word;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
for (pos_type i = 0; i < par.size(); ++i) {
|
|
|
|
|
char c = par.getUChar(params, i);
|
2000-09-26 15:25:14 +00:00
|
|
|
|
switch (c) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
case Paragraph::META_INSET:
|
2001-05-16 07:53:23 +00:00
|
|
|
|
{
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld const * inset = par.getInset(i);
|
2001-05-16 07:53:23 +00:00
|
|
|
|
if (inset) {
|
2002-01-10 10:38:49 +00:00
|
|
|
|
if (linelen > 0) {
|
2002-03-07 18:59:07 +00:00
|
|
|
|
buffer << word;
|
|
|
|
|
currlinelen += word.length();
|
|
|
|
|
word.erase();
|
2002-01-10 10:38:49 +00:00
|
|
|
|
}
|
2001-12-27 15:54:25 +00:00
|
|
|
|
if (inset->ascii(this, buffer, linelen)) {
|
2001-12-27 12:00:03 +00:00
|
|
|
|
// to be sure it breaks paragraph
|
|
|
|
|
currlinelen += linelen;
|
|
|
|
|
}
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-05-16 07:53:23 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-09-26 15:25:14 +00:00
|
|
|
|
default:
|
2001-12-27 12:00:03 +00:00
|
|
|
|
if (c == ' ') {
|
2002-03-07 18:59:07 +00:00
|
|
|
|
if (linelen > 0 &&
|
|
|
|
|
currlinelen + word.length() > linelen - 10) {
|
|
|
|
|
buffer << "\n";
|
2003-03-11 15:01:29 +00:00
|
|
|
|
pair<int, string> p = addDepth(depth, ltype_depth);
|
2002-03-07 18:59:07 +00:00
|
|
|
|
buffer << p.second;
|
|
|
|
|
currlinelen = p.first;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffer << word << ' ';
|
|
|
|
|
currlinelen += word.length() + 1;
|
|
|
|
|
word.erase();
|
|
|
|
|
|
2001-12-27 12:00:03 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (c != '\0') {
|
2002-03-14 09:59:02 +00:00
|
|
|
|
word += c;
|
2001-12-27 12:00:03 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::INFO] <<
|
|
|
|
|
"writeAsciiFile: NULL char in structure." << endl;
|
|
|
|
|
}
|
|
|
|
|
if ((linelen > 0) &&
|
2002-03-07 18:59:07 +00:00
|
|
|
|
(currlinelen + word.length()) > linelen)
|
2001-12-27 12:00:03 +00:00
|
|
|
|
{
|
|
|
|
|
buffer << "\n";
|
2002-03-07 18:59:07 +00:00
|
|
|
|
|
|
|
|
|
pair<int, string> p =
|
|
|
|
|
addDepth(depth, ltype_depth);
|
|
|
|
|
buffer << p.second;
|
|
|
|
|
currlinelen = p.first;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2001-12-27 12:00:03 +00:00
|
|
|
|
}
|
2000-09-26 15:25:14 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-07 18:59:07 +00:00
|
|
|
|
buffer << word;
|
2002-11-04 02:12:42 +00:00
|
|
|
|
return STRCONV(buffer.str());
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
void Buffer::writeFileAscii(string const & fname, int linelen)
|
2000-09-26 15:25:14 +00:00
|
|
|
|
{
|
2003-07-26 20:09:56 +00:00
|
|
|
|
ofstream ofs;
|
|
|
|
|
if (!::openFileWrite(ofs, fname))
|
2000-09-26 15:25:14 +00:00
|
|
|
|
return;
|
|
|
|
|
writeFileAscii(ofs, linelen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
void Buffer::writeFileAscii(ostream & os, int linelen)
|
2000-09-26 15:25:14 +00:00
|
|
|
|
{
|
2002-08-14 22:15:18 +00:00
|
|
|
|
ParagraphList::iterator beg = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator end = paragraphs.end();
|
|
|
|
|
ParagraphList::iterator it = beg;
|
|
|
|
|
for (; it != end; ++it) {
|
2002-08-20 17:18:21 +00:00
|
|
|
|
os << asciiParagraph(*it, linelen, it == beg);
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2002-08-20 17:18:21 +00:00
|
|
|
|
os << "\n";
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
2000-11-15 03:22:08 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
void Buffer::makeLaTeXFile(string const & fname,
|
2000-03-06 02:42:40 +00:00
|
|
|
|
string const & original_path,
|
2003-05-22 18:59:10 +00:00
|
|
|
|
LatexRunParams const & runparams,
|
2003-07-26 21:37:10 +00:00
|
|
|
|
bool output_preamble, bool output_body)
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-07-26 20:09:56 +00:00
|
|
|
|
ofstream ofs;
|
|
|
|
|
if (!::openFileWrite(ofs, fname))
|
2000-03-06 02:42:40 +00:00
|
|
|
|
return;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-05-22 18:59:10 +00:00
|
|
|
|
makeLaTeXFile(ofs, original_path,
|
2003-07-26 21:37:10 +00:00
|
|
|
|
runparams, output_preamble, output_body);
|
2002-07-05 19:21:29 +00:00
|
|
|
|
|
|
|
|
|
ofs.close();
|
|
|
|
|
if (ofs.fail()) {
|
|
|
|
|
lyxerr << "File was not closed properly." << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::makeLaTeXFile(ostream & os,
|
|
|
|
|
string const & original_path,
|
2003-05-22 21:10:22 +00:00
|
|
|
|
LatexRunParams const & runparams_in,
|
2003-07-26 21:37:10 +00:00
|
|
|
|
bool output_preamble, bool output_body)
|
2002-07-05 19:21:29 +00:00
|
|
|
|
{
|
2003-05-22 21:10:22 +00:00
|
|
|
|
LatexRunParams runparams = runparams_in;
|
|
|
|
|
niceFile = runparams.nice; // this will be used by Insetincludes.
|
2002-03-07 16:03:36 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// validate the buffer.
|
|
|
|
|
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
|
2002-03-02 19:09:56 +00:00
|
|
|
|
LaTeXFeatures features(params);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
validate(features);
|
|
|
|
|
lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.reset();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
// The starting paragraph of the coming rows is the
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// first paragraph of the document. (Asger)
|
2003-05-07 21:27:29 +00:00
|
|
|
|
texrow.start(paragraphs.begin()->id(), 0);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2003-07-26 21:37:10 +00:00
|
|
|
|
if (output_preamble && runparams.nice) {
|
2003-07-28 14:09:05 +00:00
|
|
|
|
os << "%% LyX " << lyx_version << " created this file. "
|
2000-03-06 02:42:40 +00:00
|
|
|
|
"For more info, see http://www.lyx.org/.\n"
|
|
|
|
|
"%% Do not edit unless you really know what "
|
|
|
|
|
"you are doing.\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "lyx header finished" << endl;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// There are a few differences between nice LaTeX and usual files:
|
2002-03-21 16:55:34 +00:00
|
|
|
|
// usual is \batchmode and has a
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// special input@path to allow the including of figures
|
|
|
|
|
// with either \input or \includegraphics (what figinsets do).
|
2002-08-09 00:42:12 +00:00
|
|
|
|
// input@path is set when the actual parameter
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// original_path is set. This is done for usual tex-file, but not
|
|
|
|
|
// for nice-latex-file. (Matthias 250696)
|
2003-07-26 21:37:10 +00:00
|
|
|
|
if (output_preamble) {
|
2003-05-22 21:10:22 +00:00
|
|
|
|
if (!runparams.nice) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// code for usual, NOT nice-latex-file
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\batchmode\n"; // changed
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// from \nonstopmode
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
if (!original_path.empty()) {
|
2002-03-07 16:03:36 +00:00
|
|
|
|
string inputpath = os::external_path(original_path);
|
|
|
|
|
subst(inputpath, "~", "\\string~");
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\makeatletter\n"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "\\def\\input@path{{"
|
2002-03-07 16:03:36 +00:00
|
|
|
|
<< inputpath << "/}}\n"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "\\makeatother\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
texrow.newline();
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-02-16 00:54:43 +00:00
|
|
|
|
// Write the preamble
|
2003-05-22 22:44:30 +00:00
|
|
|
|
runparams.use_babel = params.writeLaTeX(os, features, texrow);
|
2002-07-05 19:21:29 +00:00
|
|
|
|
|
2003-07-26 21:37:10 +00:00
|
|
|
|
if (!output_body)
|
2002-07-05 19:21:29 +00:00
|
|
|
|
return;
|
2002-05-10 12:58:07 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// make the body.
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\begin{document}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
2003-07-26 21:37:10 +00:00
|
|
|
|
} // output_preamble
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
|
2001-03-01 15:57:10 +00:00
|
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
|
if (!lyxrc.language_auto_begin) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << subst(lyxrc.language_command_begin, "$$lang",
|
2000-10-10 12:36:36 +00:00
|
|
|
|
params.language->babel())
|
2000-03-17 10:14:46 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-05-23 08:59:47 +00:00
|
|
|
|
latexParagraphs(this, paragraphs, os, texrow, runparams);
|
2000-05-04 08:14:34 +00:00
|
|
|
|
|
|
|
|
|
// add this just in case after all the paragraphs
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << endl;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
|
2001-03-01 15:57:10 +00:00
|
|
|
|
if (!lyxrc.language_auto_end) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << subst(lyxrc.language_command_end, "$$lang",
|
2000-10-10 12:36:36 +00:00
|
|
|
|
params.language->babel())
|
2000-05-04 08:14:34 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-26 21:37:10 +00:00
|
|
|
|
if (output_preamble) {
|
2002-07-05 19:21:29 +00:00
|
|
|
|
os << "\\end{document}\n";
|
2000-05-04 08:14:34 +00:00
|
|
|
|
texrow.newline();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
|
lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Just to be sure. (Asger)
|
|
|
|
|
texrow.newline();
|
|
|
|
|
|
2003-01-06 14:02:24 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
|
|
|
|
|
<< '.' << endl;
|
2002-03-07 16:03:36 +00:00
|
|
|
|
|
|
|
|
|
// we want this to be true outside previews (for insetexternal)
|
|
|
|
|
niceFile = true;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLatex() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
return params.getLyXTextClass().outputType() == LATEX;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLinuxDoc() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
return params.getLyXTextClass().outputType() == LINUXDOC;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLiterate() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
return params.getLyXTextClass().outputType() == LITERATE;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isDocBook() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
return params.getLyXTextClass().outputType() == DOCBOOK;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isSGML() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
return tclass.outputType() == LINUXDOC ||
|
|
|
|
|
tclass.outputType() == DOCBOOK;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-07-26 20:09:56 +00:00
|
|
|
|
ofstream ofs;
|
|
|
|
|
if (!::openFileWrite(ofs, fname))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
niceFile = nice; // this will be used by included files.
|
|
|
|
|
|
2002-03-02 19:09:56 +00:00
|
|
|
|
LaTeXFeatures features(params);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
validate(features);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
texrow.reset();
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2002-03-02 19:09:56 +00:00
|
|
|
|
|
|
|
|
|
string top_element = tclass.latexname();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
if (!body_only) {
|
2001-10-23 09:42:14 +00:00
|
|
|
|
ofs << "<!doctype linuxdoc system";
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-10-23 09:42:14 +00:00
|
|
|
|
string preamble = params.preamble;
|
2003-06-28 01:23:11 +00:00
|
|
|
|
string const name = nice ? ChangeExtension(filename_, ".sgml")
|
2002-03-05 13:38:40 +00:00
|
|
|
|
: fname;
|
|
|
|
|
preamble += features.getIncludedFiles(name);
|
2001-10-23 09:42:14 +00:00
|
|
|
|
preamble += features.getLyXSGMLEntities();
|
|
|
|
|
|
|
|
|
|
if (!preamble.empty()) {
|
|
|
|
|
ofs << " [ " << preamble << " ]";
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
2001-10-23 09:42:14 +00:00
|
|
|
|
ofs << ">\n\n";
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (params.options.empty())
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, 0, false, top_element);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
else {
|
|
|
|
|
string top = top_element;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
top += ' ';
|
2000-07-01 12:54:45 +00:00
|
|
|
|
top += params.options;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, 0, false, top);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-28 14:09:05 +00:00
|
|
|
|
ofs << "<!-- LyX " << lyx_version
|
2000-01-19 14:07:39 +00:00
|
|
|
|
<< " created this file. For more info see http://www.lyx.org/"
|
|
|
|
|
<< " -->\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth = 0; // paragraph depth
|
2002-03-21 16:55:34 +00:00
|
|
|
|
string item_name;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
vector<string> environment_stack(5);
|
|
|
|
|
|
2003-04-02 21:19:35 +00:00
|
|
|
|
ParagraphList::iterator pit = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator pend = paragraphs.end();
|
|
|
|
|
for (; pit != pend; ++pit) {
|
|
|
|
|
LyXLayout_ptr const & style = pit->layout();
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// treat <toc> as a special case for compatibility with old code
|
2003-04-02 21:19:35 +00:00
|
|
|
|
if (pit->isInset(0)) {
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * inset = pit->getInset(0);
|
|
|
|
|
InsetOld::Code lyx_code = inset->lyxCode();
|
|
|
|
|
if (lyx_code == InsetOld::TOC_CODE) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const temp = "toc";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, temp);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// environment tag closing
|
2003-04-02 21:19:35 +00:00
|
|
|
|
for (; depth > pit->params().depth(); --depth) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false, environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// write opening SGML tags
|
2002-06-24 20:28:12 +00:00
|
|
|
|
switch (style->latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_PARAGRAPH:
|
2003-04-02 21:19:35 +00:00
|
|
|
|
if (depth == pit->params().depth()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
&& !environment_stack[depth].empty()) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false, environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
if (depth)
|
1999-12-07 00:44:53 +00:00
|
|
|
|
--depth;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2002-03-21 16:55:34 +00:00
|
|
|
|
ofs << "</p>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_COMMAND:
|
2003-04-02 21:19:35 +00:00
|
|
|
|
if (depth != 0)
|
2003-07-07 08:37:02 +00:00
|
|
|
|
error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (!environment_stack[depth].empty()) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false, environment_stack[depth]);
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs << "</p>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2003-02-17 15:16:14 +00:00
|
|
|
|
case LATEX_BIB_ENVIRONMENT:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
{
|
|
|
|
|
string const & latexname = style->latexname();
|
|
|
|
|
|
2003-04-02 21:19:35 +00:00
|
|
|
|
if (depth == pit->params().depth()
|
2002-06-24 20:28:12 +00:00
|
|
|
|
&& environment_stack[depth] != latexname) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-04-02 21:19:35 +00:00
|
|
|
|
if (depth < pit->params().depth()) {
|
|
|
|
|
depth = pit->params().depth();
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (environment_stack[depth] != latexname) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (depth == 0) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, "p");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, latexname);
|
2001-03-21 23:38:07 +00:00
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (environment_stack.size() == depth + 1)
|
2001-03-21 23:38:07 +00:00
|
|
|
|
environment_stack.push_back("!-- --");
|
2002-06-24 20:28:12 +00:00
|
|
|
|
environment_stack[depth] = latexname;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2001-03-21 23:38:07 +00:00
|
|
|
|
ofs << "<![CDATA[";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latextype == LATEX_ENVIRONMENT) break;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->labeltype == LABEL_MANUAL)
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name = "tag";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name = "item";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + 1, false, item_name);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
default:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth, false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-02 10:06:07 +00:00
|
|
|
|
simpleLinuxDocOnePar(ofs, pit, depth);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs << "\n";
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// write closing SGML tags
|
2002-06-24 20:28:12 +00:00
|
|
|
|
switch (style->latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_COMMAND:
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2003-02-17 15:16:14 +00:00
|
|
|
|
case LATEX_BIB_ENVIRONMENT:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2001-03-21 23:38:07 +00:00
|
|
|
|
ofs << "]]>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// Close open tags
|
2002-06-24 20:28:12 +00:00
|
|
|
|
for (int i = depth; i >= 0; --i)
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth, false, environment_stack[i]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
if (!body_only) {
|
|
|
|
|
ofs << "\n\n";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, 0, false, top_element);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs.close();
|
|
|
|
|
// How to check for successful close
|
2002-03-07 16:03:36 +00:00
|
|
|
|
|
|
|
|
|
// we want this to be true outside previews (for insetexternal)
|
|
|
|
|
niceFile = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// checks, if newcol chars should be put into this line
|
|
|
|
|
// writes newline, if necessary.
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2001-11-08 11:32:18 +00:00
|
|
|
|
void sgmlLineBreak(ostream & os, string::size_type & colcount,
|
2000-09-27 17:07:33 +00:00
|
|
|
|
string::size_type newcol)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
colcount += newcol;
|
2000-03-12 10:35:05 +00:00
|
|
|
|
if (colcount > lyxrc.ascii_linelen) {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
colcount = newcol; // assume write after this call
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
enum PAR_TAG {
|
|
|
|
|
NONE=0,
|
|
|
|
|
TT = 1,
|
|
|
|
|
SF = 2,
|
|
|
|
|
BF = 4,
|
|
|
|
|
IT = 8,
|
|
|
|
|
SL = 16,
|
|
|
|
|
EM = 32
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string tag_name(PAR_TAG const & pt) {
|
|
|
|
|
switch (pt) {
|
2001-03-23 16:46:39 +00:00
|
|
|
|
case NONE: return "!-- --";
|
|
|
|
|
case TT: return "tt";
|
|
|
|
|
case SF: return "sf";
|
|
|
|
|
case BF: return "bf";
|
|
|
|
|
case IT: return "it";
|
|
|
|
|
case SL: return "sl";
|
|
|
|
|
case EM: return "em";
|
2001-03-23 08:37:44 +00:00
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
|
|
|
|
|
{
|
2002-03-21 16:55:34 +00:00
|
|
|
|
p1 = static_cast<PAR_TAG>(p1 | p2);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
void reset(PAR_TAG & p1, PAR_TAG const & p2)
|
|
|
|
|
{
|
2002-02-16 15:59:55 +00:00
|
|
|
|
p1 = static_cast<PAR_TAG>(p1 & ~p2);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-25 11:15:27 +00:00
|
|
|
|
} // anon
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
// Handle internal paragraph parsing -- layout already processed.
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::simpleLinuxDocOnePar(ostream & os,
|
2003-05-02 10:06:07 +00:00
|
|
|
|
ParagraphList::iterator par,
|
|
|
|
|
Paragraph::depth_type /*depth*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & style = par->layout();
|
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
string::size_type char_line_count = 5; // Heuristic choice ;-)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// gets paragraph main font
|
2001-03-21 23:38:07 +00:00
|
|
|
|
LyXFont font_old;
|
|
|
|
|
bool desc_on;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->labeltype == LABEL_MANUAL) {
|
|
|
|
|
font_old = style->labelfont;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
desc_on = true;
|
2001-03-22 19:36:21 +00:00
|
|
|
|
} else {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
font_old = style->font;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
desc_on = false;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
|
|
|
|
|
LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
|
|
|
|
|
LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
|
|
|
|
|
bool is_em = false;
|
|
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
|
stack<PAR_TAG> tag_state;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// parsing main loop
|
2001-11-27 10:34:16 +00:00
|
|
|
|
for (pos_type i = 0; i < par->size(); ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
PAR_TAG tag_close = NONE;
|
|
|
|
|
list < PAR_TAG > tag_open;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-04-16 04:35:43 +00:00
|
|
|
|
LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.family() != font.family()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (family_type) {
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::SANS_FAMILY:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= SF;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::TYPEWRITER_FAMILY:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= TT;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
family_type = font.family();
|
|
|
|
|
|
|
|
|
|
switch (family_type) {
|
|
|
|
|
case LyXFont::SANS_FAMILY:
|
|
|
|
|
tag_open.push_back(SF);
|
|
|
|
|
break;
|
|
|
|
|
case LyXFont::TYPEWRITER_FAMILY:
|
|
|
|
|
tag_open.push_back(TT);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.series() != font.series()) {
|
|
|
|
|
switch (series_type) {
|
|
|
|
|
case LyXFont::BOLD_SERIES:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= BF;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
series_type = font.series();
|
|
|
|
|
|
|
|
|
|
switch (series_type) {
|
|
|
|
|
case LyXFont::BOLD_SERIES:
|
|
|
|
|
tag_open.push_back(BF);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-03-21 23:38:07 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.shape() != font.shape()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (shape_type) {
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::ITALIC_SHAPE:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= IT;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::SLANTED_SHAPE:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= SL;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shape_type = font.shape();
|
|
|
|
|
|
|
|
|
|
switch (shape_type) {
|
|
|
|
|
case LyXFont::ITALIC_SHAPE:
|
|
|
|
|
tag_open.push_back(IT);
|
|
|
|
|
break;
|
|
|
|
|
case LyXFont::SLANTED_SHAPE:
|
|
|
|
|
tag_open.push_back(SL);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// handle <em> tag
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.emph() != font.emph()) {
|
|
|
|
|
if (font.emph() == LyXFont::ON) {
|
|
|
|
|
tag_open.push_back(EM);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
is_em = true;
|
2001-03-23 08:37:44 +00:00
|
|
|
|
}
|
|
|
|
|
else if (is_em) {
|
|
|
|
|
tag_close |= EM;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
is_em = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
list < PAR_TAG > temp;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
while (!tag_state.empty() && tag_close) {
|
2001-03-23 08:37:44 +00:00
|
|
|
|
PAR_TAG k = tag_state.top();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
tag_state.pop();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "</" << tag_name(k) << '>';
|
2001-03-23 08:37:44 +00:00
|
|
|
|
if (tag_close & k)
|
|
|
|
|
reset(tag_close,k);
|
2001-03-21 23:38:07 +00:00
|
|
|
|
else
|
|
|
|
|
temp.push_back(k);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
for(list< PAR_TAG >::const_iterator j = temp.begin();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
j != temp.end(); ++j) {
|
|
|
|
|
tag_state.push(*j);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '<' << tag_name(*j) << '>';
|
2001-03-21 23:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
for(list< PAR_TAG >::const_iterator j = tag_open.begin();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
j != tag_open.end(); ++j) {
|
|
|
|
|
tag_state.push(*j);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '<' << tag_name(*j) << '>';
|
2001-03-21 23:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
char c = par->getChar(i);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (c == Paragraph::META_INSET) {
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * inset = par->getInset(i);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->linuxdoc(this, os);
|
2001-03-21 23:38:07 +00:00
|
|
|
|
font_old = font;
|
|
|
|
|
continue;
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA") {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
// "TeX"-Mode on == > SGML-Mode on.
|
2000-03-09 03:36:48 +00:00
|
|
|
|
if (c != '\0')
|
2001-03-21 23:38:07 +00:00
|
|
|
|
os << c;
|
2000-01-24 18:34:46 +00:00
|
|
|
|
++char_line_count;
|
2000-03-09 23:58:55 +00:00
|
|
|
|
} else {
|
2002-08-09 00:42:12 +00:00
|
|
|
|
bool ws;
|
|
|
|
|
string str;
|
|
|
|
|
boost::tie(ws, str) = sgml::escapeChar(c);
|
2003-06-07 17:45:43 +00:00
|
|
|
|
if (ws && !par->isFreeSpacing()) {
|
2001-03-21 23:38:07 +00:00
|
|
|
|
// in freespacing mode, spaces are
|
|
|
|
|
// non-breaking characters
|
|
|
|
|
if (desc_on) {// if char is ' ' then...
|
|
|
|
|
|
2000-01-24 18:34:46 +00:00
|
|
|
|
++char_line_count;
|
2001-11-08 11:32:18 +00:00
|
|
|
|
sgmlLineBreak(os, char_line_count, 6);
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << "</tag>";
|
2001-03-21 23:38:07 +00:00
|
|
|
|
desc_on = false;
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
2001-11-08 11:32:18 +00:00
|
|
|
|
sgmlLineBreak(os, char_line_count, 1);
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << c;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
2002-08-09 00:42:12 +00:00
|
|
|
|
os << str;
|
|
|
|
|
char_line_count += str.length();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-21 23:38:07 +00:00
|
|
|
|
font_old = font;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
1999-11-15 12:01:38 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
while (!tag_state.empty()) {
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "</" << tag_name(tag_state.top()) << '>';
|
2001-03-21 23:38:07 +00:00
|
|
|
|
tag_state.pop();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// resets description flag correctly
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (desc_on) {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// <tag> not closed...
|
2001-11-08 11:32:18 +00:00
|
|
|
|
sgmlLineBreak(os, char_line_count, 6);
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << "</tag>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-07-26 20:09:56 +00:00
|
|
|
|
ofstream ofs;
|
|
|
|
|
if (!::openFileWrite(ofs, fname))
|
2003-03-29 09:48:03 +00:00
|
|
|
|
return;
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
niceFile = nice; // this will be used by Insetincludes.
|
|
|
|
|
|
2002-03-02 19:09:56 +00:00
|
|
|
|
LaTeXFeatures features(params);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
validate(features);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
texrow.reset();
|
|
|
|
|
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2002-03-02 19:09:56 +00:00
|
|
|
|
string top_element = tclass.latexname();
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!only_body) {
|
2001-10-23 09:42:14 +00:00
|
|
|
|
ofs << "<!DOCTYPE " << top_element
|
2001-10-24 13:08:52 +00:00
|
|
|
|
<< " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-10-23 09:42:14 +00:00
|
|
|
|
string preamble = params.preamble;
|
2003-06-28 01:23:11 +00:00
|
|
|
|
string const name = nice ? ChangeExtension(filename_, ".sgml")
|
2002-03-05 13:38:40 +00:00
|
|
|
|
: fname;
|
|
|
|
|
preamble += features.getIncludedFiles(name);
|
2001-10-23 09:42:14 +00:00
|
|
|
|
preamble += features.getLyXSGMLEntities();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-10-23 09:42:14 +00:00
|
|
|
|
if (!preamble.empty()) {
|
|
|
|
|
ofs << "\n [ " << preamble << " ]";
|
|
|
|
|
}
|
|
|
|
|
ofs << ">\n\n";
|
2000-11-13 15:43:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
string top = top_element;
|
2001-01-28 21:54:15 +00:00
|
|
|
|
top += " lang=\"";
|
|
|
|
|
top += params.language->code();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
top += '"';
|
2001-01-28 21:54:15 +00:00
|
|
|
|
|
|
|
|
|
if (!params.options.empty()) {
|
2002-11-27 10:30:28 +00:00
|
|
|
|
top += ' ';
|
2000-11-13 15:43:36 +00:00
|
|
|
|
top += params.options;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, 0, false, top);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-07-28 14:09:05 +00:00
|
|
|
|
ofs << "<!-- DocBook file was created by LyX " << lyx_version
|
2000-07-01 12:54:45 +00:00
|
|
|
|
<< "\n See http://www.lyx.org/ for more information -->\n";
|
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
vector<string> environment_stack(10);
|
|
|
|
|
vector<string> environment_inner(10);
|
|
|
|
|
vector<string> command_stack(10);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
bool command_flag = false;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type command_depth = 0;
|
|
|
|
|
Paragraph::depth_type command_base = 0;
|
|
|
|
|
Paragraph::depth_type cmd_depth = 0;
|
|
|
|
|
Paragraph::depth_type depth = 0; // paragraph depth
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
string item_name;
|
2001-04-04 21:47:26 +00:00
|
|
|
|
string command_name;
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2003-04-16 08:12:22 +00:00
|
|
|
|
ParagraphList::iterator par = paragraphs.begin();
|
|
|
|
|
ParagraphList::iterator pend = paragraphs.end();
|
|
|
|
|
|
|
|
|
|
for (; par != pend; ++par) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
string sgmlparam;
|
|
|
|
|
string c_depth;
|
|
|
|
|
string c_params;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
int desc_on = 0; // description mode
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & style = par->layout();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// environment tag closing
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (; depth > par->params().depth(); --depth) {
|
2003-06-06 11:28:12 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
item_name = "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, command_depth + depth, false, item_name);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
|
environment_inner[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth == par->params().depth()
|
2002-06-24 20:28:12 +00:00
|
|
|
|
&& environment_stack[depth] != style->latexname()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
&& !environment_stack[depth].empty()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name= "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, command_depth+depth, false, item_name);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
|
environment_inner[depth].erase();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Write opening SGML tags.
|
2002-06-24 20:28:12 +00:00
|
|
|
|
switch (style->latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_PARAGRAPH:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + command_depth,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_COMMAND:
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (depth != 0)
|
2003-07-07 08:37:02 +00:00
|
|
|
|
error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
command_name = style->latexname();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
sgmlparam = style->latexparam();
|
2001-03-23 08:37:44 +00:00
|
|
|
|
c_params = split(sgmlparam, c_depth,'|');
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
cmd_depth = atoi(c_depth);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (command_flag) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (cmd_depth < command_base) {
|
2002-05-03 11:56:49 +00:00
|
|
|
|
for (Paragraph::depth_type j = command_depth;
|
|
|
|
|
j >= command_base; --j) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, j, false, command_stack[j]);
|
2002-05-03 11:56:49 +00:00
|
|
|
|
ofs << endl;
|
|
|
|
|
}
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_depth = command_base = cmd_depth;
|
2000-11-04 10:00:12 +00:00
|
|
|
|
} else if (cmd_depth <= command_depth) {
|
2002-05-03 11:56:49 +00:00
|
|
|
|
for (int j = command_depth;
|
|
|
|
|
j >= int(cmd_depth); --j) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, j, false, command_stack[j]);
|
2002-05-03 11:56:49 +00:00
|
|
|
|
ofs << endl;
|
|
|
|
|
}
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_depth = cmd_depth;
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_depth = cmd_depth;
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
command_depth = command_base = cmd_depth;
|
|
|
|
|
command_flag = true;
|
|
|
|
|
}
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (command_stack.size() == command_depth + 1)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
command_stack.push_back(string());
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_stack[command_depth] = command_name;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// treat label as a special case for
|
|
|
|
|
// more WYSIWYM handling.
|
2001-11-30 11:56:04 +00:00
|
|
|
|
// This is a hack while paragraphs can't have
|
|
|
|
|
// attributes, like id in this case.
|
2001-11-23 10:16:02 +00:00
|
|
|
|
if (par->isInset(0)) {
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * inset = par->getInset(0);
|
|
|
|
|
InsetOld::Code lyx_code = inset->lyxCode();
|
|
|
|
|
if (lyx_code == InsetOld::LABEL_CODE) {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
command_name += " id=\"";
|
|
|
|
|
command_name += (static_cast<InsetCommand *>(inset))->getContents();
|
2002-11-27 10:30:28 +00:00
|
|
|
|
command_name += '"';
|
1999-12-07 00:44:53 +00:00
|
|
|
|
desc_on = 3;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + command_depth, false, command_name);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
2002-11-27 10:30:28 +00:00
|
|
|
|
item_name = c_params.empty() ? "title" : c_params;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth < par->params().depth()) {
|
|
|
|
|
depth = par->params().depth();
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (environment_stack[depth] != style->latexname()) {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (environment_stack.size() == depth + 1) {
|
2001-03-23 08:37:44 +00:00
|
|
|
|
environment_stack.push_back("!-- --");
|
|
|
|
|
environment_inner.push_back("!-- --");
|
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
environment_stack[depth] = style->latexname();
|
1999-12-07 00:44:53 +00:00
|
|
|
|
environment_inner[depth] = "!-- --";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name= "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, command_depth + depth, false, item_name);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latextype == LATEX_ENVIRONMENT) {
|
|
|
|
|
if (!style->latexparam().empty()) {
|
|
|
|
|
if (style->latexparam() == "CDATA")
|
2001-03-21 23:38:07 +00:00
|
|
|
|
ofs << "<![CDATA[";
|
2001-01-28 21:54:15 +00:00
|
|
|
|
else
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
|
2001-01-28 21:54:15 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
desc_on = (style->labeltype == LABEL_MANUAL);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + 1 + command_depth,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
false, environment_inner[depth]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
item_name = desc_on ? "term" : "para";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + 1 + command_depth,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
false, item_name);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::openTag(ofs, depth + command_depth,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
simpleDocBookOnePar(ofs, par, desc_on,
|
|
|
|
|
depth + 1 + command_depth);
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string end_tag;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// write closing SGML tags
|
2002-06-24 20:28:12 +00:00
|
|
|
|
switch (style->latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_COMMAND:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
end_tag = c_params.empty() ? "title" : c_params;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
false, end_tag);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (!style->latexparam().empty()) {
|
|
|
|
|
if (style->latexparam() == "CDATA")
|
2001-01-28 21:54:15 +00:00
|
|
|
|
ofs << "]]>";
|
|
|
|
|
else
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
|
2001-01-28 21:54:15 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (desc_on == 1) break;
|
2002-11-27 10:30:28 +00:00
|
|
|
|
end_tag = "para";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_PARAGRAPH:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close open tags
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (int d = depth; d >= 0; --d) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!environment_stack[depth].empty()) {
|
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
item_name = "listitem";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, command_depth + depth, false, item_name);
|
2002-03-21 16:55:34 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
|
1999-10-02 14:01:04 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
|
1999-10-02 14:01:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (int j = command_depth; j >= 0 ; --j)
|
2002-05-03 11:56:49 +00:00
|
|
|
|
if (!command_stack[j].empty()) {
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, j, false, command_stack[j]);
|
2002-05-03 11:56:49 +00:00
|
|
|
|
ofs << endl;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-13 15:43:36 +00:00
|
|
|
|
ofs << "\n\n";
|
2002-10-21 16:21:56 +00:00
|
|
|
|
sgml::closeTag(ofs, 0, false, top_element);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs.close();
|
|
|
|
|
// How to check for successful close
|
2002-03-07 16:03:36 +00:00
|
|
|
|
|
|
|
|
|
// we want this to be true outside previews (for insetexternal)
|
|
|
|
|
niceFile = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-14 09:46:05 +00:00
|
|
|
|
void Buffer::simpleDocBookOnePar(ostream & os,
|
2003-04-16 08:12:22 +00:00
|
|
|
|
ParagraphList::iterator par, int & desc_on,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
bool emph_flag = false;
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & style = par->layout();
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2000-03-09 03:36:48 +00:00
|
|
|
|
int char_line_count = depth;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
//if (!style.free_spacing)
|
|
|
|
|
// os << string(depth,' ');
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// parsing main loop
|
2001-11-27 10:34:16 +00:00
|
|
|
|
for (pos_type i = 0; i < par->size(); ++i) {
|
2003-04-16 04:35:43 +00:00
|
|
|
|
LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// handle <emphasis> tag
|
2001-03-23 08:37:44 +00:00
|
|
|
|
if (font_old.emph() != font.emph()) {
|
|
|
|
|
if (font.emph() == LyXFont::ON) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "]]>";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "<emphasis>";
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "<![CDATA[";
|
2000-03-09 03:36:48 +00:00
|
|
|
|
emph_flag = true;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
} else if (i) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "]]>";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "</emphasis>";
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "<![CDATA[";
|
2000-03-09 03:36:48 +00:00
|
|
|
|
emph_flag = false;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
if (par->isInset(i)) {
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * inset = par->getInset(i);
|
2001-11-30 11:56:04 +00:00
|
|
|
|
// don't print the inset in position 0 if desc_on == 3 (label)
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (i || desc_on != 3) {
|
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-02-18 17:33:14 +00:00
|
|
|
|
os << "]]>";
|
2002-06-18 15:44:30 +00:00
|
|
|
|
inset->docbook(this, os, false);
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-02-18 17:33:14 +00:00
|
|
|
|
os << "<![CDATA[";
|
|
|
|
|
}
|
2000-04-26 13:57:28 +00:00
|
|
|
|
} else {
|
2001-11-30 11:56:04 +00:00
|
|
|
|
char c = par->getChar(i);
|
2002-08-09 00:42:12 +00:00
|
|
|
|
bool ws;
|
|
|
|
|
string str;
|
|
|
|
|
boost::tie(ws, str) = sgml::escapeChar(c);
|
2001-10-03 17:28:08 +00:00
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->pass_thru) {
|
2001-10-03 17:28:08 +00:00
|
|
|
|
os << c;
|
2003-06-07 17:45:43 +00:00
|
|
|
|
} else if (par->isFreeSpacing() || c != ' ') {
|
2002-08-09 00:42:12 +00:00
|
|
|
|
os << str;
|
2003-06-07 17:45:43 +00:00
|
|
|
|
} else if (desc_on == 1) {
|
2001-10-03 17:28:08 +00:00
|
|
|
|
++char_line_count;
|
|
|
|
|
os << "\n</term><listitem><para>";
|
|
|
|
|
desc_on = 2;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
} else {
|
2001-10-03 17:28:08 +00:00
|
|
|
|
os << ' ';
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-23 08:37:44 +00:00
|
|
|
|
font_old = font;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (emph_flag) {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "]]>";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "</emphasis>";
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->latexparam() == "CDATA")
|
2002-05-03 11:56:49 +00:00
|
|
|
|
os << "<![CDATA[";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// resets description flag correctly
|
2001-03-23 08:37:44 +00:00
|
|
|
|
if (desc_on == 1) {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// <term> not closed...
|
2002-03-12 08:44:04 +00:00
|
|
|
|
os << "</term>\n<listitem><para> </para>";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (style->free_spacing)
|
|
|
|
|
os << '\n';
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
|
|
|
|
|
// Other flags: -wall -v0 -x
|
|
|
|
|
int Buffer::runChktex()
|
|
|
|
|
{
|
2003-07-07 08:37:02 +00:00
|
|
|
|
busy(true);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// get LaTeX-Filename
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const name = getLatexName();
|
2002-01-14 23:31:23 +00:00
|
|
|
|
string path = filePath();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const org_path = path;
|
2001-08-01 10:08:53 +00:00
|
|
|
|
if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
|
2002-03-21 16:55:34 +00:00
|
|
|
|
path = tmppath;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-13 17:32:46 +00:00
|
|
|
|
Path p(path); // path to LaTeX file
|
2003-07-07 08:37:02 +00:00
|
|
|
|
message(_("Running chktex..."));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Generate the LaTeX file if neccessary
|
2003-05-22 18:59:10 +00:00
|
|
|
|
LatexRunParams runparams;
|
|
|
|
|
runparams.flavor = LatexRunParams::LATEX;
|
2003-05-22 21:10:22 +00:00
|
|
|
|
runparams.nice = false;
|
|
|
|
|
makeLaTeXFile(name, org_path, runparams);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
TeXErrors terr;
|
2002-01-14 23:31:23 +00:00
|
|
|
|
Chktex chktex(lyxrc.chktex_command, name, filePath());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int res = chktex.run(terr); // run chktex
|
|
|
|
|
|
|
|
|
|
if (res == -1) {
|
2003-03-29 09:48:03 +00:00
|
|
|
|
Alert::error(_("chktex failure"),
|
2003-06-20 23:03:43 +00:00
|
|
|
|
_("Could not run chktex successfully."));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else if (res > 0) {
|
|
|
|
|
// Insert all errors as errors boxes
|
2003-07-07 08:37:02 +00:00
|
|
|
|
bufferErrors(*this, terr);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-07 08:37:02 +00:00
|
|
|
|
busy(false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
void Buffer::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = params.getLyXTextClass();
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
if (params.tracking_changes) {
|
|
|
|
|
features.require("dvipost");
|
|
|
|
|
features.require("color");
|
|
|
|
|
}
|
2003-03-02 12:16:00 +00:00
|
|
|
|
|
2002-03-21 16:55:34 +00:00
|
|
|
|
// AMS Style is at document level
|
2003-03-06 11:07:55 +00:00
|
|
|
|
if (params.use_amsmath == BufferParams::AMS_ON
|
|
|
|
|
|| tclass.provides(LyXTextClass::amsmath))
|
2002-01-10 10:05:45 +00:00
|
|
|
|
features.require("amsmath");
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
2002-08-14 22:15:18 +00:00
|
|
|
|
for_each(paragraphs.begin(), paragraphs.end(),
|
|
|
|
|
boost::bind(&Paragraph::validate, _1, boost::ref(features)));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// the bullet shapes are buffer level not paragraph level
|
|
|
|
|
// so they are tested here
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
|
if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
int const font = params.user_defined_bullets[i].getFont();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (font == 0) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
int const c = params
|
1999-11-04 01:40:20 +00:00
|
|
|
|
.user_defined_bullets[i]
|
|
|
|
|
.getCharacter();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (c == 16
|
|
|
|
|
|| c == 17
|
|
|
|
|
|| c == 25
|
|
|
|
|
|| c == 26
|
|
|
|
|
|| c == 31) {
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("latexsym");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-09-26 13:54:57 +00:00
|
|
|
|
} else if (font == 1) {
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("amssymb");
|
2000-09-26 13:54:57 +00:00
|
|
|
|
} else if ((font >= 2 && font <= 5)) {
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("pifont");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 16:55:34 +00:00
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::LATEX)) {
|
2000-04-10 21:40:13 +00:00
|
|
|
|
features.showStruct();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-16 11:49:38 +00:00
|
|
|
|
void Buffer::getLabelList(std::vector<string> & list) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
/// if this is a child document and the parent is already loaded
|
|
|
|
|
/// Use the parent's list instead [ale990407]
|
2000-01-25 12:35:27 +00:00
|
|
|
|
if (!params.parentname.empty()
|
|
|
|
|
&& bufferlist.exists(params.parentname)) {
|
2002-08-12 20:17:41 +00:00
|
|
|
|
Buffer const * tmp = bufferlist.getBuffer(params.parentname);
|
2003-06-16 11:49:38 +00:00
|
|
|
|
if (tmp) {
|
|
|
|
|
tmp->getLabelList(list);
|
|
|
|
|
return;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-12 20:17:41 +00:00
|
|
|
|
for (inset_iterator it = inset_const_iterator_begin();
|
|
|
|
|
it != inset_const_iterator_end(); ++it) {
|
2003-06-16 11:49:38 +00:00
|
|
|
|
it->getLabelList(list);
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// This is also a buffer property (ale)
|
2003-06-28 01:23:11 +00:00
|
|
|
|
void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
/// if this is a child document and the parent is already loaded
|
2003-02-18 13:25:18 +00:00
|
|
|
|
/// use the parent's list instead [ale990412]
|
2002-03-21 16:55:34 +00:00
|
|
|
|
if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
|
2002-04-16 09:12:36 +00:00
|
|
|
|
Buffer const * tmp = bufferlist.getBuffer(params.parentname);
|
2003-02-18 13:25:18 +00:00
|
|
|
|
if (tmp) {
|
|
|
|
|
tmp->fillWithBibKeys(keys);
|
|
|
|
|
return;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
|
for (inset_iterator it = inset_const_iterator_begin();
|
|
|
|
|
it != inset_const_iterator_end(); ++it) {
|
2003-07-25 21:20:24 +00:00
|
|
|
|
if (it->lyxCode() == InsetOld::BIBTEX_CODE)
|
2003-02-18 13:25:18 +00:00
|
|
|
|
static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
|
2003-07-25 21:20:24 +00:00
|
|
|
|
else if (it->lyxCode() == InsetOld::INCLUDE_CODE)
|
2003-02-18 13:25:18 +00:00
|
|
|
|
static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
|
2003-07-25 21:20:24 +00:00
|
|
|
|
else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
|
2003-02-21 09:20:18 +00:00
|
|
|
|
InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
|
2003-02-18 12:36:02 +00:00
|
|
|
|
string const key = bib.getContents();
|
|
|
|
|
string const opt = bib.getOptions();
|
|
|
|
|
string const ref; // = pit->asString(this, false);
|
|
|
|
|
string const info = opt + "TheBibliographyRef" + ref;
|
2003-02-18 13:25:18 +00:00
|
|
|
|
keys.push_back(pair<string, string>(key, info));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
bool Buffer::isDepClean(string const & name) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-02-09 00:27:52 +00:00
|
|
|
|
DepClean::const_iterator it = dep_clean_.find(name);
|
|
|
|
|
if (it == dep_clean_.end())
|
|
|
|
|
return true;
|
|
|
|
|
return it->second;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
void Buffer::markDepClean(string const & name)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-02-09 00:27:52 +00:00
|
|
|
|
dep_clean_[name] = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
|
2002-05-30 19:49:00 +00:00
|
|
|
|
bool Buffer::dispatch(string const & command, bool * result)
|
1999-12-10 00:07:59 +00:00
|
|
|
|
{
|
|
|
|
|
// Split command string into command and argument
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string cmd;
|
2002-07-28 22:50:13 +00:00
|
|
|
|
string line = ltrim(command);
|
|
|
|
|
string const arg = trim(split(line, cmd, ' '));
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2002-05-30 19:49:00 +00:00
|
|
|
|
return dispatch(lyxaction.LookupFunc(cmd), arg, result);
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
|
2002-05-30 19:49:00 +00:00
|
|
|
|
bool Buffer::dispatch(int action, string const & argument, bool * result)
|
1999-12-10 00:07:59 +00:00
|
|
|
|
{
|
2000-04-28 11:18:04 +00:00
|
|
|
|
bool dispatched = true;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
switch (action) {
|
2002-05-30 19:49:00 +00:00
|
|
|
|
case LFUN_EXPORT: {
|
|
|
|
|
bool const tmp = Exporter::Export(this, argument, false);
|
|
|
|
|
if (result)
|
|
|
|
|
*result = tmp;
|
1999-12-15 17:42:22 +00:00
|
|
|
|
break;
|
2002-05-30 19:49:00 +00:00
|
|
|
|
}
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
|
|
|
|
default:
|
2000-04-28 11:18:04 +00:00
|
|
|
|
dispatched = false;
|
|
|
|
|
}
|
|
|
|
|
return dispatched;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::changeLanguage(Language const * from, Language const * to)
|
2000-04-10 21:40:13 +00:00
|
|
|
|
{
|
2003-04-25 01:54:04 +00:00
|
|
|
|
lyxerr << "Changing Language!" << endl;
|
2003-04-28 21:58:53 +00:00
|
|
|
|
|
2003-04-24 23:19:41 +00:00
|
|
|
|
// Take care of l10n/i18n
|
2003-04-25 01:54:04 +00:00
|
|
|
|
updateDocLang(to);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
2001-09-01 21:26:34 +00:00
|
|
|
|
ParIterator end = par_iterator_end();
|
|
|
|
|
for (ParIterator it = par_iterator_begin(); it != end; ++it)
|
2003-06-12 11:09:55 +00:00
|
|
|
|
it->changeLanguage(params, from, to);
|
2000-04-10 21:40:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-28 21:58:53 +00:00
|
|
|
|
|
2003-04-25 01:54:04 +00:00
|
|
|
|
void Buffer::updateDocLang(Language const * nlang)
|
|
|
|
|
{
|
2003-04-27 22:11:45 +00:00
|
|
|
|
messages_.reset(new Messages(nlang->code()));
|
2003-04-25 01:54:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
bool Buffer::isMultiLingual()
|
|
|
|
|
{
|
2001-09-01 21:26:34 +00:00
|
|
|
|
ParIterator end = par_iterator_end();
|
|
|
|
|
for (ParIterator it = par_iterator_begin(); it != end; ++it)
|
2003-06-12 11:09:55 +00:00
|
|
|
|
if (it->isMultiLingual(params))
|
2000-04-10 21:40:13 +00:00
|
|
|
|
return true;
|
2001-09-01 21:26:34 +00:00
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::inset_iterator::setParagraph()
|
2000-09-26 13:54:57 +00:00
|
|
|
|
{
|
2002-08-20 17:18:21 +00:00
|
|
|
|
while (pit != pend) {
|
|
|
|
|
it = pit->insetlist.begin();
|
|
|
|
|
if (it != pit->insetlist.end())
|
2000-05-19 16:46:01 +00:00
|
|
|
|
return;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
++pit;
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * Buffer::getInsetFromID(int id_arg) const
|
2001-07-06 15:57:54 +00:00
|
|
|
|
{
|
|
|
|
|
for (inset_iterator it = inset_const_iterator_begin();
|
|
|
|
|
it != inset_const_iterator_end(); ++it)
|
|
|
|
|
{
|
2002-08-20 17:18:21 +00:00
|
|
|
|
if (it->id() == id_arg)
|
|
|
|
|
return &(*it);
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld * in = it->getInsetFromID(id_arg);
|
2001-07-06 15:57:54 +00:00
|
|
|
|
if (in)
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-07-09 09:16:00 +00:00
|
|
|
|
|
|
|
|
|
|
2003-05-22 08:01:41 +00:00
|
|
|
|
ParIterator Buffer::getParFromID(int id) const
|
2001-07-09 09:16:00 +00:00
|
|
|
|
{
|
2003-04-28 18:20:31 +00:00
|
|
|
|
#warning FIXME: const correctness! (Andre)
|
2003-05-23 10:33:40 +00:00
|
|
|
|
ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
|
|
|
|
|
ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
|
2003-04-28 18:20:31 +00:00
|
|
|
|
|
|
|
|
|
#warning FIXME, perhaps this func should return a ParIterator? (Lgb)
|
|
|
|
|
if (id < 0) {
|
|
|
|
|
// John says this is called with id == -1 from undo
|
|
|
|
|
lyxerr << "getParFromID(), id: " << id << endl;
|
2003-05-22 08:01:41 +00:00
|
|
|
|
return end;
|
2003-04-28 18:20:31 +00:00
|
|
|
|
}
|
2002-08-14 22:15:18 +00:00
|
|
|
|
|
2003-05-22 08:01:41 +00:00
|
|
|
|
for (; it != end; ++it)
|
2003-06-12 11:09:55 +00:00
|
|
|
|
if (it->id() == id)
|
2003-05-22 08:01:41 +00:00
|
|
|
|
return it;
|
2003-02-14 02:21:01 +00:00
|
|
|
|
|
2003-05-22 08:01:41 +00:00
|
|
|
|
return end;
|
2001-07-09 09:16:00 +00:00
|
|
|
|
}
|
2001-09-01 21:26:34 +00:00
|
|
|
|
|
|
|
|
|
|
2003-05-05 17:28:21 +00:00
|
|
|
|
bool Buffer::hasParWithID(int id) const
|
|
|
|
|
{
|
2003-06-12 11:09:55 +00:00
|
|
|
|
ParConstIterator it = par_iterator_begin();
|
|
|
|
|
ParConstIterator end = par_iterator_end();
|
2003-05-05 17:28:21 +00:00
|
|
|
|
|
|
|
|
|
if (id < 0) {
|
|
|
|
|
// John says this is called with id == -1 from undo
|
|
|
|
|
lyxerr << "hasParWithID(), id: " << id << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (; it != end; ++it)
|
2003-06-12 11:09:55 +00:00
|
|
|
|
if (it->id() == id)
|
2003-05-05 17:28:21 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-01 21:26:34 +00:00
|
|
|
|
ParIterator Buffer::par_iterator_begin()
|
|
|
|
|
{
|
2003-05-21 21:20:50 +00:00
|
|
|
|
return ParIterator(paragraphs.begin(), paragraphs);
|
2001-09-01 21:26:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParIterator Buffer::par_iterator_end()
|
|
|
|
|
{
|
2003-05-21 21:20:50 +00:00
|
|
|
|
return ParIterator(paragraphs.end(), paragraphs);
|
2001-09-01 21:26:34 +00:00
|
|
|
|
}
|
2002-08-20 17:18:21 +00:00
|
|
|
|
|
2002-11-08 01:08:27 +00:00
|
|
|
|
ParConstIterator Buffer::par_iterator_begin() const
|
|
|
|
|
{
|
2003-05-27 22:41:04 +00:00
|
|
|
|
return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
|
2002-11-08 01:08:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParConstIterator Buffer::par_iterator_end() const
|
|
|
|
|
{
|
2003-05-27 22:41:04 +00:00
|
|
|
|
return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
|
2002-11-08 01:08:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
Language const * Buffer::getLanguage() const
|
|
|
|
|
{
|
|
|
|
|
return params.language;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-04-24 23:19:41 +00:00
|
|
|
|
string const Buffer::B_(string const & l10n) const
|
|
|
|
|
{
|
|
|
|
|
if (messages_.get()) {
|
|
|
|
|
return messages_->get(l10n);
|
|
|
|
|
}
|
2003-04-28 21:58:53 +00:00
|
|
|
|
|
2003-04-24 23:19:41 +00:00
|
|
|
|
return _(l10n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
bool Buffer::isClean() const
|
|
|
|
|
{
|
|
|
|
|
return lyx_clean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::isBakClean() const
|
|
|
|
|
{
|
|
|
|
|
return bak_clean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::markClean() const
|
|
|
|
|
{
|
|
|
|
|
if (!lyx_clean) {
|
|
|
|
|
lyx_clean = true;
|
|
|
|
|
updateTitles();
|
|
|
|
|
}
|
|
|
|
|
// if the .lyx file has been saved, we don't need an
|
|
|
|
|
// autosave
|
|
|
|
|
bak_clean = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::markBakClean()
|
|
|
|
|
{
|
|
|
|
|
bak_clean = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::setUnnamed(bool flag)
|
|
|
|
|
{
|
|
|
|
|
unnamed = flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::isUnnamed()
|
|
|
|
|
{
|
|
|
|
|
return unnamed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::markDirty()
|
|
|
|
|
{
|
|
|
|
|
if (lyx_clean) {
|
|
|
|
|
lyx_clean = false;
|
|
|
|
|
updateTitles();
|
|
|
|
|
}
|
|
|
|
|
bak_clean = false;
|
2003-02-09 00:27:52 +00:00
|
|
|
|
|
|
|
|
|
DepClean::iterator it = dep_clean_.begin();
|
|
|
|
|
DepClean::const_iterator const end = dep_clean_.end();
|
|
|
|
|
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
it->second = false;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & Buffer::fileName() const
|
|
|
|
|
{
|
|
|
|
|
return filename_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & Buffer::filePath() const
|
|
|
|
|
{
|
|
|
|
|
return filepath_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Buffer::isReadonly() const
|
|
|
|
|
{
|
|
|
|
|
return read_only;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::setParentName(string const & name)
|
|
|
|
|
{
|
|
|
|
|
params.parentname = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator::inset_iterator()
|
2003-05-27 17:29:03 +00:00
|
|
|
|
: pit(), pend()
|
2002-08-20 17:18:21 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
|
|
|
|
|
: pit(p), pend(e)
|
|
|
|
|
{
|
|
|
|
|
setParagraph();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 14:02:58 +00:00
|
|
|
|
Buffer::inset_iterator Buffer::inset_iterator_begin()
|
|
|
|
|
{
|
|
|
|
|
return inset_iterator(paragraphs.begin(), paragraphs.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator Buffer::inset_iterator_end()
|
|
|
|
|
{
|
|
|
|
|
return inset_iterator(paragraphs.end(), paragraphs.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
|
|
|
|
|
{
|
|
|
|
|
return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
|
|
|
|
|
const_cast<ParagraphList&>(paragraphs).end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator Buffer::inset_const_iterator_end() const
|
|
|
|
|
{
|
|
|
|
|
return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
|
|
|
|
|
const_cast<ParagraphList&>(paragraphs).end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-20 17:18:21 +00:00
|
|
|
|
Buffer::inset_iterator & Buffer::inset_iterator::operator++()
|
|
|
|
|
{
|
|
|
|
|
if (pit != pend) {
|
|
|
|
|
++it;
|
|
|
|
|
if (it == pit->insetlist.end()) {
|
|
|
|
|
++pit;
|
|
|
|
|
setParagraph();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
|
|
|
|
|
{
|
|
|
|
|
inset_iterator tmp = *this;
|
|
|
|
|
++*this;
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
|
|
|
|
|
{
|
2003-05-29 01:13:18 +00:00
|
|
|
|
return *it->inset;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
|
|
|
|
|
{
|
2003-05-29 01:13:18 +00:00
|
|
|
|
return it->inset;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-02 10:38:18 +00:00
|
|
|
|
ParagraphList::iterator Buffer::inset_iterator::getPar() const
|
2002-08-20 17:18:21 +00:00
|
|
|
|
{
|
2003-05-02 10:38:18 +00:00
|
|
|
|
return pit;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lyx::pos_type Buffer::inset_iterator::getPos() const
|
|
|
|
|
{
|
2003-05-29 01:13:18 +00:00
|
|
|
|
return it->pos;
|
2002-08-20 17:18:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(Buffer::inset_iterator const & iter1,
|
2002-08-20 19:41:13 +00:00
|
|
|
|
Buffer::inset_iterator const & iter2)
|
2002-08-20 17:18:21 +00:00
|
|
|
|
{
|
|
|
|
|
return iter1.pit == iter2.pit
|
|
|
|
|
&& (iter1.pit == iter1.pend || iter1.it == iter2.it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool operator!=(Buffer::inset_iterator const & iter1,
|
2002-08-20 19:41:13 +00:00
|
|
|
|
Buffer::inset_iterator const & iter2)
|
2002-08-20 17:18:21 +00:00
|
|
|
|
{
|
|
|
|
|
return !(iter1 == iter2);
|
|
|
|
|
}
|