File: mkai.c

package info (click to toggle)
chdrv 1.0.13-0.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,204 kB
  • ctags: 1,069
  • sloc: ansic: 8,972; perl: 412; asm: 234; makefile: 195; sh: 36
file content (98 lines) | stat: -rw-r--r-- 1,789 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <stdio.h>
#include "chinese.h"
#include "phone.h"
FILE *in;
unsigned char buf[128];



static char phone_v[] = "1QAZ2WSXEDCRFV5TGBYHN";
static char phone_j1[] = "UJM";
static char phone_j2[] = "8IK,9OL.0P;/-";
static char phone_k[] = "7 634";
PHONE *PhoneTable;
int PhoneTableSize;
static void loadtable()
{
  int i,j;
  char *phone;
  FILE *in;
  char cc[128][4],*dd;

  in = fopen("phone.def","r");
  if (in == NULL)
    {
      PhoneTable = NULL;
      return;
    }
  PhoneTable = (PHONE *) malloc(sizeof(PHONE)*20000);
  if (PhoneTable == NULL)
    {
      return;
    }
  i = 0;
  while(fgets(buf,100,in))
    {
      buf[0] = toupper(buf[0]);
      buf[1] = toupper(buf[1]);
      buf[2] = toupper(buf[2]);
      if (buf[0] == ' ')
	buf[0] = 255;
      if (buf[1] == ' ')
	buf[1] = 255;
      if (buf[2] == ' ')
	buf[2] = 255;

      memcpy(PhoneTable[i].seqs,buf,4);
      PhoneTable[i].chinese.code[1] = buf[6];
      PhoneTable[i].chinese.code[0] = buf[5];
      i++;
    }
  PhoneTableSize = i;
  fclose(in);
  PhoneTable = (PHONE *) realloc(PhoneTable,i*sizeof(PHONE));
}

PHcode getPHcode(unsigned char c1,unsigned char c2)
{
  int i;
  PHcode ph;
  WORD cc;
  cc = c1*256+c2;
  for(i=0;i<PhoneTableSize;i++)
    {
      if (cc == PhoneTable[i].chinese.big5)
	{
	  memcpy(ph.seqs,PhoneTable[i].seqs,4);
	  return ph;
	}
    }
  ph.key = 0;
}

main(int argc,char *argv[])
{
  if (argc != 2)
    {
      printf("Usage : mkai <input file>\n");
      exit(-1);
    }
  in = fopen(argv[1],"r");
  loadtable();
  while(fgets(buf,100,in))
    {
      unsigned char *dd =  buf;
      PHcode ph;
      while(*dd)
	{
	  if (isspace(*dd))
	    break;
	  ph = getPHcode(dd[0],dd[1]);
	  write(1,ph.seqs,4);
	  dd +=2;
	}
      *(int *) buf = -1;
      write(1,buf,4);
    }
  
}