Some time ago when lyx was crashing every second I played a bit with const_casts. The attached patch exchanges some of them with the use of const_iterators. It makes also Paragraph::simpleTeXOnePar const.
Furthermore I think that this line in Paragraph::startTeXParParams should be a "+=" instead of a "=": os << "\\protect"; column = 8; Is this ok, or does somebody have contradicting plans? Georg
diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/ChangeLog lyx-1.4-cvs/src/ChangeLog --- lyx-1.4-clean/src/ChangeLog 2004-05-14 19:53:10.000000000 +0200 +++ lyx-1.4-cvs/src/ChangeLog 2004-05-15 12:03:44.000000000 +0200 @@ -1,4 +1,18 @@ +2004-05-15 Georg Baum <[EMAIL PROTECTED]> + + * paragraph.C (startTeXParParams): correct column count + * CutAndPaste.C (pasteSelection): remove const_cast + * output_docbook.C (docbookParagraphs): remove const_cast + * output_latex.C (TeXEnvironment, TeXOnePar, TeXDeeper): remove + const_cast and return ParagraphList::const_iterator + * output_linuxdoc.C (linuxdocParagraphs): remove const_cast + * output_plaintext.C (writeFileAscii): remove const_cast + * paragraph.[Ch] (simpleTeXOnePar): make const + * paragraph_funcs.C (outerPar): use const iterators + * paragraph_pimpl.C (validate): use const iterators + * text.C (setHeightOfRow): use const iterators + 2004-05-14 José Matos <[EMAIL PROTECTED]> * buffer.C (makeDocBookFile): add a default Formal Public Identifier if the textclass does not provide it. Have it different for sgml and diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/CutAndPaste.C lyx-1.4-cvs/src/CutAndPaste.C --- lyx-1.4-clean/src/CutAndPaste.C 2004-04-26 12:54:33.000000000 +0200 +++ lyx-1.4-cvs/src/CutAndPaste.C 2004-04-21 10:39:37.000000000 +0200 @@ -169,9 +169,9 @@ pasteSelectionHelper(Buffer const & buff for (; lit != eit; ++lit) { switch (lit->inset->lyxCode()) { case InsetOld::TABULAR_CODE: { InsetTabular * it = static_cast<InsetTabular*>(lit->inset); - it->buffer(const_cast<Buffer*>(&buffer)); + it->buffer(&buffer); break; } default: diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/output_docbook.C lyx-1.4-cvs/src/output_docbook.C --- lyx-1.4-clean/src/output_docbook.C 2004-05-14 19:53:30.000000000 +0200 +++ lyx-1.4-cvs/src/output_docbook.C 2004-05-14 19:57:55.000000000 +0200 @@ -63,10 +63,10 @@ void docbookParagraphs(Buffer const & bu string command_name; string item_tag; - ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin(); - ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end(); + ParagraphList::const_iterator par = paragraphs.begin(); + ParagraphList::const_iterator pend = paragraphs.end(); Counters & counters = buf.params().getLyXTextClass().counters(); for (; par != pend; ++par) { @@ -218,9 +218,9 @@ void docbookParagraphs(Buffer const & bu break; } par->simpleDocBookOnePar(buf, os, - outerFont(par - const_cast<ParagraphList&>(paragraphs).begin(), paragraphs), + outerFont(par - paragraphs.begin(), paragraphs), runparams, depth + 1 + command_depth); // write closing SGML tags switch (style->latextype) { diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/output_latex.C lyx-1.4-cvs/src/output_latex.C --- lyx-1.4-clean/src/output_latex.C 2004-04-26 12:54:52.000000000 +0200 +++ lyx-1.4-cvs/src/output_latex.C 2004-04-26 13:13:21.000000000 +0200 @@ -41,35 +41,35 @@ extern string bibitemWidest(Buffer const namespace { -ParagraphList::iterator +ParagraphList::const_iterator TeXEnvironment(Buffer const & buf, ParagraphList const & paragraphs, - ParagraphList::iterator pit, + ParagraphList::const_iterator pit, ostream & os, TexRow & texrow, OutputParams const & runparams); -ParagraphList::iterator +ParagraphList::const_iterator TeXOnePar(Buffer const & buf, ParagraphList const & paragraphs, - ParagraphList::iterator pit, + ParagraphList::const_iterator pit, ostream & os, TexRow & texrow, OutputParams const & runparams, string const & everypar = string()); -ParagraphList::iterator +ParagraphList::const_iterator TeXDeeper(Buffer const & buf, ParagraphList const & paragraphs, - ParagraphList::iterator pit, + ParagraphList::const_iterator pit, ostream & os, TexRow & texrow, OutputParams const & runparams) { lyxerr[Debug::LATEX] << "TeXDeeper... " << &*pit << endl; - ParagraphList::iterator par = pit; + ParagraphList::const_iterator par = pit; - while (par != const_cast<ParagraphList&>(paragraphs).end() && + while (par != paragraphs.end() && par->params().depth() == pit->params().depth()) { if (par->layout()->isEnvironment()) { par = TeXEnvironment(buf, paragraphs, par, os, texrow, runparams); @@ -83,12 +83,12 @@ TeXDeeper(Buffer const & buf, return par; } -ParagraphList::iterator +ParagraphList::const_iterator TeXEnvironment(Buffer const & buf, ParagraphList const & paragraphs, - ParagraphList::iterator pit, + ParagraphList::const_iterator pit, ostream & os, TexRow & texrow, OutputParams const & runparams) { lyxerr[Debug::LATEX] << "TeXEnvironment... " << &*pit << endl; @@ -99,9 +99,9 @@ TeXEnvironment(Buffer const & buf, Language const * language = pit->getParLanguage(bparams); Language const * doc_language = bparams.language; Language const * previous_language = - (pit != const_cast<ParagraphList&>(paragraphs).begin()) + (pit != paragraphs.begin()) ? boost::prior(pit)->getParLanguage(bparams) : doc_language; if (language->babel() != previous_language->babel()) { @@ -140,13 +140,13 @@ TeXEnvironment(Buffer const & buf, } else os << style->latexparam() << '\n'; texrow.newline(); } - ParagraphList::iterator par = pit; + ParagraphList::const_iterator par = pit; do { par = TeXOnePar(buf, paragraphs, par, os, texrow, runparams); - if (par == const_cast<ParagraphList&>(paragraphs).end()) { + if (par == paragraphs.end()) { // Make sure that the last paragraph is // correctly terminated (because TeXOnePar does // not add a \n in this case) os << '\n'; @@ -173,9 +173,9 @@ TeXEnvironment(Buffer const & buf, } par = TeXDeeper(buf, paragraphs, par, os, texrow, runparams); } - } while (par != const_cast<ParagraphList&>(paragraphs).end() + } while (par != paragraphs.end() && par->layout() == pit->layout() && par->params().depth() == pit->params().depth() && par->params().leftIndent() == pit->params().leftIndent()); @@ -208,12 +208,12 @@ InsetOptArg * optArgInset(Paragraph cons return 0; } -ParagraphList::iterator +ParagraphList::const_iterator TeXOnePar(Buffer const & buf, ParagraphList const & paragraphs, - ParagraphList::iterator pit, + ParagraphList::const_iterator pit, ostream & os, TexRow & texrow, OutputParams const & runparams, string const & everypar) { @@ -235,9 +235,9 @@ TeXOnePar(Buffer const & buf, texrow.newline(); } if (!pit->params().spacing().isDefault() - && (pit == const_cast<ParagraphList&>(paragraphs).begin() + && (pit == paragraphs.begin() || !boost::prior(pit)->hasSameLayout(*pit))) { os << pit->params().spacing().writeEnvirBegin() << '\n'; texrow.newline(); @@ -258,16 +258,16 @@ TeXOnePar(Buffer const & buf, Language const * language = pit->getParLanguage(bparams); Language const * doc_language = bparams.language; Language const * previous_language = - (pit != const_cast<ParagraphList&>(paragraphs).begin()) + (pit != paragraphs.begin()) ? boost::prior(pit)->getParLanguage(bparams) : doc_language; if (language->babel() != previous_language->babel() // check if we already put language command in TeXEnvironment() && !(style->isEnvironment() - && (pit == const_cast<ParagraphList&>(paragraphs).begin() || + && (pit == paragraphs.begin() || (boost::prior(pit)->layout() != pit->layout() && boost::prior(pit)->getDepth() <= pit->getDepth()) || boost::prior(pit)->getDepth() < pit->getDepth()))) { @@ -323,9 +323,9 @@ TeXOnePar(Buffer const & buf, } os << everypar; bool need_par = pit->simpleTeXOnePar(buf, bparams, - outerFont(pit - const_cast<ParagraphList&>(paragraphs).begin(), paragraphs), + outerFont(pit - paragraphs.begin(), paragraphs), os, texrow, runparams); // Make sure that \\par is done with the font of the last // character if this has another size as the default. @@ -336,9 +336,9 @@ TeXOnePar(Buffer const & buf, // Is this really needed ? (Dekel) // We do not need to use to change the font for the last paragraph // or for a command. LyXFont const outerfont = - outerFont(pit - const_cast<ParagraphList&>(paragraphs).begin(), + outerFont(pit - paragraphs.begin(), paragraphs); LyXFont const font = (pit->empty() @@ -347,9 +347,9 @@ paragraphs); bool is_command = style->isCommand(); if (style->resfont.size() != font.size() - && boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end() + && boost::next(pit) != paragraphs.end() && !is_command) { if (!need_par) os << '{'; os << "\\" << font.latexSize() << " \\par}"; @@ -360,29 +360,29 @@ paragraphs); switch (style->latextype) { case LATEX_ITEM_ENVIRONMENT: case LATEX_LIST_ENVIRONMENT: - if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end() + if (boost::next(pit) != paragraphs.end() && (pit->params().depth() < boost::next(pit)->params().depth())) { os << '\n'; texrow.newline(); } break; case LATEX_ENVIRONMENT: { // if its the last paragraph of the current environment // skip it otherwise fall through - ParagraphList::iterator next = boost::next(pit); + ParagraphList::const_iterator next = boost::next(pit); - if (next != const_cast<ParagraphList&>(paragraphs).end() + if (next != paragraphs.end() && (next->layout() != pit->layout() || next->params().depth() != pit->params().depth())) break; } // fall through possible default: // we don't need it for the last paragraph!!! - if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) { + if (boost::next(pit) != paragraphs.end()) { os << '\n'; texrow.newline(); } } @@ -414,9 +414,9 @@ paragraphs); texrow.newline(); } if (!pit->params().spacing().isDefault() - && (boost::next(pit) == const_cast<ParagraphList&>(paragraphs).end() + && (boost::next(pit) == paragraphs.end() || !boost::next(pit)->hasSameLayout(*pit))) { os << pit->params().spacing().writeEnvirEnd() << '\n'; texrow.newline(); @@ -425,9 +425,9 @@ paragraphs); // we don't need it for the last paragraph!!! // Note from JMarc: we will re-add a \n explicitely in // TeXEnvironment, because it is needed in this case - if (boost::next(pit) != const_cast<ParagraphList&>(paragraphs).end()) { + if (boost::next(pit) != paragraphs.end()) { os << '\n'; texrow.newline(); } @@ -448,10 +448,10 @@ void latexParagraphs(Buffer const & buf, { bool was_title = false; bool already_title = false; LyXTextClass const & tclass = buf.params().getLyXTextClass(); - ParagraphList::iterator par = const_cast<ParagraphList&>(paragraphs).begin(); - ParagraphList::iterator endpar = const_cast<ParagraphList&>(paragraphs).end(); + ParagraphList::const_iterator par = paragraphs.begin(); + ParagraphList::const_iterator endpar = paragraphs.end(); // if only_body while (par != endpar) { // well we have to check if we are in an inset with unlimited diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/output_linuxdoc.C lyx-1.4-cvs/src/output_linuxdoc.C --- lyx-1.4-clean/src/output_linuxdoc.C 2004-04-03 10:36:59.000000000 +0200 +++ lyx-1.4-cvs/src/output_linuxdoc.C 2004-04-19 21:07:06.000000000 +0200 @@ -40,15 +40,15 @@ void linuxdocParagraphs(Buffer const & b Paragraph::depth_type depth = 0; // paragraph depth string item_name; vector<string> environment_stack(5); - ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin(); - ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end(); + ParagraphList::const_iterator pit = paragraphs.begin(); + ParagraphList::const_iterator pend = paragraphs.end(); for (; pit != pend; ++pit) { LyXLayout_ptr const & style = pit->layout(); // treat <toc> as a special case for compatibility with old code if (pit->isInset(0)) { - InsetBase * inset = pit->getInset(0); + InsetBase const * inset = pit->getInset(0); if (inset->lyxCode() == InsetOld::TOC_CODE) { string const temp = "toc"; sgml::openTag(os, depth, false, temp); continue; @@ -135,9 +135,9 @@ void linuxdocParagraphs(Buffer const & b break; } pit->simpleLinuxDocOnePar(buf, os, - outerFont(pit - const_cast<ParagraphList&>(paragraphs).begin(), paragraphs), + outerFont(pit - paragraphs.begin(), paragraphs), runparams, depth); os << "\n"; // write closing SGML tags diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/output_plaintext.C lyx-1.4-cvs/src/output_plaintext.C --- lyx-1.4-clean/src/output_plaintext.C 2004-03-27 02:18:47.000000000 +0100 +++ lyx-1.4-cvs/src/output_plaintext.C 2004-04-19 21:07:06.000000000 +0200 @@ -54,13 +54,12 @@ void writeFileAscii(Buffer const & buf, void writeFileAscii(Buffer const & buf, ostream & os, OutputParams const & runparams) { - Buffer & tmp = const_cast<Buffer &>(buf); - ParagraphList par = const_cast<ParagraphList&>(tmp.paragraphs()); - ParagraphList::iterator beg = par.begin(); - ParagraphList::iterator end = par.end(); - ParagraphList::iterator it = beg; + ParagraphList const par = buf.paragraphs(); + ParagraphList::const_iterator beg = par.begin(); + ParagraphList::const_iterator end = par.end(); + ParagraphList::const_iterator it = beg; for (; it != end; ++it) { asciiParagraph(buf, *it, os, runparams, it == beg); } os << "\n"; diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/paragraph.C lyx-1.4-cvs/src/paragraph.C --- lyx-1.4-clean/src/paragraph.C 2004-05-14 19:53:31.000000000 +0200 +++ lyx-1.4-cvs/src/paragraph.C 2004-05-14 19:56:43.000000000 +0200 @@ -783,9 +783,9 @@ int Paragraph::startTeXParParams(BufferP case LYX_ALIGN_RIGHT: case LYX_ALIGN_CENTER: if (moving_arg) { os << "\\protect"; - column = 8; + column += 8; } break; } @@ -889,9 +889,9 @@ int Paragraph::endTeXParParams(BufferPar bool Paragraph::simpleTeXOnePar(Buffer const & buf, BufferParams const & bparams, LyXFont const & outerfont, ostream & os, TexRow & texrow, - OutputParams const & runparams) + OutputParams const & runparams) const { lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl; bool return_value = false; diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/paragraph_funcs.C lyx-1.4-cvs/src/paragraph_funcs.C --- lyx-1.4-clean/src/paragraph_funcs.C 2004-04-03 10:37:00.000000000 +0200 +++ lyx-1.4-cvs/src/paragraph_funcs.C 2004-04-19 21:07:06.000000000 +0200 @@ -305,10 +305,10 @@ par_type outerPar(Buffer const & buf, In for (int i = 0; (text = inset->getText(i)); ++i) if (&text->paragraphs() == &pit.plist()) return pit.outerPar(); - InsetList::iterator ii = pit->insetlist.begin(); - InsetList::iterator iend = pit->insetlist.end(); + InsetList::const_iterator ii = pit->insetlist.begin(); + InsetList::const_iterator iend = pit->insetlist.end(); for ( ; ii != iend; ++ii) if (ii->inset == inset) return pit.outerPar(); } diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/paragraph.h lyx-1.4-cvs/src/paragraph.h --- lyx-1.4-clean/src/paragraph.h 2004-05-14 19:53:31.000000000 +0200 +++ lyx-1.4-cvs/src/paragraph.h 2004-05-14 19:56:43.000000000 +0200 @@ -117,9 +117,9 @@ public: /// bool simpleTeXOnePar(Buffer const &, BufferParams const &, LyXFont const & outerfont, std::ostream &, - TexRow & texrow, OutputParams const &); + TexRow & texrow, OutputParams const &) const; /// void simpleLinuxDocOnePar(Buffer const & buf, std::ostream & os, diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/paragraph_pimpl.C lyx-1.4-cvs/src/paragraph_pimpl.C --- lyx-1.4-clean/src/paragraph_pimpl.C 2004-03-25 10:16:21.000000000 +0100 +++ lyx-1.4-cvs/src/paragraph_pimpl.C 2004-04-19 21:07:06.000000000 +0200 @@ -779,10 +779,10 @@ void Paragraph::Pimpl::validate(LaTeXFea if (!params.leftIndent().zero()) features.require("ParagraphLeftIndent"); // then the insets - InsetList::iterator icit = owner_->insetlist.begin(); - InsetList::iterator iend = owner_->insetlist.end(); + InsetList::const_iterator icit = owner_->insetlist.begin(); + InsetList::const_iterator iend = owner_->insetlist.end(); for (; icit != iend; ++icit) { if (icit->inset) { icit->inset->validate(features); if (layout.needprotect && diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/text.C lyx-1.4-cvs/src/text.C --- lyx-1.4-clean/src/text.C 2004-04-26 12:54:56.000000000 +0200 +++ lyx-1.4-cvs/src/text.C 2004-04-22 09:41:03.000000000 +0200 @@ -916,10 +916,10 @@ void LyXText::setHeightOfRow(par_type pi int maxasc = int(font_metrics::maxAscent(font) * spacing_val); int maxdesc = int(font_metrics::maxDescent(font) * spacing_val); // insets may be taller - InsetList::iterator ii = pars_[pit].insetlist.begin(); - InsetList::iterator iend = pars_[pit].insetlist.end(); + InsetList::const_iterator ii = pars_[pit].insetlist.begin(); + InsetList::const_iterator iend = pars_[pit].insetlist.end(); for ( ; ii != iend; ++ii) { if (ii->pos >= row.pos() && ii->pos < row.endpos()) { maxasc = max(maxasc, ii->inset->ascent()); maxdesc = max(maxdesc, ii->inset->descent()); diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/insets/ChangeLog lyx-1.4-cvs/src/insets/ChangeLog --- lyx-1.4-clean/src/insets/ChangeLog 2004-05-14 19:53:56.000000000 +0200 +++ lyx-1.4-cvs/src/insets/ChangeLog 2004-05-15 14:09:33.000000000 +0200 @@ -1,4 +1,8 @@ +2004-05-15 Georg Baum <[EMAIL PROTECTED]> + + * insettabular.[Ch] (buffer): make Buffer * argument const + 2004-05-14 José Matos <[EMAIL PROTECTED]> * insetlabel (docbook): do not ouput label, for the moment. diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/insets/insettabular.C lyx-1.4-cvs/src/insets/insettabular.C --- lyx-1.4-clean/src/insets/insettabular.C 2004-04-13 14:47:46.000000000 +0200 +++ lyx-1.4-cvs/src/insets/insettabular.C 2004-04-19 21:07:06.000000000 +0200 @@ -182,9 +182,9 @@ Buffer const & InsetTabular::buffer() co return *buffer_; } -void InsetTabular::buffer(Buffer * b) +void InsetTabular::buffer(Buffer const * b) { buffer_ = b; } diff -p -r -U 4 -X excl.tmp lyx-1.4-clean/src/insets/insettabular.h lyx-1.4-cvs/src/insets/insettabular.h --- lyx-1.4-clean/src/insets/insettabular.h 2004-04-13 14:47:47.000000000 +0200 +++ lyx-1.4-cvs/src/insets/insettabular.h 2004-04-19 21:07:06.000000000 +0200 @@ -132,9 +132,9 @@ public: /// Buffer const & buffer() const; /// set the owning buffer - void buffer(Buffer * buf); + void buffer(Buffer const * buf); /// lock cell with given index void edit(LCursor & cur, bool left); /// InsetBase * editXY(LCursor & cur, int x, int y);