#!/usr/local/bin/perl -Tw
# "getsett.pl" v 1.1 by Thomas Insel (tinsel@tinsel.org) January 1999
# Copyright 1995--2004 Thomas Insel
# The text file with setts.
$SETTFILE = "/home/t/ti/tinsel/public_html/tinsel/Java/Tartan/setts.txt";
# Uses Steven E. Brenner's cgi-lib.pl (http://cgi-lib.stanford.edu/cgi-lib/)
require '/home/t/ti/tinsel/public_html/cgi-bin/cgi-lib.pl';
# These allow for a bug in the Java bit.
#
# --- The Main Stuff
#
$myloc = &MyBaseUrl;
if (&ReadParse(*input) and defined $input{'clan'}) {
&PrintSett($input{'clan'});
} else {
&ListSetts;
}
sub ListSetts {
open SETTS, $SETTFILE or CgiDie("Can't open sett file");
print &PrintHeader;
print <<"END_OF_HEADER";
Index of Tartans
Index of Tartans
END_OF_HEADER
while () {
next if /^%/;
if (/^([^ ]+)/) {
print "- $1\n";
}
}
close SETTS;
print "
\n";
print &PrintFooter;
}
sub ThreadCount {
my $symm = shift;
my $sett = shift;
my $sum = 0;
# pick out the odd fields, which are numbers
@x = split ' ', $sett;
for ($i=1; $i<= $#x; $i+=2) {
push @threads, $x[$i];
$sum += $x[$i];
}
if ($symm == 1) {
$sum = 2 * $sum - $threads[$#threads] - $threads[0];
} elsif ($symm == 2) {
$sum = 2 * $sum - $threads[$#threads] - $threads[$#threads-1];
}
return $sum;
}
sub PrintSett ($) {
my $clan = shift;
my $sett = -1;
open SETTS, $SETTFILE or CgiDie("Can't open sett file");
# This loop grabs the clan and symmetry (s) from a line like:
# MacPerl (a) B 12 R 12...
# or in the case of normal symmetry:
# MacPerl B 12 R 12...
while () {
next if /^%/;
if (/^($clan)\s+\((\w+)\)(.+)/) {
$symm = ($2 eq 'a') ? 0 : 2;
$sett = $3;
} elsif (/^($clan)\s+(.+)/) {
$symm = 1;
$sett = $2;
}
}
close SETTS;
&CgiDie("Can't find the named sett") if ($sett == -1);
@symmnames = (" (asymmetric)", "", " (double-pivot)");
$tc = ThreadCount($symm,$sett);
print &PrintHeader;
print <<"END_OF_PAGE";
$clan Tartan
$clan Tartan
$sett $symmnames[$symm]
END_OF_PAGE
}
# *---*