#!/usr/local/bin/perl

dbmopen (%charname, "/usr/doc/unicode/unidata/charname.db", 0666);

open (STDOUT, "|sort");

while (<>)
{
    if (/^(=|0x|)([0-9A-F]{2})\s+(0x|<?U\+?|)([0-9A-F]{4})>?\s/i)
    {
	($position, $character) = ($2, $4);
    }
    elsif (m=/x([0-9A-F]{2})\s+<U([0-9A-F]{4})>\s=i)
    {
	($position, $character) = ($1, $2);
    }
    elsif (/^(...)\s+(...)\s+([0-9A-F]{2})\s+\S+\s+([0-9A-F]{4})\s/i)
    {
	($position, $character) = ("$3", $4);
    }
    else
    {
	warn $_; next;
    }

    next if ($character =~ /^00([0189]|7F)|^FFF/i) && ($ARGV !~ /ascii/i);
    warn $_, next if $seen{$position}++;

    $charname = $charname{pack("n",hex($character))};
    print "\U=$position\tU+$character\t$charname\n";
}

close STDOUT;
