]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - iconvdata/iso-2022-jp-3.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / iconvdata / iso-2022-jp-3.c
index 2704a17b7fe702c6757106de8d055843df90350d..7b85e609d4d35aca03f013d82eb7414cb3766d58 100644 (file)
@@ -1,5 +1,5 @@
 /* Conversion module for ISO-2022-JP-3.
-   Copyright (C) 1998-1999, 2000-2002 Free Software Foundation, Inc.
+   Copyright (C) 1998-2015 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998,
    and Bruno Haible <bruno@clisp.org>, 2002.
@@ -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 <assert.h>
 #include <dlfcn.h>
@@ -38,6 +37,7 @@
 #define TO_LOOP                        to_iso2022jp3_loop
 #define DEFINE_INIT            1
 #define DEFINE_FINI            1
+#define ONE_DIRECTION          0
 #define FROM_LOOP_MIN_NEEDED_FROM      1
 #define FROM_LOOP_MAX_NEEDED_FROM      4
 #define FROM_LOOP_MIN_NEEDED_TO                4
@@ -61,8 +61,9 @@ enum
   JISX0208_1983_set = 2 << 3,  /* Esc $ B */
   JISX0201_Roman_set = 3 << 3, /* Esc ( J */
   JISX0201_Kana_set = 4 << 3,  /* Esc ( I */
-  JISX0213_1_set = 5 << 3,     /* Esc $ ( O */
+  JISX0213_1_2000_set = 5 << 3,        /* Esc $ ( O */
   JISX0213_2_set = 6 << 3,     /* Esc $ ( P */
+  JISX0213_1_2004_set = 7 << 3,        /* Esc $ ( Q */
   CURRENT_SEL_MASK = 7 << 3
 };
 
@@ -96,7 +97,7 @@ enum
            + ((data->__statep->__count & CURRENT_SEL_MASK) != ASCII_set      \
               ? 3 : 0);                                                      \
                                                                              \
-         if (__builtin_expect (outbuf + need > outend, 0))                   \
+         if (__glibc_unlikely (outbuf + need > outend))                      \
            /* We don't have enough room in the output buffer.  */            \
            status = __GCONV_FULL_OUTPUT;                                     \
          else                                                                \
@@ -153,7 +154,7 @@ enum
     uint32_t ch = *inptr;                                                    \
                                                                              \
     /* Recognize escape sequences.  */                                       \
-    if (__builtin_expect (ch == ESC, 0))                                     \
+    if (__glibc_unlikely (ch == ESC))                                        \
       {                                                                              \
        /* We now must be prepared to read two to three more bytes.           \
           If we have a match in the first byte but then the input buffer     \
@@ -211,10 +212,12 @@ enum
              }                                                               \
            else if (inptr[2] == '(')                                         \
              {                                                               \
-               if (inptr[3] == 'O')                                          \
+               if (inptr[3] == 'O' || inptr[3] == 'Q')                       \
                  {                                                           \
                    /* JIS X 0213 plane 1 selected.  */                       \
-                   set = JISX0213_1_set;                                     \
+                   /* In this direction we don't need to distinguish the     \
+                      versions from 2000 and 2004. */                        \
+                   set = JISX0213_1_2004_set;                                \
                    inptr += 4;                                               \
                    continue;                                                 \
                  }                                                           \
@@ -240,7 +243,7 @@ enum
       {                                                                              \
        /* Use the JIS X 0201 table.  */                                      \
        ch = jisx0201_to_ucs4 (ch);                                           \
-       if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0))                 \
+       if (__glibc_unlikely (ch == __UNKNOWN_10646_CHAR))                    \
          {                                                                   \
            STANDARD_FROM_LOOP_ERR_HANDLER (1);                               \
          }                                                                   \
@@ -250,7 +253,7 @@ enum
       {                                                                              \
        /* Use the JIS X 0201 table.  */                                      \
        ch = jisx0201_to_ucs4 (ch + 0x80);                                    \
-       if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0))                 \
+       if (__glibc_unlikely (ch == __UNKNOWN_10646_CHAR))                    \
          {                                                                   \
            STANDARD_FROM_LOOP_ERR_HANDLER (1);                               \
          }                                                                   \
@@ -264,26 +267,27 @@ enum
           provide the appropriate tables.  */                                \
        ch = jisx0208_to_ucs4 (&inptr, inend - inptr, 0);                     \
                                                                              \
-       if (__builtin_expect (ch == 0, 0))                                    \
+       if (__glibc_unlikely (ch == 0))                                       \
          {                                                                   \
            result = __GCONV_INCOMPLETE_INPUT;                                \
            break;                                                            \
          }                                                                   \
-       else if (__builtin_expect (ch == __UNKNOWN_10646_CHAR, 0))            \
+       else if (__glibc_unlikely (ch == __UNKNOWN_10646_CHAR))               \
          {                                                                   \
            STANDARD_FROM_LOOP_ERR_HANDLER (1);                               \
          }                                                                   \
       }                                                                              \
-    else /* (set == JISX0213_1_set || set == JISX0213_2_set) */                      \
+    else /* (set == JISX0213_1_2004_set || set == JISX0213_2_set) */         \
       {                                                                              \
-       if (__builtin_expect (inptr + 1 >= inend, 0))                         \
+       if (__glibc_unlikely (inptr + 1 >= inend))                            \
          {                                                                   \
            result = __GCONV_INCOMPLETE_INPUT;                                \
            break;                                                            \
          }                                                                   \
                                                                              \
-       ch = jisx0213_to_ucs4 (((set - JISX0213_1_set + (1 << 3)) << 5) + ch, \
-                              inptr[1]);                                     \
+       ch = jisx0213_to_ucs4 (                                               \
+              ((JISX0213_1_2004_set - set + (1 << 3)) << 5) + ch,            \
+              inptr[1]);                                                     \
        if (ch == 0)                                                          \
          STANDARD_FROM_LOOP_ERR_HANDLER (1);                                 \
                                                                              \
@@ -408,9 +412,12 @@ static const struct
            /* We know the combined character is in JISX0213 plane 1,         \
               but the buffered character may have been in JISX0208 or in     \
               JISX0213 plane 1.  */                                          \
-           size_t need = (lasttwo >> 16 || set != JISX0213_1_set ? 4 : 0);   \
+           size_t need =                                                     \
+             (lasttwo >> 16                                                  \
+              || (set != JISX0213_1_2000_set && set != JISX0213_1_2004_set)  \
+              ? 4 : 0);                                                      \
                                                                              \
-           if (__builtin_expect (outptr + need + 2 > outend, 0))             \
+           if (__glibc_unlikely (outptr + need + 2 > outend))                \
              {                                                               \
                result = __GCONV_FULL_OUTPUT;                                 \
                break;                                                        \
@@ -422,7 +429,7 @@ static const struct
                *outptr++ = '$';                                              \
                *outptr++ = '(';                                              \
                *outptr++ = 'O';                                              \
-               set = JISX0213_1_set;                                         \
+               set = JISX0213_1_2000_set;                                    \
              }                                                               \
            lasttwo = comp_table_data[idx].composed;                          \
            *outptr++ = (lasttwo >> 8) & 0xff;                                \
@@ -438,7 +445,7 @@ static const struct
        {                                                                     \
          size_t need = (lasttwo >> 16 ? 3 : 0);                              \
                                                                              \
-         if (__builtin_expect (outptr + need + 2 > outend, 0))               \
+         if (__glibc_unlikely (outptr + need + 2 > outend))                  \
            {                                                                 \
              result = __GCONV_FULL_OUTPUT;                                   \
              break;                                                          \
@@ -514,7 +521,7 @@ static const struct
                inptr += 4;                                                   \
                continue;                                                     \
              }                                                               \
-           if (__builtin_expect (written == 0, 0))                           \
+           if (__glibc_unlikely (written == 0))                              \
              {                                                               \
                result = __GCONV_FULL_OUTPUT;                                 \
                break;                                                        \
@@ -529,11 +536,16 @@ static const struct
       }                                                                              \
     else                                                                     \
       {                                                                              \
-       /* (set == JISX0213_1_set || set == JISX0213_2_set) */                \
+       /* (set == JISX0213_1_2000_set || set == JISX0213_1_2004_set          \
+           || set == JISX0213_2_set) */                                      \
        uint32_t jch = ucs4_to_jisx0213 (ch);                                 \
                                                                              \
        if (jch != 0                                                          \
-           && (set == (jch & 0x8000 ? JISX0213_2_set : JISX0213_1_set)))     \
+           && (jch & 0x8000                                                  \
+               ? set == JISX0213_2_set                                       \
+               : (set == JISX0213_1_2004_set                                 \
+                  || (set == JISX0213_1_2000_set                             \
+                      && !jisx0213_added_in_2004_p (jch)))))                 \
          {                                                                   \
            if (jch & 0x0080)                                                 \
              {                                                               \
@@ -547,7 +559,7 @@ static const struct
                continue;                                                     \
              }                                                               \
                                                                              \
-           if (__builtin_expect (outptr + 1 >= outend, 0))                   \
+           if (__glibc_unlikely (outptr + 1 >= outend))                      \
              {                                                               \
                result = __GCONV_FULL_OUTPUT;                                 \
                break;                                                        \
@@ -567,7 +579,7 @@ static const struct
       {                                                                              \
        /* We must encode using ASCII.  First write out the escape            \
           sequence.  */                                                      \
-       if (__builtin_expect (outptr + 3 > outend, 0))                        \
+       if (__glibc_unlikely (outptr + 3 > outend))                           \
          {                                                                   \
            result = __GCONV_FULL_OUTPUT;                                     \
            break;                                                            \
@@ -578,7 +590,7 @@ static const struct
        *outptr++ = 'B';                                                      \
        set = ASCII_set;                                                      \
                                                                              \
-       if (__builtin_expect (outptr >= outend, 0))                           \
+       if (__glibc_unlikely (outptr >= outend))                              \
          {                                                                   \
            result = __GCONV_FULL_OUTPUT;                                     \
            break;                                                            \
@@ -595,7 +607,7 @@ static const struct
          {                                                                   \
            if (set != JISX0201_Roman_set)                                    \
              {                                                               \
-               if (__builtin_expect (outptr + 3 > outend, 0))                \
+               if (__glibc_unlikely (outptr + 3 > outend))                   \
                  {                                                           \
                    result = __GCONV_FULL_OUTPUT;                             \
                    break;                                                    \
@@ -606,7 +618,7 @@ static const struct
                set = JISX0201_Roman_set;                                     \
              }                                                               \
                                                                              \
-           if (__builtin_expect (outptr >= outend, 0))                       \
+           if (__glibc_unlikely (outptr >= outend))                          \
              {                                                               \
                result = __GCONV_FULL_OUTPUT;                                 \
                break;                                                        \
@@ -633,7 +645,7 @@ static const struct
                                                                              \
                if (set != JISX0208_1983_set)                                 \
                  {                                                           \
-                   if (__builtin_expect (outptr + 3 > outend, 0))            \
+                   if (__glibc_unlikely (outptr + 3 > outend))               \
                      {                                                       \
                        result = __GCONV_FULL_OUTPUT;                         \
                        break;                                                \
@@ -644,7 +656,7 @@ static const struct
                    set = JISX0208_1983_set;                                  \
                  }                                                           \
                                                                              \
-               if (__builtin_expect (outptr + 2 > outend, 0))                \
+               if (__glibc_unlikely (outptr + 2 > outend))                   \
                  {                                                           \
                    result = __GCONV_FULL_OUTPUT;                             \
                    break;                                                    \
@@ -658,11 +670,15 @@ static const struct
                if (jch != 0)                                                 \
                  {                                                           \
                    int new_set =                                             \
-                     (jch & 0x8000 ? JISX0213_2_set : JISX0213_1_set);       \
+                     (jch & 0x8000                                           \
+                      ? JISX0213_2_set                                       \
+                      : jisx0213_added_in_2004_p (jch)                       \
+                        ? JISX0213_1_2004_set                                \
+                        : JISX0213_1_2000_set);                              \
                                                                              \
                    if (set != new_set)                                       \
                      {                                                       \
-                       if (__builtin_expect (outptr + 4 > outend, 0))        \
+                       if (__glibc_unlikely (outptr + 4 > outend))           \
                          {                                                   \
                            result = __GCONV_FULL_OUTPUT;                     \
                            break;                                            \
@@ -670,7 +686,8 @@ static const struct
                        *outptr++ = ESC;                                      \
                        *outptr++ = '$';                                      \
                        *outptr++ = '(';                                      \
-                       *outptr++ = ((new_set - JISX0213_1_set) >> 3) + 'O';  \
+                       *outptr++ =                                           \
+                         ((new_set - JISX0213_1_2000_set) >> 3) + 'O';       \
                        set = new_set;                                        \
                      }                                                       \
                                                                              \
@@ -687,7 +704,7 @@ static const struct
                        continue;                                             \
                      }                                                       \
                                                                              \
-                   if (__builtin_expect (outptr + 1 >= outend, 0))           \
+                   if (__glibc_unlikely (outptr + 1 >= outend))              \
                      {                                                       \
                        result = __GCONV_FULL_OUTPUT;                         \
                        break;                                                \
@@ -716,7 +733,7 @@ static const struct
                            set = JISX0201_Kana_set;                          \
                          }                                                   \
                                                                              \
-                       if (__builtin_expect (outptr >= outend, 0))           \
+                       if (__glibc_unlikely (outptr >= outend))              \
                          {                                                   \
                            result = __GCONV_FULL_OUTPUT;                     \
                            break;                                            \
@@ -742,6 +759,12 @@ static const struct
 #define EXTRA_LOOP_DECLS       , int *statep
 #define INIT_PARAMS            int set = *statep & CURRENT_SEL_MASK;         \
                                uint32_t lasttwo = *statep >> 6
+#define REINIT_PARAMS          do                                            \
+                                 {                                           \
+                                   set = *statep & CURRENT_SEL_MASK;         \
+                                   lasttwo = *statep >> 6;                   \
+                                 }                                           \
+                               while (0)
 #define UPDATE_PARAMS          *statep = set | (lasttwo << 6)
 #include <iconv/loop.c>