home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / COMPRESS / RLE16_SC.ZIP / UNRLE16.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-14  |  2.2 KB  |  95 lines

  1. /* Run Length Decoder program
  2.  
  3.  * decodes system.rle file that uses 16 bit headers.
  4.  
  5.  *
  6.  
  7.  * written 1991 by Shaun Case in Borland C++ 2.0
  8.  
  9.  * This program and its source code are public domain.
  10.  
  11.  *
  12.  
  13.  * You can't afford not to make the left decision.
  14.  
  15.  */
  16.  
  17.  
  18.  
  19.  
  20.  
  21. #include <stdio.h>
  22.  
  23. #include <string.h>
  24.  
  25. #include "rle16.h"
  26.  
  27.  
  28.  
  29. int main(int argc, char **argv)
  30.  
  31. {
  32.  
  33.     register int byte;
  34.  
  35.     register unsigned short i;
  36.  
  37.     register unsigned short length;
  38.  
  39.     int packet_hdr;
  40.  
  41.     
  42.  
  43.     FILE *infile, *outfile;
  44.  
  45.  
  46.  
  47.     char orig_filename[14]; /* original filename */
  48.  
  49.     char *infile_name;
  50.  
  51.     char scratch_space[134];
  52.  
  53.  
  54.  
  55.     if (argc != 2)
  56.  
  57.     {
  58.  
  59.         puts("Usege: unrle16 filename");
  60.  
  61.         return 1;
  62.  
  63.     }
  64.  
  65.     puts("unlre16   by Shaun Case 1991  public domain");
  66.  
  67.  
  68.  
  69.     infile_name = argv[1];
  70.  
  71.  
  72.  
  73.     if ((infile=fopen(infile_name, "rb")) == NULL)
  74.  
  75.     {
  76.  
  77.         strcpy(scratch_space, "Unable to open ");
  78.  
  79.         strcat(scratch_space, infile_name);
  80.  
  81.         puts(scratch_space);
  82.  
  83.         return 1;
  84.  
  85.     }
  86.  
  87.  
  88.  
  89.     for (i = 0; i < 13; i++)   /* get original filename */
  90.  
  91.         if ((orig_filename[i] = fgetc(infile)) == EOF)
  92.  
  93.         {
  94.  
  95.             puts("Error reading original filename from input file.");
  96.  
  97.             return 1;
  98.  
  99.         }
  100.  
  101.  
  102.  
  103.     if ((outfile=fopen(orig_filename, "wb")) == NULL)
  104.  
  105.     {
  106.  
  107.         strcpy(scratch_space, "Unable to open ");
  108.  
  109.         strcat(scratch_space, orig_filename);
  110.  
  111.         puts(scratch_space);
  112.  
  113.         return 1;
  114.  
  115.     }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.     while (!feof(infile))
  122.  
  123.     {
  124.  
  125.         packet_hdr = fgetc(infile);         /* get lo byte   */
  126.  
  127.  
  128.  
  129.         if (feof(infile))
  130.  
  131.             continue;
  132.  
  133.  
  134.  
  135.         packet_hdr |= (((short)fgetc(infile)) << 8) ;  /* get high byte */
  136.  
  137.  
  138.  
  139.         if (feof(infile))
  140.  
  141.             continue;
  142.  
  143.  
  144.  
  145.  
  146.  
  147.         length = MAX_LEN & packet_hdr;
  148.  
  149.  
  150.  
  151.         if (packet_hdr & RUN)  /* if it's a run... */
  152.  
  153.         {
  154.  
  155.             byte = fgetc(infile);
  156.  
  157.  
  158.  
  159.             for (i = 0; i < length; i++)
  160.  
  161.                 fputc(byte, outfile);
  162.  
  163.         }
  164.  
  165.  
  166.  
  167.         else /* it's a sequence */
  168.  
  169.  
  170.  
  171.             for (i = 0; i < length; i++)
  172.  
  173.                 fputc(fgetc(infile), outfile);
  174.  
  175.  
  176.  
  177.     }
  178.  
  179.     fclose(infile);
  180.  
  181.     fclose(outfile);
  182.  
  183.     return 0;
  184.  
  185. }
  186.  
  187.  
  188.  
  189.