home *** CD-ROM | disk | FTP | other *** search
- /* cedit2gb - Convert CEDIT to GB coding */
-
- #include <stdio.h>
- #include <string.h>
-
- void main(int i, char **argv)
- {
- char ch, ch1; /* first and second character */
- int index; /* index of Chinese char */
- FILE *fi, *fo; /* infile and outfile */
-
- if(i < 2) {
- printf("Convert CEDIT21, CEDIT20, CEDIT10 files to CEDIT22 (GB) file\n\n");
- printf("Usage: %s file\n\n", argv[0]);
- printf("New file will have extension GB and overwrite existing one\n\n");
- return;
- }
-
- if((fi=fopen(argv[1], "r")) == 0) return; /* ok */
- strcpy(strchr(argv[1], '.'), ".GB");
- if((fo=fopen(argv[1], "w")) == 0) return;
- while((ch = fgetc(fi)) != EOF) {
- if(ch >= 0)
- fputc(ch, fo); /* not Chinese */
- else {
- ch1 = fgetc(fi);
- index = (ch&0x7f) | ((ch1&0x3f)<<7); /* old index */
- fputc((index/94)+0xA9, fo); /* recode */
- fputc((index%94)+0xA1, fo);
- }
- }
- fcloseall();
- }