/*(C) vvv@vvv.vsu.ru; (C) E.S.Cymbalyuk 2000, Under GNU GPL, No Warranty. Программа перекодирует словарь в любую русскую кодировку с сохранением неизменной транскрипции в квадратных скобочках и буквы "ё"*/ #include #include #include #include #include #define G(x) x=getc(in) char cp1251[]={'\300','\301','\302','\303','\304','\305','\306','\307','\310','\311','\312','\313','\314','\315','\316','\317','\320','\321','\322','\323','\324','\325','\326','\327','\330','\331','\332','\333','\334','\335','\336','\337','\340','\341','\342','\343','\344','\345','\346','\347','\350','\351','\352','\353','\354','\355','\356','\357','\360','\361','\362','\363','\364','\365','\366','\367','\370','\371','\372','\373','\374','\375','\376','\377','\250','\270'}; char koi8r[]={'\341','\342','\367','\347','\344','\345','\366','\372','\351','\352','\353','\354','\355','\356','\357','\360','\362','\363','\364','\365','\346','\350','\343','\376','\373','\375','\377','\371','\370','\374','\340','\361','\301','\302','\327','\307','\304','\305','\326','\332','\311','\312','\313','\314','\315','\316','\317','\320','\322','\323','\324','\325','\306','\310','\303','\336','\333','\335','\337','\331','\330','\334','\300','\321','\263','\243'}; char cp866[]={'\200','\201','\202','\203','\204','\205','\206','\207','\210','\211','\212','\213','\214','\215','\216','\217','\220','\221','\222','\223','\224','\225','\226','\227','\230','\231','\232','\233','\234','\235','\236','\237','\240','\241','\242','\243','\244','\245','\246','\247','\250','\251','\252','\253','\254','\255','\256','\257','\340','\341','\342','\343','\344','\345','\346','\347','\350','\351','\352','\353','\354','\355','\356','\357','\360','\361'}; char iso88595[]={'\260','\261','\262','\263','\264','\265','\266','\267','\270','\271','\272','\273','\274','\275','\276','\277','\300','\301','\302','\303','\304','\305','\306','\307','\310','\311','\312','\313','\314','\315','\316','\317','\320','\321','\322','\323','\324','\325','\326','\327','\330','\331','\332','\333','\334','\335','\336','\337','\340','\341','\342','\343','\344','\345','\346','\347','\350','\351','\352','\353','\354','\355','\356','\357','\241','\361'}; main(argc, argv) char **argv; int argc; { FILE *in, *out; struct stat buf; char *table_from, *table_to; char temp[1024]; int count,a; char r; count=0; if(argc < 2 || argc > 4) usage(argv[0]); if(!strcmp(argv[1], "-ai")){ table_from = cp866; table_to = iso88595;} else if(!strcmp(argv[1], "-ak")){ table_from = cp866; table_to = koi8r;} else if(!strcmp(argv[1], "-aw")){ table_from = cp866; table_to = cp1251;} else if(!strcmp(argv[1], "-ia")){ table_from = iso88595; table_to = cp866;} else if(!strcmp(argv[1], "-ik")){ table_from = iso88595; table_to = koi8r;} else if(!strcmp(argv[1], "-iw")){ table_from = iso88595; table_to = cp1251;} else if(!strcmp(argv[1], "-ka")){ table_from = koi8r; table_to = cp866;} else if(!strcmp(argv[1], "-ki")){ table_from = koi8r; table_to = iso88595;} else if(!strcmp(argv[1], "-kw")){ table_from = koi8r; table_to = cp1251;} else if(!strcmp(argv[1], "-wa")){ table_from = cp1251; table_to = cp866;} else if(!strcmp(argv[1], "-wi")){ table_from = cp1251; table_to = iso88595;} else if(!strcmp(argv[1], "-wk")){ table_from = cp1251; table_to = koi8r;} else usage(argv[0]); in = 0; out = 0; if(argc == 2 || (argc == 3 && !strcmp(argv[2], "-"))) { in = stdin; out = stdout; } else if(argc == 4) { if(!strcmp(argv[2], "-")) in = stdin; if(!strcmp(argv[3], "-")) out = stdout; } if(argc > 2) { if(!in) { if(stat(argv[2], &buf) < 0) { printf("%s: cannot open input file '%s'.\n", argv[0], argv[2]); exit(1); } in = fopen(argv[2], "r"); if(!in) { printf("%s: cannot open input file '%s'.\n", argv[0], argv[2]); exit(1); } } if(!out) { if(argc == 3) sprintf(temp, "%s.%d", argv[0], getpid()); else strcpy(temp, argv[3]); out = fopen(temp, "w"); if(!out) { printf("%s: cannot open %s file '%s'.\n", argv[0], ((argc == 3) ? "temporary" : "output"), temp); fclose(in); exit(1); } } } if(!in) { printf("%s: cannot open standard input.\n", argv[0]); exit(1); } if(!out) { printf("%s: cannot open standard output.\n", argv[0]); fclose(in); exit(1); } while((G(r)) != EOF) { if (r==']' && count==0) fprintf(stderr, "!!!"); if (r==']' && count==1) { count=0; } if (count==0){ for(a=0;a<66;a++) if (r==table_from[a]){ putc(table_to[a], out); a=67;} if (a==66) putc(r, out); } if (count==1){ putc(r, out); } if (r=='[') { count = 1; } } fclose(in); fclose(out); if(argc == 3 && strcmp(argv[2], "-")) { unlink(argv[2]); link(temp, argv[2]); unlink(temp); } } /**********************************************************/ usage(name) char *name; { fprintf(stderr, "Usage: %s -{ai|ak|aw|ia|ik|iw|ka|ki|kw|wa|wi|wk} ", name); fprintf(stderr, "[input_dictionary [output_dictionary]\n Parameters are:\n"); fprintf(stderr, " -ai - from Alternative to ISO,\n"); fprintf(stderr, " -ak - from Alternative to Koi8,\n"); fprintf(stderr, " -aw - from Alternative to Windows,\n"); fprintf(stderr, " -ia - from ISO to Alternative,\n"); fprintf(stderr, " -ik - from ISO to Koi8,\n"); fprintf(stderr, " -iw - from ISO to Windows,\n"); fprintf(stderr, " -ka - from Koi8 to Alternative,\n"); fprintf(stderr, " -ki - from Koi8 to ISO,\n"); fprintf(stderr, " -kw - from Koi8 to Windows,\n"); fprintf(stderr, " -wa - from Windows to Alternative,\n"); fprintf(stderr, " -wi - from Windows to ISO;\n"); fprintf(stderr, " -wk - from Windows to Koi8;\n"); fprintf(stderr, " input_dictionary - name of input dictionary, "); fprintf(stderr, "may be \"-\" as standard input;\n"); fprintf(stderr, " output_dictionary - name of output dictionary, "); fprintf(stderr, "may be \"-\" as standard output.\n"); exit(1); }