File: indian.c

package info (click to toggle)
mlterm 3.9.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,340 kB
  • sloc: ansic: 154,713; sh: 5,302; cpp: 2,953; objc: 2,776; java: 2,472; makefile: 2,445; perl: 1,674; xml: 44
file content (40 lines) | stat: -rw-r--r-- 968 bytes parent folder | download | duplicates (3)
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);
}