#!/usr/bin/perl
=head1 NAME
print_table.pl - print the marc8 conversion table as HTML
=head1 SYNOPSIS
% print_table > table.html
=head1 DESCRIPTION
This command line utility will read the db created when MARC::Charset
is installed and output the data as an HTML table. To tweak the look
and feel modify the embedded stylesheet in the code.
=head1 SEE ALSO
=over 4
=item *
MARC::Charset::Table
=back
=head1 AUTHOR
=over 4
=item *
Ed Summers
=back
=cut
use strict;
use warnings;
use MARC::Charset::Table;
use MARC::Charset::Code;
use Storable qw(thaw);
use CGI qw(escapeHTML table th td Tr);
binmode(STDOUT,'utf8');
my $table = MARC::Charset::Table->new();
my $db = $table->db();
print
<
MARC-8 Mapping Table
HTML
my $lastCharset = '';
my $count = 0;
for my $k (sort(keys(%$db)))
{
# ignore the utf8 keys
next if $k =~ /^\d+$/;
# pull the Code object out
my $code = thaw($db->{$k});
# each character set goes into it's own table
my $attr = {};
if (!$lastCharset or $code->charset() ne $lastCharset)
{
print "\n" if $lastCharset;
print_table_header($code->charset_name());
$lastCharset = $code->charset();
}
# determine the row shading
my $row_class = $count++ % 2 == 0 ? 'even' : 'odd';
# output the row
print
qq(),
'| ',int(hex($code->ucs())),'; | ',
'',$code->marc_value(),' | ',
'0x',$code->ucs(),' | ',
'',$code->name(),' | ',
"
\n";
}
print
<
HTML
sub print_table_header
{
my $charset_name = shift;
print
'',
qq(\n),
qq(| $charset_name |
\n),
'',
'| ',
' | MARC-8',
' | UCS',
' | Name',
" |
\n";
}