1/* Conversion to and from ISO 11548-1.
2 Copyright (C) 1997-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997,
5 Samuel Thibault <samuel.thibault@ens-lyon.org>, 2005.
6
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
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_11548-1//"
26#define FROM_LOOP from_iso11548_1
27#define TO_LOOP to_iso11548_1
28#define DEFINE_INIT 1
29#define DEFINE_FINI 1
30#define MIN_NEEDED_FROM 1
31#define MIN_NEEDED_TO 4
32#define ONE_DIRECTION 0
33
34#define BRAILLE_UCS_BASE 0x2800
35
36/* First define the conversion function from ISO 11548-1 to UCS4. */
37#define MIN_NEEDED_INPUT MIN_NEEDED_FROM
38#define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
39#define LOOPFCT FROM_LOOP
40#define BODY \
41 *((uint32_t *) outptr) = BRAILLE_UCS_BASE | (*inptr++); \
42 outptr += sizeof (uint32_t);
43#define ONEBYTE_BODY \
44 { \
45 return BRAILLE_UCS_BASE | c; \
46 }
47#include <iconv/loop.c>
48
49
50/* Next, define the other direction. */
51#define MIN_NEEDED_INPUT MIN_NEEDED_TO
52#define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
53#define LOOPFCT TO_LOOP
54#define BODY \
55 { \
56 uint32_t ch = *((const uint32_t *) inptr); \
57 if (__glibc_unlikely ((ch & 0xffffff00u) != BRAILLE_UCS_BASE)) \
58 { \
59 UNICODE_TAG_HANDLER (ch, 4); \
60 \
61 /* We have an illegal character. */ \
62 STANDARD_TO_LOOP_ERR_HANDLER (4); \
63 } \
64 else \
65 *outptr++ = (unsigned char) (ch & 0xff); \
66 inptr += 4; \
67 }
68#define LOOP_NEED_FLAGS
69#include <iconv/loop.c>
70
71
72/* Now define the toplevel functions. */
73#include <iconv/skeleton.c>
74