home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / detk45he.zip / uconv.h < prev    next >
C/C++ Source or Header  |  1999-03-15  |  13KB  |  304 lines

  1. /*
  2.  * uconv.h - Unicode Conversions
  3.  *
  4.  * Function:
  5.  *     Declare structures and prototypes for Unicode Conversion functions.
  6.  *
  7.  * Copyright:
  8.  *     Copyright (C) IBM Corp. 1995, 1997
  9.  *
  10.  */
  11.  
  12. #ifndef _ULS_UCONV
  13.    #define _ULS_UCONV
  14.    #include <unidef.h>
  15.  
  16.    #ifdef __cplusplus
  17.      extern "C" {
  18.    #endif
  19.  
  20.    #ifndef _ULS_UCONVP
  21.      #define _ULS_UCONVP
  22.      typedef void * UconvObject;          /* uconv Type pointer            */
  23.    #endif
  24.  
  25.    #ifndef _ULS_UNICHAR_DEFINED
  26.      #define _ULS_UNICHAR_DEFINED
  27.      typedef unsigned  short  UniChar ;
  28.    #endif
  29.  
  30.  
  31.    #ifndef ULS_ATTR
  32.    #define ULS_ATTR
  33.    /*
  34.     * Substitution options
  35.     */
  36.    #define UCONV_OPTION_SUBSTITUTE_FROM_UNICODE  1
  37.    #define UCONV_OPTION_SUBSTITUTE_TO_UNICODE    2
  38.    #define UCONV_OPTION_SUBSTITUTE_BOTH          3
  39.  
  40.    /*
  41.     * Conversion options
  42.     */
  43.    #define CVTTYPE_PATH     0x00000004   /* Treat string as a path   */
  44.    #define CVTTYPE_CDRA     0x00000002   /* Use CDRA control mapping */
  45.    #define CVTTYPE_CTRL7F   0x00000001   /* Treat 0x7F as a control  */
  46.  
  47.    /*
  48.     * Conversion mask.  This is a bit mask.  If the bit is on, the
  49.     * corresponding character 0x00-0x1f is treated as a control.
  50.     * Otherwise it is treated as a glyph.
  51.     */
  52.    #define DSPMASK_DATA    0xffffffff
  53.    #define DSPMASK_DISPLAY 0x00000000
  54.    #define DSPMASK_TAB     0x00000200
  55.    #define DSPMASK_LF      0x00000400
  56.    #define DSPMASK_CR      0x00002000
  57.    #define DSPMASK_CRLF    0x00002400
  58.  
  59.    /*
  60.     * Encoding schemes.  This is the primary item used to check if a
  61.     * a codepage is valid for a particular purpose.  A length check
  62.     * may also be made in some cases.
  63.     */
  64.    enum uconv_esid {                     /* Process Display  VIO    GPI   */
  65.        ESID_sbcs_data        = 0x2100,   /*    x      x      x       x    */
  66.        ESID_sbcs_pc          = 0x3100,   /*    x      x      x       x    */
  67.        ESID_sbcs_ebcdic      = 0x1100,   /*           x      x       x    */
  68.        ESID_sbcs_iso         = 0x4100,   /*    x      x      x       x    */
  69.        ESID_sbcs_windows     = 0x4105,   /*    x      x      x       x    */
  70.        ESID_sbcs_alt         = 0xF100,   /*           x      x       x    */
  71.        ESID_dbcs_data        = 0x2200,   /*           x              x    */
  72.        ESID_dbcs_pc          = 0x3200,   /*    x      x      x       x    */
  73.        ESID_dbcs_ebcdic      = 0x1200,   /*                          x    */
  74.        ESID_mbcs_data        = 0x2300,   /*           x      x       x    */
  75.        ESID_mbcs_pc          = 0x3300,   /*           x              x    */
  76.        ESID_mbcs_ebcdic      = 0x1301,   /*                               */
  77.        ESID_ucs_2            = 0x7200,   /*                               */
  78.        ESID_ugl              = 0x72FF,   /*                               */
  79.        ESID_utf_8            = 0x7807,   /*           x      x       x    */
  80.        ESID_upf_8            = 0x78FF    /*    x      x      x       x    */
  81.    };
  82.  
  83.    #ifndef __conv_endian_t
  84.        #define __conv_endian_t
  85.  
  86.        #define     ENDIAN_SYSTEM   0x0000
  87.        #define     ENDIAN_BIG      0xfeff
  88.        #define     ENDIAN_LITTLE   0xfffe
  89.  
  90.        typedef struct _conv_endian_rec {
  91.            unsigned short  source;   /* Used by FromUcs                   */
  92.            unsigned short  target;   /* Used by ToUcs                     */
  93.        } conv_endian_t;
  94.    #endif
  95.  
  96.    typedef struct _uconv_attribute_t {
  97.        unsigned long  version;       /* Q/S Version (must be zero)        */
  98.        char           mb_min_len;    /* Q   Minimum char size             */
  99.        char           mb_max_len;    /* Q   Maximum char size             */
  100.        char           usc_min_len;   /* Q   UCS min size                  */
  101.        char           usc_max_len;   /* Q   UCS max size                  */
  102.        unsigned short esid;          /* Q   Encoding scheme ID            */
  103.        char           options;       /* Q/S Substitution options          */
  104.        char           state;         /* Q/S State for stateful convert    */
  105.        conv_endian_t  endian;        /* Q/S Source and target endian      */
  106.        unsigned long  displaymask;   /* Q/S Display/data mask             */
  107.        unsigned long  converttype;   /* Q/S Conversion type               */
  108.        unsigned short subchar_len;   /* Q/S MBCS sub len      0=table     */
  109.        unsigned short subuni_len;    /* Q/S Unicode sub len   0=table     */
  110.        char           subchar[16];   /* Q/S MBCS sub characters           */
  111.        UniChar        subuni[8];     /* Q/S Unicode sub characters        */
  112.    } uconv_attribute_t;
  113.  
  114.    /*
  115.     * User defined character range
  116.     */
  117.    typedef struct {                /* User Defined character range      */
  118.        unsigned short   first;     /* First codepoint                   */
  119.        unsigned short   last;      /* Last codepoint                    */
  120.    } udcrange_t;
  121.    #endif  /* ULS_ATTR */
  122.    #define uconv_error_t int
  123.  
  124.    /*
  125.     * UniCreateUconvObject: Create Unicode Conversion Object
  126.     *
  127.     * return code:
  128.     *    0             - Conversion Object sucessfully initialized
  129.     *    UCONV_EMFILE  - Maximum file descriptors are opened
  130.     *    UCONV_ENFILE  - Too many files currently open in the system
  131.     *    UCONV_ENOMEM  - Insuffcient memory
  132.     *    UCONV_EINVAL  - The conversion specified by code_set or the
  133.     *                    modifier supplied is not recognized by the
  134.     *                    implementation.
  135.     *
  136.     */
  137.    int CALLCONV UniCreateUconvObject(
  138.              UniChar     * code_set,   /* I  - Unicode name of uconv table */
  139.              UconvObject * uobj  );    /* O  - Uconv object handle         */
  140.  
  141.    /*
  142.     * UniQueryUconvObject: Query Unicode Coversion Object
  143.     *
  144.     * return code:
  145.     *    0             - Operation successful
  146.     *    UCONV_EBADF   - The conversion object specified is not
  147.     *                    recognized by the implementation.
  148.     */
  149.    int CALLCONV UniQueryUconvObject(
  150.              UconvObject         uobj, /* I  - Uconv object handle         */
  151.              uconv_attribute_t * attr, /* O  - Uconv attributes            */
  152.              size_t              size, /* I  - Size of attribute structure */
  153.              char          first[256], /* O  - First byte of multibyte     */
  154.              char          other[256], /* O  - Other byte of multibyte     */
  155.              udcrange_t udcrange[32]); /* O  - User defined char range     */
  156.  
  157.    /*
  158.     * UniSetUconvObject:  Set Unicode Conversion Object
  159.     *
  160.     * return code:
  161.     *    0             - Operation successful
  162.     *    UCONV_EBADF   - The conversion object specified is not
  163.     *                    recognized by the implementation.
  164.     *    UCONV_BADATTR - attribute supplied contains invalid attribute
  165.     *                    for the conversion object
  166.     */
  167.    int CALLCONV UniSetUconvObject(
  168.              UconvObject         uobj, /* I  - Uconv object handle         */
  169.              uconv_attribute_t * attr); /* I  - Uconv attributes            */
  170.  
  171.    /*
  172.     * UniUconvToUcs:  Convert string to unicode
  173.     *
  174.     * return code:
  175.     *    0             - Operation successful
  176.     *    UCONV_EBADF   - The conversion object specified is not
  177.     *                    recognized by the implementation.
  178.     *    UCONV_E2BIG   - Input conversion stopped due to lack of space
  179.     *                    in the output buffer
  180.     *    UCONV_EINVAL  - Input conversion stopped due to incomplete
  181.     *                    character or shift sequence at the end of the
  182.     *                    input buffer.
  183.     *    UCONV_EILSEQ  - Input conversion stopped due to an input byte
  184.     *                    that does not belong to the input code set.
  185.     */
  186.    int CALLCONV UniUconvToUcs(
  187.              UconvObject uobj,         /* I  - Uconv object handle         */
  188.              void    * * inbuf,        /* IO - Input buffer                */
  189.              size_t    * inbytes,      /* IO - Input buffer size (bytes)   */
  190.              UniChar * * outbuf,       /* IO - Output buffer size          */
  191.              size_t    * outchars,     /* IO - Output size (chars)         */
  192.              size_t    * subst  );     /* IO - Substitution count          */
  193.  
  194.    /*
  195.     * UniUconvFromUcs:  Convert string from unicode
  196.     *    0             - Operation successful
  197.     *    UCONV_EBADF   - The conversion object specified is not
  198.     *                    recognized by the implementation.
  199.     *    UCONV_E2BIG   - Input conversion stopped due to lack of space
  200.     *                    in the output buffer
  201.     *    UCONV_EINVAL  - Input conversion stopped due to incomplete
  202.     *                    character or shift sequence at the end of the
  203.     *                    input buffer.
  204.     *    UCONV_EILSEQ  - Input conversion stopped due to an input byte
  205.     *                    that does not belong to the input code set.
  206.     */
  207.    int CALLCONV UniUconvFromUcs(
  208.              UconvObject uobj,         /* I  - Uconv object handle         */
  209.              UniChar * * inbuf,        /* IO - Input buffer                */
  210.              size_t    * inchars,      /* IO - Input buffer size (bytes)   */
  211.              void    * * outbuf,       /* IO - Output buffer size          */
  212.              size_t    * outbytes,     /* IO - Output size (chars)         */
  213.              size_t    * subst   );    /* IO - Substitution count          */
  214.  
  215.    /*
  216.     * UniFreeUconvObject: Close Unicode Conversion Object
  217.     *    0             - Operation successful
  218.     *    UCONV_EBADF   - The conversion object specified is not
  219.     *                    recognized by the implementation.
  220.     */
  221.    int CALLCONV UniFreeUconvObject(
  222.              UconvObject   uobj   );   /* I  - Uconv object handle         */
  223.  
  224.    /*
  225.     * UniMapCpToUcsCp: Convert a codepage number to unicode name
  226.     *
  227.     * Returns:
  228.     *     0             Goodf there is an error, the contents
  229.     *     UCONV_E2BIG   The buffer is not large enough
  230.     *
  231.     * Notes:
  232.     *     Output is undefined if there is an error.
  233.     *
  234.     *     Output buffer must be large enough to hold terminating null.
  235.     */
  236.    int CALLCONV UniMapCpToUcsCp(
  237.              unsigned long ulCodePage, /* I  - Codepage to convert         */
  238.              UniChar * ucsCodePage,    /* O  - Output buffer               */
  239.              size_t    n );            /* I  - UniChars in output buffer   */
  240.  
  241.    /*
  242.     * UniStrFromUcs: Convert a null-terminated string from Unicode.
  243.     *
  244.     * Returns:
  245.     *     0               Good
  246.     *     UCONV_EBADF     Invalid Handle
  247.     *     UCONV_EILSEQ    Unmappable char substitution off
  248.     *     UCONV_E2BIG     Max characters converted
  249.     *
  250.     * Note:
  251.     *     Output buffer must be large enough to hold terminating null
  252.     *
  253.     */
  254.     int CALLCONV UniStrFromUcs(
  255.               UconvObject   co,        /* I  - Conversion object           */
  256.               char        * target,    /* O  - Buffer for converted string */
  257.               UniChar     * source,    /* I  - String to convert           */
  258.               int           len);      /* I  - Bytes in target buffer      */
  259.  
  260.    /*
  261.     * UniStrToUcs: Convert a null-terminated string to Unicode.
  262.     *
  263.     * Returns:
  264.     *     0               Good
  265.     *     UCONV_EBADF     Invalid Handle
  266.     *     UCONV_EILSEQ    Unmappable char substitution off
  267.     *     UCONV_E2BIG     Max characters converted
  268.     *
  269.     * Note:
  270.     *     Output buffer must be large enough to hold terminating null
  271.     */
  272.    int CALLCONV UniStrToUcs(
  273.              UconvObject  co,          /* I  - Conversion object           */
  274.              UniChar    * target,      /* O  - Buffer for converted string */
  275.              char       * source,      /* I  - Character string to convert */
  276.              int          len);        /* I  - UniChars in target buffer   */
  277.  
  278.  /*
  279.   * for compatibility with old return codes for ULS
  280.   */
  281.   #define UCONV_EOTHER           ULS_OTHER
  282.   #define UCONV_EILSEQ           ULS_ILLEGALSEQUENCE
  283.   #define UCONV_EINVAL           ULS_INVALID
  284.   #define UCONV_E2BIG            ULS_BUFFERFULL
  285.   #define UCONV_ENOMEM           ULS_NOMEMORY
  286.   #define UCONV_EBADF            ULS_BADOBJECT
  287.   #define UCONV_BADATTR          ULS_BADATTR
  288.   #define UCONV_EMFILE           ULS_MAXFILESPERPROC
  289.   #define UCONV_ENFILE           ULS_MAXFILES
  290.   #define UCONV_NOTIMPLEMENTED   ULS_NOTIMPLEMENTED
  291.  
  292.   #define IBM_437         (UniChar *)L"IBM-437"
  293.   #define IBM_819         (UniChar *)L"IBM-819"
  294.   #define IBM_850         (UniChar *)L"IBM-850"
  295.   #define UTF_8           (UniChar *)L"IBM-1208"
  296.   #define UCS_2           (UniChar *)L"IBM-1200"
  297.   #define ISO8859_1       (UniChar *)L"IBM-819"
  298.  
  299.   #ifdef __cplusplus
  300.   }
  301.   #endif
  302.  
  303. #endif
  304.