home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / common / scsu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  5.4 KB  |  146 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright International Business Machines Corporation, 1998           *
  6. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  7. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  8. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  9. *                                                                             *
  10. *******************************************************************************
  11. *
  12. * File scsu.h
  13. *
  14. * Modification History:
  15. *
  16. *   Date        Name        Description
  17. *   05/17/99    stephen        Creation (ported from java UnicodeCompressor.java)
  18. *   09/21/99    stephen     Updated to handle data splits on decompression.
  19. *******************************************************************************
  20. */
  21.  
  22. #ifndef SCSU_H
  23. #define SCSU_H 1
  24.  
  25. #include "utypes.h"
  26.  
  27. /* Number of windows */
  28. #define USCSU_NUM_WINDOWS 8
  29. #define USCSU_NUM_STATIC_WINDOWS 8
  30.  
  31. /* Maximum value for a window's index */
  32. #define USCSU_MAX_INDEX 0xFF
  33.  
  34. /** The size of the internal buffer for a UnicodeCompressor */
  35. #define USCSU_BUFSIZE 3
  36.  
  37. /** The UnicodeCompressor struct */
  38. struct UnicodeCompressor {
  39.  
  40.     /** Alias to current dynamic window */
  41.     int32_t fCurrentWindow;
  42.     
  43.     /** Dynamic compression window offsets */
  44.     int32_t fOffsets    [ USCSU_NUM_WINDOWS ];
  45.     
  46.     /** Current compression mode */
  47.     int32_t fMode;
  48.  
  49.     /** Keeps count of times character indices are encountered */
  50.     int32_t fIndexCount [ USCSU_MAX_INDEX + 1 ];
  51.     
  52.     /** The time stamps indicate when a window was last defined */
  53.     int32_t fTimeStamps [ USCSU_NUM_WINDOWS ];
  54.     
  55.     /** The current time stamp */
  56.     int32_t fTimeStamp;
  57.  
  58.     /** Internal buffer for saving state */
  59.     uint8_t fBuffer [ USCSU_BUFSIZE ];
  60.   
  61.     /** Number of characters in our internal buffer */
  62.     int32_t fBufferLength;
  63. };
  64. typedef struct UnicodeCompressor UnicodeCompressor;
  65.  
  66. /**
  67.  * Initialize a UnicodeCompressor.
  68.  * Sets all windows to their default values.
  69.  * @see #reset
  70.  */
  71. U_CAPI void U_EXPORT2 scsu_init(UnicodeCompressor *comp);
  72.  
  73. /**
  74.  * Reset the compressor to its initial state. 
  75.  * @param comp The UnicodeCompressor to reset.
  76.  */
  77. U_CAPI void U_EXPORT2 scsu_reset(UnicodeCompressor *comp);
  78.  
  79. /**
  80.  * Compress a Unicode character array into a byte array.
  81.  *
  82.  * This function is not guaranteed to completely fill the output buffer, nor
  83.  * is it guaranteed to compress the entire input.  
  84.  * If the source data is completely compressed, <TT>status</TT> will be set
  85.  * to <TT>U_ZERO_ERROR</TT>.  
  86.  * If the source data is not completely compressed, <TT>status</TT> will be
  87.  * set to <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT>.  If this occurs, larger buffers
  88.  * should be allocated, or data flushed, and the function should be called
  89.  * again with the new buffers.
  90.  *
  91.  * @param comp A pointer to a previously-initialized UnicodeCompressor
  92.  * @param target I/O parameter.  On input, a pointer to a buffer of bytes to
  93.  * receive the compressed data.  On output, points to the byte following
  94.  * the last byte written.  This buffer must be at least 4 bytes.
  95.  * @param targetLimit A pointer to the end of the array <TT>target</TT>.
  96.  * @param source I/O parameter.  On input, a pointer to a buffer of
  97.  * Unicode characters to be compressed.  On output, points to the character
  98.  * following the last character compressed.
  99.  * @param sourceLimit A pointer to the end of the array <TT>source</TT>.
  100.  * @param status A pointer to an UErrorCode to receive any errors.
  101.  *
  102.  * @see #decompress
  103.  */
  104. U_CAPI void U_EXPORT2 scsu_compress(UnicodeCompressor *comp,
  105.             uint8_t           **target,
  106.             const uint8_t     *targetLimit,
  107.             const UChar       **source,
  108.             const UChar       *sourceLimit,
  109.             UErrorCode        *status);
  110.  
  111. /**
  112.  * Decompress a byte array into a Unicode character array.
  113.  *
  114.  * This function will either completely fill the output buffer, or
  115.  * consume the entire input.  
  116.  * If the source data is completely compressed, <TT>status</TT> will be set
  117.  * to <TT>U_ZERO_ERROR</TT>.  
  118.  * If the source data is not completely compressed, <TT>status</TT> will be
  119.  * set to <TT>U_INDEX_OUTOFBOUNDS_ERROR</TT>.  If this occurs, larger buffers
  120.  * should be allocated, or data flushed, and the function should be called
  121.  * again with the new buffers.
  122.  *
  123.  * @param comp A pointer to a previously-initialized UnicodeDecompressor
  124.  * @param target I/O parameter.  On input, a pointer to a buffer of Unicode
  125.  * characters to receive the compressed data.  On output, points to the 
  126.  * character following the last character written.  This buffer must be
  127.  * at least 2 bytes.
  128.  * @param targetLimit A pointer to the end of the array <TT>target</TT>.
  129.  * @param source I/O parameter.  On input, a pointer to a buffer of
  130.  * bytes to be decompressed.  On output, points to the byte following the
  131.  * last byte decompressed.
  132.  * @param sourceLimit A pointer to the end of the array <TT>source</TT>.
  133.  * @param status A pointer to an UErrorCode to receive any errors.
  134.  * @return The number of Unicode characters writeten to <TT>target</TT>.
  135.  *
  136.  * @see #compress
  137.  */
  138. U_CAPI void U_EXPORT2 scsu_decompress(UnicodeCompressor *comp,
  139.               UChar             **target,
  140.               const UChar       *targetLimit,
  141.               const uint8_t     **source,
  142.               const uint8_t     *sourceLimit,
  143.               UErrorCode        *status);
  144.  
  145. #endif
  146.