/******************************************/ /* Boshiamy Input System Example Program */ /* Date: July 20, 1993 */ /* File name: LIUBIG5.C */ /* Complier Model: Large */ /******************************************/ #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <io.h> #define MAXLEN 5 void decoder(unsigned char,unsigned char); main() { unsigned int far *index; unsigned char far *table, *index_p; int done,input_length,count; long table_size,file_size,i; unsigned int input_buffer[MAXLEN],offset,head,tail,last2,code2; char ch; FILE *fp; clrscr(); if((fp=fopen("liubig5.tab","rb"))==NULL){ puts("liubig5.tab not found"); return 0; } file_size=filelength(fileno(fp)); table_size=file_size-2050; printf("2050 bytes for index table\n"); printf("%ld bytes for data table\n",table_size); printf("%ld words total\n",table_size/3); printf("ESC to clear input buffer or quit\n"); if ((index_p = (char *) malloc(2050))== NULL){ puts("Not enough memory when alloc index"); fclose(fp); return 0; } if ((table = (char *) malloc(table_size))==NULL){ puts("Not enough memory when alloc table"); free(index_p); fclose(fp); return 0; } fread(index_p,1,2050,fp); fread(table,1,table_size,fp); fclose(fp); index=(unsigned int *) index_p; /**********************************[This while roop is input control]****/ while(1){ printf("Input : "); i=0; while(1){ ch=getch(); if(ch==' '){ if(i>0) break; else continue; } else if(ch==27){ /* ESC*/ if(i==0){ free(index_p); free(table); return 0; } else{ for(;i>0;i--){ putch('\b'); putch(' '); putch('\b'); } continue; } } else if(ch==8){ /* BACKSPACE */ if(i>0){ putch(ch); putch(' '); putch(ch); i--; continue; } else continue; } else if(i>=MAXLEN) /* The maximum input char is 5 */ continue; else if(ch>='a' && ch<='z'){ ch=ch-'a'+'A'; input_buffer[i]=ch-'A'+1; } else if(ch>='A' && ch<='Z') input_buffer[i]=ch-'A'+1; else if(ch==',') input_buffer[i]=27; else if(ch=='.') input_buffer[i]=28; else if(ch=='\'') input_buffer[i]=29; else if(ch=='[') input_buffer[i]=30; else if(ch==']') input_buffer[i]=31; else{ continue; } putch(ch); i++; } input_length=i; /***************************************[fill the rest input as 0 ]****/ while(i<MAXLEN){ input_buffer[i]=0; i++; } /************************************************[Boshiamy Kernel]*****/ offset=(unsigned int) input_buffer[0]*32+input_buffer[1]; last2 =(unsigned int) input_buffer[2]*32+input_buffer[3]; head=index[offset]; tail=index[offset+1]; i=head; count=0; if(input_length==MAXLEN) /* if input_length is 5, then do nothing */ i=tail; while(i<tail){ code2=(unsigned int) table[i]*4+table[i+1]/64; if(last2==code2){ count++; decoder(table[i+1],table[i+2]); } i=i+3; } if(count==0){ if(input_length>=3 && input_buffer[input_length-1]!=22) printf(" not found"); else{ input_buffer[input_length-1]=0; /* kill the V and find again */ last2 =(unsigned int) input_buffer[2]*32+input_buffer[3]; i=head; while(i<tail){ code2=(unsigned int) table[i]*4+table[i+1]/64; if(last2==code2){ count++; if(count==2){ /* the word we want is the 2nd word */ decoder(table[i+1],table[i+2]); break; } } i=i+3; } if(count<2) printf(" not found "); } } printf("\n"); } } void decoder(ch1,ch2) unsigned char ch1,ch2; { unsigned char high_byte,low_byte; unsigned int code; code =(unsigned int) (ch1 & 0x3F)*256+ch2; high_byte= code/157+0xA1; low_byte = code%157; if(low_byte<63) low_byte=low_byte+0x40; else low_byte=low_byte-63+0xA1; printf(" %c%c",high_byte,low_byte); }
|