Am Montag, 24. Mai 2004 13:52 schrieb Angus Leeming:
> 
> No, it's a definite improvement over what we have. Shove it in.

I did extend it to cover the include inset as well. Now the external, 
graphics and include inset write every file to the temp dir, and 
Exporter::Export() copies the files and checks for overwriting.
Updated patch is attached, I'll commit later.


Georg
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/lib/ChangeLog lyx-1.4-cvs/lib/ChangeLog
--- lyx-1.4-clean/lib/ChangeLog	2004-05-29 10:48:39.000000000 +0200
+++ lyx-1.4-cvs/lib/ChangeLog	2004-05-29 11:42:38.000000000 +0200
@@ -1,3 +1,8 @@
+2004-05-29  Georg Baum  <[EMAIL PROTECTED]>
+
+	* external_templates: add ReferencedFile commands where appropriate
+	* Makefile.am: remove compiled python files
+
 2004-05-28  Lars Gullik Bjonnes  <[EMAIL PROTECTED]>
 
 	* reLyX/Makefile.am: rewrite to not fiddle with autoconf/automake
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/lib/external_templates lyx-1.4-cvs/lib/external_templates
--- lyx-1.4-clean/lib/external_templates	2004-04-30 13:42:12.000000000 +0200
+++ lyx-1.4-cvs/lib/external_templates	2004-05-29 11:54:18.000000000 +0200
@@ -69,6 +69,8 @@ Template RasterImage
 		UpdateFormat eps
 		UpdateResult "$$AbsPath$$Basename.eps"
 		Requirement "graphicx"
+		ReferencedFile latex "$$AbsPath$$Basename.eps"
+		ReferencedFile dvi   "$$AbsPath$$Basename.eps"
 	FormatEnd
 	Format PDFLaTeX
 		TransformOption Rotate RotationLatexOption
@@ -80,6 +82,7 @@ Template RasterImage
 		UpdateFormat png
 		UpdateResult "$$AbsPath$$Basename.png"
 		Requirement "graphicx"
+		ReferencedFile latex "$$AbsPath$$Basename.png"
 	FormatEnd
 	Format Ascii
 		Product "$$Contents(\"$$AbsPath$$Basename.asc\")"
@@ -90,6 +93,8 @@ Template RasterImage
 		Product "<graphic fileref=\"$$AbsOrRelPathMaster$$Basename.eps\"></graphic>"
 		UpdateFormat eps
 		UpdateResult "$$AbsPath$$Basename.eps"
+		ReferencedFile docbook     "$$AbsPath$$Basename.eps"
+		ReferencedFile docbook-xml "$$AbsPath$$Basename.eps"
 	FormatEnd
 	Format LinuxDoc
 		Product "[Bitmap: $$FName]"
@@ -116,6 +121,9 @@ Template XFig
 		Requirement "graphicx"
 		# Preamble WarnNotFound
 		# Preamble InputOrWarn
+		ReferencedFile latex "$$AbsPath$$Basename.pstex_t"
+		ReferencedFile latex "$$AbsPath$$Basename.pstex"
+		ReferencedFile dvi   "$$AbsPath$$Basename.pstex"
 	FormatEnd
 	Format PDFLaTeX
 		TransformCommand Rotate RotationLatexCommand
@@ -126,6 +134,8 @@ Template XFig
 		Requirement "graphicx"
 		# Preamble WarnNotFound
 		# Preamble InputOrWarn
+		ReferencedFile latex "$$AbsPath$$Basename.pdftex_t"
+		ReferencedFile latex "$$AbsPath$$Basename.pdftex"
 	FormatEnd
 	Format Ascii
 		Product "$$Contents(\"$$AbsPath$$Basename.asc\")"
@@ -136,6 +146,8 @@ Template XFig
 		Product "<graphic fileref=\"$$AbsOrRelPathMaster$$Basename.eps\"></graphic>"
 		UpdateFormat eps
 		UpdateResult "$$AbsPath$$Basename.eps"
+		ReferencedFile docbook     "$$AbsPath$$Basename.eps"
+		ReferencedFile docbook-xml "$$AbsPath$$Basename.eps"
 	FormatEnd
 	Format LinuxDoc
 		Product "[XFig: $$FName]"
@@ -170,6 +182,7 @@ Template ChessDiagram
 	Format LaTeX
 		Product "\\loadgame{$$AbsOrRelPathMaster$$Basename}\\showboard"
 		Requirement "chess"
+		ReferencedFile latex "$$AbsPath$$Basename$$Extension"
 	FormatEnd
 	Format Ascii
 		Product "$$Contents(\"$$AbsPath$$Basename.asc\")"
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/lib/Makefile.am lyx-1.4-cvs/lib/Makefile.am
--- lyx-1.4-clean/lib/Makefile.am	2004-05-29 10:48:40.000000000 +0200
+++ lyx-1.4-cvs/lib/Makefile.am	2004-05-28 17:11:53.000000000 +0200
@@ -840,14 +840,8 @@ layouts_DATA =\
 lyx2lyxdir = $(pkgdatadir)/lyx2lyx
 lyx2lyx_SCRIPTS = lyx2lyx/lyx2lyx
 lyx2lyx_DATA = \
-	lyx2lyx/error.pyc \
 	lyx2lyx/lyx2lyx \
-	lyx2lyx/parser_tools.pyc \
-	lyx2lyx/lyx_1_4.pyc \
 	lyx2lyx/parser_tools.py \
-	lyx2lyx/lyxconvert_221.pyc \
-	lyx2lyx/lyxconvert_223.pyc \
-	lyx2lyx/lyxconvert_224.pyc \
 	lyx2lyx/lyx_0_12.py \
 	lyx2lyx/lyx_1_0_0.py \
 	lyx2lyx/lyx_1_0_1.py \
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/ChangeLog lyx-1.4-cvs/src/ChangeLog
--- lyx-1.4-clean/src/ChangeLog	2004-05-29 10:48:50.000000000 +0200
+++ lyx-1.4-cvs/src/ChangeLog	2004-05-29 11:41:27.000000000 +0200
@@ -1,3 +1,13 @@
+2004-05-29  Georg Baum  <[EMAIL PROTECTED]>
+
+	* exporter.C (checkOverwrite): new method
+	* exporter.C (copyFile): new method
+	* exporter.C (Export): copy referenced files to the document dir
+	* exporter.[Ch]: new class ExportedFile
+	* exporter.[Ch]: new class ExportData. Contains currently the
+	names of referenced external files
+	* outputparams.h: add exportdata member.
+
 2004-05-28  Lars Gullik Bjonnes  <[EMAIL PROTECTED]>
 
 	* Makefile.am (DISTCLEANFILES): add version.C, stamp-version and
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/exporter.C lyx-1.4-cvs/src/exporter.C
--- lyx-1.4-clean/src/exporter.C	2004-02-25 13:00:48.000000000 +0100
+++ lyx-1.4-cvs/src/exporter.C	2004-05-29 11:39:55.000000000 +0200
@@ -29,13 +29,20 @@
 #include "outputparams.h"
 #include "frontends/Alert.h"
 
+#include "support/FileInfo.h"
 #include "support/filetools.h"
+#include "support/lyxlib.h"
+#include "support/os.h"
 
 using lyx::support::AddName;
 using lyx::support::bformat;
 using lyx::support::ChangeExtension;
 using lyx::support::contains;
+using lyx::support::MakeAbsPath;
 using lyx::support::MakeDisplayPath;
+using lyx::support::OnlyFilename;
+using lyx::support::OnlyPath;
+using lyx::support::prefixIs;
 
 using std::find;
 using std::string;
@@ -53,6 +60,72 @@ vector<string> const Backends(Buffer con
 	return v;
 }
 
+
+/// ask the user what to do if a file already exists
+int checkOverwrite(string const & filename)
+{
+	if (lyx::support::FileInfo(filename, true).exist()) {
+		string text = bformat(_("The file %1$s already exists.\n\n"
+					"Do you want to over-write that file?"),
+		                      MakeDisplayPath(filename));
+		return Alert::prompt(_("Over-write file?"),
+		                     text, 0, 2,
+		                     _("&Over-write"), _("Over-write &all"),
+		                     _("&Cancel export"));
+	}
+	return 0;
+}
+
+
+enum CopyStatus {
+	SUCCESS,
+	FORCE,
+	CANCEL
+};
+
+
+/** copy file \p sourceFile to \p destFile. If \p force is false, the user
+ *  will be asked before existing files are overwritten.
+ *  \return 
+ *  - SUCCESS if this file got copied
+ *  - FORCE   if subsequent calls should not ask for confirmation before
+ *            overwriting files anymore.
+ *  - CANCEL  if the export should be cancelled
+ */
+CopyStatus copyFile(string const & sourceFile, string const & destFile,
+                   bool force)
+{
+	CopyStatus ret = force ? FORCE : SUCCESS;
+
+	// Only copy files that are in our tmp dir, all other files would
+	// overwrite themselves. This check could be changed to
+	// boost::filesystem::equivalent(sourceFile, destFile) if export to
+	// other directories than the document directory is desired.
+	if (!prefixIs(OnlyPath(sourceFile), lyx::support::os::getTmpDir()))
+		return ret;
+
+	if (!force) {
+		switch(checkOverwrite(destFile)) {
+		case 0:
+			ret = SUCCESS;
+			break;
+		case 1:
+			ret = FORCE;
+			break;
+		default:
+			return CANCEL;
+		}
+	}
+
+	if (!lyx::support::copy(sourceFile, destFile))
+		Alert::error(_("Couldn't copy file"),
+		             bformat(_("Copying %1$s to %2$s failed."),
+		                     MakeDisplayPath(sourceFile),
+		                     MakeDisplayPath(destFile)));
+
+	return ret;
+}
+
 } //namespace anon
 
 
@@ -63,6 +136,8 @@ bool Exporter::Export(Buffer * buffer, s
 	OutputParams runparams;
 	runparams.flavor = OutputParams::LATEX;
 	runparams.linelen = lyxrc.ascii_linelen;
+	ExportData exportdata;
+	runparams.exportdata = &exportdata;
 	vector<string> backends = Backends(*buffer);
 	if (find(backends.begin(), backends.end(), format) == backends.end()) {
 		for (vector<string>::const_iterator it = backends.begin();
@@ -115,18 +193,37 @@ bool Exporter::Export(Buffer * buffer, s
 		buffer->makeLaTeXFile(filename, buffer->filePath(), runparams);
 	}
 
-	string outfile_base = (put_in_tempdir)
-		? filename : buffer->getLatexName(false);
-
-	if (!converters.convert(buffer, filename, outfile_base,
+	if (!converters.convert(buffer, filename, filename,
 				backend_format, format, result_file))
 		return false;
 
-	if (!put_in_tempdir)
-		buffer->message(_("Document exported as ")
-				      + formats.prettyName(format)
-				      + _(" to file `")
-				      + MakeDisplayPath(result_file) +'\'');
+	if (!put_in_tempdir) {
+		string const tmp_result_file = result_file;
+		result_file = ChangeExtension(buffer->fileName(),
+		                              formats.extension(format));
+		// We need to copy referenced files (e. g. included graphics
+		// if format == "dvi") to the result dir.
+		vector<ExportedFile> const files = exportdata.externalFiles(format);
+		string const dest = OnlyPath(result_file);
+		CopyStatus status = SUCCESS;
+		for (vector<ExportedFile>::const_iterator it = files.begin();
+				it != files.end() && status != CANCEL; ++it)
+			status = copyFile(it->sourceName,
+			                  MakeAbsPath(it->exportName, dest),
+			                  status == FORCE);
+		if (status == CANCEL) {
+			buffer->message(_("Document export cancelled."));
+		} else {
+			// Finally copy the main file
+			status = copyFile(tmp_result_file, result_file,
+			                  status == FORCE);
+			buffer->message(bformat(_("Document exported as %1$s"
+			                          "to file `%2$s'"),
+			                        formats.prettyName(format),
+			                        MakeDisplayPath(result_file)));
+		}
+	}
+
 	return true;
 }
 
@@ -173,3 +270,47 @@ Exporter::GetExportableFormats(Buffer co
 	}
 	return result;
 }
+
+
+ExportedFile::ExportedFile(string const & s, string const & e) :
+	sourceName(s), exportName(e) {}
+
+
+bool operator==(ExportedFile const & f1, ExportedFile const & f2)
+{
+	return f1.sourceName == f2.sourceName &&
+	       f1.exportName == f2.exportName;
+
+}
+
+
+void ExportData::addExternalFile(string const & format,
+                                 string const & sourceName,
+                                 string const & exportName)
+{
+	BOOST_ASSERT(lyx::support::AbsolutePath(sourceName));
+
+	// Make sure that we have every file only once, otherwise copyFile()
+	// would ask several times if it should overwrite a file.
+	vector<ExportedFile> & files = externalfiles[format];
+	ExportedFile file(sourceName, exportName);
+	if (find(files.begin(), files.end(), file) == files.end())
+		files.push_back(file);
+}
+
+
+void ExportData::addExternalFile(string const & format,
+                                 string const & sourceName)
+{
+	addExternalFile(format, sourceName, OnlyFilename(sourceName));
+}
+
+
+vector<ExportedFile> const
+ExportData::externalFiles(string const & format) const
+{
+	FileMap::const_iterator cit = externalfiles.find(format);
+	if (cit != externalfiles.end())
+		return cit->second;
+	return vector<ExportedFile>();
+}
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/exporter.h lyx-1.4-cvs/src/exporter.h
--- lyx-1.4-clean/src/exporter.h	2003-10-07 08:45:24.000000000 +0200
+++ lyx-1.4-cvs/src/exporter.h	2004-05-29 11:48:50.000000000 +0200
@@ -13,6 +13,7 @@
 #ifndef EXPORTER_H
 #define EXPORTER_H
 
+#include <map>
 #include <string>
 #include <vector>
 
@@ -42,4 +43,44 @@ public:
 	GetExportableFormats(Buffer const & buffer, bool only_viewable);
 	///
 };
+
+
+struct ExportedFile {
+	ExportedFile(std::string const &, std::string const &);
+	/// absolute name of the source file
+	std::string sourceName;
+	/// final name that the exported file should get (absolute name or
+	/// relative to the directory of the master document)
+	std::string exportName;
+};
+
+
+bool operator==(ExportedFile const &, ExportedFile const &);
+
+
+class ExportData {
+public:
+	/** add a referenced file for one format.
+	 *  No inset should ever write any file outside the tempdir.
+	 *  Instead, files that need to be exported have to be registered
+	 *  with this method.
+	 *  Then the exporter mechanism copies them to the right place, asks
+	 *  for confirmation before overwriting existing files etc.
+	 */
+	void addExternalFile(std::string const &, std::string const &,
+	                     std::string const &);
+	/// add a referenced file for one format.
+	/// The final name is the source file name without path
+	void addExternalFile(std::string const &, std::string const &);
+	/// get referenced files for one format
+	std::vector<ExportedFile> const
+	externalFiles(std::string const &) const;
+private:
+	typedef std::map<std::string, std::vector<ExportedFile> > FileMap;
+	/** Files that are referenced by the export result in the
+	 *  different formats.
+	 */
+	FileMap externalfiles;
+};
+
 #endif
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ChangeLog lyx-1.4-cvs/src/insets/ChangeLog
--- lyx-1.4-clean/src/insets/ChangeLog	2004-05-21 08:56:11.000000000 +0200
+++ lyx-1.4-cvs/src/insets/ChangeLog	2004-05-29 11:41:16.000000000 +0200
@@ -1,3 +1,21 @@
+2004-05-29  Georg Baum  <[EMAIL PROTECTED]>
+
+	* ExternalSupport.[Ch] (doSubstitution): exchange filename argument
+	with external_in_tmpdir and compute filename ourself
+	* ExternalSupport.[Ch] (updateExternal): add exportdata argument and
+	use it to store referenced file(s)
+	* ExternalSupport.C (writeExternal): write relative filename if
+	running latex
+	* ExternalTemplate.[Ch]: add ReferencedFile command
+	* insetgraphics.C (prepareFile, docbook, linuxdoc): add file to
+	runparams.exportdata
+	* insetgraphics.C (prepareFile): write relative filename if
+	running latex
+	* insetinclude.C (latex, docbook, linuxdoc): add file to
+	runparams.exportdata and write it to the temp dir instead of
+	writing it to the final destination
+	* insetinclude.C (docbook, linuxdoc): don't copy runparams
+
 2004-05-19  Angus Leeming  <[EMAIL PROTECTED]>
 
 	* insetcite.[Ch]: small change because namespace biblio is
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ExternalSupport.C lyx-1.4-cvs/src/insets/ExternalSupport.C
--- lyx-1.4-clean/src/insets/ExternalSupport.C	2004-04-13 12:36:09.000000000 +0200
+++ lyx-1.4-cvs/src/insets/ExternalSupport.C	2004-05-28 14:34:51.000000000 +0200
@@ -19,6 +19,7 @@
 #include "buffer.h"
 #include "converter.h"
 #include "debug.h"
+#include "exporter.h"
 #include "format.h"
 
 #include "support/filetools.h"
@@ -58,31 +59,32 @@ void editExternal(InsetExternalParams co
 }
 
 
-namespace {
-
-/** Substitute meta-variables in the string \p s.
-    \p filename has to be the filename as read from the .lyx file (this
-    can be an absolute path or a path relative to the parent document).
-    Otherwise, the $$AbsOrRelPath* variables would not work.
-    If we are using a temporary directory, \p filename is the mangled name.
-*/
 string const doSubstitution(InsetExternalParams const & params,
 			    Buffer const & buffer, string const & s,
-			    string const & filename)
+			    bool external_in_tmpdir)
 {
+	Buffer const * m_buffer = buffer.getMasterBuffer();
+	string const parentpath = external_in_tmpdir ?
+		m_buffer->temppath() :
+		buffer.filePath();
+	string const filename = external_in_tmpdir ?
+		params.filename.mangledFilename() :
+		params.filename.outputFilename(parentpath);
 	string result;
 	string const basename = support::ChangeExtension(
 			support::OnlyFilename(filename), string());
-	string const absname = support::MakeAbsPath(filename, buffer.filePath());
+	string const absname = support::MakeAbsPath(filename, parentpath);
 	string const filepath = support::OnlyPath(filename);
 	string const abspath = support::OnlyPath(absname);
-	Buffer const * m_buffer = buffer.getMasterBuffer();
+	string const masterpath = external_in_tmpdir ?
+		m_buffer->temppath() :
+		m_buffer->filePath();
 	string relToMasterPath = support::OnlyPath(
-			support::MakeRelPath(absname, m_buffer->filePath()));
+			support::MakeRelPath(absname, masterpath));
 	if (relToMasterPath == "./")
 		relToMasterPath.clear();
 	string relToParentPath = support::OnlyPath(
-			support::MakeRelPath(absname, buffer.filePath()));
+			support::MakeRelPath(absname, parentpath));
 	if (relToParentPath == "./")
 		relToParentPath.clear();
 
@@ -131,6 +133,9 @@ string const doSubstitution(InsetExterna
 	return result;
 }
 
+
+namespace {
+
 /** update the file represented by the template.
     If \param external_in_tmpdir == true, then the generated file is
     place in the buffer's temporary directory.
@@ -138,6 +143,7 @@ string const doSubstitution(InsetExterna
 void updateExternal(InsetExternalParams const & params,
 		    string const & format,
 		    Buffer const & buffer,
+                    ExportData & exportdata,
 		    bool external_in_tmpdir)
 {
 	Template const * const et_ptr = getTemplatePtr(params);
@@ -185,8 +191,6 @@ void updateExternal(InsetExternalParams 
 		return; // FAILURE
 	}
 
-	string from_file = params.filename.outputFilename(buffer.filePath());
-
 	// The master buffer. This is useful when there are multiple levels
 	// of include files
 	Buffer const * m_buffer = buffer.getMasterBuffer();
@@ -209,19 +213,33 @@ void updateExternal(InsetExternalParams 
 			}
 		}
 
-		from_file = temp_file;
 		abs_from_file = temp_file;
 	}
 
 	string const to_file = doSubstitution(params, buffer,
 					      outputFormat.updateResult,
-					      from_file);
+	                                      external_in_tmpdir);
 
 	string const abs_to_file =
 		support::MakeAbsPath(to_file, external_in_tmpdir
 			? m_buffer->temppath()
 			: buffer.filePath());
 
+	// record the referenced files for the exporter
+	typedef Template::Format::FileMap FileMap;
+	FileMap::const_iterator rit  = outputFormat.referencedFiles.begin();
+	FileMap::const_iterator rend = outputFormat.referencedFiles.end();
+	for (; rit != rend; ++rit) {
+		vector<string>::const_iterator fit  = rit->second.begin();
+		vector<string>::const_iterator fend = rit->second.end();
+		for (; fit != fend; ++fit) {
+			string const file = doSubstitution(params, buffer,
+			                                   *fit,
+			                                   external_in_tmpdir);
+			exportdata.addExternalFile(rit->first, file);
+		}
+	}
+	
 	// Do we need to perform the conversion?
 	// Yes if to_file does not exist or if from_file is newer than to_file
 	if (support::compare_timestamps(abs_from_file, abs_to_file) < 0)
@@ -248,6 +266,7 @@ string const substituteOptions(InsetExte
 int writeExternal(InsetExternalParams const & params,
 		  string const & format,
 		  Buffer const & buffer, ostream & os,
+                  ExportData & exportdata,
 		  bool external_in_tmpdir)
 {
 	Template const * const et_ptr = getTemplatePtr(params);
@@ -264,34 +283,16 @@ int writeExternal(InsetExternalParams co
 		return 0;
 	}
 
-	updateExternal(params, format, buffer, external_in_tmpdir);
-
-	string from_file = params.filename.outputFilename(buffer.filePath());
-	if (external_in_tmpdir && !from_file.empty()) {
-		// We are running stuff through LaTeX
-		from_file =
-			support::MakeAbsPath(params.filename.mangledFilename(),
-			                     buffer.getMasterBuffer()->temppath());
-	}
+	updateExternal(params, format, buffer, exportdata, external_in_tmpdir);
 
 	string str = doSubstitution(params, buffer, cit->second.product,
-				    from_file);
+	                            external_in_tmpdir);
 	str = substituteCommands(params, str, format);
 	str = substituteOptions(params, str, format);
 	os << str;
 	return int(lyx::count(str.begin(), str.end(),'\n') + 1);
 }
 
-
-/// Substitute meta-variables in this string
-string const doSubstitution(InsetExternalParams const & params,
-			    Buffer const & buffer, string const & s)
-{
-	string const buffer_path = buffer.filePath();
-	string const filename = params.filename.outputFilename(buffer_path);
-	return doSubstitution(params, buffer, s, filename);
-}
-
 namespace {
 
 // Empty template, specialised below.
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ExternalSupport.h lyx-1.4-cvs/src/insets/ExternalSupport.h
--- lyx-1.4-clean/src/insets/ExternalSupport.h	2003-10-07 22:25:10.000000000 +0200
+++ lyx-1.4-cvs/src/insets/ExternalSupport.h	2004-05-20 12:17:45.000000000 +0200
@@ -17,6 +17,7 @@
 #include <string>
 
 class Buffer;
+class ExportData;
 class InsetExternalParams;
 
 namespace lyx {
@@ -33,10 +34,17 @@ void editExternal(InsetExternalParams co
 		  Buffer const & buffer);
 
 
-/// Substitute meta-variables in string s, making use of params and buffer.
+/** Substitute meta-variables in string \p s, making use of \p params and
+    \p buffer.
+    If \p external_in_tmpdir is true, all files are assumed to be in the
+    master buffers temp path, and the mangled filename is used.
+    Otherwise, the output filename (absolute or relative to the parent
+    document, as written in the .lyx file) is used.
+*/
 std::string const doSubstitution(InsetExternalParams const & params,
 				 Buffer const & buffer,
-				 std::string const & s);
+                                 std::string const & s,
+                                 bool external_in_tmpdir = false);
 
 
 /** Write the output for a specific file format
@@ -48,6 +56,7 @@ int writeExternal(InsetExternalParams co
 		  std::string const & format,
 		  Buffer const &,
 		  std::ostream &,
+		  ExportData &,
 		  bool external_in_tmpdir = false);
 
 } // namespace external
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ExternalTemplate.C lyx-1.4-cvs/src/insets/ExternalTemplate.C
--- lyx-1.4-clean/src/insets/ExternalTemplate.C	2004-04-30 13:43:07.000000000 +0200
+++ lyx-1.4-cvs/src/insets/ExternalTemplate.C	2004-05-21 19:42:37.000000000 +0200
@@ -146,6 +146,18 @@ public:
 			ost << "\t\tPreamble " << *pit << '\n';
 		}
 
+		typedef Template::Format::FileMap FileMap;
+		FileMap::const_iterator rit  = ft.referencedFiles.begin();
+		FileMap::const_iterator rend = ft.referencedFiles.end();
+		for (; rit != rend; ++rit) {
+			vector<string>::const_iterator fit  = rit->second.begin();
+			vector<string>::const_iterator fend = rit->second.end();
+			for (; fit != fend; ++fit) {
+				ost << "\t\tReferencedFile " << rit->first
+				    << " \"" << *fit << "\"\n";
+			}
+		}
+
 		ost << "\tFormatEnd\n";
 	}
 private:
@@ -452,6 +464,7 @@ void Template::Format::readFormat(LyXLex
 		FO_PREAMBLE,
 		FO_TRANSFORMCOMMAND,
 		FO_TRANSFORMOPTION,
+		FO_REFERENCEDFILE,
 		FO_END
 	};
 
@@ -460,6 +473,7 @@ void Template::Format::readFormat(LyXLex
 		{ "option", FO_OPTION },
 		{ "preamble", FO_PREAMBLE },
 		{ "product", FO_PRODUCT },
+		{ "referencedfile", FO_REFERENCEDFILE },
 		{ "requirement", FO_REQUIREMENT },
 		{ "transformcommand", FO_TRANSFORMCOMMAND },
 		{ "transformoption", FO_TRANSFORMOPTION },
@@ -521,6 +535,15 @@ void Template::Format::readFormat(LyXLex
 			break;
 		}
 
+		case FO_REFERENCEDFILE: {
+			lex.next(true);
+			string const format = lex.getString();
+			lex.next(true);
+			string const file = lex.getString();
+			referencedFiles[format].push_back(file);
+			break;
+		}
+
 		case FO_END:
 			return;
 		}
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/ExternalTemplate.h lyx-1.4-cvs/src/insets/ExternalTemplate.h
--- lyx-1.4-clean/src/insets/ExternalTemplate.h	2004-04-30 13:43:07.000000000 +0200
+++ lyx-1.4-cvs/src/insets/ExternalTemplate.h	2004-05-21 19:42:22.000000000 +0200
@@ -76,6 +76,11 @@ struct Template {
 		/// The factory functions for each supported transformation.
 		std::map<TransformID, TransformStore> command_transformers;
 		std::map<TransformID, TransformStore> option_transformers;
+
+		typedef std::map<std::string,
+		                 std::vector<std::string> > FileMap;
+		/// Referenced files for some formats
+		FileMap referencedFiles;
 	};
 	///
 	typedef std::map<std::string, Format> Formats;
Nur in lyx-1.4-cvs/src/insets: georg.
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insetexternal.C lyx-1.4-cvs/src/insets/insetexternal.C
--- lyx-1.4-clean/src/insets/insetexternal.C	2004-04-19 20:06:35.000000000 +0200
+++ lyx-1.4-cvs/src/insets/insetexternal.C	2004-05-28 14:38:17.000000000 +0200
@@ -22,6 +22,7 @@
 #include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
+#include "exporter.h"
 #include "funcrequest.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
@@ -687,32 +688,37 @@ int InsetExternal::latex(Buffer const & 
 			et.formats.find("PDFLaTeX");
 		if (cit != et.formats.end())
 			return external::writeExternal(params_, "PDFLaTeX",
-					     buf, os, external_in_tmpdir);
-	}
-
-	return external::writeExternal(params_, "LaTeX",
-				       buf, os, external_in_tmpdir);
+			                               buf, os,
+			                               *(runparams.exportdata),
+			                               external_in_tmpdir);
+	}
+	return external::writeExternal(params_, "LaTeX", buf, os,
+	                               *(runparams.exportdata),
+	                               external_in_tmpdir);
 }
 
 
 int InsetExternal::plaintext(Buffer const & buf, ostream & os,
-			 OutputParams const &) const
+			 OutputParams const & runparams) const
 {
-	return external::writeExternal(params_, "Ascii", buf, os);
+	return external::writeExternal(params_, "Ascii", buf, os,
+	                               *(runparams.exportdata));
 }
 
 
 int InsetExternal::linuxdoc(Buffer const & buf, ostream & os,
-			    OutputParams const &) const
+			    OutputParams const & runparams) const
 {
-	return external::writeExternal(params_, "LinuxDoc", buf, os);
+	return external::writeExternal(params_, "LinuxDoc", buf, os,
+	                               *(runparams.exportdata));
 }
 
 
 int InsetExternal::docbook(Buffer const & buf, ostream & os,
-			   OutputParams const &) const
+			   OutputParams const & runparams) const
 {
-	return external::writeExternal(params_, "DocBook", buf, os);
+	return external::writeExternal(params_, "DocBook", buf, os,
+	                               *(runparams.exportdata));
 }
 
 
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insetgraphics.C lyx-1.4-cvs/src/insets/insetgraphics.C
--- lyx-1.4-clean/src/insets/insetgraphics.C	2004-05-07 13:41:40.000000000 +0200
+++ lyx-1.4-cvs/src/insets/insetgraphics.C	2004-05-26 19:44:25.000000000 +0200
@@ -58,6 +58,7 @@ TODO
 #include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
+#include "exporter.h"
 #include "format.h"
 #include "funcrequest.h"
 #include "gettext.h"
@@ -93,6 +94,7 @@ using lyx::support::GetExtension;
 using lyx::support::getExtFromContents;
 using lyx::support::IsFileReadable;
 using lyx::support::LibFileSearch;
+using lyx::support::OnlyFilename;
 using lyx::support::rtrim;
 using lyx::support::subst;
 using lyx::support::Systemcall;
@@ -453,6 +455,10 @@ string const InsetGraphics::prepareFile(
 
 	if (zipped) {
 		if (params().noUnzip) {
+			// We don't know wether latex can actually handle
+			// this file, but we can't check, because that would
+			// mean to unzip the file and thereby making the
+			// noUnzip parameter meaningless.
 			lyxerr[Debug::GRAPHICS]
 				<< "\tpass zipped file to LaTeX.\n";
 			// LaTeX needs the bounding box file in the tmp dir
@@ -462,7 +468,10 @@ string const InsetGraphics::prepareFile(
 				                 ChangeExtension(temp_file, "bb"));
 			if (status == FAILURE)
 				return orig_file;
-			return temp_file;
+			runparams.exportdata->addExternalFile("latex", temp_file);
+			runparams.exportdata->addExternalFile("latex", bb_file);
+			runparams.exportdata->addExternalFile("dvi", temp_file);
+			return OnlyFilename(temp_file);
 		}
 
 		string const unzipped_temp_file = unzippedFileName(temp_file);
@@ -493,8 +502,12 @@ string const InsetGraphics::prepareFile(
 	lyxerr[Debug::GRAPHICS]
 		<< "\tthe orig file is: " << orig_file << endl;
 
-	if (from == to)
-		return stripExtensionIfPossible(temp_file, to);
+	if (from == to) {
+		// The extension of temp_file might be != to!
+		runparams.exportdata->addExternalFile("latex", temp_file);
+		runparams.exportdata->addExternalFile("dvi", temp_file);
+		return OnlyFilename(stripExtensionIfPossible(temp_file, to));
+	}
 
 	string const to_file_base = RemoveExtension(temp_file);
 	string const to_file = ChangeExtension(to_file_base, to);
@@ -507,7 +520,9 @@ string const InsetGraphics::prepareFile(
 			<< bformat(_("No conversion of %1$s is needed after all"),
 				   rel_file)
 			<< std::endl;
-		return to_file_base;
+		runparams.exportdata->addExternalFile("latex", to_file);
+		runparams.exportdata->addExternalFile("dvi", to_file);
+		return OnlyFilename(to_file_base);
 	}
 
 	lyxerr[Debug::GRAPHICS]
@@ -523,13 +538,16 @@ string const InsetGraphics::prepareFile(
 		string const command =
 			"sh " + LibFileSearch("scripts", "convertDefault.sh") +
 				' ' + from + ':' + temp_file + ' ' +
-				to + ':' + to_file_base + '.' + to;
+				to + ':' + to_file;
 		lyxerr[Debug::GRAPHICS]
 			<< "No converter defined! I use convertDefault.sh:\n\t"
 			<< command << endl;
 		Systemcall one;
 		one.startscript(Systemcall::Wait, command);
-		if (!IsFileReadable(ChangeExtension(to_file_base, to))) {
+		if (IsFileReadable(to_file)) {
+			runparams.exportdata->addExternalFile("latex", to_file);
+			runparams.exportdata->addExternalFile("dvi", to_file);
+		} else {
 			string str = bformat(_("No information for converting %1$s "
 				"format files to %2$s.\n"
 				"Try defining a convertor in the preferences."), from, to);
@@ -537,7 +556,7 @@ string const InsetGraphics::prepareFile(
 		}
 	}
 
-	return to_file_base;
+	return OnlyFilename(to_file_base);
 }
 
 
@@ -651,6 +670,8 @@ int InsetGraphics::linuxdoc(Buffer const
 				params().filename.relFilename(buf.filePath()):
 				params().filename.absFilename();
 
+	runparams.exportdata->addExternalFile("linuxdoc",
+	                                      params().filename.absFilename());
 	os << "<eps file=\"" << file_name << "\">\n";
 	os << "<img src=\"" << file_name << "\">";
 	return 0;
@@ -658,14 +679,18 @@ int InsetGraphics::linuxdoc(Buffer const
 
 
 // For explanation on inserting graphics into DocBook checkout:
-// http://en.tldp.org/LDP/LDP-Author-Guide/inserting-pictures.html
+// http://en.tldp.org/LDP/LDP-Author-Guide/html/inserting-pictures.html
 // See also the docbook guide at http://www.docbook.org/
 int InsetGraphics::docbook(Buffer const &, ostream & os,
-			   OutputParams const &) const
+			   OutputParams const & runparams) const
 {
 	// In DocBook v5.0, the graphic tag will be eliminated from DocBook, will
 	// need to switch to MediaObject. However, for now this is sufficient and
 	// easier to use.
+	runparams.exportdata->addExternalFile("docbook",
+	                                      params().filename.absFilename());
+	runparams.exportdata->addExternalFile("docbook-xml",
+	                                      params().filename.absFilename());
 	os << "<graphic fileref=\"&" << graphic_label << ";\">";
 	return 0;
 }
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/insets/insetinclude.C lyx-1.4-cvs/src/insets/insetinclude.C
--- lyx-1.4-clean/src/insets/insetinclude.C	2004-04-19 20:06:36.000000000 +0200
+++ lyx-1.4-cvs/src/insets/insetinclude.C	2004-05-28 14:41:18.000000000 +0200
@@ -20,6 +20,7 @@
 #include "cursor.h"
 #include "debug.h"
 #include "dispatchresult.h"
+#include "exporter.h"
 #include "funcrequest.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
@@ -332,13 +350,15 @@ int InsetInclude::latex(Buffer const & b
 	}
 
 	// write it to a file (so far the complete file)
-	string writefile = ChangeExtension(included_file, ".tex");
+	string const exportfile = ChangeExtension(incfile, ".tex");
+	string const mangled = FileName(ChangeExtension(included_file,
+	                                                ".tex")).mangledFilename();
+	string const writefile = MakeAbsPath(mangled, m_buffer->temppath());
 
-	if (!runparams.nice) {
-		incfile = FileName(writefile).mangledFilename();
-		writefile = MakeAbsPath(incfile, m_buffer->temppath());
-	}
+	if (!runparams.nice)
+		incfile = mangled;
 	lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+	lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
 	lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
 	if (loadIfNeeded(buffer, params_)) {
@@ -366,7 +387,7 @@ int InsetInclude::latex(Buffer const & b
 		tmp->makeLaTeXFile(writefile,
 				   OnlyPath(masterFilename(buffer)),
 				   runparams, false);
-	} else if (!runparams.nice) {
+	} else {
 		// Copy the file to the temp dir, so that .aux files etc.
 		// are not created in the original dir. Files included by
 		// this file will be found via [EMAIL PROTECTED], see ../buffer.C.
@@ -388,6 +409,9 @@ int InsetInclude::latex(Buffer const & b
 	if (isVerbatim(params_)) {
 		os << '\\' << params_.getCmdName() << '{' << incfile << '}';
 	} else if (type(params_) == INPUT) {
+		runparams.exportdata->addExternalFile("latex", writefile,
+		                                      exportfile);
+
 		// \input wants file with extension (default is .tex)
 		if (!IsLyXFilename(included_file)) {
 			os << '\\' << params_.getCmdName() << '{' << incfile << '}';
@@ -397,6 +421,9 @@ int InsetInclude::latex(Buffer const & b
 			   <<  '}';
 		}
 	} else {
+		runparams.exportdata->addExternalFile("latex", writefile,
+		                                      exportfile);
+
 		// \include don't want extension and demands that the
 		// file really have .tex
 		os << '\\' << params_.getCmdName() << '{'
@@ -428,31 +455,34 @@ int InsetInclude::linuxdoc(Buffer const 
 
 	string const included_file = includedFilename(buffer, params_);
 
+	// write it to a file (so far the complete file)
+	string const exportfile = ChangeExtension(incfile, ".sgml");
+	string writefile = ChangeExtension(included_file, ".sgml");
+
 	if (loadIfNeeded(buffer, params_)) {
 		Buffer * tmp = bufferlist.getBuffer(included_file);
 
-		// write it to a file (so far the complete file)
-		string writefile = ChangeExtension(included_file, ".sgml");
-
-		if (!runparams.nice) {
-			incfile = FileName(writefile).mangledFilename();
-			writefile = MakeAbsPath(incfile,
-			                        buffer.getMasterBuffer()->temppath());
-		}
+		writefile = MakeAbsPath(FileName(writefile).mangledFilename(),
+		                        buffer.getMasterBuffer()->temppath());
+		if (!runparams.nice)
+			incfile = writefile;
 
 		lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+		lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
 		lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
-		OutputParams runp = runparams;
-		tmp->makeLinuxDocFile(writefile, runp, true);
+		tmp->makeLinuxDocFile(writefile, runparams, true);
 	}
 
 	if (isVerbatim(params_)) {
 		os << "<![CDATA["
 		   << GetFileContents(included_file)
 		   << "]]>";
-	} else
+	} else {
+		runparams.exportdata->addExternalFile("linuxdoc", writefile,
+		                                      exportfile);
 		os << '&' << include_label << ';';
+	}
 
 	return 0;
 }
@@ -469,25 +499,31 @@ int InsetInclude::docbook(Buffer const &
 
 	string const included_file = includedFilename(buffer, params_);
 
+	// write it to a file (so far the complete file)
+	string const exportfile = ChangeExtension(incfile, ".sgml");
+	string writefile = ChangeExtension(included_file, ".sgml");
+
 	if (loadIfNeeded(buffer, params_)) {
 		Buffer * tmp = bufferlist.getBuffer(included_file);
 
-		// write it to a file (so far the complete file)
-		string writefile = ChangeExtension(included_file, ".sgml");
-
-		if (!runparams.nice) {
-			incfile = FileName(writefile).mangledFilename();
-			writefile = MakeAbsPath(incfile,
-			                        buffer.getMasterBuffer()->temppath());
-		}
+		string const mangled = FileName(writefile).mangledFilename();
+		writefile = MakeAbsPath(mangled,
+		                        buffer.getMasterBuffer()->temppath());
+		if (!runparams.nice)
+			incfile = mangled;
 
 		lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
+		lyxerr[Debug::LATEX] << "exportfile:" << exportfile << endl;
 		lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
-		OutputParams runp = runparams;
-		tmp->makeDocBookFile(writefile, runp, true);
+		tmp->makeDocBookFile(writefile, runparams, true);
 	}
 
+	runparams.exportdata->addExternalFile("docbook", writefile,
+	                                      exportfile);
+	runparams.exportdata->addExternalFile("docbook-xml", writefile,
+	                                      exportfile);
+
 	if (isVerbatim(params_)) {
 		os << "<inlinegraphic fileref=\""
 		   << '&' << include_label << ';'
diff -p -r -U 3 -X excl.tmp lyx-1.4-clean/src/outputparams.h lyx-1.4-cvs/src/outputparams.h
--- lyx-1.4-clean/src/outputparams.h	2004-05-14 19:53:31.000000000 +0200
+++ lyx-1.4-cvs/src/outputparams.h	2004-05-20 17:09:44.000000000 +0200
@@ -15,6 +15,9 @@
 #include "support/types.h"
 
 
+class ExportData;
+
+
 struct OutputParams {
 	//
 	enum FLAVOR {
@@ -26,7 +29,7 @@ struct OutputParams {
 	OutputParams()
 		: flavor(LATEX), nice(false), moving_arg(false),
 		  free_spacing(false), use_babel(false),
-		  mixed_content(false), linelen(0)
+		  mixed_content(false), linelen(0), exportdata(0)
 	{}
 
 	/** The latex that we export depends occasionally on what is to
@@ -65,6 +68,12 @@ struct OutputParams {
 	/** Line length to use with ascii export.
 	*/
 	lyx::size_type linelen;
+
+	/** Export data filled in by the latex(), docbook() etc methods.
+	    This is a hack: Make it possible to add stuff to constant
+	    OutputParams instances.
+	*/
+	ExportData *exportdata;
 };
 
 #endif // LATEXRUNPARAMS_H

Reply via email to