2dc6356a |
1 | /* |
2 | * sbcs.c - routines to handle single-byte character sets. |
3 | */ |
4 | |
5 | #include "charset.h" |
6 | #include "internal.h" |
7 | |
8 | /* |
9 | * The charset_spec for any single-byte character set should |
10 | * provide read_sbcs() as its read function, and its `data' field |
11 | * should be a wchar_t string constant containing the 256 entries |
12 | * of the translation table. |
13 | */ |
14 | |
15 | void read_sbcs(charset_spec const *charset, long int input_chr, |
16 | charset_state *state, |
17 | void (*emit)(void *ctx, long int output), void *emitctx) |
18 | { |
19 | wchar_t const *table = (wchar_t const *)charset->data; |
20 | |
21 | UNUSEDARG(state); |
22 | |
23 | emit(emitctx, table[input_chr]); |
24 | } |
25 | |
26 | void write_sbcs(charset_spec const *charset, long int input_chr, |
27 | charset_state *state, |
28 | void (*emit)(void *ctx, long int output), void *emitctx) |
29 | { |
30 | wchar_t const *table = (wchar_t const *)charset->data; |
31 | int i; |
32 | |
33 | UNUSEDARG(state); |
34 | |
35 | /* |
36 | * FIXME: this should work, but it's ludicrously inefficient. |
37 | * We should be using the ucs2sbcs table. |
38 | */ |
39 | for (i = 0; i < 256; i++) |
40 | if (table[i] == input_chr) { |
41 | emit(emitctx, i); |
42 | return; |
43 | } |
44 | emit(emitctx, ERROR); |
45 | } |