🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: sci.crypt
Article #2694

Re: Postal Bar Code help needed...

#2694
From: Bill England
Date: Mon, 13 Jan 1992 23:53
142 lines
4994 bytes
In article <13918@oasys.dt.navy.mil> tague@witchcraft.com (Michael Tague) writes:
>In sci.crypt, cmwhelp@tamsun.tamu.edu (Christopher Walton) writes:
>>I am searching for a good public domain program that will produce the
>>postal bar codes that are seen on the lower edge of some mail.
>
>>If anyone has any info on this it would be greatly
>>appreciated.
>
>Here's a message I got from a friend (posted without his permission).
>I changed the Reply-To: header to his address on this article.
>
>Curt Welch
>curt@oasys.dt.navy.mil
>

  Here is a perl subroutine that prints postal codes using jetroff
  and gives some additional information.
---------
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Copyright (c) 1991, Stephen Software Systems, Inc.
# All Rights Reserved.
#
# This software is provided under the terms of the GNU License.
#
# Changes to and distribution of this software may take place only
# under the terms of the GNU License.
#
#            THIS SOFTWARE IS SUPPLIED WITH NO WARRENTY 
#                       USE AT YOUR OWN RISK.
#
#  Modification History
#
#  WSE Fri Dec 07 12:12:44 PST 1990
#      Moved to seperate library for letter/package label simplification.
#
#  The code here is provided for testing and creating valid bar codes.
#  We recommend reading US postal publications 28 and 25 and acquireing
#  the FIM/POSTNET template available from your post office.
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# # # # #  Zip Printing Functions for jetroff/troff   # # # # # #

package postnet;
	# For every char in the zip code
	# Write the corresponding bar.
	# for the raster graphics v1 = 1.5cm line, 
	#			  v2 = 0.4cm line,
	#			  v3 = 0.2cm line
	#
	# These may vary with your jetroff/troff package.
	#
	#  0 = 11000		5 = 01010
	#  1 = 00011		6 = 01100
	#  2 = 00101		7 = 10001
	#  3 = 00110		8 = 10010
	#  4 = 01001		9 = 10100
@bar = 
('\(v2\h`-.102c`n\(v2\h`-.102c`n\(v3\h`-.102c`n\(v3\h`-.102c`n\(v3\h`-.102c`n',
 '\(v3\h`-.102c`n\(v3\h`-.102c`n\(v3\h`-.102c`n\(v2\h`-.102c`n\(v2\h`-.102c`n',
 '\(v3\h`-.102c`n\(v3\h`-.102c`n\(v2\h`-.102c`n\(v3\h`-.102c`n\(v2\h`-.102c`n',
 '\(v3\h`-.102c`n\(v3\h`-.102c`n\(v2\h`-.102c`n\(v2\h`-.102c`n\(v3\h`-.102c`n',
 '\(v3\h`-.102c`n\(v2\h`-.102c`n\(v3\h`-.102c`n\(v3\h`-.102c`n\(v2\h`-.102c`n',
 '\(v3\h`-.102c`n\(v2\h`-.102c`n\(v3\h`-.102c`n\(v2\h`-.102c`n\(v3\h`-.102c`n',
 '\(v3\h`-.102c`n\(v2\h`-.102c`n\(v2\h`-.102c`n\(v3\h`-.102c`n\(v3\h`-.102c`n',
 '\(v2\h`-.102c`n\(v3\h`-.102c`n\(v3\h`-.102c`n\(v3\h`-.102c`n\(v2\h`-.102c`n',
 '\(v2\h`-.102c`n\(v3\h`-.102c`n\(v3\h`-.102c`n\(v2\h`-.102c`n\(v3\h`-.102c`n',
 '\(v2\h`-.102c`n\(v3\h`-.102c`n\(v2\h`-.102c`n\(v3\h`-.102c`n\(v3\h`-.102c`n');

	## Replace all of the n's in the above array with
	 # a <CR> ( Probally eaiser to represent this way, alternative
	 # solutions are welcome.
	 #
	for( 0..9){
		$bar[$_] =~ y/n/\n/;
	}
1;

##
 # Init Zip, ( Basicly remember point size and anything else  )
 #    		 ( that needs changing during  zip printing.      )
##
sub Init_Postnet{
	$opt_p = pop(@_);
}
##
 # Out with the Postnet bar code
 #
##
sub Out_With_Zip_Bar_Code{
	local($zip) = @_;
	local(@zip_stack)=split(//,$zip);
	local($confirm_count, 
		  $bar_string,
		  $zip_sum )=();

	# Tack a binary 1 to string ... leading
	$bar_string = "\\(v2\\h`-.102c`\n";


	## USA mail bar codes should be either 5 or 9 chars.
	 #
	 $confirm_count = 0;
	 foreach (@zip_stack){
		if (/[0-9]/){
	 		$confirm_count++;
			$bar_string .=  $bar[$_];
			$zip_sum += $_;
		}
	}

	##
	 #
	if ($confirm_count == 5 || $confirm_count == 9){

		## Calculate zip 'checksum'
		 # (10- (sum(zip) % 10)) % 10
		 #
		$bar_string .=  $bar[ (10-($zip_sum%10)) %10];

		# Tack a binary 1 to string ... trailing
  		$bar_string .= "\\(v2\\h`-.102c`\n";

		## The point size is required to be 10
		print ".ft H\n.ps 10\n.vs 12\n";

		print $bar_string;
		print ".br\n";

	    ## Put the point size back again.
		printf(".ft H\n.ps %.f\n.vs %.2f\n", $opt_p, $opt_p * 1.2 );

	}
	##
	 # Exit without printing a barcode if zip was not valid.
}
-- 
 +-  Bill England,  wengland@stephsf.COM -----------------------------------+
 |   * *      H -> He +24MeV                                                |
 |  * * * ... Oooo, we're having so much fun making itty bitty suns *       |
 |__ * * ___________________________________________________________________| 
Technical Details
Message-ID: <1992Jan13.235336.12963@stephsf.com>
Path: arc1-ca.pugleaf.net!wupost!uwm.edu!cs.utexas.edu!uunet!stephsf.com!wengland
References: <7496@tamsun.tamu.edu> <13918@oasys.dt.navy.mil>

Show Full Headers
Complete Article Headers
Newsgroups: sci.crypt,alt.sources
Path: arc1-ca.pugleaf.net!wupost!uwm.edu!cs.utexas.edu!uunet!stephsf.com!wengland
From: wengland@stephsf.com (Bill England)
Subject: Re: Postal Bar Code help needed...
Organization: Stephen Software Systems Inc., Tacoma/Seattle, +1 800 829 1684
Distribution: usa
Date: Mon, 13 Jan 1992 23:53:36 GMT
Message-ID: <1992Jan13.235336.12963@stephsf.com>
References: <7496@tamsun.tamu.edu> <13918@oasys.dt.navy.mil>