#!/afs/athena/contrib/perl/perl

$filename = $ARGV[0];

open(RAWDATA, $filename) || die "Can't open $filename";
open(OUTFILE, ">&STDOUT") || die "Can't open STDOUT";

print OUTFILE while(<DATA>);

# Sample:
# 6.001	Lec	MWF	10	1	10-250

$i=0;
while (<RAWDATA>) {
  chop;
  next if /^#/;
  ($class, $lec, $days, $start, $length, $place) = split(/\t/, $_);
  ($a, $b) = split(/:/, $start);
  $time = $a + $b/60;
  ($a, $b) = split(/:/, $length);
  $len = $a + $b/60;
  $days =~ /M/ && print OUTFILE
    "classes ".$i++." [($class) ($lec) (M) $time $len ($place)] put\n";
  $days =~ /T/ && print OUTFILE
    "classes ".$i++." [($class) ($lec) (T) $time $len ($place)] put\n";
  $days =~ /W/ && print OUTFILE
    "classes ".$i++." [($class) ($lec) (W) $time $len ($place)] put\n";
  $days =~ /R/ && print OUTFILE
    "classes ".$i++." [($class) ($lec) (R) $time $len ($place)] put\n";
  $days =~ /F/ && print OUTFILE
    "classes ".$i++." [($class) ($lec) (F) $time $len ($place)] put\n";
}

print OUTFILE "\n/user ($ENV{'USER'}) def\n";
print OUTFILE "/numclass $i def\n";
print OUTFILE "\nmaster\n";
close OUTFILE || die "Could not close $filename";
__END__
%!
%Copyright 1992 Dave Cho  All Rights Reserved
%Permission is given to freely distribute and modify this product so long
%as it is done without charge and so long as this Copyright text remains in
%place.
%Certain designs inherent may be copyrighted elsewhere.
%Dave Cho 1992
%7.7 8.5 div   10.1 11 div scale  % for gs
/inch {72 mul} def
/cm {72 mul 2.54 div} def
/yline {10 inch} def
% the following are the parameters you might want to change:
/sp {14 neg} def % number of points between returns
/cp {4.25 inch} def % where rcenter centers around
/lm {1 inch} def % left margin
/tablen {2 inch} def % distance between tab stops
/tabpos {0} def % initial tab position
/shiftover {} def
%/shiftover {4.15 inch 0 translate /yline {9.6 inch} def 0 yline moveto
%enter} def

% don't mess with these:
/stringheight {/stringfoobar exch def gsave
newpath 0 0 moveto  stringfoobar false charpath  flattenpath pathbbox
exch pop 3 -1 roll pop  exch sub  grestore} def
/sqr {dup mul} def
/center   % stack: x y str
{/stringcenter exch def /ycenter exch def /xcenter exch def
	stringcenter stringwidth pop -2 div xcenter add
	fsize -2 div ycenter add moveto
	stringcenter show} def
/enter {lm currentpoint exch pop moveto 0 sp rmoveto
	/yline {currentpoint exch pop} def
	/tabpos lm def
	yline sp neg le {shiftover} if} def
/return {show enter} def
/rcenter {currentpoint exch pop cp exch 3 -1 roll  center enter} def
/tab {tabpos tablen add /tabnew exch def tabnew currentpoint
   exch pop moveto /tabpos tabnew def} def
/tabpos {lm} def
/stab {show tab} def
/blam { show currentpoint pop /xorig exch def /xfin {tablen lm add} def
(.) stringwidth pop /dotlen exch def xfin xorig sub dotlen div /foo exch def
/t {1} def 1 t foo {pop (.) show} for} def
/rm {7.5 inch} def
/right {currentpoint exch pop rm exch moveto dup stringwidth pop neg
0 rmoveto} def
/mark1 {currentpoint /ymark1 exch def /xmark1 exch def} def
/mark2 {currentpoint /ymark2 exch def /xmark2 exch def} def
/gofont {/fname exch def /fsize exch def fname findfont fsize scalefont
	setfont /sp (X) stringheight -1.1 mul def } def
/tb {/Palatino-Bold gofont} def
/tr {/Palatino-Roman gofont} def
/ti {/Palatino-Italic gofont} def
/tbi {/Palatino-BoldItalic gofont} def
/really {/wanted fsize def
/do-really {
(A) stringheight  wanted lt 
  {fsize 1 add fname gofont do-really} if
} def
do-really
} def
%%Trailer

/classes 100 array def

% [($class) ($lec) (M) $time $len ($place)]

/daysetup {
/class classes index get 0 get def
/lec classes index get 1 get def
/time classes index get 3 get def
/len classes index get 4 get def
/place classes index get 5 get def
} def

/doday {
1 setgray
0 time block mul neg moveto x 5 div 0 rlineto 0 len block mul neg rlineto
	x -5 div 0 rlineto closepath fill
0 setgray
0 time block mul neg moveto enter
fsize tb class rcenter fsize ti lec rcenter fsize tr place rcenter
0 time block mul neg moveto x 5 div 0 rlineto 0 len block mul neg rlineto
	x -5 div 0 rlineto closepath stroke
} def

/mon {gsave daysetup 0 0 translate doday grestore} def
/tue {gsave daysetup x 0.2 mul 0 translate doday grestore} def
/wed {gsave daysetup x 0.4 mul 0 translate doday grestore} def
/thu {gsave daysetup x 0.6 mul 0 translate doday grestore} def
/fri {gsave daysetup x 0.8 mul 0 translate doday grestore} def

/master {
.6 .6 scale
10 tr

/earliest 23 def
/latest 1 def
0 1  numclass 1 sub {/index exch def
	classes index get 3 get /time exch def
	time earliest lt {/earliest time def} if
	time latest gt {classes index get 4 get time add
		/latest exch def} if
} for

/block (X) stringheight 6 mul def
/x 250 def /y latest ceiling earliest floor sub block mul def
/cp x 10 div def

1 inch  9 inch earliest block mul add translate

0.5 setgray
0 earliest block mul neg moveto x 0 rlineto 0 y neg rlineto x neg 0 rlineto
closepath fill
0 setgray
earliest floor cvi 1 latest ceiling cvi {/oclock exch def
	-15 oclock block mul neg -4 add moveto oclock (  ) cvs show
	0 oclock block mul neg moveto x 0 rlineto
} for stroke

0 1  numclass 1 sub {/index exch def
	classes index get 2 get /day exch def
	day (M) eq {mon} if
	day (T) eq {tue} if
	day (W) eq {wed} if
	day (R) eq {thu} if
	day (F) eq {fri} if
} for

0 0.2 1 {x mul earliest block mul neg moveto 0 y neg rlineto} for stroke
0 earliest block mul neg moveto x 0 rlineto 0 y neg rlineto x neg 0 rlineto
closepath stroke
fsize tr
x 0.1 mul  earliest 0.2 sub block mul neg (Mon) center
x 0.3 mul  earliest 0.2 sub block mul neg (Tue) center
x 0.5 mul  earliest 0.2 sub block mul neg (Wed) center
x 0.7 mul  earliest 0.2 sub block mul neg (Thu) center
x 0.9 mul  earliest 0.2 sub block mul neg (Fri) center
fsize 2 mul tb
x 0.5 mul earliest 0.7 sub block mul neg user center
-25 earliest 1 sub block mul neg moveto x 1.2 mul 0 rlineto
0 y block 1.5 mul add neg rlineto x -1.2 mul 0 rlineto closepath stroke

showpage
} def % master

