#!/usr/athena/bin/perl
#
# Script for generating ESG machine labels.
#   "machines.esg" -- machine information
#   "esglabels.ps" -- PostScript template
#
# This might be gross, but it sure works.

open(MACH, "machines.esg") || die "No machine info???";

while (<MACH>) {
    chop;
    /^(.+)\|(.)(.)\|(.*)\|(.+)\|(.+)\|(.+)\|(.*)$/ || die "Invalid file format";
    ($name, $mtype, $size, $ether, $inet, $cname1, $cname2, $mit) =
	($1,$2,$3,$4,$5,$6,$7,$8);

    if ($mtype eq "M") {$type = "Apple Macintosh\\251 IIci";}
    elsif ($mtype eq "m") {$type = "Apple Macintosh\\251 IIsi";}
    elsif ($mtype eq "D") {$type = "DECstation 5000/25 \\(`Maxine'\\)";}
    elsif ($mtype eq "R") {$type = "IBM RT/PC Model 115";}
    elsif ($mtype eq "S") {$type = "IBM RS/6000 POWERstation 220";}
    else {die "Machine type not one of [DRMmS], exiting";}

    if ($size eq "S") {$small=1;} else {$small=0;}
    if ($size eq "N") {$narrow=1;} else {$narrow=0;}

    print "Opening $name.ps";
    open(PS, "> $name.ps") || die "Can't open file";

    print " and template file.\n";
    open(TMP, "esglabel.ps") || die "Can't open template";

    while (<TMP>) {
	if (/\/showStuffN/) {
	    if ($narrow) {print PS "/showStuffN {showStuffK} def\n";}
	    else {print PS "/showStuffN {showStuff} def\n";}
	}
	elsif (/\/Name/) {
	    print PS "/Name     ($name) def\n";
	}
	elsif (/\/HostType/) {
	    print PS "/HostType ($type) def\n";
	}
	elsif (/\/Ether/) {
	    print PS "/Ether    (Ethernet:  $ether) def\n";
	}
	elsif (/\/Mit/) {
	    print PS "/Mit      (MIT Inventory:  $mit) def\n";
	}
	elsif (/\/Internet/) {
	    print PS "/Internet ($inet) def\n";
	}
	elsif (/\/Cnames1/) {
	    print PS "/Cnames1  ($cname1) def\n";
	}
	elsif (/\/Cnames2/) {
	    print PS "/Cnames2  ($cname2) def\n";
	}
	elsif (/.93 dup scale/ && !$small) {
	    print PS "% ".$_;
	}
	else {print PS;}
    }
    print "  ...done.\n";
}
