home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
aufstols.zoo
/
aufstools.2
< prev
next >
Wrap
Text File
|
1991-02-26
|
45KB
|
1,251 lines
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 2 (of 4)."
# Contents: capit/capit.c mcvert/mactypes.h mcvert/mcvert.1
# mcvert/unpack.c stuffit/updcrc.c unstuffit/updcrc.c
# Wrapped by np@asun5 on Mon Dec 3 13:15:56 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'capit/capit.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'capit/capit.c'\"
else
echo shar: Extracting \"'capit/capit.c'\" \(8984 characters\)
sed "s/^X//" >'capit/capit.c' <<'END_OF_FILE'
X/* unmacbin - reverse of macbin - change a MacBinary file back in to
X the .info .data .rsrc style that xbin, macput and macget understand.
X Stole some from macbin. */
X
X/* Written by John M. Sellens, jmsellens@watdragon.uwaterloo.ca,
X Math Faculty Computing Facility,
X University of Waterloo
X Waterloo, Ontario, Canada
X N2L 3G1 */
X
X/* capit - convert a macbin file into a CAP file on a CAP Unix Mac disc.
X Basically:
X file.data => file
X file.rsrc => .resource/file
X file.info => mangle it then .finderinfo/file
X
X Nigel Perry, Dept of Computing, Imperial College, London SW7 2BZ, England. July 90.
X np@doc.ic.ac.uk
X */
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/dir.h>
X#include <strings.h>
X
X#define BSIZE (128) /* size of blocks in MacBinary file */
Xtypedef long int4;
X
X
X/* following from mcvert program */
X
X/* Useful, though not particularly Mac related, values */
Xtypedef unsigned char byte; /* one byte, obviously */
Xtypedef unsigned short word; /* must be 2 bytes */
Xtypedef unsigned long ulong; /* 4 bytes */
X
X#define NAMELEN 63 /* maximum legal Mac file name length */
X
X/* Format of a bin file:
XA bin file is composed of 128 byte blocks. The first block is the
Xinfo_header (see below). Then comes the data fork, null padded to fill the
Xlast block. Then comes the resource fork, padded to fill the last block. A
Xproposal to follow with the text of the Get Info box has not been implemented,
Xto the best of my knowledge. Version, zero1 and zero2 are what the receiving
Xprogram looks at to determine if a MacBinary transfer is being initiated.
X*/
Xtypedef struct { /* info file header (128 bytes). Unfortunately, these
X longs don't align to word boundaries */
X byte version; /* there is only a version 0 at this time */
X byte nlen; /* Length of filename. */
X byte name[NAMELEN]; /* Filename (only 1st nlen are significant)*/
X byte type[4]; /* File type. */
X byte auth[4]; /* File creator. */
X byte flags; /* file flags: LkIvBnSyBzByChIt */
X byte zero1; /* Locked, Invisible,Bundle, System */
X /* Bozo, Busy, Changed, Init */
X byte icon_vert[2]; /* Vertical icon position within window */
X byte icon_horiz[2]; /* Horizontal icon postion in window */
X byte window_id[2]; /* Window or folder ID. */
X byte protect; /* = 1 for protected file, 0 otherwise */
X byte zero2;
X byte dflen[4]; /* Data Fork length (bytes) - most sig. */
X byte rflen[4]; /* Resource Fork length byte first */
X byte cdate[4]; /* File's creation date. */
X byte mdate[4]; /* File's "last modified" date. */
X byte ilen[2]; /* GetInfo message length */
X byte flags2; /* Finder flags, bits 0-7 */
X byte unused[14];
X byte packlen[4]; /* length of total files when unpacked */
X byte headlen[2]; /* length of secondary header */
X byte uploadvers; /* Version of MacBinary II that the uploading program is written for */
X byte readvers; /* Minimum MacBinary II version needed to read this file */
X byte crc[2]; /* CRC of the previous 124 bytes */
X byte padding[2]; /* two trailing unused bytes */
X } info_header;
X
X/* end of mcvert stuff */
X/* from CAP aufs documentation */
X
X#define FINFOLEN 32
X#define MAXCLEN 199
Xtypedef struct
X{ /* byte fi_fndr[FINFOLEN]; */ /* finder info */
X /* what I think the above is... */
X ulong fndr_type, fndr_creator;
X word fndr_flags;
X ulong fndr_loc;
X word fndr_fldr;
X word fndr_icon;
X byte fndr_unused[8];
X word fndr_comment;
X ulong fndr_putaway;
X /* end of fi_fndr */
X
X word fi_attr; /* attributes */
X#define FI_MAGIC1 255
X byte fi_magic1; /* was: length of comment */
X#define FI_VERSION 0x10 /* version major 1, minor 0 */
X /* if more than 8 versions then */
X /* something wrong anyway */
X byte fi_version; /* version number */
X#define FI_MAGIC 0xda
X byte fi_magic; /* magic word check */
X byte fi_bitmap; /* bitmap of included info */
X#define FI_BM_SHORTFILENAME 0x1 /* is this included? */
X#define FI_BM_MACINTOSHFILENAME 0x2 /* is this included? */
X byte fi_shortfilename[12+1]; /* possible short file name */
X byte fi_macfilename[32+1]; /* possible macintosh file name */
X byte fi_comln; /* comment length */
X byte fi_comnt[MAXCLEN+1]; /* comment string */
X} FileInfo;
X
X/* end aufs */
X
Xstatic info_header info;
Xstatic FileInfo fndr_info;
X
Xstatic union trans {
X int4 num;
X char ch[4];
X} trans;
X
X
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
X FILE *fp, *ofp;
X char bname[MAXNAMLEN];
X char iname[MAXNAMLEN];
X char dname[MAXNAMLEN];
X char rname[MAXNAMLEN];
X char buf[BSIZE];
X char * charp;
X int verbose = 0;
X int len;
X int arg;
X int err = 0;
X long dflen, rflen;
X char *ext, *disc;
X extern char *getenv();
X
X if((ext = getenv("MAC_EXT")) == NULL) ext = ".bin";
X if((disc = getenv("MAC_DISC")) == NULL) disc = ".";
X
X arg = 1;
X if (argc > 1 && strcmp(argv[1], "-v") == 0 ) {
X verbose = 1;
X ++arg;
X }
X if ( arg >= argc ) {
X fprintf(stderr,"%s: Usage: %s [-v] filename(s)\n",argv[0],argv[0]);
X exit(1);
X }
X for ( ; arg < argc; arg++ ) {
X if ( (charp = rindex (argv[arg], '.')) != NULL
X && strcmp(charp, ext) == 0 ) {
X *charp = '\0';
X strcpy(bname, argv[arg]);
X *charp = '.';
X } else
X strcpy(bname, argv[arg]);
X
X sprintf(iname, "%s/.finderinfo/%s", disc, bname);
X sprintf(dname, "%s/%s", disc, bname);
X sprintf(rname, "%s/.resource/%s", disc, bname);
X
X if (verbose)
X printf( "Converting '%s'\n", argv[arg] );
X if ( (fp = fopen( argv[arg], "r" )) == NULL ) {
X fprintf( stderr, "%s: couldn't open '%s' for reading",
X argv[0], argv[arg] );
X perror( "" );
X exit(++err);
X }
X if ( fread(&info, sizeof(info), 1, fp) <= 0 ) {
X fprintf( stderr, "%s: couldn't read .info header from '%s'",
X argv[0], argv[arg] );
X perror( "" );
X exit(++err);
X }
X if ( info.zero1 || info.zero2 || info.version ) {
X fprintf( stderr, "%s: '%s' is not in MacBinary format - skipped\n",
X argv[0], argv[arg] );
X ++err;
X continue;
X }
X
X /* make the .finderinfo file */
X bzero(&fndr_info, sizeof(FileInfo));
X bcopy(info.type, &fndr_info.fndr_type, 4);
X bcopy(info.auth, &fndr_info.fndr_creator, 4);
X if(info.protect == '\1' ) fndr_info.fndr_flags = 0x40; /* maybe? */
X fndr_info.fi_magic1 = FI_MAGIC1;
X fndr_info.fi_version = FI_VERSION;
X fndr_info.fi_magic = FI_MAGIC;
X fndr_info.fi_bitmap = FI_BM_MACINTOSHFILENAME;
X bcopy(info.name, fndr_info.fi_macfilename, info.nlen);
X
X /* write the .finderinfo file */
X if ( (ofp = fopen( iname, "w" )) == NULL ) {
X fprintf( stderr, "%s: couldn't open '%s' for writing",
X argv[0], iname );
X perror( "" );
X exit(++err);
X }
X fwrite( &fndr_info, sizeof(FileInfo), 1, ofp );
X fclose( ofp );
X
X /* It appears that the .data and .rsrc parts of the MacBinary file
X are padded to the nearest 128 (BSIZE) byte boundary, but they
X should be trimmed to their proper size when we split them. */
X
X trans.ch[0] = info.dflen[0]; trans.ch[1] = info.dflen[1];
X trans.ch[2] = info.dflen[2]; trans.ch[3] = info.dflen[3];
X dflen = ntohl( trans.num );
X trans.ch[0] = info.rflen[0]; trans.ch[1] = info.rflen[1];
X trans.ch[2] = info.rflen[2]; trans.ch[3] = info.rflen[3];
X rflen = ntohl( trans.num );
X
X /* write the data fork */
X if ( (ofp = fopen( dname, "w" )) == NULL ) {
X fprintf( stderr, "%s: couldn't open '%s' for writing",
X argv[0], dname );
X perror( "" );
X exit(++err);
X }
X for ( len=0; len<dflen; ) {
X if ( fread( buf, sizeof(char), BSIZE, fp ) != BSIZE ) {
X fprintf( stderr, "%s: couldn't read %d bytes from '%s'",
X argv[0], BSIZE, argv[arg] );
X fprintf(stderr,"got %d of %d'n",len,dflen);
X perror( "" );
X exit(++err);
X }
X len += BSIZE;
X if ( len > dflen )
X fwrite( buf, sizeof(char), BSIZE-len+dflen, ofp );
X else
X fwrite( buf, sizeof(char), BSIZE, ofp );
X }
X fclose( ofp );
X
X /* write the .resource file */
X if ( (ofp = fopen( rname, "w" )) == NULL ) {
X fprintf( stderr, "%s: couldn't open '%s' for writing",
X argv[0], rname );
X perror( "" );
X exit(++err);
X }
X for ( len=0; len<rflen; ) {
X if ( fread( buf, sizeof(char), BSIZE, fp ) != BSIZE ) {
X fprintf( stderr, "%s: couldn't read %d bytes from '%s'",
X argv[0], BSIZE, argv[arg] );
X fprintf(stderr,"got %d of %d'n",len,rflen);
X perror( "" );
X exit(++err);
X }
X len += BSIZE;
X if ( len > rflen )
X fwrite( buf, sizeof(char), BSIZE-len+rflen, ofp );
X else
X fwrite( buf, sizeof(char), BSIZE, ofp );
X }
X fclose( ofp );
X fclose( fp );
X }
X exit( err );
X}
END_OF_FILE
if test 8984 -ne `wc -c <'capit/capit.c'`; then
echo shar: \"'capit/capit.c'\" unpacked with wrong size!
fi
# end of 'capit/capit.c'
fi
if test -f 'mcvert/mactypes.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'mcvert/mactypes.h'\"
else
echo shar: Extracting \"'mcvert/mactypes.h'\" \(7478 characters\)
sed "s/^X//" >'mcvert/mactypes.h' <<'END_OF_FILE'
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/dir.h>
X#include <sys/stat.h>
X#include <sys/timeb.h>
X
X/* Useful, though not particularly Mac related, values */
Xtypedef unsigned char byte; /* one byte, obviously */
Xtypedef unsigned short word; /* must be 2 bytes */
Xtypedef unsigned long ulong; /* 4 bytes */
X#define TRUE 1
X#define FALSE 0
X#define CR 0x0d
X#define LF 0x0a
X
X/* Compatibility issues */
X#ifdef BSD
X#define mac2word (word) ntohs
X#define mac2long (ulong) ntohl
X#define word2mac (word) htons
X#define long2mac (ulong) htonl
X#else
X#define mac2word
X#define mac2long
X#define word2mac
X#define long2mac
X#endif
X
X#ifdef MAXNAMLEN/* 4.2 BSD, stdio.h */
X#define SYSNAMELEN MAXNAMLEN
X#else
X#define SYSNAMELEN DIRSIZ
X#endif
X
X#define NAMELEN 63 /* maximum legal Mac file name length */
X#define BINNAMELEN 68 /* NAMELEN + len(".bin\0") */
X
X/* Format of a bin file:
XA bin file is composed of 128 byte blocks. The first block is the
Xinfo_header (see below). Then comes the data fork, null padded to fill the
Xlast block. Then comes the resource fork, padded to fill the last block. A
Xproposal to follow with the text of the Get Info box has not been implemented,
Xto the best of my knowledge. Version, zero1 and zero2 are what the receiving
Xprogram looks at to determine if a MacBinary transfer is being initiated.
X*/
Xtypedef struct { /* info file header (128 bytes). Unfortunately, these
X longs don't align to word boundaries */
X byte version; /* there is only a version 0 at this time */
X byte nlen; /* Length of filename. */
X byte name[NAMELEN]; /* Filename (only 1st nlen are significant)*/
X byte type[4]; /* File type. */
X byte auth[4]; /* File creator. */
X byte flags; /* file flags: LkIvBnSyBzByChIt */
X byte zero1; /* Locked, Invisible,Bundle, System */
X /* Bozo, Busy, Changed, Init */
X byte icon_vert[2]; /* Vertical icon position within window */
X byte icon_horiz[2]; /* Horizontal icon postion in window */
X byte window_id[2]; /* Window or folder ID. */
X byte protect; /* = 1 for protected file, 0 otherwise */
X byte zero2;
X byte dlen[4]; /* Data Fork length (bytes) - most sig. */
X byte rlen[4]; /* Resource Fork length byte first */
X byte ctim[4]; /* File's creation date. */
X byte mtim[4]; /* File's "last modified" date. */
X byte ilen[2]; /* GetInfo message length */
X byte flags2; /* Finder flags, bits 0-7 */
X byte unused[14];
X byte packlen[4]; /* length of total files when unpacked */
X byte headlen[2]; /* length of secondary header */
X byte uploadvers; /* Version of MacBinary II that the uploading program is written for */
X byte readvers; /* Minimum MacBinary II version needed to read this file */
X byte crc[2]; /* CRC of the previous 124 bytes */
X byte padding[2]; /* two trailing unused bytes */
X } info_header;
X
X/* The *.info file of a MacTerminal file transfer either has exactly this
Xstructure or has the protect bit in bit 6 (near the sign bit) of byte zero1.
XThe code I have for macbin suggests the difference, but I'm not so sure */
X
X/* Format of a hqx file:
XIt begins with a line that begins "(This file
Xand the rest is 64 character lines (except possibly the last, and not
Xincluding newlines) where the first begins and the last ends with a colon.
XThe characters between colons should be only from the set in tr86, below,
Xeach of which corresponds to 6 bits of data. Once that is translated to
X8 bit bytes, you have the real data, except that the byte 0x90 may
Xindicate, if the following character is nonzero, that the previous
Xbyte is to be repeated 1 to 255 times. The byte 0x90 is represented by
X0x9000. The information in the file is the hqx_buf (see below),
Xa CRC word, the data fork, a CRC word, the resource fork, and a CRC word.
XThere is considerable confusion about the flags. An official looking document
Xunclearly states that the init bit is always clear, as is the following byte.
XThe experience of others suggests, however, that this is not the case.
X*/
X
X#define HQXLINELEN 64
Xtypedef struct {
X byte version; /* there is only a version 0 at this time */
X byte type[4]; /* File type. */
X byte auth[4]; /* File creator. */
X byte flags; /* file flags: LkIvBnSyBzByChIt */
X byte protect; /* ?Pr??????, don't know what ? bits mean */
X byte dlen[4]; /* Data Fork length (bytes) - most sig. */
X byte rlen[4]; /* Resource Fork length byte first */
X byte bugblank; /* to fix obscure sun 3/60 problem
X that always makes sizeof(hqx_header
X even */
X } hqx_header;
Xtypedef struct { /* hqx file header buffer (includes file name) */
X byte nlen; /* Length of filename. */
X byte name[NAMELEN]; /* Filename: only nlen actually appear */
X hqx_header all_the_rest;/* and all the rest follows immediately */
X } hqx_buf;
X
X/* Format of a Packit file:
XRepeat the following sequence for each file in the Packit file:
X 4 byte identifier ("PMag" = not compressed, "Pma4" = compressed)
X 320 byte compression data (if compressed file)
X = preorder transversal of Huffman tree
X 255 0 bits corresponding to nonleaf nodes
X 256 1 bits corresponding to leaf nodes
X 256 bytes associating leaf nodes with bytes
X 1 completely wasted bit
X 92 byte header (see pit_header below) *
X 2 bytes CRC word for header *
X data fork (length from header) *
X resource fork (length from header) *
X 2 bytes CRC word for forks *
X
XLast file is followed by the 4 byte Ascii string, "Pend", and then the EOF.
XThe CRC calculations differ from those in the binhex format.
X
X* these are in compressed form if compression is on for the file
X
X*/
X
Xtypedef struct { /* Packit file header (92 bytes) */
X byte nlen; /* Length of filename. */
X byte name[NAMELEN]; /* Filename (only 1st nlen are significant)*/
X byte type[4]; /* File type. */
X byte auth[4]; /* File creator. */
X byte flags; /* file flags: LkIvBnSyBzByChIt */
X byte zero1;
X byte protect; /* = 1 for protected file, 0 otherwise */
X byte zero2;
X byte dlen[4]; /* Data Fork length (bytes) - most sig. */
X byte rlen[4]; /* Resource Fork length byte first */
X byte ctim[4]; /* File's creation date. */
X byte mtim[4]; /* File's "last modified" date. */
X } pit_header;
X
X/* types for constructing the Huffman tree */
Xtypedef struct branch_st {
X byte flag;
X struct branch_st *one, *zero;
X } branch;
X
Xtypedef struct leaf_st {
X byte flag;
X byte data;
X } leaf;
END_OF_FILE
if test 7478 -ne `wc -c <'mcvert/mactypes.h'`; then
echo shar: \"'mcvert/mactypes.h'\" unpacked with wrong size!
fi
# end of 'mcvert/mactypes.h'
fi
if test -f 'mcvert/mcvert.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'mcvert/mcvert.1'\"
else
echo shar: Extracting \"'mcvert/mcvert.1'\" \(5991 characters\)
sed "s/^X//" >'mcvert/mcvert.1' <<'END_OF_FILE'
X.TH MCVERT LOCAL "May 5, 1987"
X.UC 4.2
X.SH NAME
Xmcvert \- BinHex 4.0 to MacBinary file conversion utility
X.SH SYNOPSIS
X.B mcvert
X[-options] name... [[-options] name...]...
X.br
X.SH DESCRIPTION
XThe
X.I mcvert
Xprogram translates MacIntosh files from one format to another.
XThe primary formats in which MacIntosh files are represented on non-Macs are:
X.TP
X.B MacBinary:
XAn eight bit wide representation of the data and resource forks of a Mac
Xfile and of relevant Finder information, MacBinary files are recognized
Xas "special" by several MacIntosh terminal emulators. These emulators,
Xusing Kermit or Xmodem or any other file transfer protocol, can separate
Xthe incoming file into forks and appropriately modify the Desktop to display
Xicons, types, creation dates, and the like.
X.TP
X.B BinHex 4.0:
XA seven bit wide representation of a Mac file with CRC error checking,
XBinHex 4.0 files are designed for communication of Mac files over long
Xdistance, possibly noisy, seven bit wide paths.
X.TP
X.B PackIt:
XPackIt files are actually representations of collections of Mac files, possibly
XHuffman compressed. Packing many small related files together before
Xa MacBinary transfer or a translation to BinHex 4.0 is common practice.
X.TP
X.B Text:
XA MacIntosh ends each line of a plain text file with a carriage return
Xcharacter (^M), rather than the newline character (^J) that some systems
Xseem to prefer. Moreover, a MacBinary file has prepended Finder information
Xthat non-MacIntoshes don't need.
X.TP
X.B Data, Rsrc:
XA Data or Rsrc file is the exact copy of the data or resource fork of a
XMacIntosh file.
X.PP
XIt is the purpose of this program to convert to the MacBinary format
Xfiles in other of the above formats, and vice versa.
X.PP
X.SH PARAMETERS
XExactly one of the following operations may be specified for an input name:
X.TP
X.B x
XBinHex 4.0 - files in the MacBinary format are translated to BinHex
Xfiles, or vice versa. The name argument may be the name of a file to be
Xconverted or a basename to which an appropriate suffix must be appended
Xto get a filename. If the conversion is from Binhex 4.0 to MacBinary,
Xseveral files may comprise the BinHex representation of the Mac file.
XRather than manually concatenate the files and manually delete mail
Xheaders and other extraneous garbage, one may specify the names of the
Xfiles in order and
X.I mcvert
Xwill do the concatenating and deleting. Conversely, in converting
Xa MacBinary file to BinHex 4.0 format for mailing over long distances,
Xone may be restricted to mail messages of no greater that some fixed
Xlength. In this case,
X.I mcvert
Xcan automatically divide the BinHex file into pieces and label each
Xpiece appropriately.
XOption 'x' is selected by default.
X.TP
X.B r
XResource - files in the MacBinary format with empty data forks
Xand nonempty resource forks are made from ordinary data files, or vice versa.
X.TP
X.B d
XData - files in the MacBinary format with nonempty data forks
Xand empty resource forks are made from ordinary data files, or vice versa.
X.TP
X.B u
XText - files in the MacBinary format with nonempty data forks
Xand empty resource forks are made from ordinary data files, or vice versa.
XUnix newline
Xcharacters are interchanged with MacIntosh carriage return
Xcharacters, and a newly created MacBinary file has creator field given by
Xthe MAC_EDITOR environment variable.
X.PP
X.SH OPTIONS
X.TP
X.B p | q
XIf a BinHex to MacBinary conversion is taking place and option 'p' is selected,
Xany file of type "PIT "
Xwill be unpacked into its constituent parts. This option does not recursively
Xunpack "PIT " files packed in "PIT " files.
XIf a MacBinary to BinHex conversion is taking place, this option is currently
Xignored. By default, option 'q' is selected.
X.TP
X.B U | D
XWhen option 'U' is selected, the conversion that takes place is the one suitable
Xfor Uploading files. That is, the conversion is from MacBinary to something
Xelse when 'U' is selected. Conversely, option 'D', as in Download,
Xconverts from something to MacBinary. Option 'D' is the default.
X.TP
X.B s | v
XNormally,
X.I mcvert
Xprints to stderr information about the files it is creating. Selecting
Xoption 's', as in silent, disables this reporting. Option 'v', for verbose,
Xis the default.
X.SH "ENVIRONMENT VARIABLES"
XThere are four environment variables one may use to customize
Xthe behavior of
X.I mcvert
Xslightly.
X.TP
X.B MAC_EDITOR
XThe creator of MacBinary text files produced with options -uD.
XThe default is MACA, the creator type of MacWrite.
X.TP
X.B MAC_DLOAD_DIR
XThe MacBinary files created when option -D is selected are placed in this
Xdirectory. The default is ".", the current working directory.
X.TP
X.B MAC_EXT
XThe MacBinary files created when option -D is selected are named according
Xto the filename field stored in the file header, with the name extended by
Xthis suffix. The default is ".bin".
X.TP
X.B MAC_LINE_LIMIT
XThe BinHex files created when option -U is selected may be no longer than
Xthis many lines long. Files that would otherwise exceed this line limit
Xare broken up into several files with numbers embedded into their file
Xnames to show their order. Each such file has "Start of part x" and "End
Xof part x" messages included where appropriate.
X.SH BUGS
XIt should be possible to discard bad input now and successfully translate
Xgood input later, but bad input mostly just causes immediate termination.
X.PP
XA more diligent person would support BinHex 3.0 and BinHex 2.0 and BinHex
X5000.0 B. C., but I've never seen anyone use them in three years. A
Xmore diligent person would also do something for users of macget and
Xmacput, but hopefully someone will make those programs support the
XMacBinary file protocol.
X.SH SEE ALSO
Xxbin(1), macget(1), macput(1), xmodem(1), kermit(1)
X.SH AUTHOR
XDoug Moore, Cornell University Computer Science. Based upon
X.I xbin
Xby Dave Johnson, Brown University, as modified by Guido van Rossum, and upon
X.I unpit
Xby Allan G. Weber, as well as upon correspondence with several helpful
Xreaders of USENET.
X
END_OF_FILE
if test 5991 -ne `wc -c <'mcvert/mcvert.1'`; then
echo shar: \"'mcvert/mcvert.1'\" unpacked with wrong size!
fi
# end of 'mcvert/mcvert.1'
fi
if test -f 'mcvert/unpack.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'mcvert/unpack.c'\"
else
echo shar: Extracting \"'mcvert/unpack.c'\" \(6606 characters\)
sed "s/^X//" >'mcvert/unpack.c' <<'END_OF_FILE'
X#include "mactypes.h"
X
Xextern word magic[];
Xextern FILE *verbose;
Xextern char *dir, *ext;
X
Xulong pit_datalen, pit_rsrclen;
Xword hqx_crc, write_pit_fork();
Xchar pitfname[BINNAMELEN]; /* name of file being unpacked */
XFILE *pitfile; /* output file */
X
Xbranch branchlist[255], *branchptr, *read_tree();
Xleaf leaflist[256], *leafptr;
Xword Huff_nibble, Huff_bit_count;
Xbyte (*read_char)(), get_crc_byte(), getHuffbyte();
X
Xword un_pit()
X{ char PitId[4];
X int i;
X word pit_crc;
X
X hqx_crc = 0;
X /* Read and unpack until the PackIt End message is read */
X for (;;) {
X read_char = get_crc_byte;
X for (i = 0; i < 4; i++) PitId[i] = (char) get_crc_byte();
X if (!strncmp(PitId, "PEnd", 4)) break;
X
X if (strncmp(PitId, "PMag", 4) && strncmp(PitId, "PMa4", 4))
X error("Unrecognized Packit format message %s", PitId);
X
X if (PitId[3] == '4') { /* if this file is compressed */
X branchptr = branchlist; /* read the Huffman decoding */
X leafptr = leaflist; /* tree that is on the input */
X Huff_bit_count = 0; /* and use Huffman decoding */
X read_tree(); /* subsequently */
X read_char = getHuffbyte;
X }
X
X read_pit_hdr(); /* also calculates datalen, rsrclen,
X pitfile, pitfname */
X pit_crc = write_pit_fork(pit_datalen, 0);
X pit_crc = write_pit_fork(pit_rsrclen, pit_crc);
X check_pit_crc(pit_crc, " File data/rsrc CRC mismatch in %s", pitfname);
X fclose(pitfile);
X }
X hqx_crc = (hqx_crc << 8) ^ magic[hqx_crc >> 8];
X hqx_crc = (hqx_crc << 8) ^ magic[hqx_crc >> 8];
X return hqx_crc;
X }
X
Xcheck_pit_crc(calc_crc, msg, name)
Xword calc_crc;
Xchar msg[], name[];
X{ word read_crc;
X read_crc = (*read_char)() << 8;
X read_crc |= (*read_char)();
X if (read_crc != calc_crc) error(msg, name);
X }
X
X/* This routine reads the header of a packed file and appropriately twiddles it,
X determines if it has CRC problems, creates the .bin file, and puts the info
X into the .bin file.
X Output is pit_datalen, pit_rsrclen, pitfname, pitfile */
Xread_pit_hdr()
X{ register int n;
X register byte *pit_byte;
X register ulong pit_crc;
X pit_header pit;
X info_header info;
X short crc;
X
X extern short calc_mb_crc();
X /* read the pit header and compute the CRC */
X pit_crc = 0;
X pit_byte = (byte *) &pit;
X for (n = 0; n < sizeof(pit_header); n++) {
X *pit_byte = (*read_char)();
X pit_crc = ((pit_crc & 0xff) << 8)
X ^ magic[*pit_byte++ ^ (pit_crc >> 8)];
X }
X
X /* stuff the pit header data into the info header */
X bzero(&info, sizeof(info_header));
X info.nlen = pit.nlen;
X strncpy(info.name, pit.name, pit.nlen); /* name */
X bcopy(pit.type, info.type, 9); /* type, author, flag */
X bcopy(pit.dlen, info.dlen, 16); /* (d,r)len, (c,m)tim */
X info.flags &= 0x7e; /* reset lock bit, init bit */
X if (pit.protect & 0x40) info.protect = 1; /* copy protect bit */
X info.uploadvers = '\201';
X info.readvers = '\201';
X
X /* calculate MacBinary CRC */
X crc = calc_mb_crc(&info, 124, 0);
X info.crc[0] = (char) (crc >> 8);
X info.crc[1] = (char) crc;
X
X /* Create the .bin file and write the info to it */
X pit.name[pit.nlen] = '\0';
X unixify(pit.name);
X sprintf(pitfname, "%s/%s%s", dir, pit.name, ext);
X fprintf(verbose,
X " %-14s%-30s type = \"%4.4s\", author = \"%4.4s\"\n",
X (read_char == get_crc_byte) ? "Unpacking" : "Decompressing",
X pit.name, pit.type, pit.auth);
X if ((pitfile = fopen(pitfname, "w")) == NULL)
X error(" Cannot open %s", pitfname);
X check_pit_crc(pit_crc, " File header CRC mismatch in %s", pitfname);
X fwrite(&info, sizeof(info_header), 1, pitfile);
X
X /* Get a couple of items we'll need later */
X bcopy(pit.dlen, &pit_datalen, 4);
X pit_datalen = mac2long(pit_datalen);
X bcopy(pit.rlen, &pit_rsrclen, 4);
X pit_rsrclen = mac2long(pit_rsrclen);
X }
X
X/* This routine copies bytes from the decoded input stream to the output
X and calculates the CRC. It also pads to a multiple of 128 bytes on the
X output, which is part of the .bin format */
Xword write_pit_fork(nbytes, calc_crc)
Xregister ulong nbytes;
Xregister ulong calc_crc;
X{ register ulong b;
X int extra_bytes;
X
X extra_bytes = 127 - (nbytes+127)%128; /* pad fork to mult of 128 bytes */
X while (nbytes--) {
X b = (*read_char)();
X calc_crc = ((calc_crc & 0xff) << 8) ^ magic[b ^ (calc_crc >> 8)];
X putc(b, pitfile);
X }
X while (extra_bytes--) putc(0, pitfile);
X return (word) calc_crc;
X }
X
X/* This routine recursively reads the compression decoding data.
X It appears to be Huffman compression. Every leaf is represented
X by a 1 bit, then the byte it represents. A branch is represented
X by a 0 bit, then its zero and one sons */
Xbranch *read_tree()
X{ register branch *branchp;
X register leaf *leafp;
X register ulong b;
X if (!Huff_bit_count--) {
X Huff_nibble = get_crc_byte();
X Huff_bit_count = 7;
X }
X if ((Huff_nibble<<=1) & 0x0100) {
X leafp = leafptr++;
X leafp->flag = 1;
X b = get_crc_byte();
X leafp->data = Huff_nibble | (b >> Huff_bit_count);
X Huff_nibble = b << (8 - Huff_bit_count);
X return (branch *) leafp;
X }
X else {
X branchp = branchptr++;
X branchp->flag = 0;
X branchp->zero = read_tree();
X branchp->one = read_tree();
X return branchp;
X }
X }
X
X/* This routine returns the next 8 bits. It finds the byte in the
X Huffman decoding tree based on the bits from the input stream. */
Xbyte getHuffbyte()
X{ register branch *branchp;
X branchp = branchlist;
X while (!branchp->flag) {
X if (!Huff_bit_count--) {
X Huff_nibble = get_crc_byte();
X Huff_bit_count = 7;
X }
X branchp = ((Huff_nibble<<=1) & 0x0100) ? branchp->one : branchp->zero;
X }
X return ((leaf *) branchp)->data;
X }
X
X/* This routine returns the next byte on the .hqx input stream, hiding
X most file system details at a lower level. .hqx CRC is maintained
X here */
Xbyte get_crc_byte()
X{ register ulong c;
X extern byte *buf_ptr, *buf_end;
X if (buf_ptr == buf_end) fill_hqxbuf();
X c = *buf_ptr++;
X hqx_crc = ((hqx_crc << 8) | c) ^ magic[hqx_crc >> 8];
X return (byte) c;
X }
END_OF_FILE
if test 6606 -ne `wc -c <'mcvert/unpack.c'`; then
echo shar: \"'mcvert/unpack.c'\" unpacked with wrong size!
fi
# end of 'mcvert/unpack.c'
fi
if test -f 'stuffit/updcrc.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'stuffit/updcrc.c'\"
else
echo shar: Extracting \"'stuffit/updcrc.c'\" \(5848 characters\)
sed "s/^X//" >'stuffit/updcrc.c' <<'END_OF_FILE'
X/* updcrc(3), crc(1) - calculate crc polynomials
X *
X * Calculate, intelligently, the CRC of a dataset incrementally given a
X * buffer full at a time.
X *
X * Usage:
X * newcrc = updcrc( oldcrc, bufadr, buflen )
X * unsigned int oldcrc, buflen;
X * char *bufadr;
X *
X * Compiling with -DTEST creates a program to print the CRC of stdin to stdout.
X * Compile with -DMAKETAB to print values for crctab to stdout. If you change
X * the CRC polynomial parameters, be sure to do this and change
X * crctab's initial value.
X *
X * Notes:
X * Regards the data stream as an integer whose MSB is the MSB of the first
X * byte recieved. This number is 'divided' (using xor instead of subtraction)
X * by the crc-polynomial P.
X * XMODEM does things a little differently, essentially treating the LSB of
X * the first data byte as the MSB of the integer. Define SWAPPED to make
X * things behave in this manner.
X *
X * Author: Mark G. Mendel, 7/86
X * UUCP: ihnp4!umn-cs!hyper!mark, GEnie: mgm
X */
X
X/* The CRC polynomial.
X * These 4 values define the crc-polynomial.
X * If you change them, you must change crctab[]'s initial value to what is
X * printed by initcrctab() [see 'compile with -DMAKETAB' above].
X */
X /* Value used by: CITT XMODEM ARC */
X#define P 0xA001 /* the poly: 0x1021 0x1021 A001 */
X#define INIT_CRC 0L /* init value: -1 0 0 */
X#define SWAPPED /* bit order: undef defined defined */
X#define W 16 /* bits in CRC:16 16 16 */
X
X /* data type that holds a W-bit unsigned integer */
X#if W <= 16
X# define WTYPE unsigned short
X#else
X# define WTYPE unsigned long
X#endif
X
X /* the number of bits per char: don't change it. */
X#define B 8
X
Xstatic WTYPE crctab[1<<B] = /* as calculated by initcrctab() */ {
X0x0, 0xc0c1, 0xc181, 0x140, 0xc301, 0x3c0, 0x280, 0xc241,
X0xc601, 0x6c0, 0x780, 0xc741, 0x500, 0xc5c1, 0xc481, 0x440,
X0xcc01, 0xcc0, 0xd80, 0xcd41, 0xf00, 0xcfc1, 0xce81, 0xe40,
X0xa00, 0xcac1, 0xcb81, 0xb40, 0xc901, 0x9c0, 0x880, 0xc841,
X0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
X0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
X0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
X0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
X0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
X0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
X0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
X0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
X0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
X0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
X0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
X0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
X0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
X0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
X0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
X0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
X0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
X0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
X0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
X0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
X0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
X0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
X0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
X0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
X0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
X0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
X0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
X0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040,
X} ;
X
XWTYPE
Xupdcrc( icrc, icp, icnt )
X WTYPE icrc;
X unsigned char *icp;
X int icnt;
X{
X register WTYPE crc = icrc;
X register unsigned char *cp = icp;
X register int cnt = icnt;
X
X while( cnt-- ) {
X#ifndef SWAPPED
X crc = (crc<<B) ^ crctab[(crc>>(W-B)) ^ *cp++];
X#else
X crc = (crc>>B) ^ crctab[(crc & ((1<<B)-1)) ^ *cp++];
X#endif SWAPPED
X }
X
X return( crc );
X}
X
X#ifdef MAKETAB
X
X#include <stdio.h>
Xmain()
X{
X initcrctab();
X}
X
Xinitcrctab()
X{
X register int b, i;
X WTYPE v;
X
X
X for( b = 0; b <= (1<<B)-1; ++b ) {
X#ifndef SWAPPED
X for( v = b<<(W-B), i = B; --i >= 0; )
X v = v & ((WTYPE)1<<(W-1)) ? (v<<1)^P : v<<1;
X#else
X for( v = b, i = B; --i >= 0; )
X v = v & 1 ? (v>>1)^P : v>>1;
X#endif
X crctab[b] = v;
X
X printf( "0x%lx,", v & ((1L<<W)-1L));
X if( (b&7) == 7 )
X printf("\n" );
X else
X printf(" ");
X }
X}
X#endif
X
X#ifdef TEST
X
X#include <stdio.h>
X#include <fcntl.h>
X
X#define MAXBUF 4096
X
X
X
Xmain( ac, av )
X int ac; char **av;
X{
X int fd;
X int nr;
X int i;
X char buf[MAXBUF];
X WTYPE crc, crc2;
X
X fd = 0;
X if( ac > 1 )
X if( (fd = open( av[1], O_RDONLY )) < 0 ) {
X perror( av[1] );
X exit( -1 );
X }
X crc = crc2 = INIT_CRC;
X
X while( (nr = read( fd, buf, MAXBUF )) > 0 ) {
X crc = updcrc( crc, buf, nr );
X }
X
X if( nr != 0 )
X perror( "reading" );
X else {
X printf( "%lx\n", crc );
X }
X
X#ifdef MAGICCHECK
X /* tack one's complement of crc onto data stream, and
X continue crc calculation. Should get a constant (magic number)
X dependent only on P, not the data.
X */
X crc2 = crc ^ -1L;
X for( nr = W-B; nr >= 0; nr -= B ) {
X buf[0] = (crc2 >> nr);
X crc = updcrc(crc, buf, 1);
X }
X
X /* crc should now equal magic */
X buf[0] = buf[1] = buf[2] = buf[3] = 0;
X printf( "magic test: %lx =?= %lx\n", crc, updcrc(-1, buf, W/B));
X#endif MAGICCHECK
X}
X
X#endif
END_OF_FILE
if test 5848 -ne `wc -c <'stuffit/updcrc.c'`; then
echo shar: \"'stuffit/updcrc.c'\" unpacked with wrong size!
fi
# end of 'stuffit/updcrc.c'
fi
if test -f 'unstuffit/updcrc.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'unstuffit/updcrc.c'\"
else
echo shar: Extracting \"'unstuffit/updcrc.c'\" \(5848 characters\)
sed "s/^X//" >'unstuffit/updcrc.c' <<'END_OF_FILE'
X/* updcrc(3), crc(1) - calculate crc polynomials
X *
X * Calculate, intelligently, the CRC of a dataset incrementally given a
X * buffer full at a time.
X *
X * Usage:
X * newcrc = updcrc( oldcrc, bufadr, buflen )
X * unsigned int oldcrc, buflen;
X * char *bufadr;
X *
X * Compiling with -DTEST creates a program to print the CRC of stdin to stdout.
X * Compile with -DMAKETAB to print values for crctab to stdout. If you change
X * the CRC polynomial parameters, be sure to do this and change
X * crctab's initial value.
X *
X * Notes:
X * Regards the data stream as an integer whose MSB is the MSB of the first
X * byte recieved. This number is 'divided' (using xor instead of subtraction)
X * by the crc-polynomial P.
X * XMODEM does things a little differently, essentially treating the LSB of
X * the first data byte as the MSB of the integer. Define SWAPPED to make
X * things behave in this manner.
X *
X * Author: Mark G. Mendel, 7/86
X * UUCP: ihnp4!umn-cs!hyper!mark, GEnie: mgm
X */
X
X/* The CRC polynomial.
X * These 4 values define the crc-polynomial.
X * If you change them, you must change crctab[]'s initial value to what is
X * printed by initcrctab() [see 'compile with -DMAKETAB' above].
X */
X /* Value used by: CITT XMODEM ARC */
X#define P 0xA001 /* the poly: 0x1021 0x1021 A001 */
X#define INIT_CRC 0L /* init value: -1 0 0 */
X#define SWAPPED /* bit order: undef defined defined */
X#define W 16 /* bits in CRC:16 16 16 */
X
X /* data type that holds a W-bit unsigned integer */
X#if W <= 16
X# define WTYPE unsigned short
X#else
X# define WTYPE unsigned long
X#endif
X
X /* the number of bits per char: don't change it. */
X#define B 8
X
Xstatic WTYPE crctab[1<<B] = /* as calculated by initcrctab() */ {
X0x0, 0xc0c1, 0xc181, 0x140, 0xc301, 0x3c0, 0x280, 0xc241,
X0xc601, 0x6c0, 0x780, 0xc741, 0x500, 0xc5c1, 0xc481, 0x440,
X0xcc01, 0xcc0, 0xd80, 0xcd41, 0xf00, 0xcfc1, 0xce81, 0xe40,
X0xa00, 0xcac1, 0xcb81, 0xb40, 0xc901, 0x9c0, 0x880, 0xc841,
X0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
X0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
X0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
X0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
X0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
X0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
X0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
X0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
X0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
X0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
X0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
X0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
X0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
X0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
X0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
X0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
X0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
X0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
X0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
X0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
X0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
X0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
X0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
X0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
X0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
X0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
X0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
X0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040,
X} ;
X
XWTYPE
Xupdcrc( icrc, icp, icnt )
X WTYPE icrc;
X unsigned char *icp;
X int icnt;
X{
X register WTYPE crc = icrc;
X register unsigned char *cp = icp;
X register int cnt = icnt;
X
X while( cnt-- ) {
X#ifndef SWAPPED
X crc = (crc<<B) ^ crctab[(crc>>(W-B)) ^ *cp++];
X#else
X crc = (crc>>B) ^ crctab[(crc & ((1<<B)-1)) ^ *cp++];
X#endif SWAPPED
X }
X
X return( crc );
X}
X
X#ifdef MAKETAB
X
X#include <stdio.h>
Xmain()
X{
X initcrctab();
X}
X
Xinitcrctab()
X{
X register int b, i;
X WTYPE v;
X
X
X for( b = 0; b <= (1<<B)-1; ++b ) {
X#ifndef SWAPPED
X for( v = b<<(W-B), i = B; --i >= 0; )
X v = v & ((WTYPE)1<<(W-1)) ? (v<<1)^P : v<<1;
X#else
X for( v = b, i = B; --i >= 0; )
X v = v & 1 ? (v>>1)^P : v>>1;
X#endif
X crctab[b] = v;
X
X printf( "0x%lx,", v & ((1L<<W)-1L));
X if( (b&7) == 7 )
X printf("\n" );
X else
X printf(" ");
X }
X}
X#endif
X
X#ifdef TEST
X
X#include <stdio.h>
X#include <fcntl.h>
X
X#define MAXBUF 4096
X
X
X
Xmain( ac, av )
X int ac; char **av;
X{
X int fd;
X int nr;
X int i;
X char buf[MAXBUF];
X WTYPE crc, crc2;
X
X fd = 0;
X if( ac > 1 )
X if( (fd = open( av[1], O_RDONLY )) < 0 ) {
X perror( av[1] );
X exit( -1 );
X }
X crc = crc2 = INIT_CRC;
X
X while( (nr = read( fd, buf, MAXBUF )) > 0 ) {
X crc = updcrc( crc, buf, nr );
X }
X
X if( nr != 0 )
X perror( "reading" );
X else {
X printf( "%lx\n", crc );
X }
X
X#ifdef MAGICCHECK
X /* tack one's complement of crc onto data stream, and
X continue crc calculation. Should get a constant (magic number)
X dependent only on P, not the data.
X */
X crc2 = crc ^ -1L;
X for( nr = W-B; nr >= 0; nr -= B ) {
X buf[0] = (crc2 >> nr);
X crc = updcrc(crc, buf, 1);
X }
X
X /* crc should now equal magic */
X buf[0] = buf[1] = buf[2] = buf[3] = 0;
X printf( "magic test: %lx =?= %lx\n", crc, updcrc(-1, buf, W/B));
X#endif MAGICCHECK
X}
X
X#endif
END_OF_FILE
if test 5848 -ne `wc -c <'unstuffit/updcrc.c'`; then
echo shar: \"'unstuffit/updcrc.c'\" unpacked with wrong size!
fi
# end of 'unstuffit/updcrc.c'
fi
echo shar: End of archive 2 \(of 4\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 4 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
--- end of part 2 ---