mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
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
This commit is contained in:
parent
2dbd47535d
commit
38f5ce268a
27
ChangeLog
27
ChangeLog
@ -1,3 +1,30 @@
|
||||
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
|
||||
|
@ -332,6 +332,17 @@ string LaTeXFeatures::getTClassPreamble()
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
|
@ -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<string> FloatList;
|
||||
///
|
||||
FloatList usedFloats;
|
||||
///
|
||||
typedef map<string , string> FileMap;
|
||||
///
|
||||
FileMap IncludedFiles;
|
||||
//@}
|
||||
BufferParams const & bufferParams() const;
|
||||
private:
|
||||
|
129
src/buffer.C
129
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 << "<!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
|
||||
@ -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 << "<!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\"";
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
|
||||
<< "\n See http://www.lyx.org/ for more information -->\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);
|
||||
|
||||
// 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
|
||||
|
@ -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 {
|
||||
|
@ -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 << "<!-- 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;
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user