[magick-users] Automatic conversion Linux shell script -> DOS / Windows batch file
Wolfgang Hugemann
Auto at Hugemann.de
Fri May 8 07:24:47 PDT 2009
To all Windows users over here,
recently, I re-wrote the introduction to using IM under Windows, which
is now placed at http://www.imagemagick.org/Usage/windows/. I started
with what Anthony had written.
So far, I covered only batch files, but I am planning to cover the
Windows Script Host (more precisely its VisualBasic flavour) on one of
the following weekends.
Anthony suggested that someone should try to write an utility to convert
IM Linux shell scripts -- i.e. the examples on Anthony's website -- into
the equivalent DOS batch files. So I gave it a try with SED. The Unix
utility SED (Streamline EDitor) is also available for Windows at
SourceForge, see http://sed.sourceforge.net.
Basically, you only need to place the three files:
sed.exe, libiconv2.dll, libintl3.dll
into a directory which is included in the executable search path,
possibly the Windows system directory or the IM program directory.
As I am not the world's most skilled SED user, someone should perhaps
check the script given below.
I was for example unable to place a UNIX in-line comment into a separate
line BEFORE the line being commented in UNIX, so I placed it behind it.
I also tried to pack all continuated lines into just one line by the
script, such that it could be one out of a FOR loop, but my code for this:
# Merge continuated lines
:a
N
s/\\[ ]*\n[ ]*/ /
ta
somehow interfered with the rest of the script, so I dropped the issue.
After testing, we will probably place the script at
http://www.imagemagick.org/Usage/windows/.
Wolfgang Hugemann
###################################################
# SED command file to convert
# an ImageMagick Linux shell script
# into the equivalent DOS/Windows batch file.
# Get SED at http://sed.sourceforge.net
#
# USAGE: sed -f cim.txt linux.scr > windows.bat
#
# Input: linux.scr = Linus shell script
# Output: windows.bat = DOS/Windows batch file
#
# Version 0.1 by Wolfgang Hugemann
###################################################
# Replace "convert" -> "IMcomvert"
# The option 'i' means "case Insensitive"
# The option 'g' means "all occurences" (global)
s/convert/IMconvert/ig
# Replace all single quotes (') by double quotes (")
s/'/\"/g
# Double all percent signs
s/%/%%/g
# Un-escape paranthesis '(', ')' and exclamation marks '!'
s/\\\([()!]\)/\1/g
# Escape all shell characters, i.e. & | < > ^
s/\([&|<>^]\)/^\1/g
# Replace the UNIX comment sign '#' by two double colons '::'
# Insert a line break '\n' to ensure that the comment line
# starts with '::'
s/#/\n::/
# Bracket fully qualified filenames
# i.e. c:\fully qualified\finame.jpg
# by double quotes
s/\(.:.*\.[a-z,A-Z]*\)[ ]/\"\1\" /
# Replace the line continuation character
s/\\[ ]*$/^/
More information about the Magick-users
mailing list