Update.
[platform/upstream/glibc.git] / iconvdata / iso-2022-kr.c
index c4ef73e..9846d92 100644 (file)
@@ -1,23 +1,24 @@
 /* Conversion module for ISO-2022-KR.
-   Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   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.  */
 
+#include <dlfcn.h>
 #include <gconv.h>
 #include <stdint.h>
 #include <string.h>
@@ -84,18 +85,15 @@ enum
        }                                                                     \
       else                                                                   \
        {                                                                     \
-         unsigned char *outbuf = data->__outbuf;                             \
-                                                                             \
          /* We are not in the initial state.  To switch back we have         \
             to emit `SI'.  */                                                \
-         if (__builtin_expect (outbuf == data->__outbufend, 0))              \
+         if (__builtin_expect (outbuf == outend, 0))                         \
            /* We don't have enough room in the output buffer.  */            \
            status = __GCONV_FULL_OUTPUT;                                     \
          else                                                                \
            {                                                                 \
              /* Write out the shift sequence.  */                            \
              *outbuf++ = SI;                                                 \
-             data->__outbuf = outbuf;                                        \
              data->__statep->__count = ASCII_set;                            \
            }                                                                 \
        }                                                                     \
@@ -121,7 +119,7 @@ enum
     uint32_t ch = *inptr;                                                    \
                                                                              \
     /* This is a 7bit character set, disallow all 8bit characters.  */       \
-    if (__builtin_expect (ch, 0) > 0x7f)                                     \
+    if (__builtin_expect (ch > 0x7f, 0))                                     \
       {                                                                              \
        if (! ignore_errors_p ())                                             \
          {                                                                   \
@@ -130,7 +128,7 @@ enum
          }                                                                   \
                                                                              \
        ++inptr;                                                              \
-       ++*converted;                                                         \
+       ++*irreversible;                                                      \
        continue;                                                             \
       }                                                                              \
                                                                              \
@@ -141,15 +139,14 @@ enum
           switching is done using the SI and SO bytes.  But we have to       \
           recognize `Esc $ ) C' since this is a kind of flag for this        \
           encoding.  We simply ignore it.  */                                \
-       if ((NEED_LENGTH_TEST && __builtin_expect (inptr + 1 > inend, 0))     \
+       if (__builtin_expect (inptr + 1 > inend, 0)                           \
            || (inptr[1] == '$'                                               \
-               && ((NEED_LENGTH_TEST                                         \
-                    && __builtin_expect (inptr + 2 > inend, 0))              \
+               && (__builtin_expect (inptr + 2 > inend, 0)                   \
                    || (inptr[2] == ')'                                       \
                        && __builtin_expect (inptr + 3 > inend, 0)))))        \
                                                                              \
          {                                                                   \
-           result = __GCONV_EMPTY_INPUT;                                     \
+           result = __GCONV_INCOMPLETE_INPUT;                                \
            break;                                                            \
          }                                                                   \
        if (inptr[1] == '$' && inptr[2] == ')' && inptr[3] == 'C')            \
@@ -184,12 +181,11 @@ enum
        assert (set == KSC5601_set);                                          \
                                                                              \
        /* Use the KSC 5601 table.  */                                        \
-       ch = ksc5601_to_ucs4 (&inptr,                                         \
-                             NEED_LENGTH_TEST ? inend - inptr : 2, 0);       \
+       ch = ksc5601_to_ucs4 (&inptr, inend - inptr, 0);                      \
                                                                              \
-       if (NEED_LENGTH_TEST && __builtin_expect (ch, 1) == 0)                \
+       if (__builtin_expect (ch, 1) == 0)                                    \
          {                                                                   \
-           result = __GCONV_EMPTY_INPUT;                                     \
+           result = __GCONV_INCOMPLETE_INPUT;                                \
            break;                                                            \
          }                                                                   \
        else if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR)            \
@@ -201,7 +197,7 @@ enum
                break;                                                        \
              }                                                               \
                                                                              \
-           ++*converted;                                                     \
+           ++*irreversible;                                                  \
            ++inptr;                                                          \
            continue;                                                         \
          }                                                                   \
@@ -210,6 +206,7 @@ enum
     put32 (outptr, ch);                                                              \
     outptr += 4;                                                             \
   }
+#define LOOP_NEED_FLAGS
 #define EXTRA_LOOP_DECLS       , int *setp
 #define INIT_PARAMS            int set = *setp
 #define UPDATE_PARAMS          *setp = set
@@ -224,7 +221,6 @@ enum
 #define BODY \
   {                                                                          \
     uint32_t ch;                                                             \
-    size_t written = 0;                                                              \
                                                                              \
     ch = get32 (inptr);                                                              \
                                                                              \
@@ -236,7 +232,7 @@ enum
          {                                                                   \
            *outptr++ = SI;                                                   \
            set = ASCII_set;                                                  \
-           if (NEED_LENGTH_TEST && outptr == outend)                         \
+           if (__builtin_expect (outptr == outend, 0))                       \
              {                                                               \
                result = __GCONV_FULL_OUTPUT;                                 \
                break;                                                        \
@@ -244,24 +240,20 @@ enum
          }                                                                   \
                                                                              \
        *outptr++ = ch;                                                       \
-       written = 1;                                                          \
       }                                                                              \
     else                                                                     \
       {                                                                              \
        char buf[2];                                                          \
+       size_t written;                                                       \
                                                                              \
        written = ucs4_to_ksc5601 (ch, buf, 2);                               \
                                                                              \
        if (__builtin_expect (written, 0) == __UNKNOWN_10646_CHAR)            \
          {                                                                   \
-           /* Illegal character.  */                                         \
-           if (! ignore_errors_p ())                                         \
-             {                                                               \
-               result = __GCONV_ILLEGAL_INPUT;                               \
-               break;                                                        \
-             }                                                               \
+           UNICODE_TAG_HANDLER (ch, 4);                                      \
                                                                              \
-           ++*converted;                                                     \
+           /* Illegal character.  */                                         \
+           STANDARD_ERR_HANDLER (4);                                         \
          }                                                                   \
        else                                                                  \
          {                                                                   \
@@ -274,7 +266,7 @@ enum
                set = KSC5601_set;                                            \
              }                                                               \
                                                                              \
-           if (NEED_LENGTH_TEST && __builtin_expect (outptr + 2 > outend, 0))\
+           if (__builtin_expect (outptr + 2 > outend, 0))                    \
              {                                                               \
                result = __GCONV_FULL_OUTPUT;                                 \
                break;                                                        \
@@ -288,6 +280,7 @@ enum
     /* Now that we wrote the output increment the input pointer.  */         \
     inptr += 4;                                                                      \
   }
+#define LOOP_NEED_FLAGS
 #define EXTRA_LOOP_DECLS       , int *setp
 #define INIT_PARAMS            int set = *setp
 #define UPDATE_PARAMS          *setp = set