home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / apple2 / 45 < prev    next >
Encoding:
Internet Message Format  |  1991-02-17  |  27.8 KB

  1. From: jac@paul.rutgers.edu (Jonathan A. Chandross)
  2. Newsgroups: comp.sources.apple2
  3. Subject: v001SRC027:  Unix Archiving Tools (Part 1/2)
  4. Message-ID: <Feb.16.22.43.35.1991.3102@paul.rutgers.edu>
  5. Date: 17 Feb 91 03:43:36 GMT
  6. Approved: jac@paul.rutgers.edu
  7.  
  8.  
  9. Submitted-by: marcel@duteca.tudelft.nl
  10. Posting-number: Volume 1, Source:27
  11. Archive-name: archive/unix/marcel/part1
  12. Architecture: UNIX
  13. Version-number: 1.00
  14.  
  15. This package contains Unix versions of the following tools: 
  16.     unbit    - undoes the 6-bit executioner format.
  17.     unexec   - undoes the apple2 monitor format.
  18.     unblu    - view and extract from binary 2 archives.
  19.     usq      - usqueeze squeezed files (created by sq3 or
  20.            extracted from binary 2 or shrinkit archives).
  21.     sciibin  - view and extract from binscii files.
  22.  
  23. NOTE: This is part 1 of a 2 part posting.
  24.  
  25. =README
  26. -Here are a bunch of C programs to process different kind
  27. -of files containing Apple stuff.
  28. -No functional changes from the previous versions. Only some cleanups and
  29. -ports to other machines/OS like MSDOS and Macintosh.
  30. -
  31. -The programs are:
  32. -
  33. -unbit    - undoes the 6-bit executioner format.
  34. -unexec   - undoes the apple2 monitor format.
  35. -unblu    - view and extract from binary 2 archives.
  36. -usq      - usqueeze squeezed files (created by sq3 or
  37. -           extracted from binary 2 or shrinkit archives).
  38. -sciibin  - view and extract from binscii files.
  39. -
  40. -
  41. -Use this for example to extract apple files posted
  42. -to the comp.binaries.apple2 newsgroup in one of the
  43. -above formats.
  44. -I use it to extract for example binary 2  or shrinkit
  45. -archives (with Andy Mccfaden's nulib) which can easily
  46. -be transfered to the Apple as binary files.
  47. -It also allows me to print doc files on a laser printer...
  48. -This saves me telephone costs and time.
  49. -
  50. -- Marcel              marcel@duteca.tudelft.nl
  51. -#########################################
  52. -# Marcel J.E. Mol                       ######################################
  53. -# Delft University of Technology          Pink Elephant Management Services  #
  54. -# The Netherlands                         Voorburg                           #
  55. -# UUCP: marcel@duteca.tudelft.nl          Tel: 070-694231                    #
  56. -#                                          ######################################
  57. -#########################################
  58. -
  59. -Version 1.00
  60. =Manifest
  61. -Makefile
  62. -README
  63. -crc.h
  64. -filetype.h
  65. -getopt.c
  66. -sciibin.c
  67. -unbit.c
  68. -unblu.c
  69. -unexec.c
  70. -usq.c
  71. =Makefile
  72. -CFLAGS    = -s
  73. -
  74. -
  75. -all: usq unblu unexec unbit sciibin
  76. -
  77. -usq: usq.o
  78. -    cc $(CFLAGS) -o $@ $? 
  79. -
  80. -unexec: unexec.o
  81. -    cc $(CFLAGS) -o $@ $?
  82. -
  83. -unblu: unblu.o
  84. -    cc $(CFLAGS) -o $@ $?
  85. -
  86. -unbit: unbit.o
  87. -    cc $(CFLAGS) -o $@ $?
  88. -
  89. -sciibin: sciibin.o
  90. -    cc $(CFLAGS) -o $@ $?
  91. -
  92. -unblu.c: filetype.h
  93. -sciibin.c: filetype.h crc.h
  94. =crc.h
  95. -/*
  96. - * updcrc macro derived from article Copyright (C) 1986 Stephen Satchell. 
  97. - *  NOTE: First srgument must be in range 0 to 255.
  98. - *        Second argument is referenced twice.
  99. - * 
  100. - * Programmers may incorporate any or all code into their programs, 
  101. - * giving proper credit within the source. Publication of the 
  102. - * source routines is permitted so long as proper credit is given 
  103. - * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, 
  104. - * Omen Technology.
  105. - */
  106. -
  107. - /* #define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp) */
  108. -#define updcrc(cp, crc) ( (crctab[((crc >> 8) & 0xFF) ^ cp] ^ (crc << 8)) & 0xFFFF)
  109. -
  110. -
  111. -/* crctab calculated by Mark G. Mendel, Network Systems Corporation */
  112. -static unsigned short crctab[256] = {
  113. -    0x0000,  0x1021,  0x2042,  0x3063,  0x4084,  0x50a5,  0x60c6,  0x70e7,
  114. -    0x8108,  0x9129,  0xa14a,  0xb16b,  0xc18c,  0xd1ad,  0xe1ce,  0xf1ef,
  115. -    0x1231,  0x0210,  0x3273,  0x2252,  0x52b5,  0x4294,  0x72f7,  0x62d6,
  116. -    0x9339,  0x8318,  0xb37b,  0xa35a,  0xd3bd,  0xc39c,  0xf3ff,  0xe3de,
  117. -    0x2462,  0x3443,  0x0420,  0x1401,  0x64e6,  0x74c7,  0x44a4,  0x5485,
  118. -    0xa56a,  0xb54b,  0x8528,  0x9509,  0xe5ee,  0xf5cf,  0xc5ac,  0xd58d,
  119. -    0x3653,  0x2672,  0x1611,  0x0630,  0x76d7,  0x66f6,  0x5695,  0x46b4,
  120. -    0xb75b,  0xa77a,  0x9719,  0x8738,  0xf7df,  0xe7fe,  0xd79d,  0xc7bc,
  121. -    0x48c4,  0x58e5,  0x6886,  0x78a7,  0x0840,  0x1861,  0x2802,  0x3823,
  122. -    0xc9cc,  0xd9ed,  0xe98e,  0xf9af,  0x8948,  0x9969,  0xa90a,  0xb92b,
  123. -    0x5af5,  0x4ad4,  0x7ab7,  0x6a96,  0x1a71,  0x0a50,  0x3a33,  0x2a12,
  124. -    0xdbfd,  0xcbdc,  0xfbbf,  0xeb9e,  0x9b79,  0x8b58,  0xbb3b,  0xab1a,
  125. -    0x6ca6,  0x7c87,  0x4ce4,  0x5cc5,  0x2c22,  0x3c03,  0x0c60,  0x1c41,
  126. -    0xedae,  0xfd8f,  0xcdec,  0xddcd,  0xad2a,  0xbd0b,  0x8d68,  0x9d49,
  127. -    0x7e97,  0x6eb6,  0x5ed5,  0x4ef4,  0x3e13,  0x2e32,  0x1e51,  0x0e70,
  128. -    0xff9f,  0xefbe,  0xdfdd,  0xcffc,  0xbf1b,  0xaf3a,  0x9f59,  0x8f78,
  129. -    0x9188,  0x81a9,  0xb1ca,  0xa1eb,  0xd10c,  0xc12d,  0xf14e,  0xe16f,
  130. -    0x1080,  0x00a1,  0x30c2,  0x20e3,  0x5004,  0x4025,  0x7046,  0x6067,
  131. -    0x83b9,  0x9398,  0xa3fb,  0xb3da,  0xc33d,  0xd31c,  0xe37f,  0xf35e,
  132. -    0x02b1,  0x1290,  0x22f3,  0x32d2,  0x4235,  0x5214,  0x6277,  0x7256,
  133. -    0xb5ea,  0xa5cb,  0x95a8,  0x8589,  0xf56e,  0xe54f,  0xd52c,  0xc50d,
  134. -    0x34e2,  0x24c3,  0x14a0,  0x0481,  0x7466,  0x6447,  0x5424,  0x4405,
  135. -    0xa7db,  0xb7fa,  0x8799,  0x97b8,  0xe75f,  0xf77e,  0xc71d,  0xd73c,
  136. -    0x26d3,  0x36f2,  0x0691,  0x16b0,  0x6657,  0x7676,  0x4615,  0x5634,
  137. -    0xd94c,  0xc96d,  0xf90e,  0xe92f,  0x99c8,  0x89e9,  0xb98a,  0xa9ab,
  138. -    0x5844,  0x4865,  0x7806,  0x6827,  0x18c0,  0x08e1,  0x3882,  0x28a3,
  139. -    0xcb7d,  0xdb5c,  0xeb3f,  0xfb1e,  0x8bf9,  0x9bd8,  0xabbb,  0xbb9a,
  140. -    0x4a75,  0x5a54,  0x6a37,  0x7a16,  0x0af1,  0x1ad0,  0x2ab3,  0x3a92,
  141. -    0xfd2e,  0xed0f,  0xdd6c,  0xcd4d,  0xbdaa,  0xad8b,  0x9de8,  0x8dc9,
  142. -    0x7c26,  0x6c07,  0x5c64,  0x4c45,  0x3ca2,  0x2c83,  0x1ce0,  0x0cc1,
  143. -    0xef1f,  0xff3e,  0xcf5d,  0xdf7c,  0xaf9b,  0xbfba,  0x8fd9,  0x9ff8,
  144. -    0x6e17,  0x7e36,  0x4e55,  0x5e74,  0x2e93,  0x3eb2,  0x0ed1,  0x1ef0
  145. -};
  146. -
  147. =filetype.h
  148. -char * filetypes[] = {
  149. -    "non", "bad", "pcd", "ptx", "txt", "pda", "bin", "chr",
  150. -    "pic", "ba3", "da3", "wpd", "sos", "$0D", "$0E", "dir",
  151. -    "rpd", "rpi", "$12", "out", "$14", "rpt", "$16", "$17",
  152. -    "$18", "adb", "awp", "asp", "$1C", "$1D", "$1E", "$1F",
  153. -    "$20", "$21", "$22", "$23", "$24", "$25", "$26", "$27",
  154. -    "$28", "$29", "$2A", "$2B", "$2C", "$2D", "$2E", "$2F",
  155. -    "$30", "$31", "$32", "$33", "$34", "$35", "$36", "$37",
  156. -    "$38", "$39", "$3A", "$3B", "$3C", "$3D", "$3E", "$3F",
  157. -    "$40", "$41", "$42", "$43", "$44", "$45", "$46", "$47",
  158. -    "$48", "$49", "$4A", "$4B", "$4C", "$4D", "$4E", "$4F",
  159. -    "$50", "$51", "$52", "$53", "$54", "$55", "$56", "$57",
  160. -    "$58", "$59", "$5A", "$5B", "$5C", "$5D", "$5E", "$5F",
  161. -    "pre", "$61", "$62", "$63", "$64", "$65", "$66", "$67",
  162. -    "$68", "$69", "$6A", "nio", "$6C", "dvr", "$6E", "hdv",
  163. -    "$70", "$71", "$72", "$73", "$74", "$75", "$76", "$77",
  164. -    "$78", "$79", "$7A", "$7B", "$7C", "$7D", "$7E", "$7F",
  165. -    "$80", "$81", "$82", "$83", "$84", "$85", "$86", "$87",
  166. -    "$88", "$89", "$8A", "$8B", "$8C", "$8D", "$8E", "$8F",
  167. -    "$90", "$91", "$92", "$93", "$94", "$95", "$96", "$97",
  168. -    "$98", "$99", "$9A", "$9B", "$9C", "$9D", "$9E", "$9F",
  169. -    "wpf", "mac", "hlp", "dat", "$A4", "lex", "$A6", "$A7",
  170. -    "$A8", "$A9", "$AA", "gsb", "arc", "$AD", "$AE", "$AF",
  171. -    "src", "obj", "lib", "s16", "rtl", "exe", "str", "tsf",
  172. -    "nda", "cda", "tol", "drv", "$BC", "fst", "$BE", "doc",
  173. -    "pnt", "scr", "ani", "$C3", "$C4", "$C5", "$C6", "$C7",
  174. -    "fon", "fnd", "icn", "$CB", "$CC", "$CD", "$CE", "$CF",
  175. -    "$D0", "$D1", "$D2", "$D3", "$D4", "$D5", "$D6", "$D7",
  176. -    "$D8", "$D9", "$DA", "$DB", "$DC", "$DD", "$DE", "$DF",
  177. -    "lbr", "$E1", "ati", "$E3", "$E4", "$E5", "$E6", "$E7",
  178. -    "$E8", "$E9", "$EA", "$EB", "$EC", "$ED", "$EE", "pas",
  179. -    "cmd", "$F1", "$F2", "$F3", "$F4", "$F5", "$F6", "$F7",
  180. -    "$F8", "img", "int", "ivr", "bas", "var", "rel", "sys",
  181. -    };
  182. -
  183. -/*
  184. -ProDOS Filetypes
  185. -
  186. -Num    Name    OS    Meaning
  187. -========================================================================
  188. -$00            typeless
  189. -$01    BAD    both    BAD blocks file
  190. -$02    PCD    SOS    Pascal CoDe file
  191. -$03    PTX    SOS    Pascal TeXt file
  192. -$04    TXT    both    ASCII text file
  193. -$05    PDA    SOS    Pascal DAta file
  194. -$06    BIN    both    BINary file
  195. -$07    CHR    SOS    CHaRacter font file
  196. -$08    PIC    both    PICture file
  197. -$09    BA3    SOS    Business BASIC (SOS) program file
  198. -$0A    DA3    SOS    Business BASIC (SOS) data file
  199. -$0B    WPD    SOS    Word Processor Document
  200. -$0C    SOS    SOS    SOS system file
  201. -$0D        SOS    SOS reserved file type
  202. -$0E        SOS    SOS reserved file type
  203. -$0F    DIR    Both    subDIRectory file
  204. -$10    RPD    SOS    RPS data file
  205. -$11    RPI    SOS    RPS index file
  206. -$12        SOS    Applefile diskcard file
  207. -$13        SOS    Applefile model file
  208. -$14        SOS    Applefile report format file
  209. -$15        SOS    Screen library file
  210. -$16        SOS    SOS reserved file type
  211. -$17        SOS    SOS reserved file type
  212. -$18        SOS    SOS reserved file type
  213. -$19    ADB    ProDOS    AppleWorks Database file
  214. -$1A    AWP    ProDOS    AppleWorks WordProcessing file
  215. -$1B    ASP    ProDOS    AppleWorks Spreadsheet file
  216. -$1C-$5F            Reserved
  217. -$60-$6F        ProDOS    PC Transporter (Applied Engineering) reserved filetypes
  218. - $60    PRE    ProDOS    ProDOS preboot driver
  219. - $61-$6A    ProDOS    Reserved
  220. - $6B    NIO    ProDOS    PC Transporter BIOS and drivers
  221. - $6C        ProDOS    Reserved
  222. - $6D    DVR    ProDOS    PC Transporter device drivers
  223. - $6E        ProDOS    Reserved
  224. - $6F    HDV    ProDOS    MSDOS HardDisk Volume
  225. -$70-$9F            Reserved
  226. -$A0    WPF    ProDOS    WordPerfect document file
  227. -$A1    MAC    ProDOS    Macrofile
  228. -$A2    HLP    ProDOS    Help File
  229. -$A3    DAT    ProDOS    Data File
  230. -$A4            Reserved
  231. -$A5    LEX    ProDOS    Spelling dictionary
  232. -$A6-$AB            Reserved
  233. -$AC    ARC    ProDOS    General Purpose Archive file
  234. -$AD-$AF            Reserved
  235. -$B0    SRC    ProDOS    ORCA/M & APW source file
  236. -$B1    OBJ    ProDOS    ORCA/M & APW object file
  237. -$B2    LIB    ProDOS    ORCA/M & APW library file
  238. -$B3    S16    ProDOS    ProDOS16 system file
  239. -$B4    RTL    ProDOS    ProDOS16 runtime library
  240. -$B5    EXE    ProDOS    APW shell command file
  241. -$B6    STR    ProDOS    ProDOS16 startup init file
  242. -$B7    TSF    ProDOS    ProDOS16 temporary init file
  243. -$B8    NDA    ProDOS    ProDOS16 new desk accessory
  244. -$B9    CDA    ProDOS    ProDOS16 classic desk accessory
  245. -$BA    TOL    ProDOS    ProDOS16 toolset file
  246. -$BB    DRV    ProDOS    ProDOS16 driver file
  247. -$BC            Reserved for ProDOS16 load file
  248. -$BD    FST        ???
  249. -$BC            Reserved for ProDOS16 load file
  250. -$BF    DOC    ProDOS    document file
  251. -$C0    PNT    ProDOS    //gs paint document
  252. -$C1    SCR    ProDOS    //gs screen file
  253. -$C2    ANI        ???
  254. -$C3-$C7            Reserved
  255. -$C8    FNT    ProDOS    Printer font file
  256. -$C9    FND    ProDOS    finder files
  257. -$CA    ICN    ProDOS    finder icons
  258. -$CB-$DF            Reserved
  259. -$E0    LBR    ProDOS    Apple archive library file
  260. -$E1            Unknown (unlisted)
  261. -$E2    ATI    ProDOS    Appletalk init file
  262. -$E3-$EE            Reserved
  263. -$EF    PAS    ProDOS    ProDOS Pascal file
  264. -$F0    CMD    ProDOS    added command file
  265. -$F1-$F8        ProDOS    User defined filetypes (popular ones include:)
  266. - $F1    OVL    ProDOS    Overlay file
  267. - $F2    DBF    ProDOS    Database file
  268. - $F3    PAD    ProDOS    MouseWrite file
  269. - $F4    MCR    ProDOS    AE Pro macro file
  270. - $F5    ECP    ProDOS    ECP batch file
  271. - $F6    DSC    ProDOS    description file
  272. - $F7    TMP    ProDOS    temporary work file
  273. - $F8    RSX    ProDOS    linkable object module
  274. -$F9    IMG    ProDOS    ProDOS image file
  275. -$FA    INT    ProDOS    Integer BASIC program
  276. -$FB    IVR    ProDOS    Integer BASIC variables file
  277. -$FC    BAS    ProDOS    AppleSoft BASIC program
  278. -$FD    VAR    ProDOS    AppleSoft BASIC variables file
  279. -$FE    REL    ProDOS    ProDOS EDASM relocatable object module file
  280. -$FF    SYS    ProDOS    ProDOS8 system file
  281. -*/
  282. -
  283. =getopt.c
  284. -/*
  285. -* The official AT&T public domain version of getopt(3).
  286. -*/
  287. -#include <stdio.h>
  288. -
  289. -int  optopt;                                              /* For getopt */
  290. -int  opterr = 1;                                          /* For getopt */
  291. -int  optind = 1;                                          /* For getopt */
  292. -char *optarg;                                             /* For getopt */
  293. -
  294. -#define ERR(s, c) \
  295. -    if (opterr) {   \
  296. -        extern int strlen(), write();   \
  297. -        char       errbuf[2];           \
  298. -        errbuf[0] = c; errbuf[1] = '\n';\
  299. -        (void) write(2, argv[0], (unsigned) strlen(argv[0])); \
  300. -        (void) write(2, s, (unsigned) strlen(s));\
  301. -        (void) write(2, errbuf, 2);\
  302. -    }
  303. -
  304. -int getopt(argc, argv, opstring)
  305. -int   argc;
  306. -char  **argv,
  307. -     *opstring;
  308. -{
  309. -    static int    sp = 1;
  310. -    register int  c;
  311. -    register char *cp;
  312. -
  313. -    if (sp == 1)
  314. -        if (optind >= argc ||
  315. -            argv[optind][0] != '-' ||
  316. -            argv[optind][1] == '\0')
  317. -            return (EOF);
  318. -        else
  319. -            if (strcmp(argv[optind], "--") == NULL) {
  320. -                optind++;
  321. -                return (EOF);
  322. -            }
  323. -
  324. -    optopt = c = argv[optind][sp];
  325. -    if (c == ':' ||
  326. -        (cp = strchr(opstring, c)) == NULL) {
  327. -        ERR(": illegal option -- ", c);
  328. -        if (argv[optind][++sp] == '\0') {
  329. -           optind++;
  330. -           sp = 1;
  331. -        }
  332. -
  333. -        return ('?');
  334. -    }
  335. -
  336. -    if (*++cp == ':') {
  337. -        if (argv[optind][sp+1] != '\0')
  338. -            optarg = &argv[optind++][sp+1];
  339. -        else
  340. -            if (++optind >= argc) {
  341. -                ERR(": option requires an argument -- ", c);
  342. -                sp = 1;
  343. -                return ('?');
  344. -            }
  345. -            else
  346. -                optarg = argv[optind++];
  347. -
  348. -        sp = 1;
  349. -    }
  350. -    else {
  351. -        if (argv[optind][++sp] == '\0') {
  352. -            sp = 1;
  353. -            optind++;
  354. -        }
  355. -
  356. -        optarg = NULL;
  357. -    }
  358. -
  359. -    return (c);
  360. -
  361. -} /* getopt */
  362. -
  363. -
  364. -#if (0)
  365. -/*
  366. -* My own version of the UNIX getopt function for non-UNIX systems.  It is not
  367. -*  a fully functioning getopt but it will suffice for most anything
  368. -*/
  369. -int getopt(argc, argv, opstring)
  370. -int   argc;
  371. -char  **argv,
  372. -     *opstring;
  373. -{
  374. -    int   option = -1,                         /* Option to be returned    */
  375. -          index = 0,                           /* Index into opstring      */
  376. -          get_args = 0,                        /* Boolean to flag arg val. */
  377. -          found = 0,                           /* Boolean flag found flag  */
  378. -          loop;                                /* Loop counter for parsing */
  379. -    char  flag = NULL;                         /* Flag/option to check for */
  380. -
  381. -    optarg = NULL;
  382. -
  383. -    /* Check for no arguments */
  384. -    if (argc == 1)
  385. -        return(option);
  386. -
  387. -    if (argv[optind][0] != '-')
  388. -        return(option);
  389. -
  390. -    flag = opstring[index++];
  391. -    if (opstring[index] == ':')
  392. -        get_args = 1;
  393. -
  394. -    /* Scan 'next' argument until the last one */
  395. -    for (loop = optind; !found; ) {
  396. -        if (flag == argv[loop][1]) {
  397. -            if (get_args)
  398. -                optarg = (char *) argv[loop] + 2;
  399. -
  400. -            option = argv[loop][1];
  401. -            optind = loop + 1;
  402. -            found = 1;
  403. -        }
  404. -
  405. -        if (!found) {
  406. -            /* Didnt match so check next character in opstring */
  407. -            flag = opstring[index++];
  408. -
  409. -            /* Check to see if at end of opstring yet */
  410. -            if (flag == NULL)
  411. -                return ('?');
  412. -
  413. -            if (opstring[index] == ':')
  414. -                get_args = 1;
  415. -            else
  416. -                get_args = 0;
  417. -        }
  418. -    } /* for (loop = 1; loop < argc; loop++) */
  419. -
  420. -    return(option);
  421. -
  422. -} /* end getopt */
  423. -#endif
  424. =unbit.c
  425. -/*
  426. - * unbit.c
  427. - *
  428. - * By Marcel J.E. Mol               duteca!marcel
  429. - *                                  marcel@duteca.tudelft.nl
  430. - *
  431. - * I hereby place this program into public domain ...
  432. - *  ...  all those all those if and whats etc....
  433. - * I'm completely unresponsible for any damage this program may cause you,
  434. - * anyone, or anything else.
  435. - *
  436. - *
  437. - * Unbit expects a 6 bit encoding scheme of executioner output.
  438. - * Remove all stuff from the 'call -151' to 'F00G', and the last 
  439. - * few lines containing the 'BSAVE ...' stuff. Fed the resulting 
  440. - * ascii encoded data through unbit resulting in the binaru data.
  441. - * Thus each line in the input file should look something like this:
  442. - *
  443. - *     0A474CE30600AC02030053B2320F54B21E15020099030006444154452E430000
  444. - *
  445. - * Usage: The program reads from a file or stdin, and outputs to
  446. - *        stdout. I usually use the program as follows:
  447. - *
  448. - *           unbit  file.ex  > file.blu
  449. - */
  450. -
  451. -#include <stdio.h>
  452. -#if defined(MSDOS)
  453. -# include <fcntl.h>
  454. -#endif
  455. -
  456. -char * copyright = "@(#) unbit.c  2.2 26/03/90  (c) M.J.E. Mol";
  457. -
  458. -main(argc, argv)
  459. -int argc;
  460. -char **argv;
  461. -{
  462. -    FILE *fp;
  463. -
  464. -    if ((argc == 1) || (!strcmp(argv[1], "-"))) {
  465. -#if defined(MSDOS)
  466. -        setmode(fileno(stdout), O_BINARY);
  467. -#endif
  468. -        fp = stdin;
  469. -    }
  470. -    else {
  471. -#if defined(MSDOS)
  472. -        if ((fp = fopen(argv[1], "rb")) == NULL) {
  473. -#else
  474. -    if ((fp = fopen(argv[1], "r")) == NULL) {
  475. -#endif
  476. -        perror(argv[1]);
  477. -        exit(1);
  478. -    }
  479. -    }
  480. -
  481. -    unbit(fp);
  482. -
  483. -    exit(0);
  484. -
  485. -} /* main */
  486. -
  487. -
  488. -
  489. -unbit(fp)
  490. -FILE *fp;
  491. -{
  492. -    int c, co;
  493. -
  494. -    while ((c = getc(fp)) != EOF) {
  495. -        if ((c != ' ') && (c != '\n')) {
  496. -            if ((c>='0') && (c<='9')) c-= '0';
  497. -            else if ((c>='a') && (c<='f')) c = c - 'a' + 10;
  498. -            else if ((c>='A') && (c<='F')) c = c - 'A' + 10;
  499. -            else fprintf(stderr, "illegal char %c\n",c);
  500. -            co = c << 4;
  501. -            c = getc(fp);
  502. -            if ((c>='0') && (c<='9')) c-= '0';
  503. -            else if ((c>='a') && (c<='f')) c = c - 'a' + 10;
  504. -            else if ((c>='A') && (c<='F')) c = c - 'A' + 10;
  505. -            else fprintf(stderr, "illegal char %c\n",c);
  506. -            co += c;
  507. -            putchar(co);
  508. -        }
  509. -    }
  510. -
  511. -} /* unbit */
  512. -
  513. =unexec.c
  514. -
  515. -/*
  516. - * unexec.c
  517. - *
  518. - * By Marcel J.E. Mol               duteca!marcel
  519. - *                                  marcel@duteca.tudelft.nl
  520. - *
  521. - * I hereby place this program into public domain ...
  522. - *  ...  all those all those if and whats etc....
  523. - * I'm completely unresponsible for any damage this program may cause you,
  524. - * anyone, or anything else.
  525. - *
  526. - *
  527. - * Unexec expects a input file consisting of lines which are usually
  528. - * entered in the apple monitor. Remove the 'CALL -151' line from the file,
  529. - * and the 'BSAVE ..' at the end of the file. Fed the resulting data to
  530. - * unexec and binary data is output. When unexec has processed the file,
  531. - * it prints the address of the first and last databyte on stderr. The binary
  532. - * data contains all the bytes between the first and last address, even
  533. - * if no data was in the input file for a specific address (unexec just
  534. - * initializes a 64k byte array of zeros).
  535. - * Thus each line in the input file looks like:
  536. - *
  537. - *    01F0: A2 00 A0 10 A9 00 BD 00 20 E8 D0 FA
  538. - *
  539. - * Usage: The program reads from a file or stdin, and outputs to
  540. - *        stdout. I usually use the program as follows:
  541. - *
  542. - *           unexec  file.ex  > binfile
  543. - */
  544. -
  545. -#include <stdio.h>
  546. -#include <ctype.h>
  547. -#if defined(MSDOS)
  548. -# include <fcntl.h>
  549. -#endif
  550. -
  551. -char * copyright = "@(#) unexec.c  2.2 26/03/90  (c) M.J.E. Mol";
  552. -
  553. -unsigned char mem[65536];
  554. -int addr;
  555. -int memmin, memmax;
  556. -int tmp;
  557. -int b;
  558. -unsigned char buf[128];
  559. -int i;
  560. -
  561. -
  562. -main(argc, argv)
  563. -int argc;
  564. -char **argv;
  565. -{
  566. -    FILE *fp;
  567. -
  568. -    if ((argc == 1) || (!strcmp(argv[1], "-"))) {
  569. -#if defined(MSDOS)
  570. -        setmode(fileno(stdout), O_BINARY);
  571. -#endif
  572. -    fp = stdin;
  573. -    }
  574. -    else {
  575. -#if defined(MSDOS)
  576. -        if ((fp = fopen(argv[1], "rb")) == NULL) {
  577. -#else
  578. -    if ((fp = fopen(argv[1], "r")) == NULL) {
  579. -#endif
  580. -        perror(argv[1]);
  581. -        exit(1);
  582. -    }
  583. -    }
  584. -
  585. -    unexec(fp);
  586. -
  587. -    exit(0);
  588. -    
  589. -} /* main */
  590. -
  591. -
  592. -
  593. -unexec(fp)
  594. -FILE *fp;
  595. -{
  596. -    addr = -1;
  597. -    memmin = 100000;
  598. -    memmax = 0;
  599. -    tmp = 0;
  600. -    while (fgets(buf, 128, fp) != NULL) {
  601. -    i = 0;
  602. -    while (i <= strlen(buf)) {
  603. -        if (buf[i] == ':') {
  604. -        addr = tmp;
  605. -        if ((addr < memmin) && (addr >= 0))
  606. -            memmin = addr;
  607. -        tmp = 0;
  608. -        i++;
  609. -        skipblank();
  610. -        }
  611. -        else if ((isspace(buf[i])) || (buf[i] == '\0')) {
  612. -        if (tmp > 255) 
  613. -            fprintf(stderr, "Assuming %d to be $FF\n", tmp);
  614. -        mem[addr++] = tmp;
  615. -        tmp = 0;
  616. -        skipblank();
  617. -        }
  618. -        else {
  619. -        if ((buf[i] >= '0') && (buf[i] <= '9'))
  620. -            tmp = (tmp << 4) + buf[i] - '0';
  621. -        else if ((buf[i] >= 'a') && (buf[i] <= 'f'))
  622. -            tmp = (tmp << 4) + buf[i] - 'a' + 10;
  623. -        else if ((buf[i] >= 'A') && (buf[i] <= 'F'))
  624. -            tmp = (tmp << 4) + buf[i] - 'A' + 10;
  625. -        else fprintf(stderr, "Illegal character %c\n", buf[i]);
  626. -        i++;
  627. -        }
  628. -    }
  629. -    if (addr > memmax)
  630. -        memmax = addr;
  631. -    }
  632. -    for (i = memmin; i<= memmax; i++) 
  633. -    putchar(mem[i]);
  634. -    fprintf(stderr, "Lower address: %x\n", memmin);
  635. -    fprintf(stderr, "Higher address: %x\n", memmax);
  636. -
  637. -} /* unexec */
  638. -
  639. -
  640. -
  641. -skipblank()
  642. -{
  643. -
  644. -        while ((isspace(buf[i]) || (buf[i] == '\0')) && i <= strlen(buf))
  645. -        i++;
  646. -
  647. -} /* skipblank */
  648. -    
  649. =usq.c
  650. -
  651. -/*
  652. - * usq.c
  653. - *
  654. - * By Marcel J.E. Mol           duteca!marcel
  655. - *                              marcel@duteca.tudelft.nl
  656. - *
  657. - * I hereby place this program into public domain ...
  658. - *  ...  all those all those if and whats etc....
  659. - * I'm completely unresposible for any damage this program may cause you.
  660. - *
  661. - * Usq unsqueezes a file squeezed with the apple sq3 program.
  662. - * Files extracted from a binary 2 file (using unblu for example)
  663. - * with a .QQ or .Q extensing are probably squeezed files.
  664. - *
  665. - * Usage: The program reads from a file or stdin, and outputs to
  666. - *        the filename stored in the squeezed file.
  667. - *        So use the program as follows:
  668. - *
  669. - *           usq  file.QQ 
  670. - *
  671. - * Remember that the newline character on apple is different from Unix.
  672. - * Thus files extracted with unblu, and possibly unsqueezed with usq
  673. - * may have an ^M character instead of a \n character at the end of each line.
  674. - * To create a proper Unix file use the following 'tr' command:
  675. - *
  676. - *        tr '\015'  '\012' < applefile > unixfile
  677. - *
  678. - * This program is based on the unsqueeze program in the unix/PC 
  679. - * ARC utility.
  680. - */
  681. -
  682. -/* 
  683. - * Squeezed file format:
  684. - *     2 bytes MAGIC
  685. - *     2 bytes dummy ???
  686. - *     filename ended by \0
  687. - *     2 bytes node count
  688. - *     node count node values, each 2 bytes
  689. - *     squeezed data per byte
  690. - */
  691. -
  692. -#include <stdio.h>
  693. -#if defined(MSDOS)
  694. -# include <fcntl.h>
  695. -#endif
  696. -
  697. -#define BUFSIZE        128
  698. -#define MAGIC        0xff76           /* Squeezed file magic */
  699. -#define DLE        0x90           /* repeat byte flag */
  700. -#define NOHIST        0              /* no relevant history */
  701. -#define INREP        1              /* sending a repeated value */
  702. -#define SPEOF        256            /* special endfile token */
  703. -#define NUMVALS        257            /* 256 data values plus SPEOF */
  704. -
  705. -char * copyright = "@(#) usq.c  2.1 18/06/88  (c) M.J.E. Mol";
  706. -
  707. -/*
  708. - * Global variable declarations
  709. - */
  710. -char *progname;
  711. -char *sfn;                   /* squeezed file name */
  712. -struct nd {                            /* decoding tree */
  713. -    int child[2];                      /* left, right */
  714. -}   node[NUMVALS];                     /* use large buffer */
  715. -int state;                             /* repeat unpacking state */
  716. -int bpos;                              /* last bit position read */
  717. -int curin;                             /* last byte value read */
  718. -int numnodes;                          /* number of nodes in decode tree */
  719. -
  720. -
  721. -/*
  722. - * Functions declarations
  723. - */
  724. -void main      ();
  725. -int  unsqueeze ();
  726. -void putc_ncr  ();
  727. -int  get_int   ();
  728. -int  init_usq  ();
  729. -int  getc_usq  ();
  730. -
  731. -
  732. -
  733. -void main(argc, argv)
  734. -int argc;
  735. -char ** argv;
  736. -{
  737. -    
  738. -    FILE *fp;                 /* File pointer for squeezed file */
  739. -    register int r = 0;            /* Exit value */
  740. -
  741. -    progname = *argv;
  742. -
  743. -    if (argc == 1) {                    /* no args; unsqueeze standard input */
  744. -#if defined(MSDOS)
  745. -        setmode(fileno(stdin), O_BINARY);
  746. -#endif
  747. -        unsqueeze(stdin);
  748. -    }
  749. -    else                /* unsqueeze each file in arglist */
  750. -        while (--argc > 0) {
  751. -        sfn = *++argv;
  752. -#if defined(MSDOS)
  753. -            if ((fp = fopen(sfn, "rb")) == NULL) {
  754. -#else
  755. -        if ((fp = fopen(sfn, "r")) == NULL) {
  756. -#endif
  757. -            perror(sfn);
  758. -            continue;
  759. -        }
  760. -        r |= unsqueeze(fp);
  761. -        fclose(fp);
  762. -    }
  763. -
  764. -    exit(r);
  765. -
  766. -} /* main */
  767. -
  768. -
  769. -
  770. -int unsqueeze(sfp)
  771. -FILE *sfp;
  772. -{
  773. -    register int i;
  774. -    register int c;                     /* one char of stream */
  775. -    char fname[BUFSIZE];
  776. -    int magic;
  777. -    register FILE *dfp;
  778. -
  779. -    magic = get_int(sfp);
  780. -#if defined(DEBUG)
  781. -    fprintf(stderr, "Magic number: %x\n", magic);
  782. -#endif
  783. -    if (magic != MAGIC) {         /* Check magic number */
  784. -    fprintf(stderr, "%s: %s not a squeezed file\n", progname, sfn);
  785. -    fprintf(stderr, "Wrong magic number: %x\n", magic);
  786. -    return(1);
  787. -    }
  788. -    (void) get_int(sfp);        /* two dummy bytes ??? */
  789. -    i = 0;                /* get the original file name */
  790. -    while ((fname[i++] = getc(sfp)) != NULL) 
  791. -    ;
  792. -
  793. -#if defined(MSDOS)                           /* open destination file */
  794. -    if ((dfp = fopen(fname, "wb")) == NULL) {
  795. -#else
  796. -    if ((dfp = fopen(fname, "w")) == NULL) {
  797. -#endif
  798. -        perror(fname);
  799. -        return(1);
  800. -    }
  801. -
  802. -    state = NOHIST;                    /* initial repeat unpacking state */
  803. -
  804. -    if (init_usq(sfp))                /* init unsqueeze algorithm */
  805. -    return 1;
  806. -    while ((c=getc_usq(sfp)) != EOF)   /* and unsqueeze file */
  807. -         putc_ncr(c, dfp);
  808. -
  809. -    return 0;                          /* file is okay */
  810. -
  811. -} /* unsqueeze */
  812. -
  813. -
  814. -
  815. -
  816. -/*  putc-ncr -- decode non-repeat compression.  Bytes are passed one
  817. - *              at a time in coded format, and are written out uncoded.
  818. - *              The data is stored normally, except that runs of more 
  819. - *              than two characters are represented as:
  820. - *
  821. - *                       <char> <DLE> <count>
  822. - *
  823. - *              With a special case that a count of zero indicates a DLE 
  824. - *              as data, not as a repeat marker.
  825. - */
  826. -void putc_ncr(c, t)                    /* put NCR coded bytes */
  827. -unsigned char c;                       /* next byte of stream */
  828. -FILE *t;                               /* file to receive data */
  829. -{
  830. -    static int lastc;         /* last character seen */
  831. -
  832. -    switch (state) {                   /* action depends on our state */
  833. -        case NOHIST:                   /* no previous history */
  834. -            if (c==DLE)                /* if starting a series */
  835. -                 state = INREP;        /* then remember it next time */
  836. -            else putc(lastc=c, t);     /* else nothing unusual */
  837. -            return;
  838. -
  839. -        case INREP:                    /* in a repeat */
  840. -            if (c)                     /* if count is nonzero */
  841. -                while (--c)            /* then repeatedly ... */
  842. -                    putc(lastc, t);    /* ... output the byte */
  843. -            else putc(DLE, t);         /* else output DLE as data */
  844. -            state = NOHIST;            /* back to no history */
  845. -            return;
  846. -
  847. -        default:
  848. -            fprintf(stderr, "%s: bad NCR unpacking state (%d)",
  849. -                progname, state);
  850. -    }
  851. -
  852. -} /* putc_ncr */
  853. -
  854. -
  855. -
  856. -
  857. -int get_int(f)                         /* get an integer */
  858. -FILE *f;                               /* file to get it from */
  859. -{
  860. -   
  861. -    return getc(f) | (getc(f) << 8);
  862. -
  863. -} /* get_int */
  864. -
  865. -
  866. -
  867. -int init_usq(f)                        /* initialize Huffman unsqueezing */
  868. -FILE *f;                               /* file containing squeezed data */
  869. -{
  870. -    register int i;                    /* node index */
  871. -
  872. -    bpos = 99;                         /* force initial read */
  873. -
  874. -    numnodes = get_int(f);             /* get number of nodes */
  875. -
  876. -    if (numnodes<0 || numnodes>=NUMVALS) {
  877. -         fprintf(stderr, "%s: %s file has an invalid decode tree",
  878. -            progname, sfn);
  879. -     return 1;
  880. -    }
  881. -
  882. -    /* initialize for possible empty tree (SPEOF only) */
  883. -
  884. -    node[0].child[0] = -(SPEOF + 1);
  885. -    node[0].child[1] = -(SPEOF + 1);
  886. -
  887. -    for (i=0; i<numnodes; ++i) {        /* get decoding tree from file */
  888. -         node[i].child[0] = get_int(f);
  889. -         node[i].child[1] = get_int(f);
  890. -    }
  891. -
  892. -    return 0;
  893. -
  894. -} /* init_usq */
  895. -
  896. -
  897. -
  898. -
  899. -int getc_usq(f)                        /* get byte from squeezed file */
  900. -FILE *f;                               /* file containing squeezed data */
  901. -{
  902. -    register int i;                    /* tree index */
  903. -
  904. -    /* follow bit stream in tree to a leaf */
  905. -
  906. -    for (i=0; (i < 0x8000) && (i>=0); )/* work down(up?) from root */
  907. -    {  
  908. -     if (++bpos > 7) {
  909. -              if ((curin=getc(f)) == EOF)
  910. -                   return(EOF);
  911. -              bpos = 0;
  912. -
  913. -              /* move a level deeper in tree */
  914. -              i = node[i].child[1 & curin];
  915. -         }
  916. -         else i = node[i].child[1 & (curin >>= 1)];
  917. -    }
  918. -
  919. -    /* decode fake node index to original data value */
  920. -    i = i | 0xffff0000;          /* Unix hack: have 32 bits instead of 16 */
  921. -    i = -(i + 1);
  922. -
  923. -
  924. -    /* decode special endfile token to normal EOF */
  925. -    return ((i==SPEOF) ? EOF : i);
  926. -
  927. -} /* getc_usq */
  928. + END OF ARCHIVE
  929.