X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer.C;h=62750128c60941c70bda4896eb53bf3539415296;hb=dacb5be6462e278d769686b7380984b584dd86ac;hp=116253f0b8da5d9b6b9c28a66f2f03d30186aa45;hpb=197273f84066b66369dfd6b2972850223ccbc9f5;p=lyx.git
diff --git a/src/buffer.C b/src/buffer.C
index 116253f0b8..62750128c6 100644
--- a/src/buffer.C
+++ b/src/buffer.C
@@ -84,6 +84,7 @@
#include "support/syscall.h"
#include "support/lyxlib.h"
#include "support/FileInfo.h"
+#include "support/lyxmanip.h"
#include "lyxtext.h"
#include "gettext.h"
#include "language.h"
@@ -104,7 +105,6 @@ using std::pair;
using std::vector;
using std::max;
using std::set;
-using std::istringstream;
// all these externs should eventually be removed.
extern BufferList bufferlist;
@@ -178,7 +178,7 @@ void Buffer::setReadonly(bool flag)
if (read_only != flag) {
read_only = flag;
updateTitles();
- users->owner()->getDialogs()->updateBufferDependent();
+ users->owner()->getDialogs()->updateBufferDependent(false);
}
if (read_only) {
WarnReadonly(filename);
@@ -218,7 +218,7 @@ void Buffer::resetAutosaveTimers() const
}
-void Buffer::fileName(string const & newfile)
+void Buffer::setFileName(string const & newfile)
{
filename = MakeAbsPath(newfile);
filepath = OnlyPath(filename);
@@ -246,15 +246,15 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
bool the_end_read = false;
LyXParagraph * return_par = 0;
- LyXFont font(LyXFont::ALL_INHERIT, params.language_info);
- if (format < 2.16 && params.language == "hebrew")
+ LyXFont font(LyXFont::ALL_INHERIT, params.language);
+ if (format < 2.16 && params.language->lang() == "hebrew")
font.setLanguage(default_language);
// If we are inserting, we cheat and get a token in advance
bool has_token = false;
string pretoken;
- if(!par) {
+ if (!par) {
par = new LyXParagraph;
} else {
users->text->BreakParagraph(users);
@@ -363,8 +363,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
par->footnotekind = footnotekind;
#endif
par->depth = depth;
- font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
- if (format < 2.16 && params.language == "hebrew")
+ font = LyXFont(LyXFont::ALL_INHERIT, params.language);
+ if (format < 2.16 && params.language->lang() == "hebrew")
font.setLanguage(default_language);
#ifndef NEW_INSETS
} else if (token == "\\end_float") {
@@ -379,8 +379,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
pos = 0;
lex.EatLine();
par->layout = LYX_DUMMY_LAYOUT;
- font = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
- if (format < 2.16 && params.language == "hebrew")
+ font = LyXFont(LyXFont::ALL_INHERIT, params.language);
+ if (format < 2.16 && params.language->lang() == "hebrew")
font.setLanguage(default_language);
} else if (token == "\\begin_float") {
int tmpret = lex.FindToken(string_footnotekinds);
@@ -550,7 +550,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
if (tmpret != LYX_LAYOUT_DEFAULT) {
InsetQuotes::quote_language tmpl =
InsetQuotes::EnglishQ;
- switch(tmpret) {
+ switch (tmpret) {
case 0:
tmpl = InsetQuotes::EnglishQ;
break;
@@ -574,7 +574,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
}
} else if (token == "\\quotes_times") {
lex.nextToken();
- switch(lex.GetInteger()) {
+ switch (lex.GetInteger()) {
case 1:
params.quotes_times = InsetQuotes::SingleQ;
break;
@@ -641,7 +641,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
params.columns = lex.GetInteger();
} else if (token == "\\papersides") {
lex.nextToken();
- switch(lex.GetInteger()) {
+ switch (lex.GetInteger()) {
default:
case 1: params.sides = LyXTextClass::OneSide; break;
case 2: params.sides = LyXTextClass::TwoSides; break;
@@ -771,13 +771,16 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
} else if (token == "\\lang") {
lex.next();
string const tok = lex.GetString();
- Languages::iterator lit = languages.find(tok);
- if (lit != languages.end()) {
- font.setLanguage(&(*lit).second);
+ Language const * lang = languages.getLanguage(tok);
+ if (lang) {
+ font.setLanguage(lang);
} else {
- font.setLanguage(params.language_info);
+ 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()));
@@ -879,7 +882,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
++pos;
} else if (token == "\\LyXTable") {
- Inset * inset = new InsetTabular(this);
+ Inset * inset = new InsetTabular(*this);
inset->Read(this, lex);
par->InsertInset(pos, inset, font);
++pos;
@@ -918,7 +921,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
"Inserting as text.");
string::const_iterator cit = token.begin();
string::const_iterator end = token.end();
- for(; cit != end; ++cit) {
+ for (; cit != end; ++cit) {
par->InsertChar(pos, (*cit), font);
++pos;
}
@@ -957,7 +960,7 @@ void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
} else if (inscmd.getCmdName() == "index") {
inset = new InsetIndex(inscmd);
} else if (inscmd.getCmdName() == "include") {
- inset = new InsetInclude(inscmd, this);
+ inset = new InsetInclude(inscmd, *this);
} else if (inscmd.getCmdName() == "label") {
inset = new InsetLabel(inscmd);
} else if (inscmd.getCmdName() == "url"
@@ -970,7 +973,7 @@ void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
|| inscmd.getCmdName() == "prettyref") {
if (!inscmd.getOptions().empty()
|| !inscmd.getContents().empty()) {
- inset = new InsetRef(inscmd);
+ inset = new InsetRef(inscmd, *this);
}
} else if (inscmd.getCmdName() == "tableofcontents"
|| inscmd.getCmdName() == "listofalgorithms"
@@ -980,7 +983,7 @@ void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
} else if (inscmd.getCmdName() == "printindex") {
inset = new InsetPrintIndex(inscmd);
} else if (inscmd.getCmdName() == "lyxparent") {
- inset = new InsetParent(inscmd, this);
+ inset = new InsetParent(inscmd, *this);
}
} else {
if (tmptok == "Quotes") {
@@ -992,16 +995,16 @@ void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
} else if (tmptok == "Formula") {
inset = new InsetFormula;
} else if (tmptok == "Figure") {
- inset = new InsetFig(100, 100, this);
+ inset = new InsetFig(100, 100, *this);
} else if (tmptok == "Info") {
inset = new InsetInfo;
} else if (tmptok == "Include") {
InsetCommandParams p( "Include" );
- inset = new InsetInclude(p, this);
+ inset = new InsetInclude(p, *this);
} else if (tmptok == "ERT") {
inset = new InsetERT;
} else if (tmptok == "Tabular") {
- inset = new InsetTabular(this);
+ inset = new InsetTabular(*this);
} else if (tmptok == "Text") {
inset = new InsetText;
} else if (tmptok == "Foot") {
@@ -1042,15 +1045,14 @@ bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
if (token == "\\lyxformat") { // the first token _must_ be...
lex.EatLine();
format = lex.GetFloat();
- if (format > 1) {
+ if (format > 1.0) {
if (LYX_FORMAT - format > 0.05) {
-
- printf(_("Warning: need lyxformat %.2f but found %.2f\n"),
- LYX_FORMAT, format);
+ lyxerr << fmt(_("Warning: need lyxformat %.2f but found %.2f"),
+ LYX_FORMAT, format) << endl;
}
if (format - LYX_FORMAT > 0.05) {
- printf(_("ERROR: need lyxformat %.2f but found %.2f\n"),
- LYX_FORMAT, format);
+ lyxerr << fmt(_("ERROR: need lyxformat %.2f but found %.2f"),
+ LYX_FORMAT, format) << endl;
}
bool the_end = readLyXformat2(lex, par);
// Formats >= 2.13 support "\the_end" marker
@@ -1066,7 +1068,7 @@ bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
// We simulate a safe reading anyways to allow
// users to take the chance... (Asger)
return true;
- } // format < 1
+ } // format < 1.0
else {
WriteAlert(_("ERROR!"),
_("Old LyX file format found. "
@@ -1235,9 +1237,31 @@ bool Buffer::writeFile(string const & fname, bool flag) const
// Write marker that shows file is complete
ofs << "\n\\the_end" << endl;
+
ofs.close();
+
// how to check if close went ok?
- return true;
+ // Following is an attempt... (BE 20001011)
+
+ // 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
+ }
+
+ return status;
}
@@ -1265,7 +1289,7 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
return;
}
- string const fname1 = TmpFileName();
+ string const fname1 = lyx::tempName(); //TmpFileName();
LyXParagraph * par = paragraph;
while (par) {
int noparbreak = 0;
@@ -1360,15 +1384,15 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
}
LyXFont font1 =
- LyXFont(LyXFont::ALL_INHERIT, params.language_info);
+ LyXFont(LyXFont::ALL_INHERIT, params.language);
actcell = 0;
for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
if (!i && !footnoteflag && !noparbreak){
ofs << "\n\n";
- for(j = 0; j < depth; ++j)
+ for (j = 0; j < depth; ++j)
ofs << " ";
currlinelen = depth * 2;
- switch(ltype) {
+ switch (ltype) {
case 0: /* Standard */
case 4: /* (Sub)Paragraph */
case 5: /* Description */
@@ -1387,7 +1411,7 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
break;
}
if (ltype_depth > depth) {
- for(j = ltype_depth - 1; j > depth; --j)
+ for (j = ltype_depth - 1; j > depth; --j)
ofs << " ";
currlinelen += (ltype_depth-depth)*2;
}
@@ -1415,11 +1439,11 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
break;
case LyXParagraph::META_NEWLINE:
ofs << "\n";
- for(j = 0; j < depth; ++j)
+ for (j = 0; j < depth; ++j)
ofs << " ";
currlinelen = depth * 2;
if (ltype_depth > depth) {
- for(j = ltype_depth;
+ for (j = ltype_depth;
j > depth; --j)
ofs << " ";
currlinelen += (ltype_depth - depth) * 2;
@@ -1435,11 +1459,11 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
if (currlinelen > linelen - 10
&& c == ' ' && i + 2 < par->size()) {
ofs << "\n";
- for(j = 0; j < depth; ++j)
+ for (j = 0; j < depth; ++j)
ofs << " ";
currlinelen = depth * 2;
if (ltype_depth > depth) {
- for(j = ltype_depth;
+ for (j = ltype_depth;
j > depth; --j)
ofs << " ";
currlinelen += (ltype_depth-depth)*2;
@@ -1568,24 +1592,31 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
#endif
}
- font1 = LyXFont(LyXFont::ALL_INHERIT, params.language_info);
+ font1 = LyXFont(LyXFont::ALL_INHERIT, params.language);
for (LyXParagraph::size_type i = 0; i < par->size(); ++i) {
if (!i && !footnoteflag && !noparbreak){
- buffer << "\n\n";
- for(char j = 0; j < depth; ++j)
+ if (linelen > 0)
+ buffer << "\n\n";
+ for (char j = 0; j < depth; ++j)
buffer << " ";
currlinelen = depth * 2;
- switch(ltype) {
+ switch (ltype) {
case 0: /* Standard */
case 4: /* (Sub)Paragraph */
case 5: /* Description */
break;
case 6: /* Abstract */
- buffer << "Abstract\n\n";
+ if (linelen > 0)
+ buffer << "Abstract\n\n";
+ else
+ buffer << "Abstract: ";
break;
case 7: /* Bibliography */
if (!ref_printed) {
- buffer << "References\n\n";
+ if (linelen > 0)
+ buffer << "References\n\n";
+ else
+ buffer << "References: ";
ref_printed = true;
}
break;
@@ -1594,7 +1625,7 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
break;
}
if (ltype_depth > depth) {
- for(char j = ltype_depth - 1; j > depth; --j)
+ for (char j = ltype_depth - 1; j > depth; --j)
buffer << " ";
currlinelen += (ltype_depth-depth)*2;
}
@@ -1616,7 +1647,7 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
if ((inset = par->GetInset(i))) {
if (!inset->Ascii(this, buffer)) {
string dummy;
- string s = rsplit(buffer.str(),
+ string s = rsplit(buffer.str().c_str(),
dummy, '\n');
currlinelen += s.length();
} else {
@@ -1626,12 +1657,14 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
}
break;
case LyXParagraph::META_NEWLINE:
- buffer << "\n";
- for(char j = 0; j < depth; ++j)
- buffer << " ";
+ if (linelen > 0) {
+ buffer << "\n";
+ for (char j = 0; j < depth; ++j)
+ buffer << " ";
+ }
currlinelen = depth * 2;
if (ltype_depth > depth) {
- for(char j = ltype_depth;
+ for (char j = ltype_depth;
j > depth; --j)
buffer << " ";
currlinelen += (ltype_depth - depth) * 2;
@@ -1648,11 +1681,11 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
(c == ' ') && ((i + 2) < par->size()))
{
buffer << "\n";
- for(char j = 0; j < depth; ++j)
+ for (char j = 0; j < depth; ++j)
buffer << " ";
currlinelen = depth * 2;
if (ltype_depth > depth) {
- for(char j = ltype_depth;
+ for (char j = ltype_depth;
j > depth; --j)
buffer << " ";
currlinelen += (ltype_depth-depth)*2;
@@ -1665,7 +1698,7 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
break;
}
}
- return buffer.str();
+ return buffer.str().c_str();
}
@@ -1819,17 +1852,21 @@ void Buffer::makeLaTeXFile(string const & fname,
// language should be a parameter to \documentclass
bool use_babel = false;
- if (params.language_info->lang() == "hebrew") // This seems necessary
+ if (params.language->babel() == "hebrew") // This seems necessary
features.UsedLanguages.insert(default_language);
- if (params.language != "default" ||
- !features.UsedLanguages.empty() ) {
+#ifdef DO_USE_DEFAULT_LANGUAGE
+ if (params.language->lang() != "default" ||
+ !features.UsedLanguages.empty()) {
+#endif
use_babel = true;
for (LaTeXFeatures::LanguageList::const_iterator cit =
features.UsedLanguages.begin();
cit != features.UsedLanguages.end(); ++cit)
- options += (*cit)->lang() + ",";
- options += params.language_info->lang() + ',';
+ options += (*cit)->babel() + ",";
+ options += params.language->babel() + ',';
+#ifdef DO_USE_DEFAULT_LANGUAGE
}
+#endif
// the user-defined options
if (!params.options.empty()) {
@@ -1861,7 +1898,7 @@ void Buffer::makeLaTeXFile(string const & fname,
if (params.inputenc == "auto") {
string const doc_encoding =
- params.language_info->encoding()->LatexName();
+ params.language->encoding()->LatexName();
// Create a list with all the input encodings used
// in the document
@@ -1873,9 +1910,8 @@ void Buffer::makeLaTeXFile(string const & fname,
encodings.insert((*it)->encoding()->LatexName());
ofs << "\\usepackage[";
- for (set