#!/usr/local/bin/perl
#
# HLaTeX-0.95 message filter
#   
#   Choi Jun Ho, junker@vishnu.snu.ac.kr
#   1996/11/25

# This program converts HLaTeX hangul error messages
# to visible chars

# local variables
$state=0;
$c=0; 
$hnib=0;
$lnib=0;
$buf="";

while(!eof(STDIN))
{ 
    $c=getc();
    #print "[[".$c."]]; state $state\n";

    if ($c eq '^' && ($state==0 || $state==1)) {
	$state++;
	$buf=$buf.$c;
    } elsif ((($c ge '0' && $c le '9') || ($c ge 'a' && $c le 'f')) # if hex,
	&& $state==2){
	$state++;
	$hnib=hex($c);
	$buf=$buf.$c;
    } elsif ((($c ge '0' && $c le '9') || ($c ge 'a' && $c le 'f')) # if hex,
	&& $state==3){
	$lnib=hex($c);
	print chr($hnib*16+$lnib);
	$state=0;
	$buf="";
    } else {
	$state=0;
	print $buf.$c;
	$buf="";
    }
}
