home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume06 / u16.pc1 < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  5.2 KB

  1. From decwrl!labrea!eos!ames!mailrus!csd4.milw.wisc.edu!leah!itsgw!steinmetz!uunet!allbery Sun Jan 29 16:45:48 PST 1989
  2. Article 788 of comp.sources.misc:
  3. Path: granite!decwrl!labrea!eos!ames!mailrus!csd4.milw.wisc.edu!leah!itsgw!steinmetz!uunet!allbery
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v06i013: u16 patch 1
  7. Message-ID: <47279@uunet.UU.NET>
  8. Date: 24 Jan 89 03:07:23 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Reply-To: tom@SSD.HARRIS.COM (Tom Horsley)
  11. Lines: 157
  12. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  13.  
  14. Posting-number: Volume 6, Issue 13
  15. Submitted-by: tom@SSD.HARRIS.COM (Tom Horsley)
  16. Archive-name: u16.patch1
  17.  
  18. [This just about clears out the comp.sources.misc queue -- there are 4 more
  19. submissions to go, but they require further thought.  ++bsa]
  20.  
  21. This is patch number 1 (and hopefully patch number last) to the u16
  22. 16 bit uncompress for the PC.
  23. ----------------------------cut here-------------------------------
  24. *** u16.c.orig    Tue Jan  3 15:34:51 1989
  25. --- u16.c    Tue Jan  3 15:34:28 1989
  26. ***************
  27. *** 6,11 ****
  28. --- 6,23 ----
  29.    * Parts written (other parts plagarized) by Tom Horsley
  30.    *   (tahorsley@ssd.harris.com)
  31.    *   Dec 1988.
  32. +  *
  33. +  * Version 1.1
  34. +  *
  35. +  * Bug1 - fixed Dec 22, 1988
  36. +  *   The initial check for end of file that attempted to just use
  37. +  *   the current byte pointer was not good enough. Because the byte
  38. +  *   pointer might look within bounds, but a large code might eat
  39. +  *   some garbage bits beyond the end as it is assembled.
  40. +  *
  41. +  *   The fix was to add a new variable to keep track of the count
  42. +  *   of bits in the buffer and always check to see that there are
  43. +  *   enough bits for at least one new code to be extracted.
  44.    */
  45.   #include <stdio.h>
  46.   #include <fcntl.h>
  47. ***************
  48. *** 82,88 ****
  49.    * message you get with the -H option.
  50.    */
  51.   unsigned char buf[MAXBUF] = "\
  52. ! u16 - 16 bit LZW uncompress for the IBM PC\n\
  53.   u16 [-H] [files...]\n\
  54.   \n\
  55.   -H\tPrint this message and exit.\n\
  56. --- 94,100 ----
  57.    * message you get with the -H option.
  58.    */
  59.   unsigned char buf[MAXBUF] = "\
  60. ! u16 - 16 bit LZW uncompress for the IBM PC, version 1.1\n\
  61.   u16 [-H] [files...]\n\
  62.   \n\
  63.   -H\tPrint this message and exit.\n\
  64. ***************
  65. *** 97,102 ****
  66. --- 109,119 ----
  67.   on the ends of file names.\n"
  68.   ;
  69.   
  70. + /* Number of bits in the buffer.
  71. +  */
  72. + long          bitsinbuf = 0;
  73. + long          n_bits;
  74.   /* Number of bytes of file data resident in buf.
  75.    */
  76.   int          bufsize = 0;
  77. ***************
  78. *** 167,172 ****
  79. --- 184,190 ----
  80.        eofmark = &buf[bufsize];
  81.         } else {
  82.        bufsize += cursize;
  83. +      bitsinbuf += (((long)cursize) << 3);
  84.         }
  85.      }
  86.      if (eofmark == NULL) {
  87. ***************
  88. *** 203,210 ****
  89.          * have recieved a clear code then flush the current size code
  90.          * and advance to next size.
  91.          */
  92. !       while (cb.codep != vartab[curvartab].origp) xcode(&cb);
  93. !       if (cb.bufp >= endbuf) return(-1L);
  94.         if (clear_flg > 0) {
  95.        curvartab = 0;
  96.        clear_flg = 0;
  97. --- 221,230 ----
  98.          * have recieved a clear code then flush the current size code
  99.          * and advance to next size.
  100.          */
  101. !       while (cb.codep != vartab[curvartab].origp) {
  102. !      xcode(&cb);
  103. !      bitsinbuf -= n_bits;
  104. !       }
  105.         if (clear_flg > 0) {
  106.        curvartab = 0;
  107.        clear_flg = 0;
  108. ***************
  109. *** 220,232 ****
  110.         (*vartab[curvartab].initp)(&cb);
  111.         vartab[curvartab].origp = cb.codep;
  112.         maxcode = vartab[curvartab].maxcode;
  113.   #ifdef DEBUG
  114.         fprintf(stderr,
  115.        "switching to %d bit codes, bytes_out = %ld, free_ent = %ld\n",
  116. !      vartab[curvartab].n_bits,bytes_out, free_ent);
  117.   #endif
  118.      }
  119. !    return (long)(xcode(&cb));
  120.   }
  121.   
  122.   /* Decompress stdin to stdout.    This routine adapts to the codes in
  123. --- 240,258 ----
  124.         (*vartab[curvartab].initp)(&cb);
  125.         vartab[curvartab].origp = cb.codep;
  126.         maxcode = vartab[curvartab].maxcode;
  127. +       n_bits = (long)vartab[curvartab].n_bits;
  128.   #ifdef DEBUG
  129.         fprintf(stderr,
  130.        "switching to %d bit codes, bytes_out = %ld, free_ent = %ld\n",
  131. !      n_bits,bytes_out, free_ent);
  132.   #endif
  133.      }
  134. !    bitsinbuf -= n_bits;
  135. !    if (bitsinbuf < 0) {
  136. !       return -1L;
  137. !    } else {
  138. !       return (long) xcode(&cb);
  139. !    }
  140.   }
  141.   
  142.   /* Decompress stdin to stdout.    This routine adapts to the codes in
  143. ***************
  144. *** 270,276 ****
  145. --- 296,304 ----
  146.      /* Read the iniital buffer worth of data and check magic numbers
  147.       * and flags.
  148.       */
  149. +    bitsinbuf = 0;
  150.      ReadBuf();
  151. +    bitsinbuf -= 3 * 8;
  152.      if (bufsize < 3) {
  153.         fputs("u16: Missing file header.\n",stderr);
  154.         return 1;
  155. ***************
  156. *** 298,303 ****
  157. --- 326,332 ----
  158.      /*
  159.       * initialize the first 256 entries in the table.
  160.       */
  161. +    n_bits = vartab[0].n_bits;
  162.      maxcode = vartab[0].maxcode;
  163.      for ( code = 255; code >= 0; code-- ) {
  164.         tab_prefixof(code) = 0;
  165. --------------------------- cut here --------------------------------
  166. =====================================================================
  167.     usenet: tahorsley@ssd.harris.com  USMail: Tom Horsley
  168. compuserve: 76505,364                         511 Kingbird Circle
  169.      genie: T.HORSLEY                         Delray Beach, FL  33444
  170.  
  171.  
  172.