#!/usr/bin/perl
# generates the glossary html file
$DataFile = '../data/cgIndex.dat';
$SpecFile = '../data/qqq.dat';
$lsp = 'ZZ';
$fsp = 'QQ';
# get list of keys with CTitle ending with a 'Q'
#%Special = ( 'contempl', '1',
# 'ksatriya', '1',
# 'recognit', '1',
# 'sanjna', '1');
%Special = ();
if (open(SPEC, $SpecFile)) {
while ($SpecItem = ) {
chomp $SpecItem;
$Special{$SpecItem} = '1';
}
close SPEC;
} # else assume no special items
print <<_ENDPRINT;
Content-type: text/html
Buddhist Door Glossary
Buddhist Door Glossary File Generation
_ENDPRINT
# read records and store for sorting
%Rec = ();
@Indexes = ();
if (open (GLOS, $DataFile)) {
while ($Line = ) {
chomp $Line;
($ETitle, $Key, $CTitle, $Def) = split /$fsp/, $Line, 4;
$ETitle =~ s/^the\s+|a\s+|an\s+//i;
$Rec{$Key} = $Line;
push @Indexes, $ETitle.' QQ '.$Key;
} # while
close GLOS;
}
else {
print <<_ENDPRINT;
Sorry, the glossary is not available at this time.
Please try later.
_ENDPRINT
&printFooter();
exit;
} # if open
@sortedIndexes = sort @Indexes;
#&sortNoArticle(\@Indexes, \@sortedIndexes);
#@Range1 = ('A', 'F', 'L', 'S', 'T');
@Range2 = ('E', 'K', 'R', 'S', 'Z');
$Init = 'A'; # current Initial
$Range = 0; # current range
$rc = &openFile($Range);
&printFileHeader($Range);
print FILE " \n";
foreach $Index (@sortedIndexes) {
($ETitle, $Key) = split / QQ /, $Index;
#DEBUG
print "
$Index\n";
#GUBED
$Initx = uc(substr($ETitle, 0, 1));
if ($Initx gt $Range2[$Range]) {
&printFileFooter($Range);
close FILE;
$Range++;
# future enhancement - check/handle error with $rc
$rc = &openFile($Range); # 1 for success, 0 for failure
&printFileHeader($Range);
print FILE " \n";
}
if ($Initx gt $Init) {
print FILE " \n";
$Init = $Initx;
}
$Rec{$Key} =~ s/$lsp/\n/g;
($ETitle, $Key, $CTitle, $Def) = split /$fsp/, $Rec{$Key}, 4;
# special case for rec with the last Chinese char ending with a 'Q'
if (defined($Special{$Index})) {
$CTitle .= 'Q';
$Def = substr($Def, 1);
}
# end special case
print FILE <<_ENDPRINT;
$ETitle $CTitle
$Def
_ENDPRINT
}
&printFileFooter($Range);
close FILE;
&printFooter;
exit;
#---------------------------------------------------------------------
sub printFooter {
print <<_ENDPRINT;
Back to Main Page
_ENDPRINT
} # printFooter
#---------------------------------------------------------------------
sub printFileFooter {
my $IN_range = $_[0];
my $i;
my @link_current = (
'',
'',
'',
'',
'');
my @link_notcurrent = (
'',
'',
'',
'',
'');
print FILE <<_ENDPRINT;
_ENDPRINT
for ($i=0; $i<5; $i++) {
if ($i == $IN_range) {
print FILE $link_current[$i], "\n";
}
else {
print FILE $link_notcurrent[$i], "\n";
}
}
print FILE <<_ENDPRINT;