summaryrefslogtreecommitdiff
path: root/dfont2res.c
diff options
context:
space:
mode:
authorGeorge Williams <gww@silcom.com>2002-12-22 04:38:38 +0000
committerGeorge Williams <gww@silcom.com>2002-12-22 04:38:38 +0000
commitda35c171a1d649d33871708c75d645e5fe2dcfc4 (patch)
tree7ffca124aa2f34d9cd9c7a271ef17b85e6386ebb /dfont2res.c
parent7408ae59bd586e94c3b51bea73428e37b491f73b (diff)
I wasn't generating macbinary files properly
* Didn't notice that the sections had to be padded out to 128 bytes. * Got the crc wrong. I'm fed up with the fact that I can't find something that will generate a macbinary file so I wrote such a utility.
Diffstat (limited to 'dfont2res.c')
-rw-r--r--dfont2res.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/dfont2res.c b/dfont2res.c
index ec84587..d55f985 100644
--- a/dfont2res.c
+++ b/dfont2res.c
@@ -38,23 +38,20 @@ static void Usage(char *prog) {
exit(0);
}
-/* MacBinary files use the same CRC that XModem does (in the MacBinary header) */
-/* Taken from zglobal.h in lrzsz-0.12.20.tar, an xmodem package */
-/* http://www.ohse.de/uwe/software/lrzsz.html */
- /* crctab.c */
- extern unsigned short crctab[256];
-# define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
- extern long cr3tab[];
-# define UPDC32(b, c) (cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF))
-/* End of borrowed code */
-
-static int crcbuffer(uint8 *buffer,int size) {
- int crc = 0, i;
-
- for ( i=0; size>=2; i+=2, size-=2 )
- crc = updcrc( ((buffer[i]<<8)|buffer[i+1]) , crc );
-return( crc );
-}
+/* A MacBinary file */
+/* http://www.lazerware.com/formats/macbinary.html */
+/* begins with a 128 byte header */
+/* (which specifies lengths for data/resource forks) */
+/* (and contains mac type/creator data) */
+/* (and other stuff) */
+/* (and finally a crc checksum)
+/* is followed by the data section (padded to a mult of 128 bytes) */
+/* is followed by the resource section (padded to a mult of 128 bytes) */
+
+/* Crc code taken from: */
+/* http://www.ctan.org/tex-archive/tools/macutils/crc/ */
+/* MacBinary files use the same CRC that binhex does (in the MacBinary header) */
+extern unsigned long binhex_crc(unsigned char *buffer,int size);
static void DumpMacBinaryHeader(FILE *res,struct macbinaryheader *mb) {
uint8 header[128], *hpt; char buffer[256], *pt, *dpt;
@@ -104,6 +101,9 @@ static void DumpMacBinaryHeader(FILE *res,struct macbinaryheader *mb) {
fseek(res,0,SEEK_END);
len = ftell(res)-sizeof(header);
*hpt++ = len>>24; *hpt++ = len>>16; *hpt++ = len>>8; *hpt++ = len;
+ /* Pad resource fork to be a multiple of 128 bytes */
+ while ( (len&127)!=0 )
+ { putc('\0',res); ++len; }
/* Creation time, (seconds from 1/1/1904) */
time(&now);
@@ -127,7 +127,7 @@ static void DumpMacBinaryHeader(FILE *res,struct macbinaryheader *mb) {
header[122] = 130; /* MacBinary version 3, written in (129 is MB2) */
header[123] = 129; /* MacBinary Version 2, needed to read */
- crc = crcbuffer(header,124);
+ crc = binhex_crc(header,124);
header[124] = crc>>8;
header[125] = crc;