summaryrefslogtreecommitdiff
path: root/jni/iconv/lib/cp437.h
blob: a3c8e685bb46f6c00de16b0ba9811c9326a6e677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * Copyright (C) 1999-2001 Free Software Foundation, Inc.
 * This file is part of the GNU LIBICONV Library.
 *
 * The GNU LIBICONV Library is free software; you can redistribute it
 * and/or modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * The GNU LIBICONV Library is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with the GNU LIBICONV Library; see the file COPYING.LIB.
 * If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA.
 */

/*
 * CP437
 */

static const unsigned short cp437_2uni[128] = {
  /* 0x80 */
  0x00c70x00fc0x00e90x00e20x00e40x00e00x00e50x00e7,
  0x00ea0x00eb0x00e80x00ef0x00ee0x00ec0x00c40x00c5,
  /* 0x90 */
  0x00c90x00e60x00c60x00f40x00f60x00f20x00fb0x00f9,
  0x00ff0x00d60x00dc0x00a20x00a30x00a50x20a70x0192,
  /* 0xa0 */
  0x00e10x00ed0x00f30x00fa0x00f10x00d10x00aa0x00ba,
  0x00bf0x23100x00ac0x00bd0x00bc0x00a10x00ab0x00bb,
  /* 0xb0 */
  0x25910x25920x25930x25020x25240x25610x25620x2556,
  0x25550x25630x25510x25570x255d0x255c0x255b0x2510,
  /* 0xc0 */
  0x25140x25340x252c0x251c0x25000x253c0x255e0x255f,
  0x255a0x25540x25690x25660x25600x25500x256c0x2567,
  /* 0xd0 */
  0x25680x25640x25650x25590x25580x25520x25530x256b,
  0x256a0x25180x250c0x25880x25840x258c0x25900x2580,
  /* 0xe0 */
  0x03b10x00df0x03930x03c00x03a30x03c30x00b50x03c4,
  0x03a60x03980x03a90x03b40x221e0x03c60x03b50x2229,
  /* 0xf0 */
  0x22610x00b10x22650x22640x23200x23210x00f70x2248,
  0x00b00x22190x00b70x221a0x207f0x00b20x25a00x00a0,
};

static int
cp437_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
{
  unsigned char c = *s;
  if (c < 0x80)
    *pwc = (ucs4_t) c;
  else
    *pwc = (ucs4_t) cp437_2uni[c-0x80];
  return 1;
}

static const unsigned char cp437_page00[96] = {
  0xff0xad0x9b0x9c0x000x9d0x000x00/* 0xa0-0xa7 */
  0x000x000xa60xae0xaa0x000x000x00/* 0xa8-0xaf */
  0xf80xf10xfd0x000x000xe60x000xfa/* 0xb0-0xb7 */
  0x000x000xa70xaf0xac0xab0x000xa8/* 0xb8-0xbf */
  0x000x000x000x000x8e0x8f0x920x80/* 0xc0-0xc7 */
  0x000x900x000x000x000x000x000x00/* 0xc8-0xcf */
  0x000xa50x000x000x000x000x990x00/* 0xd0-0xd7 */
  0x000x000x000x000x9a0x000x000xe1/* 0xd8-0xdf */
  0x850xa00x830x000x840x860x910x87/* 0xe0-0xe7 */
  0x8a0x820x880x890x8d0xa10x8c0x8b/* 0xe8-0xef */
  0x000xa40x950xa20x930x000x940xf6/* 0xf0-0xf7 */
  0x000x970xa30x960x810x000x000x98/* 0xf8-0xff */
};
static const unsigned char cp437_page03[56] = {
  0x000x000x000xe20x000x000x000x00/* 0x90-0x97 */
  0xe90x000x000x000x000x000x000x00/* 0x98-0x9f */
  0x000x000x000xe40x000x000xe80x00/* 0xa0-0xa7 */
  0x000xea0x000x000x000x000x000x00/* 0xa8-0xaf */
  0x000xe00x000x000xeb0xee0x000x00/* 0xb0-0xb7 */
  0x000x000x000x000x000x000x000x00/* 0xb8-0xbf */
  0xe30x000x000xe50xe70x000xed0x00/* 0xc0-0xc7 */
};
static const unsigned char cp437_page22[80] = {
  0x000xf90xfb0x000x000x000xec0x00/* 0x18-0x1f */
  0x000x000x000x000x000x000x000x00/* 0x20-0x27 */
  0x000xef0x000x000x000x000x000x00/* 0x28-0x2f */
  0x000x000x000x000x000x000x000x00/* 0x30-0x37 */
  0x000x000x000x000x000x000x000x00/* 0x38-0x3f */
  0x000x000x000x000x000x000x000x00/* 0x40-0x47 */
  0xf70x000x000x000x000x000x000x00/* 0x48-0x4f */
  0x000x000x000x000x000x000x000x00/* 0x50-0x57 */
  0x000x000x000x000x000x000x000x00/* 0x58-0x5f */
  0x000xf00x000x000xf30xf20x000x00/* 0x60-0x67 */
};
static const unsigned char cp437_page23[24] = {
  0xa90x000x000x000x000x000x000x00/* 0x10-0x17 */
  0x000x000x000x000x000x000x000x00/* 0x18-0x1f */
  0xf40xf50x000x000x000x000x000x00/* 0x20-0x27 */
};
static const unsigned char cp437_page25[168] = {
  0xc40x000xb30x000x000x000x000x00/* 0x00-0x07 */
  0x000x000x000x000xda0x000x000x00/* 0x08-0x0f */
  0xbf0x000x000x000xc00x000x000x00/* 0x10-0x17 */
  0xd90x000x000x000xc30x000x000x00/* 0x18-0x1f */
  0x000x000x000x000xb40x000x000x00/* 0x20-0x27 */
  0x000x000x000x000xc20x000x000x00/* 0x28-0x2f */
  0x000x000x000x000xc10x000x000x00/* 0x30-0x37 */
  0x000x000x000x000xc50x000x000x00/* 0x38-0x3f */
  0x000x000x000x000x000x000x000x00/* 0x40-0x47 */
  0x000x000x000x000x000x000x000x00/* 0x48-0x4f */
  0xcd0xba0xd50xd60xc90xb80xb70xbb/* 0x50-0x57 */
  0xd40xd30xc80xbe0xbd0xbc0xc60xc7/* 0x58-0x5f */
  0xcc0xb50xb60xb90xd10xd20xcb0xcf/* 0x60-0x67 */
  0xd00xca0xd80xd70xce0x000x000x00/* 0x68-0x6f */
  0x000x000x000x000x000x000x000x00/* 0x70-0x77 */
  0x000x000x000x000x000x000x000x00/* 0x78-0x7f */
  0xdf0x000x000x000xdc0x000x000x00/* 0x80-0x87 */
  0xdb0x000x000x000xdd0x000x000x00/* 0x88-0x8f */
  0xde0xb00xb10xb20x000x000x000x00/* 0x90-0x97 */
  0x000x000x000x000x000x000x000x00/* 0x98-0x9f */
  0xfe0x000x000x000x000x000x000x00/* 0xa0-0xa7 */
};

static int
cp437_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
{
  unsigned char c = 0;
  if (wc < 0x0080) {
    *r = wc;
    return 1;
  }
  else if (wc >= 0x00a0 && wc < 0x0100)
    c = cp437_page00[wc-0x00a0];
  else if (wc == 0x0192)
    c = 0x9f;
  else if (wc >= 0x0390 && wc < 0x03c8)
    c = cp437_page03[wc-0x0390];
  else if (wc == 0x207f)
    c = 0xfc;
  else if (wc == 0x20a7)
    c = 0x9e;
  else if (wc >= 0x2218 && wc < 0x2268)
    c = cp437_page22[wc-0x2218];
  else if (wc >= 0x2310 && wc < 0x2328)
    c = cp437_page23[wc-0x2310];
  else if (wc >= 0x2500 && wc < 0x25a8)
    c = cp437_page25[wc-0x2500];
  if (c != 0) {
    *r = c;
    return 1;
  }
  return RET_ILUNI;
}