#!/usr/bin/perl

open(LECT, "<$ARGV[0]" . ".lec");
while (<LECT>) {
	($name, $page)=split;
	$page=~s/-[0-9]//;
	$page++;
	push(@names, $name);
	push(@pages, $page);
}

push(@pages, 99999);

close(LECT);

for ($i=0; $i<=$#names; $i++) {
	$cmd="./psselect.pl $pages[$i]-";
	$cmd.=$pages[$i+1]-1;
	$cmd.=" $ARGV[0].ps";
	if ($ARGV[1] eq "8") {
		$cmd.="| mpage -R -8";
	}
	$cmd.=" > " . "$ARGV[0]" . "-" . "$names[$i]" . ".ps";
	system ($cmd);
	#print "$cmd\n";
}
