txt2INDEX

#!/usr/bin/perl

print "txt2INDEX::::::Finding .txt files...\n";

# get a list of the place name prefices to
# the .txt files and store in %prefices...
open (TXTS, "ls -l ../TXTs/*.txt |");
while (<TXTS>) {
/TXTs\/(\D{1,6})(\d+)/;
# store the prefices by their pseudoDate...
$prefices{$2}=$1;
}
close (TXTS);

# another echo...
{
local(%preficesCopy,$prefices);
%preficesCopy=%prefices;
$prefices=join(" ",%preficesCopy);
print "txt2INDEX::::::\%prefices = $prefices\n";
}

# foreach one of these prefices, run the txt2HTML
# PERL script to turn each group of .txt files
# into 1 HTML page...
foreach $dateKey (keys(%prefices)) {

open (TXT, "cat ../TXTs/$prefices{$dateKey}*.txt |");
chop ($placeNames{$dateKey}=<TXT>);
close (TXT);

print "txt2INDEX::::::Processing $prefices{$dateKey}.html...\n";

`./txt2HTML $prefices{$dateKey}`;
}

# -------- INDEX OUTPUT --------
# Finally, create the index page.

print "txt2INDEX::::::Processing itin_index.html...\n";

# Capture the code from the index template....
($b1,$b2,$b3,$b4,$b5)=&codeCapture;

# remove any \n chars...
chop($b2,$b3,$b4);

# open a pipe to the index file...
open (INDEX, "| cat >../HTMLs/itin_index.html");

# print the header HTML....
print INDEX $b1;

# massage the %prefices array such that each
# place has one index entry...
&massagePrefices;

# print each hyperlink
foreach $dateKey (@dateKeys) {

# local vars...
local($realDay,$realMnth,$realDate);

# decode the date...
$realDay=($dateKey<31)?$dateKey:($dateKey-31);
$realMnth=($dateKey<31)?"8":"9";
$realDate="[$realDay-$realMnth-2000]";

# print to the INDEX fileHandle...
print INDEX $b2.$prefices{$dateKey}.".html".$b3."$placeNames{$dateKey}<br><font
size=\"-2\">$realDate</font>".$b4."\n";
}

#print the closing block of HTML....
print INDEX $b5;

# -------- SUBROUTINES --------

# --- &codeCapture ---
# to split the ITIN_TEMP.html file into the code
# blocks, ($b1, $b2, $b3, $b4, $b5)
# usage: &codeCapture
# rtrns: 5 string list, as above

sub codeCapture {
local ($b1,$b2,$b3,$b4,$b5);
open (TEMPLATE, "cat ../templates/INDEX_TEMP.html |");
while (<TEMPLATE>) {push(@code,$_);}

for (;$d<$#code;) {
$now=$code[$d];
if ($now=~/<LINK/) {$lA=$d;}
if ($now=~/FILENAME/) {$lB=$d;}
if ($now=~/LINKNAME/) {$lC=$d;}
if ($now=~/<\/LINK/) {$lD=$d;}
$d++;
}

return (
&htmlFragGet('0',$lA), #b1
&htmlFragGet($lA+1,$lB), #b2
&htmlFragGet($lB+1,$lC), #b3
&htmlFragGet($lC+1,$lD), #b4
&htmlFragGet($lD+1,$#code), #b5
);
}

# --- &htmlFragGet ---
# to get sections of the @code array from
# a to b excluding line b
# usage: &htmlFragGet($a, $b);
sub htmlFragGet {
if ($_[0]==$_[1]) {return;}
return $code[$_[0]].&htmlFragGet($_[0]+1,$_[1]);
}

# --- &massagePrefices ---
# to massage %prefices
# usage: just call it
# rtrns: nothing, but fills the array @placeNames
sub massagePrefices {

# local vars...
local (@prefices);

# you work it out...
foreach $dateKey (sort keys(%prefices)) {
$thisPrefix=$prefices{$dateKey};
if ($thisPrefix ne $prefices[0]) {
unshift(@prefices,$thisPrefix);
unshift(@dateKeys,$dateKey);
}
}
}