#! /bin/sh
#
#  addafmpsn
#
#  Add PSName statements to the fontlist file for all AFM files in $1.
#  Copyright (c) 1993 Frame Technology Corp. All rights reserved.
#  $Id: addafmpsn,v 1.1 1993/02/28 20:38:17 adl Exp $

myname=`expr //$0 : '.*/\(.*\)'`
usage="Usage: $myname fontdir"

if [ $# -eq 1 ]; then
	fontdir=$1
	[ -d "$fontdir" ] || {
		echo "$usage"
		echo "Error: $fontdir is not a directory."
		exit 1
	}
	fontlist=$fontdir/fontlist
	[ -f "$fontlist" -a -r "$fontlist" ] || {
		echo "$usage"
		echo "Error: fontlist file is missing or unreadable in $fontdir."
		exit 1
	}
	cp $fontlist $fontlist.new
elif [ $# -eq 2 ]; then
	fontdir=$1
	fontlist=$2
else
	echo "$usage"
	exit 1
fi

# portable echo -n
case `echo -n` in
  -n)
	nl1=''; nl2='\c' ;;
  *)
	nl1='-n '; nl2='' ;;
esac

echo "Adding PSName statements for all afm files..."
( for filename in $1/*.afm
do
	echo $nl1 `expr //$filename : '.*/\(.*\)\.afm'` ' ' $nl2
	tr '\015' '\012' < $filename | grep '^FontName'
done ) | awk '{ printf("<PSName %s  %s >\n", $1, $3); }' >> $fontlist.new

[ $# -eq 1 ] && echo "Done. Updated fontlist is in $fontlist.new"
exit 0
