2 * fromucs.c - convert Unicode to other character sets.
8 struct charset_emit_param
{
16 static void charset_emit(void *ctx
, long int output
)
18 struct charset_emit_param
*param
= (struct charset_emit_param
*)ctx
;
23 if (output
== ERROR
) {
25 outlen
= param
->errlen
;
32 if (param
->outlen
>= outlen
) {
34 *param
->output
++ = *p
++;
43 int charset_from_unicode(wchar_t **input
, int *inlen
, char *output
, int outlen
,
44 int charset
, charset_state
*state
,
45 const char *errstr
, int errlen
)
47 charset_spec
const *spec
= charset_find_spec(charset
);
48 charset_state localstate
;
49 struct charset_emit_param param
;
51 param
.output
= output
;
52 param
.outlen
= outlen
;
56 * charset_emit will expect a valid errstr.
59 /* *shrug* this is good enough, and consistent across all SBCS... */
63 param
.errstr
= errstr
;
64 param
.errlen
= errlen
;
69 localstate
= *state
; /* structure copy */
74 int lenbefore
= param
.output
- output
;
75 spec
->write(spec
, **input
, &localstate
, charset_emit
, ¶m
);
78 * The emit function has _tried_ to output some
79 * characters, but ran up against the end of the
80 * buffer. Leave immediately, and return what happened
81 * _before_ attempting to process this character.
86 *state
= localstate
; /* structure copy */
90 return param
.output
- output
;