#!/bin/bash

file=$1

if [ -z "$file" ]
then
  echo "usage $0 contourfile [rules list]"
  exit 1
fi

shift

showcmd="showcontour --ge xfig --skip 0.3 --xfigspecial --title"
title=${file%.morse}
title=${title%.sketch}

if [ -z "$1" ]
then
  cat $file | contour printmorse | $showcmd $title
  exit $?
fi

command="cat $file |"

while [ -n "$1" ]
do
  rule=$1
  shift

  title=${title}_${rule}
  command="$command contour applyrule $rule |"
done

command="$command contour printmorse | $showcmd $title"

# echo "command: $command"

eval $command
