#! /bin/bash

files="
bfs
bfs_queue
buchi
common
comm_shmem
context
darray
dbfs_comm
ddfs_comm
delta_ddd
dfs
dfs_stack
errors
event
harray
htbl
heap
graph
includes
list
main
observer
papi_stats
por_analysis
reduction
rwalk
simulator
state
workers"

toolName=helena-generate-checker
binName=../../bin/$toolName

function genString () {
    F=$1
    if [ -e $F ]
    then
	echo "    ############################################################"
	echo "    f = open (dir + \"/\" + \"$F\", \"w\")"
	echo "    f.write (\"\\"
	cat $F | \
	    sed 's/\\/\\\\/g' | \
	    sed 's/"/\\"/g' | \
	    sed 's/$/\\n\\/'
	echo "\"    )"
	echo "    f.close ()"
    fi
}

echo "#!/usr/bin/python" > $binName
echo >> $binName
echo "import sys" >> $binName
echo >> $binName
echo "def genFiles (dir):" >> $binName
for file in $files
do
    genString $file.h >> $binName
    genString $file.c >> $binName
done

echo >> $binName
echo >> $binName
echo >> $binName
echo "if (len (sys.argv) != 2):" >> $binName
echo "    print (\"usage: $toolName directory\")" >> $binName
echo "    exit (1)" >> $binName
echo "else:" >> $binName
echo "    genFiles (sys.argv[1])" >> $binName
echo "    exit (0)" >> $binName

chmod +x $binName
