characters.pl

#!/usr/bin/perl

# shall we use decimal or hexadecimal?
$hex = 1;
if ($hex==1) {
	$fmtstr{'set'} = '%04X';
	$fmtstr{'lowbit'} = '%01X';
	$fmtstr{'highbit'} = '%02X';
	$fmtstr{'char'} = '&#x%04X;';
} else {
	$fmtstr{'set'} = '%u';
	$fmtstr{'lowbit'} = '%u';
	$fmtstr{'highbit'} = '%u';
	$fmtstr{'char'} = '&#%u;';
}

#file top
print <<HEAD;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<title>Characters from U+0000 to U+FFFF</title>
<style type="text/css">
  table {
    border: 2px solid black;
    border-collapse: collapse;
  }
  td,th {
    border: 1px solid silver;
  }
</style>
HEAD

# 256 sets of characters
for ($set=0;$set<65535;$set+=256) {

	# heading for this set of characters
	$setpretty = sprintf($fmtstr{'set'},$set);
	print "<h2>Set $setpretty</h2>\n";
	
	# table header
	print "<table>\n";
	print " <tr><th>&nbsp;</th>";
	for ($lowbit=0;$lowbit<16;$lowbit++) {
		print '<th>+' . sprintf($fmtstr{'lowbit'},$lowbit) . '</th>';
	}
	print "</tr>\n";
	
	# print each row
	for ($highbit=0;$highbit<256;$highbit+=16) {
		print ' <tr>';
		print '<th>' . sprintf($fmtstr{'highbit'},$highbit) . '</th>';
		for ($lowbit=0;$lowbit<16;$lowbit++) {
			print '<td>' . sprintf($fmtstr{'char'},$set+$highbit+$lowbit) . '</td>';
		}		
		print "</tr>\n";
	}
	
	# end of this set of characters
	print "</table>\n";

}