summaryrefslogtreecommitdiff
path: root/jni/iconv/lib/cp1046.h
blob: b6716b73db328c7ae06e28659b0aa6caf9ae11f7 (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
157
/*
 * 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.
 */

/*
 * CP1046
 */

static const unsigned short cp1046_2uni[128] = {
  /* 0x80 */
  0xfe880x00d70x00f70xf8f60xf8f50xf8f40xf8f70xfe71,
  0x00880x25a00x25020x25000x25100x250c0x25140x2518,
  /* 0x90 */
  0xfe790xfe7b0xfe7d0xfe7f0xfe770xfe8a0xfef00xfef3,
  0xfef20xfece0xfecf0xfed00xfef60xfef80xfefa0xfefc,
  /* 0xa0 */
  0x00a00xf8fa0xf8f90xf8f80x00a40xf8fb0xfe8b0xfe91,
  0xfe970xfe9b0xfe9f0xfea30x060c0x00ad0xfea70xfeb3,
  /* 0xb0 */
  0x06600x06610x06620x06630x06640x06650x06660x0667,
  0x06680x06690xfeb70x061b0xfebb0xfebf0xfeca0x061f,
  /* 0xc0 */
  0xfecb0x06210x06220x06230x06240x06250x06260x0627,
  0x06280x06290x062a0x062b0x062c0x062d0x062e0x062f,
  /* 0xd0 */
  0x06300x06310x06320x06330x06340x06350x06360x0637,
  0xfec70x06390x063a0xfecc0xfe820xfe840xfe8e0xfed3,
  /* 0xe0 */
  0x06400x06410x06420x06430x06440x06450x06460x0647,
  0x06480x06490x064a0x064b0x064c0x064d0x064e0x064f,
  /* 0xf0 */
  0x06500x06510x06520xfed70xfedb0xfedf0xf8fc0xfef5,
  0xfef70xfef90xfefb0xfee30xfee70xfeec0xfee90xfffd,
};

static int
cp1046_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
{
  unsigned char c = *s;
  if (c < 0x80) {
    *pwc = (ucs4_t) c;
    return 1;
  }
  else {
    unsigned short wc = cp1046_2uni[c-0x80];
    if (wc != 0xfffd) {
      *pwc = (ucs4_t) wc;
      return 1;
    }
  }
  return RET_ILSEQ;
}

static const unsigned char cp1046_page00[112] = {
  0x880x000x000x000x000x000x000x00/* 0x88-0x8f */
  0x000x000x000x000x000x000x000x00/* 0x90-0x97 */
  0x000x000x000x000x000x000x000x00/* 0x98-0x9f */
  0xa00x000x000x000xa40x000x000x00/* 0xa0-0xa7 */
  0x000x000x000x000x000xad0x000x00/* 0xa8-0xaf */
  0x000x000x000x000x000x000x000x00/* 0xb0-0xb7 */
  0x000x000x000x000x000x000x000x00/* 0xb8-0xbf */
  0x000x000x000x000x000x000x000x00/* 0xc0-0xc7 */
  0x000x000x000x000x000x000x000x00/* 0xc8-0xcf */
  0x000x000x000x000x000x000x000x81/* 0xd0-0xd7 */
  0x000x000x000x000x000x000x000x00/* 0xd8-0xdf */
  0x000x000x000x000x000x000x000x00/* 0xe0-0xe7 */
  0x000x000x000x000x000x000x000x00/* 0xe8-0xef */
  0x000x000x000x000x000x000x000x82/* 0xf0-0xf7 */
};
static const unsigned char cp1046_page06[104] = {
  0x000x000x000x000xac0x000x000x00/* 0x08-0x0f */
  0x000x000x000x000x000x000x000x00/* 0x10-0x17 */
  0x000x000x000xbb0x000x000x000xbf/* 0x18-0x1f */
  0x000xc10xc20xc30xc40xc50xc60xc7/* 0x20-0x27 */
  0xc80xc90xca0xcb0xcc0xcd0xce0xcf/* 0x28-0x2f */
  0xd00xd10xd20xd30xd40xd50xd60xd7/* 0x30-0x37 */
  0x000xd90xda0x000x000x000x000x00/* 0x38-0x3f */
  0xe00xe10xe20xe30xe40xe50xe60xe7/* 0x40-0x47 */
  0xe80xe90xea0xeb0xec0xed0xee0xef/* 0x48-0x4f */
  0xf00xf10xf20x000x000x000x000x00/* 0x50-0x57 */
  0x000x000x000x000x000x000x000x00/* 0x58-0x5f */
  0xb00xb10xb20xb30xb40xb50xb60xb7/* 0x60-0x67 */
  0xb80xb90x000x000x000x000x000x00/* 0x68-0x6f */
};
static const unsigned char cp1046_page25[32] = {
  0x8b0x000x8a0x000x000x000x000x00/* 0x00-0x07 */
  0x000x000x000x000x8d0x000x000x00/* 0x08-0x0f */
  0x8c0x000x000x000x8e0x000x000x00/* 0x10-0x17 */
  0x8f0x000x000x000x000x000x000x00/* 0x18-0x1f */
};
static const unsigned char cp1046_pagef8[16] = {
  0x000x000x000x000x850x840x830x86/* 0xf0-0xf7 */
  0xa30xa20xa10xa50xf60x000x000x00/* 0xf8-0xff */
};
static const unsigned char cp1046_pagefe[144] = {
  0x000x870x000x000x000x000x000x94/* 0x70-0x77 */
  0x000x900x000x910x000x920x000x93/* 0x78-0x7f */
  0x000x000xdc0x000xdd0x000x000x00/* 0x80-0x87 */
  0x800x000x950xa60x000x000xde0x00/* 0x88-0x8f */
  0x000xa70x000x000x000x000x000xa8/* 0x90-0x97 */
  0x000x000x000xa90x000x000x000xaa/* 0x98-0x9f */
  0x000x000x000xab0x000x000x000xae/* 0xa0-0xa7 */
  0x000x000x000x000x000x000x000x00/* 0xa8-0xaf */
  0x000x000x000xaf0x000x000x000xba/* 0xb0-0xb7 */
  0x000x000x000xbc0x000x000x000xbd/* 0xb8-0xbf */
  0x000x000x000x000x000x000x000xd8/* 0xc0-0xc7 */
  0x000x000xbe0xc00xdb0x000x990x9a/* 0xc8-0xcf */
  0x9b0x000x000xdf0x000x000x000xf3/* 0xd0-0xd7 */
  0x000x000x000xf40x000x000x000xf5/* 0xd8-0xdf */
  0x000x000x000xfb0x000x000x000xfc/* 0xe0-0xe7 */
  0x000xfe0x000x000xfd0x000x000x00/* 0xe8-0xef */
  0x960x000x980x970x000xf70x9c0xf8/* 0xf0-0xf7 */
  0x9d0xf90x9e0xfa0x9f0x000x000x00/* 0xf8-0xff */
};

static int
cp1046_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 >= 0x0088 && wc < 0x00f8)
    c = cp1046_page00[wc-0x0088];
  else if (wc >= 0x0608 && wc < 0x0670)
    c = cp1046_page06[wc-0x0608];
  else if (wc >= 0x2500 && wc < 0x2520)
    c = cp1046_page25[wc-0x2500];
  else if (wc == 0x25a0)
    c = 0x89;
  else if (wc >= 0xf8f0 && wc < 0xf900)
    c = cp1046_pagef8[wc-0xf8f0];
  else if (wc >= 0xfe70 && wc < 0xff00)
    c = cp1046_pagefe[wc-0xfe70];
  if (c != 0) {
    *r = c;
    return 1;
  }
  return RET_ILUNI;
}