2 * fromucs.c - convert Unicode to other character sets.
8 struct charset_emit_param
{
14 static void charset_emit(void *ctx
, long int output
)
16 struct charset_emit_param
*param
= (struct charset_emit_param
*)ctx
;
18 if (param
->outlen
> 0) {
19 *param
->output
++ = output
;
26 int charset_from_unicode(const wchar_t **input
, int *inlen
,
27 char *output
, int outlen
,
28 int charset
, charset_state
*state
, int *error
)
30 charset_spec
const *spec
= charset_find_spec(charset
);
31 charset_state localstate
= CHARSET_INIT_STATE
;
32 struct charset_emit_param param
;
40 param
.output
= output
;
41 param
.outlen
= outlen
;
45 localstate
= *state
; /* structure copy */
50 int lenbefore
= param
.output
- output
;
54 ret
= spec
->write(spec
, **input
, &localstate
,
55 charset_emit
, ¶m
);
57 ret
= spec
->write(spec
, -1, &localstate
, charset_emit
, ¶m
);
60 * We have hit a difficult character, which the user
61 * wants to know about. Leave now.
68 * The emit function has _tried_ to output some
69 * characters, but ran up against the end of the
70 * buffer. Leave immediately, and return what happened
71 * _before_ attempting to process this character.
76 *state
= localstate
; /* structure copy */
81 return param
.output
- output
;