#include <stdio.h>

/*
 * Russian (KOI-8) to English (ASCII) translator.
 * Acts as a filter.
 * If started `rtol c' translates KOI-8 with 8th bit cut.
 */

char *rtol[] = {
"yu", "a",  "b", "c",  "d", "e",   "f",  "g",
"h",  "i",  "i", "k",  "l", "m",   "n",  "o",
"p",  "ya", "r", "s",  "t", "u",   "zh", "v",
"'",  "y",  "z", "sh", "e", "sch", "ch", "`"
};

char *RtoL[] = {
"YU", "A",  "B", "C",  "D", "E",   "F",  "G",
"H",  "I",  "I", "K",  "L", "M",   "N",  "O",
"P",  "YA", "R", "S",  "T", "U",   "ZH", "V",
"'",  "Y",  "Z", "SH", "E", "SCH", "CH", "`"
};

main(argc, argv) int argc; char *argv[]; {
  int c;
  int conv = (argc>=1 && argv[1][0]=='c' ? 1 : 0);
  while((c=getchar())!=EOF) {
    if(c>=0x80+'@' && c<=0x80+'_') {
      printf(rtol[c-0x80-'@']);
    } else if(c>=0x80+'`' && c<=0x80+0x7f) {
      printf(RtoL[c-0x80-'`']);
    } else if(conv && c>='@' && c<='_') {
      printf(rtol[c-'@']);
    } else if(conv && c>='`' && c<=0x7f) {
      printf(RtoL[c-'`']);
    } else {
      putchar(c);
    }
  }
}
