summaryrefslogtreecommitdiff
path: root/jni/iconv/lib/armscii_8.h
blob: 8d1613ff98c15436e6bd02bbf8bd2842006cbf45 (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
/*
 * Copyright (C) 1999-2002 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.
 */

/*
 * ARMSCII-8
 */

static const unsigned short armscii_8_2uni[96] = {
  /* 0xa0 */
  0x00a00xfffd0x05870x05890x00290x00280x00bb0x00ab,
  0x20140x002e0x055d0x002c0x002d0x058a0x20260x055c,
  /* 0xb0 */
  0x055b0x055e0x05310x05610x05320x05620x05330x0563,
  0x05340x05640x05350x05650x05360x05660x05370x0567,
  /* 0xc0 */
  0x05380x05680x05390x05690x053a0x056a0x053b0x056b,
  0x053c0x056c0x053d0x056d0x053e0x056e0x053f0x056f,
  /* 0xd0 */
  0x05400x05700x05410x05710x05420x05720x05430x0573,
  0x05440x05740x05450x05750x05460x05760x05470x0577,
  /* 0xe0 */
  0x05480x05780x05490x05790x054a0x057a0x054b0x057b,
  0x054c0x057c0x054d0x057d0x054e0x057e0x054f0x057f,
  /* 0xf0 */
  0x05500x05800x05510x05810x05520x05820x05530x0583,
  0x05540x05840x05550x05850x05560x05860x055a0xfffd,
};

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

static const unsigned char armscii_8_page00[8] = {
  0xa50xa40x2a0x2b0xab0xac0xa90x2f/* 0x28-0x2f */
};
static const unsigned char armscii_8_page00_1[32] = {
  0xa00x000x000x000x000x000x000x00/* 0xa0-0xa7 */
  0x000x000x000xa70x000x000x000x00/* 0xa8-0xaf */
  0x000x000x000x000x000x000x000x00/* 0xb0-0xb7 */
  0x000x000x000xa60x000x000x000x00/* 0xb8-0xbf */
};
static const unsigned char armscii_8_page05[96] = {
  0x000xb20xb40xb60xb80xba0xbc0xbe/* 0x30-0x37 */
  0xc00xc20xc40xc60xc80xca0xcc0xce/* 0x38-0x3f */
  0xd00xd20xd40xd60xd80xda0xdc0xde/* 0x40-0x47 */
  0xe00xe20xe40xe60xe80xea0xec0xee/* 0x48-0x4f */
  0xf00xf20xf40xf60xf80xfa0xfc0x00/* 0x50-0x57 */
  0x000x000xfe0xb00xaf0xaa0xb10x00/* 0x58-0x5f */
  0x000xb30xb50xb70xb90xbb0xbd0xbf/* 0x60-0x67 */
  0xc10xc30xc50xc70xc90xcb0xcd0xcf/* 0x68-0x6f */
  0xd10xd30xd50xd70xd90xdb0xdd0xdf/* 0x70-0x77 */
  0xe10xe30xe50xe70xe90xeb0xed0xef/* 0x78-0x7f */
  0xf10xf30xf50xf70xf90xfb0xfd0xa2/* 0x80-0x87 */
  0x000xa30xad0x000x000x000x000x00/* 0x88-0x8f */
};
static const unsigned char armscii_8_page20[24] = {
  0x000x000x000x000xa80x000x000x00/* 0x10-0x17 */
  0x000x000x000x000x000x000x000x00/* 0x18-0x1f */
  0x000x000x000x000x000x000xae0x00/* 0x20-0x27 */
};

static int
armscii_8_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
{
  unsigned char c = 0;
  if (wc < 0x0028) {
    *r = wc;
    return 1;
  }
  else if (wc >= 0x0028 && wc < 0x0030)
    c = armscii_8_page00[wc-0x0028];
  else if (wc >= 0x0030 && wc < 0x00a0)
    c = wc;
  else if (wc >= 0x00a0 && wc < 0x00c0)
    c = armscii_8_page00_1[wc-0x00a0];
  else if (wc >= 0x0530 && wc < 0x0590)
    c = armscii_8_page05[wc-0x0530];
  else if (wc >= 0x2010 && wc < 0x2028)
    c = armscii_8_page20[wc-0x2010];
  if (c != 0) {
    *r = c;
    return 1;
  }
  return RET_ILUNI;
}