[444] | 1 | /* |
---|
| 2 | * Copyright (c) 2003-2004, Artem B. Bityuckiy |
---|
| 3 | * modification, are permitted provided that the following conditions |
---|
| 4 | * are met: |
---|
| 5 | * 1. Redistributions of source code must retain the above copyright |
---|
| 6 | * notice, this list of conditions and the following disclaimer. |
---|
| 7 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 8 | * notice, this list of conditions and the following disclaimer in the |
---|
| 9 | * documentation and/or other materials provided with the distribution. |
---|
| 10 | * |
---|
| 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
| 12 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 13 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 14 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
| 15 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
| 16 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
| 17 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
| 18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
| 19 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
| 20 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
| 21 | * SUCH DAMAGE. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | /* |
---|
| 25 | * This CES converter is just an simple extension of table CES converter. |
---|
| 26 | * This CES converter is used for 16 bit CCSes which include 7bit |
---|
| 27 | * Portable Characters Set (PCS) (equivalent to ASCII) (example: BIG5). |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #include "cesbi.h" |
---|
| 31 | |
---|
| 32 | #if defined (ICONV_TO_UCS_CES_TABLE_PCS) \ |
---|
| 33 | || defined (ICONV_FROM_UCS_CES_TABLE_PCS) |
---|
| 34 | |
---|
| 35 | #include <_ansi.h> |
---|
| 36 | #include <reent.h> |
---|
| 37 | #include <sys/types.h> |
---|
| 38 | #include "../lib/local.h" |
---|
| 39 | #include "../lib/ucsconv.h" |
---|
| 40 | |
---|
| 41 | #if defined (ICONV_FROM_UCS_CES_TABLE_PCS) |
---|
| 42 | static size_t |
---|
| 43 | table_pcs_convert_from_ucs (void *data, |
---|
| 44 | ucs4_t in, |
---|
| 45 | unsigned char **outbuf, |
---|
| 46 | size_t *outbytesleft) |
---|
| 47 | { |
---|
| 48 | if (*outbytesleft < 1) |
---|
| 49 | return (size_t)ICONV_CES_NOSPACE; |
---|
| 50 | |
---|
| 51 | if (in < 0x80) |
---|
| 52 | { |
---|
| 53 | **outbuf = (unsigned char)in; |
---|
| 54 | *outbuf += 1; |
---|
| 55 | *outbytesleft -= 1; |
---|
| 56 | return 1; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | return _iconv_from_ucs_ces_handlers_table.convert_from_ucs ( |
---|
| 60 | data, |
---|
| 61 | in, |
---|
| 62 | outbuf, |
---|
| 63 | outbytesleft); |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | static void * |
---|
| 67 | table_pcs_from_ucs_init (struct _reent *rptr, |
---|
| 68 | const char *encoding) |
---|
| 69 | { |
---|
| 70 | return _iconv_from_ucs_ces_handlers_table.init (rptr, encoding); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | static size_t |
---|
| 74 | table_pcs_from_ucs_close (struct _reent *rptr, |
---|
| 75 | void *data) |
---|
| 76 | { |
---|
| 77 | return _iconv_from_ucs_ces_handlers_table.close (rptr, data); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | static int |
---|
| 81 | table_pcs_from_ucs_get_mb_cur_max (void *data) |
---|
| 82 | { |
---|
| 83 | return _iconv_from_ucs_ces_handlers_table.get_mb_cur_max (data); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | #endif /* ICONV_FROM_UCS_CES_TABLE_PCS */ |
---|
| 87 | |
---|
| 88 | #if defined (ICONV_TO_UCS_CES_TABLE_PCS) |
---|
| 89 | static ucs4_t |
---|
| 90 | table_pcs_convert_to_ucs (void *data, |
---|
| 91 | const unsigned char **inbuf, |
---|
| 92 | size_t *inbytesleft) |
---|
| 93 | { |
---|
| 94 | if (*inbytesleft < 1) |
---|
| 95 | return (ucs4_t)ICONV_CES_BAD_SEQUENCE; |
---|
| 96 | |
---|
| 97 | if (**inbuf < 0x80) |
---|
| 98 | { |
---|
| 99 | *inbytesleft -= 1; |
---|
| 100 | *inbuf += 1; |
---|
| 101 | return (ucs4_t)(*(*inbuf - 1)); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | return _iconv_to_ucs_ces_handlers_table.convert_to_ucs ( |
---|
| 105 | data, |
---|
| 106 | inbuf, |
---|
| 107 | inbytesleft); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | static void * |
---|
| 111 | table_pcs_to_ucs_init (struct _reent *rptr, |
---|
| 112 | const char *encoding) |
---|
| 113 | { |
---|
| 114 | return _iconv_to_ucs_ces_handlers_table.init (rptr, encoding); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | static size_t |
---|
| 118 | table_pcs_to_ucs_close (struct _reent *rptr, |
---|
| 119 | void *data) |
---|
| 120 | { |
---|
| 121 | return _iconv_to_ucs_ces_handlers_table.close (rptr, data); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | static int |
---|
| 125 | table_pcs_to_ucs_get_mb_cur_max (void *data) |
---|
| 126 | { |
---|
| 127 | return _iconv_to_ucs_ces_handlers_table.get_mb_cur_max (data); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | #endif /* ICONV_TO_UCS_CES_TABLE_PCS */ |
---|
| 131 | |
---|
| 132 | #if defined (ICONV_FROM_UCS_CES_TABLE_PCS) |
---|
| 133 | const iconv_from_ucs_ces_handlers_t |
---|
| 134 | _iconv_from_ucs_ces_handlers_table_pcs = |
---|
| 135 | { |
---|
| 136 | table_pcs_from_ucs_init, |
---|
| 137 | table_pcs_from_ucs_close, |
---|
| 138 | table_pcs_from_ucs_get_mb_cur_max, |
---|
| 139 | NULL, |
---|
| 140 | NULL, |
---|
| 141 | NULL, |
---|
| 142 | table_pcs_convert_from_ucs |
---|
| 143 | }; |
---|
| 144 | #endif |
---|
| 145 | |
---|
| 146 | #if defined (ICONV_TO_UCS_CES_TABLE_PCS) |
---|
| 147 | const iconv_to_ucs_ces_handlers_t |
---|
| 148 | _iconv_to_ucs_ces_handlers_table_pcs = |
---|
| 149 | { |
---|
| 150 | table_pcs_to_ucs_init, |
---|
| 151 | table_pcs_to_ucs_close, |
---|
| 152 | table_pcs_to_ucs_get_mb_cur_max, |
---|
| 153 | NULL, |
---|
| 154 | NULL, |
---|
| 155 | NULL, |
---|
| 156 | table_pcs_convert_to_ucs |
---|
| 157 | }; |
---|
| 158 | #endif |
---|
| 159 | |
---|
| 160 | #endif /* ICONV_TO_UCS_CES_TABLE_PCS || ICONV_FROM_UCS_CES_TABLE_PCS */ |
---|
| 161 | |
---|