Define macro DO_ELF_MACHINE_REL_RELATIVE for 'elf_machine_rel_relative'. (elf_dynamic...
[glibc.git] / iconvdata / jis0208.h
blobef6b891eb67f9e68009aff43091c16c1e7d8c341
1 /* Access functions for JISX0208 conversion.
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.
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 _JIS0208_H
22 #define _JIS0208_H 1
24 #include <gconv.h>
25 #include <stdint.h>
27 /* Conversion table. */
28 extern const uint16_t __jis0208_to_ucs[];
30 extern const char __jisx0208_from_ucs4_lat1[256][2];
31 extern const char __jisx0208_from_ucs4_greek[0xc1][2];
32 extern const struct jisx0208_ucs_idx __jisx0208_from_ucs_idx[];
33 extern const char __jisx0208_from_ucs_tab[][2];
36 /* Struct for table with indeces in UCS mapping table. */
37 struct jisx0208_ucs_idx
39 uint16_t start;
40 uint16_t end;
41 uint16_t idx;
45 static inline uint32_t
46 jisx0208_to_ucs4 (const unsigned char **s, size_t avail, unsigned char offset)
48 unsigned char ch = *(*s);
49 unsigned char ch2;
50 int idx;
52 if (ch < offset || (ch - offset) <= 0x20)
53 return __UNKNOWN_10646_CHAR;
55 if (avail < 2)
56 return 0;
58 ch2 = (*s)[1];
59 if (ch2 < offset || (ch2 - offset) <= 0x20 || (ch2 - offset) >= 0x7f)
60 return __UNKNOWN_10646_CHAR;
62 idx = (ch - 0x21 - offset) * 94 + (ch2 - 0x21 - offset);
63 if (idx >= 0x1e80)
64 return __UNKNOWN_10646_CHAR;
66 (*s) += 2;
68 return __jis0208_to_ucs[idx] ?: ((*s) -= 2, __UNKNOWN_10646_CHAR);
72 static inline size_t
73 ucs4_to_jisx0208 (uint32_t wch, char *s, size_t avail)
75 unsigned int ch = (unsigned int) wch;
76 const char *cp;
78 if (avail < 2)
79 return 0;
81 if (ch < 0x100)
82 cp = __jisx0208_from_ucs4_lat1[ch];
83 else if (ch >= 0x391 && ch <= 0x451)
84 cp = __jisx0208_from_ucs4_greek[ch - 0x391];
85 else
87 const struct jisx0208_ucs_idx *rp = __jisx0208_from_ucs_idx;
89 if (ch >= 0xffff)
90 return __UNKNOWN_10646_CHAR;
91 while (ch > rp->end)
92 ++rp;
93 if (ch >= rp->start)
94 cp = __jisx0208_from_ucs_tab[rp->idx + ch - rp->start];
95 else
96 return __UNKNOWN_10646_CHAR;
99 if (cp[0] == '\0')
100 return __UNKNOWN_10646_CHAR;
102 s[0] = cp[0];
103 s[1] = cp[1];
105 return 2;
108 #endif /* jis0208.h */