2#define utf_cont(ch) (((ch) & 0xc0) == 0x80)
7 if (ferror(st->file)) {
11 return post_process_weof(st);
19extern int get_wchar(
int sno) {
24 return post_process_f_weof(st);
30 return post_process_read_wchar(ch, 1, st);
36 return post_process_read_wchar(ch, 1, st);
44 memset((
void *)&(mbstate), 0,
sizeof(mbstate_t));
47 while ((out = mbrtowc(&wch, buf, 1, &(mbstate))) != 1) {
51 return post_process_weof(st);
53 return post_process_read_wchar(wch, n, st);
61 return post_process_read_wchar(ch, 1, st);
63 if ((ch - 0xc2) > (0xf4-0xc2)) {
64 return Yap_encoding_error(ch, 1, st);
70 return post_process_weof(st);
72 return Yap_encoding_error(ch, 2, st);
74 wch = ((ch & 0x1f) << 6) | (c1 & 0x3f);
75 return post_process_read_wchar(wch, 2, st);
80 return post_process_weof(st);
82 if (ch == 0xed && c1 > 0x9f) {
83 return Yap_encoding_error(ch, 1, st);
87 return post_process_weof(st);
88 if ( !utf_cont(c1) || !utf_cont(c2)) {
89 return Yap_encoding_error(ch, 2, st);
93 wch = ((ch & 0xf) << 12) | ((c1 & 0x3f) << 6) | (c2 & 0x3f);
94 return post_process_read_wchar(wch, 3, st);
98 return post_process_weof(st);
101 return post_process_weof(st);
104 return post_process_weof(st);
105 if ( !utf_cont(c1) || !utf_cont(c2) || !utf_cont(c3)) {
106 return Yap_encoding_error(ch, 3, st);
108 wch = ((ch & 7) << 18) | ((c1 & 0x3f) << 12) | ((c2 & 0x3f) << 6) |
110 return post_process_read_wchar(wch, 4, st);
119 return post_process_weof(st);
120 wch = (
unsigned int)(c1 << 8) + ch;
121 if (wch >= 0xd800 && wch < 0xdc00) {
124 return post_process_weof(st);
127 return post_process_weof(st);
128 wch = wch + ((
unsigned int)((
unsigned int)((c3 << 8) + c2) << 8) + SURROGATE_OFFSET);
129 return post_process_read_wchar(wch, 4, st);
131 return post_process_read_wchar(wch, 2, st);
140 return post_process_weof(st);
141 wch = (c1) + (ch << 8);
145 if (wch >= 0xd800 && wch < 0xdc00) {
148 return post_process_weof(st);
151 return post_process_weof(st);
152 wch = (((c3 << 8) + c2) << 8) + wch + SURROGATE_OFFSET;
153 return post_process_read_wchar(wch, 4, st);
155 return post_process_read_wchar(wch, 2, st);
164 return post_process_weof(st);
165 wch = (c1) + (ch << 8);
166 return post_process_read_wchar(wch, 2, st);
175 return post_process_weof(st);
176 wch = (c1 << 8) + ch;
178 return post_process_read_wchar(wch, 2, st);
181 case ENC_ISO_UTF32_BE:
184 unsigned int wch = ch;
188 return post_process_weof(st);
189 wch = wch + (
unsigned int)c1;
194 return post_process_weof(st);
195 wch = (wch << 8) + (
unsigned int)c1;
200 return post_process_weof(st);
201 wch = (wch << 8) + (
unsigned int)c1;
203 return post_process_read_wchar(wch, 4, st);
205 case ENC_ISO_UTF32_LE:
208 unsigned int wch = ch;
212 return post_process_weof(st);
213 wch += (
unsigned int)(c1 << 8);
218 return post_process_weof(st);
219 wch += (
unsigned int)(c1 << 16);
224 return post_process_weof(st);
225 wch += (
unsigned int)(c1 << 24);
227 return post_process_read_wchar(wch, 4, st);
230 Yap_ThrowError(SYSTEM_ERROR_OPERATING_SYSTEM, MkIntTerm(st->
encoding),
231 "Unsupported Encoding %d\n", st->
encoding);
236extern int get_wchar_UTF8(
int sno) {
240 return post_process_weof(st);
243 unsigned char buf[8];
246 return post_process_read_wchar(ch, 1, st);
253 return post_process_weof(st);
255 return Yap_encoding_error(ch, 2, st);
257 wch = ((ch & 0x1f) << 6) | (c1 & 0x3f);
258 return post_process_read_wchar(wch, 2, st);
268 return post_process_weof(st);
269 if (ch == 0xed && c1 > 0x9f)
270 return Yap_encoding_error(ch, 2, st);
273 return post_process_weof(st);
274 wch = ((ch & 0xf)<<12) | ((c1 & 0x3f)<<6) | (c2 & 0x3f);
276 return Yap_encoding_error(ch, 3, st);
277 return post_process_read_wchar(wch, 3, st);
281 return post_process_weof(st);
284 return post_process_weof(st);
287 return post_process_weof(st);
289 if (c1 < 0x90)
return Yap_encoding_error(ch, 4, st);
290 }
else if (c1 == 0xf4) {
291 if (c2 > 0x8f)
return Yap_encoding_error(ch, 4, st);
293 wch = ((ch & 7)<<18) | ((c1 & 0x3f)<<12) | ((c2 & 0x3f)<<6) | (c3 & 0x3f);
294 return post_process_read_wchar(wch, 4, st);
int(* stream_getc)(int)
function the stream uses for writing a character
encoding_t encoding
check if the next wide character is available