Jean-Marc,

it appears that LyX is outputting filenames from the graphics 
conversion code which are a weird mixture of Win32 and Unix. Stuff 
like 'C:/foo/bar/file.eps' should obviously be 'C:\foo\bar\file.eps'.

The real fix is to find the problem in the LyX sources themselves, but 
the attached patch modifies convertDefault.sh to sanitize the file 
names passed to it. I'm not sure what you think of such a thing.

The patch also fixes a real bug in convertDefault.sh. We check that 
the generated file really exists before telling the outside world 
that all is Ok. This check uses 'cut' and will fail when presented 
with Win32 file names (looks for a file called 'C' rather than for 
'C:\foo\bar\file.eps').

Is it Ok to apply the second part (I'll apply it to the devel branch 
also.)

Any thoughts on a strategy to address the first bug?

-- 
Angus
Index: lib/scripts/convertDefault.sh
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/scripts/convertDefault.sh,v
retrieving revision 1.5
diff -u -p -r1.5 convertDefault.sh
--- lib/scripts/convertDefault.sh	13 Jan 2003 23:35:18 -0000	1.5
+++ lib/scripts/convertDefault.sh	3 Nov 2003 11:42:45 -0000
@@ -6,18 +6,35 @@
 # replacement in ~/.lyx/scripts
 #
 # converts an image from $1 to $2 format
-convert -depth 8 $1 $2
-if [ $? -ne 0 ]; then
-    exit $?
-fi
+
+win32_sanitize() {
+	# If the string starts like 'PNG:C:',
+	# then change all occurences of '/' to '\'.
+	echo $1 | sed '/^[a-zA-Z]*:[A-Z]:/s,/,\\,g'
+}
+
+
+# LyX can pass the script filenames like 'C:/foo/bar/file.abc'
+# Change these to 'C:\foo\bar\file.abc'.
+arg1=`win32_sanitize $1`
+arg2=`win32_sanitize $2`
+
+convert -depth 8 $arg1 $arg2 || {
+	echo "$0 ERROR"
+	echo "Execution of \"convert\" failed."
+	exit 1
+}
 
 # It appears that convert succeeded, but we know better than to trust it ;-)
 # convert is passed strings in the form "FMT:FILENAME", so use the ':' to
 # delimit the two parts.
-FILE=`echo $2 | cut -d ':' -f 2`
+# Do not use 'cut' because Win32 filenames have the form 'C:\my\file'.
+FILE=`echo $arg2 | sed 's,^[^:]*:,,'`
 
-# FSTATUS == 0 is the file exists and == 1 if it does not.
-FSTATUS=0
-test -f $FILE || FSTATUS=1
+test -f $FILE || {
+	echo "$0 ERROR"
+	echo "Unable to find file \"${FILE}\""
+	exit 1
+}
 
-exit $FSTATUS
+echo "$0 generated file \"${FILE}\" successfully."

Reply via email to