]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - iconvdata/johab.c
Replace FSF snail mail address with URLs.
[thirdparty/glibc.git] / iconvdata / johab.c
index a0b200f36b76ab3afa194a3f515d34e22400d2f8..f5749aba7f4f516bc3a4b6230738d2bdfa368c3e 100644 (file)
@@ -1,5 +1,5 @@
 /* Mapping tables for JOHAB handling.
-   Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1998-2002, 2007, 2011 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jungshik Shin <jshin@pantheon.yale.edu>
    and Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -15,9 +15,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <dlfcn.h>
 #include <stdint.h>
@@ -93,7 +92,7 @@ static const int init_to_bit[19] =
 
 static const int mid_to_bit[21] =
 {
-          0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
+         0x0060, 0x0080, 0x00a0, 0x00c0, 0x00e0,
   0x0140, 0x0160, 0x0180, 0x01a0, 0x01c0, 0x1e0,
   0x0240, 0x0260, 0x0280, 0x02a0, 0x02c0, 0x02e0,
   0x0340, 0x0360, 0x0380, 0x03a0
@@ -132,7 +131,7 @@ static const uint16_t jamo_from_ucs_table[51] =
 };
 
 
-static inline uint32_t
+static uint32_t
 johab_sym_hanja_to_ucs (uint_fast32_t idx, uint_fast32_t c1, uint_fast32_t c2)
 {
   if (idx <= 0xdefe)
@@ -178,22 +177,13 @@ johab_sym_hanja_to_ucs (uint_fast32_t idx, uint_fast32_t c1, uint_fast32_t c2)
        0xd831-0xd87e and 0xd891-0xd8fe are user-defined area */                      \
     else                                                                     \
       {                                                                              \
-       if (__builtin_expect (ch, 0) > 0xf9                                   \
-           || __builtin_expect (ch, 0) == 0xdf                               \
-           || (__builtin_expect (ch, 0) > 0x7e && ch < 0x84)                 \
-           || (__builtin_expect (ch, 0) > 0xd3 && ch < 0xd9))                \
+       if (__builtin_expect (ch > 0xf9, 0)                                   \
+           || __builtin_expect (ch == 0xdf, 0)                               \
+           || (__builtin_expect (ch > 0x7e, 0) && ch < 0x84)                 \
+           || (__builtin_expect (ch > 0xd3, 0) && ch < 0xd9))                \
          {                                                                   \
            /* These are illegal.  */                                         \
-           if (! ignore_errors_p ())                                         \
-             {                                                               \
-               /* This is an illegal character.  */                          \
-               result = __GCONV_ILLEGAL_INPUT;                               \
-               break;                                                        \
-             }                                                               \
-                                                                             \
-           ++inptr;                                                          \
-           ++*irreversible;                                                  \
-           continue;                                                         \
+           STANDARD_FROM_LOOP_ERR_HANDLER (1);                               \
          }                                                                   \
        else                                                                  \
          {                                                                   \
@@ -212,30 +202,21 @@ johab_sym_hanja_to_ucs (uint_fast32_t idx, uint_fast32_t c1, uint_fast32_t c2)
                                                                              \
            ch2 = inptr[1];                                                   \
            idx = ch * 256 + ch2;                                             \
-           if (__builtin_expect (ch, 0) <= 0xd3)                             \
+           if (__builtin_expect (ch <= 0xd3, 1))                             \
              {                                                               \
                /* Hangul */                                                  \
-               uint_fast32_t i, m, f;                                        \
+               int_fast32_t i, m, f;                                         \
                                                                              \
                i = init[(idx & 0x7c00) >> 10];                               \
                m = mid[(idx & 0x03e0) >> 5];                                 \
                f = final[idx & 0x001f];                                      \
                                                                              \
-               if (__builtin_expect (i, 0) == -1                             \
-                   || __builtin_expect (m, 0) == -1                          \
-                   || __builtin_expect (f, 0) == -1)                         \
+               if (__builtin_expect (i == -1, 0)                             \
+                   || __builtin_expect (m == -1, 0)                          \
+                   || __builtin_expect (f == -1, 0))                         \
                  {                                                           \
                    /* This is illegal.  */                                   \
-                   if (! ignore_errors_p ())                                 \
-                     {                                                       \
-                       /* This is an illegal character.  */                  \
-                       result = __GCONV_ILLEGAL_INPUT;                       \
-                       break;                                                \
-                     }                                                       \
-                                                                             \
-                   ++inptr;                                                  \
-                   ++*irreversible;                                          \
-                   continue;                                                 \
+                   STANDARD_FROM_LOOP_ERR_HANDLER (1);                       \
                  }                                                           \
                else if (i > 0 && m > 0)                                      \
                  ch = ((i - 1) * 21 + (m - 1)) * 28 + f + 0xac00;            \
@@ -243,45 +224,27 @@ johab_sym_hanja_to_ucs (uint_fast32_t idx, uint_fast32_t c1, uint_fast32_t c2)
                  ch = init_to_ucs[i - 1];                                    \
                else if (i == 0 && m > 0 && f == 0)                           \
                  ch = 0x314e + m;      /* 0x314f + m - 1 */                  \
-               else if (__builtin_expect (i | m, 0) == 0                     \
-                        && __builtin_expect (f, 1) > 0)                      \
+               else if (__builtin_expect ((i | m) == 0, 1)                   \
+                        && __builtin_expect (f > 0, 1))                      \
                  ch = final_to_ucs[f - 1];     /* round trip?? */            \
                else                                                          \
                  {                                                           \
                    /* This is illegal.  */                                   \
-                   if (! ignore_errors_p ())                                 \
-                     {                                                       \
-                       /* This is an illegal character.  */                  \
-                       result = __GCONV_ILLEGAL_INPUT;                       \
-                       break;                                                \
-                     }                                                       \
-                                                                             \
-                   ++inptr;                                                  \
-                   ++*irreversible;                                          \
-                   continue;                                                 \
+                   STANDARD_FROM_LOOP_ERR_HANDLER (1);                       \
                  }                                                           \
              }                                                               \
            else                                                              \
              {                                                               \
-               if (__builtin_expect (ch2, 0x31) < 0x31                       \
-                   || (__builtin_expect (ch2, 0x7e) > 0x7e && ch2 < 0x91)    \
+               if (__builtin_expect (ch2 < 0x31, 0)                          \
+                   || (__builtin_expect (ch2 > 0x7e, 0) && ch2 < 0x91)       \
                    || __builtin_expect (ch2, 0) == 0xff                      \
-                   || (__builtin_expect (ch, 0) == 0xd9 && ch2 > 0xe5)       \
+                   || (__builtin_expect (ch, 0) == 0xd9 && ch2 > 0xe8)       \
                    || (__builtin_expect (ch, 0) == 0xda                      \
                        && ch2 > 0xa0 && ch2 < 0xd4)                          \
                    || (__builtin_expect (ch, 0) == 0xde && ch2 > 0xf1))      \
                  {                                                           \
                    /* This is illegal.  */                                   \
-                   if (! ignore_errors_p ())                                 \
-                     {                                                       \
-                       /* This is an illegal character.  */                  \
-                       result = __GCONV_ILLEGAL_INPUT;                       \
-                       break;                                                \
-                     }                                                       \
-                                                                             \
-                   ++inptr;                                                  \
-                   ++*irreversible;                                          \
-                   continue;                                                 \
+                   STANDARD_FROM_LOOP_ERR_HANDLER (1);                       \
                  }                                                           \
                else                                                          \
                  {                                                           \
@@ -291,7 +254,7 @@ johab_sym_hanja_to_ucs (uint_fast32_t idx, uint_fast32_t c1, uint_fast32_t c2)
                                                   + ch2 - (ch2 > 0x90        \
                                                            ? 0x43 : 0x31)];  \
                       else                                                   \
-                        ch = __ksc5601_hanja_to_ucs[(ch - 0xe0) *192         \
+                        ch = __ksc5601_hanja_to_ucs[(ch - 0xe0) *192         \
                                                     + ch2 -  (ch2 > 0x90     \
                                                               ?0x43 : 0x31)];\
                    */                                                        \
@@ -299,19 +262,10 @@ johab_sym_hanja_to_ucs (uint_fast32_t idx, uint_fast32_t c1, uint_fast32_t c2)
              }                                                               \
          }                                                                   \
                                                                              \
-       if (__builtin_expect (ch, 1) == 0)                                    \
+       if (__builtin_expect (ch == 0, 0))                                    \
          {                                                                   \
            /* This is an illegal character.  */                              \
-           if (! ignore_errors_p ())                                         \
-             {                                                               \
-               /* This is an illegal character.  */                          \
-               result = __GCONV_ILLEGAL_INPUT;                               \
-               break;                                                        \
-             }                                                               \
-                                                                             \
-           inptr += 2;                                                       \
-           ++*irreversible;                                                  \
-           continue;                                                         \
+           STANDARD_FROM_LOOP_ERR_HANDLER (2);                               \
          }                                                                   \
                                                                              \
        inptr += 2;                                                           \
@@ -321,6 +275,13 @@ johab_sym_hanja_to_ucs (uint_fast32_t idx, uint_fast32_t c1, uint_fast32_t c2)
     outptr += 4;                                                             \
   }
 #define LOOP_NEED_FLAGS
+#define ONEBYTE_BODY \
+  {                                                                          \
+    if (c <= 0x7f)                                                           \
+      return (c == 0x5c ? 0x20a9 : c);                                       \
+    else                                                                     \
+      return WEOF;                                                           \
+  }
 #include <iconv/loop.c>
 
 
@@ -394,9 +355,9 @@ johab_sym_hanja_to_ucs (uint_fast32_t idx, uint_fast32_t c1, uint_fast32_t c2)
                result = __GCONV_FULL_OUTPUT;                                 \
                break;                                                        \
              }                                                               \
-           if (__builtin_expect (written, 0) == __UNKNOWN_10646_CHAR)        \
+           if (__builtin_expect (written == __UNKNOWN_10646_CHAR, 0))        \
              {                                                               \
-               STANDARD_ERR_HANDLER (4);                                     \
+               STANDARD_TO_LOOP_ERR_HANDLER (4);                             \
              }                                                               \
                                                                              \
            outptr[0] -= 0x4a;                                                \
@@ -423,11 +384,11 @@ johab_sym_hanja_to_ucs (uint_fast32_t idx, uint_fast32_t c1, uint_fast32_t c2)
                result = __GCONV_FULL_OUTPUT;                                 \
                break;                                                        \
              }                                                               \
-           if (__builtin_expect (written, 1) == __UNKNOWN_10646_CHAR         \
-               || (outptr[0] == 0x22 && outptr[1] > 0x65))                   \
+           if (__builtin_expect (written == __UNKNOWN_10646_CHAR, 0)         \
+               || (outptr[0] == 0x22 && outptr[1] > 0x68))                   \
              {                                                               \
                UNICODE_TAG_HANDLER (ch, 4);                                  \
-               STANDARD_ERR_HANDLER (4);                                     \
+               STANDARD_TO_LOOP_ERR_HANDLER (4);                             \
              }                                                               \
                                                                              \
            temp = (outptr[0] < 0x4a ? outptr[0] + 0x191 : outptr[0] + 0x176);\