#!/bin/sh

#
# Convert ascii file to g3 fax pages (using a2x and ghostscript).
#
# usage: a2g3 [ -o fax-file ] [ ascii-file ]
#
# reads from stdin if ascii-file is missing; writes to stdout if fax-file
# is missing. Use %d within fax-file to produce one file per fax page.
# Example: a2g3 -o fax%03d.g3 README
#

while test -n "$1"
do
  case $1 in
    -o) OUT="$2"; shift;;
    *) IN="$1";;
  esac
  shift
done

if test -z "$OUT"; then OUT="-"; fi

a2x -dps -s12 $IN | gs -q -sDEVICE=faxg3 -dNOPAUSE -sOutputFile=$OUT -


