#!/bin/sh
# This is a wrapper script to let LyX/Cygwin use either a native Win32 or
# Cygwin version of convert (part of ImageMagick).
#
# This script simply changes all input pathnames into Windows or Cygwin
# pathnames depending on which version of convert is being used.
# If the pathnames contain spaces, either enclose them in double quotes
# or escape the spaces. For example:
# convert "eps:/path with/spaces.pdf" "png:file with spaces.eps"
# convert eps:/path\ with/spaces.pdf png:file\ with\ spaces.eps
#
# 2007-08-06 Enrico Forestieri
# =======================================================================

# The program to call (This should be in the PATH)
# Warning: if ImageMagick isn't installed, the Windows'
# file system convert utility will be called!
prog=convert.exe

# Check whether we are using the cygwin version
if [ "`which $prog 2>/dev/null`" = "/usr/bin/convert.exe" ]; then
    flag=""
else
    flag="-m"
    export TEMP=/tmp
fi

while [ $# -gt 0 ] ; do
    case "$1" in
	?:*)  prog="$prog '`cygpath $flag -- "$1"`'"
	      ;;
	*:*)  fmt=`echo "$1" | cut -d: -f1`
	      file=`echo "$1" | cut -d: -f2-`
	      file=`cygpath $flag -- "$file"`
	      prog="$prog '$fmt:$file'"
	      ;;
	-*)   prog="$prog $1"
	      ;;
	*)    prog="$prog '`cygpath $flag -- "$1"`'"
	      ;;
    esac
    shift
done

eval "exec $prog"
