#!/bin/bash
# (c) 1997 Ricardas Cepas <rch@pub.osf.lt>. Copying policy: BSD or GNU GPL V2.
#set -x
default="/usr/lib/kbd/consolefonts/*"
if [ "$1" = "--help" ] || [ "$1" = "-h" ]
then	echo "Usage: $0 [font_file_name] [...] "
	echo "  default is $default "
	exit
fi
if testUTF-8
then UTFmode='G'
else UTFmode='@'
fi
files="${*:-$default}"
if type file >/dev/null
then FILE_UTIL="file -L"
else FILE_UTIL=:
fi
Random=$RANDOM.$$
setfont -v -o /tmp/tempfont.$Random -om /tmp/tempmap.$Random \
						-ou /tmp/tempuni.$Random
Saved=$?
function on_exit ()
{
if (( $Saved == 0 ))
then
  setfont -v /tmp/tempfont.$Random -m /tmp/tempmap.$Random -u /tmp/tempuni.$Random
else
  setfont -v
fi
echo -ne '\033%'$UTFmode
rm --force /tmp/tempfont.$Random /tmp/tempmap.$Random /tmp/tempuni.$Random
}
trap on_exit EXIT
for f in $files
do	if	test -f $f \
		&& if [ _${f%.cp} = _$f ]
		   then setfont -v $f
		   else setfont -v -16 $f
		   fi \
		&& { glyphs; let $(( $? <= 1 )) ; }
	then	$FILE_UTIL $f
		echo "---$f---" '     (Press <Enter> to continue, q to quit )'
		read
		if [ _$REPLY = _q ]; then break; fi
	else	$FILE_UTIL $f
	fi
done

