#include /* * Cyrillic KOI-8 to AMS TeX cyrillic translator. * Acts as a filter. * * After you apply r2tex to the source KOI-8 file, you will need to LaTeX it. * Several style files are used: cyrillic.sty, cyracc.def, fullpage.sty. * You can find them in the FTP directory ams_cyrillic_style. */ char *ltot[] = { " j2", " a", " b", "_c", "_d", "_e", " f", " g", " h", "_i", " \\u\\i ","_k", "_l", " m", "_n", " o", "_p", " j1", " r", "_s", "_t", " u", " zh", " v", " \\cprime ","_y", "_z", " x", " \\`e", " w", " q", " \\cdprime ", " J2", " A", " B", "_C", "_D", "_E", " F", " G", " H", "_I", " \\u I", "_K", "_L", " M", "_N", " O", "_P", " J1", " R", "_S", "_T", " U", " Zh", " V", " \\Cprime ","_Y", "_Z", " X", " \\`E", " W", " Q", " \\Cdprime " }; void PrintLetter(s) char *s; { fputs(s+1, stdout); if(*s!=' ') fputs("\\cydot ", stdout); } main(argc, argv) int argc; char *argv[]; { int c, cc, i; int cyr = 0; int fill = 0; int nohyphen = 0; int bs_newpage = 0; int skip_at_top = 0; int cprev = '\n'; printf("\\documentstyle[fullpage,cyrillic]{article}\n\\begin{document}\n"); printf("\\setlength{\\parskip}{0.3em}\n"); printf("\\bf\n"); for(i=1; i formfeed */ bs_newpage = 1; break; default: fprintf(stderr, "Wrong option: %s\n", p); exit(1); } } else { fprintf(stderr, "No file name allowed: %s\n", p); exit(1); } } fprintf(stderr, "=== Options are ===\n"); fprintf(stderr, "Fill Paragraphs = %d\n", fill); fprintf(stderr, "Delete Hyphenation = %d\n", nohyphen); fprintf(stderr, "\\ at line beg. to FormFeed = %d\n", bs_newpage); while((c=getchar())!=EOF) { if(c>=0x80+'@' && c<=0x80+0x7f) { if(!cyr) { printf("{\\cyr "); cyr=1; } PrintLetter(ltot[c-'@'-0x80]); } else if(c=='.' || c==',' || c=='\"' || c=='?' || c=='!' || c==':' || c=='(' || c==')' || c=='-' || (c>='0' && c<='9')) { if(nohyphen && fill && c=='-') { cc=getchar(); if(cc=='\n') { } else { ungetc(cc, stdin); if(cprev!='-') printf("--"); else printf("-"); } } else { putchar(c); } } else if(c==' ') { if(cprev=='\n') { putchar('\n'); } if((fill && cprev==' ') || cprev=='.' || cprev==',' || cprev=='?' || cprev=='!') { putchar(' '); } else { fputs("\\ ", stdout); } } else if(c=='\n') { if(fill && (cprev=='.' || cprev=='?' || cprev=='!' || cprev=='"')) { fputs("\n", stdout); } else if(fill && cprev!='\n') { fputs("\\ \n", stdout); } else if(cprev=='.' || cprev=='?' || cprev=='!') { fputs("\\\\\n", stdout); } else { fputs("\\ \\\\\n", stdout); } } else if(c=='\r') { } else { if(cyr) { printf("}"); cyr = 0; } switch(c) { case '#': case '$': case '%': case '&': case '_': case '{': case '}': printf("\\%c", c); break; case '\f': case 'Z'-0x40: printf("\\newpage\n"); break; case '\\': if(bs_newpage && cprev=='\n') { printf("\\newpage\n"); break; } case '~': case '^': printf("\\verb+%c+", c); break; case '+': case '=': case '|': case '<': case '>': printf("$%c$", c); break; default: putchar(c); break; } } cprev = c; } if(cyr) { printf("}"); cyr = 0; } printf("\n\\end{document}\n"); }