using std::ostream;
using std::endl;
+using std::vector;
+using std::pair;
extern BufferView * current_view;
}
+static string unique_id() {
+ static unsigned int seed=1000;
+
+#ifdef HAVE_SSTREAM
+ std::ostringstream ost;
+ ost << "file" << ++seed;
+#else
+ char ctmp[16];
+ ostrstream ost(ctmp,16);
+ ost << "file" << ++seed << '\0';
+#endif
+
+ return ost.str();
+}
+
+
InsetInclude::InsetInclude(string const & fname, Buffer * bf)
: InsetCommand("include")
{
setContents(fname);
flag = InsetInclude::INCLUDE;
noload = false;
+ include_label = unique_id();
}
Inset * InsetInclude::Clone() const
{
- InsetInclude * ii = new InsetInclude (contents, master);
+ InsetInclude * ii = new InsetInclude (getContents(), master);
ii->setNoLoad(isNoLoad());
// By default, the newly created inset is of `include' type,
// so we do not test this case.
}
form->include->u_vdata = this;
- fl_set_input(form->input, contents.c_str());
+ fl_set_input(form->input, getContents().c_str());
fl_set_button(form->flag1, int(isNoLoad()));
fl_set_button(form->flag2, int(isInput()));
fl_set_button(form->flag3, int(isInclude()));
}
-void InsetInclude::Write(ostream & os) const
+void InsetInclude::Write(Buffer const *, ostream & os) const
{
os << "Include " << getCommand() << "\n";
}
-void InsetInclude::Read(LyXLex & lex)
+void InsetInclude::Read(Buffer const * buf, LyXLex & lex)
{
- InsetCommand::Read(lex);
+ InsetCommand::Read(buf, lex);
if (getCmdName() == "include")
setInclude();
} else temp += _("Include");
temp += ": ";
- if (contents.empty()) {
+ if (getContents().empty()) {
temp+= "???";
} else {
- temp+= contents;
+ temp+= getContents();
}
return temp;
}
void InsetInclude::setContents(string const & c)
{
InsetCommand::setContents(c);
- filename = MakeAbsPath(contents,
+ filename = MakeAbsPath(getContents(),
OnlyPath(getMasterFilename()));
}
}
-int InsetInclude::Latex(ostream & os,
- signed char /*fragile*/, bool /*fs*/) const
+int InsetInclude::Latex(Buffer const *, ostream & os,
+ bool /*fragile*/, bool /*fs*/) const
{
// Do nothing if no file name has been specified
- if (contents.empty())
+ if (getContents().empty())
return 0;
// Use += to force a copy of contents (JMarc)
// How does that force anything? (Lgb)
- string incfile(contents);
+ string incfile(getContents());
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
}
// write it to a file (so far the complete file)
- string writefile = ChangeExtension(getFileName(), ".tex", false);
+ string writefile = ChangeExtension(getFileName(), ".tex");
if (!master->tmppath.empty()
&& !master->niceFile) {
incfile = subst(incfile, '/','@');
writefile = AddName(master->tmppath, incfile);
} else
writefile = getFileName();
- writefile = ChangeExtension(writefile, ".tex", false);
+ writefile = ChangeExtension(writefile, ".tex");
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
}
if (isVerb()) {
- os << '\\' << command << '{' << incfile << '}';
- }
- else if (isInput()) {
+ os << '\\' << getCmdName() << '{' << incfile << '}';
+ } else if (isInput()) {
// \input wants file with extension (default is .tex)
if (!IsLyXFilename(getFileName())) {
- os << '\\' << command << '{' << incfile << '}';
+ os << '\\' << getCmdName() << '{' << incfile << '}';
} else {
- os << '\\' << command << '{'
- << ChangeExtension(incfile, ".tex", false)
+ os << '\\' << getCmdName() << '{'
+ << ChangeExtension(incfile, ".tex")
<< '}';
}
} else {
// \include don't want extension and demands that the
// file really have .tex
- os << '\\' << command << '{'
- << ChangeExtension(incfile, string(), false)
+ os << '\\' << getCmdName() << '{'
+ << ChangeExtension(incfile, string())
<< '}';
}
}
+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;
+}
+
+
void InsetInclude::Validate(LaTeXFeatures & features) const
{
+
+ 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;
}
-string InsetInclude::getLabel(int) const
+vector<string> InsetInclude::getLabelList() const
{
- string label;
+ vector<string> l;
string parentname;
-
-
+
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
tmp->setParentName("");
- label = tmp->getReferenceList('\n');
+ l = tmp->getLabelList();
tmp->setParentName(getMasterFilename());
}
- return label;
-}
-
-
-int InsetInclude::GetNumberOfLabels() const
-{
- string label;
-
- if (loadIfNeeded()) {
- Buffer * tmp = bufferlist.getBuffer(getFileName());
- tmp->setParentName("");
- label = tmp->getReferenceList('\n');
- tmp->setParentName(getMasterFilename());
- }
- int nl = (label.empty())? 0: 1;
-
- return nl;
+ return l;
}
-string InsetInclude::getKeys(char delim) const
+vector<pair<string,string> > InsetInclude::getKeys() const
{
- string lst;
+ vector<pair<string,string> > keys;
if (loadIfNeeded()) {
Buffer *tmp = bufferlist.getBuffer(getFileName());
tmp->setParentName("");
- lst = tmp->getBibkeyList(delim);
+ keys = tmp->getBibkeyList();
tmp->setParentName(getMasterFilename());
}
- return lst;
+ return keys;
}