#!/usr/bin/perl -w # envelope - © 2002 Ronald Florence # ron@18james.com, 24 Oct 2002 use Getopt::Std; # -- configuration -- my $separator = "#"; my $skip = 0; my $x = 230; my $y = 280; my $rotate = 90; my $font = "Palatino-Bold"; my $ptsize = 12; my $init = "%!\r\nstatusdict begin com10envelopetray end\r\n"; my $clear = ''; my $spooler = "lpr"; # -- end of configuration -- my @addr; my %Opt; my $blanks; my $zip; getopts("s:t:x:y:r:f:p:i:c:l:bh", \%Opt) or &usage; $Opt{s} and $separator = $Opt{s}; exists $Opt{t} and $skip = $Opt{t}; exists $Opt{x} and $x = $Opt{x}; exists $Opt{y} and $y = $Opt{y}; exists $Opt{r} and $rotate = $Opt{r}; $Opt{f} and $font = $Opt{f}; $Opt{p} and $ptsize = $Opt{p}; exists $Opt{i} and $init = $Opt{i}; exists $Opt{c} and $clear = $Opt{c}; $Opt{l} and $spooler = $Opt{l}; $Opt{b} and $blanks++; $Opt{h} and &usage; defined $ARGV[0] and &usage; my $preface = <) { next while $skip-- > 0; next if (/^$/ && !@addr && !$blanks); if (/^$separator$/) { @addr and &address; next; } last if (/^\s*$/ && @addr >= 3 && !$blanks); last if (/^\.(DE|fi)$/); next if (/^\.(DS|nf)$/); $_ = $1 if (/\\begin{letter}{\s*(.*)\\\\$/); $_ = $1 if (/^\s*(.*)\\\\$/); $_ = $1 if (/^\s*(.*)}$/); $zip = $1 . $2 if (/.*(\d{5})-(\d{4})$/); chomp; push (@addr, $_); } @addr and &address; print OUT $clear; sub address { print OUT "newenvelope\n"; print OUT map "($_) adline\n", @addr; $zip and &barcode; print OUT "showpage\n"; @addr = (); } sub barcode { my @bar = ("LLSSS", "SSSLL", "SSLSL", "SSLLS", "SLSSL", "SLSLS", "SLLSS", "LSSSL", "LSSLS", "LSLSS"); my $cksum; my $barcodes = "L"; for (my $i = 0; $i < length($zip); $i++) { my $s = substr($zip, $i, 1); $cksum += $s; $barcodes .= $bar[$s]; } $barcodes .= $bar[(100 - $cksum) % 10]; $barcodes .= "L"; print OUT "barcode\n"; for (my $i = 0; $i < length($barcodes); $i++) { print OUT substr($barcodes, $i, 1) . "\n"; } $zip = ''; } sub usage { print STDERR < Export -> Custom -> ASCII and giving envelope as the command. If you use return addresses on your letters you will need to supply the -t skip parameter or configure it into the perl code. All of the command-line options can be configured into envelope at installation. =head1 LIMITATIONS Only prints barcodes for full 5+4 zipcodes, as the USPS does not utilize barcodes for 5-digit zipcodes. =head1 LICENSE You may distribute this program under the same license as Perl itself. =head1 AUTHOR Ronald Florence =cut