#!perl
# Envelope printing program. Based on the psfilt library and envelopes.ps
# filter. It took 9 minutes to write *AND* verify that it produced output
# identical to the C version.
#
# It reads standard files, prepends the preamble, and adds "CLEANUP" to the
# end. This particular filter uses SLINE to show each line of the file, and
# RET to print the return address. The output file can be printed on any
# postscript printer that can handle /manualfeed, and prints one envelope
# at a time with a copy of the return address and the current destination
# address.
#
# [eichin:19910201.0222EST]
#
print <<EOF;
%!mwe
/inch { 72 mul } def
/font /Bookman-Demi findfont def
/fset { /fs exch def font fs scalefont setfont } def
/BEGINRETADDR	{ noborder 8 fset  .35 inch  -.5 inch moveto } def
/BEGINADDR	{ 18 fset 2.25 inch -1.8 inch moveto } def
/ENDADDR	{ showpage INIT } def
/CLEANUP { } def
statusdict /manualfeed true put

/SLINE { currentpoint 
	3 -1 roll
	show
	moveto
	0 fs neg rmoveto
} def

/INIT {
	8.5 inch 11 inch translate
	270 rotate
} def
/noborder { } def
/border {
	newpath
	0 0 moveto
	0 -4 inch lineto
	9.5 inch -4 inch lineto
	9.5 inch 0 inch lineto
	0 0 lineto
	closepath
	stroke
} def

INIT

EOF

print "/RET {\n	BEGINRETADDR\n";

while(<>) {
  chop;
  last if (/^$/);
  print "	(",$_,") SLINE\n";
}
print "	BEGINADDR\n} def\n\nRET\n";
while(<>) {
  chop;
  if(/^$/) {
    print "ENDADDR\nRET\n"; # if it's last, the ENDADDR below gets it
  } else {
    print "	(",$_,") SLINE\n";
  }
}
print "ENDADDR\n";
print "\nCLEANUP\n";

# that's it...


