1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-26 01:32:25 +00:00

Having painstakingly generated those reverse mapping tables in

sbcsdat.c, it would seem a shame not to actually use them. Ahem.
Thanks to Ben, without whose checkin in this area I'd have forgotten
completely :-)

[originally from svn r2404]
This commit is contained in:
Simon Tatham 2003-01-01 17:03:27 +00:00
parent f8e3eee673
commit 3deb118d4b

View File

@ -28,18 +28,26 @@ void write_sbcs(charset_spec const *charset, long int input_chr,
void (*emit)(void *ctx, long int output), void *emitctx) void (*emit)(void *ctx, long int output), void *emitctx)
{ {
const struct sbcs_data *sd = charset->data; const struct sbcs_data *sd = charset->data;
int i; int i, j, k, c;
UNUSEDARG(state); UNUSEDARG(state);
/* /*
* FIXME: this should work, but it's ludicrously inefficient. * Binary-search in the ucs2sbcs table.
* We should be using the ucs2sbcs table.
*/ */
for (i = 0; i < 256; i++) i = -1;
if (sd->sbcs2ucs[i] == input_chr) { j = sd->nvalid;
emit(emitctx, i); while (i+1 < j) {
k = (i+j)/2;
c = sd->ucs2sbcs[k];
if (input_chr < sd->sbcs2ucs[c])
j = k;
else if (input_chr > sd->sbcs2ucs[c])
i = k;
else {
emit(emitctx, c);
return; return;
} }
}
emit(emitctx, ERROR); emit(emitctx, ERROR);
} }