#!/usr/bin/perl
# 
# Layout converter for eagle-4.11. 
# Reads in top.eps, bottom.eps, top2.eps, bottom2.eps and combines these 
# EPS files into one A4 PS file called layout.ps. 
# 
# Copyright (c) 05/2004 by Wolfgang Wieser
# 
# This file may be copied under the terms of the GNU GPL. 
# 

# Input files: 
my $topfile="top.eps";
my $botfile="bottom.eps";
my $topfile2="top2.eps";
my $botfile2="bottom2.eps";

# Output file: 
my $layfile="layout.ps";

############################### Do not touch ###################################

open LAY, ">$layfile" or die "Opening $layfile for writing: $!";

# Write head: 
open TOP, "<$topfile" or die "Opening $topfile for reading: $!";
while(<TOP>)
{
	last if(/^[0-9][0-9][0-9]/);
	if(/%%BoundingBox:/)
	{  print LAY "%%BoundingBox: 0 0 596 842\n%%Orientation: Portrait\n";  next;  }
	print LAY "$_";
}
print LAY "% -- Head done. --\n\n";
close TOP;

# Write content: 
foreach $file ($topfile, $topfile2, $botfile, $botfile2)
{
	open IN, "<$file" or die "Opening $file for reading: $!";
	print LAY "\n% -- Content of $file: --\n\n";
	while(<IN>)
	{
		if(/^[0-9][0-9][0-9]/)
		{  print LAY "$_";  last;  }
	}
	while(<IN>)
	{
		last if(/^%%EOF/);
		print LAY "$_";
	}
	close IN;
}

print LAY "\n%%EOF\n";
close LAY;

################################################################################

# Lauch gv: 
`gv "$layfile"`;
