Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env perl
use warnings;
use strict;
use Encode qw(decode encode);
use POSIX qw(strftime);
use Text::Wrap;
$| = 1;
my %AGI;
my $name;
my $printer = '/dev/usb/lp0';
($AGI{arg_1}, $AGI{arg_2}, $AGI{arg_3}, $AGI{arg_4}) = @ARGV;
while (<STDIN>) {
chomp;
last if (!length);
$AGI{$1} = $2 if (/^agi_(\w+)\:\s+(.*)$/);
}
$name = " -- $AGI{request}:";
# Sanitize input of arg
$AGI{arg_1} = decode('utf8', $AGI{arg_1});
for ($AGI{arg_1}) {
s/[\\|*~<>^\(\)\[\]\{\}[:cntrl:]]/ /g;
s/\s+/ /g;
s/^\s|\s$//g;
die "$name No text passed for printing.\n" if (!length);
}
open(PRINTER, ">$printer") or die "Cannot open printer device";
# Print a bunch of blank lines to get over the header
for (my $i = 0; $i < 12; $i++) {
print PRINTER "\n";
}
# Print the date and a bunch of other stuff that goes on a telegram
# "601P EST OCT 17 64 AA582 BA287"
# "B LLT239 PD BOSTON MASS 17 603P EDT"
my $teledate = uc(strftime("%l%M%p %Z %b%e %y BW721 NY212", localtime));
my $banner = uc(strftime("B LNS194 PD NEW YORK NY %e %l%M%p %Z", localtime));
print PRINTER $teledate;
print PRINTER "\n";
print PRINTER $banner;
print PRINTER "\n";
print PRINTER "\n";
# Now print the message
$Text::Wrap::columns=70;
$Text::Wrap::separator="\n";
print PRINTER wrap("","",uc($AGI{arg_1}));
# Print a formfeed
print PRINTER "\f";
close(PRINTER);
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment