home *** CD-ROM | disk | FTP | other *** search
/ Languages Around the World / LanguageWorld.iso / translat / babylon / cedit2gb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-20  |  950 b   |  34 lines

  1. /* cedit2gb - Convert CEDIT to GB coding */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. void main(int i, char **argv)
  7. {
  8.   char ch, ch1;     /* first and second character */
  9.   int  index;        /* index of Chinese char */
  10.   FILE *fi, *fo;    /* infile and outfile */
  11.  
  12.   if(i < 2) {
  13.     printf("Convert CEDIT21, CEDIT20, CEDIT10 files to CEDIT22 (GB) file\n\n");
  14.     printf("Usage: %s file\n\n", argv[0]);
  15.     printf("New file will have extension GB and overwrite existing one\n\n");
  16.     return;
  17.   }
  18.  
  19.   if((fi=fopen(argv[1], "r")) == 0) return;        /* ok */
  20.   strcpy(strchr(argv[1], '.'), ".GB");
  21.   if((fo=fopen(argv[1], "w")) == 0) return;
  22.   while((ch = fgetc(fi)) != EOF) {
  23.     if(ch >= 0)
  24.       fputc(ch, fo);            /* not Chinese */
  25.     else {
  26.       ch1 = fgetc(fi);
  27.       index = (ch&0x7f) | ((ch1&0x3f)<<7);    /* old index */
  28.       fputc((index/94)+0xA9, fo);        /* recode */
  29.       fputc((index%94)+0xA1, fo);
  30.     }
  31.   }
  32.   fcloseall();
  33. }
  34.