#!/bin/bash

unset -v OPTIND

tmp="${TMPDIR}/.scan.tmp"

while getopts :l:o:t: OPT $@; do
    case "$OPT" in
	l)  log=$OPTARG
	;;
	o)  output=$OPTARG
	;;
	t)  tmp=$OPTARG
	;;
    esac
done

shift `expr $OPTIND - 1`

[ -n "$output" ] || (echo "Пожалуйста, укажите по ключу -o имя выходного файла"; exit -1)

if [ -z "$log" ]; then
    ./hp4600scanfullfile $tmp
else
    ./hp4600scanfullfile $tmp > $log
fi

./fixhp4600output $tmp > $output
`which rm` -f $tmp

