REBOL [
    Title:  "Create an Intelligent Mail Barcode encoding string"
    Author: "Steven White"
    File: %usps4cb.r
    Date: 7-Nov-2011
    Purpose: {This is a program to load the United States Postal Service
    Windows library for creating the new Intelligent Mail Barcode.        
    It is designed to be included in a calling program, and it provides 
    a function to generate a coding string, which in turn may be printed in
    a proper barcode font to produce an Intelligent Mail Barcode.
    Normally, one would use this program along with the Windows library
    downloaded from the postal service.  However, for demo purposes, a
    compressed version of that library is included in the source so you
    can verify that this program actually works.}
    library: [
        level: 'intermediate
        platform: 'all
        type: [tutorial tool]
        domain: [external-library]
        tested-under: none
        support: none
        license: none
        see-also: none
    ]
]

;; [---------------------------------------------------------------------------]
;; [ This is a module to call the Intelligent Mail Barcode library             ]
;; [ provided by the US Postal Service.                                        ]
;; [                                                                           ]
;; [ The way to use this module is to "do usps4cb.r" at the beginning of       ]
;; [ your program.  This will cause this module to load the library, and       ]
;; [ to define a function that you may call to encode barcode data.            ]
;; [ The parameters you will use are filled with default values because        ]
;; [ this module does one other thing after it loads the library.              ]
;; [ It makes a call to the library with values known to generate a correct    ]
;; [ encoding, and saves the results.  Then, if your calling of the module     ]
;; [ does not work for some reason, you can check the results of that          ]
;; [ first test call to make sure the library is working correctly.            ]
;; [                                                                           ]
;; [ After you "do" this module to load it, you may call the encoding          ]
;; [ function as many times as you want to.  The way to do that is,            ]
;; [ move values to encode into IMB-TRACKSTRING and IMB-ROUTESTRING.           ]
;; [ These would be strings of digits, 20 and 11 digits long respectively.     ]
;; [ Then invoke "IMB-ENCODE."  The resulting coding will be in                ]
;; [ IMB-BARSTRING, and IMB-RETURNCODE will indicate the success or failure    ]
;; [ of the library call.  A value of zero is a success.                       ]
;; [ Note that this calling procedure is not like what seems to be the         ]
;; [ normal REBOL way.  
;; [---------------------------------------------------------------------------]

;; [---------------------------------------------------------------------------]
;; [ Parameters to library routine, in required order.                         ]
;; [                                                                           ]
;; [ The calling code, in C, would be                                          ]
;; [ IMB-RETURNCODE = USPS4CB(IMB-TRACKSTRING,IMB-ROUTESTRING,IMB-BARSTRING);  ]
;; [ We have to make the REBOL code accomplish this.                           ]
;; [---------------------------------------------------------------------------]

IMB-TRACKSTRING: "00700901032403000000"
IMB-ROUTESTRING: "55431308099"
IMB-BARSTRING: (make string! 65)
IMB-RETURNCODE: 0

;; [---------------------------------------------------------------------------]
;; [ These are the results of the test call made when the library was          ]
;; [ loaded.                                                                   ]
;; [---------------------------------------------------------------------------]

IMB-TEST-TRACK: ""
IMB-TEST-ROUTE: ""
IMB-TEST-BAR: ""
IMB-TEST-RESULT: ""

;; [---------------------------------------------------------------------------]
;; [ This is the name of the dll file provided by the Post Office.             ]
;; [ We are assuming that it is in the same directory as this script,          ]
;; [ in other words, that these files will be moved around together.           ]
;; [ Also included, for demo purposes, is a compressed version of the          ]
;; [ library file.  Code in this module can be modified to load the            ]
;; [ library from a disk file you already have, or to create a library         ]
;; [ file from the enclosed data and THEN load from that newly-created file.   ]
;; [---------------------------------------------------------------------------]

IMB-LIB-FILE: %usps4cb.dll  ;; name of library file
IMB-LIB-DEMO-FILE: 
#{
789CED5C0D7454D5B53EF39364928C64D460C18A0C6DB0604998FC4042FE9C90
9988362092C4FA472F433221A3934C3A3F08969FE06496CE9AA6CDF3A7E5ADC6
65A2BE96D7DA25BE52450A6D0025D2625F445D8FB56AFBA8C576E2E02BD58829
2F326FEF73CEFD9B9B1F9AF76C5FBBBC7A73CFD9679FFDEDBDCFDEE79E73EF1D
56DFD94B0C8410239CC92421FB093BEC64FAA30BCE59F30FCC22FB325F5DB05F
57FFEA82C6364FC0DAE9F76DF2BBDAADCDAE8E0E5FD0BAD16DF5873AAC9E0EAB
E396066BBBAFC55D70D96559795CC65A2721F5BA0CF2F86FDFBD912C27E43B3A
424E93F4CF67EBF465C40A0C4570CE81D3C24F1BED66A1653DD35BC7F5A7473F
AB14FF9A50BB080AB1B02EECCA2F9D847C8D1B91A79FC2C85E4216E92EC1197F
E15110746F09C2D5319F2B64250A23D8B101FE2F6871055D50EEC736B43D1DCE
3C359F9D90C1023F63B4EB1981CABA5EC3672FD81808D0F255F067EDC4BA75A1
3C3793477D04BE425F938209E479181FF56117C7B54DA49FDBEB6BE6BEECE5F2
4A347C2B27D6E8D3E3933A9AA2EF7CF9B686F059736CBB399CD4E574FF0088D1
6D79C6D87A4B6CB5297A779E296ACE8BBBE702F518B021CFA3470A0723E7731E
1D8C1C09DE159B0D6164899C0C3A63F32C504A5CD6AB3CC209E38AD7FD736386
C860F083E430E3A6C440A227781D89E6E6C5F7CC23A4F06494360D196970C7BB
811649862CA2F8505DE179CA7FAEC73D7AD75784F547CC04EBC0DF25F23F4559
0783DE216ADA53A84EFC27A079BC0EFE8C5C974C267B99923D9B49CFC12F20D3
25E857988CA783F4689552BF33D780441F488C5F80D2103103B1707044004ACF
F3C8C1E5371D40BCE83BE1B3735EC4FE31A729DA083EADCF33468D79F11EE87C
3C3CA69B3B7894756B7A51E23F20F2D7E7611FCABF1EF98F2AFC0BE3B77EE405
304FAE87CFE6C69C96D6A8F36278BB8984CC43CEB32879E4109ABBDD4C764A14
1CEB21E72896634EF3AAA8732CBC7D8CEC68015083732CE77912759E8B39C70C
4ED32AAC1C39FCB6A9C7792ED392F342D3C598F35CCEB34790A16914883AD434
D634A63B020D0FE959AF9EB549A81D8E9B9000574BD409BC63E145FAC4B71029
741D746230138B6C325169A0AF8EEA78F6F8D1290C9CA7A306EA6403B381D21A
DE7E51C13486829ACCD1E1C363F30FC7E7F718F5AF8DE906171F890EC33084EC
A242A34CA1D1E86B07B0DB477F8A369DD3909CA354C351D4700C354CCC1A729E
23D4AB63CCAB63154EF3F6FBD0FAD368BDEC59E6CCD14C0B73953DE7790BAD5E
22AEE4EC51EE5EE66F1DD5067D4CF4895DB12670D4B9D6E8A53AF0A02642BECF
42438C000C07AC84E37A4D40F020304BE38E5AB1DA45310A766D3F878B8C9C6F
0FE63C3F48CD3087E3061A77A3BAD00A1A7DC5928F0C6033222AE20A05108500
B034694A1CD6D8774DCC992BC6F3963B7B9C17A38E3C3338A927F765362E9698
519FF3C220906100CD703162A64186F57D9C4C422404337962243E8FDDCCAC5B
13588AB22E3732E07E6062C0A31C780E00A3D02190C891506AD35C8C89714619
C798D80C57491B93529B5CA60DED973F2E6943032A51A7EEE6D01B27ECF7998B
29FD66F538C79324F1000F54B0892B0C1D4D1809AD543DCE0E6ECBD9793D40E9
06A16D1C8D0E9FD6C59AC63387C5FA6B71EC856E208961208C737979D2846281
0138C78DDEB57D3C092B9D9C6F0ED1E438CB7224CEB0E2E69D7363ABE300F7FA
58F448F86D5D0F0C2764431C44FF16C614DC154C1B0933DFA1B960A01D265A28
1E8E1B90E01CA35E1D837B128D8B3334F1C6B7EB136BC3DBCFE8425743F0F498
236C0CC1E2F1A8F172885718411B0C9DB665344952E863229DFA716409C0834C
7B8573147D7C9AFA38030ACCB9A7E53433B128D407B3E16F5A70C3C88FD0E62A
2BCCED24940F61625A83BE80A1C31511DC5ED6E25DEB393E7E66EEBF916E9688
43642DBD29588608ED96867274D499E3740212C255362AFA7A149D91C644A731
D1BDB782E8DBE4D0A0A2134BA85C6CA372699F345B8ADC0C397AB96D1688988B
CB72306E9219184490B1874FA741545C483A4D300FEAE9E09ECBD8B916020722
E442E1301DB12C0825B8DBE662D0E806A347309A0A695C2532A59083C2C26406
CCDE2CDC2E50EA051C3392F83ECF3A9834CC3B4312B44186269F18348D814444
0AF85D67E7802A43114B1227362C197909D3D38283204E03D21C137BE069F04D
72189653D1489046928A357712D64E64A57FBBCAAC21530F054D02A49943860F
51358225B188090AAB2A68CB8E85AC9381D6A06B304BD6B78712C1A4A362E74C
C67D0CDBE640814E2E9444D5A20A630666C192271AC9A53AE5723E8CB5ABEDB0
BE8A6CE15CF5B9841C8BDC0FB5826391AFC1C51A3E84DC6447E6B1C8368AFC05
1907FBCF97FA87070D28221345380F328772C90A07F5710799A2D4F5B282B75E
09CE648A43AD96D690E3F8110B2E7B1B769D3D63C0017348DEC352F6CE35314A
1AEA7E7937CCBE59382422A16F9C8FAD48284BE5A81C17FDEA607EFD57BCBD00
7EF195E82E1BCEE787F06F5A70392FDC77052B909CEEF93ABE686194CCE09DAC
909DD3DD87B3C039A255D8B8F3BAD8630E1A4566036DCBF92909C76DD1EE37DF
80AE9222AF0D451E853A26CEC80B13C8314D2E67DF247286225E5E4AB4A58ACB
9A5CDCD3D38A1B8AD48B827386222550C6F5F548759AA87636FABC878A672094
1A63FE3774BF890315ED7EB58FBA9B2AB6539F68625CE183741C337794A5F4A5
DCF1AC28EB9ED2884ADAA1E9515979D3C8561C7458595C8623EE8C8B216CA601
80D183237FE62336E1724BF0A9C448D048276653169FFB4501C05E3E4A278456
E62E7E774FE1293B4F714D69DAEEFFFD01ED6E9FB2FFD887D09F1AA19706ECCA
9DB74CA2D11E26928DE29472FB3F548CEC1E4EFCE59FA1573492FE31B6993E66
990EF30E2B19E1BE8466C47F31A67213AE9E46561BD09116A94FAEDC07158F7F
7B823E736952DBA560C452E6CE82D863763A9C28CCC0D57873778C320E395EEE
63496B67AA1F1F72EE7E448F77BFD3DBF4D41FE62C6AE5EE098C8E7DA852028D
1979548F6B9EBE87E1B24349DF46E967BE964A6FD1E3C47F46876B979C17A8AF
E06ED50AF7AACC1E67DF2E429589544A46612933E79B8374EAA9A469400D7B0C
0D5BD1F872DF362E1D1F178DA4EB2536B0B4825ABF6D25A3C09CB50AC55A31A1
280B97874CC8BE78B82797AD83A8FB61A50A89550F2C89B2A925405FA9A759D5
B38732C032AA18BBA79AB5B3867B80497B7D8CDDB417C41E5308EF7E19057D34
BC10979590964AB189E7872265924C2CD97776C61E2FA3BDE95F50CB06CB1D56
3147EC45506132285AB4FBF145B04A4AE9622D5474D950ACE9328706781953E1
C18954A0A4F0C1080A27A125521D7B92D02C58241828E9186904E7CA3547E2FA
29786B126645AD4E5601A8E1C19A63183925D28D0B4BBB5EC23BDF5DEBD90266
15DD36C33E1042E60DD02C034306772FB8151489B83419C9A1448B44C41C1CB9
606053D96C3E71D044729EC2CC10CCACC9AC6A7A059B1CBC2997AD9430A979A7
0BD9AC259BAD78590BED733A9B764749106B0449878004B171550AF9BB403E86
CB6C3B2E6373BA1FD661722F52AC323E67A7CF723E0F97F81F61820621DC287A
835C68103BA02A355CFF32E046F1A50C55D961549F8A70BF02A1478B70543F11
42174778334B83F0B006E18802E18B5A04D78408273842408B60D320CCAA9111
8E9FD720247513215C53C3102ED722FC12D7CA6976716FC1A306071E473912BF
C8EE984399B868FC18B34426BE0FC4F058AE282F13E5EDA06BEF3C29D1F2E87D
AC0676A5064ACD479CAEB2A53B66A79256C07A804BC2997DA4849A92C7E78FAE
4323D0B07447362B94C8CC189523193A39AE3136A9F2A7B89E5954F9334C7991
B82C13577FB8CC0D1FC2BFD9F75D15EBC1C27E74C4EBA7172EA0CE12138BAE76
06E842C89A1433174B1554C6F66A6A0E12F2AD2A0B1524B4D0CCC4E1CD2AD1D4
435BC1BC7DD222DA246ACF52EFF7B0F4604B7A713C95CB6D3AA8779BE88D0089
54748CFEE55B217C7924E5DCFDE851E79E89126EC7A8184A2D491E197FD453EE
89B2ED7886184712F761BD4AB632D53EA795FD8856B69867ED5AD96EB56C6592
1DFB4023BB542B5BCCB0CBB5B233D5B295E9758F56F6AF741AD9626EFD385D23
FB87AADC1227746CA613FA3774F2848E443AA16FD5C9137A0B5F0D8EB4E8E4D4
14A766693FB7241D37633D44A6DC992EE5258AA079B90045389FA649B9FDE92B
779660703A9F0E0F7661A85A14359E87D893E6E11F684A3D0D517AACEB102EAF
691262A144E6A4497888C84928DE27226D5CA9481A2621EE04894CDC0BC4A8B3
2FBCBD2FFBBE2B63ABFB5272CFCC84A3BC44F390B39F669DB3BFC2D9B77D19D5
B83F1F5F5CA10557A8EA3CD3B033CDB4EB7A9CFDB8A3669BFE94E78B0FFC0953
A7852E2CF0AFEA697E6F6F13552AFA0EBEDF909EE79B06BA4A88255C46829F49
5A6297612576ABB1A7C6F8141623274323C78FF6ECBB0E15C68D6DF8AC71C0B6
143A8C25838B2383D1A3C12BA3E7F9FB8864EEE3D8F4A5D07908BCFEC5107877
FE2199BC03D6028583E1AA126822892C7BEC9A081623BF0A8D267EAA7E9FC1E4
C7E6ED75D3F66514E945AAF4654843D03C0A3A0BDF9F68F1DEFD7D32797B2A5E
2EC33B097829FE78D1BE12DF872472991A60774C173E6CD23D0015CBAE3F63AB
FFDDF552A7A601D28AFCEB63AB8CC9DF46CF371D5849FDD9001B96F0D9167CF7
D2D3B4A7F057FC854A72767F17B11CC097B0D486F05933444246A24E77FCE62D
B3BAB65DBFA726349AF90BA86D7D3F5C5119CA889E8AAD1F3F7EF4C56E48C403
EFA2E8FA3C334A05F39E03DAFE61CC5018EEF84648A6FDE350FBC91964832D04
BE4C4BFC071F28D99F5FBEAD61D7D91368DB65A87BE478D0C4DF711D856D480D
1C031B404C4F68F790B30FAB109B78893AF70FB4E00CE27C9A51F730EAC18136
4A7D8651F732EAE0809752F7B1EA4B039DA8A8F3958120BD9E18D842AFC303DB
E8F58D9C17D2BAA0D41A855B4309F8A90FFC447D6884C165FBF948858E3E56AC
04DDE3063D2651F4684EF71D401D8F0EB19DF38B39D0F8C10F866A8DC3053C4E
866A4DC3D713CBC03044CB90013BC766BF81E5DA45E891686DEE402F8475B461
4E6CF6A358A8BD66E0B41B09D6A15A1BDEC2A2B54B62B3FBA0696037652CA303
18AD2D899E8F9E5AF00A7D9F9667D51D37D63CD47D3DEE4D6EDEFA07EAC3289D
0BA8D7A2112F16DB68111F1251FFB0E771CC37748663EEA14FAAB887BAB887BA
650F3DD41359C5E698E4ECDDD44F63E8A7646865E14988E96BA3D7E4C58FA286
A223A1157C191770177A343A0F87BDA7D6F8D439375E4D4F59B0CE43203A162F
C33DDDA9E885D07389E7E29FD549EFFAA4F981BF74B0B009C7CC261C139FBB07
F621E0A01D279FFF022594F56B71E48E1385C4E4C267A0B91727367A24171E4C
A9BF9452DF9B527F25A57E26A57E3AA57E2AA57E22A5FE564AFD8D94FA704A7D
7F4A7D30A5DE9F52EF4BA9EF56D5E9FBD56FBF9D4C8AFE81C3BA947D4292E44B
B3BFE743FCE404EFFCF8AC009F4EE113094C54BC95E3322183D7C5CF64D2793F
13A765F23E06DEAEE3E50CCE97CE79331532941846CE6FE2BC4A3CB14DC4C8E0
7C22969EA8BFFFC9E4F50C45BBA88341215B94679AC63F93F1A7CA15DB32791F
51BF74853E13F9224DD19E96E28B0CCE4F14BC46DE57E96B51A6E85B23E7CD24
B23FD3887A8C4D64E2719E281EA63AC476EC9FCDE59915F52C22C78B99CBCD48
D14DF48549816FE66D59BC9D28EA69293244DBCD448E05D1173A85DFD2153C84
C8B127FA274B617726D75F94ABF463B6C2F6A93E1D23BC3D8BCB10C744A99318
DBD90A1DC43115BFCBD371BA282F9BC8B922FA5B993F467E8A7A8A7C4A1C3117
0C5C768642AEA8B332AE457BCD0A3E31CEC47C275C8E99C83125EA3DD9615F2A
7E95271FE2BCFA8F30BFFE7F3F9A1AD63694D4AEB4DE56B8AE68B5CD5A64B395
2DB515C3FF64A1ADA8852C0C10622B2C2A2E59B6BCD4B6A2644559E9F26525C5
4585A4A6B1B10E4E4763638DA3B18696E00A979A3A87A3AEC651E7A86BACC303
8875B8E46C7440D951538374E46562090A0076B8406B236B73D4E07F28047A01
3FF4AEA340754C0EB06017071529A957465076236565CA51CD6A502828E1A052
50305650712A086A40A392EA6A64592B0AC137A02CD8E040B55192036551F56A
50610735167B3B90AD0E6DE03A3A98A5B869CFAFBF69E58DB5B55F2E2ECA77AE
CA2FCA6FB8B9FEE6FC1B1B57ADCB5F7DD39A1B810C3CF7151709813697DFDDD2
19F4E757073CF7BBAD555556BCFA5A17018FE05C2534ACAA59E7742C8611295F
182AB7B6BA3C5E778BD51508B8FD418FAFC3BA6161E00B906C05054BE1FF4DCD
CDF46CF675B47A362DF514972D5F0A28F90C251F600A9A09B9D11DAC09FADAD7
B8DADD35D6452E282EB1069688B881C58BAD0BAAACB66902E8D3E3EFFEA0DF5E
C351D729CFE5782E827A099C7638ABE61272710121AB60F3BA0EEAF7C0E9C7EF
82A1879E84029D8192E68D052D5E2FB9D9B5D925F06945B8C7DDD1EC6B71DB0B
978B330D6194A0FF6F68F0A78774D8BBE4F2895D84C0EE87342A68731E20E499
2E32E97116DAC6E034EE9269B950CE83D30667199C7638EBE1BC1DCE0D707AE1
DC0267379CBD70F6C1B907CE7DBB3E59B93A52D3D282331E4CCCCF923A4F07AF
BCA59A09F1F37A418048F675B8B778F01BFDDD4470FBFD1D3E943142048F6F23
21B3F5AE8D3E7F90D8F4ADADDE50A00DDB56E85B3BFD9E8E602B946FD0B7FADD
6EC8117DBBCB4BBF7C07DDF4EDEEF6E6CEAD58BE1FCB01378A278FE80352BFDD
FA40D0DFDC46B3E3092C7BDD1D581EC07247733BA6DC93ACCC0475C9E7979CEB
D638EB8B8B681AA2BFBA667EB6073637FB83A2A44F8F7FD80356DF6570A9B5AD
B67DD5F675DB93B6576D6FD9DEB75D5EB8A47063A1B7F0E1C2BEC22DA50F973E
573A58FA7AE97BA5996573CAD6953F5C8E6FFBF1B9E6982DADF08B856585FF59
3456942CCA2FBEB3D855FCCDE283C5478BFF547C6DC9C29286926049C372CFF2
CEE5DF59FEF2F213CB3F5ABEA074516943E9F6D2EED2674B874BBFB762DF8A9F
AD38B5E283151FAF98553EB77C45F9CAF2D5E5CDE5EDE53BCAA3E54F961F281F
2C3F59AEAB28ABA8AFB8B542A8F846C5772B7E56F16645A2E24285BE32ABF28A
CA6B2A1757DE53B9B9F26B950F567EABF289CAEF551EA8FC59E5BB951F5692AA
ECAAABAA16542DA92AA9AAAEBAB5CA5F15A9EAA97AACEA77551F545D51FDB9EA
A2EA95D5EBAA3756FBAB1FA87EB8FAC9EA7FAB3E527DB2FAEDEAF7ABF5375C71
43C90DF83B16DCCB74954CEDC2BFE7A3A015D691709D05E745D86D6DD241CA43
E6171634ABF8C47DB90E065EAF4B95C28EAB15BC6C3F880F742D12457005E98C
BA41C7E5C03CCB26D95E8922FE2E8A61412FDD8FE13257AD33FF4D141E7ACA33
815DFC774E923E3AEBA4B6CF916C07C303C1506BABDAF865700EEA26B75DD499
F12096B8CB9F99CE5649E70978B8CE2B249DC5B5977ABC9C4A2C5ADA8092754A
CA0EC27E2F2653FE19F90C4ACA0B4A7D28E524613FF09229EF11F927678C6204
9C61EEB189ACC0E36AA03FA7E73CCC36A0BC6F50526E00CA49A392723750BE94
A6A4E03BCC7115E541A0D4A72B298F03E58E0C25E5191DFBF99BAC33BE78C338
94292F416D9949D9EB1DA054654AD1EBA44B59F25196C823AE7B2F5E2EF2E071
117AADBA2A35C287A568F9D167602FA61E654DB4B4A4FC3670A268E99DADE1F1
CB82E8AA5EF715CD688811554B143340BBCBD39112512650A477EEF459C07810
CBACE5E1EA7419A7CF82BDB3A7CF825B259D61B73B81CEB97A851CD259C036B3
123AAD2D8062FF1476E151023CC373E5594B402C62BB3A754CFB25DB3F80BF97
4F63BBF86C6F2ADB350FC724DBEF926CEF0CB8432DBE7CFA0B4BD90137A25D57
4F3F5E8C07B116493E49D5B9F712C66BF012C62B21E98CD48DAA87A7525E48FA
4C206746FA4CFC8C763390F14E24EE7661DED08BE893CF5A3F009ED3572BE784
41EC355B396FBCAE57684829BFC15E2A9E045076AB78CE43B1EBB39A5942F2C6
3BD0BE641A6F4C102DDC1B92863AAB9687CF1292377447B53CE23D6EDEF4A3D3
7F09A3736E8A68C1E30A838835CD3D57D20767D0B44F441F11CB72ADF87C4423
592B87B05F46E795BEA5139FE673CAB267480AA5A43195B23C57EEC5D1AD3342
3FAB413FA8416FD1A0DB35E8B619A18F6AD05FD2A07B35E8B76BD0ED33423FAD
41DFAB41BF5D839EA7415F3B23F4310DFA2B1AF44E0DFA060DFA8619A1E39D4F
8D7E4683FE750DFA3E0D7AE78CD02D1AF4D31AF48734E87B34E85D33423769D0
4F69D0BB34E8BD1AF4DE19A18F6BC6FD84063DA841F76AD0FB67846ED6D8FE96
06BD5B83DEA741DF3B2374A306FD0D0DFA360D7AB7067D7046E844833EAC41DF
A241DFA2411F9E117A5C33EEFB35E81B34E8651AF4D333423FA341DFA741BF5B
836EFB3F423FA7411FD4A0B769D0EBE55E7C7DF8DF445C1FB6BAEE4582E268EB
70B52349BE57B606DB421DF7C25E8EA45A71EEDA4F7E95C2AD28CA15D175B944
5CCBA5F02CDB23F168B671927FD64EC5C3FD73AD6E72FFFC0D6C2FE99DDEAE65
F1E9794AE78899ABCBD6F2A4DAF51745E62B9AC8EC27A991B92A95B2DCA8C90B
327F26E82F69D0FB34E80E0DFA184945B7CC087D5083BE5B836ED7A09F25A959
593045D4895929CB11B3528125AE60E7FFF5B29290E9B3F251327D56564EC5C3
FD53790959F957B4BDA47E7ABB963D3D3D4FE909317E74974D6AFB2ADDD4CF4E
E71944DBAD53EEAD64FF4CFEECF47FED9FE6A0CF0F5C251296F6090C1E4B0DEC
B928FBBE4BE02FE7D88A487CA6B78687949E88DF80AD074AE57CF1CB4581BDFE
E3FB26B197D7206BC8280F72393A89F22DA088F321A37C1F28E2BC814F9FD8CB
48BB4AF22103FBB7DBE45E3F47C916F6AFBA31CAEF28965541F9D820FFCB6F8C
32D798AACF178DF2FCC328A51A9E9B34943B8022AE4018C56DC47FD94D4909F2
5EB2371E302A3D8FC7BF1853AD380494BD2A39BFD0A0FF5A45A16F7305815264
39EF711E4611F82BD50D2AAFEAD308C95561CD668F182CB21CFAEB65494381BF
E2ED55C9294F5345147FF53BA8E2B93D4D8E70EE31947C95D23F9B8162538D45
3750DE903414F8CB68AB4AF22388AE92F3449ACA3FFCB5F56955AF67553C781C
06CA29A2F4C6BF6BF4F94D1AFB27F8649E0FD3E4151AA398A0784245B98A1765
AF2E06CA2B2A9ED274F6C651A6D4A5A746EF5DFC7359EE67C1DDD1C2C79D5BCA
5FAE77A92CDD942E3EDBA14F77F90BFBB52A9E60BA32BBF1780028832A7DFE09
8AC32ACA13541F8B42C3FDE9A95EFD793AD357E6390594B754727E0FC5831245
609F1EF07D8AA8E1285AA11A654B866A94F907049DAA5EF380E72515D6E20CD6
43D6A786CB9129EB32E4FB3BA3B4701E99B255D3EB311545E01F37F4ABF4F921
F2A8FC7C20435EFBF17CCF489D25DE038A78B76214834969FB9550131C5EEF6A
97A7A3765D6343D0E50F863AED854510FB1E7F2028BE99143AE06E245560DEF0
09817BBCF7089E0EACAF74F91B7D9DB56D2EBFAB39E8F6DFD4D1E2DE52E3F7BB
B6D2A695BE60D0D73E59ABB263439BA735386947656BA36BA3D75DE46B2D2CBE
0934F0B8BC9EFBDD2D755ED726DEB46CC226F65ACADFE0F6B636BA034191BC3A
E40D7A3ABD5B576E0DBA032BB736B46110090ECF664F8B5B4DAB6969A1A5461F
A513A1D6D7B1D9ED0FD6F97DED94D2E8A3C256BA026E55A344957AAE73435BC0
CD05CBAAAE41CDA90D44B8D11D545665A39556225B87DB0F6353BBAEB6B0B0CE
0FEBCEDA3677F3BD0DEEAF86DC1DCDD071B22FCF04E993333106E8C87B64BFF1
B1DEE4F56D74798516BA4C50919A39A9D38DDF520AFE5047D0D3EE16E82B1717
B411E53B987CAF2710846590801F76E267954200D6459E2D2852F5ADA7D0E26E
7581CB8410C45DA71B46BF45CBB309EE142DF71509BE8DF70087D01E82E82CB0
3112985D5048204485D666E15EF7D682225AA1F462AD28D9626C73F38F8EA028
0539351429EB9AD634DEB4DA29AC6D7036396E11D639EB6FA915EA6F6A6884F9
141C030B32C85FC8225A151C8DB7AC935B535021A6DB3D1D3070D814F406141D
BD9E8DEC4323C105F0B89310044F7BA720481F67D94B44129BF44057505FF0B5
A294E67B85665F7BBB87095337F8DD01B77FB39BB6B4BBEEF1F961103606B642
3AB40B18921E5F075316D1B77865A5C46FC428326BF5286DE514766BE1BAD16F
C27859FC4E4B106049AAEC38B94B9D6B1C2A0BDADCAE4EA5650C832DFB440D3A
353A754A3A81BBC15E5F406528086D513A9CCA756D720B1B215F193CC4177243
846CEA68777730E197100922AE7AE08150AB8A0BE61E29EAD03D524F6A41B3A6
2EDB28FA166FDFC28492951FF1D104E77E537CCBC7497C8D2608B88949319731
B025807244293F0B24B5639D5BDDB5AE60739B9BEAA5C47268756C95AC1715C1
8560CAC82B43973922A870841CC64AB7E09D54C4606B404D1EAA27194C44550C
D30D8B68228B0C65F8787D2EB8A708AD702B09C89D54C92246D8BD6E7F87DB8B
739F148B13E71E6BD360A9925F3BAAD3E7914A076962115DC9ACFE1F1A8C4DA8
F95A0000
}

;; [---------------------------------------------------------------------------]
;; [ Bring library into memory and create a name with which to refer to it.    ]
;; [ Define a REBOL procedure which, when called, will call the "USPS4CB"      ]
;; [ procedure in the library.                                                 ]
;; [ So that this script can be run as a demo, a downloaded version of the     ]
;; [ library files was compressed and included in this program.                ]
;; [ Normally, one would download the library from the Post Office and         ]
;; [ read it from disk.                                                        ]
;; [ If we are in demo mode, the program will create a dot-dll file from       ]
;; [ the compressed data.  It seems that the load function must load           ]
;; [ from a file and not from data in memory.                                  ]
;; [---------------------------------------------------------------------------]

IN-DEMO-MODE?: true     ;; change to false for production
if IN-DEMO-MODE? [
    write/binary IMB-LIB-FILE decompress IMB-LIB-DEMO-FILE
]
IMB-LIB: load/library IMB-LIB-FILE

IMB-GEN-CODESTRING: make routine! [
    return: [integer!]
    IMB-TRACKING [string!] 
    IMB-ROUTING [string!]  
    IMB-CODING [string!]
]
    IMB-LIB "USPS4CB"

;; [---------------------------------------------------------------------------]
;; [ Make a test call with the default values, and save all test data          ]
;; [ for possible later use in debugging.                                      ]
;; [---------------------------------------------------------------------------]

IMB-RETURNCODE: IMB-GEN-CODESTRING IMB-TRACKSTRING IMB-ROUTESTRING IMB-BARSTRING
IMB-TEST-RESULT: IMB-RETURNCODE
IMB-TEST-TRACK: IMB-TRACKSTRING
IMB-TEST-ROUTE: IMB-ROUTESTRING
IMB-TEST-BAR:   first second first :IMB-GEN-CODESTRING

;; [---------------------------------------------------------------------------]
;; [ Now define a function that others may use to call the library.            ]
;; [ The caller will have to put values into IMB-TRACKSTRING and               ]
;; [ IMB-ROUTESTRING.                                                          ]
;; [ Does the BarString have to be initialized to 65 spaces?                   ]
;; [---------------------------------------------------------------------------]

IMB-RETURNCODE: 0
IMB-BARSTRING: copy
    "                                                                 "
IMB-ENCODE: does [
    IMB-RETURNCODE: IMB-GEN-CODESTRING IMB-TRACKSTRING IMB-ROUTESTRING IMB-BARSTRING
    IMB-BARSTRING: first second first :IMB-GEN-CODESTRING
]
   
;; [---------------------------------------------------------------------------]
;; [ Normally, one would "do" this module and then have the function called    ]
;; [ IMB-ENCODE available for creating barcode strings.                        ]
;; [ If we are doing a demo, we will print the test data generated above       ]
;; [ just to show that the procedure is working.                               ]
;; [ This code could be taken out altogether if desired, to make things        ]
;; [ look tidier (as could the code for the compressed library file).          ]
;; [---------------------------------------------------------------------------]

if IN-DEMO-MODE? [
    print "Results of initial module test:"
    print ["IMB-TEST-RESULT: " IMB-TEST-RESULT]
    print ["IMB-TEST-TRACK: " IMB-TEST-TRACK]
    print ["IMB-TEST-ROUTE: " IMB-TEST-ROUTE]
    print ["IMB-TEST-BAR: " IMB-TEST-BAR]
    print "View the above results, then enter 'quit' to quit."
    halt
]