Path: ns-mx!uunet!mcsun!sun4nl!donau!duteca.et.tudelft.nl!marcel From: marcel@duteca.et.tudelft.nl (Marcel J.E. Mol/13000) Newsgroups: comp.binaries.apple2 Subject: SCIIBIN and other unpacker programs, Source Message-ID: <1992Jan03.220252.10834@donau.et.tudelft.nl> Date: 3 Jan 92 22:02:52 GMT Sender: news@donau.et.tudelft.nl (UseNet News System) Organization: Delft University of Technology, Dept. of Electrical Engineering Lines: 1960 Nntp-Posting-Host: duteca.et.tudelft.nl As the last post seems to have failed, I'll repost the unpacker programs for encoded apple binarie files. -MArcel #! /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 'MANIFEST' <<'END_OF_FILE' X File Name Archive # Description X----------------------------------------------------------- X MANIFEST 1 X Makefile 1 X README 1 X crc.h 1 X filetype.h 1 X getopt.c 1 X sciibin.c 1 X unbit.c 1 X unblu.c 1 X unexec.c 1 X usq.c 1 END_OF_FILE if test 437 -ne `wc -c <'MANIFEST'`; then echo shar: \"'MANIFEST'\" unpacked with wrong size! fi # end of 'MANIFEST' fi if test -f 'Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Makefile'\" else echo shar: Extracting \"'Makefile'\" \(297 characters\) sed "s/^X//" >'Makefile' <<'END_OF_FILE' XCFLAGS = -s X X Xall: usq unblu unexec unbit sciibin X Xusq: usq.o X cc $(CFLAGS) -o $@ $? X Xunexec: unexec.o X cc $(CFLAGS) -o $@ $? X Xunblu: unblu.o X cc $(CFLAGS) -o $@ $? X Xunbit: unbit.o X cc $(CFLAGS) -o $@ $? X Xsciibin: sciibin.o X cc $(CFLAGS) -o $@ $? X Xunblu.c: filetype.h Xsciibin.c: filetype.h crc.h END_OF_FILE if test 297 -ne `wc -c <'Makefile'`; then echo shar: \"'Makefile'\" unpacked with wrong size! fi # end of 'Makefile' fi if test -f 'README' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'README'\" else echo shar: Extracting \"'README'\" \(1478 characters\) sed "s/^X//" >'README' <<'END_OF_FILE' XHere are a bunch of C programs to process different kind Xof files containing Apple stuff. XNo functional changes from the previous versions. Only some cleanups and Xports to other machines/OS like MSDOS and Macintosh. X XThe programs are: X Xunbit - undoes the 6-bit executioner format. Xunexec - undoes the apple2 monitor format. Xunblu - view and extract from binary 2 archives. Xusq - usqueeze squeezed files (created by sq3 or X extracted from binary 2 or shrinkit archives). Xsciibin - view and extract from binscii files. X X XUse this for example to extract apple files posted Xto the comp.binaries.apple2 newsgroup in one of the Xabove formats. XI use it to extract for example binary 2 or shrinkit Xarchives (with Andy Mccfaden's nulib) which can easily Xbe transfered to the Apple as binary files. XIt also allows me to print doc files on a laser printer... XThis saves me telephone costs and time. X X- Marcel marcel@duteca.tudelft.nl X######################################### X# Marcel J.E. Mol ###################################### X# Delft University of Technology Pink Elephant Management Services # X# The Netherlands Voorburg # X# UUCP: marcel@duteca.tudelft.nl Tel: 070-694231 # X# ###################################### X######################################### X============= CUT HERE ============== END_OF_FILE if test 1478 -ne `wc -c <'README'`; then echo shar: \"'README'\" unpacked with wrong size! fi # end of 'README' fi if test -f 'crc.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'crc.h'\" else echo shar: Extracting \"'crc.h'\" \(3148 characters\) sed "s/^X//" >'crc.h' <<'END_OF_FILE' X/* X * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. X * NOTE: First srgument must be in range 0 to 255. X * Second argument is referenced twice. X * X * Programmers may incorporate any or all code into their programs, X * giving proper credit within the source. Publication of the X * source routines is permitted so long as proper credit is given X * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, X * Omen Technology. X */ X X /* #define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp) */ X#define updcrc(cp, crc) ( (crctab[((crc >> 8) & 0xFF) ^ cp] ^ (crc << 8)) & 0xFFFF) X X X/* crctab calculated by Mark G. Mendel, Network Systems Corporation */ Xstatic unsigned short crctab[256] = { X 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, X 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, X 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, X 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, X 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, X 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, X 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, X 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, X 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, X 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, X 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, X 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, X 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, X 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, X 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, X 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, X 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, X 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, X 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, X 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, X 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, X 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, X 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, X 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, X 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, X 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, X 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, X 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, X 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, X 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, X 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, X 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 X}; X END_OF_FILE if test 3148 -ne `wc -c <'crc.h'`; then echo shar: \"'crc.h'\" unpacked with wrong size! fi # end of 'crc.h' fi if test -f 'filetype.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'filetype.h'\" else echo shar: Extracting \"'filetype.h'\" \(5087 characters\) sed "s/^X//" >'filetype.h' <<'END_OF_FILE' Xchar * filetypes[] = { X "non", "bad", "pcd", "ptx", "txt", "pda", "bin", "chr", X "pic", "ba3", "da3", "wpd", "sos", "$0D", "$0E", "dir", X "rpd", "rpi", "$12", "out", "$14", "rpt", "$16", "$17", X "$18", "adb", "awp", "asp", "$1C", "$1D", "$1E", "$1F", X "$20", "$21", "$22", "$23", "$24", "$25", "$26", "$27", X "$28", "$29", "$2A", "$2B", "$2C", "$2D", "$2E", "$2F", X "$30", "$31", "$32", "$33", "$34", "$35", "$36", "$37", X "$38", "$39", "$3A", "$3B", "$3C", "$3D", "$3E", "$3F", X "$40", "$41", "$42", "$43", "$44", "$45", "$46", "$47", X "$48", "$49", "$4A", "$4B", "$4C", "$4D", "$4E", "$4F", X "$50", "$51", "$52", "$53", "$54", "$55", "$56", "$57", X "$58", "$59", "$5A", "$5B", "$5C", "$5D", "$5E", "$5F", X "pre", "$61", "$62", "$63", "$64", "$65", "$66", "$67", X "$68", "$69", "$6A", "nio", "$6C", "dvr", "$6E", "hdv", X "$70", "$71", "$72", "$73", "$74", "$75", "$76", "$77", X "$78", "$79", "$7A", "$7B", "$7C", "$7D", "$7E", "$7F", X "$80", "$81", "$82", "$83", "$84", "$85", "$86", "$87", X "$88", "$89", "$8A", "$8B", "$8C", "$8D", "$8E", "$8F", X "$90", "$91", "$92", "$93", "$94", "$95", "$96", "$97", X "$98", "$99", "$9A", "$9B", "$9C", "$9D", "$9E", "$9F", X "wpf", "mac", "hlp", "dat", "$A4", "lex", "$A6", "$A7", X "$A8", "$A9", "$AA", "gsb", "arc", "$AD", "$AE", "$AF", X "src", "obj", "lib", "s16", "rtl", "exe", "str", "tsf", X "nda", "cda", "tol", "drv", "$BC", "fst", "$BE", "doc", X "pnt", "scr", "ani", "$C3", "$C4", "$C5", "$C6", "$C7", X "fon", "fnd", "icn", "$CB", "$CC", "$CD", "$CE", "$CF", X "$D0", "$D1", "$D2", "$D3", "$D4", "$D5", "$D6", "$D7", X "$D8", "$D9", "$DA", "$DB", "$DC", "$DD", "$DE", "$DF", X "lbr", "$E1", "ati", "$E3", "$E4", "$E5", "$E6", "$E7", X "$E8", "$E9", "$EA", "$EB", "$EC", "$ED", "$EE", "pas", X "cmd", "$F1", "$F2", "$F3", "$F4", "$F5", "$F6", "$F7", X "$F8", "img", "int", "ivr", "bas", "var", "rel", "sys", X }; X X/* XProDOS Filetypes X XNum Name OS Meaning X======================================================================== X$00 typeless X$01 BAD both BAD blocks file X$02 PCD SOS Pascal CoDe file X$03 PTX SOS Pascal TeXt file X$04 TXT both ASCII text file X$05 PDA SOS Pascal DAta file X$06 BIN both BINary file X$07 CHR SOS CHaRacter font file X$08 PIC both PICture file X$09 BA3 SOS Business BASIC (SOS) program file X$0A DA3 SOS Business BASIC (SOS) data file X$0B WPD SOS Word Processor Document X$0C SOS SOS SOS system file X$0D SOS SOS reserved file type X$0E SOS SOS reserved file type X$0F DIR Both subDIRectory file X$10 RPD SOS RPS data file X$11 RPI SOS RPS index file X$12 SOS Applefile diskcard file X$13 SOS Applefile model file X$14 SOS Applefile report format file X$15 SOS Screen library file X$16 SOS SOS reserved file type X$17 SOS SOS reserved file type X$18 SOS SOS reserved file type X$19 ADB ProDOS AppleWorks Database file X$1A AWP ProDOS AppleWorks WordProcessing file X$1B ASP ProDOS AppleWorks Spreadsheet file X$1C-$5F Reserved X$60-$6F ProDOS PC Transporter (Applied Engineering) reserved filetypes X $60 PRE ProDOS ProDOS preboot driver X $61-$6A ProDOS Reserved X $6B NIO ProDOS PC Transporter BIOS and drivers X $6C ProDOS Reserved X $6D DVR ProDOS PC Transporter device drivers X $6E ProDOS Reserved X $6F HDV ProDOS MSDOS HardDisk Volume X$70-$9F Reserved X$A0 WPF ProDOS WordPerfect document file X$A1 MAC ProDOS Macrofile X$A2 HLP ProDOS Help File X$A3 DAT ProDOS Data File X$A4 Reserved X$A5 LEX ProDOS Spelling dictionary X$A6-$AB Reserved X$AC ARC ProDOS General Purpose Archive file X$AD-$AF Reserved X$B0 SRC ProDOS ORCA/M & APW source file X$B1 OBJ ProDOS ORCA/M & APW object file X$B2 LIB ProDOS ORCA/M & APW library file X$B3 S16 ProDOS ProDOS16 system file X$B4 RTL ProDOS ProDOS16 runtime library X$B5 EXE ProDOS APW shell command file X$B6 STR ProDOS ProDOS16 startup init file X$B7 TSF ProDOS ProDOS16 temporary init file X$B8 NDA ProDOS ProDOS16 new desk accessory X$B9 CDA ProDOS ProDOS16 classic desk accessory X$BA TOL ProDOS ProDOS16 toolset file X$BB DRV ProDOS ProDOS16 driver file X$BC Reserved for ProDOS16 load file X$BD FST ??? X$BC Reserved for ProDOS16 load file X$BF DOC ProDOS document file X$C0 PNT ProDOS //gs paint document X$C1 SCR ProDOS //gs screen file X$C2 ANI ??? X$C3-$C7 Reserved X$C8 FNT ProDOS Printer font file X$C9 FND ProDOS finder files X$CA ICN ProDOS finder icons X$CB-$DF Reserved X$E0 LBR ProDOS Apple archive library file X$E1 Unknown (unlisted) X$E2 ATI ProDOS Appletalk init file X$E3-$EE Reserved X$EF PAS ProDOS ProDOS Pascal file X$F0 CMD ProDOS added command file X$F1-$F8 ProDOS User defined filetypes (popular ones include:) X $F1 OVL ProDOS Overlay file X $F2 DBF ProDOS Database file X $F3 PAD ProDOS MouseWrite file X $F4 MCR ProDOS AE Pro macro file X $F5 ECP ProDOS ECP batch file X $F6 DSC ProDOS description file X $F7 TMP ProDOS temporary work file X $F8 RSX ProDOS linkable object module X$F9 IMG ProDOS ProDOS image file X$FA INT ProDOS Integer BASIC program X$FB IVR ProDOS Integer BASIC variables file X$FC BAS ProDOS AppleSoft BASIC program X$FD VAR ProDOS AppleSoft BASIC variables file X$FE REL ProDOS ProDOS EDASM relocatable object module file X$FF SYS ProDOS ProDOS8 system file X*/ X END_OF_FILE if test 5087 -ne `wc -c <'filetype.h'`; then echo shar: \"'filetype.h'\" unpacked with wrong size! fi # end of 'filetype.h' fi if test -f 'getopt.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'getopt.c'\" else echo shar: Extracting \"'getopt.c'\" \(3658 characters\) sed "s/^X//" >'getopt.c' <<'END_OF_FILE' X/* X* The official AT&T public domain version of getopt(3). X*/ X#include X Xint optopt; /* For getopt */ Xint opterr = 1; /* For getopt */ Xint optind = 1; /* For getopt */ Xchar *optarg; /* For getopt */ X X#define ERR(s, c) \ X if (opterr) { \ X extern int strlen(), write(); \ X char errbuf[2]; \ X errbuf[0] = c; errbuf[1] = '\n';\ X (void) write(2, argv[0], (unsigned) strlen(argv[0])); \ X (void) write(2, s, (unsigned) strlen(s));\ X (void) write(2, errbuf, 2);\ X } X Xint getopt(argc, argv, opstring) Xint argc; Xchar **argv, X *opstring; X{ X static int sp = 1; X register int c; X register char *cp; X X if (sp == 1) X if (optind >= argc || X argv[optind][0] != '-' || X argv[optind][1] == '\0') X return (EOF); X else X if (strcmp(argv[optind], "--") == NULL) { X optind++; X return (EOF); X } X X optopt = c = argv[optind][sp]; X if (c == ':' || X (cp = strchr(opstring, c)) == NULL) { X ERR(": illegal option -- ", c); X if (argv[optind][++sp] == '\0') { X optind++; X sp = 1; X } X X return ('?'); X } X X if (*++cp == ':') { X if (argv[optind][sp+1] != '\0') X optarg = &argv[optind++][sp+1]; X else X if (++optind >= argc) { X ERR(": option requires an argument -- ", c); X sp = 1; X return ('?'); X } X else X optarg = argv[optind++]; X X sp = 1; X } X else { X if (argv[optind][++sp] == '\0') { X sp = 1; X optind++; X } X X optarg = NULL; X } X X return (c); X X} /* getopt */ X X X#if (0) X/* X* My own version of the UNIX getopt function for non-UNIX systems. It is not X* a fully functioning getopt but it will suffice for most anything X*/ Xint getopt(argc, argv, opstring) Xint argc; Xchar **argv, X *opstring; X{ X int option = -1, /* Option to be returned */ X index = 0, /* Index into opstring */ X get_args = 0, /* Boolean to flag arg val. */ X found = 0, /* Boolean flag found flag */ X loop; /* Loop counter for parsing */ X char flag = NULL; /* Flag/option to check for */ X X optarg = NULL; X X /* Check for no arguments */ X if (argc == 1) X return(option); X X if (argv[optind][0] != '-') X return(option); X X flag = opstring[index++]; X if (opstring[index] == ':') X get_args = 1; X X /* Scan 'next' argument until the last one */ X for (loop = optind; !found; ) { X if (flag == argv[loop][1]) { X if (get_args) X optarg = (char *) argv[loop] + 2; X X option = argv[loop][1]; X optind = loop + 1; X found = 1; X } X X if (!found) { X /* Didnt match so check next character in opstring */ X flag = opstring[index++]; X X /* Check to see if at end of opstring yet */ X if (flag == NULL) X return ('?'); X X if (opstring[index] == ':') X get_args = 1; X else X get_args = 0; X } X } /* for (loop = 1; loop < argc; loop++) */ X X return(option); X X} /* end getopt */ X#endif END_OF_FILE if test 3658 -ne `wc -c <'getopt.c'`; then echo shar: \"'getopt.c'\" unpacked with wrong size! fi # end of 'getopt.c' fi if test -f 'sciibin.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'sciibin.c'\" else echo shar: Extracting \"'sciibin.c'\" \(19112 characters\) sed "s/^X//" >'sciibin.c' <<'END_OF_FILE' X/* @(#) sciibin.c 3.01 12Feb91 */ X/************************************************************************* X ** ** X ** Name : sciibin ** X ** Author : Marcel J.E. Mol ** X ** Date : 06Mar89 (first release) ** X ** Version : 2.00 ** X ** Files : sciibin.c Main source file ** X ** Purpose : Extract or view BinSCII files ** X ** ** X ** ------------------------- Revision List ------------------------- ** X ** Ver Date Name Remarks ** X ** 1.00 06Mar89 Marcel Mol First release ** X ** 1.10 27Mar89 Marcel Mol Fished things up, error routine, ** X ** linecount, all info fields filled ** X ** in, changed info layout. ** X ** 2.00 03Jun89 Marcel Mol Bug fixes: alphabet to unsigned ** X ** (Dave Whitney) char. Some OS's need types.h. ** X ** Fixed CRE/MOD order. ** X ** Output filenames can be wrong ** X ** when multiple files are ** X ** extracted. Made crc and file- ** X ** type arrays in seperate includes ** X ** 3.00 22Mar90 Marcel Mol Includeed ports of Bruce Kahn ** X ** 1.30 27 Feb 90 Bruce Kahn Ported to AOS/VS C 4.01 and MSC 5.1 ** X ** Added explicit long definitions ** X ** needed. ** X ** Redid layouts for dates to be US. ** X ** Modified the open routines for MSC ** X ** to include binary mode, not text. ** X ** Changed the way 8 bit integers are ** X ** handled (redone MM). ** X ** Added getopt() (see below MM). ** X ** 3.01 22Feb91 Marcel Mol Fixed bug: only close output ** X ** when output is generated. ** X ** ================================================================= ** X ** ** X ** Compile as follows: ** X ** If you don't have getopt, compile and link the given getopt.c ** X ** ** X ** UNIX: cc sciibin.c -Oso sciibin ** X ** ** X ** MSC 5.1: cl /c /Ox sciibin.c ** X ** (add /DMSDOS, if MSC didn't do it) ** X ** link /CO /STACK:10000 sciibin; ** X ** ** X ** AOS/VS: cc sciibin.c ** X ** ccl sciibin ** X ** ** X ** Defining DEBUG gives some debug information. ** X ** Defining DEBUGALL gives input and output of the decode routine. ** X ** ** X ** Usage: sciibin [-hvtc] [-o] ** X ** ** X ** -v show only info on file, do not create output. ** X ** -t test file, do not create output. ** X ** -c do not check checksums. ** X ** -o create given filename instead of the one in ** X ** binscii file. Use this only if the input files ** X ** contain only one output file. ** X ** -h help. ** X ** ** X ** ** X ** This software is freeware. We can not be held responsible to ** X ** any damage this program may coase you or anyone or anything else. ** X ** ** X ** Mail bugs to: marcel@duteca.tudelft.nl ** X ** ** X ************************************************************************/ X X X#include X#include /* keep sun OS happy */ X#include /* mostly includes types.h ... */ X#if defined(MSDOS) X#include /* For the memset function */ X#endif X#include "crc.h" X#include "filetype.h" X X#define BUFLEN 256 X#define FILENAME_LEN 15 X#define BINSCII_HEADER "FiLeStArTfIlEsTaRt\n" X#define MAXSEGLEN 0x3000 X X#if defined(INT8) Xtypedef long int16; X#else Xtypedef int int16; X#endif X X/* ==> Expect int variables to be at least 16 bits X * Global variables ==> and longs to be at least 32 bits X * ==> If not, you have some work to do... X */ /* MSDOS has 16 bit ints. */ Xchar buf[BUFLEN+1]; Xunsigned char dec[BUFLEN+1]; Xunsigned char alphabet[BUFLEN+1]; /* need $FF in alphabet */ Xchar outfilename[BUFLEN+1]; X X Xunsigned char outflag = 0, /* the -o option */ X crcflag = 0, /* the -c option */ X infoflag = 0, /* the -v option */ X testflag = 0, /* the -t option */ X makeoutput, /* ! (-t | -v) */ X crcok; /* -t | -c */ XFILE *outfp; /* output file */ X Xunsigned char filetype, stortype, X file_access; /* access -> file_access for MSDOS */ Xunsigned char modyear, modmonth, modday, modhour, modmin, X creyear, cremonth, creday, crehour, cremin; Xint namlen, linecount, X numblocks, auxtype; Xlong filesize, startbyte, segmentlen; Xchar * infilename; X Xchar * progname; X X X/* X * function declarations X */ Xint main (); Xint sciibin (); Xint getheader (); Xint decode (); Xint decodestring (); Xchar *myfgets (); Xvoid usage (); Xvoid error (); X X Xchar * copyright = "@(#) sciibin.c 3.01 12Feb91 (c) 1989, 1991 M.J.E. Mol"; X Xmain(argc, argv) Xint argc; Xchar **argv; X{ X FILE *fp; X int c; X extern int optind; /* For getopt */ X extern char * optarg; /* For getopt */ X int flag; /* Flag for getopt */ X X progname = *argv; X X while ((flag = getopt(argc, argv, "hvcto:")) != EOF) { /* Process options */ X switch (flag) { X case 'v': infoflag = 1; /* Want only info of file */ X break; X case 'h': usage(); /* Give help */ X exit(0); X case 'c': crcflag = 1; X break; X case 't': testflag = 1; X break; X case 'o': X#if defined(MSDOS) X memset(outfilename, NULL, FILENAME_LEN + 1); X#endif X strcpy(outfilename, optarg); X outflag = 1; X break; X default : fprintf(stderr, "%s: skipping unkown flag %c, use -h.\n", X progname, flag); X break; X } X } X X makeoutput = !(testflag | infoflag); X crcok = testflag | crcflag; X X#if defined(DEBUG) X fprintf(stderr, "make output: %d, crcok: %d\n", makeoutput, crcok); X#endif X X if (optind >= argc) { /* No files given, use stdin */ X infilename = "stdin"; X linecount = 0; X sciibin(stdin); X } X else X while (optind < argc) { X infilename = argv[optind]; X optind++; X if ((fp = fopen(infilename, "r")) == NULL) { X perror(infilename); X continue; X } X linecount = 0; X sciibin(fp); X fclose(fp); X } X X exit(0); X X} /* main */ X X X X/* X * Walk over the file processing all segments in it X */ Xsciibin(fp) XFILE *fp; X{ X int processed = 0; /* number of processed binscii segments */ X int status = 0; /* return codes of calls to decode */ X X while (myfgets(buf, BUFLEN, fp) != NULL) { X X#if defined(DEBUG) X fprintf(stderr, "(%s) get start:%s", infilename, buf); X#endif X X if (!strncmp(buf, BINSCII_HEADER, strlen(BINSCII_HEADER))) { X if (!getheader(fp) && !infoflag) /* if header ok and not -v flag */ X status |= decode(fp); X processed++; X } X } X X if (processed == 0) { X error("not a BinSCII file"); X return 1; X } X X return status; X X} /* sciibin */ X X X X/* X * Build the alphabet, get the output file info and open output file X * if necessary. X * Still contains lots of debug code to find out the header structure. X * (every bit is known now...) X */ Xgetheader(fp) XFILE *fp; X{ X register int i, j; X register int16 crc = 0; X struct stat statbuf; /* MUST know if file exists */ X char *iomod; /* write or readwrite a file */ X X /* X * Get the alphabet X */ X if (myfgets(buf, BUFLEN, fp) == NULL) { X error("reading alphabet: unexpected end of file"); X return 1; X } X X#if defined(DEBUG) X fprintf(stderr, "(%s) alphabet:%s", infilename, buf); X#endif X X if (strlen(buf) != 65) { X error("alphabet corrupted"); X return 1; X } X X /* X * Process the alphabet X */ X for (i = 0; i < BUFLEN; i++) X alphabet[i] = 0xff; X X for (i = 0; i < 64; i++) { X j = buf[i]; X if (alphabet[j] != 0xff) X error("Warning: double character in alphabet"); X alphabet[j] = i; X } X X#if defined(DEBUG) X for (i = 0; i < BUFLEN; i+=16) { X fprintf(stderr, "(%s) alphabet[%3d] =", infilename, i); X for (j = 0; j < 16; j++) X fprintf(stderr, " %02X", alphabet[i+j]); X putc('\n', stderr); X } X#endif X X /* X * Get the file header X */ X if (myfgets(buf, BUFLEN, fp) == NULL) { X error("reading fileheader: unexpected end of file"); X return 1; X } X X#if defined(DEBUG) X fprintf(stderr, "(%s) fileheader:%s", infilename, buf); X#endif X X /* X * Extract output filename if needed X */ X if (!outflag) { X namlen = *buf - 'A' + 1; /* IS +1 NEEDED ?? */ X#if defined(MSDOS) X memset(outfilename, NULL, FILENAME_LEN + 1); X#endif X strncpy(outfilename, buf+1, namlen); X outfilename[namlen] = '\0'; X } X X#if defined(DEBUG) X fprintf(stderr, "(%s) filename:**%s**\n", infilename, outfilename); X fprintf(stderr, "(%s) fileinfo:**%s**", infilename, buf+16); X#endif X X /* X * Decode and process the file header information X */ X if ((i = decodestring(buf+FILENAME_LEN+1, dec)) != 27) X error("warning: corrupted file header length"); X X for (i = 0; i < 24; i++) X crc = updcrc(dec[i], crc); X X if (crc != (dec[24] | (dec[25] << 8))) { X if (crcok) X error("warning: CRC error in file header"); X else { X error("error: CRC error in file header"); X return 1; X } X } X X /* Calculate file length */ X filesize = dec[0] + (dec[1]<<8) + ((long) dec[2]<<16); X startbyte = dec[3] + (dec[4]<<8) + ((long) dec[5]<<16); X X /* Calculate file attributes and size */ X file_access= dec[6]; X filetype = dec[7]; X auxtype = dec[8] + (dec[9] << 8); X stortype = dec[10]; X numblocks = dec[11] + (dec[12]<<8); X X /* Calculate creation and modification dates */ X#define MOD 13 X#define CRE 17 /* perhaps creation and modification date are swapped */ X creday = dec[CRE] & 0x1f; X cremonth = ((dec[CRE+1] & 0x01) << 3) | (dec[CRE] >> 5); X creyear = dec[CRE+1] >>1; X cremin = dec[CRE+2] & 0x3f; X crehour = dec[CRE+3] & 0x1f; X modday = dec[MOD] & 0x1f; X modmonth = ((dec[MOD+1] & 0x01) << 3) | (dec[MOD] >> 5); X modyear = dec[MOD+1] >>1; X modmin = dec[MOD+2] & 0x3f; X modhour = dec[MOD+3] & 0x1f; X X segmentlen = dec[21] + (dec[22]<<8) + ((long) dec[23]<<16); X if (segmentlen > MAXSEGLEN) X error("warning: segmentlen probably to long"); X X#define READ 0x01 X#define WRITE 0x02 X#define BACKUP 0x20 X#define RENAME 0x40 X#define DESTROY 0x80 X X if (infoflag) { X X /* Display the files name, type and auxtype */ X printf("%-15s %3s aux: $%04X ", X outfilename, filetypes[filetype], auxtype); X X /* Display the file access type */ X putchar(file_access & READ ? 'r' : '-'); X putchar(file_access & WRITE ? 'w' : '-'); X putchar(file_access & RENAME ? 'n' : '-'); X putchar(file_access & DESTROY ? 'd' : '-'); X putchar(file_access & BACKUP ? 'b' : '-'); X X /* Display the type of file this is - ProDOS Specific */ X switch (stortype) { X case 0x0F : printf(" voldir"); break; X case 0x0D : printf(" dir"); break; X case 0x01 : printf(" seed"); break; X case 0x02 : printf(" sap"); break; X case 0x03 : printf(" tree"); break; X default : printf(" ???"); break; X } X X /* Display modification and creation information */ X printf(" %02d/%02d/%02d(%02d:%02d) -", modmonth, modday, modyear, X modhour, modmin); X printf(" %02d/%02d/%02d(%02d:%02d)\n", cremonth, creday, creyear, X crehour, cremin); X X /* Display segment information */ X printf("Part %4d of %4d,", (int) (startbyte / MAXSEGLEN) + 1, X (int) ((filesize + MAXSEGLEN-1) / MAXSEGLEN)); X printf(" bytes %7ld to %7ld of %7ld bytes, %5d blocks\n", X startbyte, startbyte+segmentlen, filesize, numblocks); X X } /* if (infoflag) */ X X if (makeoutput) { X /* will creating output, not just information so verify the access */ X#if defined(MSDOS) X iomod = (stat(outfilename, &statbuf) == 0) ? "r+b" : "wb"; X#else X iomod = (stat(outfilename, &statbuf) == 0) ? "r+" : "w"; X#endif X if ((outfp = fopen(outfilename, iomod)) == NULL) { X error("unable to open output file"); X perror(outfilename); X return 1; X } X fseek(outfp, startbyte, 0); X } /* if (makeoutput) */ X X return 0; X X} /* getheader */ X X X X/* X * Do the actual decoding of the bin data. X */ Xdecode(fp) XFILE *fp; X{ X register int i; X register int crc = 0; X int len; X X crc = 0; X while (segmentlen > 0) { X if (myfgets(buf, BUFLEN, fp) == NULL) { X error("reading file: unexpected end of file"); X return 1; X } X X#if defined(DEBUG) X fprintf(stderr, "(%s) data:%s", infilename, buf); X#endif X X if ((len = decodestring(buf, dec)) != 48) X error("warning: corrupted line length"); X for (i = 0; i < 48; i++) X crc = updcrc(dec[i], crc); X if (makeoutput) X for (i = 0; (i < len) && (segmentlen > 0); i++, segmentlen--) X putc(dec[i], outfp); /* COULD CR/NL TXT FILES */ X else X segmentlen -= len; X X#if defined(DEBUG) X fprintf(stderr, "(%s) still need %d bytes\n", infilename, segmentlen); X#endif X X } X X /* X * must be at end of segment now, with one remaining line containing X * the crc check. X */ X if (myfgets(buf, BUFLEN, fp) == NULL) { X error("reading file crc: unexpected end of file"); X return 1; X } X X#if defined(DEBUG) X fprintf(stderr, "(%s) crc:%s", infilename, buf); X#endif X X if ((len = decodestring(buf, dec)) != 3) X error("warning: corrupted crc length"); X if (crc != (dec[0] | (dec[1] << 8))) { X if (crcok) X error("warning: CRC error in file data"); X else { X error("error: CRC error in file data"); X return 1; X } X } X X if (makeoutput) X fclose(outfp); X X return 0; X X} /* decode */ X X X/* X * Decode one string off scii characters to binary data, meanwhile X * calculating crc. X */ Xdecodestring(in, out) Xregister char *in; Xregister unsigned char *out; X{ X register int len = 0; X X#if defined(DEBUGALL) X char *b; X X fprintf(stderr, "(%s) decode in: %s\n", infilename, in); X b = in; X while (*b) X fprintf(stderr, ".%02X", alphabet[*b++]); X putc('\n', stderr); X b = out; X#endif X X while (strlen(in) > 3) { X *out++ = ((alphabet[in[3]] << 2) | (alphabet[in[2]] >> 4)) & 0xFF; X *out++ = ((alphabet[in[2]] << 4) | (alphabet[in[1]] >> 2)) & 0xFF; X *out++ = ((alphabet[in[1]] << 6) | (alphabet[in[0]])) & 0xFF; X len += 3; X in += 4; X } X X *out = '\0'; X if (*in != '\0' && *in != '\n') X error("warning: line not ended by NULL or NEWLINE"); X X#if defined(DEBUGALL) X fprintf(stderr, "(%s) decode out:\n", infilename); X while (b != out) X fprintf(stderr, ".%02X", *b++); X putc('\n', stderr); X#endif X X return len; X X} /* decodestring */ X X X Xchar *myfgets(buf, len, fp) Xchar *buf; Xint len; XFILE *fp; X{ X X linecount++; X X return fgets(buf, len, fp); X X} /* myfgets */ X X X Xvoid usage() X{ X X fprintf(stderr, "%s\n\n", copyright); X fprintf(stderr, "Usage: sciibin [-vtch] [-o] \n\n"); X fprintf(stderr, " -v show only info on file, do not create output.\n"); X fprintf(stderr, " -t test file, do not create output.\n"); X fprintf(stderr, " -c do not check checksums.\n"); X fprintf(stderr, " -o create given filename instead of the one in\n"); X fprintf(stderr, " binscii file. Use this only if the input files\n"); X fprintf(stderr, " contain only one output file.\n"); X fprintf(stderr, " -h this help message.\n"); X X} /* usage */ X X X Xvoid error(str) Xchar *str; X{ X X fprintf(stderr, "%s (%s, %d): %s\n", X progname, infilename, linecount, str); X X} /* error */ X END_OF_FILE if test 19112 -ne `wc -c <'sciibin.c'`; then echo shar: \"'sciibin.c'\" unpacked with wrong size! fi # end of 'sciibin.c' fi if test -f 'unbit.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'unbit.c'\" else echo shar: Extracting \"'unbit.c'\" \(2053 characters\) sed "s/^X//" >'unbit.c' <<'END_OF_FILE' X/* X * unbit.c X * X * By Marcel J.E. Mol duteca!marcel X * marcel@duteca.tudelft.nl X * X * I hereby place this program into public domain ... X * ... all those all those if and whats etc.... X * I'm completely unresponsible for any damage this program may cause you, X * anyone, or anything else. X * X * X * Unbit expects a 6 bit encoding scheme of executioner output. X * Remove all stuff from the 'call -151' to 'F00G', and the last X * few lines containing the 'BSAVE ...' stuff. Fed the resulting X * ascii encoded data through unbit resulting in the binaru data. X * Thus each line in the input file should look something like this: X * X * 0A474CE30600AC02030053B2320F54B21E15020099030006444154452E430000 X * X * Usage: The program reads from a file or stdin, and outputs to X * stdout. I usually use the program as follows: X * X * unbit file.ex > file.blu X */ X X#include X#if defined(MSDOS) X# include X#endif X Xchar * copyright = "@(#) unbit.c 2.2 26/03/90 (c) M.J.E. Mol"; X Xmain(argc, argv) Xint argc; Xchar **argv; X{ X FILE *fp; X X if ((argc == 1) || (!strcmp(argv[1], "-"))) { X#if defined(MSDOS) X setmode(fileno(stdout), O_BINARY); X#endif X fp = stdin; X } X else { X#if defined(MSDOS) X if ((fp = fopen(argv[1], "rb")) == NULL) { X#else X if ((fp = fopen(argv[1], "r")) == NULL) { X#endif X perror(argv[1]); X exit(1); X } X } X X unbit(fp); X X exit(0); X X} /* main */ X X X Xunbit(fp) XFILE *fp; X{ X int c, co; X X while ((c = getc(fp)) != EOF) { X if ((c != ' ') && (c != '\n')) { X if ((c>='0') && (c<='9')) c-= '0'; X else if ((c>='a') && (c<='f')) c = c - 'a' + 10; X else if ((c>='A') && (c<='F')) c = c - 'A' + 10; X else fprintf(stderr, "illegal char %c\n",c); X co = c << 4; X c = getc(fp); X if ((c>='0') && (c<='9')) c-= '0'; X else if ((c>='a') && (c<='f')) c = c - 'a' + 10; X else if ((c>='A') && (c<='F')) c = c - 'A' + 10; X else fprintf(stderr, "illegal char %c\n",c); X co += c; X putchar(co); X } X } X X} /* unbit */ X END_OF_FILE if test 2053 -ne `wc -c <'unbit.c'`; then echo shar: \"'unbit.c'\" unpacked with wrong size! fi # end of 'unbit.c' fi if test -f 'unblu.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'unblu.c'\" else echo shar: Extracting \"'unblu.c'\" \(10165 characters\) sed "s/^X//" >'unblu.c' <<'END_OF_FILE' X/* @(#) unblu.c 2.2 18/06/89 */ X/************************************************************************* X ** ** X ** Name : unblu ** X ** Author : Marcel J.E. Mol ** X ** Date : 10/05/88 (first release) ** X ** Version : 2.20 ** X ** Files : unblu.c Main source file ** X ** ** X ** ------------------------- Revision List ------------------------- ** X ** Ver Date Name Remarks ** X ** 1.00 10/05/88 Marcel Mol Raw copy of a basic program** X ** 2.00 03/06/88 Marcel Mol Rewrite after blu info ** X ** was send to the net ** X ** 2.10 18/06/88 Marcel Mol Added filetype texts ** X ** 2.20 23/09/88 Marcel Mol Show mod and creation time ** X ** ** X ** ================================================================= ** X ** ** X ** Compile as follows: cc unblu.c -Oso unblu ** X ** ** X ** Usage: unblu [-vh] [] ** X ** ** X ************************************************************************/ X X /************************************************************************ X ** ** X ** NAME ** X ** unblu - Extract files from an apple binary ][ archive. ** X ** ** X ** ** X ** SYNOPSIS ** X ** unblu [-vh] arcfile [files-to-extract] ** X ** ** X ** ** X ** DESCRIPTION ** X ** Unblu list the contents of a binary ][ archive (the -v option) ** X ** or extracts the listed files from the archive (without the ** X ** -v option). If no files are listed, the comlete archive is ** X ** extracted or listed. ** X ** The -h option gives a help message on the usage of unblu. ** X ** ** X ** AUTHOR ** X ** Marcel J.E. Mol ** X ** ** X ** BUGS ** X ** Mail bugs to: marcel@duteca.tudelft.nl ** X ** ** X ************************************************************************/ X Xchar * copyright = "@(#) unblu.c 2.2 18/06/89 (c) M.J.E. Mol"; X#include X#include X#include "filetype.h" X X#define BUFSIZE 128 /* Blu block length */ X#define DEBUG X X/* Global variables */ Xchar * progname; Xchar * blufile; Xint verbose = 0; X X X/* Function declarations */ Xvoid main (); Xvoid unblu (); Xvoid process_file (); Xvoid extract_file (); Xvoid print_global_info (); Xint want (); Xvoid usage (); Xvoid printhelp (); X X Xvoid main(argc, argv) Xint argc; Xchar ** argv; X{ X int flag; /* Flag for getopt */ X int bfd; /* File descriptor for blu file */ X extern int optind; /* For getopt */ X extern char * optarg; /* For getopt */ X X progname = argv[0]; X while ((flag = getopt(argc, argv, "vh")) != EOF) { /* Process options */ X switch (flag) { X case 'v': verbose = 1; /* Want only listing of archive */ X break; X case 'h': usage(); /* Give help */ X printhelp(); X exit(0); X default : fprintf(stderr, "%s: skipping unkown flag %c.\n", X progname, flag); X break; X } X } X X if (optind >= argc) { /* No archive given */ X usage(); X exit(1); X } X X blufile = argv[optind++]; /* Get archive name */ X if ((bfd = open(blufile, O_RDONLY)) == -1) { X perror(blufile); X exit(2); X } X X unblu(bfd, &argv[optind]); /* Process wanted files */ X X close(bfd); X X exit(0); X X} /* main */ X X X/* X * unblu -- process a binary II file fd, and process the filenames X * listed in wated. If wanted is \0, all files are processed. X */ Xvoid unblu(fd, wanted) Xint fd; Xchar ** wanted; X{ X unsigned char buf[BUFSIZE]; X int firstblock = 1; /* First block needs special processing */ X int tofollow = 1; /* Files to follow in the archive */ X int n; X X while (tofollow && ((n = read(fd, buf, BUFSIZE)) != -1)) { X /* If there is a header block */ X if (n != BUFSIZE) { X fprintf(stderr, "%s: %s file size is broken\n", progname, blufile); X exit(1); X } X if ((buf[0] != 10) || (buf[1] != 71) || X (buf[2] != 76) || (buf[18] != 2)) { X fprintf(stderr, "%s: %s not a binary II file\n", progname, blufile); X exit(1); X } X tofollow = buf[127]; /* How many files to follow */ X if (firstblock && verbose) { X print_global_info(buf); X firstblock = 0; X } X process_file(fd, buf, wanted); /* process the file for it */ X } X return; X X} /* unblu */ X X X/* X * process_file -- retrieve or print file information of file given X * in buf X */ Xvoid process_file(fd, buf, wanted) Xint fd; Xunsigned char * buf; Xchar ** wanted; X{ X int tf; X int ftype; X int dflags; X int fnamelen; X int filelen; X char fname[64]; X int nblocks; X int modyear, modmonth, modday; X int creyear, cremonth, creday; X int modhour, modsec; X int crehour, cresec; X X /* X * Get fileinfo X */ X ftype = buf[4]; /* File type */ X fnamelen = buf[23]; /* filename */ X strncpy(fname, &buf[24], fnamelen); X fname[fnamelen] = '\0'; X dflags = buf[125]; /* Data flags */ X tf = buf[127]; /* Number of files to follow */ X filelen = buf[20] + (buf[21]<<8) + (buf[22]<<16);/* Calculate file length */ X nblocks = (filelen + BUFSIZE-1) / BUFSIZE; X modyear = buf[11] >>1; X modday = buf[10] & 0x1f; X modmonth= ((buf[11] & 0x01) << 3) + (buf[10] >> 5); X modhour = buf[13] & 0x1f; X modsec = buf[12] & 0x3f; X creyear = buf[15] >>1; X creday = buf[14] & 0x1f; X cremonth= ((buf[15] & 0x01) << 3) + (buf[14] >> 5); X crehour = buf[17] & 0x1f; X cresec = buf[16] & 0x3f; X X X if (*wanted == NULL || want(fname, wanted)) { X if (verbose) { /* print file information */ X printf("%-15s %3s", fname, filetypes[ftype]); X printf(" %02d/%02d/%02d(%02d:%02d)", modyear, modmonth, modday, X modhour, modsec); X printf(" - %02d/%02d/%02d(%02d:%02d)", creyear, cremonth, creday, X crehour, cresec); X printf(" %5d bytes ", filelen); X if (dflags == 0) X printf("stored"); X else { X if (dflags & 128) { X printf("squeezed"); X } X if (dflags & 64) { X printf("encrypted"); X } X if (dflags & 1) X printf("packed"); X } X putchar('\n'); X X if (ftype != 15) /* If not a directory */ X lseek(fd, BUFSIZE*nblocks, 1); /* Seek to next file */ X } X else if (ftype != 15) X extract_file(fd, fname, filelen); X } X else if (ftype != 15) /* If not a directory */ X lseek(fd, BUFSIZE*nblocks, 1); /* Seek to next file */ X X return; X X} /* process_file */ X X X/* X * extract_file -- extract file fname from the archive fd. Fname X * comtains filelen bytes. X */ Xvoid extract_file(fd, fname, filelen) Xint fd; Xchar * fname; Xint filelen; X{ X int ofd; X int n; X unsigned char buf[BUFSIZE]; X X printf("x - %s\n", fname); X if ((ofd = open(fname, O_CREAT | O_WRONLY | O_TRUNC, 0644)) == -1) { X /* Open (PRODOS) file */ X perror(fname); X exit(1); X } X X while (filelen > 0) { X if ((n = read(fd, buf, BUFSIZE)) != BUFSIZE) { /* Read 128 bytes */ X fprintf(stderr, "%s: %s file size is broken\n", progname, blufile); X exit(1); X } X write(ofd, buf, (filelen >= BUFSIZE ? BUFSIZE : filelen)); X filelen -= BUFSIZE; X } X X close(ofd); /* Close (PRODOS) file */ X return; X X} /* extract_file */ X X X X/* X * print_global_info -- print global information of the binary II file X */ Xvoid print_global_info(buf) Xunsigned char * buf; X{ X int disk_blocks; X X disk_blocks = buf[117] + (buf[118]<<8) + (buf[119]<<16) + (buf[120]<<24); X printf("%s, by Blu %d, ", blufile, buf[126]); X printf("%d files, using %d blocks\n", buf[127]+1, disk_blocks); X return; X X} /* print_global_info */ X X X X/* X * want -- return 1 if name exists in array wantlist, X * else return 0 X */ Xwant(name, wantlist) Xchar * name; Xchar ** wantlist; X{ X while (*wantlist != NULL) { X if (strcmp(name, *wantlist++) == NULL) X return(1); X } X return(0); X X} /* want */ X X X Xvoid usage() X{ X fprintf(stderr, "usage: %s [-hv] [ ...]\n", X progname); X return; X X} /* usage */ X X X Xvoid printhelp() X{ X fprintf(stderr, "\t-h show this help.\n"); X fprintf(stderr, "\t-v show contents of archive.\n"); X} END_OF_FILE if test 10165 -ne `wc -c <'unblu.c'`; then echo shar: \"'unblu.c'\" unpacked with wrong size! fi # end of 'unblu.c' fi if test -f 'unexec.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'unexec.c'\" else echo shar: Extracting \"'unexec.c'\" \(3019 characters\) sed "s/^X//" >'unexec.c' <<'END_OF_FILE' X X/* X * unexec.c X * X * By Marcel J.E. Mol duteca!marcel X * marcel@duteca.tudelft.nl X * X * I hereby place this program into public domain ... X * ... all those all those if and whats etc.... X * I'm completely unresponsible for any damage this program may cause you, X * anyone, or anything else. X * X * X * Unexec expects a input file consisting of lines which are usually X * entered in the apple monitor. Remove the 'CALL -151' line from the file, X * and the 'BSAVE ..' at the end of the file. Fed the resulting data to X * unexec and binary data is output. When unexec has processed the file, X * it prints the address of the first and last databyte on stderr. The binary X * data contains all the bytes between the first and last address, even X * if no data was in the input file for a specific address (unexec just X * initializes a 64k byte array of zeros). X * Thus each line in the input file looks like: X * X * 01F0: A2 00 A0 10 A9 00 BD 00 20 E8 D0 FA X * X * Usage: The program reads from a file or stdin, and outputs to X * stdout. I usually use the program as follows: X * X * unexec file.ex > binfile X */ X X#include X#include X#if defined(MSDOS) X# include X#endif X Xchar * copyright = "@(#) unexec.c 2.2 26/03/90 (c) M.J.E. Mol"; X Xunsigned char mem[65536]; Xint addr; Xint memmin, memmax; Xint tmp; Xint b; Xunsigned char buf[128]; Xint i; X X Xmain(argc, argv) Xint argc; Xchar **argv; X{ X FILE *fp; X X if ((argc == 1) || (!strcmp(argv[1], "-"))) { X#if defined(MSDOS) X setmode(fileno(stdout), O_BINARY); X#endif X fp = stdin; X } X else { X#if defined(MSDOS) X if ((fp = fopen(argv[1], "rb")) == NULL) { X#else X if ((fp = fopen(argv[1], "r")) == NULL) { X#endif X perror(argv[1]); X exit(1); X } X } X X unexec(fp); X X exit(0); X X} /* main */ X X X Xunexec(fp) XFILE *fp; X{ X addr = -1; X memmin = 100000; X memmax = 0; X tmp = 0; X while (fgets(buf, 128, fp) != NULL) { X i = 0; X while (i <= strlen(buf)) { X if (buf[i] == ':') { X addr = tmp; X if ((addr < memmin) && (addr >= 0)) X memmin = addr; X tmp = 0; X i++; X skipblank(); X } X else if ((isspace(buf[i])) || (buf[i] == '\0')) { X if (tmp > 255) X fprintf(stderr, "Assuming %d to be $FF\n", tmp); X mem[addr++] = tmp; X tmp = 0; X skipblank(); X } X else { X if ((buf[i] >= '0') && (buf[i] <= '9')) X tmp = (tmp << 4) + buf[i] - '0'; X else if ((buf[i] >= 'a') && (buf[i] <= 'f')) X tmp = (tmp << 4) + buf[i] - 'a' + 10; X else if ((buf[i] >= 'A') && (buf[i] <= 'F')) X tmp = (tmp << 4) + buf[i] - 'A' + 10; X else fprintf(stderr, "Illegal character %c\n", buf[i]); X i++; X } X } X if (addr > memmax) X memmax = addr; X } X for (i = memmin; i<= memmax; i++) X putchar(mem[i]); X fprintf(stderr, "Lower address: %x\n", memmin); X fprintf(stderr, "Higher address: %x\n", memmax); X X} /* unexec */ X X X Xskipblank() X{ X X while ((isspace(buf[i]) || (buf[i] == '\0')) && i <= strlen(buf)) X i++; X X} /* skipblank */ X END_OF_FILE if test 3019 -ne `wc -c <'unexec.c'`; then echo shar: \"'unexec.c'\" unpacked with wrong size! fi # end of 'unexec.c' fi if test -f 'usq.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'usq.c'\" else echo shar: Extracting \"'usq.c'\" \(7875 characters\) sed "s/^X//" >'usq.c' <<'END_OF_FILE' X X/* X * usq.c X * X * By Marcel J.E. Mol duteca!marcel X * marcel@duteca.tudelft.nl X * X * I hereby place this program into public domain ... X * ... all those all those if and whats etc.... X * I'm completely unresposible for any damage this program may cause you. X * X * Usq unsqueezes a file squeezed with the apple sq3 program. X * Files extracted from a binary 2 file (using unblu for example) X * with a .QQ or .Q extensing are probably squeezed files. X * X * Usage: The program reads from a file or stdin, and outputs to X * the filename stored in the squeezed file. X * So use the program as follows: X * X * usq file.QQ X * X * Remember that the newline character on apple is different from Unix. X * Thus files extracted with unblu, and possibly unsqueezed with usq X * may have an ^M character instead of a \n character at the end of each line. X * To create a proper Unix file use the following 'tr' command: X * X * tr '\015' '\012' < applefile > unixfile X * X * This program is based on the unsqueeze program in the unix/PC X * ARC utility. X */ X X/* X * Squeezed file format: X * 2 bytes MAGIC X * 2 bytes dummy ??? X * filename ended by \0 X * 2 bytes node count X * node count node values, each 2 bytes X * squeezed data per byte X */ X X#include X#if defined(MSDOS) X# include X#endif X X#define BUFSIZE 128 X#define MAGIC 0xff76 /* Squeezed file magic */ X#define DLE 0x90 /* repeat byte flag */ X#define NOHIST 0 /* no relevant history */ X#define INREP 1 /* sending a repeated value */ X#define SPEOF 256 /* special endfile token */ X#define NUMVALS 257 /* 256 data values plus SPEOF */ X Xchar * copyright = "@(#) usq.c 2.1 18/06/88 (c) M.J.E. Mol"; X X/* X * Global variable declarations X */ Xchar *progname; Xchar *sfn; /* squeezed file name */ Xstruct nd { /* decoding tree */ X int child[2]; /* left, right */ X} node[NUMVALS]; /* use large buffer */ Xint state; /* repeat unpacking state */ Xint bpos; /* last bit position read */ Xint curin; /* last byte value read */ Xint numnodes; /* number of nodes in decode tree */ X X X/* X * Functions declarations X */ Xvoid main (); Xint unsqueeze (); Xvoid putc_ncr (); Xint get_int (); Xint init_usq (); Xint getc_usq (); X X X Xvoid main(argc, argv) Xint argc; Xchar ** argv; X{ X X FILE *fp; /* File pointer for squeezed file */ X register int r = 0; /* Exit value */ X X progname = *argv; X X if (argc == 1) { /* no args; unsqueeze standard input */ X#if defined(MSDOS) X setmode(fileno(stdin), O_BINARY); X#endif X unsqueeze(stdin); X } X else /* unsqueeze each file in arglist */ X while (--argc > 0) { X sfn = *++argv; X#if defined(MSDOS) X if ((fp = fopen(sfn, "rb")) == NULL) { X#else X if ((fp = fopen(sfn, "r")) == NULL) { X#endif X perror(sfn); X continue; X } X r |= unsqueeze(fp); X fclose(fp); X } X X exit(r); X X} /* main */ X X X Xint unsqueeze(sfp) XFILE *sfp; X{ X register int i; X register int c; /* one char of stream */ X char fname[BUFSIZE]; X int magic; X register FILE *dfp; X X magic = get_int(sfp); X#if defined(DEBUG) X fprintf(stderr, "Magic number: %x\n", magic); X#endif X if (magic != MAGIC) { /* Check magic number */ X fprintf(stderr, "%s: %s not a squeezed file\n", progname, sfn); X fprintf(stderr, "Wrong magic number: %x\n", magic); X return(1); X } X (void) get_int(sfp); /* two dummy bytes ??? */ X i = 0; /* get the original file name */ X while ((fname[i++] = getc(sfp)) != NULL) X ; X X#if defined(MSDOS) /* open destination file */ X if ((dfp = fopen(fname, "wb")) == NULL) { X#else X if ((dfp = fopen(fname, "w")) == NULL) { X#endif X perror(fname); X return(1); X } X X state = NOHIST; /* initial repeat unpacking state */ X X if (init_usq(sfp)) /* init unsqueeze algorithm */ X return 1; X while ((c=getc_usq(sfp)) != EOF) /* and unsqueeze file */ X putc_ncr(c, dfp); X X return 0; /* file is okay */ X X} /* unsqueeze */ X X X X X/* putc-ncr -- decode non-repeat compression. Bytes are passed one X * at a time in coded format, and are written out uncoded. X * The data is stored normally, except that runs of more X * than two characters are represented as: X * X * X * X * With a special case that a count of zero indicates a DLE X * as data, not as a repeat marker. X */ Xvoid putc_ncr(c, t) /* put NCR coded bytes */ Xunsigned char c; /* next byte of stream */ XFILE *t; /* file to receive data */ X{ X static int lastc; /* last character seen */ X X switch (state) { /* action depends on our state */ X case NOHIST: /* no previous history */ X if (c==DLE) /* if starting a series */ X state = INREP; /* then remember it next time */ X else putc(lastc=c, t); /* else nothing unusual */ X return; X X case INREP: /* in a repeat */ X if (c) /* if count is nonzero */ X while (--c) /* then repeatedly ... */ X putc(lastc, t); /* ... output the byte */ X else putc(DLE, t); /* else output DLE as data */ X state = NOHIST; /* back to no history */ X return; X X default: X fprintf(stderr, "%s: bad NCR unpacking state (%d)", X progname, state); X } X X} /* putc_ncr */ X X X X Xint get_int(f) /* get an integer */ XFILE *f; /* file to get it from */ X{ X X return getc(f) | (getc(f) << 8); X X} /* get_int */ X X X Xint init_usq(f) /* initialize Huffman unsqueezing */ XFILE *f; /* file containing squeezed data */ X{ X register int i; /* node index */ X X bpos = 99; /* force initial read */ X X numnodes = get_int(f); /* get number of nodes */ X X if (numnodes<0 || numnodes>=NUMVALS) { X fprintf(stderr, "%s: %s file has an invalid decode tree", X progname, sfn); X return 1; X } X X /* initialize for possible empty tree (SPEOF only) */ X X node[0].child[0] = -(SPEOF + 1); X node[0].child[1] = -(SPEOF + 1); X X for (i=0; i=0); )/* work down(up?) from root */ X { X if (++bpos > 7) { X if ((curin=getc(f)) == EOF) X return(EOF); X bpos = 0; X X /* move a level deeper in tree */ X i = node[i].child[1 & curin]; X } X else i = node[i].child[1 & (curin >>= 1)]; X } X X /* decode fake node index to original data value */ X i = i | 0xffff0000; /* Unix hack: have 32 bits instead of 16 */ X i = -(i + 1); X X X /* decode special endfile token to normal EOF */ X return ((i==SPEOF) ? EOF : i); X X} /* getc_usq */ END_OF_FILE if test 7875 -ne `wc -c <'usq.c'`; then echo shar: \"'usq.c'\" unpacked with wrong size! fi # end of 'usq.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 need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- ######################################### # Marcel J.E. Mol ###################################### # Delft University of Technology Pink Elephant Management Services # # The Netherlands Voorburg # # UUCP: marcel@duteca.et.tudelft.nl Tel: 070-3694231 # # (Tel prive: 070-3361515) # ##############################################################################