home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / macutils.lzh / MACUTILS / MACUNPACK / jdw.c < prev    next >
C/C++ Source or Header  |  1995-09-18  |  4KB  |  161 lines

  1. #include "macunpack.h"
  2. #ifdef JDW
  3. #include "jdw.h"
  4. #include "globals.h"
  5. #include "huffman.h"
  6. #include "../fileio/wrfile.h"
  7. #include "../fileio/machdr.h"
  8. #include "../util/util.h"
  9. #include "../util/masks.h"
  10.  
  11. extern void de_huffman();
  12. extern void set_huffman();
  13. extern void read_tree();
  14. extern void clrhuff();
  15.  
  16. static void jdw_wrfile();
  17. static void jdw_wrfork();
  18. static void jdw_block();
  19.  
  20. void jdw(ibytes)
  21. unsigned long ibytes;
  22. {
  23.     char fauth[5], ftype[5];
  24.     int filel, i;
  25.     unsigned int rsrcLength, dataLength;
  26.  
  27.     set_huffman(HUFF_BE);
  28.     for(i = 0; i < 6; i++) (void)getb(infp);
  29.     for(i = 0; i < INFOBYTES; i++) {
  30.     info[i] = 0;
  31.     }
  32.     for(i = 0; i < 4; i++) {
  33.     info[I_TYPEOFF + i] = getb(infp);
  34.     }
  35.     for(i = 0; i < 4; i++) {
  36.     info[I_AUTHOFF + i] = getb(infp);
  37.     }
  38.     for(i = 0; i < 8; i++) {
  39.     info[I_FLAGOFF + i] = getb(infp);
  40.     }
  41.     for(i = 0; i < 4; i++) {
  42.     info[I_DLENOFF + i] = getb(infp);
  43.     }
  44.     for(i = 0; i < 4; i++) {
  45.     info[I_RLENOFF + i] = getb(infp);
  46.     }
  47.     for(i = 0; i < 4; i++) {
  48.     info[I_CTIMOFF + i] = getb(infp);
  49.     }
  50.     for(i = 0; i < 4; i++) {
  51.     info[I_MTIMOFF + i] = getb(infp);
  52.     }
  53.     filel = getb(infp);
  54.     info[I_NAMEOFF] = filel;
  55.     i = filel;
  56.     for(i = 1; i <= filel; i++) {
  57.     info[I_NAMEOFF + i] = getb(infp);
  58.     }
  59.     (void)getb(infp);
  60.     rsrcLength = get4(info + I_RLENOFF);
  61.     dataLength = get4(info + I_DLENOFF);
  62.     ibytes -= filel + 40;
  63.     write_it = 1;
  64.     if(list) {
  65.     transname(info + I_NAMEOFF + 1, text, (int)info[I_NAMEOFF]);
  66.     transname(info + I_TYPEOFF, ftype, 4);
  67.     transname(info + I_AUTHOFF, fauth, 4);
  68.     do_indent(indent);
  69.     (void)fprintf(stderr,
  70.         "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  71.         text, ftype, fauth, (long)dataLength, (long)rsrcLength);
  72.     if(info_only) {
  73.         write_it = 0;
  74.     }
  75.     if(query) {
  76.         write_it = do_query();
  77.     } else {
  78.         (void)fputc('\n', stderr);
  79.     }
  80.     }
  81.     jdw_wrfile((unsigned long)rsrcLength, (unsigned long)dataLength);
  82. }
  83.  
  84. static void jdw_wrfile(rsrcLength, dataLength)
  85. unsigned long rsrcLength, dataLength;
  86. {
  87.     if(write_it) {
  88.     define_name(text);
  89.     start_info(info, rsrcLength, dataLength);
  90.     start_data();
  91.     }
  92.     if(verbose) {
  93.     (void)fprintf(stderr, "\tData: ");
  94.     }
  95.     jdw_wrfork(dataLength);
  96.     if(write_it) {
  97.     start_rsrc();
  98.     }
  99.     if(verbose) {
  100.     (void)fprintf(stderr, ", Rsrc: ");
  101.     }
  102.     jdw_wrfork(rsrcLength);
  103.     if(write_it) {
  104.     end_file();
  105.     }
  106.     if(verbose) {
  107.     (void)fprintf(stderr, ".\n");
  108.     }
  109. }
  110.  
  111. static void jdw_wrfork(length)
  112. unsigned long length;
  113. {
  114.     int olength, ilength, i;
  115.     unsigned long origlength, comprlength;
  116.  
  117.     if(length == 0) {
  118.     (void)fprintf(stderr, "empty");
  119.     return;
  120.     }
  121.     (void)fprintf(stderr, "Huffman compressed ");
  122.     comprlength = 0;
  123.     origlength = length;
  124.     while(length > 0) {
  125.     olength = getb(infp) & BYTEMASK;
  126.     olength = (olength << 8) | (getb(infp) & BYTEMASK);
  127.     ilength = getb(infp) & BYTEMASK;
  128.     ilength = (ilength << 8) | (getb(infp) & BYTEMASK);
  129.     if(write_it) {
  130.         jdw_block(olength);
  131.     } else {
  132.         for(i = 0; i < ilength; i++) {
  133.         (void)getb(infp);
  134.         }
  135.     }
  136.     comprlength += ilength + 4;
  137.     length -= olength;
  138.     }
  139.     if(verbose) {
  140.     (void)fprintf(stderr, "(%4.1f%%)", 100.0 * comprlength / origlength);
  141.     }
  142. }
  143.  
  144. static void jdw_block(olength)
  145. int olength;
  146. {
  147.     bytesread = 0;
  148.     read_tree();
  149.     /* Put reading back at a word boundary! */
  150.     while(bytesread & 3) {
  151.     (void)getb(infp);
  152.     bytesread++;
  153.     }
  154.     clrhuff();
  155.     de_huffman((unsigned long)olength);
  156. }
  157. #else /* JDW */
  158. int jdw; /* keep lint and some compilers happy */
  159. #endif /* JDW */
  160.  
  161.