home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / envelope / part01 < prev    next >
Encoding:
Text File  |  1992-09-19  |  10.6 KB  |  315 lines

  1. Newsgroups: comp.sources.misc
  2. From: andyr@wizzy.com (Andy Rabagliati)
  3. Subject:  v32i089:  envelope - Perl Envelope Addresser tool, v2, Part01/01
  4. Message-ID: <1992Sep21.000624.5611@sparky.imd.sterling.com>
  5. X-Md4-Signature: c7153b8bfe2b8357079e0458c0a6283e
  6. Date: Mon, 21 Sep 1992 00:06:24 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: andyr@wizzy.com (Andy Rabagliati)
  10. Posting-number: Volume 32, Issue 89
  11. Archive-name: envelope/part01
  12. Environment: Perl, SGI, HPLJ, PostScript
  13. Supersedes: envelope: Volume 22, Issue 59
  14.  
  15. Envelope Addresser tool, Perl script.
  16.  
  17. Given an address, either from stdin or a file argument, addresses a 
  18. commercial envelope, including generating postal bar codes, on your 
  19. HP Laserjet II or III printer or compatible, or PostScript printer.
  20.  
  21. -------------
  22. #! /bin/sh
  23. # This is a shell archive.  Remove anything before this line, then unpack
  24. # it by saving it into a file and typing "sh file".  To overwrite existing
  25. # files, type "sh file -c".  You can also feed this as standard input via
  26. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  27. # will see the following message at the end:
  28. #        "End of shell archive."
  29. # Contents:  README env.pl
  30. # Wrapped by andyr@wizzy on Fri Sep 18 18:09:44 1992
  31. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  32. if test -f 'README' -a "${1}" != "-c" ; then 
  33.   echo shar: Will not clobber existing file \"'README'\"
  34. else
  35. echo shar: Extracting \"'README'\" \(2670 characters\)
  36. sed "s/^X//" >'README' <<'END_OF_FILE'
  37. XEnvelope Addresser tool, Perl script.
  38. XGiven an address, either from stdin or a file argument,
  39. Xaddresses a commercial envelope, including generating postal
  40. Xbar codes, on your HP Laserjet II or III printer or compatible.
  41. X
  42. XYou may want to adapt this to print your return address, as shown
  43. Xin the commented-out example.
  44. XYou may have to adjust the X-Y coordinates if your envelopes are
  45. Xnon-standard (or you don't like where I put things!)
  46. X
  47. XIn order for the barcode stuff to function properly, the last address
  48. Xline must end in a zip code, either 5 digits or (zip+4 format)
  49. X5 digits, a dash, and 4 digits.  Well, ok, I don't check specifically
  50. Xfor that format, but am looking for the end of the last line, minus
  51. Xwhite space, to consist of 5 to 10 dashes and/or digits.  It is up
  52. Xto you to provide the garbage-in in the right format for me to
  53. Xgenerate the right garbage-out.
  54. X
  55. XThe barcode portion of this perl script was inspired by a recent posting
  56. Xto alt.sources:
  57. X
  58. X    From: todd@toolz.uucp (Todd Merriman)
  59. X    Newsgroups: alt.sources
  60. X    Subject: Generate postal barcodes on HPLJ
  61. X    Message-ID: <1991Aug13.220925.28106@toolz.uucp>
  62. X    Date: 13 Aug 91 22:09:25 GMT
  63. X    Organization: Software Toolz, Inc.
  64. X
  65. XTodd wrote a C program to generate the barcodes only, and mentioned
  66. Xhow useful it would be to any U.S.P.S. mail program:
  67. X
  68. X    barcode.c
  69. X
  70. X    This is a program to produce postal barcodes on an HPLJ.  It was
  71. X    printed in the Winter '90 issue of the C Gazette (a fine publication).
  72. X    For a complete technical description, see that issue of the magazine.
  73. X
  74. X    This code could probable be easily adapted to almost any mailing
  75. X    list manager, as it accepts the zip code digits in ASCII and outputs
  76. X    the required HPLJ graphics commands to product a properly formatted
  77. X    postal bar code.
  78. X
  79. XDave Buck Caveats:
  80. XI haven't read the article mentioned by Todd, and only attempted to verify
  81. Xthe implementation by visual comparison to the barcodes I've actually seen
  82. Xadded by the U.S.P.S. themselves on three commercial envelopes I received
  83. Xin yesterday's mail.  So you KNOW what the warranty's worth on this one.
  84. X
  85. X
  86. X    {aeras,amdahl,ames,daver,netcomsv,sun,zygot}!dlb!dave
  87. XD. L. Buck and Associates, Inc.; San Jose, California 95119; (408)972-2825
  88. X
  89. XAndy Rabagliati ported this to PostScript. I corrected a bug on the
  90. Xcheck digit calculation. I use labels, as my printer seals envelopes
  91. Xput through it !! You may have to twiddle the PostScript stuff if you
  92. Xwant envelopes. I hope I have made this easy.
  93. X
  94. XI stuck in the #ifdef conditional stuff, and you will notice that the
  95. Xscript invocation includes a -P option - this is so Perl runs it all
  96. Xthrough the PreProcessor to get the HP or PostScript version.
  97. X
  98. XEnjoy,   Andy.
  99. END_OF_FILE
  100. if test 2670 -ne `wc -c <'README'`; then
  101.     echo shar: \"'README'\" unpacked with wrong size!
  102. fi
  103. # end of 'README'
  104. fi
  105. if test -f 'env.pl' -a "${1}" != "-c" ; then 
  106.   echo shar: Will not clobber existing file \"'env.pl'\"
  107. else
  108. echo shar: Extracting \"'env.pl'\" \(5916 characters\)
  109. sed "s/^X//" >'env.pl' <<'END_OF_FILE'
  110. X#!/usr/local/bin/perl -P
  111. X    # Envelope Label Addresser tool, Perl script.
  112. X    # Given an address, either from stdin or a file argument,
  113. X    # addresses a commercial envelope label, including generating postal
  114. X    # bar codes.
  115. X    # I couldn't put envelopes thru my printer without them being sealed!!
  116. X    #
  117. X    # You may want to adapt this to print your return address, as shown
  118. X    # in the commented-out example. (HP only)
  119. X    # You may have to adjust the X-Y coordinates if your envelopes are
  120. X    # non-standard (or you don't like where I put things!)
  121. X    #
  122. X    # In order for the barcode stuff to function properly, the last address
  123. X    # line must end in a zip code, either 5 digits or (zip+4 format)
  124. X    # 5 digits, a dash, and 4 digits.  Well, ok, I don't check specifically
  125. X    # for that format, but am looking for the end of the last line, minus
  126. X    # white space, to consist of 5 to 10 dashes and/or digits.  It is up
  127. X    # to you to provide the garbage-in in the right format for me to
  128. X    # generate the right garbage-out.
  129. X
  130. X    # credits :-
  131. X
  132. X    # todd@toolz.uucp (Todd Merriman) for barcode stuff
  133. X    # He credits :- the Winter '90 issue of the C Gazette 
  134. X    # Dave Buck    {aeras,amdahl,ames,daver,netcomsv,sun,zygot}!dlb!dave
  135. X    # for original Perl port to HP LaserJet
  136. X    # Andy Rabagliati (andyr@wizzy.com) - who hacked the above to PostScript,
  137. X    #    and changed the checkdigit stuff, as I think there was a bug
  138. X
  139. X    # ---- CONFIGURATION ----
  140. X
  141. X    # stick #define PS or HP here
  142. X
  143. X#ifndef PS
  144. X#ifndef HP
  145. Xprint <<"EndOfNoConfig";
  146. XHP / PostScript label / envelope printer
  147. XPlease state which configuration you want by putting
  148. X '#define HP'     or
  149. X '#define PS'     in the CONFIGURATION section of script.
  150. XEndOfNoConfig
  151. Xexit(1);
  152. X#endif
  153. X#endif
  154. X
  155. X#ifdef PS
  156. X$font = "NewCenturySchlbk-Bold";        # font of choice
  157. X
  158. X    # depending on the size of labels / letters, you need to move
  159. X    # the user origin to the bottom left corner of the area we are
  160. X    # working with. A rotate comes in handy too, sometimes.
  161. X
  162. X$xorigin = 0; $yorigin = 684;        # x,y origin
  163. X                    # this is my origin for labels printed
  164. X                    # in a letter printer, sure to need changing
  165. X
  166. X$rotate = 0;                # rotate ? You might want +-90
  167. X
  168. X$barcode_x = 290;
  169. X$barcode_y = 10;            # this is 100ths of an inch from origin
  170. X
  171. X#endif
  172. X
  173. X    # open (out,"|lp");        # Change this to how you like to get
  174. X    # select(out);            # to your printer
  175. X
  176. X    # ------ END OF CONFIGURATION -----
  177. X
  178. X#ifdef PS
  179. Xprint "%! Hey, we talk PostScript\n";
  180. X
  181. Xprint "$xorigin $yorigin translate $rotate rotate\n";
  182. Xprint "/$font findfont 12 scalefont setfont\n";
  183. X#endif
  184. X
  185. X#ifdef HP
  186. X
  187. Xprint "\033&l81a3h1O"; # Comm. Envelope, Manual Env. Feed, Landscape
  188. Xprint "\033(s1p12v0s0b4101T"; 
  189. X    # Prop., 12 pts, no slant, no bold, CG Times
  190. X    # Here's a dandy place to put your return address, if you want to
  191. X    # use blank commercial envelopes, e.g. ...
  192. X    # print "\033&a4L";    # L Mgin .4", (top 1/2")
  193. X    # print "International Foobs, Ltd.\r\nPOBox 000\r\nArmpit, Wyoming 54321\r\n";
  194. X    # Position for Addressee
  195. Xprint "\033&a70L\033*p500Y";    
  196. X    # L Mgin 3 1/2", (top 1/2"), vert posn 500 d
  197. X
  198. X#endif
  199. X
  200. X#ifdef PS
  201. X$y = 80;                # start position
  202. X#endif
  203. X
  204. Xwhile (<>) {                # Get address from stdin or file arg.
  205. X#ifdef PS
  206. X    print "10 $y moveto ($_) show\n";
  207. X    $y -= 13;            # next line down
  208. X#endif
  209. X#ifdef HP
  210. X    print "\r", $_;
  211. X#endif
  212. X    $zipline = $_;            # save last address line for possible zip
  213. X}
  214. X
  215. X$_ = $zipline;
  216. Xs/\s*$//;                # scrub white space at end
  217. Xif (/[-0-9]{5,10}$/) {            # Does this look like a zip, 5 or 5-4?
  218. X    $_ = $&;                # get 5 to 9 digit zip, optional dash
  219. X    s/-//;                # delete '-' for zip+4 codes
  220. X    # compute check digit: 10 - (mod 10 sum of all digits)
  221. X
  222. X    $digits = $_;
  223. X    while(length($digits)) {
  224. X    $ckdigit += chop($digits);        # sum all digits
  225. X    }
  226. X    $ckdigit = (100 - $ckdigit) % 10;        # 10 - (mod 10 of sum)
  227. X    $_ = 'L' . $_ . $ckdigit . 'L';        # long line start and stop markers
  228. X
  229. X    s/0/LLSSS/g;            # postal bar codes for each digit
  230. X    s/1/SSSLL/g;
  231. X    s/2/SSLSL/g;
  232. X    s/3/SSLLS/g;
  233. X    s/4/SLSSL/g;
  234. X    s/5/SLSLS/g;
  235. X    s/6/SLLSS/g;
  236. X    s/7/LSSSL/g;
  237. X    s/8/LSSLS/g;
  238. X    s/9/LSLSS/g;
  239. X#ifdef PS
  240. X    # Now output the graphic commands for the postal bar code
  241. X
  242. X    # scale to 1/100 ths of an inch
  243. X    # Bar width .015" to .025", we choose .02"
  244. X    print "0.72 dup scale 2 setlinewidth\n";
  245. X
  246. X    # Short: .04" to .06", we choose .05"
  247. X    print "/short { 0 5  rlineto stroke } def\n";
  248. X
  249. X    # Long: .115" to .135", we choose .12"
  250. X    print "/long  { 0 12 rlineto stroke } def\n";
  251. X
  252. X    # chopping here - which means from last to first.
  253. X    # so we move LEFT after each bar, having started right
  254. X
  255. X    $x = $barcode_x;     $y = $barcode_y;    # move to bottom right of label
  256. X
  257. X
  258. X    while ($_) {            # process each Short/Long line indicator
  259. X    $d = chop;
  260. X    ($d eq 'S') && print "$x $y moveto short\n";
  261. X    ($d eq 'L') && print "$x $y moveto long\n";
  262. X
  263. X    # Go left .045 to .05", we choose .05"
  264. X    $x -= 5;
  265. X    }
  266. X#endif
  267. X#ifdef HP
  268. X    # Left edge of barcode 4" from right edge of envelope
  269. X    # Base of barcode .2" from bottom edge of envelope
  270. X    print "\033*p990y1575X";     # vert posn 990 d, hor posn 1575 d
  271. X    print "\033*c6A";        # Bar width .015" to .025", we choose .02"
  272. X
  273. X    # chop is cheap, and takes last char off of string, too bad you
  274. X    # can't as easily chop from the beginning.  So we reverse the
  275. X    # string, and chop from the end.
  276. X
  277. X    $_ = reverse($_);
  278. X    while ($_) {    # process each Short/Long line indicator
  279. X    $d = chop;
  280. X    if ($d eq 'S') {
  281. X    # Short: .04" to .06", we choose .05"
  282. X    # move down, draw down, move back up
  283. X        print "\033*p+21Y\033*c15b0P\033*p-21Y";
  284. X    } else    {
  285. X    # Long: .115" to .135", we choose .12"
  286. X    # draw down
  287. X        print "\033*c36b0P";
  288. X    }
  289. X    print "\033*p+15X";
  290. X    # Go right .045 to .05", we choose .05"
  291. X    }
  292. X
  293. X#endif
  294. X}
  295. X#ifdef PS
  296. Xprint "showpage\n";
  297. X#endif
  298. X
  299. X#ifdef HP
  300. Xprint "\033E";
  301. X#endif
  302. END_OF_FILE
  303. if test 5916 -ne `wc -c <'env.pl'`; then
  304.     echo shar: \"'env.pl'\" unpacked with wrong size!
  305. fi
  306. chmod +x 'env.pl'
  307. # end of 'env.pl'
  308. fi
  309. echo shar: End of shell archive.
  310. exit 0
  311.  
  312.  
  313.  
  314. exit 0 # Just in case...
  315.