#!/usr/bin/perl -w
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
#NAME
#  getglyph - Get Unicde glyphs
#
#SYNOPSIS
#  getglyph hexcode1 [hexcode2]
#
#REQUIRES
#
#DESCRIPTION
#  This program downloads a range of glyphs (GIF files) from the  unicode.org
#  server's  database,  and stores them in local files that have the hex code
#  (4 digits) in the file names.
#
#  If you just give one hex code, only that one glyph will be downloaded.
#
#OPTIONS
#
#EXAMPLES
#  getglyph 2E80 2F00
#
#FILES
#
#BUGS
#  If we ever need chars above FFFF, we'll have to extend this program a bit.
#
#SEE ALSO
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #

$| = 1;
$exitstat = 0;
($P = $0) =~ s".*/"";
$V = $ENV{"V_$P"} || $ENV{"D_$P"} || 2;	# Verbose level.
$base = 'http://www.unicode.org/cgi-bin/refglyph?24-';

die "Usage: $P hexcode1 [hexcode2]\n"
	unless (@ARGV);
$locode = $ARGV[0];
$hicode = $ARGV[1] || $locode;

$lo = hex $locode;
$hi = hex $hicode;

print "$P: lo=$lo hi=$hi\n" if $V>1;

$code  = $lo;
while ($code <= $hi) {
	print "$P: code=$code\n" if $V>2;
	$hexcode = sprintf("%04X",$code);
	print "$P: hexcode='$hexcode'\n" if $V>2;
	$cmd = "webcat $base$hexcode  > U$hexcode.gif";
	print "$P: cmd='$cmd'\n" if $V>2;
	$rsp = `$cmd`;
	print "$P: rsp='$rsp'\n" if $V>2 && $rsp;
	$exitstat = $?
		if ($? > $exitstat);
	system "ls -l U$hexcode.gif" if $V>1;
	++$code;
}

system "relink +rv";

print "$P: Exit with status $exitstat.\n" if $V>1;
exit $exitstat;

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