Fix tst_wcscpy.c test.
[platform/upstream/glibc.git] / iconvdata / sjis.c
index 6f53646..6caae2c 100644 (file)
@@ -1,5 +1,5 @@
 /* Mapping tables for SJIS handling.
-   Copyright (C) 1997-2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1997-2015 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
 
@@ -14,9 +14,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>
@@ -4321,6 +4320,7 @@ static const char from_ucs4_extra[0x100][2] =
 #define MIN_NEEDED_FROM                1
 #define MAX_NEEDED_FROM                2
 #define MIN_NEEDED_TO          4
+#define ONE_DIRECTION          0
 
 /* First define the conversion function from SJIS to UCS4.  */
 #define MIN_NEEDED_INPUT       MIN_NEEDED_FROM
@@ -4353,16 +4353,7 @@ static const char from_ucs4_extra[0x100][2] =
             || __builtin_expect (ch <= 0x80, 0))                             \
       {                                                                              \
        /* 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                                                                     \
       {                                                                              \
@@ -4371,7 +4362,7 @@ static const char from_ucs4_extra[0x100][2] =
        uint32_t ch2;                                                         \
        uint_fast32_t idx;                                                    \
                                                                              \
-       if (__builtin_expect (inptr + 1 >= inend, 0))                         \
+       if (__glibc_unlikely (inptr + 1 >= inend))                            \
          {                                                                   \
            /* The second byte is not available.  Store                       \
               the intermediate result.  */                                   \
@@ -4381,23 +4372,18 @@ static const char from_ucs4_extra[0x100][2] =
                                                                              \
        ch2 = inptr[1];                                                       \
        idx = ch * 256 + ch2;                                                 \
-       if (__builtin_expect (ch2 < 0x40, 0)                                  \
-           || (__builtin_expect (idx > 0x84be, 0) && idx < 0x889f)      \
-           || (__builtin_expect (idx > 0x88fc, 0) && idx < 0x8940)      \
-           || (__builtin_expect (idx > 0x9ffc, 0) && idx < 0xe040)      \
-           || __builtin_expect (idx > 0xeaa4, 0))                            \
+       if (__glibc_unlikely (ch2 < 0x40))                                    \
          {                                                                   \
            /* 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 (idx > 0x84be && idx < 0x889f, 0))         \
+                || (__builtin_expect (idx > 0x88fc && idx < 0x8940, 0))      \
+                || (__builtin_expect (idx > 0x9ffc && idx < 0xe040, 0))      \
+                || __builtin_expect (idx > 0xeaa4, 0))                       \
+         {                                                                   \
+           /* This is illegal.  */                                           \
+           STANDARD_FROM_LOOP_ERR_HANDLER (2);                               \
          }                                                                   \
        else                                                                  \
          {                                                                   \
@@ -4413,22 +4399,13 @@ static const char from_ucs4_extra[0x100][2] =
            else                                                              \
              ch = cjk_block4[(ch - 0xe0) * 192 + ch2 - 0x40];                \
                                                                              \
-           inptr += 2;                                                       \
-         }                                                                   \
-                                                                             \
-       if (__builtin_expect (ch, 1) == 0)                                    \
-         {                                                                   \
-           /* This is an illegal character.  */                              \
-           if (! ignore_errors_p ())                                         \
+           if (__glibc_unlikely (ch == 0))                                   \
              {                                                               \
-               /* This is an illegal character.  */                          \
-               result = __GCONV_ILLEGAL_INPUT;                               \
-               break;                                                        \
+               /* This is an illegal character.  */                          \
+               STANDARD_FROM_LOOP_ERR_HANDLER (2);                           \
              }                                                               \
                                                                              \
            inptr += 2;                                                       \
-           ++*irreversible;                                                  \
-           continue;                                                         \
          }                                                                   \
       }                                                                              \
                                                                              \
@@ -4436,6 +4413,20 @@ static const char from_ucs4_extra[0x100][2] =
     outptr += 4;                                                             \
   }
 #define LOOP_NEED_FLAGS
+#define ONEBYTE_BODY \
+  {                                                                          \
+    if (c < 0x80)                                                            \
+      {                                                                              \
+       if (c == 0x5c)                                                        \
+         return 0xa5;                                                        \
+       if (c == 0x7e)                                                        \
+         return 0x203e;                                                      \
+       return c;                                                             \
+      }                                                                              \
+    if (c >= 0xa1 && c <= 0xdf)                                                      \
+      return 0xfec0 + c;                                                     \
+    return WEOF;                                                             \
+  }
 #include <iconv/loop.c>
 
 
@@ -4468,10 +4459,10 @@ static const char from_ucs4_extra[0x100][2] =
     else                                                                     \
       cp = from_ucs4_lat1[ch];                                               \
                                                                              \
-    if (__builtin_expect (cp[0], '\1') == '\0' && ch != 0)                   \
+    if (__builtin_expect (cp[0] == '\0', 0) && ch != 0)                              \
       {                                                                              \
        /* Illegal character.  */                                             \
-       STANDARD_ERR_HANDLER (4);                                             \
+       STANDARD_TO_LOOP_ERR_HANDLER (4);                                     \
       }                                                                              \
     else                                                                     \
       {                                                                              \
@@ -4479,7 +4470,7 @@ static const char from_ucs4_extra[0x100][2] =
        /* Now test for a possible second byte and write this if possible.  */\
        if (cp[1] != '\0')                                                    \
          {                                                                   \
-           if (__builtin_expect (outptr + 1 >= outend, 0))                   \
+           if (__glibc_unlikely (outptr + 1 >= outend))                      \
              {                                                               \
                /* The result does not fit into the buffer.  */               \
                result = __GCONV_FULL_OUTPUT;                                 \