#!/bin/sh
echo Content-type: text/html
echo
echo '<HTML><HEAD><TITLE>FlamingText Font Browser</TITLE>'
cat top.txt
cat ../net-fu/ads/flycast.top
cat left.txt
UH="/www/bin/unescape_hack"
QS="&""$QUERY_STRING""&"
UCHAR=`echo $QS | grep "&char=" | sed -e 's/.*&char=\([^&]*\)&.*/\1/'`
CHAR=`echo $UCHAR | sed -e 's/+/ /g' | $UH`
UFONTNAME=`echo $QS | grep "&fontname=" | sed -e 's/.*&fontname=\([^&]*\)&.*/\1/'`
FONTNAME=`echo $UFONTNAME | sed -e 's/+/ /g' | $UH`
FONTSIZE=`echo $QS | grep "&fontsize=" | sed -e 's/.*&fontsize=\([^&]*\)&.*/\1/' | sed -e 's/+/ /g' | $UH`
STYLE=`echo $QS | grep "&style=" | sed -e 's/.*&style=\([^&]*\)&.*/\1/' | sed -e 's/+/ /g' | $UH`

if [ x"$FONTSIZE" = "x" ]; then
	FONTSIZE="70"
fi
if [ x"$STYLE" = "x" ]; then
	STYLE="plain-logo"
fi
if [ x"$FONTNAME" = "x" ]; then
	FONTNAME="agate"
	UFONTNAME="agate"
fi
if [ x"$CHAR" = "x" ]; then
	CHAR="A"
	UCHAR="%41"
fi
XCHAR=`echo $UCHAR | sed -e 's/%//'`
thischar="chars/$UFONTNAME/$STYLE/$FONTSIZE/char-$XCHAR.gif"
if [ -r $thischar ]; then
	if [ ! -s $thischar ]; then
		# already tried
		thischar="/fonts/notavailable.gif"
	fi
else
	mkdir -p `dirname $thischar` 2> /dev/null
	/usr/local/bin/lynx -source 'http://www.flamingtext.com/general/simple.cgi?script='"$STYLE"'&text='"$UCHAR"'&fontname='"$UFONTNAME"'&fontsize='"$FONTSIZE"'&imageoutput=true' > $thischar
	file $thischar  | grep GIF > /dev/null
	if [ $? -ne 0 ]; then
		/bin/rm -f $thischar
		touch $thischar
		thischar="/fonts/notavailable.gif"
	fi
fi
nextchar=`echo $thischar | sed -e 's/+/%2B/g'`
echo "<center>This FontBrowser is <b>STILL IN TEST</b>.<br>Feel free to use it,<br>and make suggestions. Thanks!<p>"
echo "Actually, sorry, but this is off-line for a while<!--"
echo "<table border=0 cellpadding=10 cellspacing=5><tr><td bgcolor=#CCCCCC><a href=\"/general/whatnow.cgi?image=http://www.flamingtext.com/fonts/$nextchar\"><img border=0 src=\"$nextchar\"></a></td></tr></table>"
echo "<table><tr><FORM ACTION=fontbrowser.cgi></tr><tr><td>Font: <select name=fontname>"
echo "<option>$FONTNAME"
cat gen/fontlist.inc
echo "</select>"
echo "<input type=hidden name=fontsize value=$FONTSIZE>"
echo "<input type=hidden name=char value=\"$CHAR\">"
echo "<input type=hidden name=style value=$STYLE>"
echo "<input type=submit value=GO></td></tr></FORM>"
echo "<FORM ACTION=fontbrowser.cgi><tr><td>Style: <select name=style>"
echo "<option selected>$STYLE"
echo '
<option value=plain-logo>Plain</option>
<option value=drop-shadow-logo>Drop Shadow</option>
<option value=beveled-pattern-heading>Beveled</option>
<option value=flaming-logo>Flaming Text</option>
<option value=whirl-anim-logo>Whirl (Anim)</option>
<option value=alien-glow-anim-logo>Alien Glow (Anim)</option>
'
echo "</select>"
echo "<input type=hidden name=fontsize value=$FONTSIZE>"
echo "<input type=hidden name=fontname value=\"$FONTNAME\">"
echo "<input type=hidden name=char value=\"$CHAR\">"
echo "<input type=submit value=GO></td></tr></FORM><tr></tr></table>"
echo "<br>CHAR: $CHAR"
echo "<br>Hex: "`echo $UCHAR | sed -e 's/%/#/'`
HEX="0 1 2 3 4 5 6 7 8 9  A B C D E F";
echo '<table>'
n=0;
for a in $HEX; do
  echo '<tr>'
  for b in $HEX; do
    if [ $a = "0" -a $b = "0" ]; then
	echo "<td></td>"
    else
    	echo '<td bgcolor=#cccccc><a href="fontbrowser.cgi?char=%'$a$b'&fontname='"$UFONTNAME"'&fontsize='"$FONTSIZE"'&style='"$STYLE"'">&#'$n';</a></td>'
    fi
    n=`expr $n + 1`
  done
  echo '</tr>'
done
echo '</table>'
echo '-->'

cat trailer.txt

