#!/bin/sh -
#
# gif2xpm files...
#
#   This uses the pbmplus package to convert from gif to xpm
# This will convert black and white gifs to xbm's automatically
#
b="                                                                         
"
tmp=/tmp/gif2xpm.$$

trap "rm -f $tmp; exit 0" 1 2 3 15

for i in "$@" ; do
  echo -n "${b}  converting \"$i\"
"
  if [ ! -f "$i" ]; then
    echo -n "${b}"
    echo >&2 "Unable find file \"$i\""
    continue
  fi

  # --- find out the type ---
  name="`expr "//$i" : '.*/\([^/]*\)'`"
  suffix="`expr '$name' : '.*\.\([^.]*\)'`"
  name="`expr '$name' : '\([^.]*\)'`"

  j=`basename $i .$suffix`   # destination name

  bmptoppm "$i" | ppmtoxpm 2>/dev/null | xpm-fix -o "$j".xpm
done

echo "${b}DONE!"

rm -f $tmp

