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(const char **input, int *inlen,
50 wchar_t *output, int outlen,
51 int charset, charset_state *state,
52 const wchar_t *errstr, int errlen)
54 charset_spec const *spec = charset_find_spec(charset);
55 charset_state localstate;
56 struct unicode_emit_param param;
58 param.output = output;
59 param.outlen = outlen;
60 param.errstr = errstr;
61 param.errlen = errlen;
67 localstate = *state; /* structure copy */
71 int lenbefore = param.output - output;
72 spec->read(spec, (unsigned char)**input, &localstate,
73 unicode_emit, ¶m);
76 * The emit function has _tried_ to output some
77 * characters, but ran up against the end of the
78 * buffer. Leave immediately, and return what happened
79 * _before_ attempting to process this character.
84 *state = localstate; /* structure copy */
89 return param.output - output;