From: SMTP%"titandmp@ftp-gw-1.pa.dec.com" 5-SEP-1994 13:59:30.38 To: USRC CC: Subj: v44i051: hp-barcode - barcode print for HP laser, Part01/01 Resent-Date: 5 Sep 1994 11:56:37 -0500 Path: decwrl!spool.mu.edu!howland.reston.ans.net!math.ohio-state.edu!jussieu.fr!univ-lyon1.fr!swidir.switch.ch!newsfeed.ACO.net!Austria.EU.net!EU.net!uunet!sparky!not-for-mail From: Dennis_Taylor@mindlink.bc.ca (Dennis Taylor) Newsgroups: comp.sources.misc Subject: v44i051: hp-barcode - barcode print for HP laser, Part01/01 Followup-To: comp.sources.d Date: 5 Sep 1994 11:56:37 -0500 Organization: MIND LINK! - British Columbia, Canada Lines: 239 Sender: kent@sparky.sterling.com Approved: kent@sparky.sterling.com Message-Id: <34fik5$3m7@sparky.sterling.com> Nntp-Posting-Host: sparky.sterling.com X-Md4-Signature: 4f33517d7e57f2480bb91b8b21dff3be To: unix-sources@pa.dec.com Resent-Message-Id: <"tTfpU1.0.N51.z_qQk"@ftp-gw-1.pa.dec.com> Resent-From: unix-sources@pa.dec.com X-Mailing-List: archive/latest/66 X-Loop: unix-sources@pa.dec.com Precedence: list Resent-Sender: unix-sources-request@pa.dec.com Submitted-by: Dennis_Taylor@mindlink.bc.ca (Dennis Taylor) Posting-number: Volume 44, Issue 51 Archive-name: hp-barcode/part01 Environment: HP Laser barcode print for HP laser The following code produces CODE 39 barcodes on an hp laser. There are several different barcode standards, but these days most barcode readers will read all the major ones. In CODE 39, each character consists of 9 bars, 5 of which are black, and 4 of which are white (the gaps are considered bars). 3 of the 9 are thick bars (thus code 39), and 6 are thin. There is a thin gap between each character. Every bar code starts and ends with an asterisk, which is generally accepted as the delimiter character. The ratio of thick to thin is supposed to be in the range 2:1 to 3:1. i find that 2.5:1 works well. Execute this sample program by typing: barcode DENNIS TAYLOR you will get two barcodes on your laser; if you scan them, I am immortalized. Ok, maybe not. --------------- #! /bin/sh # This is a shell archive. Remove anything before this line, then feed it # into a shell via "sh file" or similar. To overwrite existing files, # type "sh file -c". # Contents: barcode.c # Wrapped by kent@sparky on Mon Sep 5 11:51:21 1994 PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH echo If this archive is complete, you will see the following message: echo ' "shar: End of archive 1 (of 1)."' if test -f 'barcode.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'barcode.c'\" else echo shar: Extracting \"'barcode.c'\" \(5913 characters\) sed "s/^X//" >'barcode.c' <<'END_OF_FILE' X/* X** barcode print for laser X* X* The following code produces CODE 39 barcodes on an hp laser. There are X* several different barcode standards, but these days most barcode readers X* will read all the major ones. X* X* In CODE 39, each character consists of 9 bars, 5 of which are black, and X* 4 of which are white (the gaps are considered bars). 3 of the 9 are thick X* bars (thus code 39), and 6 are thin. there is a thin gap between each X* character. every bar code starts and ends with an asterisk, which is X* generally accepted as the delimiter character. X* X* the ratio of thick to thin is supposed to be in the range 2:1 to 3:1. i X* find that 2.5:1 works well. X* X* execute this sample program by typing: barcode DENNIS TAYLOR X* you will get two barcodes on your laser; if you scan them, I am X* immortalized. ok maybe not. X*/ X X Xstatic int atx; X X/* X** usage: progname word word word ... X*/ Xint main(int argc, char **argv) X{ X int x; X X for(x=1;x < argc;x++){ X PrintThis(argv[x]); X } X exit(0); X} X X X/* X** given an asciiz string, do what's necessary. tack on delimiter '*'s X*/ Xint PrintThis(char *string) X{ X int x; X X PutBars('*'); /* starting delimiter */ X for(x=0;string[x];x++){ X PutBars(string[x]); /* do each char */ X } X PutBars('*'); /* ending delimiter */ X atx += 100; /* big space between complete barcodes */ X} X X/* X** determine the actual thick/thin pattern for the submitted character X*/ Xint PutBars(char c) X{ X switch(c){ X case '0': BarChar("000110100");break; X case '1': BarChar("100100001");break; X case '2': BarChar("001100001");break; X case '3': BarChar("101100000");break; X case '4': BarChar("000110001");break; X case '5': BarChar("100110000");break; X case '6': BarChar("001110000");break; X case '7': BarChar("000100101");break; X case '8': BarChar("100100100");break; X case '9': BarChar("001100100");break; X case '-': BarChar("010000101");break; X case '.': BarChar("110000100");break; X case ' ': BarChar("011000100");break; X case '+': BarChar("010001010");break; X case '%': BarChar("000101010");break; X case '$': BarChar("010101000");break; X case '/': BarChar("010100010");break; X case 'A': X case 'a': BarChar("100001001");break; X case 'B': X case 'b': BarChar("001001001");break; X case 'C': X case 'c': BarChar("101001000");break; X case 'D': X case 'd': BarChar("000011001");break; X case 'E': X case 'e': BarChar("100011000");break; X case 'F': X case 'f': BarChar("001011000");break; X case 'G': X case 'g': BarChar("000001101");break; X case 'H': X case 'h': BarChar("100001100");break; X case 'I': X case 'i': BarChar("001001100");break; X case 'J': X case 'j': BarChar("000011100");break; X case 'K': X case 'k': BarChar("100000011");break; X case 'L': X case 'l': BarChar("001000011");break; X case 'M': X case 'm': BarChar("101000010");break; X case 'N': X case 'n': BarChar("000010011");break; X case 'O': X case 'o': BarChar("100010010");break; X case 'P': X case 'p': BarChar("001010010");break; X case 'Q': X case 'q': BarChar("000000111");break; X case 'R': X case 'r': BarChar("100000110");break; X case 'S': X case 's': BarChar("001000110");break; X case 'T': X case 't': BarChar("000010110");break; X case 'U': X case 'u': BarChar("110000001");break; X case 'V': X case 'v': BarChar("011000001");break; X case 'W': X case 'w': BarChar("111000000");break; X case 'X': X case 'x': BarChar("010010001");break; X case 'Y': X case 'y': BarChar("110010000");break; X case 'Z': X case 'z': BarChar("011010000");break; X default: BarChar("010010100");break; X } X} X X/* X** given the thick/thin map of 9 0's and 1's, order up some rectangles X** of the appropriate sizes and positions X*/ Xint BarChar(char *mapstring) X{ X int x; X int littlebar=8; /* these numbers are arbitrary, as long as Xthe ratio */ X int bigbar=20; /* stays between 2:1 and 3:1 */ X int barsize; X int ysize=75; X X for(x=0;x < 9;x++){ X if(mapstring[x]=='0'){ X /* thin one */ X barsize=littlebar; X } else { X /* thick one */ X barsize=bigbar; X } X if(x%2){ X /* gap - do nothing */ X } else { X /* black bar - draw it */ X DoRectangle(atx,barsize,0,ysize); X } X atx += barsize; /* move over that much */ X } X atx += littlebar; /* gap between each bar code character */ X} X X/* X** low-level hp commands to fill rectangles X*/ Xint DoRectangle(int atx,int xsize,int aty,int ysize) X{ X printf("%c*p%dy%dX",27,aty,atx); /* position */ X printf("%c*c%da%dB",27,xsize,ysize); /* size */ X printf("%c*c0P",27); /* fill */ X} X X END_OF_FILE if test 5913 -ne `wc -c <'barcode.c'`; then echo shar: \"'barcode.c'\" unpacked with wrong size! fi # end of 'barcode.c' fi echo shar: End of archive 1 \(of 1\). cp /dev/null ark1isdone MISSING="" for I in 1 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have the archive. rm -f ark[1-9]isdone else echo You still must unpack the following archives: echo " " ${MISSING} fi exit 0 exit 0 # Just in case...