/*
	ReCoder.h	Recodes different Russian tables:
			ASCII(a,b), MIC, KOI-8, KOI-7, ISO-8859-5
			and different new line symbols:
			CR+LF <-> CR.

	NOTE:		If you want to translate from
			SRC-code to DST-code, you may use
			tr/<DST-table>/<SRC-table>/;
			Note, that tables are swapped.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifndef	BYTE_DEF
typedef unsigned char	BYTE;
#define BYTE_DEF
#endif

#define QUESTION	(BYTE)'?'
#define CONTROL_Z	(BYTE)26

#define	ASCII_128	(BYTE)''
#define	ASCII_32	(BYTE)' '
#define	ASCII_64	(BYTE)'@'


#if defined (_MSDOS_) || defined (_MS_DOS_) || defined (__MSDOS__)
  #ifndef __MSDOS__
    #define __MSDOS__
  #endif
#else
  #ifndef __UNIX__
    #define __UNIX__
  #endif
#endif

#ifdef __UNIX__
	#define STRCMP	strcmp
	#define	stdhelp	stderr
#else
	#define STRCMP	stricmp
	#define	stdhelp	stdout
#endif

#ifndef stricmp
#define stricmp strcmp
#endif

#define	ERROR(s)	fprintf(stderr,"%s: %s\n",argv[0],s),exit(1)
#define	ERROR2(s,t)	fprintf(stderr,"%s: %s %s\n",argv[0],s,t),exit(1)



const char HELPTEXT[]       =
   "\n"
   "Written by Alexey Roytman.\n"
   "Version 2.0\n"
   "Last modified: Apr  1 1998\n"
   "\n"
   "Recodes different Russian code tables and\n"
   "UNIX/DOS new line codes ('\\n'<->'\\r'+'\\n')\n"
   "         and \"end-of-file\" symbols (''<->'^Z')\n\n"

   "Usage:\n"
   "\tReCoder [options] [infile [outfile]]\n"
   "\t\twhere 'infile' and 'outfile' are filenames or devicenames,\n"
   "\t\tor '--' for standart input-output device\n\n"

   "or\n"
   "\tReCoder [options] [ < instream] [ > outstream]\n"
   "\t\twhere 'instream' and 'outstream' are filenames or devicenames.\n\n"

   "'options' -- either sequence or one of the following types:\n"
   "\n"
   "\t-help\t-- this help\n"
   "\n"
   "\t-<FROMletter>2<TOletter>\n"
   "\t\twhere <FROMletter> and <TOletter> are both from the set:\n"
   "\t\ta\t-- alternative\n"
   "\t\tk\t-- KOI-8\n"
   "\t\tb\t-- Besta\n"
   "\t\t7\t-- KOI-7\n"
   "\t\tl\t-- KOI-7 uppercase-downcase inversed (latin transliterated)\n"
   "\t\tw\t-- Windows\n"
   "\t\ti\t-- ISO-8859-5\n"
   "\t\tg\t-- MIC Bulgarian\n"
   "\t\to\t-- main\n"
   "\t\tm\t-- Macintosh\n"
   "\n"
   "\t\t(for example: totally 8x8=64 possibilities of such pairs\n"
   "\t\t              [such as: a2k, k2a, a2w, w2a, k2w, w2k, ...]\n"
   "\t\t              are acceptable, including the tautologies\n"
   "\t\t              [such as: a2a, k2k, w2w, ...]\n"
   "\t\t              that produce \"letter-to-itself\" translation\n"
   "\n"
   "\t-u2d\t-- UNIX -> DOS\n"
   "\t-d2u\t-- DOS  -> UNIX (in DOS works only for files, not for streams).\n"
   "\n"
   "\n"
   "Usable [i.e. I use them frequently] examples of parameters:\n"
   "\n"
   "\t-a2k -d2u \\\n"
   "\t            -- translate de-facto Russian standards: from DOS to *NIX\n"
   "\t-d2u -a2k /\n"
   "\t-k2a -u2d \\\n"
   "\t            -- translate de-facto Russian standards: from *NIX to DOS\n"
   "\t-u2d -a2k /\n"
   "\t-a2w        -- translate alternative encoding to Windows one...\n"
   "\t-w2a        -- ... and vice versa\n"
   "\n"
   "\t-k2l        -- translate KOI-8 to pseudo-transliterated Russian\n"
   "\n"
   "\n"
   "Additional information:\n"
   "table sample: \"[ABV.\\EJuJa.abv.\\ejuja]\"\n"
   "\n"
   "Alternative -- Brjabrin's \"al'ternativnaya kodirovka\";\n"
   "               Microsoft DOS Code Page 866 compatible\n"
   "[\"...\"]\n"
   "\n"
   "ISO-8859-5  -- Standard 8859-5 by International Standard Organization\n"
   "[\"...\"]\n"
   "\n"
   "Main        -- Brjabrin's \"osnovnaya kodirovka\";\n"
   "               GOST main standard\n"
   "[\"...\"]\n"
   "\n"
   "MIC         -- \"standard\" before GOST;\n"
   "               \"Bulgarian\" code table\n"
   "[\"...\"]\n"
   "\n"
   "KOI-8       -- KOI-8 according to RFC-1489 (1993) standard\n"
   "               (by A.Chernov, RELCOM Development Team)\n"
   "[\"...\"]\n"
   "\n"
   "KOI-7       -- 7-bit\n"
   "[\"abw.|`q.ABW.\\@Q\"]\n"
   "\n"
   "KOI-7 inv   -- 7-bit uppercase-downcase inversed.\n"
   "               Useful for \"Russian->Transliterated\" translation.\n"
   "[\"ABW.\\@Q.abw.|`q\"]\n"
   "\n"
   "Besta       -- as KOI-8, but Russian upper- and lower-case\n"
   "               letters interchanged\n"
   "[\"...\"]\n"
   "\n"
   "Windows     -- Microsoft Windows Code Page 1251\n"
   "[\"...\"]\n"
   "\n"
   "Macintosh   -- Apple Macintosh\n"
   "[\"...\"]\n"
   "\n"
   "\n"
   "-----------------------------------------------------------------------\n"

;


/*
  "GOST alternative" and "GOST alternative modified"
  are the same main part but different at the end
  (last 16 symbols are irrelevant).
  (by V.M.Brjabrin and V.E.Figurnov)
*/
const BYTE Tbl_GOST_alt[]=
""
""
""
""
""
""
""
"";


/*
  "GOST main" is rather different from "GOST alternative".
  (by V.M.Brjabrin and V.E.Figurnov)
*/
const BYTE Tbl_GOST_main[]=
/*
	"ѵս"
	"ɻͺ˹ΰ"
	"ڿĳ´"
	""
	""
	""
	""
	"";
*/
""
""
""
""
""
""
""
"";


/*
  "MIC" or "bulgar" coding (the basic table before GOST).
  Caution: the symbols with codes 224239 are irrelevant.
  (by V.E.Figurnov)
*/
const BYTE Tbl_MIC[]=
/*
	""
	""
	""
	""
	"Źο"
	""
	"                "
	"";
*/
""
""
""
"??????"
"???"
"?????????"
""
"";

/*
  "KOI-8" coding table.
  (according to RFC 1489 by A.Chernov)
*/
const BYTE Tbl_KOI8[]=
/*
	"ĳڿô"
	""
	"ͺɸȾ"
	"̵"
	"椥娩"
	"㦢"
	""
	"";
*/
""
""
""
""
""
""
""
"";



/*
  "Besta" -- "KOI-8 inversed" coding table.
*/
const BYTE Tbl_BESTA[]=
/*
	"ĳڿô"
	""
	"ͺɸȾ"
	"̵"
	""
	""
	"椥娩"
	"㦢";
*/
""
""
""
""
""
""
""
"";


/*
  MS-Windows Code Page 1251.
*/
const BYTE Tbl_CP1251[]=
/*
	"                "
	"                "
	"               "
	"               "
	""
	""
	""
	"";
*/
""
""
""
"                "
"                "
"                "
""
"              ";


/*
  ISO-8859-5.
*/
const BYTE Tbl_ISO8859_5[]=
/*
	"                "
	"                "
	"               "
	""
	""
	""
	""
	"               ";
*/
""
""
""
"                "
"                "
"                "
""
"              ";


/*
  KOI-7.
*/
const BYTE Tbl_KOI7[]=
"abwgdevzijklmnop"
"rstufhc~{}\"yx|`q"
"ABWGDEVZIJKLMNOP"
"                "
"                "
"                "
"RSTUFHC^[]_YX\\@Q"
"$#              ";


/*
	KOI-7	inversed.
*/
const BYTE Tbl_KOI7_inv[]=
"ABWGDEVZIJKLMNOP"
"RSTUFHC^[]_YX\\@Q"
"abwgdevzijklmnop"
"                "
"                "
"                "
"rstufhc~{}\"yx|`q"
"#$              ";


/*
	Macintosh.
*/
const BYTE Tbl_Macintosh[]=
""
""
""
""
""
""
""
"";

/*<EOF>*/

