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(const wchar_t **input, int *inlen,
44 char *output, int outlen,
45 int charset, charset_state *state,
46 const char *errstr, int errlen)
48 charset_spec const *spec = charset_find_spec(charset);
49 charset_state localstate;
50 struct charset_emit_param param;
52 param.output = output;
53 param.outlen = outlen;
57 * charset_emit will expect a valid errstr.
60 /* *shrug* this is good enough, and consistent across all SBCS... */
64 param.errstr = errstr;
65 param.errlen = errlen;
70 localstate = *state; /* structure copy */
75 int lenbefore = param.output - output;
76 spec->write(spec, **input, &localstate, charset_emit, ¶m);
79 * The emit function has _tried_ to output some
80 * characters, but ran up against the end of the
81 * buffer. Leave immediately, and return what happened
82 * _before_ attempting to process this character.
87 *state = localstate; /* structure copy */
91 return param.output - output;