#!/bin/sh -
# figlist by Glenn Chappell <ggc@uiuc.edu>
# 12 Aug 1994
#
# Lists all fonts and control files in figlet's default font directory.
# Replaces "figlet -F", which has been removed from figlet version 2.1.
#
# Usage: figlist [ -d directory ] [ -f defaultfont ]

# Set up PATH so figlet can be found
PATH=$PATH:`dirname $0`

# Get figlet version
FIGLETVERSION=`figlet -I1 2>/dev/null`
if [ -z "$FIGLETVERSION" ]; then
  FIGLETVERSION=20000
fi

if [ $FIGLETVERSION -lt 20100 ]; then
  # figlet 2.0
  figlet $* -F
  exit
fi

# From here on we may assume figlet 2.1 or later

FONTOPT=""
FONTDIROPT=""
while getopts d:f: c ; do
  case $c in
    d)     FONTDIROPT="-d $OPTARG";;
    f)     FONTOPT="-f $OPTARG";;
    \?)    ;;
  esac
done
shift `expr $OPTIND - 1`
if [ $# -gt 0 ]; then
  echo `basename $0`:' illegal parameter -- '$1
fi

FONTDIR=`figlet $FONTDIROPT -I2`
FONT=`figlet $FONTOPT -I3`
echo "Default font: $FONT"
echo "Font directory: $FONTDIR"

if [ -d $FONTDIR ] && [ -r $FONTDIR ] && [ -x $FONTDIR ]; then
  cd $FONTDIR
  if ls *.flf >/dev/null 2>&1 ; then
    echo "Figlet fonts in this directory:"
    ls *.flf 2>/dev/null | sed s/\.flf$//
  else
    echo 'No figlet fonts in this directory'
  fi
  if ls *.flc >/dev/null 2>&1 ; then
    echo "Figlet control files in this directory:"
    ls *.flc 2>/dev/null | sed s/\.flc$//
  else
    echo 'No figlet control files in this directory'
  fi
else
  echo 'Unable to open directory'
fi
