1c42f4d56SDmitri Tikhonov#!/bin/bash
2c42f4d56SDmitri Tikhonov#
3c42f4d56SDmitri Tikhonov# Script to run a scenario file.  A scenario file contains encoder parameters
4c42f4d56SDmitri Tikhonov# as well as a list of headers in QIF format.  The headers are encoded and
5c42f4d56SDmitri Tikhonov# the output is then decoded and compared to the original.
6c42f4d56SDmitri Tikhonov
7c42f4d56SDmitri Tikhonovset -x
8c42f4d56SDmitri Tikhonovset -e
9c42f4d56SDmitri Tikhonov
10c42f4d56SDmitri Tikhonovfor NEED in interop-encode interop-decode sort-qif.pl; do
11c42f4d56SDmitri Tikhonov    type $NEED
12c42f4d56SDmitri Tikhonov    if [ $? -ne 0 ]; then
13c42f4d56SDmitri Tikhonov        echo $NEED is not in $PATH 1>&2
14c42f4d56SDmitri Tikhonov        exit 1
15c42f4d56SDmitri Tikhonov    fi
16c42f4d56SDmitri Tikhonovdone
17c42f4d56SDmitri Tikhonov
18c42f4d56SDmitri Tikhonovfunction cleanup {
19c42f4d56SDmitri Tikhonov    rm -vf $QIF_FILE
20c42f4d56SDmitri Tikhonov    rm -vf $BIN_FILE
21c42f4d56SDmitri Tikhonov    rm -vf $RESULTING_QIF_FILE
22c42f4d56SDmitri Tikhonov    rm -vf $ENCODE_LOG
23c42f4d56SDmitri Tikhonov    rmdir $DIR
24c42f4d56SDmitri Tikhonov}
25c42f4d56SDmitri Tikhonov
26c42f4d56SDmitri Tikhonovif [ -z "$DO_CLEANUP" -o "$DO_CLEANUP" != 0 ]; then
27c42f4d56SDmitri Tikhonov    trap cleanup EXIT
28c42f4d56SDmitri Tikhonovfi
29c42f4d56SDmitri Tikhonov
30c42f4d56SDmitri TikhonovRECIPE=$1
31c42f4d56SDmitri Tikhonov
32c42f4d56SDmitri Tikhonovsource $RECIPE
33c42f4d56SDmitri Tikhonov
34c42f4d56SDmitri TikhonovDIR=/tmp/recipe-out-$$$RANDOM
35c42f4d56SDmitri TikhonovENCODE_LOG=$DIR/encode.log
36c42f4d56SDmitri TikhonovQIF_FILE=$DIR/qif
37c42f4d56SDmitri TikhonovBIN_FILE=$DIR/out
38c42f4d56SDmitri TikhonovRESULTING_QIF_FILE=$DIR/qif-result
39c42f4d56SDmitri Tikhonovmkdir -p $DIR
40c42f4d56SDmitri Tikhonov
41c42f4d56SDmitri Tikhonovif [ "$AGGRESSIVE" = 1 ]; then
42c42f4d56SDmitri Tikhonov    ENCODE_ARGS="$ENCODE_ARGS -A"
43c42f4d56SDmitri Tikhonovfi
44c42f4d56SDmitri Tikhonov
4529e375a4SDmitri Tikhonovif [ "$IMMEDIATE_ACK" = 1 ]; then
4629e375a4SDmitri Tikhonov    ENCODE_ARGS="$ENCODE_ARGS -a 1"
4729e375a4SDmitri Tikhonovfi
4829e375a4SDmitri Tikhonov
49eaae2701SStephen Petridesif [ "$ANNOTATIONS" = 1 ]; then
50eaae2701SStephen Petrides    ENCODE_ARGS="$ENCODE_ARGS -n"
51eaae2701SStephen Petridesfi
52eaae2701SStephen Petrides
53c42f4d56SDmitri Tikhonovif [ -n "$RISKED_STREAMS" ]; then
54c42f4d56SDmitri Tikhonov    ENCODE_ARGS="$ENCODE_ARGS -s $RISKED_STREAMS"
55c42f4d56SDmitri Tikhonov    DECODE_ARGS="$DECODE_ARGS -s $RISKED_STREAMS"
56c42f4d56SDmitri Tikhonovfi
57c42f4d56SDmitri Tikhonov
58c42f4d56SDmitri Tikhonovif [ -n "$TABLE_SIZE" ]; then
59c42f4d56SDmitri Tikhonov    ENCODE_ARGS="$ENCODE_ARGS -t $TABLE_SIZE"
60c42f4d56SDmitri Tikhonov    DECODE_ARGS="$DECODE_ARGS -t $TABLE_SIZE"
61c42f4d56SDmitri Tikhonovfi
62c42f4d56SDmitri Tikhonov
63c42f4d56SDmitri Tikhonovecho -e "$QIF"\\n > $QIF_FILE
64c42f4d56SDmitri Tikhonov
65c42f4d56SDmitri Tikhonovinterop-encode $ENCODE_ARGS -i $QIF_FILE -o $BIN_FILE 2>$ENCODE_LOG
66c42f4d56SDmitri Tikhonovinterop-decode $DECODE_ARGS -i $BIN_FILE -o $RESULTING_QIF_FILE
67c42f4d56SDmitri Tikhonovdiff <(sort-qif.pl --strip $QIF_FILE) \
68c42f4d56SDmitri Tikhonov                <(sort-qif.pl --strip $RESULTING_QIF_FILE)
69