summaryrefslogtreecommitdiff
path: root/libiconv
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@uclibc-ng.org>2018-05-26 21:47:00 +0200
committerWaldemar Brodkorb <wbrodkorb@conet.de>2018-05-27 08:30:51 +0200
commit5fdd379d9dbf8be74f2f1a0d33e62958e817ae7d (patch)
tree95e07c474181bac55136c2aa51a264335f66e80a /libiconv
parentddbb03e77ac1a48740688814b82f45c97ee81f37 (diff)
libiconv: port over simplified iconv from musl
Diffstat (limited to 'libiconv')
-rw-r--r--libiconv/iconv.c652
-rw-r--r--libiconv/include/charmaps.h80
-rw-r--r--libiconv/include/charmaps/iso-8859-10.h24
-rw-r--r--libiconv/include/charmaps/iso-8859-13.h24
-rw-r--r--libiconv/include/charmaps/iso-8859-14.h25
-rw-r--r--libiconv/include/charmaps/iso-8859-16.h24
-rw-r--r--libiconv/include/charmaps/iso-8859-2.h24
-rw-r--r--libiconv/include/charmaps/iso-8859-3.h24
-rw-r--r--libiconv/include/charmaps/iso-8859-4.h24
-rw-r--r--libiconv/include/charmaps/iso-8859-5.h24
-rw-r--r--libiconv/include/charmaps/iso-8859-6.h24
-rw-r--r--libiconv/include/charmaps/iso-8859-7.h24
-rw-r--r--libiconv/include/charmaps/iso-8859-8.h24
-rw-r--r--libiconv/include/charmaps/iso-8859-9.h24
-rw-r--r--libiconv/include/charmaps/koi8-r.h24
-rw-r--r--libiconv/include/charmaps/windows-1250.h24
-rw-r--r--libiconv/include/charmaps/windows-1251.h24
-rw-r--r--libiconv/include/charmaps/windows-1252.h25
-rw-r--r--libiconv/include/charmaps/windows-1253.h24
-rw-r--r--libiconv/include/charmaps/windows-1254.h24
-rw-r--r--libiconv/include/charmaps/windows-1255.h24
-rw-r--r--libiconv/include/charmaps/windows-1256.h24
-rw-r--r--libiconv/include/charmaps/windows-1257.h24
-rw-r--r--libiconv/include/charmaps/windows-1258.h24
-rw-r--r--libiconv/include/charmaps/windows-874.h24
-rw-r--r--libiconv/include/codepages.h320
-rw-r--r--libiconv/include/legacychars.h40
27 files changed, 811 insertions, 835 deletions
diff --git a/libiconv/iconv.c b/libiconv/iconv.c
index c028f0a51..ec01f381d 100644
--- a/libiconv/iconv.c
+++ b/libiconv/iconv.c
@@ -1,3 +1,32 @@
+/*
+ * Copyright © 2018 Waldemar Brodkorb <wbx@uclibc-ng.org>
+ * Simplified port of iconv.c from musl C library including
+ * parts of libiconv-tiny.
+ */
+
+/* Copyright © 2005-2018 Rich Felker, et al.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+*/
+
#include <iconv.h>
#include <errno.h>
#include <wchar.h>
@@ -5,7 +34,6 @@
#include <strings.h>
#include <stdlib.h>
#include <limits.h>
-
#include <dirent.h>
#include <fcntl.h>
#include <sys/mman.h>
@@ -13,124 +41,177 @@
#include <unistd.h>
#include <stdint.h>
-/* builtin charmaps */
-#include "charmaps.h"
-
-/* only 0-7 are valid as dest charset */
-#define UTF_16BE 000
-#define UTF_16LE 001
-#define UTF_32BE 002
-#define UTF_32LE 003
-#define WCHAR_T 004
-#define UTF_8 005
-#define US_ASCII 006
-#define LATIN_1 007
-
-/* additional charsets with algorithmic conversion */
-#define LATIN_9 010
-#define TIS_620 011
-#define JIS_0201 012
-#define EUC_JP 013
-
-/* some programs like php need this */
-int _libiconv_version = _LIBICONV_VERSION;
-
-/* these must match the constants above */
-static const unsigned char charsets[] =
- "\005" "UTF-8" "\0"
- "\004" "WCHAR_T" "\0"
- "\000" "UTF-16BE" "\0"
- "\001" "UTF-16LE" "\0"
- "\002" "UTF-32BE" "\0"
- "\003" "UTF-32LE" "\0"
- "\006" "ASCII" "\0"
- "\006" "US-ASCII" "\0"
- "\007" "ISO-8859-1" "\0"
- "\007" "LATIN1" "\0"
- "\010" "ISO-8859-15""\0"
- "\010" "LATIN9" "\0"
- "\011" "ISO-8859-11""\0"
- "\011" "TIS-620" "\0"
- "\012" "JIS-0201" "\0"
- "\013" "EUC-JP" "\0"
- "\377";
-
-/* separate identifiers for sbcs/dbcs/etc map type */
-#define UCS2_8BIT 000
-#define UCS3_8BIT 001
-#define EUC_JP 002
-#define EUC_TW 003
-#define SHIFT_JIS 004
-#define BIG5 005
-#define GBK 006
-
-/* FIXME: these are not implemented yet
-// EUC: A1-FE A1-FE
-// GBK: 81-FE 40-7E,80-FE
-// Big5: A1-FE 40-7E,A1-FE
-*/
+#define UTF_32BE 0300
+#define UTF_16LE 0301
+#define UTF_16BE 0302
+#define UTF_32LE 0303
+#define UCS2BE 0304
+#define UCS2LE 0305
+#define WCHAR_T 0306
+#define US_ASCII 0307
+#define UTF_8 0310
+#define UTF_16 0312
+#define UTF_32 0313
+#define UCS2 0314
+#define EUC_JP 0320
+#define SHIFT_JIS 0321
+#define ISO2022_JP 0322
+#define GB18030 0330
+#define GBK 0331
+#define GB2312 0332
+#define BIG5 0340
+#define EUC_KR 0350
+
+/* Definitions of charmaps. Each charmap consists of:
+ * 1. Empty-string-terminated list of null-terminated aliases.
+ * 2. Special type code or number of elided quads of entries.
+ * 3. Character table (size determined by field 2), consisting
+ * of 5 bytes for every 4 characters, interpreted as 10-bit
+ * indices into the legacy_chars table. */
+
+static const unsigned char charmaps[] =
+"utf8\0char\0\0\310"
+"wchart\0\0\306"
+"ucs2be\0\0\304"
+"ucs2le\0\0\305"
+"utf16be\0\0\302"
+"utf16le\0\0\301"
+"ucs4be\0utf32be\0\0\300"
+"ucs4le\0utf32le\0\0\303"
+"ascii\0usascii\0iso646\0iso646us\0\0\307"
+"utf16\0\0\312"
+"ucs4\0utf32\0\0\313"
+"ucs2\0\0\314"
+"eucjp\0\0\320"
+"shiftjis\0sjis\0\0\321"
+"iso2022jp\0\0\322"
+"gb18030\0\0\330"
+"gbk\0\0\331"
+"gb2312\0\0\332"
+"big5\0bigfive\0cp950\0big5hkscs\0\0\340"
+"euckr\0ksc5601\0ksx1001\0cp949\0\0\350"
+#include "codepages.h"
+;
+
+/* Table of characters that appear in legacy 8-bit codepages,
+ * limited to 1024 slots (10 bit indices). The first 256 entries
+ * are elided since those characters are obviously all included. */
+static const unsigned short legacy_chars[] = {
+#include "legacychars.h"
+};
+
+static const unsigned short jis0208[84][94] = {
+#include "jis0208.h"
+};
-static const unsigned short maplen[] = {
- [UCS2_8BIT] = 4+ 2* 128,
- [UCS3_8BIT] = 4+ 3* 128,
- [EUC_JP] = 4+ 2* 94*94,
- [SHIFT_JIS] = 4+ 2* 94*94,
- [BIG5] = 4+ 2* 94*157,
- [GBK] = 4+ 2* 126*190,
- [EUC_TW] = 4+ 2* 2*94*94,
+static const unsigned short rev_jis[] = {
+#include "revjis.h"
};
-static int find_charmap(const char *name)
+static int fuzzycmp(const unsigned char *a, const unsigned char *b)
{
- int i;
- for (i = 0; i < (sizeof(charmaps) / sizeof(charmaps[0])); i++)
- if (!strcasecmp(charmaps[i].name, name))
- return i;
- return -1;
+ for (; *a && *b; a++, b++) {
+ while (*a && (*a|32U)-'a'>26 && *a-'0'>10U) a++;
+ if ((*a|32U) != *b) return 1;
+ }
+ return *a != *b;
}
-static int find_charset(const char *name)
+static size_t find_charmap(const void *name)
{
const unsigned char *s;
- for (s=charsets; *s<0xff && strcasecmp(s+1, name); s+=strlen(s)+1);
- return *s;
+ if (!*(char *)name) name=charmaps; /* "utf8" */
+ for (s=charmaps; *s; ) {
+ if (!fuzzycmp(name, s)) {
+ for (; *s; s+=strlen((void *)s)+1);
+ return s+1-charmaps;
+ }
+ s += strlen((void *)s)+1;
+ if (!*s) {
+ if (s[1] > 0200) s+=2;
+ else s+=2+(64U-s[1])*5;
+ }
+ }
+ return -1;
}
-iconv_t iconv_open(const char *to, const char *from)
+struct stateful_cd {
+ iconv_t base_cd;
+ unsigned state;
+};
+
+static iconv_t combine_to_from(size_t t, size_t f)
{
- unsigned f, t;
- int m;
+ return (void *)(f<<16 | t<<1 | 1);
+}
- if ((t = find_charset(to)) > 8)
- return -1;
+static size_t extract_from(iconv_t cd)
+{
+ return (size_t)cd >> 16;
+}
- if ((f = find_charset(from)) < 255)
- return 0 | (t<<1) | (f<<8);
+static size_t extract_to(iconv_t cd)
+{
+ return (size_t)cd >> 1 & 0x7fff;
+}
- if ((m = find_charmap(from)) > -1)
- return 1 | (t<<1) | (m<<8);
+iconv_t iconv_open(const char *to, const char *from)
+{
+ size_t f, t;
+ struct stateful_cd *scd;
+
+ if ((t = find_charmap(to))==-1
+ || (f = find_charmap(from))==-1
+ || (charmaps[t] >= 0330)) {
+ errno = EINVAL;
+ return (iconv_t)-1;
+ }
+ iconv_t cd = combine_to_from(t, f);
+
+ switch (charmaps[f]) {
+ case UTF_16:
+ case UTF_32:
+ case UCS2:
+ case ISO2022_JP:
+ scd = malloc(sizeof *scd);
+ if (!scd) return (iconv_t)-1;
+ scd->base_cd = cd;
+ scd->state = 0;
+ cd = (iconv_t)scd;
+ }
- return -1;
+ return cd;
}
-int iconv_close(iconv_t cd)
+static unsigned get_16(const unsigned char *s, int e)
{
- return 0;
+ e &= 1;
+ return s[e]<<8 | s[1-e];
}
-static inline wchar_t get_16(const unsigned char *s, int endian)
+static void put_16(unsigned char *s, unsigned c, int e)
{
- endian &= 1;
- return s[endian]<<8 | s[endian^1];
+ e &= 1;
+ s[e] = c>>8;
+ s[1-e] = c;
}
-static inline void put_16(unsigned char *s, wchar_t c, int endian)
+static unsigned get_32(const unsigned char *s, int e)
{
- endian &= 1;
- s[endian] = c>>8;
- s[endian^1] = c;
+ e &= 3;
+ return s[e]+0U<<24 | s[e^1]<<16 | s[e^2]<<8 | s[e^3];
}
+static void put_32(unsigned char *s, unsigned c, int e)
+{
+ e &= 3;
+ s[e^0] = c>>24;
+ s[e^1] = c>>16;
+ s[e^2] = c>>8;
+ s[e^3] = c;
+}
+
+
static inline int utf8enc_wchar(char *outb, wchar_t c)
{
if (c <= 0x7F) {
@@ -246,133 +327,211 @@ static inline int utf8dec_wchar(wchar_t *c, unsigned char *in, size_t inb)
return -1;
}
-static inline char latin9_translit(wchar_t c)
+static unsigned legacy_map(const unsigned char *map, unsigned c)
+{
+ if (c < 4*map[-1]) return c;
+ unsigned x = c - 4*map[-1];
+ x = map[x*5/4]>>2*x%8 | map[x*5/4+1]<<8-2*x%8 & 1023;
+ return x < 256 ? x : legacy_chars[x-256];
+}
+
+static unsigned uni_to_jis(unsigned c)
{
- /* a number of trivial iso-8859-15 <> utf-8 transliterations */
- switch (c) {
- case 0x20AC: return 0xA4; /* Euro */
- case 0x0160: return 0xA6; /* S caron */
- case 0x0161: return 0xA8; /* s caron */
- case 0x017D: return 0xB4; /* Z caron */
- case 0x017E: return 0xB8; /* z caron */
- case 0x0152: return 0xBC; /* OE */
- case 0x0153: return 0xBD; /* oe */
- case 0x0178: return 0xBE; /* Y diaeresis */
- default: return '?';
+ unsigned nel = sizeof rev_jis / sizeof *rev_jis;
+ unsigned d, j, i, b = 0;
+ for (;;) {
+ i = nel/2;
+ j = rev_jis[b+i];
+ d = jis0208[j/256][j%256];
+ if (d==c) return j + 0x2121;
+ else if (nel == 1) return 0;
+ else if (c < d)
+ nel /= 2;
+ else {
+ b += i;
+ nel -= nel/2;
+ }
}
}
-size_t iconv(iconv_t cd, char **in, size_t *inb, char **out, size_t *outb)
+size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restrict out, size_t *restrict outb)
{
size_t x=0;
- unsigned char to = (cd>>1)&127;
- unsigned char from = 255;
- const unsigned char *map = 0;
+ struct stateful_cd *scd=0;
+ if (!((size_t)cd & 1)) {
+ scd = (void *)cd;
+ cd = scd->base_cd;
+ }
+ unsigned to = extract_to(cd);
+ unsigned from = extract_from(cd);
+ const unsigned char *map = charmaps+from+1;
+ const unsigned char *tomap = charmaps+to+1;
char tmp[MB_LEN_MAX];
- wchar_t c, d;
+ unsigned c, d;
size_t k, l;
int err;
+ unsigned char type = map[-1];
+ unsigned char totype = tomap[-1];
if (!in || !*in || !*inb) return 0;
- if (cd & 1)
- map = charmaps[cd>>8].map;
- else
- from = cd>>8;
-
for (; *inb; *in+=l, *inb-=l) {
c = *(unsigned char *)*in;
l = 1;
- if (from >= UTF_8 && c < 0x80) goto charok;
- switch (from) {
- case WCHAR_T:
- l = sizeof(wchar_t);
- if (*inb < l) goto starved;
- c = *(wchar_t *)*in;
- break;
+
+ switch (type) {
case UTF_8:
+ if (c < 128) break;
l = utf8dec_wchar(&c, *in, *inb);
if (!l) l++;
else if (l == (size_t)-1) goto ilseq;
else if (l == (size_t)-2) goto starved;
break;
case US_ASCII:
- goto ilseq;
- case LATIN_9:
- if ((unsigned)c - 0xa4 <= 0xbe - 0xa4) {
- static const unsigned char map[] = {
- 0, 0x60, 0, 0x61, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0x7d, 0, 0, 0, 0x7e, 0, 0, 0,
- 0x52, 0x53, 0x78
- };
- if (c == 0xa4) c = 0x20ac;
- else if (map[c-0xa5]) c = 0x100 | map[c-0xa5];
- }
- case LATIN_1:
- goto charok;
- case TIS_620:
- if (c >= 0xa1) c += 0x0e01-0xa1;
- goto charok;
- case JIS_0201:
- if (c >= 0xa1) {
- if (c <= 0xdf) c += 0xff61-0xa1;
- else goto ilseq;
+ if (c >= 128) goto ilseq;
+ break;
+ case WCHAR_T:
+ l = sizeof(wchar_t);
+ if (*inb < l) goto starved;
+ c = *(wchar_t *)*in;
+ if (0) {
+ case UTF_32BE:
+ case UTF_32LE:
+ l = 4;
+ if (*inb < 4) goto starved;
+ c = get_32((void *)*in, type);
}
- goto charok;
+ if (c-0xd800u < 0x800u || c >= 0x110000u) goto ilseq;
+ break;
+ case UCS2BE:
+ case UCS2LE:
case UTF_16BE:
case UTF_16LE:
l = 2;
if (*inb < 2) goto starved;
- c = get_16(*in, from);
+ c = get_16((void *)*in, type);
if ((unsigned)(c-0xdc00) < 0x400) goto ilseq;
if ((unsigned)(c-0xd800) < 0x400) {
+ if (type-UCS2BE < 2U) goto ilseq;
l = 4;
if (*inb < 4) goto starved;
- d = get_16(*in + 2, from);
- if ((unsigned)(c-0xdc00) >= 0x400) goto ilseq;
- c = ((c-0xd800)<<10) | (d-0xdc00);
+ d = get_16((void *)(*in + 2), type);
+ if ((unsigned)(d-0xdc00) >= 0x400) goto ilseq;
+ c = ((c-0xd7c0)<<10) + (d-0xdc00);
}
break;
- case UTF_32BE:
- case UTF_32LE:
- l = 4;
- if (*inb < 4) goto starved;
- // FIXME
- // c = get_32(*in, from);
- break;
- default:
- /* only support ascii supersets */
- if (c < 0x80) break;
- switch (map[0]) {
- case UCS2_8BIT:
- c -= 0x80;
+ case UCS2:
+ case UTF_16:
+ l = 0;
+ if (!scd->state) {
+ if (*inb < 2) goto starved;
+ c = get_16((void *)*in, 0);
+ scd->state = type==UCS2
+ ? c==0xfffe ? UCS2LE : UCS2BE
+ : c==0xfffe ? UTF_16LE : UTF_16BE;
+ if (c == 0xfffe || c == 0xfeff)
+ l = 2;
+ }
+ type = scd->state;
+ continue;
+ case UTF_32:
+ l = 0;
+ if (!scd->state) {
+ if (*inb < 4) goto starved;
+ c = get_32((void *)*in, 0);
+ scd->state = c==0xfffe0000 ? UTF_32LE : UTF_32BE;
+ if (c == 0xfffe0000 || c == 0xfeff)
+ l = 4;
+ }
+ type = scd->state;
+ continue;
+ case SHIFT_JIS:
+ if (c < 128) break;
+ if (c-0xa1 <= 0xdf-0xa1) {
+ c += 0xff61-0xa1;
break;
- case EUC_JP:
- if ((unsigned)c - 0xa1 >= 94) goto ilseq;
- if ((unsigned)in[0][1] - 0xa1 >= 94) goto ilseq;
- c = (c-0xa1)*94 + (in[0][1]-0xa1);
- l = 2;
+ }
+ l = 2;
+ if (*inb < 2) goto starved;
+ d = *((unsigned char *)*in + 1);
+ if (c-129 <= 159-129) c -= 129;
+ else if (c-224 <= 239-224) c -= 193;
+ else goto ilseq;
+ c *= 2;
+ if (d-64 <= 158-64) {
+ if (d==127) goto ilseq;
+ if (d>127) d--;
+ d -= 64;
+ } else if (d-159 <= 252-159) {
+ c++;
+ d -= 159;
+ }
+ c = jis0208[c][d];
+ if (!c) goto ilseq;
+ break;
+ case EUC_JP:
+ if (c < 128) break;
+ l = 2;
+ if (*inb < 2) goto starved;
+ d = *((unsigned char *)*in + 1);
+ if (c==0x8e) {
+ c = d;
+ if (c-0xa1 > 0xdf-0xa1) goto ilseq;
+ c += 0xff61 - 0xa1;
break;
- case SHIFT_JIS:
- if ((unsigned)c - 0xa1 <= 0xdf-0xa1) {
- c += 0xff61-0xa1;
- goto charok;
+ }
+ c -= 0xa1;
+ d -= 0xa1;
+ if (c >= 84 || d >= 94) goto ilseq;
+ c = jis0208[c][d];
+ if (!c) goto ilseq;
+ break;
+ case ISO2022_JP:
+ if (c >= 128) goto ilseq;
+ if (c == '\033') {
+ l = 3;
+ if (*inb < 3) goto starved;
+ c = *((unsigned char *)*in + 1);
+ d = *((unsigned char *)*in + 2);
+ if (c != '(' && c != '$') goto ilseq;
+ switch (128*(c=='$') + d) {
+ case 'B': scd->state=0; continue;
+ case 'J': scd->state=1; continue;
+ case 'I': scd->state=4; continue;
+ case 128+'@': scd->state=2; continue;
+ case 128+'B': scd->state=3; continue;
}
- // FIXME...
+ goto ilseq;
+ }
+ switch (scd->state) {
+ case 1:
+ if (c=='\\') c = 0xa5;
+ if (c=='~') c = 0x203e;
+ break;
+ case 2:
+ case 3:
l = 2;
+ if (*inb < 2) goto starved;
+ d = *((unsigned char *)*in + 1);
+ c -= 0x21;
+ d -= 0x21;
+ if (c >= 84 || d >= 94) goto ilseq;
+ c = jis0208[c][d];
+ if (!c) goto ilseq;
+ break;
+ case 4:
+ if (c-0x60 < 0x1f) goto ilseq;
+ if (c-0x21 < 0x5e) c += 0xff61-0x21;
break;
- default:
- goto badf;
}
- c = get_16(map + 4 + 2*c, 0);
- if (c == 0xffff) goto ilseq;
- goto charok;
+ break;
+ default:
+ if (!c) break;
+ c = legacy_map(map, c);
+ if (!c) goto ilseq;
}
- if ((unsigned)c - 0xd800 < 0x800 || (unsigned)c >= 0x110000)
- goto ilseq;
-charok:
- switch (to) {
+ switch (totype) {
case WCHAR_T:
if (*outb < sizeof(wchar_t)) goto toobig;
*(wchar_t *)*out = c;
@@ -389,36 +548,124 @@ charok:
*outb -= k;
break;
case US_ASCII:
- if (c > 0x7f) c = 0xfffd;
- /* fall thru and count replacement in latin1 case */
- case LATIN_9:
- if (c >= 0x100 && c != 0xfffd)
- c = latin9_translit(c);
- /* fall through */
- case LATIN_1:
- if (!*outb) goto toobig;
- if (c < 0x100) **out = c;
- else x++, **out = '*'; //FIXME: translit?
- ++*out;
- --*outb;
+ if (c > 0x7f) subst: x++, c='*';
+ default:
+ if (*outb < 1) goto toobig;
+ if (c<256 && c==legacy_map(tomap, c)) {
+ revout:
+ *(*out)++ = c;
+ *outb -= 1;
+ break;
+ }
+ d = c;
+ for (c=4*totype; c<256; c++) {
+ if (d == legacy_map(tomap, c)) {
+ goto revout;
+ }
+ }
+ goto subst;
+ case SHIFT_JIS:
+ if (c < 128) goto revout;
+ if (c == 0xa5) {
+ x++;
+ c = '\\';
+ goto revout;
+ }
+ if (c == 0x203e) {
+ x++;
+ c = '~';
+ goto revout;
+ }
+ if (c-0xff61 <= 0xdf-0xa1) {
+ c += 0xa1 - 0xff61;
+ goto revout;
+ }
+ c = uni_to_jis(c);
+ if (!c) goto subst;
+ if (*outb < 2) goto toobig;
+ d = c%256;
+ c = c/256;
+ *(*out)++ = (c+1)/2 + (c<95 ? 112 : 176);
+ *(*out)++ = c%2 ? d + 31 + d/96 : d + 126;
+ *outb -= 2;
+ break;
+ case EUC_JP:
+ if (c < 128) goto revout;
+ if (c-0xff61 <= 0xdf-0xa1) {
+ c += 0x0e00 + 0x21 - 0xff61;
+ } else {
+ c = uni_to_jis(c);
+ }
+ if (!c) goto subst;
+ if (*outb < 2) goto toobig;
+ *(*out)++ = c/256 + 0x80;
+ *(*out)++ = c%256 + 0x80;
+ *outb -= 2;
break;
+ case ISO2022_JP:
+ if (c < 128) goto revout;
+ if (c-0xff61 <= 0xdf-0xa1 || c==0xa5 || c==0x203e) {
+ if (*outb < 7) goto toobig;
+ *(*out)++ = '\033';
+ *(*out)++ = '(';
+ if (c==0xa5) {
+ *(*out)++ = 'J';
+ *(*out)++ = '\\';
+ } else if (c==0x203e) {
+ *(*out)++ = 'J';
+ *(*out)++ = '~';
+ } else {
+ *(*out)++ = 'I';
+ *(*out)++ = c-0xff61+0x21;
+ }
+ *(*out)++ = '\033';
+ *(*out)++ = '(';
+ *(*out)++ = 'B';
+ *outb -= 7;
+ break;
+ }
+ c = uni_to_jis(c);
+ if (!c) goto subst;
+ if (*outb < 8) goto toobig;
+ *(*out)++ = '\033';
+ *(*out)++ = '$';
+ *(*out)++ = 'B';
+ *(*out)++ = c/256;
+ *(*out)++ = c%256;
+ *(*out)++ = '\033';
+ *(*out)++ = '(';
+ *(*out)++ = 'B';
+ *outb -= 8;
+ break;
+ case UCS2:
+ totype = UCS2BE;
+ case UCS2BE:
+ case UCS2LE:
+ case UTF_16:
case UTF_16BE:
case UTF_16LE:
- if (c < 0x10000) {
+ if (c < 0x10000 || totype-UCS2BE < 2U) {
+ if (c >= 0x10000) c = 0xFFFD;
if (*outb < 2) goto toobig;
- put_16(*out, c, to);
+ put_16((void *)*out, c, totype);
*out += 2;
*outb -= 2;
break;
}
if (*outb < 4) goto toobig;
- put_16(*out, (c>>10)|0xd800, to);
- put_16(*out + 2, (c&0x3ff)|0xdc00, to);
+ c -= 0x10000;
+ put_16((void *)*out, (c>>10)|0xd800, totype);
+ put_16((void *)(*out + 2), (c&0x3ff)|0xdc00, totype);
+ *out += 4;
+ *outb -= 4;
+ break;
+ case UTF_32BE:
+ case UTF_32LE:
+ if (*outb < 4) goto toobig;
+ put_32((void *)*out, c, totype);
*out += 4;
*outb -= 4;
break;
- default:
- goto badf;
}
}
return x;
@@ -426,17 +673,20 @@ ilseq:
err = EILSEQ;
x = -1;
goto end;
-badf:
- err = EBADF;
- x = -1;
- goto end;
toobig:
err = E2BIG;
x = -1;
goto end;
starved:
err = EINVAL;
+ x = -1;
end:
errno = err;
return x;
}
+
+int iconv_close(iconv_t cd)
+{
+ return 0;
+}
+
diff --git a/libiconv/include/charmaps.h b/libiconv/include/charmaps.h
deleted file mode 100644
index 083cd699f..000000000
--- a/libiconv/include/charmaps.h
+++ /dev/null
@@ -1,80 +0,0 @@
-#include "charmaps/iso-8859-2.h"
-#include "charmaps/iso-8859-10.h"
-#include "charmaps/windows-874.h"
-#include "charmaps/windows-1250.h"
-#include "charmaps/koi8-r.h"
-
-#ifdef ALL_CHARSETS
-#include "charmaps/iso-8859-3.h"
-#include "charmaps/iso-8859-4.h"
-#include "charmaps/iso-8859-5.h"
-#include "charmaps/iso-8859-6.h"
-#include "charmaps/iso-8859-7.h"
-#include "charmaps/iso-8859-8.h"
-#include "charmaps/iso-8859-9.h"
-#include "charmaps/iso-8859-13.h"
-#include "charmaps/iso-8859-14.h"
-#include "charmaps/iso-8859-16.h"
-#include "charmaps/windows-1251.h"
-#include "charmaps/windows-1252.h"
-#include "charmaps/windows-1253.h"
-#include "charmaps/windows-1254.h"
-#include "charmaps/windows-1255.h"
-#include "charmaps/windows-1256.h"
-#include "charmaps/windows-1257.h"
-#include "charmaps/windows-1258.h"
-#endif
-
-
-struct charmap {
- const char name[13];
- const unsigned char *map;
-};
-
-static struct charmap charmaps[] = {
- { "ISO-8859-2", map_iso_8859_2 },
- { "ISO-8859-10", map_iso_8859_10 },
-
-#ifdef ALL_CHARSETS
- { "ISO-8859-3", map_iso_8859_3 },
- { "ISO-8859-4", map_iso_8859_4 },
- { "ISO-8859-5", map_iso_8859_5 },
- { "ISO-8859-6", map_iso_8859_6 },
- { "ISO-8859-7", map_iso_8859_7 },
- { "ISO-8859-8", map_iso_8859_8 },
- { "ISO-8859-9", map_iso_8859_9 },
- { "ISO-8859-13", map_iso_8859_13 },
- { "ISO-8859-14", map_iso_8859_14 },
- { "ISO-8859-16", map_iso_8859_16 },
-#endif
-
- { "WINDOWS-874", map_windows_874 },
- { "WINDOWS-1250", map_windows_1250 },
-
-#ifdef ALL_CHARSETS
- { "WINDOWS-1251", map_windows_1251 },
- { "WINDOWS-1252", map_windows_1252 },
- { "WINDOWS-1253", map_windows_1253 },
- { "WINDOWS-1254", map_windows_1254 },
- { "WINDOWS-1255", map_windows_1255 },
- { "WINDOWS-1256", map_windows_1256 },
- { "WINDOWS-1257", map_windows_1257 },
- { "WINDOWS-1258", map_windows_1258 },
-#endif
-
- { "KOI8-R", map_koi8_r },
-
- /* Aliases */
- { "LATIN2", map_iso_8859_2 },
- { "LATIN6", map_iso_8859_10 },
-
-#ifdef ALL_CHARSETS
- { "ARABIC", map_iso_8859_6 },
- { "CYRILLIC", map_iso_8859_5 },
- { "GREEK", map_iso_8859_7 },
- { "HEBREW", map_iso_8859_8 },
- { "LATIN3", map_iso_8859_3 },
- { "LATIN4", map_iso_8859_4 },
- { "LATIN5", map_iso_8859_9 },
-#endif
-};
diff --git a/libiconv/include/charmaps/iso-8859-10.h b/libiconv/include/charmaps/iso-8859-10.h
deleted file mode 100644
index cb93d027d..000000000
--- a/libiconv/include/charmaps/iso-8859-10.h
+++ /dev/null
@@ -1,24 +0,0 @@
-static const unsigned char map_iso_8859_10[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x81, 0x00, 0x82, 0x00, 0x83,
- 0x00, 0x84, 0x00, 0x85, 0x00, 0x86, 0x00, 0x87, 0x00, 0x88, 0x00, 0x89,
- 0x00, 0x8a, 0x00, 0x8b, 0x00, 0x8c, 0x00, 0x8d, 0x00, 0x8e, 0x00, 0x8f,
- 0x00, 0x90, 0x00, 0x91, 0x00, 0x92, 0x00, 0x93, 0x00, 0x94, 0x00, 0x95,
- 0x00, 0x96, 0x00, 0x97, 0x00, 0x98, 0x00, 0x99, 0x00, 0x9a, 0x00, 0x9b,
- 0x00, 0x9c, 0x00, 0x9d, 0x00, 0x9e, 0x00, 0x9f, 0x00, 0xa0, 0x01, 0x04,
- 0x01, 0x12, 0x01, 0x22, 0x01, 0x2a, 0x01, 0x28, 0x01, 0x36, 0x00, 0xa7,
- 0x01, 0x3b, 0x01, 0x10, 0x01, 0x60, 0x01, 0x66, 0x01, 0x7d, 0x00, 0xad,
- 0x01, 0x6a, 0x01, 0x4a, 0x00, 0xb0, 0x01, 0x05, 0x01, 0x13, 0x01, 0x23,
- 0x01, 0x2b, 0x01, 0x29, 0x01, 0x37, 0x00, 0xb7, 0x01, 0x3c, 0x01, 0x11,
- 0x01, 0x61, 0x01, 0x67, 0x01, 0x7e, 0x20, 0x15, 0x01, 0x6b, 0x01, 0x4b,
- 0x01, 0x00, 0x00, 0xc1, 0x00, 0xc2, 0x00, 0xc3, 0x00, 0xc4, 0x00, 0xc5,
- 0x00, 0xc6, 0x01, 0x2e, 0x01, 0x0c, 0x00, 0xc9, 0x01, 0x18, 0x00, 0xcb,
- 0x01, 0x16, 0x00, 0xcd, 0x00, 0xce, 0x00, 0xcf, 0x00, 0xd0, 0x01, 0x45,
- 0x01, 0x4c, 0x00, 0xd3, 0x00, 0xd4, 0x00, 0xd5, 0x00, 0xd6, 0x01, 0x68,
- 0x00, 0xd8, 0x01, 0x72, 0x00, 0xda, 0x00, 0xdb, 0x00, 0xdc, 0x00, 0xdd,
- 0x00, 0xde, 0x00, 0xdf, 0x01, 0x01, 0x00, 0xe1, 0x00, 0xe2, 0x00, 0xe3,
- 0x00, 0xe4, 0x00, 0xe5, 0x00, 0xe6, 0x01, 0x2f, 0x01, 0x0d, 0x00, 0xe9,
- 0x01, 0x19, 0x00, 0xeb, 0x01, 0x17, 0x00, 0xed, 0x00, 0xee, 0x00, 0xef,
- 0x00, 0xf0, 0x01, 0x46, 0x01, 0x4d, 0x00, 0xf3, 0x00, 0xf4, 0x00, 0xf5,
- 0x00, 0xf6, 0x01, 0x69, 0x00, 0xf8, 0x01, 0x73, 0x00, 0xfa, 0x00, 0xfb,
- 0x00, 0xfc, 0x00, 0xfd, 0x00, 0xfe, 0x01, 0x38
-};
diff --git a/libiconv/include/charmaps/iso-8859-13.h b/libiconv/include/charmaps/iso-8859-13.h
deleted file mode 100644
index b44d1b434..000000000
--- a/libiconv/include/charmaps/iso-8859-13.h
+++ /dev/null
@@ -1,24 +0,0 @@
-static const unsigned char map_iso_8859_13[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x81, 0x00, 0x82, 0x00, 0x83,
- 0x00, 0x84, 0x00, 0x85, 0x00, 0x86, 0x00, 0x87, 0x00, 0x88, 0x00, 0x89,
- 0x00, 0x8a, 0x00, 0x8b, 0x00, 0x8c, 0x00, 0x8d, 0x00, 0x8e, 0x00, 0x8f,
- 0x00, 0x90, 0x00, 0x91, 0x00, 0x92, 0x00, 0x93, 0x00, 0x94, 0x00, 0x95,
- 0x00, 0x96, 0x00, 0x97, 0x00, 0x98, 0x00, 0x99, 0x00, 0x9a, 0x00, 0x9b,
- 0x00, 0x9c, 0x00, 0x9d, 0x00, 0x9e, 0x00, 0x9f, 0x00, 0xa0, 0x20, 0x1d,
- 0x00, 0xa2, 0x00, 0xa3, 0x00, 0xa4, 0x20, 0x1e, 0x00, 0xa6, 0x00, 0xa7,
- 0x00, 0xd8, 0x00, 0xa9, 0x01, 0x56, 0x00, 0xab, 0x00, 0xac, 0x00, 0xad,
- 0x00, 0xae, 0x00, 0xc6, 0x00, 0xb0, 0x00, 0xb1, 0x00, 0xb2, 0x00, 0xb3,
- 0x20, 0x1c, 0x00, 0xb5, 0x00, 0xb6, 0x00, 0xb7, 0x00, 0xf8, 0x00, 0xb9,
- 0x01, 0x57, 0x00, 0xbb, 0x00, 0xbc, 0x00, 0xbd, 0x00, 0xbe, 0x00, 0xe6,
- 0x01, 0x04, 0x01, 0x2e, 0x01, 0x00, 0x01, 0x06, 0x00, 0xc4, 0x00, 0xc5,
- 0x01, 0x18, 0x01, 0x12, 0x01, 0x0c, 0x00, 0xc9, 0x01, 0x79, 0x01, 0x16,
- 0x01, 0x22, 0x01, 0x36, 0x01, 0x2a, 0x01, 0x3b, 0x01, 0x60, 0x01, 0x43,
- 0x01, 0x45, 0x00, 0xd3, 0x01, 0x4c, 0x00, 0xd5, 0x00, 0xd6, 0x00, 0xd7,
- 0x01, 0x72, 0x01, 0x41, 0x01, 0x5a, 0x01, 0x6a, 0x00, 0xdc, 0x01, 0x7b,
- 0x01, 0x7d, 0x00, 0xdf, 0x01, 0x05, 0x01, 0x2f, 0x01, 0x01, 0x01, 0x07,
- 0x00, 0xe4, 0x00, 0xe5, 0x01, 0x19, 0x01, 0x13, 0x01, 0x0d, 0x00, 0xe9,
- 0x01, 0x7a, 0x01, 0x17, 0x01, 0x23, 0x01, 0x37, 0x01, 0x2b, 0x01, 0x3c,
- 0x01, 0x61, 0x01, 0x44, 0x01, 0x46, 0x00, 0xf3, 0x01, 0x4d, 0x00, 0xf5,
- 0x00, 0xf6, 0x00, 0xf7, 0x01, 0x73, 0x01, 0x42, 0x01, 0x5b, 0x01, 0x6b,
- 0x00, 0xfc, 0x01, 0x7c, 0x01, 0x7e, 0x20, 0x19
-};
diff --git a/libiconv/include/charmaps/iso-8859-14.h b/libiconv/include/charmaps/iso-8859-14.h
deleted file mode 100644
index 76cead98c..000000000
--- a/