home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / arcppc / src / rcs / arcusq.c,v < prev    next >
Text File  |  1998-04-23  |  4KB  |  179 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    hyc:1.2; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     88.06.02.16.27.44;  author hyc;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     88.04.11.18.45.37;  author hyc;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @Minor fixes & speedups
  27. @
  28. text
  29. @/*
  30.  * $Header: arcusq.c,v 1.4 88/04/18 14:52:09 hyc Locked $
  31.  */
  32.  
  33. /*
  34.  * ARC - Archive utility - ARCUSQ
  35.  * 
  36.  * Version 3.14, created on 07/25/86 at 13:04:19
  37.  * 
  38.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  39.  * 
  40.  * By:  Thom Henderson
  41.  * 
  42.  * Description: This file contains the routines used to expand a file which was
  43.  * packed using Huffman squeezing.
  44.  * 
  45.  * Most of this code is taken from an USQ program by Richard Greenlaw, which was
  46.  * adapted to CI-C86 by Robert J. Beilstein.
  47.  * 
  48.  * Language: Computer Innovations Optimizing C86
  49.  */
  50. #include <stdio.h>
  51. #include "arc.h"
  52.  
  53. void    abort();
  54. int    getc_unp();
  55.  
  56. /* stuff for Huffman unsqueezing */
  57.  
  58. #define ERROR (-1)
  59.  
  60. #define SPEOF 256        /* special endfile token */
  61. #define NUMVALS 257        /* 256 data values plus SPEOF */
  62.  
  63. extern    struct nd {        /* decoding tree */
  64.     int    child[2];    /* left, right */
  65. }               node[NUMVALS];    /* use large buffer */
  66.  
  67. static int      bpos;        /* last bit position read */
  68. static int      curin;        /* last byte value read */
  69. static int      numnodes;    /* number of nodes in decode tree */
  70.  
  71. static          short
  72. get_int(f)            /* get a 16bit integer */
  73.     FILE           *f;    /* file to get it from */
  74. {
  75.     int    i,j;
  76.     i = getc_unp(f);
  77.     j = getc_unp(f) << 8;
  78.     return (i | j) & 0xFFFF;
  79. }
  80.  
  81. void
  82. init_usq(f)            /* initialize Huffman unsqueezing */
  83.     FILE           *f;    /* file containing squeezed data */
  84. {
  85.     int             i;    /* node index */
  86.  
  87.     bpos = 99;        /* force initial read */
  88.  
  89.     numnodes = get_int(f);
  90.  
  91.     if (numnodes < 0 || numnodes >= NUMVALS)
  92.         abort("File has an invalid decode tree");
  93.  
  94.     /* initialize for possible empty tree (SPEOF only) */
  95.  
  96.     node[0].child[0] = -(SPEOF + 1);
  97.     node[0].child[1] = -(SPEOF + 1);
  98.  
  99.     for (i = 0; i < numnodes; ++i) {    /* get decoding tree from
  100.                          * file */
  101.         node[i].child[0] = get_int(f);
  102.         node[i].child[1] = get_int(f);
  103.     }
  104. }
  105.  
  106. int
  107. getc_usq(f)            /* get byte from squeezed file */
  108.     FILE           *f;    /* file containing squeezed data */
  109. {
  110.     int             i;    /* tree index */
  111.  
  112.     /* follow bit stream in tree to a leaf */
  113.  
  114.     for (i = 0; i >= 0;) {    /* work down(up?) from root */
  115.         if (++bpos > 7) {
  116.             if ((curin = getc_unp(f)) == ERROR)
  117.                 return (ERROR);
  118.             bpos = 0;
  119.  
  120.             /* move a level deeper in tree */
  121.             i = node[i].child[1 & curin];
  122.         } else
  123.             i = node[i].child[1 & (curin >>= 1)];
  124.     }
  125.  
  126.     /* decode fake node index to original data value */
  127.  
  128.     i = -(i + 1);
  129.  
  130.     /* decode special endfile token to normal EOF */
  131.  
  132.     i = (i == SPEOF) ? EOF : i;
  133.     return i;
  134. }
  135. @
  136.  
  137.  
  138. 1.1
  139. log
  140. @Initial revision
  141. @
  142. text
  143. @d2 1
  144. a2 7
  145.  * $Log:        arcusq.c,v $
  146.  * Revision 1.3  87/08/13  17:06:12  hyc
  147.  * Run thru indent, fixed some signed vs. unsigned problems
  148.  * with bp <-> buf, and inbuf and localbuf...
  149.  *  Revision 1.2  87/07/21  09:31:43  hyc *** empty
  150.  * log message ***
  151.  * 
  152. d25 3
  153. d35 2
  154. a36 2
  155. struct nd {            /* decoding tree */
  156.     INT             child[2];    /* left, right */
  157. d39 3
  158. a41 3
  159. static INT      bpos;        /* last bit position read */
  160. static INT      curin;        /* last byte value read */
  161. static INT      numnodes;    /* number of nodes in decode tree */
  162. d43 2
  163. a44 2
  164. static          INT
  165. get_int(f)            /* get an integer */
  166. d47 4
  167. a50 1
  168.     return getc_unp(f) | (getc_unp(f) << 8);
  169. d53 1
  170. a53 1
  171. INT
  172. d57 1
  173. a57 1
  174.     INT             i;    /* node index */
  175. d71 1
  176. a71 1
  177.     for (i = 0; i < numnodes; ++i) {    /* get decoding tree from *
  178. @
  179.