Logo Search packages:      
Sourcecode: xcingb version File versions  Download package

cj2cin.c

/*
      Copyright (C) 1994,1995  Edward Der-Hua Liu, Hsin-Chu, Taiwan
*/

#include <stdio.h>
#include <memory.h>
#include <sys/types.h>
#include "xi.h"
#include "constant.h"

unsigned char *bf;

extern void *malloc(size_t size);
extern void free(void *ptr);
extern void SORTFUNC(void *base, size_t nmemb, size_t size,
            int (*compar)(const void *, const void *));
extern void ser_b5(u_char *ch, u_char *tt);
extern int unlink(const char *pathname);


#define KeyNum (27)
u_long MaxPress=5;
char keymap[]=" abcdefghijklmnopqrstuvwxyz";
char tran[]="  日月金木水火土竹戈十大中一弓人心手口户廿山女田难卜重";

#define swap(a,b) { tt=a; a=b; b=tt; }

typedef struct {
      u_char key[4];
      u_char ch[2];
      u_short oseq;
} ITE;

int qcmp(a, b)
  ITE *a, *b;
{
      if (CONVT(a->key) > CONVT(b->key)) return 1;
      if (CONVT(a->key) < CONVT(b->key)) return -1;
      if (a->oseq > b->oseq) return 1;
      return 0;
}


int main()
{
FILE *fp/*,*fw*/;
unsigned long kk;
unsigned long k1,k2,k3,k4,k5,tt;
unsigned long /*q,r,*/ofs;
unsigned char c1,c2;
int i,/*j,*/fsize;
ITE *itar;
/*unsigned short idx1[27];*/
/*char def1[27];*/
u_short orgseq=0;
  
puts("%ename changjei");
puts("%prompt 【仓颉】");
puts("%selkey 1234567890");
puts("%dupsel 9");
puts("%keyname begin");
for(i=1;i<=25;i++)
      printf("%c %c%c\n", keymap[i], tran[i*2], tran[i*2+1]);
puts("%keyname end");
puts("%quick begin");
puts("%quick end");
puts("%sel1st begin");
puts("%sel1st end");

if ((fp=fopen("changjei.tab","r"))==NULL) {
      puts("open err");
      exit(1);
}
if ((bf=(unsigned char *)malloc(40000))==NULL) {
      puts("malloc err");
      exit(1);
}

fsize=fread(bf,1,40000,fp);
fclose(fp);

if ((fp=fopen("cj.tmp1","w"))==NULL) {
  puts("create");
  exit(-1);
}

orgseq=0;
for(i=0;i<fsize;i+=3) {
/*       kk=*(unsigned long *)(&bf[i]) & 0xffffff; */
      kk=((u_long)bf[i+2]<<16) |(u_long)(bf[i+1]<<8) |(u_long)bf[i];   /* avoid endian */


       k5=kk%27;
       kk/=27;
       k4=kk%27;
       kk/=27;
       k3=kk%27;
       kk/=27;
       k2=kk%27;
       k1=kk/27;
       if (k1>27) break;  /* end of table mark */

       if (k5!=0)
       swap(k2,k5)
       else
       if (k4!=0)
       swap(k2,k4)
       else
       if (k3!=0)
       swap(k2,k3)
       kk=k5|k4<<6|k3<<12|k2<<18|k1<<24;
       fwrite(&kk,4,1,fp);

      ofs=i/3;
      ofs+=0x8800;
      c1=ofs>>8;
      c2=ofs&255;
      fwrite(&c1,1,1,fp);
      fwrite(&c2,1,1,fp);
      fwrite(&orgseq,2,1,fp);
      orgseq++;
}
fclose(fp);
if ((fp=fopen("cj.tmp1","r"))==NULL) {
  puts("cj.tmp1 open");
  exit(-1);
}

free(bf);
i=0;
if ((itar=(ITE *)malloc((fsize+1)*sizeof(ITE)))==NULL) {
      puts("-- malloc err 2");
      exit(-1);
}

fsize=fread(itar, sizeof(ITE), fsize, fp);

SORTFUNC(itar,fsize,sizeof(ITE),qcmp);

for(i=0;i<fsize;i++) {
  u_long kk=CONVT(itar[i].key);
  char tt[3];

  ser_b5(itar[i].ch, tt);
  k1=(kk>>24)&0x1f;
  k2=(kk>>18)&0x1f;
  k3=(kk>>12)&0x1f;
  k4=(kk>>6)&0x1f;
  k5=(kk)&0x1f;
#define tk(kk) (keymap[kk])

printf("%c", tk(k1));
if (k2) printf("%c", tk(k2));
if (k3) printf("%c", tk(k3));
if (k4) printf("%c", tk(k4));
if (k5) printf("%c", tk(k5));
printf(" %s\n", tt);
}
unlink("cj.tmp1");
exit(0);
}

Generated by  Doxygen 1.6.0   Back to index