#!/local/bin/perl # # Command line interface to Xphone database # # File: pphone # # Author: Nem W Schlecht # Last Modification: $Date: 1995/08/11 18:11:55 $ # # $Id: pphone.pl,v 1.1 1995/08/11 18:11:55 nem Exp nem $ # $Log: pphone.pl,v $ # Revision 1.1 1995/08/11 18:11:55 nem # Initial revision # # use Getopt::Long; GetOptions(qw(n:s help or print legal letter card file=s a:s h:s w:s f:s g:s e:s o:s t:s)); $letps="/home/nem/ps/posttemp.ps"; @me=split(/\//,$0); $ME=pop(@me); undef(@me); if ($opt_help == 1) { print "usage $ME:\n"; print "\t[-or] [-print] [-file ] -n -a
-h \n"; print "\t-w -x -g -e -o -t \n"; print "\t-legal -letter -card (these are for printing USPS 'happy' envelopes)\n"; print "usage $ME: \n"; print "usage $ME: -help\n"; exit; } @fields=qw(address home work fax pager email other notes); %flook=qw(address a home h work w fax x pager g email e other o notes t); if (!($opt_n||$opt_a||$opt_h||$opt_w||$opt_f||$opt_g||$opt_e||$opt_o||$opt_t)) { if ($#ARGV != -1) { $opt_n = $ARGV[0]; } else { die "Must supply some type of argument\ntry: $ME -help\n"; } } open (RCFILE, "$ENV{HOME}/.xphonerc"); while () { @in=split(' ',$_); shift(@in); if ($in[0] =~ /search_fields.*/) { $in[0] =~ s/\(/ /; $in[0] =~ s/\)/ /; @temp=split(' ',$in[0]); $search{$temp[1]}=$in[1]; } else { $rc_file{$in[0]}=$in[1]; } } close (RCFILE); $IRS_ORIG=$/; $/=""; if ($opt_f ne "") { open(PHONEBOOK, "$opt_f"); } else { open(PHONEBOOK, "$rc_file{phonebook}"); } while () { push(@data,$_); } close(PHONEBOOK); shift(@data); $/=$IRS_ORIG; for (@data) { s/\[set name\]//g; @info=split(/set /,$_); for (@info) { next if /^entries/; next if ($_ eq ""); s/[\(\)]//g; s/\n$//; m/(.*)\s\{(.*)\}/s; $temp{$1}=$2; } $name=$temp{name}; push(@names,$name); delete($temp{name}); foreach $key (keys(%temp)) { $$key{$name}=$temp{$key}; } undef($name); undef(%temp); } if ($opt_n) { $index{name}=1; if ($rc_file{case} == 1) { for (grep(/$opt_n/i,@names)) { $out{$_} += 1; } }else { for (grep(/$opt_n/,@names)) { $out{$_} += 1; } } } foreach $name (@names) { for (@fields) { my($spam)='opt_' . $flook{$_}; if ($$spam ne "") { if ($rc_file{case} == 1) { if ($$_{$name} =~ /$$spam/i) { $out{$name} += 1; $index{$_} = 1; } } else { if ($$_{$name} =~ /$$spam/) { $out{$name} += 1; $index{$_} = 1; } } } } } if ($opt_print ne "") { open (PRINT, "|lp -s -d$ENV{PRINTER}"); $fileh = "PRINT"; undef($printer); } else { $fileh = "STDOUT"; } if (%out) { print $fileh "\n"; } foreach $key (keys(%index)) { $ind_tot += $index{$key}; } my(@blah)=keys(%out); if ((scalar @blah) > 1) { $nophone = 1 }; foreach $name (sort(keys(%out))) { if ($opt_or eq "") { next if ($out{$name} != $ind_tot); } print $fileh "$name\n"; for (@fields) { &printenv($name,$_) if (($opt_legal||$opt_letter||$opt_card)&&($_ eq "address")); $$_{$name} = proc_multi($$_{$name}) if (($_ eq "address")||($_ eq "notes")); print $fileh " $_ :\t$$_{$name}\n" if $$_{$name}; } print $fileh "\n"; if (!$nophone) { phonehuh("Home", $home{$name}) if ($home{$name}); phonehuh("Work", $work{$name}) if ($work{$name}); phonehuh("Pager", $pager{$name}) if ($pager{$name}); } } sub phonehuh { my($what,$num)=@_; if ($num =~ /^231/o) { $num =~ s/231/1/og; } else { $num = "9,$num"; } print "Dial $what ($num) [ynq] "; chop($dialyn = ); exit if ($dialyn =~ /^q|^$/io); if ($dialyn =~ /^y/io) { exec ("dial $num"); }; } if ($opt_print) { close(PRINT); } sub proc_multi { my($in)=@_; $in =~ s/\n/\n \t/g; return $in; } sub printenv { if ($opt_legal) { $EHEIGHT="/EHEIGHT 10.5 cm def"; $EWIDTH="/EWIDTH 9.5 inch def"; $LWIDTH="/LWIDTH 10.8 cm def"; $addfonts="16"; $addoffset="4"; } elsif ($opt_letter) { $EHEIGHT="/EHEIGHT 9.2 cm def"; $EWIDTH="/EWIDTH 6.5 inch def"; $LWIDTH="/LWIDTH 9.5 cm def"; $addfonts="14"; $addoffset="2.5"; } elsif ($opt_card) { $EHEIGHT="/EHEIGHT 4.25 inch def"; $EWIDTH="/EWIDTH 5.75 inch def"; $LWIDTH="/LWIDTH 4.5 inch def"; $addfonts="14"; $addoffset="2.5"; } my($name,$field)=@_; $toadd = " ($name)\n"; @add=split(/\n/,$$_{$name}); for (@add) { $toadd .= " ($_)\n"; } # open (PRENV, "|lpr -d$ENV{PRINTER}"); open (PRENV, "|lpr -Phpprint"); print PRENV < - exch findfont exch dup /POINTSIZE exch def scalefont setfont } def /defleading { % define leading for nl /LEADING interline def } def /nl { % print string and move to start of next line dup stringwidth pop exch show neg LEADING neg rmoveto } def /addressfont { % set font for address /Helvetica $addfonts fontset defleading } def /returnfont { % set font for return address /Helvetica 12 fontset defleading } def /envelope { % translate and rotate coordinate system to match com10 LWIDTH EHEIGHT sub 2 div EHEIGHT add LHEIGHT EWIDTH sub translate 90 rotate 0 3 32 div inch translate % fudge factor for my printer - change or remove } def /returnaddress { % Print the return address gsave returnfont % This positions the return address .25 inches from upper left of envelope .25 inch EHEIGHT .25 inch sub POINTSIZE 3 64 div inch sub sub moveto {nl} forall grestore } def /address { % Print the address gsave addressfont $addoffset inch 2.25 inch moveto % Magic numbers conform to USPS guidelines dup % save the address {nl} forall dup length 1 sub get % Get the last line of the address mark { exch token not {exit} if } loop % Get the last word of the last line dup /str 20 string def type cvlit /marktype ne {str cvs barcode} if cleartomark grestore } def /barcodebits [ % From "A Guide to Business Mail Preparation" (11000) %0 % USPS Brochure/Pamphlet (00011) %1 (00101) %2 (00110) %3 (01001) %4 (01010) %5 (01100) %6 (10001) %7 (10010) %8 (10100) %9 ] def /bit1 { % Draw a 1 bit of the POSTNET Barcode 0 .125 inch rlineto 1 inch 21 div .125 inch neg rmoveto } bind def /bit0 { % Draw a 0 bit of the POSTNET Barcode 0 .05 inch rlineto 1 inch 21 div .05 inch neg rmoveto } bind def /dodigit { % Do a complete digit of the barcode barcodebits exch get { 2 mod 1 eq {bit1} {bit0} ifelse /BITS BITS 1 add def } forall } def /barcode { % Do a complete barcode gsave /CHECKSUM 0 def /BITS 0 def % More magic numbers to conform to USPS guidelines EWIDTH 3.9375 inch sub .25 inch moveto bit1 { (0) 0 get sub dup dup 0 ge exch 9 le and { dup /CHECKSUM exch CHECKSUM add def dodigit } if } forall CHECKSUM 10 mod neg 10 add dup 10 eq {pop 0} if dodigit bit1 BITS 50 eq {.02 inch setlinewidth stroke} if % if you want 5 digit zip codes barcoded as well, make the previous line be % BITS 50 eq BITS 30 eq or {.02 inch setlinewidth stroke} if % I don't think it's a good idea to barcode a 5-digit zip. Kinda defeats % the purpose. grestore } def % Note that if you print your own barcode, you need not follow the address font % guidelines since the only use of the OCR machines is to print barcodes. /nem [ (Nem (Ryun) W Schlecht) (910 3RD AVE S) (Fargo, ND 58103-1707) ] def /addressee [ $toadd ] def envelope nem returnaddress addressee address showpage EOM close(PRENV); }