#!/bin/sh

###############################################################
# NAME	otsotemplate	@(#)otsotemplate	1.1
#
# SYNOPSIS
#   Unix shell script for creating a minimum subset of source
#   code files when writing a new OTSO protocol class.
#
# DESCRIPTION
#   Make a bare-bones compilable template of source files
#   for an OTSO protocol.  No Upper or Lower layers are assumed,
#   you must add them later to the source code by hand.
#
#   'otsotemplate' creates .cx and .hx files for a protocol class,
#   as well as the service and peer interface files (.hx).
#
#   Usage:
#	otsotemplate filePrefix ClassName
#
#   Example:
#	otsotemplate tran0 Tran0
#
# BUGS:
#   None, but lots of missing features.
#
###############################################################

#
# directory where template source code lives
#
# was: TEMPL_DIR=$OTSO/demo/Examples/template
TEMPL_DIR=$OTSO/tools/otso-template

HERE=`pwd`

CMDNAME=`basename ${0}`

USAGE="
	Usage: ${CMDNAME} filePrefix classPrefix

	where:
		classPrefix = C++ class prefix name for created protocol classes

		filePrefix  = prefix name for the files to be created 

	example: ${CMDNAME} sess Session
"

#
# Verify number of arguments
#
if [ $# -ne 2 ]; then
	echo "${CMDNAME}: incorrect number of arguments."
	echo "${USAGE}"
	exit 1
fi

OBJECT=${1}; shift
CLASS=${1}; shift

#
# clean up template directory first, before using it.
#
LOCALDIR="-templ"
LOCAL=${HERE}/${OBJECT}${LOCALDIR}
rm -f ${TEMPL_DIR}/*.o ${TEMPL_DIR}/*xx ${TEMPL_DIR}/*demo
rm -rf ${LOCAL}
mkdir ${LOCAL}

#
# make new files from template directory's source code
#
cd ${TEMPL_DIR}
for i in `ls xxx*`
do
  FILENAME=`echo $i | sed -e "s/xxx/${OBJECT}/g"`
  sed -e "s/XXX/${CLASS}/g" $i | sed -e "s/xxx/${OBJECT}/g" \
	 > ${LOCAL}/${FILENAME}
done

sed -e "s/XXX/${CLASS}/g" Makefile | sed -e "s/xxx/${OBJECT}/g" \
	> ${LOCAL}/Makefile

ln -s $OTSO/makes/absolute.make ${LOCAL}/make
