#!/bin/ksh

USAGE="$0 dirname/classname"

if [[ ! -d common ]] || [[ ! -d client ]] || [[ ! -d server ]]
then
	print -u2 "Run from top level directory."
	exit 1
fi

if (( $# != 1 )) || [[ $1 != @(common|client|server|metaserver)"/"+([A-Za-z0-9_]) ]]
then
	print -u2 "Usage: $USAGE"
	print -u2 "(Leave off file name extension)"
	exit 2
fi

name="$1"
classname="$(print -- "$name" | cut -f2 -d/)"

hfile="${name}.hpp"
cfile="${name}.cpp"
guard="LM_$(print -- "$name" | tr / _ | tr a-z A-Z)_HPP"

if [[ -a $hfile ]] || [[ -a $cfile ]]
then
	print -u2 "$name: already exists"
	exit 1
fi

print "Creating $hfile..."
cat > "$hfile" <<EOF
/*
 * $hfile
 *
$(sed 's/^/ * /' < tools/boilerplate.txt)
 * 
 */

#ifndef $guard
#define $guard

namespace LM {
	class $classname {
	private:

	public:

	};
}

#endif
EOF

print "Creating $cfile..."
cat > "$cfile" <<EOF
/*
 * $cfile
 *
$(sed 's/^/ * /' < tools/boilerplate.txt)
 * 
 */

#include "${classname}.hpp"

using namespace LM;
using namespace std;

EOF

print "Adding $hfile..."
svn add "$hfile"
print "Adding $cfile..."
svn add "$cfile"

print "Make sure you add ${classname}.o to the OBJS variable in the Makefile."
