#include <config.h>
#include "buffer.h"
+#include "buffer_funcs.h"
#include "bufferlist.h"
#include "LyXAction.h"
#include "lyxrc.h"
#include "mathed/formulamacro.h"
#include "mathed/formula.h"
-#include "insets/inseterror.h"
#include "insets/insetbibitem.h"
#include "insets/insetbibtex.h"
#include "insets/insetinclude.h"
#include <locale>
#endif
+using namespace lyx::support;
+
#ifndef CXX_GLOBAL_CSTD
using std::pow;
#endif
if (read_only != flag) {
read_only = flag;
updateTitles();
- users->owner()->getDialogs().updateBufferDependent(false);
+ if (users)
+ users->owner()->getDialogs().updateBufferDependent(false);
}
}
lyxerr[Debug::PARSER] << "Handling header token: `"
<< token << '\'' << endl;
+
string unknown = params.readToken(lex, token);
if (!unknown.empty()) {
if (unknown[0] != '\\') {
unknownClass(unknown);
} else {
++unknown_tokens;
+ string const s = bformat(_("Unknown token: "
+ "%1$s %2$s\n"),
+ token,
+ lex.getString());
+ parseError(ErrorItem(_("Header error"), s,
+ -1, 0, 0));
}
}
}
// Returns false if "\the_end" is not read (Asger)
bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
{
- int unknown_tokens = 0;
-
Paragraph::depth_type depth = 0;
bool the_end_read = false;
if (paragraphs.empty()) {
- unknown_tokens += readHeader(lex);
-
+ readHeader(lex);
if (!params.getLyXTextClass().load()) {
string theclass = params.getLyXTextClass().name();
Alert::error(_("Can't load document class"), bformat(
continue;
}
- unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth);
- }
-
-
- if (unknown_tokens > 0) {
- string s;
- if (unknown_tokens == 1) {
- s = bformat(_("Encountered one unknown token when reading "
- "the document %1$s."), fileName());
- } else {
- s = bformat(_("Encountered %1$s unknown tokens when reading "
- "the document %2$s."), tostr(unknown_tokens), fileName());
- }
- Alert::warning(_("Document format failure"), s);
+ readParagraph(lex, token, paragraphs, pit, depth);
}
return the_end_read;
int Buffer::readParagraph(LyXLex & lex, string const & token,
- ParagraphList & pars, ParagraphList::iterator & pit,
- Paragraph::depth_type & depth)
+ ParagraphList & pars, ParagraphList::iterator & pit,
+ Paragraph::depth_type & depth)
{
static Change current_change;
int unknown = 0;
LyXFont f(LyXFont::ALL_INHERIT, params.language);
par.setFont(0, f);
- // FIXME: goddamn InsetTabular makes us pass a Buffer
- // not BufferParams
- unknown += ::readParagraph(*this, par, lex);
-
// insert after
if (pit != pars.end())
++pit;
+
pit = pars.insert(pit, par);
+
+ // FIXME: goddamn InsetTabular makes us pass a Buffer
+ // not BufferParams
+ ::readParagraph(*this, *pit, lex);
+
} else if (token == "\\begin_deeper") {
++depth;
} else if (token == "\\end_deeper") {
// This code is reached if lyx2lyx failed (for
// some reason) to change the file format of
// the file.
- lyx::Assert(false);
+ Assert(false);
return false;
}
}
} else {
// Saving failed, so backup is not backup
if (lyxrc.make_backup) {
- lyx::rename(s, fileName());
+ rename(s, fileName());
}
return false;
}
ofs << "<!doctype linuxdoc system";
string preamble = params.preamble;
- const string name = nice ? ChangeExtension(filename_, ".sgml")
+ string const name = nice ? ChangeExtension(filename_, ".sgml")
: fname;
preamble += features.getIncludedFiles(name);
preamble += features.getLyXSGMLEntities();
string item_name;
vector<string> environment_stack(5);
- users->resetErrorList();
-
ParagraphList::iterator pit = paragraphs.begin();
ParagraphList::iterator pend = paragraphs.end();
for (; pit != pend; ++pit) {
case LATEX_COMMAND:
if (depth != 0)
- sgmlError(pit, 0,
- _("Error: Wrong depth for LatexType Command.\n"));
+ parseError(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
if (!environment_stack[depth].empty()) {
sgml::closeTag(ofs, depth, false, environment_stack[depth]);
// we want this to be true outside previews (for insetexternal)
niceFile = true;
-
- users->showErrorList(_("LinuxDoc"));
}
}
-// Print an error message.
-void Buffer::sgmlError(ParagraphList::iterator pit, int pos,
- string const & message) const
-{
- users->addError(ErrorItem(message, string(), pit->id(), pos, pos));
-}
-
-
void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
{
ofstream ofs(fname.c_str());
<< " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
string preamble = params.preamble;
- const string name = nice ? ChangeExtension(filename_, ".sgml")
+ string const name = nice ? ChangeExtension(filename_, ".sgml")
: fname;
preamble += features.getIncludedFiles(name);
preamble += features.getLyXSGMLEntities();
string item_name;
string command_name;
- users->resetErrorList();
-
ParagraphList::iterator par = paragraphs.begin();
ParagraphList::iterator pend = paragraphs.end();
case LATEX_COMMAND:
if (depth != 0)
- sgmlError(par, 0,
- _("Error: Wrong depth for LatexType Command.\n"));
+ parseError(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
command_name = style->latexname();
sgmlparam = style->latexparam();
c_params = split(sgmlparam, c_depth,'|');
- cmd_depth = lyx::atoi(c_depth);
+ cmd_depth = atoi(c_depth);
if (command_flag) {
if (cmd_depth < command_base) {
// we want this to be true outside previews (for insetexternal)
niceFile = true;
- users->showErrorList(_("DocBook"));
}
if (res == -1) {
Alert::error(_("chktex failure"),
- _("Could not run chktex successfully."));
+ _("Could not run chktex successfully."));
} else if (res > 0) {
// Insert all errors as errors boxes
- ErrorList el (*this, terr);
- users->setErrorList(el);
- users->showErrorList(_("ChkTeX"));
+ parseErrors(*this, terr);
}
users->owner()->busy(false);
// This is also a buffer property (ale)
-void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
+void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
{
/// if this is a child document and the parent is already loaded
/// use the parent's list instead [ale990412]