#! /bin/bash
src="./pure_data_docs_test"
dest="./pure_data_docs_svgs/pure_data_docs"

for i in `find "$path" -name "*.pd"`
do
	name=$(echo `basename "$i"`)
	dir=$(echo `dirname "$i"`)
	namedir=$(echo `basename "$dir"`)

	echo ./pure_data_docs_svgs/pure_data_docs/"$namedir"/"$name".svg

	
	/usr/lib/puredata/bin/pd -open "$i" -open "autoexport.pd"
	
#the sleep seems required because if pd is opened too many times it throws a networked needed errors. so this gives the windows time to close.
	
	sleep 3

#cleanup	
	find . -maxdepth 1 -name "autoexport*svg" -exec rm -rf {} \;
	find . -maxdepth 1 -name "$name*svg" -exec mv {} "$dest"/"$namedir"/"$name".svg \;
	
done

#additionally on any stragglers, subpatches (that don't get moved because they don't have a .pd extention you can run the following to clear out the text patch2svg makes on its output

#for i in *.svg
#do	
#	n=$(echo "${i%%.*}")
#	mv "$i" "$n".svg
#done