#!/bin/sh
# fontctl by Jun Nishii <nishii@postman.riken.go.jp>
#################################################
# set the directory of dvi2ps and dvips

DVI2PSDIR=/usr/share/dvi2ps/
DVI2PSCNF=fontdesc

DVIPSDIR=/usr/share/texmf/dvips/
DVIPSCNF=config.ps

#################################################
CheckFile(){ # <directory storing the file> <file name>
if [ ! -f "$1/$2" ]; then
    echo "$2 is not found in " $1
    echo "Check the directory and try again!!!"
    exit
fi
}

StartCMPS(){ # <directory of config file> <config file name>
if [ ! -d $1 ]; then
    echo "$1 is not found..."
    exit
fi

CheckFile $1 $2
CheckFile $1 $2.cmps
(cd $1; rm $2; ln -s $2.cmps $2)

echo "OK, Enjoy CMPS fonts!"
}

StartPK(){ # <directory of config file> <config file name>
if [ ! -d $1 ]; then
    echo "$1 is not found..."
    exit
fi
CheckFile $1 $2
CheckFile $1 "$2.pk"
(cd $1; rm $2; ln -s $2.pk $2)

echo "OK, Enjoy PK fonts!"
}

Status(){ # <directory of config file> <config file name>
CheckFile $1 $2
CONF=`ls -l $1/$2`
MODE="${CONF##*.}"
case "$MODE" in
    cmps) echo "CMPS font mode" ;;
    pk)   echo "PK font mode" ;;
    *)    echo "unknown mode" ;;
esac
}

case ${0##*/} in
    dvi2psfnt)TAGDIR=$DVI2PSDIR; CNFFILE=$DVI2PSCNF ;;
    dvipsfnt) TAGDIR=$DVIPSDIR;  CNFFILE=$DVIPSCNF  ;;
    *)  echo "This program control the font setting of dvips and dvi2ps"
	echo "Usage:"
	echo " dvipsfnt  [cmps|pk|status]   : [CMPS|PK|status] mode for dvips"
	echo " dvi2psfnt [cmps|pk|status]   : [CMPS|PK|status] mode for dvi2ps"
    ;;
esac

case $1 in
    cmps|CMPS)     StartCMPS $TAGDIR $CNFFILE ;;
    pk|PK)         StartPK $TAGDIR $CNFFILE ;;
    status|STATUS) Status $TAGDIR $CNFFILE ;;
    *)	echo Usage: 
	echo " $0 cmps    : start CMPS-mode"
	echo " $0 pk      : stop  CMPS-mode (start PK-mode)"
	echo " $0 status  : check status (CMPS|PK|unknown)"
    ;;
esac
exit
