SGML patch from Jose'

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1214 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2000-11-13 15:43:36 +00:00
parent 7581869fc6
commit 000001c24b
11 changed files with 104 additions and 38 deletions

View File

@ -1,3 +1,35 @@
2000-11-13 José Abílio Matos <jamatos@fep.up.pt>
* lib/layouts/docbook-book.layout
* lib/layouts/docbook.layout
* lib/layouts/linuxdoc.layout: No need for "dummy" paragraphs, now
those paragraphs are expresse as SGML comments <!-- -->.
* src/LaTeXFeatures.h
* src/LaTeXFeatures.C (getIncludedFiles): takes a filename as
parameter, this allows to express all the include files as relative
paths to the master buffer. The verbatim insert works as the other
include file modes.
* src/buffer.C (sgmlOpenTag) (sgmlCloseTag): don't write if latexname
is a SGML comment.
(MakeLinuxdocFile) (MakeDocBookFile): included files are relative
to master path.
(MakeDocBookFile): top_element is always written. Some clean up, as
sgmlOpenTag() and sgmlCloseTag() take care of the SGML comment case.
* src/insets/insetinclude.C (Linuxdoc): Added verbatim file fix.
(DocBook) added close tag to inlinegraphics trick for verbatim. Now
a reference is written instead of the name.
(Validate): use the relative path for the filename.
* src/insets/insetlabel.C (DocBook): write end tag, for XML
compatibility.
* src/support/filetools.h
* src/support/filetools.C (IsSGMLFilename): added.
(BasePath): added.
2000-11-13 Miyata Shigeru <miyata@kusm.kyoto-u.ac.jp>
* development/OS2/quick_fix.patch:

View File

@ -163,6 +163,7 @@ End
# SGML style definition
Style SGML
CopyStyle LaTeX
LatexName "!-- --"
End
# There are no chapters or parts in an docbook article.

View File

@ -153,6 +153,7 @@ End
# SGML style definition
Style SGML
CopyStyle LaTeX
LatexName "!-- --"
End
# There are no chapters or parts in an docbook article.

View File

@ -368,7 +368,7 @@ End
Style SGML
Margin Static
LatexType Paragraph
LatexName dummy
LatexName "!-- --"
NewLine 0
ParIndent MM
ParSkip 0.4

View File

@ -22,7 +22,7 @@
#include "LaTeXFeatures.h"
#include "bufferparams.h"
#include "layout.h"
#include "support/filetools.h"
using std::endl;
LaTeXFeatures::LaTeXFeatures(BufferParams const & p, LyXTextClass::size_type n)
@ -338,14 +338,17 @@ string const LaTeXFeatures::getTClassPreamble()
}
string const LaTeXFeatures::getIncludedFiles()
string const LaTeXFeatures::getIncludedFiles(string const fname) const
{
string sgmlpreamble;
string basename = BasePath(fname);
FileMap::const_iterator end = IncludedFiles.end();
for (FileMap::const_iterator fi = IncludedFiles.begin();
fi != end; ++fi)
sgmlpreamble += "\n<!entity " + fi->first
+ " system \"" + fi->second + "\">";
sgmlpreamble += "\n<!ENTITY " + fi->first
+ (IsSGMLFilename(fi->second) ? " SYSTEM \"" : " \"" )
+ MakeRelPath(fi->second,basename) + "\">";
return sgmlpreamble;
}

View File

@ -42,7 +42,7 @@ struct LaTeXFeatures {
/// The definitions needed by the document's textclass
string const getTClassPreamble();
///
string const getIncludedFiles();
string const getIncludedFiles(string const fname) const;
///
void showStruct();

View File

@ -2336,6 +2336,7 @@ bool Buffer::isSGML() const
void Buffer::sgmlOpenTag(ostream & os, int depth,
string const & latexname) const
{
if (latexname != "!-- --")
os << string(depth, ' ') << "<" << latexname << ">\n";
}
@ -2343,6 +2344,7 @@ void Buffer::sgmlOpenTag(ostream & os, int depth,
void Buffer::sgmlCloseTag(ostream & os, int depth,
string const & latexname) const
{
if (latexname != "!-- --")
os << string(depth, ' ') << "</" << latexname << ">\n";
}
@ -2380,7 +2382,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
texrow.reset();
if (!body_only) {
string sgml_includedfiles=features.getIncludedFiles();
string sgml_includedfiles=features.getIncludedFiles(fname);
if (params.preamble.empty() && sgml_includedfiles.empty()) {
ofs << "<!doctype linuxdoc system>\n\n";
@ -3000,7 +3002,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
texrow.reset();
if (!only_body) {
string sgml_includedfiles=features.getIncludedFiles();
string sgml_includedfiles=features.getIncludedFiles(fname);
ofs << "<!doctype " << top_element
<< " public \"-//OASIS//DTD DocBook V3.1//EN\"";
@ -3010,6 +3012,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
else
ofs << "\n [ " << params.preamble
<< sgml_includedfiles << " \n]>\n\n";
}
if (params.options.empty())
sgmlOpenTag(ofs, 0, top_element);
@ -3019,7 +3022,6 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
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";
@ -3069,9 +3071,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
// Write opening SGML tags.
switch (style.latextype) {
case LATEX_PARAGRAPH:
if (style.latexname() != "dummy")
sgmlOpenTag(ofs, depth+command_depth,
style.latexname());
sgmlOpenTag(ofs, depth+command_depth, style.latexname());
break;
case LATEX_COMMAND:
@ -3124,6 +3124,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
sgmlOpenTag(ofs, depth + command_depth, command_name);
item_name = "title";
if (command_name != "!-- --")
sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
break;
@ -3203,6 +3204,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
switch (style.latextype) {
case LATEX_COMMAND:
end_tag = "title";
if (command_name != "!-- --")
sgmlCloseTag(ofs, depth + command_depth, end_tag);
break;
case LATEX_ENVIRONMENT:
@ -3216,13 +3218,10 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
break;
case LATEX_PARAGRAPH:
if (style.latexname() != "dummy")
sgmlCloseTag(ofs, depth + command_depth,
style.latexname());
sgmlCloseTag(ofs, depth + command_depth, style.latexname());
break;
default:
sgmlCloseTag(ofs, depth + command_depth,
style.latexname());
sgmlCloseTag(ofs, depth + command_depth, style.latexname());
break;
}
}
@ -3248,10 +3247,8 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
if (!command_stack[j].empty())
sgmlCloseTag(ofs, j, command_stack[j]);
if (!only_body) {
ofs << "\n\n";
sgmlCloseTag(ofs, 0, top_element);
}
ofs.close();
// How to check for successful close

View File

@ -451,7 +451,9 @@ int InsetInclude::Linuxdoc(Buffer const * buffer, ostream & os) const
}
if (isVerb()) {
os << "<!-- includefile verbatim=\"" << incfile << "\" -->";
os << "<inlinegraphic fileref=\"" << '&' << include_label << ';'
<< "\" format=\"linespecific\">"
<< "</inlinegraphic>";
} else
os << '&' << include_label << ';';
@ -487,7 +489,9 @@ int InsetInclude::DocBook(Buffer const * buffer, ostream & os) const
}
if (isVerb()) {
os << "<inlinegraphic fileref=\"" << incfile << "\" format=\"linespecific\">";
os << "<inlinegraphic fileref=\"" << '&' << include_label << ';'
<< "\" format=\"linespecific\">"
<< "</inlinegraphic>";
} else
os << '&' << include_label << ';';
@ -499,14 +503,15 @@ void InsetInclude::Validate(LaTeXFeatures & features) const
{
string incfile(getContents());
string writefile = ChangeExtension(getFileName(), ".sgml");
string writefile; // = ChangeExtension(getFileName(), ".sgml");
if (!master->tmppath.empty() && !master->niceFile) {
incfile = subst(incfile, '/','@');
writefile = AddName(master->tmppath, incfile);
} else
// writefile = getFileName();
writefile = getFileName();
// Use the relative path.
writefile = incfile;
//writefile = incfile;
if (IsLyXFilename(getFileName()))
writefile = ChangeExtension(writefile, ".sgml");

View File

@ -88,7 +88,7 @@ int InsetLabel::Linuxdoc(Buffer const *, ostream & os) const
int InsetLabel::DocBook(Buffer const *, ostream & os) const
{
os << "<anchor id=\"" << getContents() << "\" >";
os << "<anchor id=\"" << getContents() << "\" ></anchor>";
return 0;
}

View File

@ -79,6 +79,12 @@ bool IsLyXFilename(string const & filename)
}
bool IsSGMLFilename(string const & filename)
{
return contains(filename, ".sgml");
}
// Substitutes spaces with underscores in filename (and path)
string const MakeLatexName(string const & file)
{
@ -733,6 +739,21 @@ string const OnlyFilename(string const & fname)
}
// Strips filename from path
string const BasePath(string const & fname)
{
if (fname.empty())
return fname;
string::size_type j = fname.rfind('/');
if (j == string::npos) // no '/' in fname
return string();
// Strip to basename
return fname.substr(0,j + 1);
}
// Is a filename/path absolute?
bool AbsolutePath(string const & path)
{

View File

@ -83,6 +83,9 @@ int IsFileWriteable (string const & path);
///
bool IsLyXFilename(string const & filename);
///
bool IsSGMLFilename(string const & filename);
/** Returns the path of a library data file.
Search the file name.ext in the subdirectory dir of
\begin{enumerate}
@ -191,6 +194,9 @@ string const NormalizePath(string const & path);
/// Strips path from filename
string const OnlyFilename(string const & fname);
/// Strips filename from path
string const BasePath(string const & fname);
/// Get the contents of a file as a huge string
string const GetFileContents(string const & fname);