| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
print_table.pl - print the marc8 conversion table as HTML |
| 6 |
|
| 7 |
=head1 SYNOPSIS |
| 8 |
|
| 9 |
% print_table > table.html |
| 10 |
|
| 11 |
=head1 DESCRIPTION |
| 12 |
|
| 13 |
This command line utility will read the db created when MARC::Charset |
| 14 |
is installed and output the data as an HTML table. To tweak the look |
| 15 |
and feel modify the embedded stylesheet in the code. |
| 16 |
|
| 17 |
=head1 SEE ALSO |
| 18 |
|
| 19 |
=over 4 |
| 20 |
|
| 21 |
=item * |
| 22 |
|
| 23 |
MARC::Charset::Table |
| 24 |
|
| 25 |
=back |
| 26 |
|
| 27 |
=head1 AUTHOR |
| 28 |
|
| 29 |
=over 4 |
| 30 |
|
| 31 |
=item * |
| 32 |
|
| 33 |
Ed Summers |
| 34 |
|
| 35 |
=back |
| 36 |
|
| 37 |
=cut |
| 38 |
|
| 39 |
use strict; |
| 40 |
use warnings; |
| 41 |
use MARC::Charset::Table; |
| 42 |
use MARC::Charset::Code; |
| 43 |
use Storable qw(thaw); |
| 44 |
use CGI qw(escapeHTML table th td Tr); |
| 45 |
|
| 46 |
binmode(STDOUT,'utf8'); |
| 47 |
my $table = MARC::Charset::Table->new(); |
| 48 |
my $db = $table->db(); |
| 49 |
|
| 50 |
print |
| 51 |
<<HTML; |
| 52 |
<html> |
| 53 |
<head> |
| 54 |
<style> |
| 55 |
|
| 56 |
body |
| 57 |
{ |
| 58 |
font-size: 18pt; |
| 59 |
margin: 10px; |
| 60 |
} |
| 61 |
|
| 62 |
table |
| 63 |
{ |
| 64 |
margin: 0; |
| 65 |
padding: 0; |
| 66 |
width: 100%; |
| 67 |
border: thin solid black; |
| 68 |
} |
| 69 |
|
| 70 |
tr |
| 71 |
{ |
| 72 |
border: none; |
| 73 |
padding: 0; |
| 74 |
} |
| 75 |
|
| 76 |
th |
| 77 |
{ |
| 78 |
font-weight: bold; |
| 79 |
background-color: #E89E71; |
| 80 |
border: none; |
| 81 |
text-align: left; |
| 82 |
} |
| 83 |
|
| 84 |
td |
| 85 |
{ |
| 86 |
border: none; |
| 87 |
padding: 0; |
| 88 |
} |
| 89 |
|
| 90 |
.menu |
| 91 |
{ |
| 92 |
padding: 10px; |
| 93 |
background: #F6F4E8; |
| 94 |
text-align: center; |
| 95 |
} |
| 96 |
|
| 97 |
.character |
| 98 |
{ |
| 99 |
text-align: center; |
| 100 |
font-size: 20pt; |
| 101 |
font-weight: bold; |
| 102 |
} |
| 103 |
|
| 104 |
.charset_name |
| 105 |
{ |
| 106 |
font-size: 16pt; |
| 107 |
text-align: center; |
| 108 |
} |
| 109 |
|
| 110 |
.even |
| 111 |
{ |
| 112 |
background-color: #FFFEF2; |
| 113 |
} |
| 114 |
|
| 115 |
.odd |
| 116 |
{ |
| 117 |
background-color: #F6F4E8; |
| 118 |
} |
| 119 |
|
| 120 |
</style> |
| 121 |
</head> |
| 122 |
<body> |
| 123 |
|
| 124 |
<h1 style="align: center">MARC-8 Mapping Table</h1> |
| 125 |
|
| 126 |
<div class="menu"> |
| 127 |
<a href="#GREEK_SYMBOLS">Greek Symbols</a> | |
| 128 |
<a href="#SUBSCRIPTS">Subscripts</a> | |
| 129 |
<a href="#SUPERSCRIPTS">Superscripts</a> | |
| 130 |
<a href="#BASIC_ARABIC">Basic Arabic</a> | |
| 131 |
<a href="#EXTENDED_ARABIC">Extended Arabic</a> | |
| 132 |
<a href="#BASIC_LATIN">Basic Latin</a> | |
| 133 |
<a href="#EXTENDED_LATIN">Extended Latin</a> | |
| 134 |
<a href="#BASIC_CYRILLIC">Basic Cyrillic</a> | |
| 135 |
<a href="#EXTENDED_CYRILLIC">Extended Cyrillic</a> | |
| 136 |
<a href="#BASIC_GREEK">Greek</a> | |
| 137 |
<a href="#BASIC_HEBREW">Hebrew</a> |
| 138 |
<a href="#CJK">Chinese/Japanese/Korean</a> |
| 139 |
</div> |
| 140 |
|
| 141 |
HTML |
| 142 |
|
| 143 |
my $lastCharset = ''; |
| 144 |
my $count = 0; |
| 145 |
for my $k (sort(keys(%$db))) |
| 146 |
{ |
| 147 |
# ignore the utf8 keys |
| 148 |
next if $k =~ /^\d+$/; |
| 149 |
|
| 150 |
# pull the Code object out |
| 151 |
my $code = thaw($db->{$k}); |
| 152 |
|
| 153 |
# each character set goes into it's own table |
| 154 |
my $attr = {}; |
| 155 |
if (!$lastCharset or $code->charset() ne $lastCharset) |
| 156 |
{ |
| 157 |
print "</table>\n" if $lastCharset; |
| 158 |
print_table_header($code->charset_name()); |
| 159 |
$lastCharset = $code->charset(); |
| 160 |
} |
| 161 |
|
| 162 |
# determine the row shading |
| 163 |
my $row_class = $count++ % 2 == 0 ? 'even' : 'odd'; |
| 164 |
|
| 165 |
# output the row |
| 166 |
print |
| 167 |
qq(<tr class="$row_class">), |
| 168 |
'<td class="character">&#',int(hex($code->ucs())),';</td>', |
| 169 |
'<td>',$code->marc_value(),'</td>', |
| 170 |
'<td>0x',$code->ucs(),'</td>', |
| 171 |
'<td>',$code->name(),'</td>', |
| 172 |
"</tr>\n"; |
| 173 |
} |
| 174 |
|
| 175 |
print |
| 176 |
<<HTML; |
| 177 |
</table> |
| 178 |
</body> |
| 179 |
</html> |
| 180 |
HTML |
| 181 |
|
| 182 |
|
| 183 |
sub print_table_header |
| 184 |
{ |
| 185 |
my $charset_name = shift; |
| 186 |
print |
| 187 |
'<p />', |
| 188 |
qq(<table id="$charset_name" cellspacing="0" cellpadding="5">\n), |
| 189 |
qq(<tr><th class="charset_name" colspan="5">$charset_name</th></tr>\n), |
| 190 |
'<tr>', |
| 191 |
'<th width="10%"> </td>', |
| 192 |
'<th width="15%">MARC-8</td>', |
| 193 |
'<th width="15%">UCS</td>', |
| 194 |
'<th width="70%">Name</td>', |
| 195 |
"</tr>\n"; |
| 196 |
} |