/**  recode.c  **/

/*
 * Text recoder (Koi8<->Alternative<->Windows<->ISO).
 * And from HEX-style ("=EF=F0") to normal,
 * and from HTML-style ("&...;") to normal.
 *
 * Made by Serge Bajin (bsv@cntc.dubna.su).
 *
 * some adds by lavr
 *
 * compilation: gcc -s -o recode recode.c
 *
 * Last revision - 13/08/96 20:39:14.
 */

/*#define MSDOS*/

#include <stdio.h>

#ifdef MSDOS

#   include <stdlib.h>
#   include <string.h>

int from_hex_to_char(char *shex), range_ok(char c);
void usage(char *name), do_output(char *str, int l);
void kawi_recode(void), hex_recode(void), html_recode(void), kbr_recode(void), kbe_recode(void);

#else

int from_hex_to_char(), range_ok();
void usage(), do_output(), kawi_recode(), hex_recode(), html_recode();
void kbr_recode(), kbe_recode(), kb_recode(int kb);

#endif

typedef unsigned char uchar;

struct rec {
           char *sht;
           uchar cht;
           };

struct rec rec_rec[] = {"&#128;",   128, "&#129;",   129, "&#130;",   130,
                        "&#131;",   131, "&#132;",   132, "&#134;",   134,
                        "&#135;",   135, "&#136;",   136, "&#137;",   137,
                        "&#138;",   138, "&#139;",   139, "&#140;",   140,
                        "&#141;",   141, "&#142;",   142, "&#143;",   143,
                        "&#144;",   144, "&#152;",   152, "&#154;",   154,
                        "&#155;",   155, "&#156;",   156, "&#157;",   157,
                        "&#158;",   158, "&#159;",   159, "&#161;",   161,
                        "&#162;",   162, "&#163;",   163, "&#164;",   164,
                        "&#165;",   165, "&#166;",   166, "&#167;",   167,
                        "&#168;",   168, "&#170;",   170, "&#171;",   171,
                        "&#172;",   172, "&#173;",   173, "&#175;",   175,
                        "&#176;",   176, "&#177;",   177, "&#178;",   178,
                        "&#179;",   179, "&#180;",   180, "&#181;",   181,
                        "&#182;",   182, "&#183;",   183, "&#184;",   184,
                        "&#185;",   185, "&#186;",   186, "&#187;",   187,
                        "&#191;",   191, "&Agrave;", 192, "&Aacute;", 193,
                        "&Acirc;",  194, "&Atilde;", 195, "&Auml;",   196,
                        "&Aring;",  197, "&AElig;",  198, "&Ccedil;", 199,
                        "&Egrave;", 200, "&Eacute;", 201, "&Ecirc;",  202,
                        "&Euml;",   203, "&Igrave;", 204, "&Iacute;", 205,
                        "&Icirc;",  206, "&Iuml;",   207, "&ETH;",    208,
                        "&Ntilde;", 209, "&Ograve;", 210, "&Oacute;", 211,
                        "&Ocirc;",  212, "&Otilde;", 213, "&Ouml;",   214,
                        "&#215;",   215, "&Oslash;", 216, "&Ugrave;", 217,
                        "&Uacute;", 218, "&Ucirc;",  219, "&Uuml;",   220,
                        "&Yacute;", 221, "&THORN;",  222, "&szlig;",  223,
                        "&agrave;", 224, "&aacute;", 225, "&acirc;",  226,
                        "&atilde;", 227, "&auml;",   228, "&aring;",  229,
                        "&aelig;",  230, "&ccedil;", 231, "&egrave;", 232,
                        "&eacute;", 233, "&ecirc;",  234, "&euml;",   235,
                        "&igrave;", 236, "&iacute;", 237, "&icirc;",  238,
                        "&iuml;",   239, "&eth;",    240, "&ntilde;", 241,
                        "&ograve;", 242, "&oacute;", 243, "&ocirc;",  244,
                        "&otilde;", 245, "&ouml;",   246, "&#247;",   247,
                        "&oslash;", 248, "&ugrave;", 249, "&uacute;", 250,
                        "&ucirc;",  251, "&uuml;",   252, "&yacute;", 253,
                        "&thorn;",  254, "&yuml;",   255, NULL,         0};

uchar ai[] = {176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
              192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
              208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
              136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,
              152,153,154,129,156,157,158,159,160,161,162,163,164,165,166,167,
              168,169,170,171,172,173,174,175,240,241,242,243,244,245,246,247,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
              130,132,135,134,128,133,131,155,248,249,250,251,252,253,254,255};

uchar ak[] = {225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
              242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
              193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
              136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,
              152,153,154,129,156,157,158,159,160,161,162,163,164,165,166,167,
              168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,
              210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
              130,132,135,134,128,133,131,155,184,185,186,187,188,189,190,191};

uchar aw[] = {192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
              208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
              136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,
              152,153,154,129,156,157,158,159,160,161,162,163,164,165,166,167,
              168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,
              240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
              130,132,135,134,128,133,131,155,184,185,186,187,188,189,190,191};

uchar ia[] = {244,195,240,246,241,245,243,242,176,177,178,179,180,181,182,183,
              184,185,186,187,188,189,190,191,192,193,194,247,196,197,198,199,
              200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
              128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
              216,217,218,219,220,221,222,223,248,249,250,251,252,253,254,255};

uchar ik[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
              225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
              242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
              193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
              210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
              176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191};

uchar iw[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
              192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
              208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
              240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
              176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191};

uchar ka[] = {244,195,240,246,241,245,243,242,176,177,178,179,180,181,182,183,
              184,185,186,187,188,189,190,191,192,193,194,247,196,197,198,199,
              200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
              216,217,218,219,220,221,222,223,248,249,250,251,252,253,254,255,
              238,160,161,230,164,165,228,163,229,168,169,170,171,172,173,174,
              175,239,224,225,226,227,166,162,236,235,167,232,237,233,231,234,
              158,128,129,150,132,133,148,131,149,136,137,138,139,140,141,142,
              143,159,144,145,146,147,134,130,156,155,135,152,157,153,151,154};

uchar ki[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
              240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
              238,208,209,230,212,213,228,211,229,216,217,218,219,220,221,222,
              223,239,224,225,226,227,214,210,236,235,215,232,237,233,231,234,
              206,176,177,198,180,181,196,179,197,184,185,186,187,188,189,190,
              191,207,192,193,194,195,182,178,204,203,183,200,205,201,199,202};

uchar kw[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
              176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
              254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238,
              239,255,240,241,242,243,230,226,252,251,231,248,253,249,247,250,
              222,192,193,214,196,197,212,195,213,200,201,202,203,204,205,206,
              207,223,208,209,210,211,198,194,220,219,199,216,221,217,215,218};

uchar wa[] = {244,195,240,246,241,245,243,242,176,177,178,179,180,181,182,183,
              184,185,186,187,188,189,190,191,192,193,194,247,196,197,198,199,
              200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
              216,217,218,219,220,221,222,223,248,249,250,251,252,253,254,255,
              128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239};

uchar wi[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
              240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
              176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
              192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
              208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
              224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239};

uchar wk[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
              160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
              176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
              225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
              242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
              193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
              210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209};

/* Russian keyboard */
uchar r[]= {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
            25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,
            47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,
            69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,
            91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,
           110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,
           127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
           144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,
           161,162,96,164,165,166,167,168,169,170,171,172,173,174,175,176,177,
           178,126,180,181,182,183,184,185,186,187,188,189,190,191,46,102,44,
           119,108,116,97,117,91,98,113,114,107,118,121,106,103,122,104,99,110,
           101,59,100,109,115,112,105,39,111,120,93,62,70,60,87,76,84,65,85,123,
            66,81,82,75,86,89,74,71,90,72,67,78,69,58,68,77,83,80,73,34,79,88,
           125};

/* English keyboard */
uchar e[]= {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,
            26,27,28,29,30,31,32,33,252,35,36,37,38,220,40,41,42,43,194,45,192,
            47,48,49,50,51,52,53,54,55,56,57,246,214,226,61,224,63,64,230,233,
            243,247,245,225,240,242,251,239,236,228,248,244,253,250,234,235,249,
            229,231,237,227,254,238,241,200,92,223,94,95,163,198,201,211,215,
            213,193,208,210,219,207,204,196,216,212,221,218,202,203,217,197,199,
            205,195,222,206,209,232,124,255,179,127,128,129,130,131,132,133,134,
            135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,
            152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,
            169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,
            186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,
            203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,
            220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,
            237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,
            254,255};

char translit[64][4] = {"A","B","V","G","D","E","ZH","Z","I","J","K","L","M",
                        "N","O","P","R","S","T","U","F","H","C","CH","SH","SCH",
                        "'","Y","'","E","YU","YA",
                        "a","b","v","g","d","e","zh","z","i","j","k","l","m","n",
                        "o","p","r","s","t","u","f","h","c","ch","sh","sch",
                        "'","y","'","e","yu","ya"};

FILE *in, *out;
uchar *table, *ttab;
int hex;

/**********************************************************/
main(argc, argv)
char **argv;
int argc;
{
char temp[1024];
int i;
int convert = 1;                    /* should conversion to be performed? */
int toT = 0;                        /* Should translitiration be performed? */

int ke = 0;                       /* keyboard to English */
int kr = 0;                       /* keyboard to Russian */
int kbd = 0;

if(argc < 2 || argc > 4)
   usage(argv[0]);
table = NULL;
hex = 0;
if(!strcmp(argv[1], "-ai"))
   table = ai;
else if(!strcmp(argv[1], "-ak"))
   table = ak;
else if(!strcmp(argv[1], "-aw"))
   table = aw;
else if(!strcmp(argv[1], "-ia"))
   table = ia;
else if(!strcmp(argv[1], "-ik"))
   table = ik;
else if(!strcmp(argv[1], "-iw"))
   table = iw;
else if(!strcmp(argv[1], "-ka"))
   table = ka;
else if(!strcmp(argv[1], "-ki"))
   table = ki;
else if(!strcmp(argv[1], "-kw"))
   table = kw;
else if(!strcmp(argv[1], "-wa"))
   table = wa;
else if(!strcmp(argv[1], "-wi"))
   table = wi;
else if(!strcmp(argv[1], "-wk"))
   table = wk;
else if(!strcmp(argv[1], "-at"))
   { toT = 1; table = aw; }
else if(!strcmp(argv[1], "-it"))
   { toT = 1; table = iw; }
else if(!strcmp(argv[1], "-kt"))
   { toT = 1; table = kw; }
else if(!strcmp(argv[1], "-wt"))
   { toT = 1; convert=0; }
else if(!strcmp(argv[1], "-hex"))
   hex = 1;
else if(!strcmp(argv[1], "-ke"))
   { kbd = 1; ttab = r; ke = 1; }
else if(!strcmp(argv[1], "-kr"))
   { kbd = 1; ttab = e; kr = 1; }
else if(strcmp(argv[1], "-html"))
   usage(argv[0]);
in = NULL;
out = NULL;
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 == NULL)
      in = fopen(argv[2], "r");
   if(in == NULL)
      {
      printf("%s: cannot open input file '%s'.\n", argv[0], argv[2]);
      exit(1);
      }
   if(out == NULL)
      {
      if(argc == 3)
         strcpy(temp, (char *) mkstemp(NULL));
      else
         strcpy(temp, argv[3]);
      out = fopen(temp, "w");
      if(out == NULL)
         {
         printf("%s: cannot open %s file '%s'.\n", argv[0],
                ((argc == 3) ? "temporary" : "output"), temp);
         fclose(in);
         exit(1);
         }
      }
   }
if(in == NULL)
   {
   printf("%s: cannot open standard input.\n", argv[0]);
   exit(1);
   }
if(out == NULL)
   {
   printf("%s: cannot open standard output.\n", argv[0]);
   fclose(in);
   exit(1);
   }
if(table != NULL)
/*
   kawi_recode();
*/
while((i = getc(in)) != -1)
{
  i &= 0xFF;                    /* i &= 255 (convert to CHAR)*/
    if(i & 0x80)                /* i & 128 (is EXTENDED ASCII ?)*/
      {
        if (convert)     /*should conversion to another CP be performed?*/
           i = table[i & 0x7F];  /*assign the value from the table [i & 127]*/
          if (toT)                /*convert to translitirate?*/
            {   /*assumption is that 'i' already in WinCP1251 */
              if (i >= 192)
                fputs(translit[i-192], out);
              else if (i == 168)  
                fputs("YO", out);
              else if (i == 184)
                fputs("yo", out);
              else
                putc(i, out);
            }
          else
            putc(i, out);
      }
    else
      putc(i, out);                /*write out char*/
}

else if(hex)
   hex_recode();
else if(kr)
   kb_recode(kbd);
else if(ke)
   kb_recode(kbd);
else 
   html_recode();
fclose(in);
fclose(out);
if(argc == 3 && strcmp(argv[2], "-"))
   {
   in = fopen(temp, "r");
   if(in == NULL)
      {
      printf("%s: cannot open temporary file.\n", argv[0]);
      unlink(temp);
      exit(1);
      }
   out = fopen(argv[2], "w");
   if(out == NULL)
      {
      printf("%s: cannot open output file. See \"%s\"\n", argv[0], temp);
      fclose(in);
      exit(1);
      }
   while((i = fgetc(in)) != -1)
      fputc(i, out);
   fclose(in);
   fclose(out);
   unlink(temp);
   }
}

/**********************************************************/
void kb_recode(kb)
int kb;
{
  int i;

  while((i = fgetc(in)) != -1)
    {
      i &= 0xFF;

      if(ttab == e)
        i = ttab[i];
      else
        i = ttab[i];
      fputc(i, out);
    }
}

/**********************************************************/
void kawi_recode()
{
int i;
while((i = fgetc(in)) != -1)
   {
   i &= 0377;
   if(i & 0200)
      i = table[i & 0177];
   fputc(i, out);
   }
}

/**********************************************************/
void hex_recode()
{
char pat[5];
int c, l;
c = 0;
l = 0;
for(;;)
   {
   if(c != -1)
      c = fgetc(in);
   if(c == -1)
      {
      if(l)
         do_output(pat, l);
      break;
      }
   c &= 0377;
   switch(c)
      {
      case '=':
         if(l)
            do_output(pat, l);
         l = 1;
         pat[0] = c;
         break;
      case '?':
         if(l)
            do_output(pat, l);
         c = fgetc(in);
         if(c != '=')
            {
            fputc('?', out);
            if(c != -1)
               fputc(c, out);
            }
         else
            {
            c = fgetc(in);
            if(range_ok(c))
               {
               pat[0] = c;
               c = fgetc(in);
               if(range_ok(c))
                  {
                  pat[1] = c;
                  fputc('?', out);
                  fputc(from_hex_to_char(pat), out);
                  }
               else
                  {
                  fputc(pat[0], out);
                  if(c != -1)
                     fputc(c, out);
                  }
               }
            else if(c != -1)
               fputc(c, out);
            }
         l = 0;
         break;
      case '\n':
         if(l != 1)
            {
            do_output(pat, l);
            fputc(c, out);
            }
         l = 0;
         break;
      default:
         if(!l)
            {
            fputc(c, out);
            break;
            }
         pat[l++] = c;
         if(l == 3)
            {
            if(range_ok(pat[1]) && range_ok(pat[2]))
               fputc(from_hex_to_char(&pat[1]), out);
            else
               do_output(pat, l);
            l = 0;
            }
         break;
      }
   }
}

/**********************************************************/
void html_recode()
{
struct rec *tr;
char *pat;
int l, max_seq_length, c;
max_seq_length = 0;
for(tr = rec_rec; tr->sht != NULL; tr++)
   {
   l = strlen(tr->sht);
   if(l > max_seq_length)
      max_seq_length = l;
   }
pat = (char *) malloc(max_seq_length + 1);
l = 0;
for(;;)
   {
   c = fgetc(in);
   if(c == -1)
      {
      if(l)
         do_output(pat, l);
      break;
      }
   c &= 0377;
   switch(c)
      {
      case '&':
         if(l)
            do_output(pat, l);
         l = 1;
         pat[0] = c;
         break;
      case ';':
         if(!l)
            {
            fputc(c, out);
            break;
            }
         pat[l++] = c;
         pat[l] = 0;
         for(tr = rec_rec; tr->sht != NULL; tr++)
            if(!strcmp(tr->sht, pat))
               {
               fputc(tr->cht, out);
               break;
               }
         if(tr->sht == NULL)
            do_output(pat, l);
         l = 0;
         break;
      default:
         if(!l)
            {
            fputc(c, out);
            break;
            }
         pat[l++] = c;
         if(l == max_seq_length)
            {
            do_output(pat, l);
            l = 0;
            }
         break;
      }
   }
}

/**********************************************************/
void do_output(str, l)
char *str;
int l;
{
int i;
for(i = 0; i < l; i++)
   fputc(str[i], out);
}

/**********************************************************/
int from_hex_to_char(shex)
char *shex;
{
int i;
i = (((shex[0] & ~0160) + (shex[0] >> 6) * 9) << 4) +
     ((shex[1] & ~0160) + (shex[1] >> 6) * 9);
return(i);
}

/**********************************************************/
int range_ok(c)
char c;
{
if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
   return(1);
return(0);
}

/**********************************************************/
void usage(name)
char *name;
{
fprintf(stderr, "Usage: %s ", name);
fprintf(stderr, " -{ai|ak|aw|ia|ik|iw|ka|ki|kw|wa|wi|wk|at|it|kt|wt|kr|ke|hex|html} ");
fprintf(stderr, "[input_file [output_file]]\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, "       -at         - from Alternative to Transliterate,\n");
fprintf(stderr, "       -it         - from ISO to Transliterate,\n");
fprintf(stderr, "       -kt         - from Koi8 to Transliterate,\n");
fprintf(stderr, "       -wt         - from Windows to Transliterate,\n");  
fprintf(stderr, "       -kr         - from Keyboard: Latin to Cyrillic, from \"QwErtY\" -> \"êÃõËÅî\"\n");
fprintf(stderr, "       -ke         - from Keyboard: Cyrillic to Latin, from \"æÙ÷ÁÐò\" -> \"AsDfgH\"\n");
fprintf(stderr, "       -hex        - from HEX-style (\"=EF=F0\") to Normal;\n");
fprintf(stderr, "       -html       - from HTML-style (\"&...;\") to Normal;\n");
fprintf(stderr, "       input_file  - name of input file, ");
fprintf(stderr, "may be \"-\" as standard input;\n");
fprintf(stderr, "       output_file - name of output file, ");
fprintf(stderr, "may be \"-\" as standard output.\n");
exit(1);
}
