* stdlib/quick_exit.c (quick_exit): Pass &__quick_exit_funcs
[glibc.git] / iconvdata / jis0212.h
blob1f61c258a747e4ae558f592df90f556be2ededc4
1 /* Access functions for JISX0212 conversion.
2 Copyright (C) 1997, 1998, 1999, 2003, 2007 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _JIS0212_H
22 #define _JIS0212_H 1
24 #include <assert.h>
25 #include <gconv.h>
26 #include <stdint.h>
29 /* Struct for table with indeces in mapping table. */
30 struct jisx0212_idx
32 uint16_t start;
33 uint16_t end;
34 uint16_t idx;
37 /* Conversion table. */
38 extern const struct jisx0212_idx __jisx0212_to_ucs_idx[];
39 extern const uint16_t __jisx0212_to_ucs[];
41 extern const struct jisx0212_idx __jisx0212_from_ucs_idx[];
42 extern const char __jisx0212_from_ucs[][2];
45 static inline uint32_t
46 __attribute ((always_inline))
47 jisx0212_to_ucs4 (const unsigned char **s, size_t avail, unsigned char offset)
49 const struct jisx0212_idx *rp = __jisx0212_to_ucs_idx;
50 unsigned char ch = *(*s);
51 unsigned char ch2;
52 uint32_t wch = 0;
53 int idx;
55 if (ch < offset || (ch - offset) < 0x22 || (ch - offset) > 0x6d)
56 return __UNKNOWN_10646_CHAR;
58 if (avail < 2)
59 return 0;
61 ch2 = (*s)[1];
62 if (ch2 < offset || (ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
63 return __UNKNOWN_10646_CHAR;
65 idx = (ch - offset - 0x21) * 94 + (ch2 - offset - 0x21);
67 while (idx > rp->end)
68 ++rp;
69 if (idx >= rp->start)
70 wch = __jisx0212_to_ucs[rp->idx + idx - rp->start];
72 if (wch != L'\0')
73 (*s) += 2;
74 else
75 wch = __UNKNOWN_10646_CHAR;
77 return wch;
81 static inline size_t
82 __attribute ((always_inline))
83 ucs4_to_jisx0212 (uint32_t wch, unsigned char *s, size_t avail)
85 const struct jisx0212_idx *rp = __jisx0212_from_ucs_idx;
86 unsigned int ch = (unsigned int) wch;
87 const char *cp;
89 if (ch >= 0xffff)
90 return __UNKNOWN_10646_CHAR;
91 while (ch > rp->end)
92 ++rp;
93 if (ch >= rp->start)
94 cp = __jisx0212_from_ucs[rp->idx + ch - rp->start];
95 else
96 return __UNKNOWN_10646_CHAR;
98 if (cp[0] == '\0')
99 return __UNKNOWN_10646_CHAR;
101 s[0] = cp[0];
102 assert (cp[1] != '\0');
103 if (avail < 2)
104 return 0;
106 s[1] = cp[1];
107 return 2;
110 #endif /* jis0212.h */