#!/bin/sh
#=========================================================================
# Script to configure EPOS applications
#
# Auth: Guto
#=========================================================================

#=========================================================================
# CUSTOMIZABLE DEFINITIONS
#=========================================================================
SYSTEM_INFO=$EPOS/include

#=========================================================================
# VARIABLES
#=========================================================================
status=0
do_exec=eval
do_echo=:
getting_output_file=0
my_name=`basename $0`

#=========================================================================
# ARGUMENT PARSING
#=========================================================================
for arg in "$@" ; do
    if [ $getting_output_file = 1 ] ; then
	getting_output_file=0
	output_file="$arg"
	continue
    fi
    case "$arg" in 
    -o)
	getting_output_file=1
	;;
    --help)
	echo "This is a script to extract system dependencies from "
	echo "pre-compiled EPOS programs."
	echo
	echo "Options:"
        echo "  -o <FILE> write output to <FILE>"
	echo "  --help    print this help"
	echo
	echo "Examples:"
	echo "   $my_name foo.o"
	echo "   $my_name -o foo.anl foo.o"
	exit 1
	;;
    *)
	if [ -s "$arg" ] ; then
	    ext=`expr "$arg" : '.*\(\..*\)'`
	    if [ "$ext" = ".anl" ] ; then
		input_file="$arg"
	    else
		echo "Error: file \"$input_file\" is corrupted!"
		exit -1
	    fi
	else
	    echo "Error: invalid argument \"$arg\"!"
	    exit -1
	fi
	;;
    esac
done

#=========================================================================
# COMMAND ISSUING
#=========================================================================
if [ -z $output_file ] ; then
    output_file="`basename $input_file $ext`.key"
fi

if [ -s $output_file ] ; then
    echo "Error: file \"$output_file\" already exists!"
    exit -1
fi

cp $SYSTEM_INFO/default.key $output_file
	
exit $status
