#!/usr/bin/perl

print <<EOF;
\\pdfpagewidth 7.573in
\\pdfpageheight 5.6733in
\\pdfimageresolution 300
\\hoffset=-1in
\\voffset=-1in
\\def\\pic#1#2#3{
\\pdfdest name{#2}xyz
\\pdfoutline goto name{#2}{#3}
\\pdfximage{#1}\\pdfrefximage\\pdflastximage
text
\\eject
}
EOF



#	@cat pics/INDEX \
#		| sed 's/\(\S*\)\s*\(\S*\)\s*\(.*\)/\\pic{\1}{\2}{\3}/' \
#		>> $@
#	@echo "\bye" >> $@



foreach  (`ls \`pwd\`/pics/*.jpg`) {
    
    chop;

    if (/(SM-[XVI]*)[_2]*\/L(\d)\/pics\/s(\d)(.*)\.jpg/) {
	
	$filename = "s$3$4.jpg";
	$ref      = "l$2s$3$4";

	if ($4 eq "") {
	    $label    = "$1 L$2 S$3";
	} elsif ($4 eq "dcs") {
	    $label    = "$1 L$2 S$3 DCS";
	} elsif ($4 eq "a") {
	    $label    = "$1 L$2 S$3 A-Side";
	} elsif ($4 eq "b") {
	    $label    = "$1 L$2 S$3 B-Side";
	} elsif ($4 eq "c") {
	    $label    = "$1 L$2 S$3 C-Side";
	} else {
	    die "unknown spec: $_";
	}
	
	print "\\pic{pics/$filename}{$ref}{$label}\n";
    }


}

print "\\bye\n";
