]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - iconvdata/cp1255.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / iconvdata / cp1255.c
index f8a769539959fb194718a4f7daec8664211e6257..5de7337c947175d595af32a32229f85b2ef64a09 100644 (file)
@@ -1,5 +1,5 @@
 /* Conversion from and to CP1255.
-   Copyright (C) 1998, 2001 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 <haible@clisp.cons.org>, 2001.
@@ -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>
 #define TO_LOOP                        to_cp1255
 #define DEFINE_INIT            1
 #define DEFINE_FINI            1
-#define MIN_NEEDED_FROM                1
-#define MAX_NEEDED_FROM                1
-#define MIN_NEEDED_TO          4
-#define MAX_NEEDED_TO          4
+#define ONE_DIRECTION          0
+#define FROM_LOOP_MIN_NEEDED_FROM      1
+#define FROM_LOOP_MAX_NEEDED_FROM      1
+#define FROM_LOOP_MIN_NEEDED_TO                4
+#define FROM_LOOP_MAX_NEEDED_TO                4
+#define TO_LOOP_MIN_NEEDED_FROM                4
+#define TO_LOOP_MAX_NEEDED_FROM                4
+#define TO_LOOP_MIN_NEEDED_TO          1
+#define TO_LOOP_MAX_NEEDED_TO          3
 #define PREPARE_LOOP \
   int saved_state;                                                           \
   int *statep = &data->__statep->__count;
     {                                                                        \
       if (FROM_DIRECTION)                                                    \
        {                                                                     \
-         if (__builtin_expect (outbuf + 4 <= outend, 1))                     \
+         if (__glibc_likely (outbuf + 4 <= outend))                          \
            {                                                                 \
              /* Write out the last character.  */                            \
-             *((uint32_t *) outbuf)++ = data->__statep->__count >> 3;        \
+             *((uint32_t *) outbuf) = data->__statep->__count >> 3;          \
+             outbuf += sizeof (uint32_t);                                    \
              data->__statep->__count = 0;                                    \
            }                                                                 \
          else                                                                \
@@ -183,9 +188,10 @@ static const struct { unsigned int idx; unsigned int len; } comp_table[8] = {
   { COMP_TABLE_IDX_05C2, COMP_TABLE_LEN_05C2 },
 };
 
-#define MIN_NEEDED_INPUT       MIN_NEEDED_FROM
-#define MIN_NEEDED_OUTPUT      MIN_NEEDED_TO
-#define MAX_NEEDED_OUTPUT      8
+#define MIN_NEEDED_INPUT       FROM_LOOP_MIN_NEEDED_FROM
+#define MAX_NEEDED_INPUT       FROM_LOOP_MAX_NEEDED_FROM
+#define MIN_NEEDED_OUTPUT      FROM_LOOP_MIN_NEEDED_TO
+#define MAX_NEEDED_OUTPUT      FROM_LOOP_MAX_NEEDED_TO
 #define LOOPFCT                        FROM_LOOP
 #define BODY \
   {                                                                          \
@@ -196,18 +202,10 @@ static const struct { unsigned int idx; unsigned int len; } comp_table[8] = {
     if (ch >= 0x80)                                                          \
       {                                                                              \
        ch = to_ucs4[ch - 0x80];                                              \
-       if (__builtin_expect (ch == L'\0', 0))                                \
+       if (__glibc_unlikely (ch == L'\0'))                                   \
          {                                                                   \
            /* This is an illegal character.  */                              \
-           if (! ignore_errors_p ())                                         \
-             {                                                               \
-               result = __GCONV_ILLEGAL_INPUT;                               \
-               break;                                                        \
-             }                                                               \
-                                                                             \
-           ++inptr;                                                          \
-           ++*irreversible;                                                  \
-           continue;                                                         \
+           STANDARD_FROM_LOOP_ERR_HANDLER (1);                               \
          }                                                                   \
       }                                                                              \
                                                                              \
@@ -324,6 +322,15 @@ static const struct { unsigned int idx; unsigned int len; } comp_table[8] = {
   }
 #define LOOP_NEED_FLAGS
 #define EXTRA_LOOP_DECLS       , int *statep
+#define ONEBYTE_BODY \
+  {                                                                          \
+    if (c < 0x80)                                                            \
+      return c;                                                                      \
+    uint32_t ch = to_ucs4[c - 0x80];                                         \
+    if (ch == L'\0' || (ch >= 0x05d0 && ch <= 0x05f2))                       \
+      return WEOF;                                                           \
+    return ch;                                                               \
+  }
 #include <iconv/loop.c>
 
 
@@ -417,9 +424,10 @@ static const struct {
   { 0xFB4E, 0x05E4, 5, -1 },
 };
 
-#define MIN_NEEDED_INPUT       MIN_NEEDED_TO
-#define MIN_NEEDED_OUTPUT      MIN_NEEDED_FROM
-#define MAX_NEEDED_OUTPUT      3
+#define MIN_NEEDED_INPUT       TO_LOOP_MIN_NEEDED_FROM
+#define MAX_NEEDED_INPUT       TO_LOOP_MAX_NEEDED_FROM
+#define MIN_NEEDED_OUTPUT      TO_LOOP_MIN_NEEDED_TO
+#define MAX_NEEDED_OUTPUT      TO_LOOP_MAX_NEEDED_TO
 #define LOOPFCT                        TO_LOOP
 #define BODY \
   {                                                                          \
@@ -456,7 +464,7 @@ static const struct {
            res = 0;                                                          \
          }                                                                   \
                                                                              \
-       if (__builtin_expect (res != 0, 1))                                   \
+       if (__glibc_likely (res != 0))                                        \
          {                                                                   \
            *outptr++ = res;                                                  \
            inptr += 4;                                                       \
@@ -508,7 +516,7 @@ static const struct {
                if (decomp_table[i].comb2 < 0)                                \
                  {                                                           \
                    /* See whether we have room for two bytes.  */            \
-                   if (__builtin_expect (outptr + 1 >= outend, 0))           \
+                   if (__glibc_unlikely (outptr + 1 >= outend))              \
                      {                                                       \
                        result = __GCONV_FULL_OUTPUT;                         \
                        break;                                                \
@@ -520,7 +528,7 @@ static const struct {
                else                                                          \
                  {                                                           \
                    /* See whether we have room for three bytes.  */          \
-                   if (__builtin_expect (outptr + 2 >= outend, 0))           \
+                   if (__glibc_unlikely (outptr + 2 >= outend))              \
                      {                                                       \
                        result = __GCONV_FULL_OUTPUT;                         \
                        break;                                                \
@@ -537,7 +545,7 @@ static const struct {
                                                                              \
          failed:                                                             \
            /* This is an illegal character.  */                              \
-           STANDARD_ERR_HANDLER (4);                                         \
+           STANDARD_TO_LOOP_ERR_HANDLER (4);                                 \
          }                                                                   \
       }                                                                              \
   }