From: José Matox Date: Sat, 1 Jul 2000 12:54:45 +0000 (+0000) Subject: Include file inset now works with linuxdoc and docbook. X-Git-Tag: 1.6.10~22144 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=38f5ce268a94c6d47f77fbdd6b6dd9c8bd34b7f6;p=features.git Include file inset now works with linuxdoc and docbook. Several small cleanups regarding docbook and linuxdoc code, (see Changelog). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@851 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index 6c8f432e98..71d09cef3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2000-07-01 José Abílio Matos + * src/LaTeXFeatures.h: new member IncludedFiles, for + a map of key, included file name. + + * src/LaTeXFeatures.C (getIncludedFiles): returns a string + with the included files for inclusion in SGML preamble, + i. e., linuxdoc and docbook. + + * src/buffer.h: + * src/buffer.C (makeLinuxDocFile): takes two new arguments, + nice (is the generated linuxdoc code to be exported?), that + allows to remove column, and only_body that will be true for + slave documents. Insets are allowed inside SGML font type. + New handling of the SGML preamble for included files. + (makeDocBookFile): the same for docbook. + + * src/insets/insetinclude.h: + * src/insets/insetinclude.C (Validate): keeps a list of included files. + (Linuxdoc): + (DocBook): new export methods. + + * src/lyx_cb.C: adjust to the new calling sequence for makeLinuxDocFile + and makeDocBookFile. + + * src/lyx_main.C (easyParse): accept linuxdoc and docbook as + formats to export with command line argument -x. + 2000-06-28 Lars Gullik Bjønnes * src/BufferView_pimpl.h: remove member variables lyx_focus and diff --git a/src/LaTeXFeatures.C b/src/LaTeXFeatures.C index 67341747bd..d64f96b3ee 100644 --- a/src/LaTeXFeatures.C +++ b/src/LaTeXFeatures.C @@ -332,6 +332,17 @@ string LaTeXFeatures::getTClassPreamble() } +string LaTeXFeatures::getIncludedFiles() +{ + string sgmlpreamble; + + for(FileMap::const_iterator fi=IncludedFiles.begin(); fi != IncludedFiles.end(); ++fi) + sgmlpreamble += "\nfirst + " system \"" + fi->second + "\">"; + + return sgmlpreamble; +} + + void LaTeXFeatures::showStruct() { lyxerr << "LyX needs the following commands when LaTeXing:" << "\n***** Packages:" << getPackages() diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index 70054ca33d..1446ebe64a 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -40,6 +40,8 @@ struct LaTeXFeatures { string getMacros(); /// The definitions needed by the document's textclass string getTClassPreamble(); + /// + string getIncludedFiles(); /// void showStruct(); @@ -152,6 +154,10 @@ struct LaTeXFeatures { typedef std::set FloatList; /// FloatList usedFloats; + /// + typedef map FileMap; + /// + FileMap IncludedFiles; //@} BufferParams const & bufferParams() const; private: diff --git a/src/buffer.C b/src/buffer.C index 1d4b8dc059..bb1d109db1 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -2149,10 +2149,12 @@ void Buffer::sgmlCloseTag(ostream & os, int depth, } -void Buffer::makeLinuxDocFile(string const & fname, int column) +void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) { LyXParagraph * par = paragraph; + niceFile = nice; // this will be used by Insetincludes. + string top_element = textclasslist.LatexnameOfClass(params.textclass); string environment_stack[10]; string item_name; @@ -2165,35 +2167,49 @@ void Buffer::makeLinuxDocFile(string const & fname, int column) WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname); return; } - - tex_code_break_column = column; + + 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; + texrow.reset(); - - if (params.preamble.empty()) { - ofs << "\n\n"; - } - else { - ofs << "\n\n"; + + if (!body_only) { + string sgml_includedfiles=features.getIncludedFiles(); + + if (params.preamble.empty() && sgml_includedfiles.empty()) { + ofs << "\n\n"; + } + else { + 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); + } } ofs << "\n"; - if(params.options.empty()) - sgmlOpenTag(ofs, 0, top_element); - else { - string top = top_element; - top += " "; - top += params.options; - sgmlOpenTag(ofs, 0, top); - } - while (par) { int desc_on = 0; // description mode LyXLayout const & style = - textclasslist.Style(users->buffer()->params.textclass, + textclasslist.Style(params.textclass, par->layout); // treat as a special case for compatibility with old code @@ -2314,8 +2330,10 @@ void Buffer::makeLinuxDocFile(string const & fname, int column) if(!environment_stack[depth].empty()) sgmlCloseTag(ofs, depth, environment_stack[depth]); - ofs << "\n\n"; - sgmlCloseTag(ofs, 0, top_element); + if (!body_only) { + ofs << "\n\n"; + sgmlCloseTag(ofs, 0, top_element); + } ofs.close(); // How to check for successful close @@ -2659,15 +2677,17 @@ void Buffer::SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par, } c = par->GetChar(i); - + + if (c == LyXParagraph::META_INSET) { + inset = par->GetInset(i); + inset->Linuxdoc(this, os); + } + if (font2.latex() == LyXFont::ON) { // "TeX"-Mode on == > SGML-Mode on. if (c != '\0') os << c; // see LaTeX-Generation... ++char_line_count; - } else if (c == LyXParagraph::META_INSET) { - inset = par->GetInset(i); - inset->Linuxdoc(this, os); } else { string sgml_string; if (par->linuxDocConvertChar(c, sgml_string) @@ -2738,10 +2758,12 @@ void Buffer::LinuxDocError(LyXParagraph * par, int pos, enum { MAX_NEST_LEVEL = 25}; -void Buffer::makeDocBookFile(string const & fname, int column) +void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) { LyXParagraph * par = paragraph; + niceFile = nice; // this will be used by Insetincludes. + string top_element= textclasslist.LatexnameOfClass(params.textclass); // Please use a real stack. string environment_stack[MAX_NEST_LEVEL]; @@ -2755,8 +2777,16 @@ void Buffer::makeDocBookFile(string const & fname, int column) string c_depth, c_params, tmps; int depth = 0; // paragraph depth + LyXTextClass const & tclass = + textclasslist.TextClass(params.textclass); - tex_code_break_column = column; + 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) { @@ -2766,30 +2796,35 @@ void Buffer::makeDocBookFile(string const & fname, int column) texrow.reset(); - ofs << "\n\n"; - else - ofs << "\n [ " << params.preamble << " \n]>\n\n"; + ofs << "\n"; + if (params.preamble.empty() && sgml_includedfiles.empty()) + ofs << ">\n\n"; + else + ofs << "\n [ " << params.preamble + << sgml_includedfiles << " \n]>\n\n"; - if(params.options.empty()) - sgmlOpenTag(ofs, 0, top_element); - else { - string top = top_element; - top += " "; - top += params.options; - sgmlOpenTag(ofs, 0, top); + if(params.options.empty()) + sgmlOpenTag(ofs, 0, top_element); + else { + string top = top_element; + top += " "; + top += params.options; + sgmlOpenTag(ofs, 0, top); + } } + ofs << "\n"; + while (par) { int desc_on = 0; // description mode LyXLayout const & style = - textclasslist.Style(users->buffer()->params.textclass, + textclasslist.Style(params.textclass, par->layout); // environment tag closing @@ -3011,8 +3046,10 @@ void Buffer::makeDocBookFile(string const & fname, int column) if(!command_stack[j].empty()) sgmlCloseTag(ofs, j, command_stack[j]); - ofs << "\n\n"; - sgmlCloseTag(ofs, 0, top_element); + if (!only_body) { + ofs << "\n\n"; + sgmlCloseTag(ofs, 0, top_element); + } ofs.close(); // How to check for successful close diff --git a/src/buffer.h b/src/buffer.h index 6e02dfce38..9f968892a8 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -171,9 +171,11 @@ public: int runChktex(); /// - void makeLinuxDocFile(string const & filename, int column); + void makeLinuxDocFile(string const & filename, + bool nice, bool only_body = false); /// - void makeDocBookFile(string const & filename, int column); + void makeDocBookFile(string const & filename, + bool nice, bool only_body = false); /// returns the main language for the buffer (document) string GetLanguage() const { diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 3f51118155..9bc670cf7b 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -404,8 +404,115 @@ int InsetInclude::Latex(Buffer const *, ostream & os, } +int InsetInclude::Linuxdoc(Buffer const *, ostream & os) const +{ + // Do nothing if no file name has been specified + if (getContents().empty()) + return 0; + + string incfile(getContents()); + + if (loadIfNeeded()) { + Buffer * tmp = bufferlist.getBuffer(getFileName()); + + // write it to a file (so far the complete file) + string writefile = ChangeExtension(getFileName(), ".sgml"); + if (!master->tmppath.empty() && !master->niceFile) { + incfile = subst(incfile, '/','@'); + writefile = AddName(master->tmppath, incfile); + } else + writefile = getFileName(); + + if(IsLyXFilename(getFileName())) + writefile = ChangeExtension(writefile, ".sgml"); + + lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; + lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; + + tmp->makeLinuxDocFile(writefile, master->niceFile, true); + } + + if (isVerb()) { + os << ""; + } else + os << '&' << include_label << ';'; + + return 0; +} + + +int InsetInclude::DocBook(Buffer const *, ostream & os) const +{ + // Do nothing if no file name has been specified + if (getContents().empty()) + return 0; + + string incfile(getContents()); + + if (loadIfNeeded()) { + Buffer * tmp = bufferlist.getBuffer(getFileName()); + + // write it to a file (so far the complete file) + string writefile = ChangeExtension(getFileName(), ".sgml"); + if (!master->tmppath.empty() && !master->niceFile) { + incfile = subst(incfile, '/','@'); + writefile = AddName(master->tmppath, incfile); + } else + writefile = getFileName(); + if(IsLyXFilename(getFileName())) + writefile = ChangeExtension(writefile, ".sgml"); + + lyxerr[Debug::LATEX] << "incfile:" << incfile << endl; + lyxerr[Debug::LATEX] << "writefile:" << writefile << endl; + + tmp->makeDocBookFile(writefile, master->niceFile, true); + } + + if (isVerb()) { + os << ""; + } else + os << '&' << include_label << ';'; + + return 0; +} + + +static unsigned int unique_id() { + static unsigned int seed=1000; + + return ++seed; +} + + void InsetInclude::Validate(LaTeXFeatures & features) const { + +#ifdef HAVE_SSTREAM + std::ostringstream ost; + ost << "file" << unique_id(); + include_label = ost.str(); +#else + char ctmp[16]; + ostrstream ost(ctmp,16); + ost << "file" << unique_id() << '\0'; + include_label = ost.str(); +#endif + + string incfile(getContents()); + string writefile = ChangeExtension(getFileName(), ".sgml"); + if (!master->tmppath.empty() && !master->niceFile) { + incfile = subst(incfile, '/','@'); + writefile = AddName(master->tmppath, incfile); + } else + // writefile = getFileName(); + // Use the relative path. + writefile = incfile; + + if(IsLyXFilename(getFileName())) + writefile = ChangeExtension(writefile, ".sgml"); + + features.IncludedFiles[include_label] = writefile; + if (isVerb()) features.verbatim = true; diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 90c1f71ef9..8bb15af631 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -58,6 +58,10 @@ public: /// int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const; /// + int Linuxdoc(Buffer const *, std::ostream &) const; + /// + int DocBook(Buffer const *, std::ostream &) const; + /// void Validate(LaTeXFeatures &) const; /// Input inserts anything inside a paragraph, Display can give some visual feedback @@ -120,6 +124,8 @@ private: Buffer * master; /// string filename; + /// + string include_label; }; diff --git a/src/lyx_cb.C b/src/lyx_cb.C index ebf9ceb814..b8cbbb89a2 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -743,7 +743,7 @@ void MenuMakeLinuxDoc(Buffer * buffer) ShowMessage(buffer, _("Building LinuxDoc SGML file `"), MakeDisplayPath(s),"'..."); - buffer->makeLinuxDocFile(s, 65); + buffer->makeLinuxDocFile(s, true); buffer->redraw(); ShowMessage(buffer, _("LinuxDoc SGML file save as"), MakeDisplayPath(s)); @@ -770,7 +770,7 @@ void MenuMakeDocBook(Buffer * buffer) ShowMessage(buffer, _("Building DocBook SGML file `"), MakeDisplayPath(s), "'..."); - buffer->makeDocBookFile(s, 65); + buffer->makeDocBookFile(s, true); buffer->redraw(); ShowMessage(buffer, _("DocBook SGML file save as"), MakeDisplayPath(s)); @@ -1212,7 +1212,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename) if (!bv->available()) return 0; - bv->buffer()->makeLinuxDocFile(name, 0); + bv->buffer()->makeLinuxDocFile(name, false); // CHECK remove this once we have a proper geometry class @@ -1273,7 +1273,7 @@ int RunDocBook(int flag, string const & filename) if (!current_view->available()) return 0; - current_view->buffer()->makeDocBookFile(name, 0); + current_view->buffer()->makeDocBookFile(name, false); // Shall this code go or should it stay? (Lgb) // This code is a placeholder for future implementation. (Jose') diff --git a/src/lyx_main.C b/src/lyx_main.C index 585ef8da55..db2e00c1aa 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -682,6 +682,7 @@ bool LyX::easyParse(int * argc, char * argv[]) type = "ascii"; if (type == "latex" || type == "postscript" + || type == "linuxdoc" || type == "docbook" || type == "ascii" || type == "html") batch_command = "buffer-export " + type; else