From:	SMTP%"VMSSERV@kcl.ac.uk" 19-AUG-1996 18:16:44.00
To:	everhart@star.zko.dec.com
CC:	
Subj:	XBIN.31-OF-31

-+-+-+-+-+-+-+-+ START OF PART 31 -+-+-+-+-+-+-+-+
X`09`09&0209`09eof = 2;
X`09`09`09*ip = c;
X`09`09`7D
X`09`09obuf`5B0`5D = (i\0B07<< 2 `7C ibuf`5B1`5D >> 4);
X`09`09obuf`5B1`5D = (i\0B07<< 4 `7C ibuf`5B2`5D >> 2);
X`09`09obuf`5B2`5D = (i\0B07<< 6 `7C ibuf`5B3`5D);
X`09`7D
X`09if ((eof) `26 (op >= `26obuf`5Beof`5D))
X`09`09return EOF;
X`09c = *op++;
X`09if (op >= oend)
X`09`09op = obuf;
X`09return (c `26 BYTEMASK);
X`7D
X
X/*
Xchar tr`5B`5D = "!`5C"#$%`26'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ`5B`60abc
Vdefhijklmpqr";
X`09     0 123456789abcdef0\1010\201F
X`09     0          \0A061\110F2\210F3`20
Xtrlookup is used to translate by direct \2606.  The input character
Xis an index into trlookup.  If the result is 0xFF, a bad char has been read.
XAdded by:  Dan LaLiberte, l\0906@uiucdcs.Uiuc.ARPA, ihnp4!\1907!\2907
X*/
Xchar trlookup`5B83`5D = `7B `090xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
V
X`09`09`090x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0xFF\0606,
X`09`09`090x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0xFF,
X`09`09`090x14, 0x15, 0xFF\0606\0C0C\180D
X`09`09`090x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
X`09`09`090x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0xFF,
X`09`09`090x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0xFF,
X`09`09`090x2C, 0x2D, 0x2E, 0x2F, 0xF\0606\0C0CF,
X`09`09`090x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0xFF,
X`09`09`090x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0xFF\0606,
X`09`09`090x3D, 0x3E, 0x3F `7D;
X
X/* q format -- decode one byte into 6 bit binary */
Xget6bits()
X`7B
X`09register int c;
X`09register int tc;
X
X`09while (1) `7B
X`09`09c = getc(ifp);
X`09`09switch (c) `7B
X`09`09case '`5Cn':
X`09`09case '`5Cr':
X`09`09`09continue;
X`09`09case ':':
X`09`09case EOF:
X`09`09`09return EOF;
X`09`09default:
X`09`09 `09tc = ((c-' ') < 83) ? trlookup`5Bc-' '`5D : 0xff;
X/*`09`09`09fprintf(stderr, "c = '%c'  tc = %4x`5Cn", c, tc); */
X`09`09`09if (tc != 0xff)
X`09`09&0209return (tc);
X`09`09`09fprintf(stderr, "bad char: '%c'`5Cn", c);
X`09`09`09return EOF;
X`09`09`7D
X`09`7D
X`7D
X
X
X#define CRCCONSTANT 0x1021
X
Xcomp_q_crc(c)
Xregister unsigned int c;
X`7B
X`09register int i;
X`09register unsigned long temp = crc;
X
X`09for (i=0; i<8; i++) `7B
X`09`09c <<= 1;
X`09`09if ((temp <<= 1) `26 WORDBIT)
X`09`09`09temp = (temp `26 WORDMASK) `5E CRCCONSTANT;
X`09`09temp `5E= (c >> 8);
X`09`09c `26= BYTEMASK;
X`09`7D
X`09crc = temp;
X`7D
X
X/* old format -- process .hex and .hcx files */
Xdo_o_header(macname, filename)
Xchar *macname, *filename;
X`7B
X`09char namebuf`5B256`5D;`09`09/* big enough for both att `26 bsd */
X`09char ibuf`5BBUFSIZ`5D;
X`09int n;
X
X`09/* set up name for output files */
X`09if (macname`5B0`5D == '`5C0') `7B
X`09`09strcpy(namebuf, filename);
X
X`09`09/* strip directories */
X`09`09macname = search_last(namebuf, '/');
X`09`09if (macname == NULL)
X`09`09`09macname = namebuf;
X`09`09else
X`09`09`09macname++;
X
X`09`09/* strip extension */
X`09`09n = strlen(macname);
X`09`09if (n > 4) `7B
X`09`09    n -= 4;
X`09`09    if (macname`5Bn`5D == '.' `26`26 \1509+1\1706h'
X`09`09&0209`09    `26`26 macname`5Bn+3`5D == 'x')
X`09`09`09    macname`5Bn`5D = '`5C0';
X`09`09`7D
X`09`7D
X`09n = strlen(macname);
X`09if (n > NAMEBYTES)
X`09`09n = NAMEBYTES;
X`09strncpy(mh.m_name, mac\0906n);
X`09mh.m_name`5Bn`5D = '`5C0';
X
X`09/* read "#TYPEAUTH$flag"  line */
X`09if (fgets(ibuf, BUFSIZ, ifp) == NULL) `7B
X`09`09fprintf(stderr, "unexpected EOF`5Cn");
X`09`09exit(2);
X`09`7D
X`09n = strlen(ibuf);
X`09if (n >= 7 `26`26 ibuf`5B0`5D == '#'\1209n-6\1406$') `7B
X`09`09if (n >= 11)
X`09`09`09strncpy(mh.m_type, `26ibuf`5B1`5D, 4);
X`09`09if (n >= 15)
X`09`09`09strncpy(mh.m_author, `26ibuf`5B5`5D, 4);
X`09`09sscanf(`26ibuf`5Bn-5`5D, "%4hx", `26mh.m_flags);
X`09`7D
X`7D
X
Xdo_o_forks()
X`7B
X`09char ibuf`5BBUFSIZ`5D;
X`09int forks = 0, found_crc = 0;
X`09unsigned int calc_crc, file_crc;
X`09extern long make_file();
X
X
X`09crc = 0;`09/* calculate a crc for both forks */
X
X`09/* create empty files ahead of time */
X`09close(creat(files.f_data, 0666));
X`09close(creat(files.f_rsrc, 0666));
X
X`09while (!found_crc `26`26 fgets(ibuf, BUFSIZ, ifp) != NULL) `7B
X`09`09if (forks == 0 `26`26 strncmp(ibuf, "***COMPRESSED", 13) == 0) `7B
X`09`09`09compressed++;
X`09`09`09continue;
X`09`09`7D
X`09`09if (strncmp(ibuf, "***DATA", 7) == 0) `7B
X`09`09`09mh.m_datalen = make_file(files.f_data, compressed);
X`09`09`09forks++;
X`09`09`09continue;
X`09`09`7D
X`09`09if (strncmp(ibuf, "***RESOURCE", 11) == 0) `7B
X`09`09`09mh.m_rsrclen = make_file(files.f_rsrc, compressed);
X`09`09`09forks++;
X`09`09`09continue;
X`09`09`7D
X`09`09if (compressed `26`26 strncmp(ibuf, "***CRC:", 7) == 0) `7B
X`09`09`09found_crc++;
X`09`09`09calc_crc = crc;
X`09`09`09sscanf(`26ibuf`5B7`5D, "%x", `26file_crc);
X`09`09`09break;
X`09`09`7D
X`09`09if (!compressed `26`26 strncmp(ibuf, "***CHECKSUM:", 12) == 0) `7B
X`09`09`09found_crc++;
X`09`09`09calc_crc = crc `26 BYTEMASK;
X`09`09`09sscanf(`26ibuf`5B12`5D, "%x", `26file_crc);
X`09`09`09file_crc `26= BYTEMASK;
X`09`09`09break;
X`09`09`7D
X`09`7D
X
X`09if (found_crc)
X`09`09verify_crc(calc_crc, file_crc);
X`09else `7B
X`09`09fprintf(stderr, "missing CRC`5Cn");
X`09`09exit(3);
X`09`7D
X`7D
X
Xlong
Xmake_file(fname, compressed)
Xchar *fname;
Xint compressed;
X`7B
X`09char ibuf`5BBUFSIZ`5D;
X`09FILE *outf;
X`09register long nbytes = 0L;
X
X`09outf = fopen(fname, "w");
X`09if (outf == NULL) `7B
X`09`09perror(fname);
X`09`09exit(-1);
X`09`7D
X
X`09while (fgets(ibuf, BUFSIZ, ifp) != NULL) `7B
X`09`09if (strncmp(ibuf, "***END", 6) == 0)
X`09`09`09break;
X`09`09if (compressed)
X`09`09`09nbytes += comp_to_bin(ibuf, outf);
X`09`09else
X`09`09`09nbytes += hex_to_bin(ibuf, outf);
X`09`7D
X
X`09fclose(outf);
X`09return nbytes;
X`7D
X
Xcomp_c_crc(c)
Xunsigned char c;
X`7B
X`09crc = (crc + c) `26 WORDMASK;
X`09crc = ((crc << 3) `26 WORDMASK) `7C (crc >> 13);
X`7D
X
Xcomp_e_crc(c)
Xunsigned char c;
X`7B
X`09crc += c;
X`7D
X
X#define SIXB(c) (((c)-0x20) `26 0x3f)
X
Xcomp_to_bin(ibuf, outf)
Xchar ibuf`5B`5D;
XFILE *outf;
X`7B
X`09char obuf`5BBUFSIZ`5D;
X`09register char *ip = ibuf;
X`09register char *op = obuf;
X`09register int n, outcount;
X`09int numread, incount;
X
X`09numread = strlen(ibuf);
X`09ip`5Bnumread-1`5D = ' ';`09`09/* zap out the newline */
X`09outcount = (SIXB(ip`5B0`5D) << 2) `7C\150A1`5D) >> 4);
X`09incount = ((out\0D06/ 3) + 1) * 4;
X`09for (n = numread; n < incount; n++)`09/* restore lost spaces */
X`09`09ibuf`5Bn`5D = ' ';
X
X`09n = 0;
X`09while (n <= outcount) `7B
X`09`09*op++ = SIXB(ip`5B0`5D) << 2 `7C\13091`5D) >> 4;
X`09`09*op++ = SIXB(ip`5B1`5D) << 4 `7C\13092`5D) >> 2;
X`09`09*op++ = SIXB(ip`5B2`5D) << 6 `7C\13093`5D);
X`09`09ip += 4;
X`09`09n += 3;
X`09`7D
X
X`09for (n=1; n <= outcount; n++)
X`09`09comp_c_crc((unsigned)obuf`5Bn`5D);
X
X`09fwrite(obuf+1, 1, outcount, outf);
X`09return outcount;
X`7D
X
Xhex_to_bin(ibuf, outf)
Xchar ibuf`5B`5D;
XFILE *outf;
X`7B
X`09register char *ip = ibuf;
X`09register int n, outcount;
X`09int c;
X
X`09n = strlen(ibuf) - 1;
X`09outcount = n / 2;
X`09for (n = 0; n < outcount; n++) `7B
X`09`09c = hexit(*ip++);
X`09`09comp_e_crc((unsigned)(c = (c << 4) `7C hexit(*ip++)));
X`09`09fputc(c, outf);
X`09`7D
X`09return outcount;
X`7D
X
Xhexit(c)
Xint c;
X`7B
X`09if ('0' <= c `26`26 c <= '9')
X`09`09return c - '0';
X`09if ('A' <= c `26`26 c <= 'F')
X`09`09return c - 'A' + 10;
X
X`09fprintf(stderr, "illegal hex digit: %c", c);
X`09exit(4);
X`09/* NOTREACHED */
X`7D
X
Xput2(bp, value)
Xchar *bp;
Xshort value;
X`7B
X`09*bp++ = (value >> 8) `26 BYTEMASK;
X`09*bp++ = value `26 BYTEMASK;
X`7D
X
Xput4(bp, value)
Xchar *bp;
Xlong value;
X`7B
X`09register int i, c;
X
X`09for (i = 0; i < 4; i++) `7B
X`09`09c = (value >> 24) `26 BYTEMASK;
X`09`09value <<= 8;
X`09`09*bp++ = c;
X`09`7D
X`7D
$ call unpack [.XBIN.SRC]XBIN.C_ORIG;1 -
 740955909 "FORMAT STREAM_LF;CARRIAGE_CONTROL CARRIAGE_RETURN" 38 13 16
$!
$ create 'f'
X`03`01`00`00`81%`EC`0D`03&0200`00`17VAX-11 Librarian V04-00&0300&0300&0200`A0
V`1C`BB9`15N`9A`00 7`C19`15N`9A`00\1808\2008`0B&0300D`01`0C&0300`04&0300`03
V&0300`06&0300`02&0300`01&0200`00`01&0200`00`01&0300\0E06&0400`14\4211\5311
V\2222&03005`00`10`00`02&0300\4F47\4A4A\9494\FF0F
X`0B`00`00&0200&0400&0300`07&0300`06`00`04XBIN\160B\210B\1616\2C2C\5858\B0B0
V\FF89
X`04`00`00&0200&0400\0808\1010\2020\4040\8080\FFFF
X`05`00`00&0200&0400\0808\1010\2020\4040\8080\FFFF
X`06`00`00&0200&0400\0808\1010\2020\4040\8080\FFFF
X`00`00&0200&0400\0808\1010\2020\4040\8080\FFFF`00
X`12`00`08`00`00`00`10&0200`AD&0200`01&0300 7`C19`15N`9A`00`06`001 XBIN&0200+
V`00Convert mailable format BinHex into binary.&0300`06`00Syntax&0200)`00     x
Vbin `5B-o`5D `5B-v`5D `5B-l`5D `5B-n`5D `5Bname`5D file&0300`0D`002 Descriptio
Vn&0300E`00XBIN c\7F06s a file created by\8208(usually named with one of the`00
VB`00extensions ".hex", ".hcx", or ".hqx")\C906three host-system files3`00suit
V\FE08 downloading to a Macintosh via macput.&0300@`00This program is designed
V for use with the 1.1 Release version ofC`00MacTerminal, but includes a compat
Vibility option for the old -0.15X`00`15`00Almost-Alpha \5F07.`00
X`15`00`09`00`00&0200`00`09`002 Options&0300"`00Use these o\1606 to control XBI
VN.&0200`04`003 -l&0200D`00The -l (list)\3207 reads the header information and
V prints out allC`00the useful \2B0Cthere, without creating any converted outpu
Vt`00`06`00files\9E08v&0200E`00The  -v (verbose\A209\8107a line for each file t
Vo be \6009,`00+`00indic\7C06the input and \7C06\3806names.&0200\8006n&0200B`00
VThe -n name\7A08allows \F207r to specify the name to use whenE`00\F609the hos
V\6E06s and the eventual\3B0Don the mac. This`008`00\FA07must prec
X`0B`00`0A`00`00`00ede the input file name it is to affect.&0200E`00If this opt
Vion is not used, the names will be derived from either the`00@`00\6C10(.hex or
V .hcx files), or \5508 encoded in theE`00header information (.hq\3D08. Spaces
V and slashe\980Aconverted`00A`00to underscores, and the .h?x extension \D30Ale
Vted, if one is`00 `00inclu\9D0A in\DE0D.`00`00@`00A\EE0Bof "-" indicates that
V\3A0Bshould be taken fromC`00stdin. If no mac\510Bis specified, the default na
Vme (for .hex`00`1A`00or .hcx file
X`14`00`0B`00`00`00s) is "stdin".&0200D`00Mail or news headers and signatures n
Veed not be manually stripped --6`00xbin will ignore pretty much anything it do
Vesn't need.&0200:\3A06creates three host-system files from each input file:`0F
V`00   name .info ,`00\120Bdata ,`00`03`00and\180Crsrc .&0200`00`04`003 -o&0200
V8`00The -o flag specifies "old" (version -0.15X) MacTerminal`13`00compatibilit
Vy mode.&0300`06`002 BUGS&0200E`00The "LOCKED" bit in the flags cannot be set b
Vy xbin. This is due to a`00B`00bug in \7E0B, which sets \530Awhe\6207ile is cr
Veated,
X`0B`00`00&0200`00C`00rather than after it has been transfered, resulting in it
V not being`00`17`00able to write the file.&0300D`00Input files must contain a
V line starting with "(This file" to detect(`00the beginning of the BinHex info
Vrmation.&0200`08`002 AUTHOR&0200`1D`00Dave Johnson, Brown 12/16/84;`006`00CRC
V handling code by Darin Adler, TMQ Software 3/16/85`03`00w`00w&0300&0300\0606
V\0C0C\1818\3030\605D
$ call unpack [.XBIN.SRC]XBIN.HLB;1 -
 1773176669 "FORMAT FIX;SIZE 512;CARRIAGE_CONTROL NONE" 12 14 16
$!
$ create 'f'
X1 XBIN
X
XConvert mailable format BinHex into binary.
X
XSyntax
X
X     xbin `5B-o`5D `5B-v`5D `5B-l`5D `5B-n`5D `5Bname`5D file
X
X2 Description
X
XXBIN converts a file created by BinHex (usually named with one of the
Xextensions ".hex", ".hcx", or ".hqx") into three host-system files
Xsuitable for downloading to a Macintosh via macput.
X
XMail or news headers and signatures need not be manually stripped --
Xxbin will ignore pretty much anything it doesn't need.
X
XXBIN creates three host-system files from each input file. With a
Xfilename of   name.ext, the three files become (due to VMS naming
Xconventions):
X   name.ext_info ,   \130Adata , and\290Crsrc .
X
XFor example, if the input file is BT.SEA, the out\1B08s are:
X   BT.SEA_INFO,\0F0ADATA,  and  BT.EA_RSRC
X
XThis program is designed for use with the 1.1 Release version of
XMacTerminal, but includes a compatibility option for the old -0.15X
XAlmost-Alpha version.
X
X2 Options
X
XUse these options to control XBIN.
X
X3 -l
X
XThe -l (list) option reads the header information and prints out all
Xthe useful information there, without creating any converted output
Xfiles.
X
X3 -v
X
XThe  -v (verbose) option prints a line for each file to be converted,
Xindicating the input and output file names.
X
X3 -n
X
XThe -n name option allows the user to specify the name to use when
Xcreating the host files and the eventual name to use on the mac. This
Xoption must precede the input file name it is to affect.
X
XIf this option is not used, the names will be derived from either the
Xinput file name (.hex or .hcx files), or the\2206encoded in the
Xheader information (.hqx files). Spaces and slashes will be converted
Xto underscores, and the .h?x extension will be deleted, if one is
Xincluded in the input file name.
X
XA file name of "-" indicates that the input should be taken from
Xstdin. If no mac file name is specified, the default\1F06(for .hex
Xor .hcx files) is "stdin".
X
X3 -o
X
XThe -o flag specifies "old" (version -0.15X) MacTerminal
Xcompatibility mode.
X
X2 BUGS
X
XThe "LOCKED" bit in the flags cannot be set by xbin. This is due to a
Xbug in MacTerminal, which sets the flags when the file is created,
Xrather than after it has been transfered, resulting in it not being
Xable to write the file.
X
XInput files must contain a line starting with "(This file" to detect
Xthe beginning of the BinHex information.
X
X2 AUTHOR
X
XDave Johnson, Brown 12/16/84;
XCRC handling code by Darin Adler, TMQ Software 3/16/85
$ call unpack [.XBIN.SRC]XBIN.HLP;3 -
 827396707 "FORMAT STREAM_LF;CARRIAGE_CONTROL CARRIAGE_RETURN" 6 15 16
$!
$ create 'f'
X.TH XBIN local "24 Mar 1985"
X.UC 4
X.SH NAME
Xxbin `5C- convert mailable format BinHex file into binary before downloading
Xto MacTerminal
X.SH SYNOPSIS
X.B xbin
X`5B
X.B `5C-o
X`5D
X`5B
X.B `5C-v
X`5D
X`5B
X.B `5C-l
X`5D
X`5B`5B
X.B `5C-n
Xname
X`5D file`5D ...
X.SH DESCRIPTION
X.I Xbin
Xconverts a file created by BinHex (usually
Xnamed with one of the extensions ".hex", ".hcx", or ".hqx")
Xinto three host-system files suitable for downloading to a
XMacintosh via macput.
XThis program is designed for use with the 1.1 Release
Xversion of MacTerminal, but includes a compatibility option for the
Xold -0.15X Almost-Alpha version.
X.PP
XThe
X.B -l
X(list) option reads the header information and
Xprints out all the useful information there,
Xwithout creating any converted output files.
X.PP
XThe
X.B -v
X(verbose) option prints a line for each file to be converted, indicating
Xthe input and output file names.
X.PP
XThe
X.B -n
Xname
Xoption allows the user to specify the name to use when creating
Xthe host files and the eventual name to use on the mac.
XThis option must precede the input file name it is to affect.
X.PP
XIf this option is not used, the names will be derived from
Xeither the input file name (.hex or .hcx files),
Xor the name encoded in the header information (.hqx files).
XSpaces and slashes will be converted to underscores, and
Xthe .h?x extension will be deleted, if one is included in the
Xinput file name.
X.PP
XA file name of "-" indicates that the input should be taken from stdin.
XIf no mac file name is specified, the default\1F06(for .hex or .hcx files)
Xis "stdin".
X.PP
XMail or news headers and signatures need not be manually
Xstripped -- xbin will ignore pretty much anything
Xit doesn't need.
X.PP
X.I xbin
Xcreates three host-system files from each input file:
X.IB name .info ,
X.IB name .data ,
Xand
X.IB name .rsrc .
X.PP
XThe
X.B `5C-o
Xflag specifies "old" (version -0.15X) MacTerminal compatibility mode.
X.SH BUGS
XThe "LOCKED" bit in the flags cannot be set by xbin.
XThis is due to a bug in MacTerminal, which sets the flags
Xwhen the file is created, rather than after it has been
Xtransfered, resulting in it not being able to write the
Xfile.
X.PP
XInput files must contain a line starting with "(This file"
Xto detect the beginning of the BinHex information.
X.SH SEE ALSO
Xmacput(1), macget(1)
X.SH AUTHOR
XDave Johnson, Brown 12/16/84;
XCRC handling code by Darin Adler, TMQ Software 3/16/85
$ call unpack [.XBIN.SRC]XBIN.L;1 -
 673697729 "FORMAT STREAM_LF;CARRIAGE_CONTROL CARRIAGE_RETURN" 5 16 16
$ v=f$verify(v)
$ exit
================== RFC 822 Headers ==================
Return-Path: VMSSERV@kcl.ac.uk
Received: by galaxy.zko.dec.com (UCX V4.0-10B, OpenVMS V6.2 VAX);
	Mon, 19 Aug 1996 18:16:38 -0400
Received: from newt.kcl.ac.uk by mail11.digital.com (8.7.5/UNX 1.2/1.0/WV)
	id SAA14765; Mon, 19 Aug 1996 18:04:53 -0400 (EDT)
Received: from bay.cc.kcl.ac.uk by newt.kcl.ac.uk with SMTP (PP) 
          id <23403-0@newt.kcl.ac.uk>; Mon, 19 Aug 1996 23:04:29 +0100
Received: by alder.cc.kcl.ac.uk (MX V4.2 AXP) id 735;
          Mon, 19 Aug 1996 23:04:48 EDT
Date: Mon, 19 Aug 1996 23:04:34 BST
From: Kings College London File Server <VMSSERV@kcl.ac.uk>
To: everhart@star.zko.dec.com
Message-ID: <009A71AB.40206E60.735@alder.cc.kcl.ac.uk>
Subject: XBIN.31-OF-31
