#!/bin/sh
# Author: Guido Flohr <gufl0000@stud.uni-sb.de>
# Starts CAB from the command line or from within your mailer.
# Please edit this file and copy it to /usr/local/bin.  Now
# change the mailer configuration to make it call the script
# to display html files.

# Replace /e/cab with the path where cab.app resides.  This is
# necessary since CAB won't find its resource file if you start
# it from the current directory.
cd /e/cab/

# Now convert all arguments into a format that CAB understands:
NEWARGS=$*

# Now convert each argument:
for ARG in $NEWARGS; do
  # Change every slash into a backslash: /tmp/foobar -> \tmp\foobar
  CONVERTED=`echo $ARG | tr '/' '\\\\'`
  # Prepend "U:" to it: \tmp\foobar -> U:\tmp\foobar
  CONVERTED="U:$CONVERTED"
  
  # For CAB we have to do something special now.  If the argument was
  # a URL we have to leave it unchanged.  We simply assume a URL if
  # there was a colon (:) inside the argument.  Of course it could
  # be possible that the colon wasn't meant to indicate a URL but
  # was meant to indicate a drive letter like "D:\html\foobar.html".
  # But in this case it also doesn't hurt to leave it unchanged.
  echo "$ARG" | grep -q ':'
  test $? && CONVERTED="$ARG"
  
  # The rest is alright with every program not only CAB.  
  # Add the converted argument to the rest of the arguments.
  CALLARGS="$CALLARGS $CONVERTED"
  # We're already in CAB's directory.  We simply call it with the
  # converted arguments.
  ./cab.app $CALLARGS
done

# And that's it.  If you want to use this file with another program
# than CAB it should usually be sufficient to change the path where
# CAB is found to the path where your program is found.  You can
# also remove the two special lines for CAB that undo the converting
# for URLs.  If you leave them unchanged it shouldn't hurt however.
# Just in case:  This isn't meant to be as an example for elegant
# shell programming. I just wanted to show non-programmers an 
# easy-to-understand way to invoke GEM programs from the command line.
