X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer.C;h=67d895c460b4c7c1058202fdde62755e360440dd;hb=00d24ec87650e4ac7db77ad54cb4aa2f688100f3;hp=ff79a73d823f574347c4e7cf0229ed88c2ea61c2;hpb=d46b4d4360ffb10a06ae0dcd508de8f42dc9affd;p=lyx.git
diff --git a/src/buffer.C b/src/buffer.C
index ff79a73d82..67d895c460 100644
--- a/src/buffer.C
+++ b/src/buffer.C
@@ -4,9 +4,9 @@
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
- * Copyright 1995-2000 The LyX Team.
+ * Copyright 1995-2001 The LyX Team.
*
- * This file is Copyright 1996-1999
+ * This file is Copyright 1996-2001
* Lars Gullik Bjønnes
*
* ======================================================
@@ -16,8 +16,12 @@
#include
#include
+#include
";
@@ -2448,7 +2630,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
case LATEX_COMMAND:
if (depth!= 0)
- LinuxDocError(par, 0,
+ linuxDocError(par, 0,
_("Error : Wrong depth for"
" LatexType Command.\n"));
@@ -2464,32 +2646,33 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
case LATEX_ENVIRONMENT:
case LATEX_ITEM_ENVIRONMENT:
- if (depth == par->depth
- && environment_stack[depth] != style.latexname()
- && !environment_stack[depth].empty()) {
-
+ if (depth == par->params().depth()
+ && environment_stack[depth] != style.latexname()) {
sgmlCloseTag(ofs, depth,
environment_stack[depth]);
environment_stack[depth].erase();
}
- if (depth < par->depth) {
- depth = par->depth;
+ if (depth < par->params().depth()) {
+ depth = par->params().depth();
environment_stack[depth].erase();
}
if (environment_stack[depth] != style.latexname()) {
- if(depth == 0) {
- string const temp = "p";
- sgmlOpenTag(ofs, depth, temp);
+ if (depth == 0) {
+ sgmlOpenTag(ofs, depth, "p");
}
+ sgmlOpenTag(ofs, depth, style.latexname());
+
+ if (environment_stack.size() == depth + 1)
+ environment_stack.push_back("!-- --");
environment_stack[depth] = style.latexname();
- sgmlOpenTag(ofs, depth,
- environment_stack[depth]);
}
- if(style.latextype == LATEX_ENVIRONMENT) break;
- desc_on = (style.labeltype == LABEL_MANUAL);
+ if (style.latexparam() == "CDATA")
+ ofs << "next;
-#ifndef NEW_INSETS
- linuxDocHandleFootnote(ofs, par, depth);
- }
- while(par && par->IsDummy());
-#endif
+ par = par->next();
ofs << "\n";
// write closing SGML tags
- switch(style.latextype) {
+ switch (style.latextype) {
case LATEX_COMMAND:
+ break;
case LATEX_ENVIRONMENT:
case LATEX_ITEM_ENVIRONMENT:
+ if (style.latexparam() == "CDATA")
+ ofs << "]]>";
break;
default:
sgmlCloseTag(ofs, depth, style.latexname());
@@ -2527,11 +2705,8 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
}
// Close open tags
- for(; depth > 0; --depth)
- sgmlCloseTag(ofs, depth, environment_stack[depth]);
-
- if(!environment_stack[depth].empty())
- sgmlCloseTag(ofs, depth, environment_stack[depth]);
+ for (int i=depth; i >= 0; --i)
+ sgmlCloseTag(ofs, depth, environment_stack[i]);
if (!body_only) {
ofs << "\n\n";
@@ -2543,368 +2718,254 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
}
-#ifndef NEW_INSETS
-void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
- int depth)
+void Buffer::docBookHandleCaption(ostream & os, string & inner_tag,
+ Paragraph::depth_type depth, int desc_on,
+ Paragraph * & par)
{
- string const tag = "footnote";
-
- while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
- sgmlOpenTag(os, depth + 1, tag);
- SimpleLinuxDocOnePar(os, par, 0, depth + 1);
- sgmlCloseTag(os, depth + 1, tag);
- par = par->next;
- }
-}
-#endif
-
-
-void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
- int depth, int desc_on,
- LyXParagraph * & par)
-{
- LyXParagraph * tpar = par;
+ Paragraph * tpar = par;
while (tpar
-#ifndef NEW_INSETS
- && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
-#endif
&& (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
- "Caption").second))
- tpar = tpar->next;
+ "Caption").second))
+ tpar = tpar->next();
+
if (tpar &&
tpar->layout == textclasslist.NumberOfLayout(params.textclass,
"Caption").second) {
sgmlOpenTag(os, depth + 1, inner_tag);
string extra_par;
- SimpleDocBookOnePar(os, extra_par, tpar,
+ 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;
}
}
-#ifndef NEW_INSETS
-void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
- int depth)
-{
- string tag, inner_tag;
- string tmp_par, extra_par;
- bool inner_span = false;
- int desc_on = 4;
-
- // Someone should give this enum a proper name (Lgb)
- enum SOME_ENUM {
- NO_ONE,
- FOOTNOTE_LIKE,
- MARGIN_LIKE,
- FIG_LIKE,
- TAB_LIKE
- };
- SOME_ENUM last = NO_ONE;
- SOME_ENUM present = FOOTNOTE_LIKE;
-
- while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
- if (last == present) {
- if (inner_span) {
- if (!tmp_par.empty()) {
- os << tmp_par;
- tmp_par.erase();
- sgmlCloseTag(os, depth + 1, inner_tag);
- sgmlOpenTag(os, depth + 1, inner_tag);
- }
- } else {
- os << "\n";
- }
- } else {
- 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);
- extra_par.erase();
-
- switch (par->footnotekind) {
- case LyXParagraph::FOOTNOTE:
- case LyXParagraph::ALGORITHM:
- tag = "footnote";
- inner_tag = "para";
- present = FOOTNOTE_LIKE;
- inner_span = true;
- break;
- case LyXParagraph::MARGIN:
- tag = "sidebar";
- inner_tag = "para";
- present = MARGIN_LIKE;
- inner_span = true;
- break;
- case LyXParagraph::FIG:
- case LyXParagraph::WIDE_FIG:
- tag = "figure";
- inner_tag = "title";
- present = FIG_LIKE;
- inner_span = false;
- break;
- case LyXParagraph::TAB:
- case LyXParagraph::WIDE_TAB:
- tag = "table";
- inner_tag = "title";
- present = TAB_LIKE;
- inner_span = false;
- break;
- }
- sgmlOpenTag(os, depth, tag);
- if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
- DocBookHandleCaption(os, inner_tag, depth,
- desc_on, par);
- inner_tag.erase();
- } else {
- sgmlOpenTag(os, depth + 1, inner_tag);
- }
- }
- // ignore all caption here, we processed them above!!!
- if (par->layout != textclasslist
- .NumberOfLayout(params.textclass,
- "Caption").second) {
- std::ostringstream ost;
- SimpleDocBookOnePar(ost, extra_par, par,
- desc_on, depth + 2);
- tmp_par += ost.str().c_str();
- }
- tmp_par = frontStrip(strip(tmp_par));
+// checks, if newcol chars should be put into this line
+// writes newline, if necessary.
+namespace {
- last = present;
- par = par->next;
+void linux_doc_line_break(ostream & os, string::size_type & colcount,
+ string::size_type newcol)
+{
+ colcount += newcol;
+ if (colcount > lyxrc.ascii_linelen) {
+ os << "\n";
+ colcount = newcol; // assume write after this call
}
- 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);
}
-#endif
+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) {
+ 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";
+ }
+ return "";
+}
-// push a tag in a style stack
-void Buffer::push_tag(ostream & os, string const & tag,
- int & pos, char stack[5][3])
-{
-#ifdef WITH_WARNINGS
-#warning Use a real stack! (Lgb)
-#endif
- // pop all previous tags
- for (int j = pos; j >= 0; --j)
- os << "" << stack[j] << ">";
-
- // add new tag
- sprintf(stack[++pos], "%s", tag.c_str());
- // push all tags
- for (int i = 0; i <= pos; ++i)
- os << "<" << stack[i] << ">";
+inline
+void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
+{
+ p1 = static_cast(p1 | p2);
}
-void Buffer::pop_tag(ostream & os, string const & tag,
- int & pos, char stack[5][3])
+inline
+void reset(PAR_TAG & p1, PAR_TAG const & p2)
{
-#ifdef WITH_WARNINGS
-#warning Use a real stack! (Lgb)
-#endif
- // Please, Lars, do not remove the global variable. I already
- // had to reintroduce it twice! (JMarc)
- int j;
-
- // pop all tags till specified one
- for (j = pos; (j >= 0) && (strcmp(stack[j], tag.c_str())); --j)
- os << "" << stack[j] << ">";
-
- // closes the tag
- os << "" << tag << ">";
-
- // push all tags, but the specified one
- for (j = j + 1; j <= pos; ++j) {
- os << "<" << stack[j] << ">";
- strcpy(stack[j-1], stack[j]);
- }
- --pos;
+ p1 = static_cast( p1 & ~p2);
}
+} // namespace anon
-// Handle internal paragraph parsing -- layout already processed.
-// checks, if newcol chars should be put into this line
-// writes newline, if necessary.
-static
-void linux_doc_line_break(ostream & os, string::size_type & colcount,
- string::size_type newcol)
-{
- colcount += newcol;
- if (colcount > lyxrc.ascii_linelen) {
- os << "\n";
- colcount = newcol; // assume write after this call
- }
-}
-void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
- int desc_on, int /*depth*/)
+// Handle internal paragraph parsing -- layout already processed.
+void Buffer::simpleLinuxDocOnePar(ostream & os,
+ Paragraph * par,
+ Paragraph::depth_type /*depth*/)
{
- LyXFont font1;
- char c;
- Inset * inset;
- LyXParagraph::size_type main_body;
- int j;
LyXLayout const & style = textclasslist.Style(params.textclass,
- par->GetLayout());
-
- char family_type = 0; // family font flag
- bool is_bold = false; // series font flag
- char shape_type = 0; // shape font flag
- bool is_em = false; // emphasis (italic) font flag
-
- int stack_num = -1; // style stack position
- // Can this be rewritten to use a std::stack, please. (Lgb)
- char stack[5][3]; // style stack
+ par->getLayout());
string::size_type char_line_count = 5; // Heuristic choice ;-)
- if (style.labeltype != LABEL_MANUAL)
- main_body = 0;
- else
- main_body = par->BeginningOfMainBody();
-
// gets paragraph main font
- if (main_body > 0)
- font1 = style.labelfont;
- else
- font1 = style.font;
+ LyXFont font_old;
+ bool desc_on;
+ if (style.labeltype == LABEL_MANUAL) {
+ font_old = style.labelfont;
+ desc_on = true;
+ } else {
+ font_old = style.font;
+ desc_on = false;
+ }
-
+ 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;
+
+ stack tag_state;
// parsing main loop
- for (LyXParagraph::size_type i = 0;
- i < par->size(); ++i) {
+ for (Paragraph::size_type i = 0; i < par->size(); ++i) {
- // handle quote tag
- if (i == main_body
-#ifndef NEW_INSETS
- && !par->IsDummy()
-#endif
- ) {
- if (main_body > 0)
- font1 = style.font;
- }
+ PAR_TAG tag_close = NONE;
+ list < PAR_TAG > tag_open;
- LyXFont const font2 = par->getFont(params, i);
+ LyXFont const font = par->getFont(params, i);
- if (font1.family() != font2.family()) {
- switch(family_type) {
- case 0:
- if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
- push_tag(os, "tt", stack_num, stack);
- family_type = 1;
- }
- else if (font2.family() == LyXFont::SANS_FAMILY) {
- push_tag(os, "sf", stack_num, stack);
- family_type = 2;
- }
+ if (font_old.family() != font.family()) {
+ switch (family_type) {
+ case LyXFont::SANS_FAMILY:
+ tag_close |= SF;
break;
- case 1:
- pop_tag(os, "tt", stack_num, stack);
- if (font2.family() == LyXFont::SANS_FAMILY) {
- push_tag(os, "sf", stack_num, stack);
- family_type = 2;
- } else {
- family_type = 0;
- }
+ case LyXFont::TYPEWRITER_FAMILY:
+ tag_close |= TT;
+ 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:
break;
- case 2:
- pop_tag(os, "sf", stack_num, stack);
- if (font2.family() == LyXFont::TYPEWRITER_FAMILY) {
- push_tag(os, "tt", stack_num, stack);
- family_type = 1;
- } else {
- family_type = 0;
- }
}
}
- // handle bold face
- if (font1.series() != font2.series()) {
- if (font2.series() == LyXFont::BOLD_SERIES) {
- push_tag(os, "bf", stack_num, stack);
- is_bold = true;
- } else if (is_bold) {
- pop_tag(os, "bf", stack_num, stack);
- is_bold = false;
+ if (font_old.series() != font.series()) {
+ switch (series_type) {
+ case LyXFont::BOLD_SERIES:
+ tag_close |= BF;
+ break;
+ default:
+ break;
}
+
+ series_type = font.series();
+
+ switch (series_type) {
+ case LyXFont::BOLD_SERIES:
+ tag_open.push_back(BF);
+ break;
+ default:
+ break;
+ }
+
}
- // handle italic and slanted fonts
- if (font1.shape() != font2.shape()) {
- switch(shape_type) {
- case 0:
- if (font2.shape() == LyXFont::ITALIC_SHAPE) {
- push_tag(os, "it", stack_num, stack);
- shape_type = 1;
- } else if (font2.shape() == LyXFont::SLANTED_SHAPE) {
- push_tag(os, "sl", stack_num, stack);
- shape_type = 2;
- }
+ if (font_old.shape() != font.shape()) {
+ switch (shape_type) {
+ case LyXFont::ITALIC_SHAPE:
+ tag_close |= IT;
break;
- case 1:
- pop_tag(os, "it", stack_num, stack);
- if (font2.shape() == LyXFont::SLANTED_SHAPE) {
- push_tag(os, "sl", stack_num, stack);
- shape_type = 2;
- } else {
- shape_type = 0;
- }
+ case LyXFont::SLANTED_SHAPE:
+ tag_close |= SL;
+ 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:
break;
- case 2:
- pop_tag(os, "sl", stack_num, stack);
- if (font2.shape() == LyXFont::ITALIC_SHAPE) {
- push_tag(os, "it", stack_num, stack);
- shape_type = 1;
- } else {
- shape_type = 0;
- }
}
}
// handle tag
- if (font1.emph() != font2.emph()) {
- if (font2.emph() == LyXFont::ON) {
- push_tag(os, "em", stack_num, stack);
+ if (font_old.emph() != font.emph()) {
+ if (font.emph() == LyXFont::ON) {
+ tag_open.push_back(EM);
is_em = true;
- } else if (is_em) {
- pop_tag(os, "em", stack_num, stack);
+ }
+ else if (is_em) {
+ tag_close |= EM;
is_em = false;
}
}
- c = par->GetChar(i);
+ list < PAR_TAG > temp;
+ while(!tag_state.empty() && tag_close ) {
+ PAR_TAG k = tag_state.top();
+ tag_state.pop();
+ os << "" << tag_name(k) << ">";
+ if (tag_close & k)
+ reset(tag_close,k);
+ else
+ temp.push_back(k);
+ }
+
+ for(list< PAR_TAG >::const_iterator j = temp.begin();
+ j != temp.end(); ++j) {
+ tag_state.push(*j);
+ os << "<" << tag_name(*j) << ">";
+ }
- if (c == LyXParagraph::META_INSET) {
- inset = par->GetInset(i);
- inset->Linuxdoc(this, os);
+ for(list< PAR_TAG >::const_iterator j = tag_open.begin();
+ j != tag_open.end(); ++j) {
+ tag_state.push(*j);
+ os << "<" << tag_name(*j) << ">";
}
- if (font2.latex() == LyXFont::ON) {
+ char c = par->getChar(i);
+
+ if (c == Paragraph::META_INSET) {
+ Inset * inset = par->getInset(i);
+ inset->linuxdoc(this, os);
+ font_old = font;
+ continue;
+ }
+
+ if (style.latexparam() == "CDATA") {
// "TeX"-Mode on == > SGML-Mode on.
if (c != '\0')
- os << c; // see LaTeX-Generation...
+ os << c;
++char_line_count;
} else {
string sgml_string;
if (par->linuxDocConvertChar(c, sgml_string)
- && !style.free_spacing) { // in freespacing
- // mode, spaces are
- // non-breaking characters
- // char is ' '
- if (desc_on == 1) {
+ && !style.free_spacing) {
+ // in freespacing mode, spaces are
+ // non-breaking characters
+ if (desc_on) {// if char is ' ' then...
+
++char_line_count;
linux_doc_line_break(os, char_line_count, 6);
os << "";
- desc_on = 2;
+ desc_on = false;
} else {
linux_doc_line_break(os, char_line_count, 1);
os << c;
@@ -2914,93 +2975,57 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
char_line_count += sgml_string.length();
}
}
- font1 = font2;
- }
-
- // needed if there is an optional argument but no contents
- if (main_body > 0 && main_body == par->size()) {
- font1 = style.font;
+ font_old = font;
}
- // pop all defined Styles
- for (j = stack_num; j >= 0; --j) {
- linux_doc_line_break(os,
- char_line_count,
- 3 + strlen(stack[j]));
- os << "" << stack[j] << ">";
+ while (!tag_state.empty()) {
+ os << "" << tag_name(tag_state.top()) << ">";
+ tag_state.pop();
}
// resets description flag correctly
- switch(desc_on){
- case 1:
+ if (desc_on) {
// not closed...
linux_doc_line_break(os, char_line_count, 6);
os << "";
- break;
- case 2:
- // fprintf(file, "");
- break;
}
}
// Print an error message.
-void Buffer::LinuxDocError(LyXParagraph * par, int pos,
+void Buffer::linuxDocError(Paragraph * par, int pos,
string const & message)
{
// insert an error marker in text
InsetError * new_inset = new InsetError(message);
- par->InsertInset(pos, new_inset);
+ par->insertInset(pos, new_inset);
}
-// This constant defines the maximum number of
-// environment layouts that can be nesteded.
-// The same applies for command layouts.
-// These values should be more than enough.
-// José Matos (1999/07/22)
-
-enum { MAX_NEST_LEVEL = 25};
void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
{
- LyXParagraph * par = paragraph;
-
- niceFile = nice; // this will be used by Insetincludes.
+ ofstream ofs(fname.c_str());
+ if (!ofs) {
+ WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
+ return;
+ }
- string top_element= textclasslist.LatexnameOfClass(params.textclass);
- // Please use a real stack.
- string environment_stack[MAX_NEST_LEVEL];
- string environment_inner[MAX_NEST_LEVEL];
- // Please use a real stack.
- string command_stack[MAX_NEST_LEVEL];
- bool command_flag= false;
- int command_depth= 0, command_base= 0, cmd_depth= 0;
+ Paragraph * par = paragraph;
- string item_name, command_name;
- string c_depth, c_params, tmps;
+ niceFile = nice; // this will be used by Insetincludes.
- int depth = 0; // paragraph depth
LyXTextClass const & tclass =
textclasslist.TextClass(params.textclass);
LaTeXFeatures features(params, tclass.numLayouts());
validate(features);
-
- //if(nice)
- tex_code_break_column = lyxrc.ascii_linelen;
- //else
- //tex_code_break_column = 0;
-
- ofstream ofs(fname.c_str());
- if (!ofs) {
- WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
- return;
- }
texrow.reset();
- if(!only_body) {
- string sgml_includedfiles=features.getIncludedFiles();
+ string top_element = textclasslist.LatexnameOfClass(params.textclass);
+
+ if (!only_body) {
+ string sgml_includedfiles = features.getIncludedFiles(fname);
ofs << "\n\n";
+ }
- if(params.options.empty())
- sgmlOpenTag(ofs, 0, top_element);
- else {
- string top = top_element;
- top += " ";
- top += params.options;
- sgmlOpenTag(ofs, 0, top);
- }
+ string top = top_element;
+ top += " lang=\"";
+ top += params.language->code();
+ top += "\"";
+
+ if (!params.options.empty()) {
+ top += " ";
+ top += params.options;
}
+ sgmlOpenTag(ofs, 0, top);
ofs << "\n";
+ vector environment_stack(10);
+ vector environment_inner(10);
+ vector command_stack(10);
+
+ bool command_flag = false;
+ 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
+
+ string item_name;
+ string command_name;
+
while (par) {
+ string sgmlparam;
+ string c_depth;
+ string c_params;
int desc_on = 0; // description mode
+
LyXLayout const & style =
textclasslist.Style(params.textclass,
par->layout);
// environment tag closing
- for( ; depth > par->depth; --depth) {
- if(environment_inner[depth] != "!-- --") {
- item_name= "listitem";
+ for (; depth > par->params().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]);
}
@@ -3046,14 +3090,14 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
environment_inner[depth].erase();
}
- if(depth == par->depth
+ if (depth == par->params().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]);
@@ -3067,53 +3111,49 @@ 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")
- sgmlOpenTag(ofs, depth+command_depth,
- style.latexname());
+ sgmlOpenTag(ofs, depth + command_depth,
+ style.latexname());
break;
case LATEX_COMMAND:
- if (depth!= 0)
- LinuxDocError(par, 0,
+ if (depth != 0)
+ linuxDocError(par, 0,
_("Error : Wrong depth for "
"LatexType Command.\n"));
command_name = style.latexname();
- tmps = style.latexparam();
- c_params = split(tmps, c_depth,'|');
+ sgmlparam = style.latexparam();
+ c_params = split(sgmlparam, c_depth,'|');
- cmd_depth= lyx::atoi(c_depth);
+ cmd_depth = lyx::atoi(c_depth);
- if(command_flag) {
- if(cmd_depth= command_base; --j)
- 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;
- j >= cmd_depth; --j)
-
- if(!command_stack[j].empty())
- sgmlCloseTag(ofs, j, command_stack[j]);
- command_depth= cmd_depth;
+ if (command_flag) {
+ if (cmd_depth < command_base) {
+ for (Paragraph::depth_type j = command_depth; j >= command_base; --j)
+ sgmlCloseTag(ofs, j, command_stack[j]);
+ command_depth = command_base = cmd_depth;
+ } else if (cmd_depth <= command_depth) {
+ for (int j = command_depth; j >= int(cmd_depth); --j)
+ sgmlCloseTag(ofs, j, command_stack[j]);
+ command_depth = cmd_depth;
} else
- command_depth= cmd_depth;
+ command_depth = cmd_depth;
} else {
command_depth = command_base = cmd_depth;
command_flag = true;
}
- command_stack[command_depth]= command_name;
+ if (command_stack.size() == command_depth + 1)
+ command_stack.push_back(string());
+ command_stack[command_depth] = command_name;
// treat label as a special case for
// more WYSIWYM handling.
- if (par->GetChar(0) == LyXParagraph::META_INSET) {
- Inset * inset = par->GetInset(0);
- Inset::Code lyx_code = inset->LyxCode();
+ if (par->getChar(0) == Paragraph::META_INSET) {
+ Inset * inset = par->getInset(0);
+ Inset::Code lyx_code = inset->lyxCode();
if (lyx_code == Inset::LABEL_CODE){
command_name += " id=\"";
command_name += (static_cast(inset))->getContents();
@@ -3123,24 +3163,31 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
sgmlOpenTag(ofs, depth + command_depth, command_name);
- item_name = "title";
+ if (c_params.empty())
+ item_name = "title";
+ else
+ item_name = c_params;
sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
break;
case LATEX_ENVIRONMENT:
case LATEX_ITEM_ENVIRONMENT:
- if (depth < par->depth) {
- depth = par->depth;
+ if (depth < par->params().depth()) {
+ depth = par->params().depth();
environment_stack[depth].erase();
}
if (environment_stack[depth] != style.latexname()) {
+ if(environment_stack.size() == depth + 1) {
+ environment_stack.push_back("!-- --");
+ environment_inner.push_back("!-- --");
+ }
environment_stack[depth] = style.latexname();
environment_inner[depth] = "!-- --";
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,
@@ -3152,16 +3199,20 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
}
- if(style.latextype == LATEX_ENVIRONMENT) {
- if(!style.latexparam().empty())
- sgmlOpenTag(ofs, depth + command_depth,
- style.latexparam());
+ if (style.latextype == LATEX_ENVIRONMENT) {
+ if (!style.latexparam().empty()) {
+ if(style.latexparam() == "CDATA")
+ ofs << "next;
-#ifndef NEW_INSETS
- DocBookHandleFootnote(ofs, par,
- depth + 1 + command_depth);
- }
- while(par && par->IsDummy());
-#endif
+ string extra_par;
+ simpleDocBookOnePar(ofs, extra_par, par, desc_on,
+ depth + 1 + command_depth);
+ par = par->next();
+
string end_tag;
// write closing SGML tags
- switch(style.latextype) {
+ switch (style.latextype) {
case LATEX_COMMAND:
- end_tag = "title";
+ if (c_params.empty())
+ end_tag = "title";
+ else
+ end_tag = c_params;
sgmlCloseTag(ofs, depth + command_depth, end_tag);
break;
case LATEX_ENVIRONMENT:
- if(!style.latexparam().empty())
- sgmlCloseTag(ofs, depth + command_depth,
- style.latexparam());
+ if (!style.latexparam().empty()) {
+ if(style.latexparam() == "CDATA")
+ ofs << "]]>";
+ else
+ 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")
- sgmlCloseTag(ofs, depth + command_depth,
- style.latexname());
+ sgmlCloseTag(ofs, depth + command_depth, style.latexname());
break;
default:
- sgmlCloseTag(ofs, depth + command_depth,
- style.latexname());
+ sgmlCloseTag(ofs, depth + command_depth, style.latexname());
break;
}
}
// Close open tags
- for(; depth >= 0; --depth) {
- if(!environment_stack[depth].empty()) {
- if(environment_inner[depth] != "!-- --") {
- item_name= "listitem";
+ for (int d = depth; d >= 0; --d) {
+ 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]);
}
@@ -3244,65 +3291,55 @@ 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 >= 0 ; --j)
+ if (!command_stack[j].empty())
sgmlCloseTag(ofs, j, command_stack[j]);
- if (!only_body) {
- ofs << "\n\n";
- sgmlCloseTag(ofs, 0, top_element);
- }
+ ofs << "\n\n";
+ sgmlCloseTag(ofs, 0, top_element);
ofs.close();
// How to check for successful close
}
-void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
- LyXParagraph * par, int & desc_on,
- int depth) const
+void Buffer::simpleDocBookOnePar(ostream & os, string & extra,
+ Paragraph * par, int & desc_on,
+ Paragraph::depth_type depth) const
{
bool emph_flag = false;
LyXLayout const & style = textclasslist.Style(params.textclass,
- par->GetLayout());
+ par->getLayout());
- LyXParagraph::size_type main_body;
- if (style.labeltype != LABEL_MANUAL)
- main_body = 0;
- else
- main_body = par->BeginningOfMainBody();
+ LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
- // gets paragraph main font
- LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
-
int char_line_count = depth;
- if(!style.free_spacing)
- for (int j = 0; j < depth; ++j)
- os << ' ';
+ //if (!style.free_spacing)
+ // os << string(depth,' ');
// parsing main loop
- for (LyXParagraph::size_type i = 0;
+ for (Paragraph::size_type i = 0;
i < par->size(); ++i) {
- LyXFont font2 = par->getFont(params, i);
+ LyXFont font = par->getFont(params, i);
// handle tag
- if (font1.emph() != font2.emph() && i) {
- if (font2.emph() == LyXFont::ON) {
+ if (font_old.emph() != font.emph()) {
+ if (font.emph() == LyXFont::ON) {
os << "";
emph_flag = true;
- }else {
+ }else if(i) {
os << "";
emph_flag = false;
}
}
- char c = par->GetChar(i);
+ char c = par->getChar(i);
- if (c == LyXParagraph::META_INSET) {
- Inset * inset = par->GetInset(i);
- std::ostringstream ost;
- inset->DocBook(this, ost);
+ if (c == Paragraph::META_INSET) {
+ Inset * inset = par->getInset(i);
+ ostringstream ost;
+ inset->docBook(this, ost);
string tmp_out = ost.str().c_str();
//
@@ -3315,9 +3352,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, '@');
@@ -3325,11 +3362,6 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
else
os << tmp_out;
}
- } else if (font2.latex() == LyXFont::ON) {
- // "TeX"-Mode on ==> SGML-Mode on.
- if (c != '\0')
- os << c;
- ++char_line_count;
} else {
string sgml_string;
if (par->linuxDocConvertChar(c, sgml_string)
@@ -3348,25 +3380,19 @@ void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
os << sgml_string;
}
}
- font1 = font2;
+ font_old = font;
}
- // needed if there is an optional argument but no contents
- if (main_body > 0 && main_body == par->size()) {
- font1 = style.font;
- }
if (emph_flag) {
os << "";
}
// resets description flag correctly
- switch(desc_on){
- case 1:
+ if (desc_on == 1) {
// not closed...
os << "";
- break;
}
- os << '\n';
+ if(style.free_spacing) os << '\n';
}
@@ -3377,19 +3403,19 @@ int Buffer::runChktex()
{
if (!users->text) return 0;
- ProhibitInput(users);
+ users->owner()->prohibitInput();
// get LaTeX-Filename
string const name = getLatexName();
string path = OnlyPath(filename);
string const org_path = path;
- if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
+ if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
path = tmppath;
}
Path p(path); // path to LaTeX file
- users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
+ users->owner()->message(_("Running chktex..."));
// Remove all error insets
bool const removedErrorInsets = users->removeAutoInsets();
@@ -3413,9 +3439,9 @@ int Buffer::runChktex()
// error insets after we ran chktex, this must be run:
if (removedErrorInsets || res){
users->redraw();
- users->fitCursor(users->text);
+ users->fitCursor();
}
- AllowInput(users);
+ users->owner()->allowInput();
return res;
}
@@ -3423,12 +3449,11 @@ int Buffer::runChktex()
void Buffer::validate(LaTeXFeatures & features) const
{
- LyXParagraph * par = paragraph;
+ Paragraph * par = paragraph;
LyXTextClass const & tclass =
textclasslist.TextClass(params.textclass);
// AMS Style is at document level
-
features.amsstyle = (params.use_amsmath ||
tclass.provides(LyXTextClass::amsmath));
@@ -3442,7 +3467,7 @@ void Buffer::validate(LaTeXFeatures & features) const
par->validate(features);
// and then the next paragraph
- par = par->next;
+ par = par->next();
}
// the bullet shapes are buffer level not paragraph level
@@ -3508,18 +3533,17 @@ string const Buffer::getIncludeonlyList(char delim)
string lst;
for (inset_iterator it = inset_iterator_begin();
it != inset_iterator_end(); ++it) {
- if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
+ if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
InsetInclude * insetinc =
static_cast(*it);
- if (insetinc->isInclude()
- && insetinc->isNoLoad()) {
+ if (insetinc->isIncludeOnly()) {
if (!lst.empty())
lst += delim;
- lst += OnlyFilename(ChangeExtension(insetinc->getContents(), string()));
+ lst += insetinc->getRelFileBaseName();
}
}
}
- lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
+ lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
return lst;
}
@@ -3545,65 +3569,72 @@ vector const Buffer::getLabelList()
}
-vector > const Buffer::getTocList()
+Buffer::Lists const Buffer::getLists() const
{
- vector > l(4);
- LyXParagraph * par = paragraph;
+ Lists l;
+ Paragraph * par = paragraph;
+ bool found;
+ LyXTextClassList::size_type cap;
+ boost::tie(found, cap) = textclasslist
+ .NumberOfLayout(params.textclass, "Caption");
+
while (par) {
-#ifndef NEW_INSETS
- if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
- if (textclasslist.Style(params.textclass,
- par->GetLayout()).labeltype
- == LABEL_SENSITIVE) {
- TocItem tmp;
- tmp.par = par;
- tmp.depth = 0;
- tmp.str = par->String(this, false);
- switch (par->footnotekind) {
- case LyXParagraph::FIG:
- case LyXParagraph::WIDE_FIG:
- l[TOC_LOF].push_back(tmp);
- break;
- case LyXParagraph::TAB:
- case LyXParagraph::WIDE_TAB:
- l[TOC_LOT].push_back(tmp);
- break;
- case LyXParagraph::ALGORITHM:
- l[TOC_LOA].push_back(tmp);
- break;
- case LyXParagraph::FOOTNOTE:
- case LyXParagraph::MARGIN:
- break;
- }
- }
- } else if (!par->IsDummy()) {
-#endif
- char const labeltype =
- textclasslist.Style(params.textclass,
- par->GetLayout()).labeltype;
-
- if (labeltype >= LABEL_COUNTER_CHAPTER
- && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
+ char const labeltype =
+ textclasslist.Style(params.textclass,
+ par->getLayout()).labeltype;
+
+ if (labeltype >= LABEL_COUNTER_CHAPTER
+ && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
// insert this into the table of contents
- TocItem tmp;
- tmp.par = par;
- tmp.depth = max(0,
- labeltype -
- textclasslist.TextClass(params.textclass).maxcounter());
- tmp.str = par->String(this, true);
- l[TOC_TOC].push_back(tmp);
+ SingleList & item = l["TOC"];
+ int depth = max(0,
+ labeltype -
+ textclasslist.TextClass(params.textclass).maxcounter());
+ item.push_back(TocItem(par, depth, par->asString(this, true)));
+ }
+ // For each paragrph, traverse its insets and look for
+ // FLOAT_CODE
+
+ if (found) {
+ Paragraph::inset_iterator it =
+ par->inset_iterator_begin();
+ Paragraph::inset_iterator end =
+ par->inset_iterator_end();
+
+ for (; it != end; ++it) {
+ if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
+ InsetFloat * il =
+ static_cast(*it);
+
+ string const type = il->type();
+
+ // Now find the caption in the float...
+ // We now tranverse the paragraphs of
+ // the inset...
+ Paragraph * tmp = il->inset.paragraph();
+ while (tmp) {
+ if (tmp->layout == cap) {
+ SingleList & item = l[type];
+ string const str =
+ tostr(item.size()+1) + ". " + tmp->asString(this, false);
+ item.push_back(TocItem(tmp, 0 , str));
+ }
+ tmp = tmp->next();
+ }
+ }
}
-#ifndef NEW_INSETS
+ } else {
+ lyxerr << "caption not found" << endl;
}
-#endif
- par = par->next;
+
+ par = par->next();
}
return l;
}
// This is also a buffer property (ale)
-vector > const Buffer::getBibkeyList()
+vector > const Buffer::getBibkeyList()
{
/// if this is a child document and the parent is already loaded
/// Use the parent's list instead [ale990412]
@@ -3614,12 +3645,12 @@ vector > const Buffer::getBibkeyList()
}
vector > keys;
- LyXParagraph * par = paragraph;
+ Paragraph * par = paragraph;
while (par) {
if (par->bibkey)
keys.push_back(pair(par->bibkey->getContents(),
- par->String(this, false)));
- par = par->next;
+ par->asString(this, false)));
+ par = par->next();
}
// Might be either using bibtex or a child has bibliography
@@ -3627,11 +3658,11 @@ vector > const Buffer::getBibkeyList()
for (inset_iterator it = inset_iterator_begin();
it != inset_iterator_end(); ++it) {
// Search for Bibtex or Include inset
- if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
+ if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
vector > tmp =
static_cast(*it)->getKeys(this);
keys.insert(keys.end(), tmp.begin(), tmp.end());
- } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
+ } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
vector > const tmp =
static_cast(*it)->getKeys();
keys.insert(keys.end(), tmp.begin(), tmp.end());
@@ -3676,18 +3707,18 @@ void Buffer::markDepClean(string const & name)
}
-bool Buffer::Dispatch(string const & command)
+bool Buffer::dispatch(string const & command)
{
// 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);
}
-bool Buffer::Dispatch(int action, string const & argument)
+bool Buffer::dispatch(int action, string const & argument)
{
bool dispatched = true;
switch (action) {
@@ -3702,66 +3733,99 @@ bool Buffer::Dispatch(int action, string const & argument)
}
-void Buffer::resize()
-{
- /// resize the BufferViews!
- if (users)
- users->resize();
-}
-
-
void Buffer::resizeInsets(BufferView * bv)
{
/// then remove all LyXText in text-insets
- LyXParagraph * par = paragraph;
- for(; par; par = par->next) {
+ Paragraph * par = paragraph;
+ for (; par; par = par->next()) {
par->resizeInsetsLyXText(bv);
}
}
-void Buffer::ChangeLanguage(Language const * from, Language const * to)
+
+void Buffer::redraw()
{
+ users->redraw();
+ users->fitCursor();
+}
- LyXParagraph * par = paragraph;
+
+void Buffer::changeLanguage(Language const * from, Language const * to)
+{
+
+ Paragraph * par = paragraph;
while (par) {
- par->ChangeLanguage(params, from, to);
- par = par->next;
+ par->changeLanguage(params, from, to);
+ par = par->next();
}
}
bool Buffer::isMultiLingual()
{
- LyXParagraph * par = paragraph;
+ Paragraph * par = paragraph;
while (par) {
if (par->isMultiLingual(params))
return true;
- par = par->next;
+ par = par->next();
}
return false;
}
-Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
- LyXParagraph::size_type pos)
+Buffer::inset_iterator::inset_iterator(Paragraph * paragraph,
+ Paragraph::size_type pos)
: par(paragraph)
{
it = par->InsetIterator(pos);
if (it == par->inset_iterator_end()) {
- par = par->next;
- SetParagraph();
+ par = par->next();
+ setParagraph();
}
}
-void Buffer::inset_iterator::SetParagraph()
+void Buffer::inset_iterator::setParagraph()
{
while (par) {
it = par->inset_iterator_begin();
if (it != par->inset_iterator_end())
return;
- par = par->next;
+ par = par->next();
}
//it = 0;
// We maintain an invariant that whenever par = 0 then it = 0
}
+
+
+Inset * Buffer::getInsetFromID(int id_arg) const
+{
+ for (inset_iterator it = inset_const_iterator_begin();
+ it != inset_const_iterator_end(); ++it)
+ {
+ if ((*it)->id() == id_arg)
+ return *it;
+ Inset * in = (*it)->getInsetFromID(id_arg);
+ if (in)
+ return in;
+ }
+ return 0;
+}
+
+
+Paragraph * Buffer::getParFromID(int id) const
+{
+ if (id < 0) return 0;
+ Paragraph * par = paragraph;
+ while (par) {
+ if (par->id() == id) {
+ return par;
+ }
+ Paragraph * tmp = par->getParFromID(id);
+ if (tmp) {
+ return tmp;
+ }
+ par = par->next();
+ }
+ return 0;
+}