Back to index

glibc  2.9
cp1255.c
Go to the documentation of this file.
00001 /* Conversion from and to CP1255.
00002    Copyright (C) 1998, 2001, 2002, 2004 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998,
00005    and Bruno Haible <haible@clisp.cons.org>, 2001.
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; if not, write to the Free
00019    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020    02111-1307 USA.  */
00021 
00022 #include <dlfcn.h>
00023 #include <stdint.h>
00024 #include <assert.h>
00025 
00026 #define NELEMS(arr) (sizeof (arr) / sizeof (arr[0]))
00027 
00028 /* Definitions used in the body of the `gconv' function.  */
00029 #define CHARSET_NAME        "CP1255//"
00030 #define FROM_LOOP           from_cp1255
00031 #define TO_LOOP                    to_cp1255
00032 #define DEFINE_INIT         1
00033 #define DEFINE_FINI         1
00034 #define FROM_LOOP_MIN_NEEDED_FROM  1
00035 #define FROM_LOOP_MAX_NEEDED_FROM  1
00036 #define FROM_LOOP_MIN_NEEDED_TO           4
00037 #define FROM_LOOP_MAX_NEEDED_TO           4
00038 #define TO_LOOP_MIN_NEEDED_FROM           4
00039 #define TO_LOOP_MAX_NEEDED_FROM           4
00040 #define TO_LOOP_MIN_NEEDED_TO             1
00041 #define TO_LOOP_MAX_NEEDED_TO             3
00042 #define PREPARE_LOOP \
00043   int saved_state;                                                   \
00044   int *statep = &data->__statep->__count;
00045 #define EXTRA_LOOP_ARGS            , statep
00046 
00047 
00048 /* Since we might have to reset input pointer we must be able to save
00049    and restore the state.  */
00050 #define SAVE_RESET_STATE(Save) \
00051   if (Save)                                                          \
00052     saved_state = *statep;                                           \
00053   else                                                               \
00054     *statep = saved_state
00055 
00056 
00057 /* During CP1255 to UCS4 conversion, the COUNT element of the state
00058    contains the last UCS4 character, shifted by 3 bits.  */
00059 
00060 
00061 /* Since this is a stateful encoding we have to provide code which resets
00062    the output state to the initial state.  This has to be done during the
00063    flushing.  */
00064 #define EMIT_SHIFT_TO_INIT \
00065   if (data->__statep->__count != 0)                                         \
00066     {                                                                \
00067       if (FROM_DIRECTION)                                            \
00068        {                                                             \
00069          if (__builtin_expect (outbuf + 4 <= outend, 1))                    \
00070            {                                                         \
00071              /* Write out the last character.  */                           \
00072              *((uint32_t *) outbuf) = data->__statep->__count >> 3;         \
00073              outbuf += sizeof (uint32_t);                            \
00074              data->__statep->__count = 0;                            \
00075            }                                                         \
00076          else                                                        \
00077            /* We don't have enough room in the output buffer.  */           \
00078            status = __GCONV_FULL_OUTPUT;                             \
00079        }                                                             \
00080       else                                                           \
00081        /* We don't use shift states in the TO_DIRECTION.  */                \
00082        data->__statep->__count = 0;                                         \
00083     }
00084 
00085 
00086 /* First define the conversion function from CP1255 to UCS4.  */
00087 
00088 static const uint16_t to_ucs4[128] = {
00089   /* 0x80 */
00090   0x20AC,      0, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
00091   0x02C6, 0x2030,      0, 0x2039,      0,      0,      0,      0,
00092   /* 0x90 */
00093        0, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
00094   0x02DC, 0x2122,      0, 0x203A,      0,      0,      0,      0,
00095   /* 0xA0 */
00096   0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AA, 0x00A5, 0x00A6, 0x00A7,
00097   0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
00098   /* 0xB0 */
00099   0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
00100   0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
00101   /* 0xC0 */
00102   0x05B0, 0x05B1, 0x05B2, 0x05B3, 0x05B4, 0x05B5, 0x05B6, 0x05B7,
00103   0x05B8, 0x05B9,      0, 0x05BB, 0x05BC, 0x05BD, 0x05BE, 0x05BF,
00104   /* 0xD0 */
00105   0x05C0, 0x05C1, 0x05C2, 0x05C3, 0x05F0, 0x05F1, 0x05F2, 0x05F3,
00106   0x05F4,      0,      0,      0,      0,      0,      0,      0,
00107   /* 0xE0 */
00108   0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
00109   0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
00110   /* 0xF0 */
00111   0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
00112   0x05E8, 0x05E9, 0x05EA,      0,      0, 0x200E, 0x200F,      0,
00113 };
00114 
00115 /* CP1255 contains eight combining characters:
00116    0x05b4, 0x05b7, 0x05b8, 0x05b9, 0x05bc, 0x05bf, 0x05c1, 0x05c2.  */
00117 
00118 /* Composition tables for each of the relevant combining characters.  */
00119 static const struct {
00120   uint16_t base;
00121   uint16_t composed;
00122 } comp_table_data[] = {
00123 #define COMP_TABLE_IDX_05B4 0
00124 #define COMP_TABLE_LEN_05B4 1
00125   { 0x05D9, 0xFB1D },
00126 #define COMP_TABLE_IDX_05B7 (COMP_TABLE_IDX_05B4 + COMP_TABLE_LEN_05B4)
00127 #define COMP_TABLE_LEN_05B7 2
00128   { 0x05D0, 0xFB2E },
00129   { 0x05F2, 0xFB1F },
00130 #define COMP_TABLE_IDX_05B8 (COMP_TABLE_IDX_05B7 + COMP_TABLE_LEN_05B7)
00131 #define COMP_TABLE_LEN_05B8 1
00132   { 0x05D0, 0xFB2F },
00133 #define COMP_TABLE_IDX_05B9 (COMP_TABLE_IDX_05B8 + COMP_TABLE_LEN_05B8)
00134 #define COMP_TABLE_LEN_05B9 1
00135   { 0x05D5, 0xFB4B },
00136 #define COMP_TABLE_IDX_05BC (COMP_TABLE_IDX_05B9 + COMP_TABLE_LEN_05B9)
00137 #define COMP_TABLE_LEN_05BC 24
00138   { 0x05D0, 0xFB30 },
00139   { 0x05D1, 0xFB31 },
00140   { 0x05D2, 0xFB32 },
00141   { 0x05D3, 0xFB33 },
00142   { 0x05D4, 0xFB34 },
00143   { 0x05D5, 0xFB35 },
00144   { 0x05D6, 0xFB36 },
00145   { 0x05D8, 0xFB38 },
00146   { 0x05D9, 0xFB39 },
00147   { 0x05DA, 0xFB3A },
00148   { 0x05DB, 0xFB3B },
00149   { 0x05DC, 0xFB3C },
00150   { 0x05DE, 0xFB3E },
00151   { 0x05E0, 0xFB40 },
00152   { 0x05E1, 0xFB41 },
00153   { 0x05E3, 0xFB43 },
00154   { 0x05E4, 0xFB44 },
00155   { 0x05E6, 0xFB46 },
00156   { 0x05E7, 0xFB47 },
00157   { 0x05E8, 0xFB48 },
00158   { 0x05E9, 0xFB49 },
00159   { 0x05EA, 0xFB4A },
00160   { 0xFB2A, 0xFB2C },
00161   { 0xFB2B, 0xFB2D },
00162 #define COMP_TABLE_IDX_05BF (COMP_TABLE_IDX_05BC + COMP_TABLE_LEN_05BC)
00163 #define COMP_TABLE_LEN_05BF 3
00164   { 0x05D1, 0xFB4C },
00165   { 0x05DB, 0xFB4D },
00166   { 0x05E4, 0xFB4E },
00167 #define COMP_TABLE_IDX_05C1 (COMP_TABLE_IDX_05BF + COMP_TABLE_LEN_05BF)
00168 #define COMP_TABLE_LEN_05C1 2
00169   { 0x05E9, 0xFB2A },
00170   { 0xFB49, 0xFB2C },
00171 #define COMP_TABLE_IDX_05C2 (COMP_TABLE_IDX_05C1 + COMP_TABLE_LEN_05C1)
00172 #define COMP_TABLE_LEN_05C2 2
00173   { 0x05E9, 0xFB2B },
00174   { 0xFB49, 0xFB2D },
00175 #define COMP_TABLE_IDX_END (COMP_TABLE_IDX_05C2 + COMP_TABLE_LEN_05C2)
00176 };
00177 /* Compile-time verification of table size.  */
00178 typedef int verify1[(NELEMS (comp_table_data) == COMP_TABLE_IDX_END) - 1];
00179 
00180 static const struct { unsigned int idx; unsigned int len; } comp_table[8] = {
00181   { COMP_TABLE_IDX_05B4, COMP_TABLE_LEN_05B4 },
00182   { COMP_TABLE_IDX_05B7, COMP_TABLE_LEN_05B7 },
00183   { COMP_TABLE_IDX_05B8, COMP_TABLE_LEN_05B8 },
00184   { COMP_TABLE_IDX_05B9, COMP_TABLE_LEN_05B9 },
00185   { COMP_TABLE_IDX_05BC, COMP_TABLE_LEN_05BC },
00186   { COMP_TABLE_IDX_05BF, COMP_TABLE_LEN_05BF },
00187   { COMP_TABLE_IDX_05C1, COMP_TABLE_LEN_05C1 },
00188   { COMP_TABLE_IDX_05C2, COMP_TABLE_LEN_05C2 },
00189 };
00190 
00191 #define MIN_NEEDED_INPUT    FROM_LOOP_MIN_NEEDED_FROM
00192 #define MAX_NEEDED_INPUT    FROM_LOOP_MAX_NEEDED_FROM
00193 #define MIN_NEEDED_OUTPUT   FROM_LOOP_MIN_NEEDED_TO
00194 #define MAX_NEEDED_OUTPUT   FROM_LOOP_MAX_NEEDED_TO
00195 #define LOOPFCT                    FROM_LOOP
00196 #define BODY \
00197   {                                                                  \
00198     uint32_t ch = *inptr;                                            \
00199     uint32_t last_ch;                                                       \
00200     int must_buffer_ch;                                                     \
00201                                                                      \
00202     if (ch >= 0x80)                                                  \
00203       {                                                                     \
00204        ch = to_ucs4[ch - 0x80];                                      \
00205        if (__builtin_expect (ch == L'\0', 0))                               \
00206          {                                                           \
00207            /* This is an illegal character.  */                      \
00208            STANDARD_FROM_LOOP_ERR_HANDLER (1);                              \
00209          }                                                           \
00210       }                                                                     \
00211                                                                      \
00212     /* Determine whether there is a buffered character pending.  */         \
00213     last_ch = *statep >> 3;                                          \
00214                                                                      \
00215     /* We have to buffer ch if it is a possible match in comp_table_data.  */ \
00216     must_buffer_ch = (ch >= 0x05d0 && ch <= 0x05f2);                        \
00217                                                                      \
00218     if (last_ch)                                                     \
00219       {                                                                     \
00220        if (ch >= 0x05b0 && ch < 0x05c5)                              \
00221          {                                                           \
00222            /* See whether last_ch and ch can be combined.  */               \
00223            unsigned int i, i1, i2;                                   \
00224                                                                      \
00225            switch (ch)                                                      \
00226              {                                                              \
00227              case 0x05b4:                                            \
00228               i = 0;                                                 \
00229               break;                                                 \
00230              case 0x05b7:                                            \
00231               i = 1;                                                 \
00232               break;                                                 \
00233              case 0x05b8:                                            \
00234               i = 2;                                                 \
00235               break;                                                 \
00236              case 0x05b9:                                            \
00237               i = 3;                                                 \
00238               break;                                                 \
00239              case 0x05bc:                                            \
00240               i = 4;                                                 \
00241               break;                                                 \
00242              case 0x05bf:                                            \
00243               i = 5;                                                 \
00244               break;                                                 \
00245              case 0x05c1:                                            \
00246               i = 6;                                                 \
00247               break;                                                 \
00248              case 0x05c2:                                            \
00249               i = 7;                                                 \
00250               break;                                                 \
00251              default:                                                       \
00252               goto not_combining;                                    \
00253              }                                                              \
00254                                                                      \
00255            i1 = comp_table[i].idx;                                   \
00256            i2 = i1 + comp_table[i].len - 1;                                 \
00257                                                                      \
00258            if (last_ch >= comp_table_data[i1].base                          \
00259               && last_ch <= comp_table_data[i2].base)                       \
00260              {                                                              \
00261               for (;;)                                               \
00262                 {                                                    \
00263                   i = (i1 + i2) >> 1;                                       \
00264                   if (last_ch == comp_table_data[i].base)                   \
00265                     break;                                           \
00266                   if (last_ch < comp_table_data[i].base)                    \
00267                     {                                                       \
00268                      if (i1 == i)                                    \
00269                        goto not_combining;                                  \
00270                      i2 = i;                                                \
00271                     }                                                       \
00272                   else                                               \
00273                     {                                                       \
00274                      if (i1 != i)                                    \
00275                        i1 = i;                                       \
00276                      else                                            \
00277                        {                                             \
00278                          i = i2;                                     \
00279                          if (last_ch == comp_table_data[i].base)            \
00280                            break;                                    \
00281                          goto not_combining;                                \
00282                        }                                             \
00283                     }                                                       \
00284                 }                                                    \
00285               last_ch = comp_table_data[i].composed;                        \
00286               if (last_ch == 0xfb2a || last_ch == 0xfb2b                    \
00287                   || last_ch == 0xfb49)                              \
00288                 /* Buffer the combined character.  */                       \
00289                 *statep = last_ch << 3;                              \
00290               else                                                   \
00291                 {                                                    \
00292                   /* Output the combined character.  */              \
00293                   put32 (outptr, last_ch);                                  \
00294                   outptr += 4;                                       \
00295                   *statep = 0;                                       \
00296                 }                                                    \
00297               ++inptr;                                               \
00298               continue;                                              \
00299              }                                                              \
00300          }                                                           \
00301                                                                      \
00302       not_combining:                                                 \
00303        /* Output the buffered character.  */                                \
00304        put32 (outptr, last_ch);                                      \
00305        outptr += 4;                                                  \
00306        *statep = 0;                                                  \
00307                                                                      \
00308        /* If we don't have enough room to output ch as well, then deal             \
00309           with it in another round.  */                              \
00310        if (!must_buffer_ch && __builtin_expect (outptr + 4 > outend, 0))     \
00311          continue;                                                   \
00312       }                                                                     \
00313                                                                      \
00314     if (must_buffer_ch)                                                     \
00315       *statep = ch << 3;                                             \
00316     else                                                             \
00317       {                                                                     \
00318        put32 (outptr, ch);                                           \
00319        outptr += 4;                                                  \
00320       }                                                                     \
00321     ++inptr;                                                         \
00322   }
00323 #define LOOP_NEED_FLAGS
00324 #define EXTRA_LOOP_DECLS    , int *statep
00325 #define ONEBYTE_BODY \
00326   {                                                                  \
00327     if (c < 0x80)                                                    \
00328       return c;                                                             \
00329     uint32_t ch = to_ucs4[c - 0x80];                                        \
00330     if (ch == L'\0' || (ch >= 0x05d0 && ch <= 0x05f2))                      \
00331       return WEOF;                                                   \
00332     return ch;                                                              \
00333   }
00334 #include <iconv/loop.c>
00335 
00336 
00337 /* Next, define the conversion function from UCS4 to CP1255.  */
00338 
00339 static const unsigned char from_ucs4[] = {
00340 #define FROM_IDX_00 0
00341   0xa0, 0xa1, 0xa2, 0xa3, 0x00, 0xa5, 0xa6, 0xa7, /* 0x00a0-0x00a7 */
00342   0xa8, 0xa9, 0x00, 0xab, 0xac, 0xad, 0xae, 0xaf, /* 0x00a8-0x00af */
00343   0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, /* 0x00b0-0x00b7 */
00344   0xb8, 0xb9, 0x00, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, /* 0x00b8-0x00bf */
00345   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00c0-0x00c7 */
00346   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00c8-0x00cf */
00347   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, /* 0x00d0-0x00d7 */
00348   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00d8-0x00df */
00349   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00e0-0x00e7 */
00350   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00e8-0x00ef */
00351   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xba, /* 0x00f0-0x00f7 */
00352 #define FROM_IDX_02 (FROM_IDX_00 + 88)
00353                                       0x88, 0x00, /* 0x02c6-0x02c7 */
00354   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02c8-0x02cf */
00355   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02d0-0x02d7 */
00356   0x00, 0x00, 0x00, 0x00, 0x98,                   /* 0x02d8-0x02dc */
00357 #define FROM_IDX_05 (FROM_IDX_02 + 23)
00358   0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* 0x05b0-0x05b7 */
00359   0xc8, 0xc9, 0x00, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, /* 0x05b8-0x05bf */
00360   0xd0, 0xd1, 0xd2, 0xd3, 0x00, 0x00, 0x00, 0x00, /* 0x05c0-0x05c7 */
00361   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x05c8-0x05cf */
00362   0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, /* 0x05d0-0x05d7 */
00363   0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, /* 0x05d8-0x05df */
00364   0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, /* 0x05e0-0x05e7 */
00365   0xf8, 0xf9, 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x05e8-0x05ef */
00366   0xd4, 0xd5, 0xd6, 0xd7, 0xd8,                   /* 0x05f0-0x05f4 */
00367 #define FROM_IDX_20 (FROM_IDX_05 + 69)
00368                                       0xfd, 0xfe, /* 0x200e-0x200f */
00369   0x00, 0x00, 0x00, 0x96, 0x97, 0x00, 0x00, 0x00, /* 0x2010-0x2017 */
00370   0x91, 0x92, 0x82, 0x00, 0x93, 0x94, 0x84, 0x00, /* 0x2018-0x201f */
00371   0x86, 0x87, 0x95, 0x00, 0x00, 0x00, 0x85, 0x00, /* 0x2020-0x2027 */
00372   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2028-0x202f */
00373   0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2030-0x2037 */
00374   0x00, 0x8b, 0x9b,                               /* 0x2038-0x203a */
00375 #define FROM_IDX_FF (FROM_IDX_20 + 45)
00376 };
00377 /* Compile-time verification of table size.  */
00378 typedef int verify2[(NELEMS (from_ucs4) == FROM_IDX_FF) - 1];
00379 
00380 static const unsigned char comb_table[8] = {
00381   0xc4, 0xc7, 0xc8, 0xc9, 0xcc, 0xcf, 0xd1, 0xd2,
00382 };
00383 
00384 /* Decomposition table for the relevant Unicode characters. */
00385 static const struct {
00386   uint16_t composed;
00387   uint16_t base;
00388   uint32_t comb1 : 8;
00389   int32_t comb2 : 8;
00390 } decomp_table[] = {
00391   { 0xFB1D, 0x05D9, 0, -1 },
00392   { 0xFB1F, 0x05F2, 1, -1 },
00393   { 0xFB2A, 0x05E9, 6, -1 },
00394   { 0xFB2B, 0x05E9, 7, -1 },
00395   { 0xFB2C, 0x05E9, 4, 6 },
00396   { 0xFB2D, 0x05E9, 4, 7 },
00397   { 0xFB2E, 0x05D0, 1, -1 },
00398   { 0xFB2F, 0x05D0, 2, -1 },
00399   { 0xFB30, 0x05D0, 4, -1 },
00400   { 0xFB31, 0x05D1, 4, -1 },
00401   { 0xFB32, 0x05D2, 4, -1 },
00402   { 0xFB33, 0x05D3, 4, -1 },
00403   { 0xFB34, 0x05D4, 4, -1 },
00404   { 0xFB35, 0x05D5, 4, -1 },
00405   { 0xFB36, 0x05D6, 4, -1 },
00406   { 0xFB38, 0x05D8, 4, -1 },
00407   { 0xFB39, 0x05D9, 4, -1 },
00408   { 0xFB3A, 0x05DA, 4, -1 },
00409   { 0xFB3B, 0x05DB, 4, -1 },
00410   { 0xFB3C, 0x05DC, 4, -1 },
00411   { 0xFB3E, 0x05DE, 4, -1 },
00412   { 0xFB40, 0x05E0, 4, -1 },
00413   { 0xFB41, 0x05E1, 4, -1 },
00414   { 0xFB43, 0x05E3, 4, -1 },
00415   { 0xFB44, 0x05E4, 4, -1 },
00416   { 0xFB46, 0x05E6, 4, -1 },
00417   { 0xFB47, 0x05E7, 4, -1 },
00418   { 0xFB48, 0x05E8, 4, -1 },
00419   { 0xFB49, 0x05E9, 4, -1 },
00420   { 0xFB4A, 0x05EA, 4, -1 },
00421   { 0xFB4B, 0x05D5, 3, -1 },
00422   { 0xFB4C, 0x05D1, 5, -1 },
00423   { 0xFB4D, 0x05DB, 5, -1 },
00424   { 0xFB4E, 0x05E4, 5, -1 },
00425 };
00426 
00427 #define MIN_NEEDED_INPUT    TO_LOOP_MIN_NEEDED_FROM
00428 #define MAX_NEEDED_INPUT    TO_LOOP_MAX_NEEDED_FROM
00429 #define MIN_NEEDED_OUTPUT   TO_LOOP_MIN_NEEDED_TO
00430 #define MAX_NEEDED_OUTPUT   TO_LOOP_MAX_NEEDED_TO
00431 #define LOOPFCT                    TO_LOOP
00432 #define BODY \
00433   {                                                                  \
00434     uint32_t ch = get32 (inptr);                                     \
00435                                                                      \
00436     if (ch < 0x0080)                                                 \
00437       {                                                                     \
00438        *outptr++ = ch;                                                      \
00439        inptr += 4;                                                   \
00440       }                                                                     \
00441     else                                                             \
00442       {                                                                     \
00443        unsigned char res;                                            \
00444                                                                      \
00445        if (ch >= 0x00a0 && ch < 0x00f8)                              \
00446          res = from_ucs4[ch - 0x00a0 + FROM_IDX_00];                        \
00447        else if (ch == 0x0192)                                               \
00448          res = 0x83;                                                 \
00449        else if (ch >= 0x02c6 && ch < 0x02dd)                                \
00450          res = from_ucs4[ch - 0x02c6 + FROM_IDX_02];                        \
00451        else if (ch >= 0x05b0 && ch < 0x05f5)                                \
00452          res = from_ucs4[ch - 0x05b0 + FROM_IDX_05];                        \
00453        else if (ch >= 0x200e && ch < 0x203b)                                \
00454          res = from_ucs4[ch - 0x200e + FROM_IDX_20];                        \
00455        else if (ch == 0x20aa)                                               \
00456          res = 0xa4;                                                 \
00457        else if (ch == 0x20ac)                                               \
00458          res = 0x80;                                                 \
00459        else if (ch == 0x2122)                                               \
00460          res = 0x99;                                                 \
00461        else                                                          \
00462          {                                                           \
00463            UNICODE_TAG_HANDLER (ch, 4);                              \
00464            res = 0;                                                  \
00465          }                                                           \
00466                                                                      \
00467        if (__builtin_expect (res != 0, 1))                                  \
00468          {                                                           \
00469            *outptr++ = res;                                          \
00470            inptr += 4;                                                      \
00471          }                                                           \
00472        else                                                          \
00473          {                                                           \
00474            /* Try canonical decomposition.  */                              \
00475            unsigned int i1, i2;                                      \
00476                                                                      \
00477            i1 = 0;                                                   \
00478            i2 = sizeof (decomp_table) / sizeof (decomp_table[0]) - 1;       \
00479            if (ch >= decomp_table[i1].composed                              \
00480               && ch <= decomp_table[i2].composed)                           \
00481              {                                                              \
00482               unsigned int i;                                               \
00483                                                                      \
00484               for (;;)                                               \
00485                 {                                                    \
00486                   i = (i1 + i2) >> 1;                                       \
00487                   if (ch == decomp_table[i].composed)                       \
00488                     break;                                           \
00489                   if (ch < decomp_table[i].composed)                        \
00490                     {                                                       \
00491                      if (i1 == i)                                    \
00492                        goto failed;                                         \
00493                      i2 = i;                                                \
00494                     }                                                       \
00495                   else                                               \
00496                     {                                                       \
00497                      if (i1 != i)                                    \
00498                        i1 = i;                                       \
00499                      else                                            \
00500                        {                                             \
00501                          i = i2;                                     \
00502                          if (ch == decomp_table[i].composed)                \
00503                            break;                                    \
00504                          goto failed;                                \
00505                        }                                             \
00506                     }                                                       \
00507                 }                                                    \
00508                                                                      \
00509               /* Found a canonical decomposition.  */                       \
00510               ch = decomp_table[i].base;                             \
00511               /* ch is one of 0x05d0..0x05d6, 0x05d8..0x05dc, 0x05de,       \
00512                  0x05e0..0x05e1, 0x05e3..0x05e4, 0x05e6..0x05ea, 0x05f2. */ \
00513               ch = from_ucs4[ch - 0x05b0 + FROM_IDX_05];                    \
00514               assert (ch != 0);                                      \
00515                                                                      \
00516               if (decomp_table[i].comb2 < 0)                                \
00517                 {                                                    \
00518                   /* See whether we have room for two bytes.  */            \
00519                   if (__builtin_expect (outptr + 1 >= outend, 0))           \
00520                     {                                                       \
00521                      result = __GCONV_FULL_OUTPUT;                          \
00522                      break;                                          \
00523                     }                                                       \
00524                                                                      \
00525                   *outptr++ = (unsigned char) ch;                           \
00526                   *outptr++ = comb_table[decomp_table[i].comb1];            \
00527                 }                                                    \
00528               else                                                   \
00529                 {                                                    \
00530                   /* See whether we have room for three bytes.  */          \
00531                   if (__builtin_expect (outptr + 2 >= outend, 0))           \
00532                     {                                                       \
00533                      result = __GCONV_FULL_OUTPUT;                          \
00534                      break;                                          \
00535                     }                                                       \
00536                                                                      \
00537                   *outptr++ = (unsigned char) ch;                           \
00538                   *outptr++ = comb_table[decomp_table[i].comb1];            \
00539                   *outptr++ = comb_table[decomp_table[i].comb2];            \
00540                 }                                                    \
00541                                                                      \
00542               inptr += 4;                                            \
00543               continue;                                              \
00544              }                                                              \
00545                                                                      \
00546          failed:                                                     \
00547            /* This is an illegal character.  */                      \
00548            STANDARD_TO_LOOP_ERR_HANDLER (4);                                \
00549          }                                                           \
00550       }                                                                     \
00551   }
00552 #define LOOP_NEED_FLAGS
00553 #define EXTRA_LOOP_DECLS    , int *statep
00554 #include <iconv/loop.c>
00555 
00556 
00557 /* Now define the toplevel functions.  */
00558 #include <iconv/skeleton.c>