Update.
[platform/upstream/glibc.git] / iconvdata / iso8859-1.c
1 /* Conversion to and from ISO 8859-1.
2    Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Library General Public License as
8    published by the Free Software Foundation; either version 2 of the
9    License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Library General Public License for more details.
15
16    You should have received a copy of the GNU Library General Public
17    License along with the GNU C Library; see the file COPYING.LIB.  If not,
18    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.  */
20
21 #include <dlfcn.h>
22 #include <stdint.h>
23
24 /* Definitions used in the body of the `gconv' function.  */
25 #define CHARSET_NAME            "ISO-8859-1//"
26 #define FROM_LOOP               from_iso8859_1
27 #define TO_LOOP                 to_iso8859_1
28 #define DEFINE_INIT             1
29 #define DEFINE_FINI             1
30 #define MIN_NEEDED_FROM         1
31 #define MIN_NEEDED_TO           4
32
33 /* First define the conversion function from ISO 8859-1 to UCS4.  */
34 #define MIN_NEEDED_INPUT        MIN_NEEDED_FROM
35 #define MIN_NEEDED_OUTPUT       MIN_NEEDED_TO
36 #define LOOPFCT                 FROM_LOOP
37 #define BODY \
38   *((uint32_t *) outptr)++ = *inptr++;
39 #include <iconv/loop.c>
40
41
42 /* Next, define the other direction.  */
43 #define MIN_NEEDED_INPUT        MIN_NEEDED_TO
44 #define MIN_NEEDED_OUTPUT       MIN_NEEDED_FROM
45 #define LOOPFCT                 TO_LOOP
46 #define BODY \
47   {                                                                           \
48     uint32_t ch = *((uint32_t *) inptr);                                      \
49     if (__builtin_expect (ch, 0) > 0xff)                                      \
50       {                                                                       \
51         /* We have an illegal character.  */                                  \
52         if (step_data->__trans.__trans_fct != NULL)                           \
53           {                                                                   \
54             result = DL_CALL_FCT (step_data->__trans.__trans_fct,             \
55                                   (step, step_data, *inptrp, &inptr, inend,   \
56                                    *outptrp, &outptr, outend, irreversible)); \
57             if (result != __GCONV_OK)                                         \
58               break;                                                          \
59           }                                                                   \
60         else if (! ignore_errors_p ())                                        \
61           {                                                                   \
62             result = __GCONV_ILLEGAL_INPUT;                                   \
63             break;                                                            \
64           }                                                                   \
65         else                                                                  \
66           {                                                                   \
67             inptr += 4;                                                       \
68             ++*irreversible;                                                  \
69           }                                                                   \
70         continue;                                                             \
71       }                                                                       \
72     else                                                                      \
73       *outptr++ = (unsigned char) ch;                                         \
74     inptr += 4;                                                               \
75   }
76 #define LOOP_NEED_FLAGS
77 #include <iconv/loop.c>
78
79
80 /* Now define the toplevel functions.  */
81 #include <iconv/skeleton.c>