#!/bin/sh -- # A comment mentioning perl, indented for bash's sake. eval 'exec perl -S $0 ${1+"$@"}' if 0; chop($Program = `basename $0`); if ( $ENV{ENVELOPE_XTERM} eq '' ) { foreach $arg (@ARGV) { next if $arg !~ /^-x$/i; $ENV{ENVELOPE_XTERM} = 1; if ( fork ) { sleep 1; exit 0; } else { exec 'xterm', '-geom', '+350+350', '-e', $0, @ARGV; exit 1; } } } #print STDERR join(' ', @ARGV), "\n"; sleep 1; if ( $ENV{FULLNAME} eq '' ) { $ENV{FULLNAME} = 'Karl J. Runge'; } if ( $ENV{FULLSTREETADDRESS} eq '' ) { $ENV{FULLSTREETADDRESS} = '66 McIntosh Lane:Bedford, NH 03110-4418'; } $From = "$ENV{FULLNAME}:$ENV{FULLSTREETADDRESS}"; $Interactive = 1; $InFile = ''; $Number = 1; $Enscript = "enscript -B -f %FONT"; $Gv = 'ghostview'; $Gv = 'gv'; ############################################################################# $mode = 0; $Style{$mode}{font} = 'Helvetica-BoldOblique11'; $Style{$mode}{skip_from} = 0; $Style{$mode}{skip_to} = 6; $Style{$mode}{indent_from} = ' ' x 0; $Style{$mode}{indent_to} = ' ' x 80; ############################################################################# $mode++; $Style{$mode}{font} = 'Helvetica-BoldOblique11'; $Style{$mode}{skip_from} = 0; $Style{$mode}{skip_to} = 5; $Style{$mode}{indent_from} = ' ' x 15; $Style{$mode}{indent_to} = ' ' x 60; ############################################################################# $Mode = 0; if ( $ENV{ENVELOPE_DEBUG} ne '' ) { $Debug = 1; } else { $Debug = 0; } $Usage = <<"END"; $Program: Print out a envelopes. Usage: $Program Options: -f 1 line squeezed from -t 1 line squeezed to -x Doing X windows -m mode (0 .. $mode) -s small envelope (mode=1) -d debug -q Non-interactive -n Number of envelopes -i Input file for To. Notes: To and from are ":" separated for each line. Renata B. Hesse:U.S. Department of Justice:601 D Street NW:Suite 1200:Washington, DC 20530-0001 When using -i input mode it can either be squeezed format with :...:...: or a single multiline address. For small envelope, it is a bit tricky in the HP 500C: Wheel Wheel Wheel # # # # # # Tab == == Tab | | |-----small-----| |--------large------| The left edge of the small env. just touches the left wheel. END select(STDERR); $| = 1; select(STDOUT); $| = 1; LOOP: while (@ARGV) { $_ = shift; CASE: { /^-f$/ && ($From = shift, last CASE); /^-t$/ && ($To = shift, last CASE); /^-x$/ && ($Doing_X = 1, last CASE); /^-m$/ && ($Mode = shift, last CASE); /^-s$/ && ($Mode = 1, last CASE); /^-d$/ && ($Debug = 1, last CASE); /^-q$/ && ($Interactive = 0, last CASE); /^-i$/ && ($InFile = shift, last CASE); /^-n$/ && ($Number = shift, last CASE); /^--$/ && (last LOOP); # -- means end of switches /^-(-.*)$/ && (unshift(@ARGV, $1), last CASE); /^(-h|-help)$/ && ((print STDERR $Usage), exit 0, last CASE); if ( /^-(..+)$/ ) { # split bundled switches: local($y, $x) = ($1, ''); foreach $x (reverse(split(//, $y))) { unshift(@ARGV,"-$x") }; last CASE; } /^-/ && ((print STDERR "Invalid arg: $_\n$Usage"), exit 1, last CASE); unshift(@ARGV,$_); last LOOP; } } if ( !defined($Style{$Mode}) ) { print STDERR "BAD MODE: $Mode\n"; exit 1; } $Enscript =~ s/%FONT/$Style{$Mode}{font}/g; $Skip_FR = $Style{$Mode}{skip_from}; $Skip_TO = $Style{$Mode}{skip_to}; $Spac_FR = $Style{$Mode}{indent_from}; $Spac_TO = $Style{$Mode}{indent_to}; $EnvFile = "/tmp/$Program.$$"; sub process { local($from, $to) = @_; local($part, $example); my $street = $ENV{FULLSTREETADDRESS}; $street =~ s/:.*$//; if ( $to =~ /$ENV{FULLNAME}/ && $from =~ /$ENV{FULLNAME}/ && $to =~ /$street/ && $from =~ /$street/ ) { $from =~ s/\S/ /g; } open(ENVELOPE, ">$EnvFile") || die "$!"; print ENVELOPE "\n" x $Skip_FR; foreach $part (split(/:/, $from)) { print ENVELOPE $Spac_FR, $part, "\n"; $example .= $part . "\n"; } $example .= "\n"; $example_space = ' ' x 30; print ENVELOPE "\n" x $Skip_TO; foreach $part (split(/:/, $to)) { print ENVELOPE $Spac_TO, $part, "\n"; $example .= $example_space . $part . "\n"; } close(ENVELOPE); $gv = "$Gv -geometry +0+0 -"; if ( $Debug ) { system("$Enscript -p - $EnvFile | $gv"); } else { $x = ''; if ( $Interactive ) { while (1) { print STDERR "\nfile: $EnvFile\n\n"; print STDERR $example, "\n"; print STDERR "\nFor HP 500, put envelope in tray under the wheels, then press the \"Envelope\"\n"; print STDERR "button, which will suck in the envelope part way. Then press here.\n\n"; print STDERR "Press when printer is ready,\n\t(v to view, e to edit, q/x to quit, or s to skip): "; $x = ; if ( $x =~ /[xq]/i ) { &cleanup; exit; } elsif ( $x =~ /s/i ) { return; } elsif ( $x =~ /v/i ) { system("$Enscript -p - $EnvFile | $gv"); } elsif ( $x =~ /e/i ) { my $ed = 'vi'; $ed = $ENV{VISUAL} if $ENV{VISUAL} ne ''; $ed = $ENV{EDITOR} if $ENV{EDITOR} ne ''; if ( $ed =~ /vi/ ) { $ed .= " +"; # last line } system("$ed $EnvFile"); if ( open(ENVELOPE, "<$EnvFile") ) { $example = ''; while () { $_ =~ s/^${Spac_TO}/$example_space/; $example .= $_; } close(ENVELOPE); } } else { last; } } } system("$Enscript $EnvFile"); } if ( $Doing_X ) { sleep 2; } } sub cleanup { unlink($EnvFile); } if ( -f $InFile || $InFile eq '-' ) { open(IN, "$InFile") || die "$!"; $to = ''; while () { chop($_); next if $_ =~ /^\s*$/; next if $_ =~ /^#/; if ( $_ =~ /:.+:/ ) { $To .= "::$_"; } else { $_ =~ s/^\s*//; $_ =~ s/\s*$//; $to .= $_ . ':'; } } close(IN); $to =~ s/:$//; if ( $to ne '' && $to =~ /:.+:/ ) { $To = $to; print "To: $To\n"; } } foreach $to (split(/::/, $To)) { next if $to =~ /^\s*$/; for ($i=0; $i<$Number; $i++) { &process($From, $to); } } &cleanup;