#!/bin/sh

# chimera-giftoppm 1.1
# Created Fri Jun 17 02:56:27 MET DST 1994
# <Nicolas.Pioch@enst.fr>

# I hope Chimera can eventually set the environment variable
# CHIMERA_BACKGROUND, but this hack will do in the meantime...
# (edit as needed, or set it before starting Chimera)

back_color=${CHIMERA_BACKGROUND-moccasin}

default_conv=color

while test $# -gt 0; do
  case "$1" in
  -m*) default_conv=mono ;;
  -g*) default_conv=gray ;;
  -c*) default_conv=color ;;
  -*)
    echo "$0: unknown option: $1" >&2
    exit 1
    ;;
  *)
    if test "$filename"; then
      echo "$0: only one file name allowed: $1" >&2
      exit 1
    else
      filename="$1"
    fi
    ;;
  esac
  shift
done

if test "$filename"; then :; else
cat <<EOF
Usage: $0 [-option] <filename>

Converts a gif file into a format suitable for Chimera,
eventually adapting the background color.

Available options: -mono, -gray, -color (default).
EOF
exit 1
fi

exec 2>/dev/null

case "$default_conv" in
gray) giftrans -C -B "$back_color" "$filename" | giftoppm | ppmtopgm ;;
mono) giftrans -C -B "$back_color" "$filename" | giftoppm |ppmtopgm|pgmtopbm ;;
*)    giftrans -C -B "$back_color" "$filename" | giftoppm ;;
esac

