2 * fromucs.c - convert Unicode to other character sets.
8 struct charset_emit_param
{
15 static void charset_emit(void *ctx
, long int output
)
17 struct charset_emit_param
*param
= (struct charset_emit_param
*)ctx
;
19 if (param
->outlen
!= 0) {
21 *param
->output
++ = output
;
22 if (param
->outlen
> 0)
30 int charset_from_unicode(const wchar_t **input
, int *inlen
,
31 char *output
, int outlen
,
32 int charset
, charset_state
*state
, int *error
)
34 charset_spec
const *spec
= charset_find_spec(charset
);
35 charset_state localstate
= CHARSET_INIT_STATE
;
36 struct charset_emit_param param
;
44 param
.output
= output
;
45 param
.outlen
= outlen
;
50 localstate
= *state
; /* structure copy */
55 int lenbefore
= param
.writtenlen
;
59 ret
= spec
->write(spec
, **input
, &localstate
,
60 charset_emit
, ¶m
);
62 ret
= spec
->write(spec
, -1, &localstate
, charset_emit
, ¶m
);
65 * We have hit a difficult character, which the user
66 * wants to know about. Leave now.
73 * The emit function has _tried_ to output some
74 * characters, but ran up against the end of the
75 * buffer. Leave immediately, and return what happened
76 * _before_ attempting to process this character.
81 *state
= localstate
; /* structure copy */
86 return param
.writtenlen
;