2 * toucs.c - convert charsets to Unicode.
8 struct unicode_emit_param
{
11 const wchar_t *errstr
;
16 static void unicode_emit(void *ctx
, long int output
)
18 struct unicode_emit_param
*param
= (struct unicode_emit_param
*)ctx
;
23 if (output
== ERROR
) {
26 outlen
= param
->errlen
;
28 outval
= 0xFFFD; /* U+FFFD REPLACEMENT CHARACTER */
38 if (param
->outlen
>= outlen
) {
40 *param
->output
++ = *p
++;
49 int charset_to_unicode(char **input
, int *inlen
, wchar_t *output
, int outlen
,
50 int charset
, charset_state
*state
,
51 const wchar_t *errstr
, int errlen
)
53 charset_spec
const *spec
= charset_find_spec(charset
);
54 charset_state localstate
;
55 struct unicode_emit_param param
;
57 param
.output
= output
;
58 param
.outlen
= outlen
;
59 param
.errstr
= errstr
;
60 param
.errlen
= errlen
;
66 localstate
= *state
; /* structure copy */
70 int lenbefore
= param
.output
- output
;
71 spec
->read(spec
, (unsigned char)**input
, &localstate
,
72 unicode_emit
, ¶m
);
75 * The emit function has _tried_ to output some
76 * characters, but ran up against the end of the
77 * buffer. Leave immediately, and return what happened
78 * _before_ attempting to process this character.
83 *state
= localstate
; /* structure copy */
88 return param
.output
- output
;