home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / UTUNSQZ.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.1 KB  |  113 lines

  1. /**
  2. *
  3. * Name        UTUNSQZ - Uncompress a screen image.
  4. *
  5. * Synopsis    length = utunsqz(psource, pdestination,
  6. *                 source_length, destination_length);
  7. *
  8. *        int length        The number of bytes actually
  9. *                    used by the unsqueezed image.
  10. *        const char *psource    The address of the squeezed
  11. *                    image to be uncompressed.
  12. *        char far *pdestination    The target address for the
  13. *                    uncompressed image to be placed.
  14. *        int source_length    The length in bytes of the
  15. *                    compressed screen image.
  16. *        int destination_length    The maximum length in bytes of
  17. *                    the uncompressed image. This is
  18. *                    the size of the destination
  19. *                    buffer.
  20. *
  21. * Description    UTUNSQZ expands a screen image compressed by UTSQZSCN.
  22. *        For details of the technique used to compress the image,
  23. *        see UTSQZSCN. If the length of the destination buffer
  24. *        is smaller than the uncompressed image, UTUNSQZ will
  25. *        uncompress only as much of the image as will fit in the
  26. *        destination buffer, but will still return the length
  27. *        required for the complete uncompressed image.
  28. *
  29. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  30. *
  31. **/
  32. #include <butil.h>
  33.  
  34. int utunsqz(psource, pdestination, source_length, destination_length)
  35. const char *psource;
  36. char far   *pdestination;
  37. int        source_length;
  38. int        destination_length;
  39. {
  40.     unsigned char char_key;
  41.     unsigned char attr_key;
  42.     int       source_index, destination_index;
  43.     int       character_count;
  44.     int       expanded_len;
  45.     unsigned char current_attr = 0;
  46.     unsigned char current_byte;
  47.  
  48.     if ((psource == NIL) || (pdestination == NIL))
  49.     return(0);
  50.  
  51.     current_attr = 0;
  52.  
  53.     attr_key = psource[0];
  54.     char_key = psource[1];
  55.  
  56.     expanded_len = *((int *) &psource[2]);
  57.  
  58.     source_index       = 4;
  59.     destination_index  = 0;
  60.  
  61.     /* Now pass through the compressed image.  If an attribute key is */
  62.     /* found, the current attribute is altered to the attribute value.*/
  63.     /* If a character key is found, the number of copies of the       */
  64.     /* character is output (together with the current attribute). If  */
  65.     /* a key is found at the end of the source, it is treated as a    */
  66.     /* normal character.                          */
  67.  
  68.     while (source_index < source_length)
  69.     {
  70.     current_byte = psource[source_index];
  71.  
  72.     if (current_byte == attr_key)
  73.     {
  74.         if (source_index < (source_length - 1))
  75.         {
  76.         source_index++;
  77.         current_attr = psource[source_index];
  78.         }
  79.         else
  80.         {
  81.         pdestination[destination_index++] = current_attr;
  82.         pdestination[destination_index++] = current_byte;
  83.         }
  84.     }
  85.     else
  86.     {
  87.         if ((current_byte == char_key) && ((source_index + 3)
  88.         < source_length))
  89.         {
  90.         source_index++;
  91.         character_count = *((int *) &psource[source_index]);
  92.         source_index += sizeof(int);
  93.         current_byte = psource[source_index];
  94.         }
  95.         else
  96.         character_count = 1;
  97.  
  98.         while (character_count--)
  99.         {
  100.         if (destination_index >= (destination_length - 1))
  101.             return(expanded_len);
  102.  
  103.         pdestination[destination_index++] = current_byte;
  104.         pdestination[destination_index++] = current_attr;
  105.         }
  106.     }
  107.  
  108.     source_index++;
  109.     }
  110.  
  111.     return(expanded_len);
  112. }
  113.