#! /bin/bash -e

. usage.sh

echoHelp()
{
    usage faust2svg "<file.dsp>"
    echo "Compiles Faust programs to SVG"
    exit
}

if [ "$#" -eq 0 ]; then
    echo 'Please, provide a Faust file to process !'
    echo ''
    echoHelp
fi

for p in $@; do
    if [ $p = "-help" ] || [ $p = "-h" ]; then
        echoHelp
    elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
        FILES="$FILES $p"
    else
        OPTIONS="$OPTIONS $p"
    fi
done

for f in $FILES; do
    faust $OPTIONS -t 0 -svg $@ -o /dev/null
done

