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