#!/bin/sh

# start of redirection stdout -> stderr, stdin <- /dev/null
{
progname=`basename $0`

DIR_PERMS=1777
FILE_PERMS=644

if test $# -lt 1 ; then
  echo "Usage: $progname name."
  exit 1
fi

if test ! -f "`kpsetool -w cnf texmf.cnf`"; then
	echo "$progname: global Kpathsea configurarion file texmf.cnf not found."
	echo
	echo "Please set the environment variable TETEXDIR or TEXMFCNF correctly."
	echo "For details see the teTeX and the Kpathsea manual"
	exit
fi

TEXMF=`kpsetool -v '$TEXMF'`
dcfontdir="$TEXMF/fonts/source/public/dc"
ls_R="$TEXMF/ls-R"

test -d "$dcfontdir" || exit 1
cd "$dcfontdir" || exit 1

NAME="`basename $1 .mf`"
rootname=`echo "$NAME" | sed 's/[0-9]*$//'`
pointsize=`echo "$NAME" | sed "s/^$rootname//"`

case "$NAME" in
dc*)	;;
*)	exit
esac

case "$pointsize" in
"") ;;
11) realsize=10.95444 ;;	# \magstephalf
14) realsize=14.4 ;;	# \magstep2
17) realsize=17.28 ;;	# \magstep3
20) realsize=20.74 ;;	# \magstep4
25) realsize=24.88 ;;	# \magstep5
*) realsize="$pointsize" ;;
esac

mfname="$NAME.mf"
if test -f "$mfname"; then
	echo "$dcfontdir/$mfname already exists!"
	echo $dcfontdir/$mfname >&3
	append_db "$dcfontdir" "$mfname"
	exit
fi

cat > "$mfname.tmp$$" <<EOF
if unknown dxbase: input dxbase fi;
gensize:=$realsize;
generate $rootname;
EOF

chmod "$FILE_PERMS" "$mfname.tmp$$"
rm -f "$mfname"
mv "$mfname.tmp$$" "$mfname"
} 1>&2 </dev/null
# end of redirection stdout, stdin

echo "$dcfontdir/$mfname"
append_db "$dcfontdir" "$mfname" 1>&2
