From: Lars Gullik Bjønnes Date: Thu, 2 Mar 2000 02:19:43 +0000 (+0000) Subject: change to use only ostream to write latex from insets X-Git-Tag: 1.6.10~22358 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=a9b448a027036c65c40b372bd19e02f243d1f1ab;p=features.git change to use only ostream to write latex from insets git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@581 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index 6475fc4d9d..f1b17ae886 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2000-03-02 Lars Gullik Bjønnes + + * src/mathed/math_utils.C (MathedLookupBOP): using only res->id == + id in the check of the result from lower_bound is not enough since + lower_bound can return last too, and then res->id will not be a + valid construct. + + * all insets and some code that use them: I have conditionalized + removed the Latex(string & out, ...) this means that only the + Latex(ostream &, ...) will be used. This is a work in progress to + move towards using streams for all output of files. + + * src/text.C (GetColumnNearX): initialize LyXParagraph::size_type + c to 0. + 2000-03-02 Jean-Marc Lasgouttes * src/mathed/math_utils.C (MathedLookupBOP): fix the search diff --git a/acinclude.m4 b/acinclude.m4 index f055262b95..7c317dbd23 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -183,7 +183,7 @@ dnl Check the version of g++ CXXFLAGS="$ac_save_CXXFLAGS" elif test $ac_cv_prog_cxx_g = yes; then case $gxx_version in - 2.95.1) CXXFLAGS="-g $lyx_opt -fpermissive -fno-rtti";; + 2.95.1) CXXFLAGS="-g $lyx_opt -fpermissive -fno-rtti -fno-exceptions";; 2.95.*) CXXFLAGS="-g $lyx_opt -fno-rtti -fno-exceptions";; 2.96*) CXXFLAGS="-g $lyx_opt -fno-rtti -fno-exceptions";; *2.91.*) CXXFLAGS="-g $lyx_opt -fno-rtti -fno-exceptions";; @@ -194,9 +194,9 @@ dnl Check the version of g++ fi if test x$with_warnings = xyes ; then case $gxx_version in - 2.95.*) CXXFLAGS="$CXXFLAGS -Wall -W -Wconversion";; - 2.96*) CXXFLAGS="$CXXFLAGS -Wall -W -Wconversion";; - *) CXXFLAGS="$CXXFLAGS -ansi -Wall -W -Wno-return-type";; + 2.95.*) CXXFLAGS="$CXXFLAGS -W -Wall -Wconversion";; + 2.96*) CXXFLAGS="$CXXFLAGS -W -Wall -Wconversion";; + *) CXXFLAGS="$CXXFLAGS -ansi -W -Wall -Wno-return-type";; esac if test $lyx_devel_version = yes ; then case $gxx_version in diff --git a/config/lyxinclude.m4 b/config/lyxinclude.m4 index bf009dc7c2..a430a0933a 100644 --- a/config/lyxinclude.m4 +++ b/config/lyxinclude.m4 @@ -183,7 +183,7 @@ dnl Check the version of g++ CXXFLAGS="$ac_save_CXXFLAGS" elif test $ac_cv_prog_cxx_g = yes; then case $gxx_version in - 2.95.1) CXXFLAGS="-g $lyx_opt -fpermissive -fno-rtti";; + 2.95.1) CXXFLAGS="-g $lyx_opt -fpermissive -fno-rtti -fno-exceptions";; 2.95.*) CXXFLAGS="-g $lyx_opt -fno-rtti -fno-exceptions";; 2.96*) CXXFLAGS="-g $lyx_opt -fno-rtti -fno-exceptions";; *2.91.*) CXXFLAGS="-g $lyx_opt -fno-rtti -fno-exceptions";; @@ -194,9 +194,9 @@ dnl Check the version of g++ fi if test x$with_warnings = xyes ; then case $gxx_version in - 2.95.*) CXXFLAGS="$CXXFLAGS -Wall -W -Wconversion";; - 2.96*) CXXFLAGS="$CXXFLAGS -Wall -W -Wconversion";; - *) CXXFLAGS="$CXXFLAGS -ansi -Wall -W -Wno-return-type";; + 2.95.*) CXXFLAGS="$CXXFLAGS -W -Wall -Wconversion";; + 2.96*) CXXFLAGS="$CXXFLAGS -W -Wall -Wconversion";; + *) CXXFLAGS="$CXXFLAGS -ansi -W -Wall -Wno-return-type";; esac if test $lyx_devel_version = yes ; then case $gxx_version in diff --git a/src/insets/figinset.C b/src/insets/figinset.C index 1c3939b8c9..6bc9176219 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -1202,12 +1202,14 @@ int InsetFig::Latex(ostream & os, signed char /* fragile*/ ) const } +#ifndef USE_OSTREAM_ONLY int InsetFig::Latex(string & file, signed char /* fragile*/ ) const { Regenerate(); file += cmd + ' '; return 0; } +#endif int InsetFig::Linuxdoc(string &/*file*/) const diff --git a/src/insets/figinset.h b/src/insets/figinset.h index 1ee86e042a..83234badc5 100644 --- a/src/insets/figinset.h +++ b/src/insets/figinset.h @@ -39,8 +39,10 @@ public: void Read(LyXLex & lex); /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & file) const; /// diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index dd34a47a22..61f71bcb4a 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -313,14 +313,52 @@ string InsetBibtex::getScreenLabel() const int InsetBibtex::Latex(ostream & os, signed char /*fragile*/) const { +#ifdef USE_OSTREAM_ONLY + // this looks like an horrible hack and it is :) The problem + // is that owner is not initialized correctly when the bib + // inset is cut and pasted. Such hacks will not be needed + // later (JMarc) + if (!owner) { + owner = current_view->buffer(); + } + // If we generate in a temp dir, we might need to give an + // absolute path there. This is a bit complicated since we can + // have a comma-separated list of bibliographies + string adb, db_out; + string db_in = getContents(); + db_in = split(db_in, adb, ','); + while(!adb.empty()) { + if (!owner->niceFile && + IsFileReadable(MakeAbsPath(adb, owner->filepath)+".bib")) + adb = MakeAbsPath(adb, owner->filepath); + db_out += adb; + db_out += ','; + db_in= split(db_in, adb,','); + } + db_out = strip(db_out, ','); + // Idem, but simpler + string style; + if (!owner->niceFile + && IsFileReadable(MakeAbsPath(getOptions(), owner->filepath) + + ".bst")) + style = MakeAbsPath(getOptions(), owner->filepath); + else + style = getOptions(); + + os << "\\bibliographystyle{" << style << "}\n" + << "\\bibliography{" << db_out << "}\n"; + return 2; +#else string bib; signed char dummy = 0; int result = Latex(bib, dummy); os << bib; return result; +#endif } +#ifndef USE_OSTREAM_ONLY int InsetBibtex::Latex(string & file, signed char /*fragile*/) const { // this looks like an horrible hack and it is :) The problem @@ -362,7 +400,7 @@ int InsetBibtex::Latex(string & file, signed char /*fragile*/) const file += "}\n"; return 2; } - +#endif // This method returns a comma separated list of Bibtex entries string InsetBibtex::getKeys(char delim) diff --git a/src/insets/insetbib.h b/src/insets/insetbib.h index 3b862fb3e9..32063d1b86 100644 --- a/src/insets/insetbib.h +++ b/src/insets/insetbib.h @@ -128,8 +128,10 @@ public: void Edit(BufferView *, int x, int y, unsigned int button); /// int Latex(ostream &, signed char) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// string getKeys(char delim); /// diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 61d516961a..9c7c8b1bda 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -251,11 +251,13 @@ int InsetCommand::Latex(ostream & os, signed char /*fragile*/) const } +#ifndef USE_OSTREAM_ONLY int InsetCommand::Latex(string & file, signed char /*fragile*/) const { file += getCommand(); return 0; } +#endif int InsetCommand::Linuxdoc(string &/*file*/) const diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index c784b19544..bc3cb17978 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -48,8 +48,10 @@ public: void Read(LyXLex & lex); /// virtual int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// virtual int Latex(string & file, signed char fragile) const; +#endif /// virtual int Linuxdoc(string & file) const; /// diff --git a/src/insets/inseterror.C b/src/insets/inseterror.C index d41ad691db..93fbda4a4d 100644 --- a/src/insets/inseterror.C +++ b/src/insets/inseterror.C @@ -107,10 +107,12 @@ int InsetError::Latex(ostream &, signed char /*fragile*/) const } +#ifndef USE_OSTREAM_ONLY int InsetError::Latex(string &, signed char /*fragile*/) const { return 0; } +#endif int InsetError::Linuxdoc(string &) const diff --git a/src/insets/inseterror.h b/src/insets/inseterror.h index 4fe2556586..86f7c712f9 100644 --- a/src/insets/inseterror.h +++ b/src/insets/inseterror.h @@ -48,8 +48,10 @@ public: void Read(LyXLex & lex); /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & file) const; /// diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 1d7e0306df..dcbfc71a35 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -225,10 +225,12 @@ int InsetGraphics::Latex(ostream & os, signed char /*fragile*/) const } +#ifndef USE_OSTREAM_ONLY int InsetGraphics::Latex(string & /*file*/, signed char /*fragile*/) const { return 0; } +#endif int InsetGraphics::Linuxdoc(string & /*file*/) const diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 27de01f9af..f54d1f29ad 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -46,8 +46,10 @@ public: fragile commands by adding a \protect before. */ int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & /*file*/) const; /// diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index b9fdd55e03..1007ea6eef 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -317,24 +317,91 @@ bool InsetInclude::loadIfNeeded() const int InsetInclude::Latex(ostream & os, signed char /*fragile*/) const { +#ifdef USE_OSTREAM_ONLY + // Do nothing if no file name has been specified + if (contents.empty()) + return 0; + + // Use += to force a copy of contents (JMarc) + // How does that force anything? (Lgb) + string incfile(contents); + + if (loadIfNeeded()) { + Buffer * tmp = bufferlist.getBuffer(getFileName()); + + if (tmp->params.textclass != master->params.textclass) { + lyxerr << "ERROR: Cannot handle include file `" + << MakeDisplayPath(getFileName()) + << "' which has textclass `" + << textclasslist.NameOfClass(tmp->params.textclass) + << "' instead of `" + << textclasslist.NameOfClass(master->params.textclass) + << "'." << endl; + return 0; + } + + // write it to a file (so far the complete file) + string writefile = ChangeExtension(getFileName(), ".tex", false); + if (!master->tmppath.empty() + && !master->niceFile) { + incfile = subst(incfile, '/','@'); +#ifdef __EMX__ + incfile = subst(incfile, ':', '$'); +#endif + writefile = AddName(master->tmppath, incfile); + } else + writefile = getFileName(); + writefile = ChangeExtension(writefile, ".tex", false); + lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; + lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; + + tmp->markDepClean(master->tmppath); + + tmp->makeLaTeXFile(writefile, + OnlyPath(getMasterFilename()), + master->niceFile, true); + } + + if (isVerb()) { + os << '\\' << command << '{' << incfile << '}'; + } + else if (isInput()) { + // \input wants file with extension (default is .tex) + if (!IsLyXFilename(getFileName())) { + os << '\\' << command << '{' << incfile << '}'; + } else { + os << '\\' << command << '{' + << ChangeExtension(incfile, ".tex", false) + << '}'; + } + } else { + // \include don't want extension and demands that the + // file really have .tex + os << '\\' << command << '{' + << ChangeExtension(incfile, string(), false) + << '}'; + } + + return 0; +#else string include_file; signed char dummy = 0; Latex(include_file, dummy); os << include_file; return 0; +#endif } +#ifndef USE_OSTREAM_ONLY int InsetInclude::Latex(string & file, signed char /*fragile*/) const { - string writefile, incfile; - // Do nothing if no file name has been specified if (contents.empty()) return 0; // Use += to force a copy of contents (JMarc) - incfile += contents; + string incfile += contents; if (loadIfNeeded()) { Buffer * tmp = bufferlist.getBuffer(getFileName()); @@ -351,7 +418,8 @@ int InsetInclude::Latex(string & file, signed char /*fragile*/) const } // write it to a file (so far the complete file) - writefile = ChangeExtension(getFileName(), ".tex", false); + string writefile = + ChangeExtension(getFileName(), ".tex", false); if (!master->tmppath.empty() && !master->niceFile) { incfile = subst(incfile, '/','@'); @@ -400,6 +468,7 @@ int InsetInclude::Latex(string & file, signed char /*fragile*/) const return 0; } +#endif void InsetInclude::Validate(LaTeXFeatures & features) const diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 0cd817b2f2..7ea9085fa0 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -59,9 +59,10 @@ public: void Read(LyXLex &); /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; - +#endif /// void Validate(LaTeXFeatures &) const; diff --git a/src/insets/insetinfo.C b/src/insets/insetinfo.C index 848285ee59..9499ec0de2 100644 --- a/src/insets/insetinfo.C +++ b/src/insets/insetinfo.C @@ -132,10 +132,12 @@ int InsetInfo::Latex(ostream &, signed char /*fragile*/) const } +#ifndef USE_OSTREAM_ONLY int InsetInfo::Latex(string &, signed char /*fragile*/) const { return 0; } +#endif int InsetInfo::Linuxdoc(string &) const diff --git a/src/insets/insetinfo.h b/src/insets/insetinfo.h index 20ffaf207c..5fa617c66b 100644 --- a/src/insets/insetinfo.h +++ b/src/insets/insetinfo.h @@ -50,8 +50,10 @@ public: void Read(LyXLex & lex); /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & file) const; /// diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index 9e5143df54..697a524079 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -50,11 +50,13 @@ int InsetLabel::Latex(ostream & os, signed char /*fragile*/) const } +#ifndef USE_OSTREAM_ONLY int InsetLabel::Latex(string & file, signed char /*fragile*/) const { file += escape(getCommand()); return 0; } +#endif int InsetLabel::Linuxdoc(string & file) const diff --git a/src/insets/insetlabel.h b/src/insets/insetlabel.h index d4366befd6..9c95af71ef 100644 --- a/src/insets/insetlabel.h +++ b/src/insets/insetlabel.h @@ -40,8 +40,10 @@ public: unsigned char Editable() const { return 0; } /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & file) const; /// diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index 671c97d38b..0adb04841d 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -752,11 +752,13 @@ int InsetLatexAccent::Latex(ostream & os, signed char /*fragile*/) const } +#ifndef USE_OSTREAM_ONLY int InsetLatexAccent::Latex(string & file, signed char /*fragile*/) const { file += contents; return 0; } +#endif int InsetLatexAccent::Linuxdoc(string & file) const diff --git a/src/insets/insetlatexaccent.h b/src/insets/insetlatexaccent.h index 53fef7fb1e..1da3e79482 100644 --- a/src/insets/insetlatexaccent.h +++ b/src/insets/insetlatexaccent.h @@ -54,8 +54,10 @@ public: void Read(LyXLex & lex); /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & file) const; /// diff --git a/src/insets/insetparent.C b/src/insets/insetparent.C index 0fd046ddab..fb06667f8f 100644 --- a/src/insets/insetparent.C +++ b/src/insets/insetparent.C @@ -51,6 +51,7 @@ int InsetParent::Latex(ostream & os, signed char fragile) const } +#ifndef USE_OSTREAM_ONLY // LaTeX must just ignore this command int InsetParent::Latex(string & file, signed char fragile) const { @@ -58,3 +59,4 @@ int InsetParent::Latex(string & file, signed char fragile) const InsetCommand::Latex(file, fragile); return 0; } +#endif diff --git a/src/insets/insetparent.h b/src/insets/insetparent.h index 2e863c1dea..cc0ecb319d 100644 --- a/src/insets/insetparent.h +++ b/src/insets/insetparent.h @@ -33,8 +33,10 @@ public: InsetParent(string const & fn, Buffer * owner = 0); /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// Inset * Clone() const { return new InsetParent(getContents()); } /// diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index 0e731c4c96..3e044d20c5 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -226,13 +226,52 @@ void InsetQuotes::Read(LyXLex & lex) int InsetQuotes::Latex(ostream & os, signed char /*fragile*/) const { +#ifdef USE_OSTREAM_ONLY + string doclang = + current_view->buffer()->GetLanguage(); + int quoteind = quote_index[side][language]; + string qstr; + + if (lyxrc->fontenc == "T1") { + qstr = latex_quote_t1[times][quoteind]; + } + else if (doclang == "default") { + qstr = latex_quote_ot1[times][quoteind]; + } + else if (language == InsetQuotes::FrenchQ + && times == InsetQuotes::DoubleQ + && doclang == "frenchb") { + if (side == InsetQuotes::LeftQ) + qstr = "\\og{}"; + else + qstr = " \\fg{}"; + } + else + qstr = latex_quote_babel[times][quoteind]; + + // protect against !` and ?` ligatures. + // Is it very bad of us to always protect against those ligatures? +#if 0 + if ((suffixIs(file, '?') || suffixIs(file, '!')) + && qstr[0] == '`') + qstr = "{}" + qstr; +#else + // Always guard against unfortunate ligatures (!` ?`) + qstr.insert(0, "{}"); +#endif + + os << qstr; + return 0; +#else string quote; int res = Latex(quote, 0); os << quote; return res; +#endif } +#ifndef USE_OSTREAM_ONLY int InsetQuotes::Latex(string & file, signed char /*fragile*/) const { string doclang = @@ -265,6 +304,7 @@ int InsetQuotes::Latex(string & file, signed char /*fragile*/) const file += qstr; return 0; } +#endif int InsetQuotes::Linuxdoc(string & file) const diff --git a/src/insets/insetquotes.h b/src/insets/insetquotes.h index 69fbc5605d..cd554cf280 100644 --- a/src/insets/insetquotes.h +++ b/src/insets/insetquotes.h @@ -86,8 +86,10 @@ public: void Read(LyXLex & lex); /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & file) const; /// diff --git a/src/insets/insetref.C b/src/insets/insetref.C index 79dd932872..bd0fa93757 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -81,6 +81,7 @@ int InsetRef::Latex(ostream & os, signed char /*fragile*/) const } +#ifndef USE_OSTREAM_ONLY int InsetRef::Latex(string & file, signed char /*fragile*/) const { if(getOptions().empty()) @@ -93,6 +94,7 @@ int InsetRef::Latex(string & file, signed char /*fragile*/) const } return 0; } +#endif int InsetRef::Linuxdoc(string & file) const diff --git a/src/insets/insetref.h b/src/insets/insetref.h index 3644753e23..4c897c93f7 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -62,8 +62,10 @@ public: void gotoLabel(); /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & file) const; /// diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index 3c4193b08f..2db0639952 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -189,14 +189,26 @@ void InsetSpecialChar::Read(LyXLex & lex) int InsetSpecialChar::Latex(ostream & os, signed char /*fragile*/) const { +#ifdef USE_OSTREAM_ONLY + switch (kind) { + case HYPHENATION: os << "\\-"; break; + case END_OF_SENTENCE: os << "\\@."; break; + case LDOTS: os << "\\ldots{}"; break; + case MENU_SEPARATOR: os << "\\lyxarrow{}"; break; + case PROTECTED_SEPARATOR: os << "~"; break; + } + return 0; +#else string command; signed char dummy = 0; Latex(command, dummy); os << command; return 0; +#endif } +#ifndef USE_OSTREAM_ONLY int InsetSpecialChar::Latex(string & file, signed char /*fragile*/) const { switch (kind) { @@ -208,6 +220,7 @@ int InsetSpecialChar::Latex(string & file, signed char /*fragile*/) const } return 0; } +#endif int InsetSpecialChar::Linuxdoc(string & file) const diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index 8069134186..410b66ed16 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -60,8 +60,10 @@ public: void Read(LyXLex & lex); /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & file) const; /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index f8348852c5..38d2cf1f21 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -99,16 +99,18 @@ void InsetText::Write(ostream & os) const WriteParagraphData(os); } + void InsetText::WriteParagraphData(ostream & os) const { par->writeFile(os, buffer->params, 0, 0); } + void InsetText::Read(LyXLex & lex) { string token, tmptok; int pos = 0; - LyXParagraph *return_par = 0; + LyXParagraph * return_par = 0; char depth = 0; // signed or unsigned? LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE; LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE; @@ -425,8 +427,9 @@ void InsetText::InsetKeyPress(XKeyEvent * xke) } -UpdatableInset::RESULT InsetText::LocalDispatch(BufferView * bv, - int action, string const & arg) +UpdatableInset::RESULT +InsetText::LocalDispatch(BufferView * bv, + int action, string const & arg) { no_selection = false; if (UpdatableInset::LocalDispatch(bv, action, arg)) { @@ -590,22 +593,32 @@ UpdatableInset::RESULT InsetText::LocalDispatch(BufferView * bv, } -int InsetText::Latex(ostream & os, signed char fragile) const +int InsetText::Latex(ostream & os, signed char /*fragile*/) const { +#ifdef USE_OSTREAM_ONLY + string fstr; + TexRow texrow; + int ret = par->SimpleTeXOnePar(fstr, texrow); + os << fstr; + return ret; +#else string fstr; int i = Latex(fstr, fragile); os << fstr; return i; +#endif } +#ifndef USE_OSTREAM_ONLY int InsetText::Latex(string & file, signed char /* fragile */) const { TexRow texrow; return par->SimpleTeXOnePar(file, texrow); } +#endif void InsetText::Validate(LaTeXFeatures & features) const diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 7220ad8416..b1b1ae94dd 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -81,8 +81,10 @@ public: UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &); /// int Latex(ostream &, signed char) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string &, signed char) const; +#endif /// int Linuxdoc(string &) const { return 0; } /// diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index af46990837..9416d82660 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -168,14 +168,24 @@ string InsetUrl::getScreenLabel() const int InsetUrl::Latex(ostream & os, signed char fragile) const { +#ifdef USE_OSTREAM_ONLY + if (!getOptions().empty()) + os << getOptions() + ' '; + if (fragile) + os << "\\protect"; + os << "\\url{" << getContents() << '}'; + return 0; +#else string latex_output; int res = Latex(latex_output, fragile); os << latex_output; return res; +#endif } +#ifndef USE_OSTREAM_ONLY int InsetUrl::Latex(string & file, signed char fragile) const { if (!getOptions().empty()) @@ -187,6 +197,7 @@ int InsetUrl::Latex(string & file, signed char fragile) const return 0; } +#endif int InsetUrl::Linuxdoc(string & file) const diff --git a/src/insets/inseturl.h b/src/insets/inseturl.h index c60de849fd..f6f84f4acf 100644 --- a/src/insets/inseturl.h +++ b/src/insets/inseturl.h @@ -71,8 +71,10 @@ public: void gotoLabel(); /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & file) const; /// diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index c0db3273dc..5c3b3ee908 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -26,6 +26,8 @@ class BufferView; struct LaTeXFeatures; +#define USE_OSTREAM_ONLY 1 + /// Insets class Inset { public: @@ -113,8 +115,10 @@ public: fragile commands by adding a \protect before. */ virtual int Latex(ostream &, signed char fragile) const = 0; +#ifndef USE_OSTREAM_ONLY /// virtual int Latex(string & file, signed char fragile) const = 0; +#endif /// virtual int Linuxdoc(string & /*file*/) const = 0; /// diff --git a/src/lyxlookup.C b/src/lyxlookup.C index 437ca99d09..4e0d1f9494 100644 --- a/src/lyxlookup.C +++ b/src/lyxlookup.C @@ -20,6 +20,7 @@ #ifdef HAVE_LOCALE_H #include #endif +#include #include "debug.h" diff --git a/src/mathed/formula.C b/src/mathed/formula.C index e2e957533a..d98625962f 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -59,7 +59,8 @@ int MathedInset::df_des; int MathedInset::df_width; -inline bool IsMacro(short token, int id) +inline +bool IsMacro(short token, int id) { return (token != LM_TK_FRAC && token != LM_TK_SQRT && !((token == LM_TK_SYM || token == LM_TC_BSYM) && id < 255)); @@ -147,7 +148,7 @@ void mathed_init_fonts() //removed 'static' because DEC cxx does not Math_Fonts = new LyXFont[8]; //DEC cxx cannot initialize all fonts //at once (JMarc) rc - for (int i = 0 ; i < 8 ; ++i){ + for (int i = 0 ; i < 8 ; ++i) { Math_Fonts[i] = LyXFont(LyXFont::ALL_SANE); } Math_Fonts[0].setShape(LyXFont::ITALIC_SHAPE); @@ -307,12 +308,21 @@ int InsetFormula::Latex(ostream & os, signed char fragile) const //#warning Alejandro, the number of lines is not returned in this case // This problem will disapear at 0.13. string output; +#ifdef USE_OSTREAM_ONLY + if (fragile < 0) + par->Write(output); + else + mathed_write(par, output, &ret, fragile, label.c_str()); + +#else InsetFormula::Latex(output, fragile); +#endif os << output; return ret; } +#ifndef USE_OSTREAM_ONLY int InsetFormula::Latex(string & file, signed char fragile) const { int ret = 0; @@ -324,6 +334,7 @@ int InsetFormula::Latex(string & file, signed char fragile) const mathed_write(par, file, &ret, fragile, label.c_str()); return ret; } +#endif int InsetFormula::Linuxdoc(string &/*file*/) const diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 551ab6b2c4..7c87264e50 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -50,8 +50,10 @@ public: void Read(LyXLex & lex); /// int Latex(ostream &, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & file) const; /// diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index 0b5d5025a6..d971ac8b2b 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -78,12 +78,14 @@ int InsetFormulaMacro::Latex(ostream & os, signed char /*fragile*/) const } +#ifndef USE_OSTREAM_ONLY int InsetFormulaMacro::Latex(string &file, signed char /*fragile*/) const { int ret = 1; tmacro->WriteDef(file); return ret; } +#endif int InsetFormulaMacro::Linuxdoc(string &/*file*/) const diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index b4a76021fb..8b9a6ae6c1 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -49,8 +49,10 @@ public: void Write(ostream & os) const; /// int Latex(ostream & os, signed char fragile) const; +#ifndef USE_OSTREAM_ONLY /// int Latex(string & file, signed char fragile) const; +#endif /// int Linuxdoc(string & file) const; /// diff --git a/src/mathed/math_utils.C b/src/mathed/math_utils.C index a5fb789cce..d13408c8ff 100644 --- a/src/mathed/math_utils.C +++ b/src/mathed/math_utils.C @@ -65,11 +65,13 @@ binary_op_pair binary_op_table[] = { struct compara { // used by sort + inline int operator()(binary_op_pair const & a, binary_op_pair const & b) const { return a.id < b.id; } // used by lower_bound + inline int operator()(binary_op_pair const & a, short int id) const { return a.id < id; } @@ -78,7 +80,8 @@ struct compara { int MathedLookupBOP(short id) { - static int bopCount = sizeof(binary_op_table) / sizeof(binary_op_pair); + static int const bopCount = + sizeof(binary_op_table) / sizeof(binary_op_pair); static bool issorted = false; if (!issorted) { @@ -89,7 +92,7 @@ int MathedLookupBOP(short id) binary_op_pair * res = lower_bound(binary_op_table, binary_op_table + bopCount, id, compara()); - if (res->id == id) + if (res != binary_op_table + bopCount && res->id == id) return res->isrel; else return LMB_NONE; diff --git a/src/paragraph.C b/src/paragraph.C index 2504a391ba..7da6e8ce0a 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1930,9 +1930,24 @@ LyXParagraph * LyXParagraph::TeXOnePar(string & file, TexRow & texrow, file += style.latexparam(); break; case LATEX_ITEM_ENVIRONMENT: - if (bibkey) + if (bibkey) { +#ifdef USE_OSTREAM_ONLY +#ifdef HAVE_SSTREAM + ostringstream ost; + bibkey->Latex(ost, false); + file += ost.str().c_str(); +#else + ostrstream ost; + bibkey->Latex(ost, false); + ost << '\0'; + char * tmp = ost.str(); + file += tmp; + delete [] tmp; +#endif +#else bibkey->Latex(file, false); - else +#endif + } else file += "\\item "; break; case LATEX_LIST_ENVIRONMENT: @@ -2942,7 +2957,22 @@ void LyXParagraph::SimpleTeXSpecialChars(string & file, TexRow & texrow, file += "\\L{"; close = true; } +#ifdef USE_OSTREAM_ONLY +#ifdef HAVE_SSTREAM + ostringstream ost; + int tmp = inset->Latex(ost, style.isCommand()); + file += ost.str().c_str(); +#else + ostrstream ost; + int tmp = inset->Latex(ost, style.isCommand()); + ost << '\0'; + char * chtmp = ost.str(); + file += chtmp; + delete [] chtmp; +#endif +#else int tmp = inset->Latex(file, style.isCommand()); +#endif if (close) file += "}"; diff --git a/src/support/filetools.C b/src/support/filetools.C index a19bc74f03..9f1f1061a6 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -1025,6 +1025,25 @@ string findtexfile(string const & fil, string const & /*format*/) return MakeAbsPath(fil); // No we try to find it using kpsewhich. + // It seems from the kpsewhich manual page that it is safe to use + // kpsewhich without --format: "When the --format option is not + // given, the search path used when looking for a file is inferred + // from the name given, by looking for a known extension. If no + // known extension is found, the search path for TeX source files + // is used." + // However, we want to take advantage of the format sine almost all + // the different formats has environment variables that can be used + // to controll which paths to search. f.ex. bib looks in + // BIBINPUTS and TEXBIB. Small list follows: + // bib - BIBINPUTS, TEXBIB + // bst - BSTINPUTS + // graphic/figure - TEXPICTS, TEXINPUTS + // ist - TEXINDEXSTYLE, INDEXSTYLE + // pk - PROGRAMFONTS, PKFONTS, TEXPKS, GLYPHFONTS, TEXFONTS + // tex - TEXINPUTS + // tfm - TFMFONTS, TEXFONTS + // This means that to use kpsewhich in the best possible way we + // should help it by setting additional path in the approp. envir.var. string kpsecmd = "kpsewhich " + fil; cmdret c = do_popen(kpsecmd); diff --git a/src/text.C b/src/text.C index 2bc2b48923..e987c96765 100644 --- a/src/text.C +++ b/src/text.C @@ -2958,18 +2958,39 @@ char * LyXText::SelectNextWord(float & value) /* Start the selection from here */ sel_cursor = cursor; +#ifdef USE_OSTREAM_ONLY +#ifdef HAVE_SSTREAM + ostringstream latex; +#else + ostrstream latex; +#endif +#else string latex; - +#endif /* and find the end of the word (optional hyphens are part of a word) */ while (cursor.pos < cursor.par->Last() && (cursor.par->IsLetter(cursor.pos)) - || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET && - cursor.par->GetInset(cursor.pos) != 0 && - cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 && - latex == "\\-")) + || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET + && cursor.par->GetInset(cursor.pos) != 0 + && cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 +#ifdef USE_OSTREAM_ONLY +#ifdef HAVE_SSTREAM + && latex.str() == "\\-" +#else + && string(latex.str(), 3) == "\\-" // this is not nice at all +#endif +#else + && latex == "\\-" +#endif + )) cursor.pos++; +#ifdef USE_OSTREAM_ONLY +#ifndef HAVE_SSTREAM + delete [] latex.str(); +#endif +#endif // Finally, we copy the word to a string and return it char * str = 0; @@ -2995,17 +3016,39 @@ void LyXText::SelectSelectedWord() /* set the sel cursor */ sel_cursor = cursor; +#ifdef USE_OSTREAM_ONLY +#ifdef HAVE_SSTREAM + ostringstream latex; +#else + ostrstream latex; +#endif +#else string latex; +#endif /* now find the end of the word */ while (cursor.pos < cursor.par->Last() && (cursor.par->IsLetter(cursor.pos) - || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET && - cursor.par->GetInset(cursor.pos) != 0 && - cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 && - latex == "\\-"))) + || (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET + && cursor.par->GetInset(cursor.pos) != 0 + && cursor.par->GetInset(cursor.pos)->Latex(latex, 0) == 0 +#ifdef USE_OSTREAM_ONLY +#ifdef HAVE_SSTREAM + && latex.str() == "\\-" +#else + && string(latex.str(), 3) == "\\-" +#endif +#else + && latex == "\\-" +#endif + ))) cursor.pos++; +#ifdef USE_OSTREAM_ONLY +#ifndef HAVE_SSTREAM + delete [] latex.str(); +#endif +#endif SetCursor(cursor.par, cursor.pos); /* finally set the selection */ @@ -4149,7 +4192,7 @@ int LyXText::GetColumnNearX(Row * row, int & x) const LyXDirection direction = row->par->getParDirection(); LyXParagraph::size_type vc = row->pos; LyXParagraph::size_type last = RowLast(row); - LyXParagraph::size_type c; + LyXParagraph::size_type c = 0; LyXLayout const & layout = textclasslist.Style(parameters->textclass, row->par->GetLayout());