<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl

use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser/;
$query = new CGI;

print header(),
    start_html( -title=&gt;"CMU Computer Club Documentation -- Machines");
    
open(MACHINES, "/afs/club/admin/misc/data");

if (defined $query-&gt;param('sort')) {
   if ($query-&gt;param('u') eq 'd') {
	$sortdir = -1;
   } else {
	$sortdir = 1;
   }
} else {
   $sortdir = 0;
}

@headings = ( '&lt;a href="index.pl?sort=0"&gt;host&lt;/a&gt;', '&lt;a href="index.pl?sort=1"&gt;IP Address&lt;/a&gt;', '&lt;a href="index.pl?sort=2"&gt;Contact Person&lt;/a&gt;', '&lt;a href="index.pl?sort=3"&gt;Net Port&lt;/a&gt;', '&lt;a href="index.pl?sort=4"&gt;Circuit&lt;/a&gt;', 
   '&lt;a href="index.pl?sort=5"&gt;Load&lt;/a&gt;', '&lt;a href="index.pl?sort=6"&gt;Services&lt;/a&gt;', "More info" );
$headings[$query-&gt;param('sort') + 0] =~ s/"&gt;/\&amp;u=d"&gt;/ if ($sortdir &gt; 0);
@rows = th[@headings];
@ents = ();

while(&lt;MACHINES&gt;) {

    if(/^\s*$/ || /^\#.*$/) { next; }
    ($host,$addr,$contact,$port,$circuit,$load,$srv) = split(/\t+/);
    $shorthost = (split(/\./, $host))[0];

    if(-r "/afs/club/public/doc/machines/$shorthost.html") {
	$moreinfo = a({href=&gt;"$shorthost.html"},"More Info");
    }
    else {
	$moreinfo = "";
    }
    if (-r "/afs/club/public/doc/machines/$shorthost.gone") {
	foreach $foo ($host,$addr,$contact,$port,$circuit,$load,$srv,$moreinfo) {

		$foo = "&lt;strike&gt;".$foo."&lt;/strike&gt;"
		if ($foo ne '');
	}
    }

    push(@ents, [$host,$addr,$contact,$port,
		    $circuit,$load,$srv,$moreinfo]);
}

sub cmpstrike {
    my ($a, $b) = @_;
    my ($aa, $bb) = ($a-&gt;[0], $b-&gt;[0]);
    if ($aa =~ m/^&lt;strike/) {
    	if ($bb =~ m/^&lt;strike/) {
	    return 0;
	}
    return 1;
    }
    if ($bb =~ m/^&lt;strike/) {
    	return -1;
    }
    return 0;
}


if (defined $query-&gt;param("sort")) {
    $sortcol = ($query-&gt;param("sort")) + 0;
    @ents = sort { &amp;cmpstrike($a, $b) ||
   	 ($a-&gt;[$sortcol] cmp $b-&gt;[$sortcol])*$sortdir } @ents;
} else {
    @ents = sort { &amp;cmpstrike($a, $b) } @ents;
}

push(@rows, map { td $_ } @ents);

print table(Tr(\@rows));

print end_html();
</pre></body></html>