#!/bin/bash
# Silver Grammar Duplicator
# Use this script to duplicate grammar directories

if [ $# -ne 2 ]; then 
	echo -e -n "Silver Grammar Duplicator, use with:\n"
	echo -e -n "\t${0##*/} origin destiny\n"
	exit 0;
fi
if [ -d "$1" ]; then
	mkdir "$2" || exit 2; 
	cd "$1"
	for f in *; do
#		FILE=
		if [ "${f##*.}" = "sv" ] || [ "$f" = "silver-compile" ]; then 
			sed "s/$1/$2/" "$f" > "../$2/$f" 
		else
			if [ "${f##*.}" != "jar" ];then
				cp "$f" "../$2/$f"
			fi
		fi
	done
	cd ..
else
	echo "The specified grammar origin, isn't a folder"
fi
exit 0;