X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer.C;h=62750128c60941c70bda4896eb53bf3539415296;hb=dacb5be6462e278d769686b7380984b584dd86ac;hp=02e54b679439afaa60ca6a904e06f42d8a9a7da0;hpb=e7401bd8f2310213b4b765c01676459f37adb530;p=lyx.git
diff --git a/src/buffer.C b/src/buffer.C
index 02e54b6794..62750128c6 100644
--- a/src/buffer.C
+++ b/src/buffer.C
@@ -105,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;
@@ -179,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);
@@ -219,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);
@@ -255,7 +254,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
bool has_token = false;
string pretoken;
- if(!par) {
+ if (!par) {
par = new LyXParagraph;
} else {
users->text->BreakParagraph(users);
@@ -551,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;
@@ -575,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;
@@ -642,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;
@@ -922,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;
}
@@ -1046,7 +1045,7 @@ 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) {
lyxerr << fmt(_("Warning: need lyxformat %.2f but found %.2f"),
LYX_FORMAT, format) << endl;
@@ -1069,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. "
@@ -1238,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;
}
@@ -1268,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;
@@ -1368,10 +1389,10 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
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 */
@@ -1390,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;
}
@@ -1418,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;
@@ -1438,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;
@@ -1576,10 +1597,10 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
if (!i && !footnoteflag && !noparbreak){
if (linelen > 0)
buffer << "\n\n";
- for(char j = 0; j < depth; ++j)
+ 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 */
@@ -1604,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;
}
@@ -1626,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 {
@@ -1638,12 +1659,12 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
case LyXParagraph::META_NEWLINE:
if (linelen > 0) {
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;
@@ -1660,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;
@@ -1677,7 +1698,7 @@ string const Buffer::asciiParagraph(LyXParagraph const * par,
break;
}
}
- return buffer.str();
+ return buffer.str().c_str();
}
@@ -1835,7 +1856,7 @@ void Buffer::makeLaTeXFile(string const & fname,
features.UsedLanguages.insert(default_language);
#ifdef DO_USE_DEFAULT_LANGUAGE
if (params.language->lang() != "default" ||
- !features.UsedLanguages.empty() ) {
+ !features.UsedLanguages.empty()) {
#endif
use_babel = true;
for (LaTeXFeatures::LanguageList::const_iterator cit =
@@ -1889,8 +1910,8 @@ void Buffer::makeLaTeXFile(string const & fname,
encodings.insert((*it)->encoding()->LatexName());
ofs << "\\usepackage[";
- copy(encodings.begin(), encodings.end(),
- ostream_iterator(ofs, ","));
+ std::copy(encodings.begin(), encodings.end(),
+ std::ostream_iterator(ofs, ","));
ofs << doc_encoding << "]{inputenc}\n";
texrow.newline();
} else if (params.inputenc != "default") {
@@ -2351,7 +2372,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
LaTeXFeatures features(params, tclass.numLayouts());
validate(features);
- //if(nice)
+ //if (nice)
tex_code_break_column = lyxrc.ascii_linelen;
//else
//tex_code_break_column = 0;
@@ -2368,7 +2389,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
<< params.preamble << sgml_includedfiles << " \n]>\n\n";
}
- if(params.options.empty())
+ if (params.options.empty())
sgmlOpenTag(ofs, 0, top_element);
else {
string top = top_element;
@@ -2413,11 +2434,11 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
// write opening SGML tags
switch (style.latextype) {
case LATEX_PARAGRAPH:
- if(depth == par->depth
+ if (depth == par->depth
&& !environment_stack[depth].empty()) {
sgmlCloseTag(ofs, depth, environment_stack[depth]);
environment_stack[depth].erase();
- if(depth)
+ if (depth)
--depth;
else
ofs << "
";
@@ -2456,7 +2477,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
environment_stack[depth].erase();
}
if (environment_stack[depth] != style.latexname()) {
- if(depth == 0) {
+ if (depth == 0) {
string const temp = "p";
sgmlOpenTag(ofs, depth, temp);
}
@@ -2464,11 +2485,11 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
sgmlOpenTag(ofs, depth,
environment_stack[depth]);
}
- if(style.latextype == LATEX_ENVIRONMENT) break;
+ if (style.latextype == LATEX_ENVIRONMENT) break;
desc_on = (style.labeltype == LABEL_MANUAL);
- if(desc_on)
+ if (desc_on)
item_name = "tag";
else
item_name = "item";
@@ -2494,7 +2515,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
ofs << "\n";
// write closing SGML tags
- switch(style.latextype) {
+ switch (style.latextype) {
case LATEX_COMMAND:
case LATEX_ENVIRONMENT:
case LATEX_ITEM_ENVIRONMENT:
@@ -2506,10 +2527,10 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
}
// Close open tags
- for(; depth > 0; --depth)
+ for (; depth > 0; --depth)
sgmlCloseTag(ofs, depth, environment_stack[depth]);
- if(!environment_stack[depth].empty())
+ if (!environment_stack[depth].empty())
sgmlCloseTag(ofs, depth, environment_stack[depth]);
if (!body_only) {
@@ -2558,7 +2579,7 @@ void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
SimpleDocBookOnePar(os, extra_par, tpar,
desc_on, depth + 2);
sgmlCloseTag(os, depth+1, inner_tag);
- if(!extra_par.empty())
+ if (!extra_par.empty())
os << extra_par;
}
}
@@ -2657,9 +2678,9 @@ void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
par = par->next;
}
os << tmp_par;
- if(!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
- if(!extra_par.empty()) os << extra_par;
- if(!tag.empty()) sgmlCloseTag(os, depth, tag);
+ if (!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
+ if (!extra_par.empty()) os << extra_par;
+ if (!tag.empty()) sgmlCloseTag(os, depth, tag);
}
#endif
@@ -2776,7 +2797,7 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
LyXFont const font2 = par->getFont(params, i);
if (font1.family() != font2.family()) {
- switch(family_type) {
+ switch (family_type) {
case 0:
if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
push_tag(os, "tt", stack_num, stack);
@@ -2820,7 +2841,7 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
// handle italic and slanted fonts
if (font1.shape() != font2.shape()) {
- switch(shape_type) {
+ switch (shape_type) {
case 0:
if (font2.shape() == LyXFont::ITALIC_SHAPE) {
push_tag(os, "it", stack_num, stack);
@@ -2910,7 +2931,7 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
}
// resets description flag correctly
- switch(desc_on){
+ switch (desc_on){
case 1:
// not closed...
linux_doc_line_break(os, char_line_count, 6);
@@ -2965,7 +2986,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
LaTeXFeatures features(params, tclass.numLayouts());
validate(features);
- //if(nice)
+ //if (nice)
tex_code_break_column = lyxrc.ascii_linelen;
//else
//tex_code_break_column = 0;
@@ -2978,7 +2999,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
texrow.reset();
- if(!only_body) {
+ if (!only_body) {
string sgml_includedfiles=features.getIncludedFiles();
ofs << "\n\n";
- if(params.options.empty())
+ if (params.options.empty())
sgmlOpenTag(ofs, 0, top_element);
else {
string top = top_element;
@@ -3010,12 +3031,12 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
par->layout);
// environment tag closing
- for( ; depth > par->depth; --depth) {
- if(environment_inner[depth] != "!-- --") {
+ for (; depth > par->depth; --depth) {
+ if (environment_inner[depth] != "!-- --") {
item_name= "listitem";
sgmlCloseTag(ofs, command_depth + depth,
item_name);
- if( environment_inner[depth] == "varlistentry")
+ if (environment_inner[depth] == "varlistentry")
sgmlCloseTag(ofs, depth+command_depth,
environment_inner[depth]);
}
@@ -3025,14 +3046,14 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
environment_inner[depth].erase();
}
- if(depth == par->depth
+ if (depth == par->depth
&& environment_stack[depth] != style.latexname()
&& !environment_stack[depth].empty()) {
- if(environment_inner[depth] != "!-- --") {
+ if (environment_inner[depth] != "!-- --") {
item_name= "listitem";
sgmlCloseTag(ofs, command_depth+depth,
item_name);
- if( environment_inner[depth] == "varlistentry")
+ if (environment_inner[depth] == "varlistentry")
sgmlCloseTag(ofs,
depth + command_depth,
environment_inner[depth]);
@@ -3046,9 +3067,9 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
// Write opening SGML tags.
- switch(style.latextype) {
+ switch (style.latextype) {
case LATEX_PARAGRAPH:
- if(style.latexname() != "dummy")
+ if (style.latexname() != "dummy")
sgmlOpenTag(ofs, depth+command_depth,
style.latexname());
break;
@@ -3066,18 +3087,18 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
cmd_depth= lyx::atoi(c_depth);
- if(command_flag) {
- if(cmd_depth= command_base; --j)
- if(!command_stack[j].empty())
+ if (!command_stack[j].empty())
sgmlCloseTag(ofs, j, command_stack[j]);
command_depth= command_base= cmd_depth;
- } else if(cmd_depth <= command_depth) {
- for(int j = command_depth;
+ } else if (cmd_depth <= command_depth) {
+ for (int j = command_depth;
j >= cmd_depth; --j)
- if(!command_stack[j].empty())
+ if (!command_stack[j].empty())
sgmlCloseTag(ofs, j, command_stack[j]);
command_depth= cmd_depth;
} else
@@ -3119,7 +3140,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
sgmlOpenTag(ofs, depth + command_depth,
environment_stack[depth]);
} else {
- if(environment_inner[depth] != "!-- --") {
+ if (environment_inner[depth] != "!-- --") {
item_name= "listitem";
sgmlCloseTag(ofs,
command_depth + depth,
@@ -3131,8 +3152,8 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
}
- if(style.latextype == LATEX_ENVIRONMENT) {
- if(!style.latexparam().empty())
+ if (style.latextype == LATEX_ENVIRONMENT) {
+ if (!style.latexparam().empty())
sgmlOpenTag(ofs, depth + command_depth,
style.latexparam());
break;
@@ -3140,7 +3161,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
desc_on = (style.labeltype == LABEL_MANUAL);
- if(desc_on)
+ if (desc_on)
environment_inner[depth]= "varlistentry";
else
environment_inner[depth]= "listitem";
@@ -3148,7 +3169,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
sgmlOpenTag(ofs, depth + 1 + command_depth,
environment_inner[depth]);
- if(desc_on) {
+ if (desc_on) {
item_name= "term";
sgmlOpenTag(ofs, depth + 1 + command_depth,
item_name);
@@ -3179,23 +3200,23 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
#endif
string end_tag;
// write closing SGML tags
- switch(style.latextype) {
+ switch (style.latextype) {
case LATEX_COMMAND:
end_tag = "title";
sgmlCloseTag(ofs, depth + command_depth, end_tag);
break;
case LATEX_ENVIRONMENT:
- if(!style.latexparam().empty())
+ if (!style.latexparam().empty())
sgmlCloseTag(ofs, depth + command_depth,
style.latexparam());
break;
case LATEX_ITEM_ENVIRONMENT:
- if(desc_on == 1) break;
+ if (desc_on == 1) break;
end_tag= "para";
sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
break;
case LATEX_PARAGRAPH:
- if(style.latexname() != "dummy")
+ if (style.latexname() != "dummy")
sgmlCloseTag(ofs, depth + command_depth,
style.latexname());
break;
@@ -3207,13 +3228,13 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
// Close open tags
- for(; depth >= 0; --depth) {
- if(!environment_stack[depth].empty()) {
- if(environment_inner[depth] != "!-- --") {
+ for (; depth >= 0; --depth) {
+ if (!environment_stack[depth].empty()) {
+ if (environment_inner[depth] != "!-- --") {
item_name= "listitem";
sgmlCloseTag(ofs, command_depth + depth,
item_name);
- if( environment_inner[depth] == "varlistentry")
+ if (environment_inner[depth] == "varlistentry")
sgmlCloseTag(ofs, depth + command_depth,
environment_inner[depth]);
}
@@ -3223,8 +3244,8 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
}
- for(int j = command_depth; j >= command_base; --j)
- if(!command_stack[j].empty())
+ for (int j = command_depth; j >= command_base; --j)
+ if (!command_stack[j].empty())
sgmlCloseTag(ofs, j, command_stack[j]);
if (!only_body) {
@@ -3239,7 +3260,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
LyXParagraph * par, int & desc_on,
- int depth)
+ int depth) const
{
bool emph_flag = false;
@@ -3256,7 +3277,7 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
int char_line_count = depth;
- if(!style.free_spacing)
+ if (!style.free_spacing)
for (int j = 0; j < depth; ++j)
os << ' ';
@@ -3294,9 +3315,9 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
// and title should come first
// desc_on == 4
//
- if(desc_on!= 3 || i!= 0) {
- if(!tmp_out.empty() && tmp_out[0] == '@') {
- if(desc_on == 4)
+ if (desc_on!= 3 || i!= 0) {
+ if (!tmp_out.empty() && tmp_out[0] == '@') {
+ if (desc_on == 4)
extra += frontStrip(tmp_out, '@');
else
os << frontStrip(tmp_out, '@');
@@ -3339,7 +3360,7 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
}
// resets description flag correctly
- switch(desc_on){
+ switch (desc_on){
case 1:
// not closed...
os << "";
@@ -3693,7 +3714,7 @@ void Buffer::resizeInsets(BufferView * bv)
{
/// then remove all LyXText in text-insets
LyXParagraph * par = paragraph;
- for(; par; par = par->next) {
+ for (; par; par = par->next) {
par->resizeInsetsLyXText(bv);
}
}