#!/bin/sh
# sparse shell script interpreter
# usage: sssi <input file> <output file>
#
readSssCommand() {
	rm -f ${tmp}
	while read line
	  do
	  if test "X${line}" = "X#SPARSE_SHELL_SCRIPT_EXECUTE_END"
		  then
		  break
	  else
		  echo ${line} >> ${tmp}
	  fi
	done
}

if test $# != 2
then
	echo "usage: sssi <input file> <output file>"
fi
input=$1
output=$2
tmp=/tmp/sssitmpscript
rm ${output}
cat ${input} | while read line
do
	if test "X${line}" = "X#SPARSE_SHELL_SCRIPT_EXECUTE"
	then
		readSssCommand
		source ${tmp}
	elif test "X${line}" = "X#SPARSE_SHELL_SCRIPT_EXECUTE_AND_INCLUDE_STDOUT"
    then
		readSssCommand
		source ${tmp} >> ${output}
    else
		echo "${line}" >> ${output}
    fi
done
