Am Montag, 5. April 2004 18:07 schrieb Angus Leeming:
> Georg Baum wrote:
> > Here is a patch that implements this with one small change: use
> > $$AbsOrRelPath_Parent instead of $$AbsPathOrRelPath_Parent
> > (otherwise substitution would not work properly).
> > 
> > Is this ok?
> 
> Yes, with one proviso. '_' doesn't mean anything and doesn't give
> anything. I'd like to see
>         $$AbsOrRelPathFromParent
>         $$AbsOrRelPathFromMaster

Ok, I changed that. The other difference to the previous patch is a comment 
for doSubstitution(), I think that it is necessary to explain the filename 
parameter.
Could you apply it, please?


Georg
Index: lib/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/lib/ChangeLog,v
retrieving revision 1.578
diff -u -p -r1.578 ChangeLog
--- lib/ChangeLog	2004/04/01 08:09:14	1.578
+++ lib/ChangeLog	2004/04/06 19:31:26
@@ -1,3 +1,8 @@
+2004-04-06  Georg Baum  <[EMAIL PROTECTED]>
+
+	* external_templates: use some new variables instead of $$Basename
+	(needed to fix bug #605)
+
 2004-04-01  Jürgen Spitzmüller  <[EMAIL PROTECTED]>
 
 	* help/ and contents is gone (outdated).
Index: lib/external_templates
===================================================================
RCS file: /cvs/lyx/lyx-devel/lib/external_templates,v
retrieving revision 1.22
diff -u -p -r1.22 external_templates
--- lib/external_templates	2004/01/05 16:49:34	1.22
+++ lib/external_templates	2004/04/06 19:31:29
@@ -35,14 +35,14 @@ PreambleDefEnd
 
 
 Template RasterImage
-	GuiName "Bitmap: $$Basename"
+	GuiName "Bitmap: $$AbsOrRelPathParent$$Basename"
 	HelpText
 		A bitmap file.
 		This template uses Gimp for editing.
 	HelpTextEnd
 	InputFormat "*"
 	FileFilter "*.{gif,png,jpg,bmp,pbm,ppm,tga,tif,xpm,xbm}"
-	EditCommand "gimp $$FName"
+	EditCommand "gimp $$Absname"
 	AutomaticProduction true
 	Transform Rotate
 	Transform Resize
@@ -54,9 +54,9 @@ Template RasterImage
 		TransformOption Clip   ClipLatexOption
 		TransformOption Extra  ExtraOption
 		Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
-		Product "\\includegraphics$$Arg{$$Basename}"
+		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
 		UpdateFormat eps
-		UpdateResult "$$Basename.eps"
+		UpdateResult "$$AbsPath$$Basename.eps"
 		Requirement "graphicx"
 	FormatEnd
 	Format PDFLaTeX
@@ -65,20 +65,20 @@ Template RasterImage
 		TransformOption Clip   ClipLatexOption
 		TransformOption Extra  ExtraOption
 		Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
-		Product "\\includegraphics$$Arg{$$Basename}"
+		Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
 		UpdateFormat png
-		UpdateResult "$$Basename.png"
+		UpdateResult "$$AbsPath$$Basename.png"
 		Requirement "graphicx"
 	FormatEnd
 	Format Ascii
-		Product "$$Contents(\"$$Basename.asc\")"
+		Product "$$Contents(\"$$AbsPath$$Basename.asc\")"
 		UpdateFormat asciiimage
-		UpdateResult "$$Basename.asc"
+		UpdateResult "$$AbsPath$$Basename.asc"
 	FormatEnd
 	Format DocBook
-		Product "<graphic fileref=\"$$Basename.eps\"></graphic>"
+		Product "<graphic fileref=\"$$AbsOrRelPathMaster$$Basename.eps\"></graphic>"
 		UpdateFormat eps
-		UpdateResult "$$Basename.eps"
+		UpdateResult "$$AbsPath$$Basename.eps"
 	FormatEnd
 	Format LinuxDoc
 		Product "[Bitmap: $$FName]"
@@ -87,23 +87,23 @@ TemplateEnd
 
 
 Template XFig
-	GuiName "XFig: $$Basename"
+	GuiName "XFig: $$AbsOrRelPathParent$$Basename"
 	HelpText
 		An XFig figure.
 		This template uses XFig for editing.
 	HelpTextEnd
 	InputFormat fig
 	FileFilter "*.fig"
-	EditCommand "xfig $$FName"
+	EditCommand "xfig $$Absname"
 	AutomaticProduction true
 	Transform Rotate
 	Transform Resize
 	Format LaTeX
 		TransformCommand Rotate RotationLatexCommand
 		TransformCommand Resize ResizeLatexCommand
-		Product "$$RotateFront$$ResizeFront\\input{$$Basename.pstex_t}$$ResizeBack$$RotateBack"
+		Product "$$RotateFront$$ResizeFront\\input{$$AbsOrRelPathMaster$$Basename.pstex_t}$$ResizeBack$$RotateBack"
 		UpdateFormat pstex
-		UpdateResult "$$Basename.pstex_t"
+		UpdateResult "$$AbsPath$$Basename.pstex_t"
 		Requirement "graphicx"
 		Preamble WarnNotFound
 		Preamble InputOrWarn
@@ -111,22 +111,22 @@ Template XFig
 	Format PDFLaTeX
 		TransformCommand Rotate RotationLatexCommand
 		TransformCommand Resize ResizeLatexCommand
-		Product "$$RotateFront$$ResizeFront\\input{$$Basename.pdftex_t}$$ResizeBack$$RotateBack"
+		Product "$$RotateFront$$ResizeFront\\input{$$AbsOrRelPathMaster$$Basename.pdftex_t}$$ResizeBack$$RotateBack"
 		UpdateFormat pdftex
-		UpdateResult "$$Basename.pdftex_t"
+		UpdateResult "$$AbsPath$$Basename.pdftex_t"
 		Requirement "graphicx"
 		Preamble WarnNotFound
 		Preamble InputOrWarn
 	FormatEnd
 	Format Ascii
-		Product "$$Contents(\"$$Basename.asc\")"
+		Product "$$Contents(\"$$AbsPath$$Basename.asc\")"
 		UpdateFormat asciixfig
-		UpdateResult "$$Basename.asc"
+		UpdateResult "$$AbsPath$$Basename.asc"
 	FormatEnd
 	Format DocBook
-		Product "<graphic fileref=\"$$Basename.eps\"></graphic>"
+		Product "<graphic fileref=\"$$AbsOrRelPathMaster$$Basename.eps\"></graphic>"
 		UpdateFormat eps
-		UpdateResult "$$Basename.eps"
+		UpdateResult "$$AbsPath$$Basename.eps"
 	FormatEnd
 	Format LinuxDoc
 		Product "[XFig: $$FName]"
@@ -135,7 +135,7 @@ TemplateEnd
 
 
 Template ChessDiagram
-	GuiName "Chess: $$Basename"
+	GuiName "Chess: $$AbsOrRelPathParent$$Basename"
 	HelpText
 		A chess position diagram.
 		This template will use XBoard to edit the position.
@@ -157,19 +157,19 @@ Template ChessDiagram
 	HelpTextEnd
 	InputFormat fen
 	FileFilter "*.fen"
-	EditCommand "xboard -lpf $$FName -mode EditPosition"
+	EditCommand "xboard -lpf $$Absname -mode EditPosition"
 	AutomaticProduction true
 	Format LaTeX
-		Product "\\loadgame{$$FPath$$Basename}\\showboard"
+		Product "\\loadgame{$$AbsOrRelPathMaster$$Basename}\\showboard"
 		Requirement "chess"
 	FormatEnd
 	Format Ascii
-		Product "$$Contents(\"$$Basename.asc\")"
+		Product "$$Contents(\"$$AbsPath$$Basename.asc\")"
 		UpdateFormat asciichess
-		UpdateResult "$$Basename.asc"
+		UpdateResult "$$AbsPath$$Basename.asc"
 	FormatEnd
 	Format DocBook
-		Product "[Chess: $$Basename]"
+		Product "[Chess: $$AbsOrRelPathMaster$$Basename]"
 	FormatEnd
 	Format LinuxDoc
 		Product "[Chess: $$FName]"
Index: src/insets/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.995
diff -u -p -r1.995 ChangeLog
--- src/insets/ChangeLog	2004/04/05 16:47:55	1.995
+++ src/insets/ChangeLog	2004/04/06 19:34:52
@@ -1,3 +1,11 @@
+2004-04-06  Georg Baum  <[EMAIL PROTECTED]>
+
+	* ExternalSupport.C (doSubstitution): add new variables $$AbsPath,
+	$$RelPath_Master, $$RelPath_Parent, $$Extension,
+	$$AbsOrRelPath_Master and $$AbsOrRelPath_Parent. Change the meaning
+	of $$Basename
+	* ExternalSupport.C (updateExternal): use absolute and output
+	filename where appropriate
 
 2004-04-05  André Pönitz  <[EMAIL PROTECTED]>
 	
Index: src/insets/ExternalSupport.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/insets/ExternalSupport.C,v
retrieving revision 1.5
diff -u -p -r1.5 ExternalSupport.C
--- src/insets/ExternalSupport.C	2004/03/25 10:12:43	1.5
+++ src/insets/ExternalSupport.C	2004/04/06 19:34:53
@@ -73,17 +73,51 @@ 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)
 {
 	string result;
-	string const basename = support::ChangeExtension(filename, string());
+	string const basename = support::ChangeExtension(
+			support::OnlyFilename(filename), string());
+	string const absname = support::MakeAbsPath(filename, buffer.filePath());
 	string const filepath = support::OnlyPath(filename);
+	string const abspath = support::OnlyPath(absname);
+	Buffer const * m_buffer = buffer.getMasterBuffer();
+	string relToMasterPath = support::OnlyPath(
+			support::MakeRelPath(absname, m_buffer->filePath()));
+	if (relToMasterPath == "./")
+		relToMasterPath.clear();
+	string relToParentPath = support::OnlyPath(
+			support::MakeRelPath(absname, buffer.filePath()));
+	if (relToParentPath == "./")
+		relToParentPath.clear();
 
 	result = support::subst(s, "$$FName", filename);
 	result = support::subst(result, "$$Basename", basename);
+	result = support::subst(result, "$$Extension",
+			'.' + support::GetExtension(filename));
 	result = support::subst(result, "$$FPath", filepath);
+	result = support::subst(result, "$$AbsPath", abspath);
+	result = support::subst(result, "$$RelPathMaster", relToMasterPath);
+	result = support::subst(result, "$$RelPathParent", relToParentPath);
+	if (support::AbsolutePath(filename)) {
+		result = support::subst(result, "$$AbsOrRelPathMaster",
+		                        abspath);
+		result = support::subst(result, "$$AbsOrRelPathParent",
+		                        abspath);
+	} else {
+		result = support::subst(result, "$$AbsOrRelPathMaster",
+		                        relToMasterPath);
+		result = support::subst(result, "$$AbsOrRelPathParent",
+		                        relToParentPath);
+	}
 	result = support::subst(result, "$$Tempname", params.tempname());
 	result = support::subst(result, "$$Sysdir", support::system_lyxdir());
 
@@ -96,7 +130,7 @@ string const doSubstitution(InsetExterna
 		string contents;
 
 		string const filepath = support::IsFileReadable(file) ?
-			buffer.filePath() : buffer.getMasterBuffer()->temppath();
+			buffer.filePath() : m_buffer->temppath();
 		support::Path p(filepath);
 
 		if (support::IsFileReadable(file))
@@ -139,16 +173,17 @@ void updateExternal(InsetExternalParams 
 	if (from_format.empty())
 		return; // NOT_NEEDED
 
-	string from_file = params.filename.absFilename();
+	string abs_from_file = params.filename.absFilename();
 
 	if (from_format == "*") {
-		if (from_file.empty())
+		if (abs_from_file.empty())
 			return; // NOT_NEEDED
 
 		// Try and ascertain the file format from its contents.
-		from_format = support::getExtFromContents(from_file);
+		from_format = support::getExtFromContents(abs_from_file);
 		if (from_format.empty())
 			return; // FAILURE
+
 	}
 
 	string const to_format = outputFormat.updateFormat;
@@ -163,24 +198,32 @@ 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();
 
-	if (external_in_tmpdir && !from_file.empty()) {
+	if (external_in_tmpdir && !abs_from_file.empty()) {
 		// We are running stuff through LaTeX
 		string const temp_file =
 			support::MakeAbsPath(params.filename.mangledFilename(),
 					     m_buffer->temppath());
-		unsigned long const from_checksum = support::sum(from_file);
+		unsigned long const from_checksum = support::sum(abs_from_file);
 		unsigned long const temp_checksum = support::sum(temp_file);
 
 		if (from_checksum != temp_checksum) {
-			if (!support::copy(from_file, temp_file))
+			if (!support::copy(abs_from_file, temp_file)) {
+				lyxerr[Debug::EXTERNAL]
+					<< "external::updateExternal. "
+					<< "Unable to copy "
+					<< abs_from_file << " to " << temp_file << endl;
 				return; // FAILURE
+			}
 		}
 
 		from_file = temp_file;
+		abs_from_file = temp_file;
 	}
 
 	string const to_file = doSubstitution(params, buffer,
@@ -192,13 +235,13 @@ void updateExternal(InsetExternalParams 
 
 	// 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(from_file, abs_to_file) < 0)
+	if (support::compare_timestamps(abs_from_file, abs_to_file) < 0)
 		return; // SUCCESS
 
 	string const to_file_base =
 		support::ChangeExtension(to_file, string());
 	/* bool const success = */
-		converters.convert(&buffer, from_file, to_file_base,
+		converters.convert(&buffer, abs_from_file, to_file_base,
 				   from_format, to_format);
 	// return success
 }

Reply via email to