Back to index

glibc  2.9
8bit-generic.c
Go to the documentation of this file.
00001 /* Generic conversion to and from 8bit charsets.
00002    Copyright (C) 1997-1999, 2000-2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <dlfcn.h>
00022 
00023 #define FROM_LOOP           from_generic
00024 #define TO_LOOP                    to_generic
00025 #define DEFINE_INIT         1
00026 #define DEFINE_FINI         1
00027 #define MIN_NEEDED_FROM            1
00028 #define MIN_NEEDED_TO              4
00029 
00030 
00031 /* First define the conversion function from the 8bit charset to UCS4.  */
00032 #define MIN_NEEDED_INPUT    MIN_NEEDED_FROM
00033 #define MIN_NEEDED_OUTPUT   MIN_NEEDED_TO
00034 #define LOOPFCT                    FROM_LOOP
00035 #define BODY \
00036   {                                                                  \
00037     uint32_t ch = to_ucs4[*inptr];                                   \
00038                                                                      \
00039     if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && *inptr != '\0')     \
00040       {                                                                     \
00041        /* This is an illegal character.  */                                 \
00042        STANDARD_FROM_LOOP_ERR_HANDLER (1);                                  \
00043       }                                                                     \
00044                                                                      \
00045     put32 (outptr, ch);                                                     \
00046     outptr += 4;                                                     \
00047     ++inptr;                                                         \
00048   }
00049 #define LOOP_NEED_FLAGS
00050 #define ONEBYTE_BODY \
00051   {                                                                  \
00052     uint32_t ch = to_ucs4[c];                                               \
00053                                                                      \
00054     if (HAS_HOLES && __builtin_expect (ch == L'\0', 0) && c != '\0')        \
00055       return WEOF;                                                   \
00056     else                                                             \
00057       return ch;                                                     \
00058   }
00059 #include <iconv/loop.c>
00060 
00061 
00062 /* Next, define the other direction.  */
00063 #define MIN_NEEDED_INPUT    MIN_NEEDED_TO
00064 #define MIN_NEEDED_OUTPUT   MIN_NEEDED_FROM
00065 #define LOOPFCT                    TO_LOOP
00066 #define BODY \
00067   {                                                                  \
00068     uint32_t ch = get32 (inptr);                                     \
00069                                                                      \
00070     if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), 0)\
00071        || (__builtin_expect (from_ucs4[ch], '\1') == '\0' && ch != 0))             \
00072       {                                                                     \
00073        UNICODE_TAG_HANDLER (ch, 4);                                         \
00074                                                                      \
00075        /* This is an illegal character.  */                                 \
00076        STANDARD_TO_LOOP_ERR_HANDLER (4);                             \
00077       }                                                                     \
00078                                                                      \
00079     *outptr++ = from_ucs4[ch];                                              \
00080     inptr += 4;                                                             \
00081   }
00082 #define LOOP_NEED_FLAGS
00083 #include <iconv/loop.c>
00084 
00085 
00086 /* Now define the toplevel functions.  */
00087 #include <iconv/skeleton.c>