提交 3aac9e54 编写于 作者: X x-xiny 提交者: x_xiny

feat: 新增 L0 posix接口

【背景】L0 需要新增适配posix接口

【修改方案】
 新增 L0 posix接口

 re #I42IQY
Signed-off-by: Nx-xiny <1301913191@qq.com>

Change-Id: I5c3faf8ea00f9c6bb2713e84321bc368e4abbd14
上级 25ef3591
...@@ -6,10 +6,10 @@ __attribute__((__noinline__)) ...@@ -6,10 +6,10 @@ __attribute__((__noinline__))
#endif #endif
static int locking_getc(FILE *f) static int locking_getc(FILE *f)
{ {
FLOCK(f); FLOCK(f);
int c = getc_unlocked(f); int c = getc_unlocked(f);
FUNLOCK(f); FUNLOCK(f);
return c; return c;
} }
static inline int do_getc(FILE *f) static inline int do_getc(FILE *f)
......
...@@ -50,12 +50,16 @@ static_library(libc) { ...@@ -50,12 +50,16 @@ static_library(libc) {
"src/errno/strerror.c", "src/errno/strerror.c",
"src/exit/abort.c", "src/exit/abort.c",
"src/exit/assert.c", "src/exit/assert.c",
"src/exit/atexit.c",
"src/internal/floatscan.c",
"src/internal/intscan.c", "src/internal/intscan.c",
"src/internal/shgetc.c", "src/internal/shgetc.c",
"src/locale/__lctrans.c", "src/locale/__lctrans.c",
"src/locale/c_locale.c", "src/locale/c_locale.c",
"src/locale/langinfo.c", "src/locale/langinfo.c",
"src/misc/dirname.c", "src/misc/dirname.c",
"src/multibyte/internal.c",
"src/multibyte/mbtowc.c",
"src/multibyte/wcrtomb.c", "src/multibyte/wcrtomb.c",
"src/multibyte/wctomb.c", "src/multibyte/wctomb.c",
"src/network/h_errno.c", "src/network/h_errno.c",
...@@ -63,6 +67,7 @@ static_library(libc) { ...@@ -63,6 +67,7 @@ static_library(libc) {
"src/network/htons.c", "src/network/htons.c",
"src/network/ntohl.c", "src/network/ntohl.c",
"src/network/ntohs.c", "src/network/ntohs.c",
"src/prng/rand.c",
"src/prng/random.c", "src/prng/random.c",
"src/regex/regcomp.c", "src/regex/regcomp.c",
"src/regex/regexec.c", "src/regex/regexec.c",
...@@ -105,17 +110,26 @@ static_library(libc) { ...@@ -105,17 +110,26 @@ static_library(libc) {
"src/stdio/vsnprintf.c", "src/stdio/vsnprintf.c",
"src/stdio/vsprintf.c", "src/stdio/vsprintf.c",
"src/stdlib/abs.c", "src/stdlib/abs.c",
"src/stdlib/atof.c",
"src/stdlib/atoi.c", "src/stdlib/atoi.c",
#"src/stdlib/strtol.c", #"src/stdlib/strtol.c",
"src/locale/iconv.c",
"src/stdio/ungetc.c",
"src/stdlib/atol.c", "src/stdlib/atol.c",
"src/stdlib/atoll.c", "src/stdlib/atoll.c",
"src/stdlib/bsearch.c",
"src/stdlib/llabs.c",
"src/stdlib/strtod.c",
"src/string/memchr.c", "src/string/memchr.c",
"src/string/memcmp.c", "src/string/memcmp.c",
"src/string/memcpy.c", "src/string/memcpy.c",
"src/string/memmove.c",
"src/string/memrchr.c", "src/string/memrchr.c",
"src/string/memset.c", "src/string/memset.c",
"src/string/stpcpy.c",
"src/string/strcasecmp.c", "src/string/strcasecmp.c",
"src/string/strcat.c",
"src/string/strchr.c", "src/string/strchr.c",
"src/string/strchrnul.c", "src/string/strchrnul.c",
"src/string/strcmp.c", "src/string/strcmp.c",
...@@ -124,12 +138,16 @@ static_library(libc) { ...@@ -124,12 +138,16 @@ static_library(libc) {
"src/string/strlen.c", "src/string/strlen.c",
"src/string/strncasecmp.c", "src/string/strncasecmp.c",
"src/string/strncmp.c", "src/string/strncmp.c",
"src/string/strncpy.c",
"src/string/strnlen.c", "src/string/strnlen.c",
"src/string/strrchr.c", "src/string/strrchr.c",
"src/string/strspn.c",
"src/string/strstr.c", "src/string/strstr.c",
"src/string/strtok.c",
"src/string/wcschr.c", "src/string/wcschr.c",
"src/string/wcslen.c", "src/string/wcslen.c",
"src/time/__month_to_secs.c", "src/time/__month_to_secs.c",
"src/time/__secs_to_tm.c",
"src/time/__tm_to_secs.c", "src/time/__tm_to_secs.c",
"src/time/__tz.c", "src/time/__tz.c",
"src/time/__year_to_secs.c", "src/time/__year_to_secs.c",
......
#include <stdlib.h>
int atexit(void (*func)(void))
{
return 0;
}
\ No newline at end of file
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <errno.h>
#include <ctype.h>
#include "shgetc.h"
#include "floatscan.h"
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
#define LD_B1B_DIG 2
#define LD_B1B_MAX 9007199, 254740991
#define KMAX 128
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
#define LD_B1B_DIG 3
#define LD_B1B_MAX 18, 446744073, 709551615
#define KMAX 2048
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
#define LD_B1B_DIG 4
#define LD_B1B_MAX 10384593, 717069655, 257060992, 658440191
#define KMAX 2048
#else
#error Unsupported long double representation
#endif
#define MASK (KMAX-1)
static long long scanexp(FILE *f, int pok)
{
int c;
int x;
long long y;
int neg = 0;
c = shgetc(f);
if (c=='+' || c=='-') {
neg = (c=='-');
c = shgetc(f);
if (c-'0'>=10U && pok) shunget(f);
}
if (c-'0'>=10U) {
shunget(f);
return LLONG_MIN;
}
for (x=0; c-'0'<10U && x<INT_MAX/10; c = shgetc(f))
x = 10*x + c-'0';
for (y=x; c-'0'<10U && y<LLONG_MAX/100; c = shgetc(f))
y = 10*y + c-'0';
for (; c-'0'<10U; c = shgetc(f));
shunget(f);
return neg ? -y : y;
}
static long double decfloat(FILE *f, int c, int bits, int emin, int sign, int pok)
{
uint32_t x[KMAX];
static const uint32_t th[] = { LD_B1B_MAX };
int i, j, k, a, z;
long long lrp=0, dc=0;
long long e10=0;
int lnz = 0;
int gotdig = 0, gotrad = 0;
int rp;
int e2;
int emax = -emin-bits+3;
int denormal = 0;
long double y;
long double frac=0;
long double bias=0;
static const int p10s[] = { 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000 };
j=0;
k=0;
/* Don't let leading zeros consume buffer space */
for (; c=='0'; c = shgetc(f)) gotdig=1;
if (c=='.') {
gotrad = 1;
for (c = shgetc(f); c=='0'; c = shgetc(f)) gotdig=1, lrp--;
}
x[0] = 0;
for (; c-'0'<10U || c=='.'; c = shgetc(f)) {
if (c == '.') {
if (gotrad) break;
gotrad = 1;
lrp = dc;
} else if (k < KMAX-3) {
dc++;
if (c!='0') lnz = dc;
if (j) x[k] = x[k]*10 + c-'0';
else x[k] = c-'0';
if (++j==9) {
k++;
j=0;
}
gotdig=1;
} else {
dc++;
if (c!='0') {
lnz = (KMAX-4)*9;
x[KMAX-4] |= 1;
}
}
}
if (!gotrad) lrp=dc;
if (gotdig && (c|32)=='e') {
e10 = scanexp(f, pok);
if (e10 == LLONG_MIN) {
if (pok) {
shunget(f);
} else {
shlim(f, 0);
return 0;
}
e10 = 0;
}
lrp += e10;
} else if (c>=0) {
shunget(f);
}
if (!gotdig) {
errno = EINVAL;
shlim(f, 0);
return 0;
}
/* Handle zero specially to avoid nasty special cases later */
if (!x[0]) return sign * 0.0;
/* Optimize small integers (w/no exponent) and over/under-flow */
if (lrp==dc && dc<10 && (bits>30 || x[0]>>bits==0))
return sign * (long double)x[0];
if (lrp > -emin/2) {
errno = ERANGE;
return sign * LDBL_MAX * LDBL_MAX;
}
if (lrp < emin-2*LDBL_MANT_DIG) {
errno = ERANGE;
return sign * LDBL_MIN * LDBL_MIN;
}
/* Align incomplete final B1B digit */
if (j) {
for (; j<9; j++) x[k]*=10;
k++;
j=0;
}
a = 0;
z = k;
e2 = 0;
rp = lrp;
/* Optimize small to mid-size integers (even in exp. notation) */
if (lnz<9 && lnz<=rp && rp < 18) {
if (rp == 9) return sign * (long double)x[0];
if (rp < 9) return sign * (long double)x[0] / p10s[8-rp];
int bitlim = bits-3*(int)(rp-9);
if (bitlim>30 || x[0]>>bitlim==0)
return sign * (long double)x[0] * p10s[rp-10];
}
/* Drop trailing zeros */
for (; !x[z-1]; z--);
/* Align radix point to B1B digit boundary */
if (rp % 9) {
int rpm9 = rp>=0 ? rp%9 : rp%9+9;
int p10 = p10s[8-rpm9];
uint32_t carry = 0;
for (k=a; k!=z; k++) {
uint32_t tmp = x[k] % p10;
x[k] = x[k]/p10 + carry;
carry = 1000000000/p10 * tmp;
if (k==a && !x[k]) {
a = ((a+1) & MASK);
rp -= 9;
}
}
if (carry) x[z++] = carry;
rp += 9-rpm9;
}
/* Upscale until desired number of bits are left of radix point */
while (rp < 9*LD_B1B_DIG || (rp == 9*LD_B1B_DIG && x[a]<th[0])) {
uint32_t carry = 0;
e2 -= 29;
for (k=((z-1) & MASK); ; k=((k-1) & MASK)) {
uint64_t tmp = ((uint64_t)x[k] << 29) + carry;
if (tmp > 1000000000) {
carry = tmp / 1000000000;
x[k] = tmp % 1000000000;
} else {
carry = 0;
x[k] = tmp;
}
if (k==((z-1) & MASK) && k!=a && !x[k]) z = k;
if (k==a) break;
}
if (carry) {
rp += 9;
a = ((a-1) & MASK);
if (a == z) {
z = ((z-1) & MASK);
x[(z-1) & MASK] |= x[z];
}
x[a] = carry;
}
}
/* Downscale until exactly number of bits are left of radix point */
for (;;) {
uint32_t carry = 0;
int sh = 1;
for (i=0; i<LD_B1B_DIG; i++) {
k = ((a+i) & MASK);
if (k == z || x[k] < th[i]) {
i=LD_B1B_DIG;
break;
}
if (x[(a+i) & MASK] > th[i]) break;
}
if (i==LD_B1B_DIG && rp==9*LD_B1B_DIG) break;
/* FIXME: find a way to compute optimal sh */
if (rp > 9+9*LD_B1B_DIG) sh = 9;
e2 += sh;
for (k=a; k!=z; k=((k+1) & MASK)) {
uint32_t tmp = x[k] & ((1<<sh)-1);
x[k] = (x[k]>>sh) + carry;
carry = (1000000000>>sh) * tmp;
if (k==a && !x[k]) {
a = ((a+1) & MASK);
i--;
rp -= 9;
}
}
if (carry) {
if (((z+1) & MASK) != a) {
x[z] = carry;
z = ((z+1) & MASK);
} else x[(z-1) & MASK] |= 1;
}
}
/* Assemble desired bits into floating point variable */
for (y=i=0; i<LD_B1B_DIG; i++) {
if (((a+i) & MASK)==z) x[(z=((z+1) & MASK))-1] = 0;
y = 1000000000.0L * y + x[(a+i) & MASK];
}
y *= sign;
/* Limit precision for denormal results */
if (bits > LDBL_MANT_DIG+e2-emin) {
bits = LDBL_MANT_DIG+e2-emin;
if (bits<0) bits=0;
denormal = 1;
}
/* Calculate bias term to force rounding, move out lower bits */
if (bits < LDBL_MANT_DIG) {
bias = copysignl(scalbn(1, 2*LDBL_MANT_DIG-bits-1), y);
frac = fmodl(y, scalbn(1, LDBL_MANT_DIG-bits));
y -= frac;
y += bias;
}
/* Process tail of decimal input so it can affect rounding */
if (((a+i) & MASK) != z) {
uint32_t t = x[(a+i) & MASK];
if (t < 500000000 && (t || ((a+i+1) & MASK) != z))
frac += 0.25*sign;
else if (t > 500000000)
frac += 0.75*sign;
else if (t == 500000000) {
if (((a+i+1) & MASK) == z)
frac += 0.5*sign;
else
frac += 0.75*sign;
}
if (LDBL_MANT_DIG-bits >= 2 && !fmodl(frac, 1))
frac++;
}
y += frac;
y -= bias;
if (((e2+LDBL_MANT_DIG) & INT_MAX) > emax-5) {
if (fabsl(y) >= 2/LDBL_EPSILON) {
if (denormal && bits==LDBL_MANT_DIG+e2-emin)
denormal = 0;
y *= 0.5;
e2++;
}
if (e2+LDBL_MANT_DIG>emax || (denormal && frac))
errno = ERANGE;
}
return scalbnl(y, e2);
}
static long double hexfloat(FILE *f, int bits, int emin, int sign, int pok)
{
uint32_t x = 0;
long double y = 0;
long double scale = 1;
long double bias = 0;
int gottail = 0, gotrad = 0, gotdig = 0;
long long rp = 0;
long long dc = 0;
long long e2 = 0;
int d;
int c;
c = shgetc(f);
/* Skip leading zeros */
for (; c=='0'; c = shgetc(f)) gotdig = 1;
if (c=='.') {
gotrad = 1;
c = shgetc(f);
/* Count zeros after the radix point before significand */
for (rp=0; c=='0'; c = shgetc(f), rp--) gotdig = 1;
}
for (; c-'0'<10U || (c|32)-'a'<6U || c=='.'; c = shgetc(f)) {
if (c=='.') {
if (gotrad) break;
rp = dc;
gotrad = 1;
} else {
gotdig = 1;
if (c > '9') d = (c|32)+10-'a';
else d = c-'0';
if (dc<8) {
x = x*16 + d;
} else if (dc < LDBL_MANT_DIG/4+1) {
y += d*(scale/=16);
} else if (d && !gottail) {
y += 0.5*scale;
gottail = 1;
}
dc++;
}
}
if (!gotdig) {
shunget(f);
if (pok) {
shunget(f);
if (gotrad) shunget(f);
} else {
shlim(f, 0);
}
return sign * 0.0;
}
if (!gotrad) rp = dc;
while (dc<8) x *= 16, dc++;
if ((c|32)=='p') {
e2 = scanexp(f, pok);
if (e2 == LLONG_MIN) {
if (pok) {
shunget(f);
} else {
shlim(f, 0);
return 0;
}
e2 = 0;
}
} else {
shunget(f);
}
e2 += 4*rp - 32;
if (!x) return sign * 0.0;
if (e2 > -emin) {
errno = ERANGE;
return sign * LDBL_MAX * LDBL_MAX;
}
if (e2 < emin-2*LDBL_MANT_DIG) {
errno = ERANGE;
return sign * LDBL_MIN * LDBL_MIN;
}
while (x < 0x80000000) {
if (y>=0.5) {
x += x + 1;
y += y - 1;
} else {
x += x;
y += y;
}
e2--;
}
if (bits > 32+e2-emin) {
bits = 32+e2-emin;
if (bits<0) bits=0;
}
if (bits < LDBL_MANT_DIG)
bias = copysignl(scalbn(1, 32+LDBL_MANT_DIG-bits-1), sign);
if (bits<32 && y && !(x&1)) x++, y=0;
y = bias + sign*(long double)x + sign*y;
y -= bias;
if (!y) errno = ERANGE;
return scalbnl(y, e2);
}
long double __floatscan(FILE *f, int prec, int pok)
{
int sign = 1;
size_t i;
int bits;
int emin;
int c;
switch (prec) {
case 0:
bits = FLT_MANT_DIG;
emin = FLT_MIN_EXP-bits;
break;
case 1:
bits = DBL_MANT_DIG;
emin = DBL_MIN_EXP-bits;
break;
case 2:
bits = LDBL_MANT_DIG;
emin = LDBL_MIN_EXP-bits;
break;
default:
return 0;
}
while (isspace((c=shgetc(f))));
if (c=='+' || c=='-') {
sign -= 2*(c=='-');
c = shgetc(f);
}
for (i=0; i<8 && (c|32)=="infinity"[i]; i++)
if (i<7) c = shgetc(f);
if (i==3 || i==8 || (i>3 && pok)) {
if (i!=8) {
shunget(f);
if (pok) for (; i>3; i--) shunget(f);
}
return sign * INFINITY;
}
if (!i) for (i=0; i<3 && (c|32)=="nan"[i]; i++)
if (i<2) c = shgetc(f);
if (i==3) {
if (shgetc(f) != '(') {
shunget(f);
return NAN;
}
for (i=1; ; i++) {
c = shgetc(f);
if (c-'0'<10U || c-'A'<26U || c-'a'<26U || c=='_')
continue;
if (c==')') return NAN;
shunget(f);
if (!pok) {
errno = EINVAL;
shlim(f, 0);
return 0;
}
while (i--) shunget(f);
return NAN;
}
return NAN;
}
if (i) {
shunget(f);
errno = EINVAL;
shlim(f, 0);
return 0;
}
if (c=='0') {
c = shgetc(f);
if ((c|32) == 'x')
return hexfloat(f, bits, emin, sign, pok);
shunget(f);
c = '0';
}
return decfloat(f, c, bits, emin, sign, pok);
}
\ No newline at end of file
#ifndef FLOATSCAN_H
#define FLOATSCAN_H
#include <stdio.h>
hidden long double __floatscan(FILE *, int, int);
#endif
\ No newline at end of file
#ifndef LOCK_H
#define LOCK_H
hidden void __lock(volatile int *);
hidden void __unlock(volatile int *);
#define LOCK(x) __lock(x)
#define UNLOCK(x) __unlock(x)
#endif
此差异已折叠。
"iso88591\0"
"latin1\0"
"\0\100"
"iso88592\0"
"\0\50"
"\240\20\364\127\116\244\334\364\324\51\250\124\65\125\126\156\265\42\27\134"
"\260\24\24\230\116\264\340\4\225\137\270\130\105\225\126\157\15\66\127\134"
"\111\5\43\214\100\304\314\144\320\61\14\45\143\321\62\30\65\343\214\103"
"\20\355\364\323\64\324\24\145\315\65\115\215\245\115\131\334\164\163\325\67"
"\112\205\43\316\100\344\320\164\320\71\15\245\163\321\72\31\265\343\316\103"
"\21\361\4\324\74\364\30\145\317\75\116\221\245\217\131\374\364\203\25\140"
"iso88593\0"
"\0\50"
"\240\220\364\327\50\244\0\40\322\51\250\260\64\25\107\56\265\2\0\134"
"\260\224\44\313\54\264\324\62\322\55\270\264\104\125\107\57\365\2\100\134"
"\300\4\43\14\0\304\50\204\320\61\310\44\243\314\62\314\64\343\314\63"
"\0\104\43\315\64\324\170\144\315\65\32\145\243\315\66\334\204\25\325\67"
"\340\204\43\16\0\344\54\224\320\71\350\244\243\316\72\354\264\343\316\73"
"\0\304\43\317\74\364\174\144\317\75\33\345\243\317\76\374\210\45\25\140"
"iso88594\0"
"\0\50"
"\240\20\44\323\122\244\230\124\323\51\250\124\45\21\110\133\265\42\327\53"
"\260\24\24\30\123\264\234\144\223\137\270\130\65\121\110\134\5\65\227\120"
"\0\5\43\314\60\304\24\143\214\112\14\45\143\321\62\24\65\343\14\112"
"\20\365\64\24\114\324\124\143\315\65\330\234\245\315\66\334\164\365\325\67"
"\1\205\43\316\70\344\224\143\316\112\15\245\163\321\72\25\265\343\116\112"
"\21\371\104\124\114\364\324\143\317\75\370\240\245\317\76\374\170\5\26\140"
"iso88595\0"
"\0\50"
"\240\104\47\335\164\324\125\147\335\165\330\145\247\335\166"
"\334\265\322\235\167\337\201\27\236\170\343\221\127\236\171"
"\347\241\227\236\172\353\261\327\236\173\357\301\27\237\174"
"\363\321\127\237\175\367\341\227\237\176\373\361\327\237\177\377\1\30\240\200"
"\3\22\130\240\201\7\42\230\240\202\13\62\330\240\203\17\102\30\241\204"
"\23\122\130\241\205\27\142\230\241\206\33\162\330\241\207\46\177\10\142\210"
"\42\216\110\142\211\46\236\210\142\212\52\236\262\42\213"
"iso88596\0"
"\0\50"
"\240\0\0\0\0\244\0\0\0\0\0\0\0\0\0\142\266\2\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\300\230\0\0\0\0\231\0\224\151\346\231\150\246\251\346\232"
"\154\266\351\346\233\160\306\51\347\234\164\326\151\347\235"
"\170\346\251\347\236\174\366\351\47\0\0\0\0\0\0\177\2\32\250\240"
"\203\22\132\250\241\207\42\232\250\242\213\62\332\250\243\217\102\32\51\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"iso88597\0"
"\0\50"
"\240\114\114\361\50\44\227\154\312\51\250\244\222\330\52\254\264\2\100\304"
"\260\304\42\313\54\212\55\306\330\55\215\71\366\330\56\220\365\22\231\144"
"\223\121\126\231\145\227\141\226\231\146\233\161\326\231\147"
"\237\201\26\232\150\243\221\6\100\151\246\235\206\132\152\252\255\306\132\153"
"\256\275\6\133\154\262\315\106\133\155\266\335\206\133\156\272\355\306\133\157"
"\276\375\6\134\160\302\15\107\134\161\306\35\207\134\162\312\55\307\134\163"
"\316\75\7\35\0"
"iso88598\0"
"\0\50"
"\240\0\40\312\50\244\224\142\312\51\250\244\162\315\52\254\264\342\312\53"
"\260\304\42\313\54\264\324\142\313\55\270\344\162\317\56\274\364\342\13\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\200\304\102\16\111\144\221\106\36\211\144\222\112\56\311\144\223"
"\116\76\11\145\224\122\116\111\145\225\126\136\211\145\226\132\156\311\45\0"
"\0\64\354\60\0"
"iso88599\0"
"\0\64"
"\34\105\43\315\64\324\124\143\315\65\330\144\243\315\66\334\260\64\325\67"
"\340\204\43\316\70\344\224\143\316\71\350\244\243\316\72\354\264\343\316\73"
"\35\305\43\317\74\364\324\143\317\75\370\344\243\317\76\374\264\104\325\77"
"iso885910\0"
"\0\50"
"\240\20\44\21\110\50\231\4\323\51\65\101\124\325\126\162\265\362\125\120"
"\260\24\64\121\110\51\235\24\323\55\66\105\144\25\127\163\105\14\226\120"
"\0\5\43\314\60\304\24\143\214\112\14\45\143\321\62\24\65\343\314\63"
"\320\364\64\324\64\324\124\143\115\127\330\234\245\315\66\334\164\343\315\67"
"\1\205\43\316\70\344\224\143\316\112\15\245\163\321\72\25\265\343\316\73"
"\360\370\104\324\74\364\324\143\217\127\370\240\245\317\76\374\364\343\217\114"
"iso885911\0"
"tis620\0"
"\0\50"
"\240\170\372\51\250\241\212\72\52\251\245\232\172\52\252\251\252\272\52\253"
"\255\272\372\52\254\261\312\72\53\255\265\332\172\53\256\271\352\272\53\257"
"\275\372\372\53\260\301\12\73\54\261\305\32\173\54\262\311\52\273\54\263"
"\315\72\373\54\264\321\112\73\55\265\325\132\173\55\0\0\0\0\0\266"
"\331\152\273\55\267\335\172\373\55\270\341\212\73\56\271\345\232\173\56\272"
"\351\252\273\56\273\355\272\373\56\274\361\312\73\57\275\0\0\0\0\0"
"iso885913\0"
"\0\50"
"\240\134\54\312\50\244\140\154\312\51\330\244\262\324\52\254\264\342\212\61"
"\260\304\42\313\54\26\327\142\313\55\370\344\302\324\56\274\364\342\213\71"
"\4\251\4\220\101\304\24\143\221\104\14\45\343\26\105\40\301\204\122\115"
"\125\355\324\323\64\103\125\143\315\65\147\345\364\324\127\334\300\45\327\67"
"\5\255\24\320\101\344\224\163\321\104\15\245\363\126\105\41\305\224\222\115"
"\126\361\344\323\74\104\325\143\317\75\150\351\4\25\130\374\304\65\27\305"
"iso885914\0"
"\0\50"
"\240\324\153\357\50\12\55\164\357\51\3\247\122\60\276\11\267\342\112\133"
"\371\352\353\321\107\373\362\153\113\277\4\373\153\360\277\12\37\214\60\300"
"\300\4\43\314\60\304\24\143\314\61\310\44\243\314\62\314\64\343\314\63"
"\151\105\43\315\64\324\124\143\115\300\330\144\243\315\66\334\164\263\326\67"
"\340\204\43\316\70\344\224\143\316\71\350\244\243\316\72\354\264\343\316\73"
"\152\305\43\317\74\364\324\143\217\300\370\344\243\317\76\374\364\303\326\77"
"iso885915\0"
"latin9\0"
"\0\51"
"\44\227\122\325\51\126\245\242\312\52\254\264\342\312\53\260\304\42\313\54"
"\162\325\142\313\55\163\345\242\313\56\107\41\325\326\57\300\4\43\314\60"
"\304\24\143\314\61\310\44\243\314\62\314\64\343\314\63\320\104\43\315\64"
"\324\124\143\315\65\330\144\243\315\66\334\164\343\315\67\340\204\43\316\70"
"\344\224\143\316\71\350\244\243\316\72\354\264\343\316\73\360\304\43\317\74"
"\364\324\143\317\75\370\344\243\317\76\374\364\343\317\77"
"iso885916\0"
"\0\50"
"\240\20\124\120\116\44\143\134\325\51\126\245\222\327\52\156\265\362\26\134"
"\260\304\302\220\116\162\135\154\313\55\163\65\244\327\56\107\41\325\126\134"
"\300\4\43\214\100\304\30\144\314\61\310\44\243\314\62\314\64\343\314\63"
"\20\355\44\315\64\324\24\145\315\123\145\145\243\315\66\334\130\264\327\67"
"\340\204\43\316\100\344\34\144\316\71\350\244\243\316\72\354\264\343\316\73"
"\21\361\44\317\74\364\30\145\17\124\146\345\243\317\76\374\134\304\327\77"
"cp1250\0"
"windows1250\0"
"\0\40"
"\44\3\120\61\0\30\163\234\261\306\0\164\134\225\307\117\145\45\227\133"
"\0\114\114\261\305\27\157\374\60\304\0\234\154\325\307\120\151\65\327\133"
"\240\370\365\127\116\244\20\144\312\51\250\244\62\325\52\254\264\342\12\134"
"\260\304\22\230\116\264\324\142\313\55\270\24\104\325\56\67\15\206\123\134"
"\111\5\43\214\100\304\314\144\320\61\14\45\143\321\62\30\65\343\214\103"
"\20\355\364\323\64\324\24\145\315\65\115\215\245\115\131\334\164\163\325\67"
"\112\205\43\316\100\344\320\164\320\71\15\245\163\321\72\31\265\343\316\103"
"\21\361\4\324\74\364\30\145\317\75\116\221\245\217\131\374\364\203\25\140"
"cp1251\0"
"windows1251\0"
"\0\40"
"\322\115\127\161\210\30\163\234\261\306\44\167\234\235\307\332\161\267\235\167"
"\40\116\114\261\305\27\157\374\60\304\0\234\174\342\307\50\252\230\42\213"
"\240\164\267\42\166\244\264\150\312\51\321\245\102\335\52\254\264\342\312\165"
"\260\304\142\35\211\56\326\142\313\55\37\232\54\342\56\46\126\67\142\211"
"\337\201\27\236\170\343\221\127\236\171\347\241\227\236\172"
"\353\261\327\236\173\357\301\27\237\174\363\321\127\237\175"
"\367\341\227\237\176\373\361\327\237\177\377\1\30\240\200\3\22\130\240\201"
"\7\42\230\240\202\13\62\330\240\203\17\102\30\241\204\23\122\130\241\205"
"\27\142\230\241\206\33\162\330\241\207"
"cp1252\0"
"windows1252\0"
"\0\40"
"\44\3\120\61\135\30\163\234\261\306\175\165\134\225\307\107\1\40\27\0"
"\0\114\114\261\305\27\157\374\60\304\202\235\154\325\307\110\1\60\127\133"
"\240\204\42\312\50\244\224\142\312\51\250\244\242\312\52\254\264\342\312\53"
"\260\304\42\313\54\264\324\142\313\55\270\344\242\313\56\274\364\342\313\57"
"\300\4\43\314\60\304\24\143\314\61\310\44\243\314\62\314\64\343\314\63"
"\320\104\43\315\64\324\124\143\315\65\330\144\243\315\66\334\164\343\315\67"
"\340\204\43\316\70\344\224\143\316\71\350\244\243\316\72\354\264\343\316\73"
"\360\304\43\317\74\364\324\143\317\75\370\344\243\317\76\374\364\343\317\77"
"cp1253\0"
"windows1253\0"
"\0\40"
"\44\3\120\61\135\30\163\234\261\306\0\164\14\200\307\0\0\0\0\0"
"\0\114\114\261\305\27\157\374\60\304\0\234\14\300\307\0\0\0\0\0"
"\240\54\306\330\50\244\224\142\312\51\250\244\2\300\52\254\264\342\112\304"
"\260\304\42\313\54\212\325\142\313\55\215\71\366\330\56\220\365\22\231\144"
"\223\121\126\231\145\227\141\226\231\146\233\161\326\231\147"
"\237\201\26\232\150\243\221\6\100\151\246\235\206\132\152\252\255\306\132\153"
"\256\275\6\133\154\262\315\106\133\155\266\335\206\133\156\272\355\306\133\157"
"\276\375\6\134\160\302\15\107\134\161\306\35\207\134\162\312\55\307\134\163"
"\316\75\7\35\0"
"cp1254\0"
"windows1254\0"
"\0\40"
"\44\3\120\61\135\30\163\234\261\306\175\165\134\225\307\107\1\0\0\0"
"\0\114\114\261\305\27\157\374\60\304\202\235\154\325\307\110\1\0\100\133"
"\240\204\42\312\50\244\224\142\312\51\250\244\242\312\52\254\264\342\312\53"
"\260\304\42\313\54\264\324\142\313\55\270\344\242\313\56\274\364\342\313\57"
"\300\4\43\314\60\304\24\143\314\61\310\44\243\314\62\314\64\343\314\63"
"\34\105\43\315\64\324\124\143\315\65\330\144\243\315\66\334\260\64\325\67"
"\340\204\43\316\70\344\224\143\316\71\350\244\243\316\72\354\264\343\316\73"
"\35\305\43\317\74\364\324\143\317\75\370\344\243\317\76\374\264\104\325\77"
"cp1255\0"
"windows1255\0"
"\0\40"
"\44\3\120\61\135\30\163\234\261\306\175\165\14\200\307\0\0\0\0\0"
"\0\114\114\261\305\27\157\374\60\304\202\235\14\300\307\0\0\0\0\0"
"\240\204\42\312\50\42\227\142\312\51\250\244\162\315\52\254\264\342\312\53"
"\260\304\42\313\54\264\324\142\313\55\270\344\162\317\56\274\364\342\313\57"
"\57\302\30\243\214\63\322\130\243\215\67\342\10\100\216\72\356\310\143\217"
"\76\376\10\144\220\135\172\371\45\230\141\2\0\0\0\0\0\0\0\0\102\16\111\144\221"
"\106\36\211\144\222\112\56\311\144\223\116\76\11\145\224\122\116\111\145\225"
"\126\136\211\145\226\132\156\311\45\0\0\64\354\60\0"
"cp1256\0"
"windows1256\0"
"\0\40"
"\44\117\132\61\135\30\163\234\261\306\175\165\54\251\307\107\121\172\151\245"
"\231\116\114\261\305\27\157\374\60\304\230\236\154\351\307\110\55\314\260\246"
"\240\210\51\312\50\244\224\142\312\51\250\244\262\351\52\254\264\342\312\53"
"\260\304\42\313\54\264\324\142\313\55\270\344\62\346\56\274\364\342\13\231"
"\234\226\151\346\231\150\246\251\346\232\154\266\351\346\233"
"\160\306\51\347\234\164\326\151\347\235\170\346\251\347\65\173\362\331\247\237"
"\177\2\32\250\240\340\14\52\16\241\205\32\172\350\71\350\244\243\316\72"
"\210\46\352\316\73\212\56\312\150\243\364\70\372\350\75\220\346\23\351\76"
"\374\64\354\160\247"
"cp1257\0"
"windows1257\0"
"\0\40"
"\44\3\120\61\0\30\163\234\261\306\0\164\14\200\307\0\240\342\27\56"
"\0\114\114\261\305\27\157\374\60\304\0\234\14\300\307\0\274\22\30\0"
"\240\0\40\312\50\244\0\140\312\51\330\244\262\324\52\254\264\342\212\61"
"\260\304\42\313\54\264\324\142\313\55\370\344\302\324\56\274\364\342\213\71"
"\4\251\4\220\101\304\24\143\221\104\14\45\343\26\105\40\301\204\122\115"
"\125\355\324\323\64\103\125\143\315\65\147\345\364\324\127\334\300\45\327\67"
"\5\255\24\320\101\344\224\163\321\104\15\245\363\126\105\41\305\224\222\115"
"\126\361\344\323\74\104\325\143\317\75\150\351\4\25\130\374\304\65\27\140"
"cp1258\0"
"windows1258\0"
"\0\40"
"\44\3\120\61\135\30\163\234\261\306\175\165\14\200\307\107\1\0\0\0"
"\0\114\114\261\305\27\157\374\60\304\202\235\14\300\307\110\1\0\100\133"
"\240\204\42\312\50\244\224\142\312\51\250\244\242\312\52\254\264\342\312\53"
"\260\304\42\313\54\264\324\142\313\55\270\344\242\313\56\274\364\342\313\57"
"\300\4\43\214\100\304\24\143\314\61\310\44\243\314\62\204\65\343\314\63"
"\20\105\163\330\64\324\324\145\315\65\330\144\243\315\66\334\334\145\330\67"
"\340\204\43\316\100\344\224\143\316\71\350\244\243\316\72\205\265\343\316\73"
"\21\305\203\330\74\364\330\145\317\75\370\344\243\317\76\374\340\65\362\77"
"koi8r\0"
"\0\40"
"\63\323\134\263\315\67\343\234\263\316\73\363\334\363\326\134\167\355\365\327"
"\140\207\55\166\314\143\243\234\62\313\56\277\14\212\314\260\310\162\313\75"
"\76\377\14\364\207\101\13\75\64\321\105\33\175\64\322\111\53\275\64\323"
"\115\73\375\164\164\120\107\55\365\324\124\127\155\365\325\130\147\255\165\52"
"\35\376\7\140\205\3\22\70\241\200\24\36\210\140\202\12\56\310\140\203"
"\16\172\370\40\204\21\112\130\140\200\33\152\150\340\205\34\142\150\141\206"
"\375\175\7\136\175\343\221\67\237\170\364\235\207\136\172\352\255\307\136\173"
"\356\371\367\36\174\361\311\127\136\170\373\351\147\336\175"
"\374\341\147\137\176"
"koi8u\0"
"\0\40"
"\63\323\134\263\315\67\343\234\263\316\73\363\334\363\326\134\167\355\365\327"
"\140\207\55\166\314\143\243\234\62\313\56\277\14\212\314\260\310\162\313\75"
"\76\377\14\364\207\42\12\115\142\211\105\33\175\64\322\111\273\270\64\323"
"\115\73\375\164\164\324\105\155\335\165\124\127\155\365\325\130\267\250\165\52"
"\35\376\7\140\205\3\22\70\241\200\24\36\210\140\202\12\56\310\140\203"
"\16\172\370\40\204\21\112\130\140\200\33\152\150\340\205\34\142\150\141\206"
"\375\175\7\136\175\343\221\67\237\170\364\235\207\136\172\352\255\307\136\173"
"\356\371\367\36\174\361\311\127\136\170\373\351\147\336\175"
"\374\341\147\137\176"
"cp437\0"
"\0\40"
"\307\360\223\216\70\344\200\123\316\71\352\254\203\316\73\356\260\103\114\61"
"\311\230\143\14\75\366\310\263\117\76\377\130\303\215\50\243\224\22\62\135"
"\341\264\63\217\76\361\104\243\212\56\277\300\314\112\57\274\204\262\312\56"
"\140\207\55\66\315\72\77\15\65\321\103\107\375\163\321\113\53\235\264\315"
"\67\363\274\163\316\63\367\314\164\323\110\13\175\65\325\116\373\254\165\325"
"\126\113\75\365\321\106\3\35\164\326\130\343\134\163\327\134\173\375\365\326"
"\263\175\143\231\160\245\25\127\213\161\250\155\266\232\155\52\43\167\333\312"
"\55\307\362\262\313\61\313\174\17\313\260\240\174\113\312\40\313\62\66\50"
"cp850\0"
"\0\40"
"\307\360\223\216\70\344\200\123\316\71\352\254\203\316\73\356\260\103\114\61"
"\311\230\143\14\75\366\310\263\117\76\377\130\303\15\76\243\140\163\15\135"
"\341\264\63\217\76\361\104\243\212\56\277\270\302\112\57\274\204\262\312\56"
"\140\207\55\66\315\72\7\43\14\60\251\104\375\163\321\113\213\122\212\315"
"\67\363\274\163\316\63\367\74\316\60\110\13\175\65\325\116\373\254\65\51"
"\360\100\243\314\62\310\264\324\214\63\317\340\134\163\327\134\233\302\314\326"
"\323\174\103\215\64\365\124\123\213\77\336\150\263\115\66\375\164\363\12\55"
"\255\304\42\261\57\266\234\162\17\56\260\240\162\113\56\263\310\62\66\50"
"cp866\0"
"\0\40"
"\337\201\27\236\170\343\221\127\236\171\347\241\227\236\172"
"\353\261\327\236\173\357\301\27\237\174\363\321\127\237\175"
"\367\341\227\237\176\373\361\327\237\177\377\1\30\240\200\3\22\130\240\201"
"\7\42\230\240\202\13\62\330\240\203\140\207\55\66\315\72\77\15\65\321"
"\103\107\375\163\321\113\53\235\264\315\67\363\274\163\316\63\367\314\164\323"
"\110\13\175\65\325\116\373\254\165\325\126\113\75\365\321\106\3\35\164\326"
"\130\343\134\163\327\134\173\375\365\326\17\102\30\241\204\23\122\130\241\205"
"\27\142\230\241\206\33\162\330\241\207\321\175\110\235\210\327\225\330\335\212"
"\260\240\174\113\312\46\223\62\66\50"
"ibm1047\0"
"cp1047\0"
"\0\1"
"\234\44\140\310\37\227\64\342\310\2\14\64\340\300\3\20\104\40\301\4"
"\235\24\202\300\41\30\144\40\311\43\34\164\340\301\7\200\4\42\310\40"
"\204\50\160\301\6\210\44\242\310\42\214\24\140\300\1\220\104\142\301\44"
"\224\124\142\11\1\230\144\242\311\46\24\124\340\211\6\40\200\42\16\71"
"\340\204\63\116\71\347\304\43\212\13\74\240\260\2\37\46\244\243\316\72"
"\350\264\343\316\73\354\174\23\2\11\52\244\260\203\27\55\274\40\14\61"
"\300\4\63\114\61\307\104\143\12\13\45\174\341\303\17\370\44\243\314\62"
"\310\64\343\314\63\314\200\241\303\10\100\234\320\203\10\330\204\41\306\30"
"\144\224\141\306\31\150\244\261\312\56\360\364\343\117\54\260\250\261\6\33"
"\155\270\361\6\34\161\310\241\212\56\346\340\142\14\51\265\370\61\7\35"
"\165\330\161\7\36\171\350\21\312\57\320\154\341\215\53\254\214\122\312\55"
"\251\234\142\13\57\275\370\322\15\52\257\164\101\313\65\173\4\41\304\20"
"\104\24\141\304\21\110\44\321\12\75\366\310\63\117\75\175\50\261\4\23"
"\115\70\361\4\24\121\110\221\313\76\374\344\243\317\77\134\334\63\5\25"
"\125\130\161\5\26\131\150\41\13\65\326\110\63\115\65\60\304\40\303\14"
"\64\324\140\303\15\70\344\60\313\66\334\144\243\315\47"
此差异已折叠。
此差异已折叠。
#include <iconv.h>
#include <errno.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <stdint.h>
#include "locale_impl.h"
#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 gb18030[126][190] = {
#include "gb18030.h"
};
static const unsigned short big5[89][157] = {
#include "big5.h"
};
static const unsigned short hkscs[] = {
#include "hkscs.h"
};
static const unsigned short ksc[93][94] = {
#include "ksc.h"
};
static const unsigned short rev_jis[] = {
#include "revjis.h"
};
static int fuzzycmp(const unsigned char *a, const unsigned char *b)
{
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 size_t find_charmap(const void *name)
{
const unsigned char *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;
}
struct stateful_cd {
iconv_t base_cd;
unsigned state;
};
static iconv_t combine_to_from(size_t t, size_t f)
{
return (void *)(f<<16 | t<<1 | 1);
}
static size_t extract_from(iconv_t cd)
{
return (size_t)cd >> 16;
}
static size_t extract_to(iconv_t cd)
{
return (size_t)cd >> 1 & 0x7fff;
}
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 cd;
}
static unsigned get_16(const unsigned char *s, int e)
{
e &= 1;
return s[e]<<8 | s[1-e];
}
static void put_16(unsigned char *s, unsigned c, int e)
{
e &= 1;
s[e] = c>>8;
s[1-e] = c;
}
static unsigned get_32(const unsigned char *s, int e)
{
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;
}
/* Adapt as needed */
#define mbrtowc_utf8 mbrtowc
#define wctomb_utf8 wctomb
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)
{
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 **restrict in, size_t *restrict inb, char **restrict out, size_t *restrict outb)
{
size_t x=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;
mbstate_t st = {0};
wchar_t wc;
unsigned c, d;
size_t k, l;
int err;
unsigned char type = map[-1];
unsigned char totype = tomap[-1];
locale_t locale = CURRENT_LOCALE;
locale_t *ploc = &locale, loc = *ploc;
if (!in || !*in || !*inb) return 0;
*ploc = UTF8_LOCALE;
for (; *inb; *in+=l, *inb-=l) {
c = *(unsigned char *)*in;
l = 1;
switch (type) {
case UTF_8:
if (c < 128) break;
l = mbrtowc_utf8(&wc, *in, *inb, &st);
if (l == (size_t)-1) goto ilseq;
if (l == (size_t)-2) goto starved;
c = wc;
break;
case US_ASCII:
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);
}
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((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((void *)(*in + 2), type);
if ((unsigned)(d-0xdc00) >= 0x400) goto ilseq;
c = ((c-0xd7c0)<<10) + (d-0xdc00);
}
break;
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;
}
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;
}
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;
}
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;
}
break;
case GB2312:
if (c < 128) break;
if (c < 0xa1) goto ilseq;
case GBK:
case GB18030:
if (c < 128) break;
c -= 0x81;
if (c >= 126) goto ilseq;
l = 2;
if (*inb < 2) goto starved;
d = *((unsigned char *)*in + 1);
if (d < 0xa1 && type == GB2312) goto ilseq;
if (d-0x40>=191 || d==127) {
if (d-'0'>9 || type != GB18030)
goto ilseq;
l = 4;
if (*inb < 4) goto starved;
c = (10*c + d-'0') * 1260;
d = *((unsigned char *)*in + 2);
if (d-0x81>126) goto ilseq;
c += 10*(d-0x81);
d = *((unsigned char *)*in + 3);
if (d-'0'>9) goto ilseq;
c += d-'0';
c += 128;
for (d=0; d<=c; ) {
k = 0;
for (int i=0; i<126; i++)
for (int j=0; j<190; j++)
if (gb18030[i][j]-d <= c-d)
k++;
d = c+1;
c += k;
}
break;
}
d -= 0x40;
if (d>63) d--;
c = gb18030[c][d];
break;
case BIG5:
if (c < 128) break;
l = 2;
if (*inb < 2) goto starved;
d = *((unsigned char *)*in + 1);
if (d-0x40>=0xff-0x40 || d-0x7f<0xa1-0x7f) goto ilseq;
d -= 0x40;
if (d > 0x3e) d -= 0x22;
if (c-0xa1>=0xfa-0xa1) {
if (c-0x87>=0xff-0x87) goto ilseq;
if (c < 0xa1) c -= 0x87;
else c -= 0x87 + (0xfa-0xa1);
c = (hkscs[4867+(c*157+d)/16]>>(c*157+d)%16)%2<<17
| hkscs[c*157+d];
/* A few HKSCS characters map to pairs of UCS
* characters. These are mapped to surrogate
* range in the hkscs table then hard-coded
* here. Ugly, yes. */
if (c/256 == 0xdc) {
union {
char c[8];
wchar_t wc[2];
} tmp;
char *ptmp = tmp.c;
size_t tmpx = iconv(combine_to_from(to, find_charmap("utf8")),
&(char *){"\303\212\314\204"
"\303\212\314\214"
"\303\252\314\204"
"\303\252\314\214"
+c%256}, &(size_t){4},
&ptmp, &(size_t){sizeof tmp});
size_t tmplen = ptmp - tmp.c;
if (tmplen > *outb) goto toobig;
if (tmpx) x++;
memcpy(*out, &tmp, tmplen);
*out += tmplen;
*outb -= tmplen;
continue;
}
if (!c) goto ilseq;
break;
}
c -= 0xa1;
c = big5[c][d]|(c==0x27&&(d==0x3a||d==0x3c||d==0x42))<<17;
if (!c) goto ilseq;
break;
case EUC_KR:
if (c < 128) break;
l = 2;
if (*inb < 2) goto starved;
d = *((unsigned char *)*in + 1);
c -= 0xa1;
d -= 0xa1;
if (c >= 93 || d >= 94) {
c += (0xa1-0x81);
d += 0xa1;
if (c >= 93 || c>=0xc6-0x81 && d>0x52)
goto ilseq;
if (d-'A'<26) d = d-'A';
else if (d-'a'<26) d = d-'a'+26;
else if (d-0x81<0xff-0x81) d = d-0x81+52;
else goto ilseq;
if (c < 0x20) c = 178*c + d;
else c = 178*0x20 + 84*(c-0x20) + d;
c += 0xac00;
for (d=0xac00; d<=c; ) {
k = 0;
for (int i=0; i<93; i++)
for (int j=0; j<94; j++)
if (ksc[i][j]-d <= c-d)
k++;
d = c+1;
c += k;
}
break;
}
c = ksc[c][d];
if (!c) goto ilseq;
break;
default:
if (!c) break;
c = legacy_map(map, c);
if (!c) goto ilseq;
}
switch (totype) {
case WCHAR_T:
if (*outb < sizeof(wchar_t)) goto toobig;
*(wchar_t *)*out = c;
*out += sizeof(wchar_t);
*outb -= sizeof(wchar_t);
break;
case UTF_8:
if (*outb < 4) {
char tmp[4];
k = wctomb_utf8(tmp, c);
if (*outb < k) goto toobig;
memcpy(*out, tmp, k);
} else k = wctomb_utf8(*out, c);
*out += k;
*outb -= k;
break;
case US_ASCII:
if (c > 0x7f) subst: x++, c='*';
default:
if (*outb < 1) goto toobig;
if (c<256 && c==legacy_map(tomap, c)) {
revout:
if (*outb < 1) goto toobig;
*(*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 || totype-UCS2BE < 2U) {
if (c >= 0x10000) c = 0xFFFD;
if (*outb < 2) goto toobig;
put_16((void *)*out, c, totype);
*out += 2;
*outb -= 2;
break;
}
if (*outb < 4) goto toobig;
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_32:
totype = UTF_32BE;
case UTF_32BE:
case UTF_32LE:
if (*outb < 4) goto toobig;
put_32((void *)*out, c, totype);
*out += 4;
*outb -= 4;
break;
}
}
*ploc = loc;
return x;
ilseq:
err = EILSEQ;
x = -1;
goto end;
toobig:
err = E2BIG;
x = -1;
goto end;
starved:
err = EINVAL;
x = -1;
end:
errno = err;
*ploc = loc;
return x;
}
此差异已折叠。
此差异已折叠。
256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,
275,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,
296,297,298,299,302,303,304,305,308,309,310,311,312,313,314,315,316,317,318,
321,322,323,324,325,326,327,328,330,331,332,333,336,337,338,339,340,341,342,
343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,
362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,
381,382,402,416,417,431,432,536,537,538,539,710,711,728,729,731,732,733,768,
769,771,777,803,890,900,901,902,904,905,906,908,910,911,912,913,914,915,916,
917,918,919,920,921,922,923,924,925,926,927,928,929,931,932,933,934,935,936,
937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,
956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,
1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1038,1039,1040,
1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,
1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,
1071,
1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,
1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,
1102,1103,1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1118,
1119,1168,1169,1456,1457,1458,1459,1460,1461,1462,1463,1464,1465,1467,1468,
1469,1470,1471,1472,1473,1474,1475,1488,1489,1490,1491,1492,1493,1494,1495,
1496,1497,1498,1499,1500,1501,1502,1503,1504,1505,1506,1507,1508,1509,1510,
1511,1512,1513,1514,1520,1521,1522,1523,1524,1548,1563,1567,1569,1570,1571,
1572,1573,1574,1575,1576,1577,1578,1579,1580,1581,1582,1583,1584,1585,1586,
1587,1588,1589,1590,1591,1592,1593,1594,1600,1601,1602,1603,1604,1605,1606,
1607,1608,1609,1610,1611,1612,1613,1614,1615,1616,1617,1618,1657,1662,1670,
1672,1681,1688,1705,1711,1722,1726,1729,1746,3585,3586,3587,3588,3589,3590,
3591,3592,3593,3594,3595,3596,3597,3598,3599,3600,3601,3602,3603,3604,3605,
3606,3607,3608,3609,3610,3611,3612,3613,3614,3615,3616,3617,3618,3619,3620,
3621,3622,3623,3624,3625,3626,3627,3628,3629,3630,3631,3632,3633,3634,3635,
3636,3637,3638,3639,3640,3641,3642,3647,3648,3649,3650,3651,3652,3653,3654,
3655,3656,3657,3658,3659,3660,3661,3662,3663,3664,3665,3666,3667,3668,3669,
3670,3671,3672,3673,3674,3675,7682,7683,7690,7691,7710,7711,7744,7745,7766,
7767,
7776,7777,7786,7787,7808,7809,7810,7811,7812,7813,7922,7923,8204,8205,8206,
8207,8211,8212,8213,8215,8216,8217,8218,8220,8221,8222,8224,8225,8226,8230,
8240,8249,8250,8319,8359,8362,8363,8364,8367,8470,8482,8729,8730,8734,8745,
8776,8801,8804,8805,8976,8992,8993,9472,9474,9484,9488,9492,9496,9500,9508,
9516,9524,9532,9552,9553,9554,9555,9556,9557,9558,9559,9560,9561,9562,9563,
9564,9565,9566,9567,9568,9569,9570,9571,9572,9573,9574,9575,9576,9577,9578,
9579,9580,9600,9604,9608,9612,9616,9617,9618,9619,9632,
此差异已折叠。
此差异已折叠。
文件模式从 100755 更改为 100644
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册