:
#! /bin/sh -f
#
# Take all of the Type 1 .ps files in a directory and generate a fonts.scale
# file containing each of the fonts with scalable entries.
#
# $NCDId: @(#)mkfdir,v 1.4 1996/03/14 01:31:53 jcc Exp $
#

# --------------------------------------------------------------------------
# Determine whether we are using BSD or SYSV echo

if test "`echo -n x`" = x ; then
        ECHON=-n
elif test "`echo x\\\\c`" = x ; then
        ECHOC="\\c"
fi
export ECHON ECHOC

IS_DIR=-d

# --------------------------------------------------------------------------
# Set some paths

PATH=/bin:/usr/bin:/usr/ucb

TMP=/tmp/mkfdir.temp
TMPFILES=/tmp/mkfdir.tempfiles

destdir=$1
if test $# -lt 1; then
  destdir="."
fi

if [ ! -d $destdir ] ; then
	echo "mkfdir, Error: Directory \"$destdir\" is not accessable."; exit 1
fi
outfile=$destdir/fonts.scale

# --------------------------------------------------------------------------
# Determine whether we are using BSD or SYSV ls
if '/bin/ls -1 $destdir' > /dev/null 2>&1 ; then
	LS="/bin/ls -1"
else
	LS="/bin/ls"
fi

# --------------------------------------------------------------------------

$LS $destdir | grep '\.ps$' > $TMPFILES
$LS $destdir | grep '\.pfa$' >> $TMPFILES
# some binary files make it barf
#$LS | grep '\.pfb$' >> $TMPFILES

sayfont='echo $font with $encoding'
addfont='echo $file" -adobe-"$facename"-"$weight"-"$italic"-"$sWidth"--0-0-0-0-"$pitch"-0-"$registry"-"$encoding >> $TMP'

# Clear the temporary file.
echo $ECHON "" $ECHOC > $TMP

for file in `cat $TMPFILES` ; do

  font=`fgrep FontName $destdir/$file | sed -e 's#.* /##g' -e 's# .*##g'`

  # See if this is an italic or oblique font.
  #
  italic="r"

  temp=`echo $font | sed -e 's/[iI]ta//g'`
  if test "$temp" != "$font" ; then
    italic="i"
  fi

  temp=`echo $font | sed -e 's/[oO]bl//g'`
  if test "$temp" != "$font" ; then
    italic="o"
  fi

  # See if this is a fixed pitch font.
  #
  pitch="P"
  
  temp=`fgrep isFixedPitch $destdir/$file`
  if test "$temp[2]" = "true" ; then
    pitch="m"
  fi

  # Separate the facename and get the weight.
  #
  facename=`echo $font | sed -e 's/-.*//g'`
  weight=`fgrep Weight $destdir/$file | sed -e 's/.*(//g' -e 's/).*//g'`

  # Look for variations on Condensed
  #
  sWidth=""
  comp=`echo $font | sed -e "s/$weight//g"`

  # Special prefixes.
  temp=`echo $comp | sed -e 's/[Uu]lt//g'`
  if test "$temp" != "$comp" ; then
    sWidth='ultra '
  fi
  temp=`echo $comp | sed -e 's/[Ee]xt//g'`
  if test "$temp" != "$comp" ; then
    sWidth='extra '
  fi

  # The meat.
  temp=`echo $comp | sed -e 's/[Cc]ond//g'`
  if test "$temp" != "$comp" ; then
    sWidth="${sWidth}condensed"
  else 
    temp=`echo $comp | sed -e 's/[Cc]omp//g'`
    if test "$temp" != "$comp" ; then
      sWidth="${sWidth}compressed"
    else
      temp=`echo $comp | sed -e 's/[Nn]arr//g'`
      if test "$temp" != "$comp" ; then
        sWidth="${sWidth}narrow"
      fi
    fi
  fi

  if test -z "$sWidth" ; then
    sWidth='normal'
  fi

  # Echo the stuff out to std out.

  if fgrep 'StandardEncoding' $destdir/$file >/dev/null 2>&1 ; then

    registry="iso8859"
    encoding="1"

    eval $sayfont
    eval $addfont

    encoding="adobe"

    eval $sayfont
    eval $addfont
  
  else

    registry="adobe"
    encoding="fontspecific"

    eval $sayfont
    eval $addfont

  fi

done

lines=`wc $TMP`
set $lines
echo $1 > $outfile

cat $TMP >> $outfile
