Skip to content

Instantly share code, notes, and snippets.

@juliandunn
Created June 24, 2015 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliandunn/faadc5f04a0be5268162 to your computer and use it in GitHub Desktop.
Save juliandunn/faadc5f04a0be5268162 to your computer and use it in GitHub Desktop.
#!/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