home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / uconv123.zip / uc_convp.h < prev    next >
Text File  |  1998-04-02  |  12KB  |  263 lines

  1. /*static char sccsid[] = "@(#)11  1.2  src/uls/common/include/uc_convP.h"
  2.  *
  3.  *   COMPONENT_NAME:   wp.uconv
  4.  *
  5.  *   Private functions:
  6.  *     __getTableName
  7.  *     __getUcTable
  8.  *     __freeUcTable
  9.  *
  10.  *   IBM CONFIDENTIAL -- (IBM Confidential Restricted when
  11.  *   combined with the aggregated modules for this product)
  12.  *   OBJECT CODE ONLY SOURCE MATERIALS
  13.  *
  14.  *   (C) COPYRIGHT International Business Machines Corp. 1995
  15.  *   All Rights Reserved
  16.  *   US Government Users Restricted Rights - Use, duplication or
  17.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  18.  */
  19.  
  20. #ifndef __UC_CONVP
  21.    #define __UC_CONVP
  22.  
  23.    #include <ucommon.h>
  24.  
  25.    #ifdef __cplusplus
  26.      extern "C" {
  27.    #endif
  28.  
  29.    #if defined(__IBMCPP__) || defined(__IBMC__)
  30.      #pragma pack(1)
  31.    #else
  32.      #pragma Align_members(1)
  33.    #endif
  34.  
  35.    /*
  36.     * UCS conversion table version & release
  37.     */
  38.    #define UC_VERSION  0x02
  39.    #define UC_RELEASE  0x00
  40.  
  41.    /*
  42.     * UCS conversion table types
  43.     */
  44.    #define UC_CLASS_INVAL            0       /* Invalid type              */
  45.    #define UC_CLASS_ASCII7           0       /* UCS <-> ASCII7 data       */
  46.    #define UC_CLASS_SBCS             1       /* UCS <-> SBCS              */
  47.    #define UC_CLASS_DBCS             2       /* UCS <-> DBCS  (stateless) */
  48.    #define UC_CLASS_MBCS             3       /* UCS <-> MBCS  (stateless) */
  49.    #define UC_CLASS_EBCDIC_STATEFUL  4       /* UCS <-> EBCDIC (stateful) */
  50.    #define UC_CLASS_EBCS             4       /* UCS <-> EBCDIC (stateful) */
  51.    #define UC_CLASS_UCS2             5       /* Unicode (null map)        */
  52.    #define UC_CLASS_UTF8             6       /* UCS <-> UTF-8             */
  53.    #define UC_CLASS_UPF8             7       /* UCS <-> UTF-7             */
  54.  
  55.    /*
  56.     * UCS conversion table default substitution character
  57.     */
  58.    #define UC_DEF_SUB         0xfffd
  59.    #define STEM_MAX           13
  60.  
  61.    /*
  62.     * Version 2 UCS conversion table header structures
  63.     *
  64.     * This is the header for both file and in-memory tables since we just
  65.     * memory map the file.
  66.     *
  67.     */
  68.    #ifndef _USE_FILESERVER
  69.       typedef unsigned int   uint32;
  70.       typedef unsigned short uint16;
  71.    #endif
  72.  
  73.    typedef struct _ucm_base_rec {
  74.       uint32    size;                /* size of header                  */
  75.       uint16    bom;                 /* = 0xfeff      (our endian)      */
  76.       char      version;             /* = UC_VERSION                    */
  77.       char      release;             /* = UC_RELEASE                    */
  78.       char      eyecatcher[4];       /* "ucv"                           */
  79.       uint16    codepage;            /* IBM registered codepage         */
  80.       uint16    flags;               /* Flags UCVF_                     */
  81.       char      name[16];            /* Name of codepage                */
  82.       uint16    hdrlen;              /* Length of header                */
  83.       uint16    copyright;           /* Offset to copyright             */
  84.       uint16    desc;                /* Offset to description           */
  85.       uint16    uconv_more;          /* Additional codepoints           */
  86.       uint16    udctab;              /* User defined characters         */
  87.       uint16    udclen;              /* Length (bytes) of udc table     */
  88.       uint16    codeoffset;          /* Offset to code table            */
  89.       UniChar   Display7F;           /* Display char for 0x7f           */
  90.       uint16    uconv_class;         /* UCONV CLASS                     */
  91.       uint16    encoding;            /* Encoding scheme id              */
  92.       uint16    mb_min_len;          /* Minimum character length        */
  93.       uint16    mb_max_len;          /* Maximum character length        */
  94.       uint16    subchar_len;         /* Substitution character length   */
  95.       UniChar   undef_uni;           /* Equivalent char of undef_char   */
  96.       char      undef_char;          /* Marker for invalid char in MBCS */
  97.       char      noncdra;             /* Allow non-CRDA                  */
  98.       UniChar   subuni;              /* Substitution char in UCS        */
  99.       char      subchar[16];         /* Substitution char in MBCS       */
  100.       uint16    upperlower;
  101.       uint16    crc;                 /* Validity check                  */
  102.       char      date[12];            /* Build date                      */
  103.       char      vardata[64];         /* Variable length data            */
  104.    } ucm_base_t;
  105.  
  106.    typedef struct _ucm_normal_rec {
  107.       ucm_base_t base;
  108.       UniChar    Display[32];        /* Display translations            */
  109.       uint16     U2Mof4set[256];     /* Offsets to conversion rows      */
  110.       uint16     M2Uof4set[256];     /* Offsets to conversion rows      */
  111.    } ucm_normal_t;
  112.  
  113.    typedef struct _ucm_extra_rec {
  114.       ucm_base_t base;
  115.       UniChar    Display[32];        /* Display translations            */
  116.       uint16     U2Mof4set[256];     /* Offsets to conversion rows      */
  117.       uint16     M2Uof4set[256];     /* Offsets to conversion rows      */
  118.       char       code_len[256];      /* Code length array   (optional)  */
  119.       char       other_byte[256];    /* Other byte array    (optional)  */
  120.    } ucm_extra_t;
  121.  
  122.    typedef union _ucm_hdr_rec {
  123.       ucm_base_t   base;
  124.       ucm_normal_t normal;
  125.       ucm_extra_t  extra;
  126.    } ucm_hdr_t;
  127.  
  128.    typedef struct _ucm_hdrbak_rec {
  129.       uint32    size;                /* size of header                  */
  130.       uint16    bom;                 /* = 0xfeff      (our endian)      */
  131.       char      version;             /* = UC_VERSION                    */
  132.       char      release;             /* = UC_RELEASE                    */
  133.       char      eyecatcher[4];       /* "ucv"                           */
  134.       uint16    codepage;            /* IBM registered codepage         */
  135.       uint16    flags;               /* Flags UCVF_                     */
  136.       char      name[16];            /* Name of codepage                */
  137.       uint16    hdrlen;              /* Length of header                */
  138.       uint16    copyright;           /* Offset to copyright             */
  139.       uint16    desc;                /* Offset to description           */
  140.       uint16    uconv_more;          /* Additional codepoints           */
  141.       uint16    udctab;              /* User defined characters         */
  142.       uint16    udclen;              /* Length (bytes) of udc table     */
  143.       uint16    codeoffset;          /* Offset to code table            */
  144.       UniChar   Display7F;           /* Display char for 0x7f           */
  145.       uint16    uconv_class;         /* UCONV CLASS                     */
  146.       uint16    encoding;            /* Encoding scheme id              */
  147.       uint16    mb_min_len;          /* Minimum character length        */
  148.       uint16    mb_max_len;          /* Maximum character length        */
  149.       uint16    subchar_len;         /* Substitution character length   */
  150.       UniChar   undef_uni;           /* Equivalent char of undef_char   */
  151.       char      undef_char;          /* Marker for invalid char in MBCS */
  152.       char      noncdra;             /* Allow non-CRDA                  */
  153.       UniChar   subuni;              /* Substitution char in UCS        */
  154.       char      subchar[16];         /* Substitution char in MBCS       */
  155.       uint16    resv;
  156.       uint16    crc;                 /* Validity check                  */
  157.       char      date[12];            /* Build date                      */
  158.       char      vardata[64];         /* Variable length data            */
  159.  
  160.       UniChar   Display[32];         /* Display translations            */
  161.       uint16    U2Mof4set[256];      /* Offsets to conversion rows      */
  162.       uint16    M2Uof4set[256];      /* Offsets to conversion rows      */
  163.  
  164.       char      code_len[256];       /* Code length array   (optional)  */
  165.       char      other_byte[256];     /* Other byte array    (optional)  */
  166.    } ucm_hdrbak_t;
  167.  
  168.    #define M2Utable M2Uof4set
  169.    #define UCMHDR_BASE  sizeof (ucm_base_t)
  170.    #define UCMHDR_NORM  sizeof (ucm_normal_t)
  171.    #define UCMHDR_EXTRA sizeof (ucm_extra_t)
  172.  
  173.    /*
  174.     * MBCS conversion table
  175.     */
  176.    typedef struct {                  /* MBCS conversion row table unit  */
  177.       uint16    n_slots;             /* Number of slots of this table   */
  178.       uint16    l_value;             /* Lowest byte value in row        */
  179.       uint16    nextOf4set[256];     /* Offsets to next rows            */
  180.    } _uc_row_t;
  181.  
  182.    typedef struct {                  /* MBCS STEM information           */
  183.       char      stem[STEM_MAX+1];    /* Stem string                     */
  184.       uint16    stem_len;            /* Stem length                     */
  185.    } _uc_stem_t;
  186.  
  187.    typedef struct {                  /* UCS_MBCS conversion table unit  */
  188.       uint16    stem_index;          /* Index for stem table            */
  189.       uint16    code;                /* The last 2 byte of codepoint    */
  190.    } _uc_u2m_t;
  191.  
  192.    #define SHIFT_IN   0
  193.    #define SHIFT_OUT  1
  194.  
  195.    /*
  196.     * Conversion handle table
  197.     *
  198.     * This is an internal table, so only those field we need now are
  199.     * encoded.  Other data we need is in the table itself.  Only the
  200.     * uconv_class is copies since it is used a lot.
  201.     */
  202.    typedef struct _uc_ch_rec {
  203.       ucm_hdr_t * table;             /* Conversion table C/B            */
  204.       uint16      uconv_class;       /* Type of conversion              */
  205.       uint16      endianto;          /* To endian                       */
  206.       uint16      endianfrom;        /* From endian                     */
  207.       uint16      subuni_len;        /* Substitution option             */
  208.       UniChar     subuni;            /* Substitution char in UCS        */
  209.       uint16      subchar_len;       /* Substitution char length        */
  210.       char        subchar[16];       /* Substitution char in MBCS       */
  211.       char        state_flag_from;   /* State flag                      */
  212.       char        state_flag_to;     /* State flag                      */
  213.       uint16      options;           /* Map and Substitution Options    */
  214.       uint32      displaymask;       /* Display mask                    */
  215.       uint32      converttype;       /* Conversion options              */
  216.     } _uc_ch_t;
  217.  
  218.     typedef int (*table_fvt_t)(char *buf, size_t bufsize, size_t filesize, int flag);
  219.  
  220.     #define TYPE_UCTABLE               0x0001
  221.     #define TYPE_UCSID                 0x0002
  222.  
  223.     #define UCONV_ENV_PATH           "ULSPATH"
  224.     #define DEF_ULSPATH_LEN          14
  225.     #define DEF_CODEPAGEPATH         (UniChar *)L"codepage\\"
  226.     #define DEF_CODEPAGEPATH_LEN     9
  227.     #define UCSID_DATAPATH_LEN       18
  228.     #define DEF_ULSPATH              "c:\\language\\"
  229.     #define ALIAS_TABLE              "ucstbl.lst"
  230.     #define ALIAS_TABLE_UNI          (UniChar)L"ucstbl.lst"
  231.     #define ALIAS_TABLE_LEN          10
  232.     #define MYEOF                      EOF
  233.     #define _UCONV_MAX_PATH            256
  234.     /*
  235.      * Internal use function prototypes
  236.      */
  237.     int __getTableName (            /* Get table File/Path name        */
  238.         UniChar      * cs_name,     /* Unicode table name              */
  239.         size_t         length,      /* name length                     */
  240.         char         * table_name); /* Returns relative File/Path name */
  241.  
  242.     int __getUcTable (              /* Get conversion table            */
  243.         char         * table_name,  /* Conversion table File/Path name */
  244.         size_t         name_len,    /* base file name length           */
  245.         table_fvt_t    table_func,  /* test function execute in loading*/
  246.         ucm_hdr_t  * * ucmap);      /* Returns pointer to found table  */
  247.  
  248. /*4ADWH149653start*/
  249.  
  250.     int __freeUcTable (             /* Free conversion table           */
  251.         ucm_hdr_t * ucmap);         /* Conversion table C/B            */
  252.  
  253.   #if defined(__IBMCPP__) || defined(__IBMC__)
  254.     #pragma pack()
  255.   #else
  256.     #pragma Align_members()
  257.   #endif
  258.  
  259.   #ifdef __cplusplus
  260.   }
  261.   #endif
  262. #endif
  263.