#include "version.h"
#include "LaTeX.h"
#include "Chktex.h"
-#include "LyXView.h"
+#include "frontends/LyXView.h"
#include "debug.h"
#include "LaTeXFeatures.h"
#include "lyxtext.h"
#include <locale>
#endif
+#ifndef CXX_GLOBAL_CSTD
+using std::pow;
+#endif
using std::ostream;
using std::ofstream;
Paragraph * first_par = 0;
LyXFont font(LyXFont::ALL_INHERIT, params.language);
+
+#if 0
if (file_format < 216 && params.language->lang() == "hebrew")
font.setLanguage(default_language);
+#endif
if (!par) {
par = new Paragraph;
void Buffer::insertErtContents(Paragraph * par, int & pos, bool set_inactive)
{
- string str = frontStrip(strip(ert_comp.contents, ' '), ' ');
- if (!str.empty()) {
+ if (ert_comp.contents.find_first_not_of(' ') != string::npos) {
+ // we only skip completely empty ERT (only spaces) otherwise
+ // we have to insert it as is.
+ string str(ert_comp.contents);
lyxerr[Debug::INSETS] << "ERT contents:\n'"
<< str << "'" << endl;
// check if we have already an ert inset a position earlier
static Paragraph * parBeforeMinipage;
#endif
#endif
+
+ // The order of the tags tested may seem unnatural, but this
+ // has been done in order to reduce the number of string
+ // comparisons needed to recognize a given token. This leads
+ // on large documents like UserGuide to a reduction of a
+ // factor 5! (JMarc)
if (token[0] != '\\') {
#ifndef NO_COMPABILITY
if (ert_comp.active) {
#ifndef NO_COMPABILITY
}
#endif
- } else if (token == "\\i") {
- Inset * inset = new InsetLatexAccent;
- inset->read(this, lex);
- par->insertInset(pos, inset, font);
- ++pos;
} else if (token == "\\layout") {
#ifndef NO_COMPABILITY
bool old_fromlayout = ert_comp.fromlayout;
// not ALL_INHERIT,document_language then it will be set to the
// right values after this tag (Jug 20020420)
font = LyXFont(LyXFont::ALL_INHERIT, params.language);
+
+#if 0
if (file_format < 216 && params.language->lang() == "hebrew")
font.setLanguage(default_language);
+#endif
lex.eatLine();
string layoutname = lex.getString();
}
#endif
+ } else if (token == "\\end_inset") {
+ lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
+ << "Last inset read was: " << last_inset_read
+ << endl;
+ // Simply ignore this. The insets do not have
+ // to read this.
+ // But insets should read it, it is a part of
+ // the inset isn't it? Lgb.
+ } else if (token == "\\begin_inset") {
+#ifndef NO_COMPABILITY
+ insertErtContents(par, pos, false);
+ ert_stack.push(ert_comp);
+ ert_comp = ErtComp();
+#endif
+ readInset(lex, par, pos, font);
+#ifndef NO_COMPABILITY
+ ert_comp = ert_stack.top();
+ ert_stack.pop();
+ insertErtContents(par, pos);
+#endif
+ } else if (token == "\\family") {
+ lex.next();
+ font.setLyXFamily(lex.getString());
+ } else if (token == "\\series") {
+ lex.next();
+ font.setLyXSeries(lex.getString());
+ } else if (token == "\\shape") {
+ lex.next();
+ font.setLyXShape(lex.getString());
+ } else if (token == "\\size") {
+ lex.next();
+ font.setLyXSize(lex.getString());
+#ifndef NO_COMPABILITY
+ } else if (token == "\\latex") {
+ lex.next();
+ string const tok = lex.getString();
+ if (tok == "no_latex") {
+ // Do the insetert.
+ insertErtContents(par, pos);
+ } else if (tok == "latex") {
+ ert_comp.active = true;
+ ert_comp.font = font;
+ } else if (tok == "default") {
+ // Do the insetert.
+ insertErtContents(par, pos);
+ } else {
+ lex.printError("Unknown LaTeX font flag "
+ "`$$Token'");
+ }
+#endif
+ } else if (token == "\\lang") {
+ lex.next();
+ string const tok = lex.getString();
+ Language const * lang = languages.getLanguage(tok);
+ if (lang) {
+ font.setLanguage(lang);
+ } else {
+ font.setLanguage(params.language);
+ lex.printError("Unknown language `$$Token'");
+ }
+ } else if (token == "\\numeric") {
+ lex.next();
+ font.setNumber(font.setLyXMisc(lex.getString()));
+ } else if (token == "\\emph") {
+ lex.next();
+ font.setEmph(font.setLyXMisc(lex.getString()));
+ } else if (token == "\\bar") {
+ lex.next();
+ string const tok = lex.getString();
+ // This is dirty, but gone with LyX3. (Asger)
+ if (tok == "under")
+ font.setUnderbar(LyXFont::ON);
+ else if (tok == "no")
+ font.setUnderbar(LyXFont::OFF);
+ else if (tok == "default")
+ font.setUnderbar(LyXFont::INHERIT);
+ else
+ lex.printError("Unknown bar font flag "
+ "`$$Token'");
+ } else if (token == "\\noun") {
+ lex.next();
+ font.setNoun(font.setLyXMisc(lex.getString()));
+ } else if (token == "\\color") {
+ lex.next();
+ font.setLyXColor(lex.getString());
+ } else if (token == "\\SpecialChar") {
+ LyXLayout const & layout =
+ textclasslist[params.textclass][par->layout()];
+
+ // Insets don't make sense in a free-spacing context! ---Kayvan
+ if (layout.free_spacing || par->isFreeSpacing()) {
+ if (lex.isOK()) {
+ lex.next();
+ string next_token = lex.getString();
+ if (next_token == "\\-") {
+ par->insertChar(pos, '-', font);
+ } else if (next_token == "\\protected_separator"
+ || next_token == "~") {
+ par->insertChar(pos, ' ', font);
+ } else {
+ lex.printError("Token `$$Token' "
+ "is in free space "
+ "paragraph layout!");
+ --pos;
+ }
+ }
+ } else {
+ Inset * inset = new InsetSpecialChar;
+ inset->read(this, lex);
+ par->insertInset(pos, inset, font);
+ }
+ ++pos;
+ } else if (token == "\\i") {
+ Inset * inset = new InsetLatexAccent;
+ inset->read(this, lex);
+ par->insertInset(pos, inset, font);
+ ++pos;
+ } else if (token == "\\backslash") {
+#ifndef NO_COMPABILITY
+ if (ert_comp.active) {
+ ert_comp.contents += "\\";
+ } else {
+#endif
+ par->insertChar(pos, '\\', font);
+ ++pos;
+#ifndef NO_COMPABILITY
+ }
+#endif
#ifndef NO_COMPABILITY
} else if (token == "\\begin_float") {
insertErtContents(par, pos);
LyXLex nylex(0, 0);
nylex.setStream(istr);
inset->read(this, nylex);
-
par->insertInset(pos, inset, font);
++pos;
insertErtContents(par, pos);
} else if (token == "\\float_placement") {
lex.nextToken();
params.float_placement = lex.getString();
- } else if (token == "\\family") {
- lex.next();
- font.setLyXFamily(lex.getString());
- } else if (token == "\\series") {
- lex.next();
- font.setLyXSeries(lex.getString());
- } else if (token == "\\shape") {
- lex.next();
- font.setLyXShape(lex.getString());
- } else if (token == "\\size") {
- lex.next();
- font.setLyXSize(lex.getString());
-#ifndef NO_COMPABILITY
- } else if (token == "\\latex") {
- lex.next();
- string const tok = lex.getString();
- if (tok == "no_latex") {
- // Do the insetert.
- insertErtContents(par, pos);
- } else if (tok == "latex") {
- ert_comp.active = true;
- ert_comp.font = font;
- } else if (tok == "default") {
- // Do the insetert.
- insertErtContents(par, pos);
- } else {
- lex.printError("Unknown LaTeX font flag "
- "`$$Token'");
- }
-#endif
- } else if (token == "\\lang") {
- lex.next();
- string const tok = lex.getString();
- Language const * lang = languages.getLanguage(tok);
- if (lang) {
- font.setLanguage(lang);
- } else {
- font.setLanguage(params.language);
- lex.printError("Unknown language `$$Token'");
- }
-#ifndef NO_COMPABILITY
- // if the contents is still empty we're just behind the
- // latex font change and so this inset should also be
- // inserted with that language tag!
- if (ert_comp.active && ert_comp.contents.empty()) {
- ert_comp.font.setLanguage(font.language());
- }
-#endif
- } else if (token == "\\numeric") {
- lex.next();
- font.setNumber(font.setLyXMisc(lex.getString()));
- } else if (token == "\\emph") {
- lex.next();
- font.setEmph(font.setLyXMisc(lex.getString()));
- } else if (token == "\\bar") {
- lex.next();
- string const tok = lex.getString();
- // This is dirty, but gone with LyX3. (Asger)
- if (tok == "under")
- font.setUnderbar(LyXFont::ON);
- else if (tok == "no")
- font.setUnderbar(LyXFont::OFF);
- else if (tok == "default")
- font.setUnderbar(LyXFont::INHERIT);
- else
- lex.printError("Unknown bar font flag "
- "`$$Token'");
- } else if (token == "\\noun") {
- lex.next();
- font.setNoun(font.setLyXMisc(lex.getString()));
- } else if (token == "\\color") {
- lex.next();
- font.setLyXColor(lex.getString());
} else if (token == "\\align") {
int tmpret = lex.findToken(string_align);
if (tmpret == -1) ++tmpret;
} else if (token == "\\added_space_top") {
lex.nextToken();
VSpace value = VSpace(lex.getString());
+ // only add the length when value > 0 or
+ // with option keep
if ((value.length().len().value() != 0) ||
+ value.keep() ||
(value.kind() != VSpace::LENGTH))
- par->params().spaceTop(value);
+ par->params().spaceTop(value);
} else if (token == "\\added_space_bottom") {
lex.nextToken();
VSpace value = VSpace(lex.getString());
+ // only add the length when value > 0 or
+ // with option keep
if ((value.length().len().value() != 0) ||
+ value.keep() ||
(value.kind() != VSpace::LENGTH))
- par->params().spaceBottom(value);
+ par->params().spaceBottom(value);
#ifndef NO_COMPABILITY
#ifndef NO_PEXTRA_REALLY
} else if (token == "\\pextra_type") {
lex.eatLine();
par->params().labelWidthString(lex.getString());
// do not delete this token, it is still needed!
- } else if (token == "\\end_inset") {
- lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
- << "Last inset read was: " << last_inset_read
- << endl;
- // Simply ignore this. The insets do not have
- // to read this.
- // But insets should read it, it is a part of
- // the inset isn't it? Lgb.
- } else if (token == "\\begin_inset") {
-#ifndef NO_COMPABILITY
- insertErtContents(par, pos, false);
- ert_stack.push(ert_comp);
- ert_comp = ErtComp();
-#endif
- readInset(lex, par, pos, font);
-#ifndef NO_COMPABILITY
- ert_comp = ert_stack.top();
- ert_stack.pop();
-#endif
- } else if (token == "\\SpecialChar") {
- LyXLayout const & layout =
- textclasslist[params.textclass][par->layout()];
-
- // Insets don't make sense in a free-spacing context! ---Kayvan
- if (layout.free_spacing || par->isFreeSpacing()) {
- if (lex.isOK()) {
- lex.next();
- string next_token = lex.getString();
- if (next_token == "\\-") {
- par->insertChar(pos, '-', font);
- } else if (next_token == "\\protected_separator"
- || next_token == "~") {
- par->insertChar(pos, ' ', font);
- } else {
- lex.printError("Token `$$Token' "
- "is in free space "
- "paragraph layout!");
- --pos;
- }
- }
- } else {
- Inset * inset = new InsetSpecialChar;
- inset->read(this, lex);
- par->insertInset(pos, inset, font);
- }
- ++pos;
} else if (token == "\\newline") {
#ifndef NO_COMPABILITY
if (!ert_comp.in_tabular && ert_comp.active) {
par->bibkey = new InsetBibKey(p);
}
par->bibkey->read(this, lex);
- } else if (token == "\\backslash") {
-#ifndef NO_COMPABILITY
- if (ert_comp.active) {
- ert_comp.contents += "\\";
- } else {
-#endif
- par->insertChar(pos, '\\', font);
- ++pos;
-#ifndef NO_COMPABILITY
- }
-#endif
} else if (token == "\\the_end") {
#ifndef NO_COMPABILITY
// If we still have some ert active here we have to insert
_("Old LyX file format found. "
"Use LyX 0.10.x to read this!"));
return false;
+ } else if (file_format < 220) {
+ Alert::alert(_("ERROR!"),
+ _("Old LyX file format found. "
+ "User LyX 1.2.x to read this!"));
+ return false;
}
}
bool the_end = readLyXformat2(lex, par);
params.setPaperStuff();
+
+#if 0
// the_end was added in 213
if (file_format < 213)
the_end = true;
+#endif
if (!the_end) {
Alert::alert(_("Warning!"),
*/
// Should probably have some more error checking here.
- // Should be cleaned up in 0.13, at least a bit.
// 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.
void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
string const & /*message*/) const
{
+#ifdef WITH_WARNINGS
#warning This is wrong we cannot insert an inset like this!!!
// I guess this was Jose' so I explain you more or less why this
// is wrong. This way you insert something in the paragraph and
// don't tell it to LyXText (row rebreaking and undo handling!!!)
// I deactivate this code, have a look at BufferView::insertErrors
// how you should do this correctly! (Jug 20020315)
+#endif
#if 0
// insert an error marker in text
InsetError * new_inset = new InsetError(message);
}
-// This should be enabled when the Chktex class is implemented. (Asger)
// chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
// Other flags: -wall -v0 -x
int Buffer::runChktex()
}
-bool Buffer::dispatch(string const & command)
+bool Buffer::dispatch(string const & command, bool * result)
{
// Split command string into command and argument
string cmd;
string line = frontStrip(command);
string const arg = strip(frontStrip(split(line, cmd, ' ')));
- return dispatch(lyxaction.LookupFunc(cmd), arg);
+ return dispatch(lyxaction.LookupFunc(cmd), arg, result);
}
-bool Buffer::dispatch(int action, string const & argument)
+bool Buffer::dispatch(int action, string const & argument, bool * result)
{
bool dispatched = true;
+
switch (action) {
- case LFUN_EXPORT:
- Exporter::Export(this, argument, false);
+ case LFUN_EXPORT: {
+ bool const tmp = Exporter::Export(this, argument, false);
+ if (result)
+ *result = tmp;
break;
+ }
default:
dispatched = false;