#!/usr/bin/perl
# This script is in the public domain.
# Usage: "stroke.pl <kanjidic"
while ($line = <STDIN>) {
    if (substr ($line, 0, 1) eq "#") {
	next;
    }
    chomp ($line);
    $jouyou = 0;
    $sh = "";
    @toks = split (/\s+/, $line);
    foreach $tok (@toks) {
	if (substr ($tok, 0, 2) eq "IN") {
	    $jouyou = 1;
	} elsif (substr ($tok, 0, 1) eq "I") {
	    $sh = substr ($tok, 1);
	}
    }
    if ($jouyou) {
	$sh =~ /^(1?[0-9])([a-z])([0-9][0-9]?)/;
	$number = $1;
	$letter = $2;
	$residual = $3;
	$radical = "$1$2";
	$byradical{$radical} = [$toks[0] . " " . $sh, $byradical{$radical}];
	$bysh{$sh} = $toks[0];
	print STDERR "#";
    }
}
print STDERR "\n";

for ($stroke = 0; $stroke < 30; ++$stroke) {
    print $stroke . ": \n";
    foreach $number ("0", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11") {
	foreach $letter ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
			 "k", "m", "n", "o", "p", "q", "r", "s", "t") {
	    $radical = $number . $letter;
	    if ($byradical{$radical}->[0]) {
		$residual = $stroke - $number;
		for ($seqn = 0; $seqn < 50; ++$seqn) {
		    $sh = $radical . $residual . "." . $seqn;
		    if ($bysh{$sh}) {
			print "   " . $bysh{$sh} . " " . $sh . " (?)\n";
		    }
		}
	    }
	}
    }
}
