1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
/* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
#include "indian.h"
char *binsearch(struct tabl *table, int sz, char *word) {
int result, index, lindex, hindex;
if (word[1] == '\0') {
if (0xf1 <= ((unsigned char *)word)[0] && ((unsigned char *)word)[0] <= 0xfa) {
/* is digit */
word[0] -= 0xc1;
return word;
} else if (((unsigned char *)word)[0] == 0xea) {
/* full stop */
word[0] = 0x2a;
return word;
}
}
lindex = 0;
hindex = sz;
while (1) {
index = (lindex + hindex) / 2;
result = strcmp(table[index].iscii, word);
if (result == 0) return table[index].font;
if (result > 0) hindex = index;
if (result < 0) lindex = index + 1;
if (lindex >= hindex) return NULL;
}
}
int iscii2font(struct tabl *table, char *input, char *output, int sz) {
memset(output, 0, strlen(output));
strcat(output, (char *)split(table, input, sz));
return strlen(output);
}
|