tim@callan.UUCP (Tim Smith) (08/13/85)
I recently needed to convert a macget upload to a .hqx file. I was not able to find anything to do this ( does everyone else use a pre 5.0 BinHex and do the conversion on the Mac, or what? 5.0 only converts to .bin files ). The result was a quick sets of hacks to do this. Here they are for anybody that needs them. ---------------------------------------- cut here ------------------ #!/bin/sh # This is meant to be run through the shell echo extract 8to6.c cat >8to6.c <<"--EOF--" /* * Convert 8 bit data stream into 6 bit data stream. * The approach is very dumb, but I was in a hurry. */ #include <stdio.h> char tr[]="!\"#$%&'()*+,-012345689@ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr"; getbit() { static int c, mask = 0x00; static int count; if ( mask == 0 ) { mask = 0x80; c = getchar(); if ( c == EOF ) if ( count % 3 == 0 ) return -1; else c = 0; /* make everything come out even */ count++; } if ( c & mask ) { mask >>= 1; return 1; } else { mask >>= 1; return 0; } } main() { int bits = 0; int c; int count; int val; printf( "(This file must be converted with something)\n:" ); count = 1; while ( ( val = getbit() ) != -1 ) { c = c + c + val; bits++; if ( bits == 6 ) { bits = 0; putchar( tr[ c ] ); c = 0; if ( count++ > 62 ) { count = 0; putchar( '\n' ); } } } if ( bits != 0 ) write( 2, "no bits\n", 8 ); putchar( ':' ); putchar( '\n' ); } --EOF-- echo extract README cat >README <<"--EOF--" These programs are a quick hack to convert *.{info,data,rsrc} files from macget back to something that xbin will accept. The only reason I wrote these was so that I could post version 4.5 of Switcher. These files are in no way optimum, elegant, or pretty. In fact, they might not even be correct. If you need to do this sort of thing very often, you should obtain whatever it is everybody else uses ( and post it to the net so that I can get it! ). Enough blithering. Here is what is here: README This file gethead filter to turn *.info into a valid header crc writes crc of stdin on stdout unrun filter to change 0x90 into 0x90 0x00. needed because I don't do run length encoding, because this is all a kludge. 8to6 filter to convert 8 bit data stream into 6 bit data stream that xbin wants. Uses worst algorithm I could think of, so don't look at it, please! unxbin shell script to use the above stuff To install: #!/bin/sh for i in gethead crc unrun 8to6 do cc $i.c -o /where/you/want/it/in/your/path/$i done cp unxbin /some/where/in/your/path To use: unxbin file # convert file.{info,data,rsrs} to file.hqx --EOF-- echo extract crc.c cat >crc.c <<"--EOF--" /* * compute the crc used in .hqx files */ #include <stdio.h> int crc, temp; main() { int c; crc = 0; while ( ( c = getchar() ) != EOF ) docrc( c ); docrc(0); docrc(0); putchar( (crc>>8) & 0xff ); putchar( crc & 0xff ); } docrc( c ) int c; { register int i; temp = crc; for ( i = 0; i < 8; i++ ) { c <<= 1; if ( (temp <<= 1) & 0x10000 ) temp = (temp & 0xffff) ^ 0x1021; temp ^= (c >> 8); c &= 0xff; } crc = temp; } --EOF-- echo extract gethead.c cat >gethead.c <<"--EOF--" /* * filter to change a foo.info file into a proper header for a .hqx file */ char head[ 128 ]; main() { int n; read( 0, head, 128 ); put( 1, 1 ); for ( n = 0; n < head[1]; n++ ) put( 1, n+2 ); head[0] = 0; put( 1, 0 ); put( 4, 65 ); put( 4, 69 ); put( 2, 63 ); put( 4, 83 ); put( 4, 87 ); } put( cnt, offset ) { while ( cnt-- > 0 ) putchar( head[ offset++ ] ); } --EOF-- echo extract unrun.c cat >unrun.c <<"--EOF--" /* * remove run length problems */ #include <stdio.h> main() { int c; while ( (c = getchar()) != EOF ) { putchar( c ); if ( c == 0x90 ) putchar( 0 ); } } --EOF-- echo extract unxbin cat >unxbin <<"--EOF--" : # convert foo.info, foo.data, foo.rsrc files to a single file suitable # for xbin trap "rm $TMP;echo aborted;exit" 1 2 3 15 BASENAME=$1 # argument is name of file TMP=/tmp/unxbin$$ gethead < $BASENAME.info > /tmp/unxbin$$ crc < $TMP >> $TMP cat $BASENAME.data >> $TMP crc < $BASENAME.data >> $TMP cat $BASENAME.rsrc >> $TMP crc < $BASENAME.rsrc >> $TMP unrun < $TMP | 8to6 > $BASENAME.hqx rm $TMP --EOF-- chmod +x unxbin echo all done exit -- Tim Smith ihnp4!{cithep,wlbr!callan}!tim