#! /usr/local/bin/perl

&init();

$ARGV[0] = "worldcat.dat";

while (<>) {
	chop;
	($lang, $doctype, $count) = split(/\s+/);
	next unless $count;
	$count{"$lang$doctype"} = $count;
	# print "$lang	$doctype	$count\n";
	$count{$lang} += $count;
	$count{$doctype} += $count;
	$doctypes{$doctype} = $doctype;
	$langs{$lang} = $lang;
}

for $doctype (keys (%doctypes)) {
	$count{"other$doctype"} = $total{$doctype} - $count{$doctype}
}
$langs{"other"} = "other";

print "Language	Doctype	Records\n";
print "STRING	STRING	INTEGER\n";

for $lang (sort keys (%langs)) {
	for $doctype (sort keys (%doctypes)) {
		showit ($lang, $doctype);
	}
}

sub showit
{
	local ($lang, $doctype) = (@_);
	$key = "$lang$doctype";
	printf "$name{$lang}	$name{$doctype}	%d\n", $count{$key};
}

sub init {

$total{'art'} = 948503;
$total{'bks'} = 55151427;
$total{'com'} = 217212;
$total{'int'} = 2;
$total{'map'} = 1004998;
$total{'mix'} = 279318;
$total{'rec'} = 1993745;
$total{'sco'} = 1549717;
$total{'ser'} = 2724900;
$total{'url'} = 1169521;
$total{'vis'} = 2088590;

$name{'art'} = "Articles";
$name{'bks'} = "Books";
$name{'com'} = "Computer Files";
$name{'int'} = "Updated Resources";
$name{'map'} = "Maps";
$name{'mix'} = "Archival Materials";
$name{'rec'} = "Sound Recordings";
$name{'sco'} = "Scores";
$name{'ser'} = "Serials";
$name{'url'} = "Internet Resources";
$name{'vis'} = "Visual Materials";

$total{'ara'} = 305521;
$total{'bul'} = 65191;
$total{'chi'} = 1360328;
$total{'scr'} = 68972;
$total{'cze'} = 344808;
$total{'dan'} = 256432;
$total{'dut'} = 1975035;
$total{'eng'} = 37704794;
$total{'fre'} = 3916003;
$total{'ger'} = 4222400;
$total{'gre'} = 104191;
$total{'heb'} = 268080;
$total{'hin'} = 85844;
$total{'hun'} = 123012;
$total{'ind'} = 210418;
$total{'ita'} = 946405;
$total{'jpn'} = 1425648;
$total{'kor'} = 222625;
$total{'lat'} = 599963;
$total{'nor'} = 100029;
$total{'per'} = 88875;
$total{'pol'} = 500986;
$total{'por'} = 630210;
$total{'rum'} = 65635;
$total{'rus'} = 1097732;
$total{'spa'} = 2692754;
$total{'swe'} = 273194;
$total{'tha'} = 88635;
$total{'tur'} = 135302;
$total{'ukr'} = 85105;

$name{'ara'} = "Arabic";
$name{'bul'} = "Bulgarian";
$name{'chi'} = "Chinese";
$name{'scr'} = "Croatian";
$name{'cze'} = "Czech";
$name{'dan'} = "Danish";
$name{'dut'} = "Dutch";
$name{'eng'} = "English";
$name{'fre'} = "French";
$name{'ger'} = "German";
$name{'gre'} = "Greek";
$name{'heb'} = "Hebrew";
$name{'hin'} = "Hindi";
$name{'hun'} = "Hungarian";
$name{'ind'} = "Indonesian";
$name{'ita'} = "Italian";
$name{'jpn'} = "Japanese";
$name{'kor'} = "Korean";
$name{'lat'} = "Latin";
$name{'nor'} = "Norwegian";
$name{'per'} = "Persian";
$name{'pol'} = "Polish";
$name{'por'} = "Portugues";
$name{'rum'} = "Romanian";
$name{'rus'} = "Russian";
$name{'spa'} = "Spanish";
$name{'swe'} = "Swedish";
$name{'tha'} = "Thai";
$name{'tur'} = "Turkish";
$name{'ukr'} = "Ukranian";
$name{'other'} = "Other";

}
