+2000-07-01 José Abílio Matos <jamatos@fep.up.pt>
+ * 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 <larsbj@lyx.org>
* src/BufferView_pimpl.h: remove member variables lyx_focus and
}
+string LaTeXFeatures::getIncludedFiles()
+{
+ string sgmlpreamble;
+
+ for(FileMap::const_iterator fi=IncludedFiles.begin(); fi != IncludedFiles.end(); ++fi)
+ sgmlpreamble += "\n<!entity " + fi->first + " system \"" + fi->second + "\">";
+
+ return sgmlpreamble;
+}
+
+
void LaTeXFeatures::showStruct() {
lyxerr << "LyX needs the following commands when LaTeXing:"
<< "\n***** Packages:" << getPackages()
string getMacros();
/// The definitions needed by the document's textclass
string getTClassPreamble();
+ ///
+ string getIncludedFiles();
///
void showStruct();
typedef std::set<string> FloatList;
///
FloatList usedFloats;
+ ///
+ typedef map<string , string> FileMap;
+ ///
+ FileMap IncludedFiles;
//@}
BufferParams const & bufferParams() const;
private:
}
-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;
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 << "<!doctype linuxdoc system>\n\n";
- }
- else {
- ofs << "<!doctype linuxdoc system \n [ "
- << params.preamble << " \n]>\n\n";
+
+ if (!body_only) {
+ string sgml_includedfiles=features.getIncludedFiles();
+
+ if (params.preamble.empty() && sgml_includedfiles.empty()) {
+ ofs << "<!doctype linuxdoc system>\n\n";
+ }
+ else {
+ ofs << "<!doctype linuxdoc system [ "
+ << 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);
+ }
}
ofs << "<!-- " << LYX_DOCVERSION
<< " created this file. For more info see http://www.lyx.org/"
<< " -->\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 <toc> as a special case for compatibility with old code
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
}
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)
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];
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) {
texrow.reset();
- ofs << "<!doctype " << top_element
- << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
+ if(!only_body) {
+ string sgml_includedfiles=features.getIncludedFiles();
- if (params.preamble.empty())
- ofs << ">\n\n";
- else
- ofs << "\n [ " << params.preamble << " \n]>\n\n";
+ ofs << "<!doctype " << top_element
+ << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
- ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
- << "\n See http://www.lyx.org/ for more information -->\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 << "<!-- DocBook file was created by " << LYX_DOCVERSION
+ << "\n See http://www.lyx.org/ for more information -->\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
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
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 {
}
+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 << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+ } 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 << "<!-- includefile verbatim=\"" << incfile << "\" -->";
+ } 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;
///
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
Buffer * master;
///
string filename;
+ ///
+ string include_label;
};
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));
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));
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
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')
type = "ascii";
if (type == "latex" || type == "postscript"
+ || type == "linuxdoc" || type == "docbook"
|| type == "ascii" || type == "html")
batch_command = "buffer-export " + type;
else