1 /**
2  * @namespace   biew_plugins_II
3  * @file        plugins/nls/russian.c
4  * @brief       This file contains support of russian codepages.
5  * @version     -
6  * @remark      this source file is part of Binary vIEW project (BIEW).
7  *              The Binary vIEW (BIEW) is copyright (C) 1995 Nickols_K.
8  *              All rights reserved. This software is redistributable under the
9  *              licence given in the file "Licence.en" ("Licence.ru" in russian
10  *              translation) distributed in the BIEW archive.
11  * @note        Requires POSIX compatible development system
12  *
13  * @author      Nickols_K
14  * @since       1995
15  * @note        Development, fixes and improvements
16 **/
17 #include <ctype.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20 
21 #include "plugins/textmode.h"
22 #include "bconsole.h"
23 #include "biewutil.h"
24 
25 #define TXT_CURRCP      0
26 #define TXT_CP866       1
27 #define TXT_WIN1251     2
28 #define TXT_KOIR8       3
29 #define TXT_ISO         4
30 #define TXT_CP855       5
31 #define TXT_APPLE       6
32 #define TXT_UNICODE     7
33 #define TXT_BIG_UNICODE 8
34 #define TXT_EBCDIC      9
35 #define TXT_MIK16       10
36 #define TXT_GOST87      11
37 #define TXT_KOI0        12
38 #define TXT_KOI7        13
39 #define TXT_KOI8A       14
40 #define TXT_KOI8E       15
41 #define TXT_KOIR8V2     16
42 #define TXT_TRANSLIT    17
43 #define TXT_7BIT        18
44 
45 #define TXT_MAXMODE     18
46 
47 static const char * ru_cp_names[] =
48 {
49    "~Current",
50    "CP 8~66 (DOS)",
51    "CP 1251 (~Windows)",
52    "CP 878 (Unix ~KOI8-R)",
53    "~ISO-8859-5-Cyrillic",
54    "CP ~855",
55    "CP 10007 (Apple-~Macintosh)",
56    "~Unicode ISO/IEC 10646-1 UCS (UTF-16 little-endian)",
57    "Unicode ISO/IEC 10646-1 UCS (UTF-16 ~big-endian)",
58    "~EBCDIC",
59    "~Bulgarian Prawek 16 PC",
60    "~GOST 19768-87",
61    "KOI-~0 (GOST 13052)",
62    "KOI-~7 (GOST 19768-74)",
63    "O~riginal KOI-8 (GOST 19768-74)",
64    "~European KOI-8 (ISO-IR-111)",
65    "KOI~8-R v2",
66    "~Translit of KOI8-R",
67    "~View as UUCP 7bit compatible (meaningful only for KOI8-R)"
68 };
69 
70 
71 static unsigned cp_mode = TXT_CURRCP;
72 static unsigned char cp_symb_len = 1;
73 
74 #if 0
75 static const tUInt16 cp866_2_Unicode[] =
76 {
77   0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, /*0x00*/
78   0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
79   0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, /*0x10*/
80   0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
81   0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, /*0x20*/
82   0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
83   0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, /*0x30*/
84   0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
85   0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, /*0x40*/
86   0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
87   0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, /*0x50*/
88   0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
89   0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, /*0x60*/
90   0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
91   0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, /*0x60*/
92   0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
93 
94   0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, /*0x80*/
95   0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
96   0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, /*0x90*/
97   0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
98   0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, /*0xA0*/
99   0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
100 
101   0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, /*0xB0*/
102   0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
103 
104   0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, /*0xC0*/
105   0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
106 
107   0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, /*0xD0*/
108   0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
109 
110   0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, /*0xE0*/
111   0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
112   0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E, /*0xF0*/
113   0x00B0, 0x2022, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0
114 };
115 #endif
116 static const unsigned char uni_draw[] =
117 {
118 0xc4,0x3f,0xb3,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xda,0x3f,0x3f,0x3f, /*0x00*/
119 0xbf,0x3f,0x3f,0x3f,0xc0,0x3f,0x3f,0x3f,0xd9,0x3f,0x3f,0x3f,0xc3,0x3f,0x3f,0x3f, /*0x10*/
120 0x3f,0x3f,0x3f,0x3f,0xb4,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xc2,0x3f,0x3f,0x3f, /*0x20*/
121 0x3f,0x3f,0x3f,0x3f,0xc1,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xc5,0x3f,0x3f,0x3f, /*0x30*/
122 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, /*0x40*/
123 0xcd,0xba,0xd5,0xd6,0xc9,0xb8,0xb7,0xbb,0xd4,0xd3,0xc8,0xbe,0xbd,0xbc,0xc6,0xc7, /*0x50*/
124 0xcc,0xb5,0xb6,0xb9,0xd1,0xd2,0xcb,0xcf,0xd0,0xca,0xd8,0xd7,0xce,0x3f,0x3f,0x3f, /*0x60*/
125 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, /*0x70*/
126 0xdf,0x3f,0x3f,0x3f,0xdc,0x3f,0x3f,0x3f,0xdb,0x3f,0x3f,0x3f,0xdd,0x3f,0x3f,0x3f, /*0x80*/
127 0xde,0xb0,0xb1,0xb2,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, /*0x90*/
128 0xfe,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, /*0xA0*/
129 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, /*0xB0*/
130 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, /*0xC0*/
131 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, /*0xD0*/
132 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, /*0xE0*/
133 0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f, /*0xF0*/
134 };
135 
txt_cvt_unicode(unsigned char * str,int size,tBool big_endian)136 static void __NEAR__ __FASTCALL__ txt_cvt_unicode(unsigned char * str,int size,tBool big_endian)
137 {
138   int i;
139   unsigned high_byte,low_byte;
140   size >>= 1;
141   for(i = 0;i < size;i++)
142   {
143     if(big_endian)
144     {
145       low_byte = str[(i<<1)+1];
146       high_byte  = str[(i<<1)];
147     }
148     else
149     {
150       high_byte = str[(i<<1)+1];
151       low_byte  = str[(i<<1)];
152     }
153     switch(high_byte)
154     {
155       case 0x00:  /** Basic latin & latin 1 supplement zone */
156                     if(low_byte < 0x80) str[i] = low_byte;
157                     else
158                       if(low_byte == 0xA0) str[i] = 0xFF;
159                       else
160                         if(low_byte == 0xB7) str[i] = 0xFD;
161                         else
162                           if(low_byte == 0xB0) str[i] = 0xF8;
163                           else
164                             if(low_byte == 0xB7) str[i] = 0xFA;
165                             else           str[i] = '?';
166                   break;
167       case 0x04:  /** Cyrillic zone */
168                   if(low_byte >= 0x10 && low_byte < 0x40) str[i] = (unsigned char)(low_byte + 0x80 - 0x410);
169                   else
170                     if(low_byte >= 0x40 && low_byte < 0x50) str[i] = (unsigned char)(low_byte + 0xE0 - 0x440);
171                     else str[i] = '?';
172                   break;
173       case 0x20:
174                   if(low_byte == 0x22) str[i] = 0xF9;
175                   else           str[i] = '?';
176                   break;
177       case 0x21:
178                   if(low_byte == 0x16) str[i] = 0xFC;
179                   else           str[i] = '?';
180                   break;
181       case 0x22:
182                   if(low_byte == 0x1A) str[i] = 0xFB;
183                   else           str[i] = '?';
184                   break;
185       case 0x25: /** Box draw zone */
186                   str[i] = uni_draw[low_byte];
187                   break;
188       default:    str[i] = '?';
189     }
190   }
191 }
192 
193 static const unsigned char e2a[256] = {
194 0x00,0x01,0x02,0x03,0x9c,0x09,0x86,0x7f,0x97,0x8d,0x8e,0x0b,0x0c,0x0d,0x0e,0x0f,
195 0x10,0x11,0x12,0x13,0x9d,0x85,0x08,0x87,0x18,0x19,0x92,0x8f,0x1c,0x1d,0x1e,0x1f,
196 0x80,0x81,0x82,0x83,0x84,0x0a,0x17,0x1b,0x88,0x89,0x8a,0x8b,0x8c,0x05,0x06,0x07,
197 0x90,0x91,0x16,0x93,0x94,0x95,0x96,0x04,0x98,0x99,0x9a,0x9b,0x14,0x15,0x9e,0x1a,
198 0x20,0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0x5b,0x2e,0x3c,0x28,0x2b,0x21,
199 0x26,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0x5d,0x24,0x2a,0x29,0x3b,0x5e,
200 0x2d,0x2f,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0x7c,0x2c,0x25,0x5f,0x3e,0x3f,
201 0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0x60,0x3a,0x23,0x40,0x27,0x3d,0x22,
202 0xc3,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0xc0,0xc5,0xc6,0xc7,0xc8,0xc9,
203 0xca,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,
204 0xd1,0x7e,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,
205 0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
206 0x7b,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0xe8,0xe9,0xea,0xeb,0xec,0xed,
207 0x7d,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0xee,0xef,0xf0,0xf1,0xf2,0xf3,
208 0x5c,0x9f,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,
209 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
210 };
211 
212 static const unsigned char Win2Alt[] = {
213 0xf4,0xc3,0xf0,0xf6,0xf1,0xf5,0xf3,0xf2,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,
214 0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xf7,0xc4,0xc5,0xc6,0xc7,
215 0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,
216 0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
217 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
218 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
219 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
220 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef
221 };
222 
223 static const unsigned char koi8r2AltV2[] = { /** KOI8-R to AltDOS v2 */
224 0xf4,0xc3,0xf0,0xf6,0xf1,0xf5,0xf3,0xf2,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,
225 0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xf7,0xc4,0xc5,0xc6,0xc7,
226 0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,
227 0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
228 0xee,0xa0,0xa1,0xe6,0xa4,0xa5,0xe4,0xa3,0xe5,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,
229 0xaf,0xef,0xe0,0xe1,0xe2,0xe3,0xa6,0xa2,0xec,0xeb,0xa7,0xe8,0xed,0xe9,0xe7,0xea,
230 0x9e,0x80,0x81,0x96,0x84,0x85,0x94,0x83,0x95,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,
231 0x8f,0x9f,0x90,0x91,0x92,0x93,0x86,0x82,0x9c,0x9b,0x87,0x98,0x9d,0x99,0x97,0x9a
232 };
233 
234 static const unsigned char koi8r2Alt[] = { /** by Chernov 1994 */
235 0xc4,0xb3,0xda,0xbf,0xc0,0xd9,0xc3,0xb4,0xc2,0xc1,0xc5,0xdf,0xdc,0xdb,0xdd,0xde,
236 0xb0,0xb1,0xb2,0xf4,0xfe,0xf9,0xfb,0xf7,0xf3,0xf2,0xff,0xf5,0xf8,0xfd,0xfa,0xf6,
237 0xcd,0xba,0xd5,0xf1,0xd6,0xc9,0xb8,0xb7,0xbb,0xd4,0xd3,0xc8,0xbe,0xbd,0xbc,0xc6,
238 0xc7,0xcc,0xb5,0xf0,0xb6,0xb9,0xd1,0xd2,0xcb,0xcf,0xd0,0xca,0xd8,0xd7,0xce,0xfc,
239 0xee,0xa0,0xa1,0xe6,0xa4,0xa5,0xe4,0xa3,0xe5,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,
240 0xaf,0xef,0xe0,0xe1,0xe2,0xe3,0xa6,0xa2,0xec,0xeb,0xa7,0xe8,0xed,0xe9,0xe7,0xea,
241 0x9e,0x80,0x81,0x96,0x84,0x85,0x94,0x83,0x95,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,
242 0x8f,0x9f,0x90,0x91,0x92,0x93,0x86,0x82,0x9c,0x9b,0x87,0x98,0x9d,0x99,0x97,0x9a
243 };
244 
245 static const unsigned char mac2Alt[128] = {
246 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, /*0x80*/
247 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, /*0x90*/
248 0xDD,0xDE,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF, /*0xA0*/
249 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, /*0xB0*/
250 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, /*0xC0*/
251 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xF0,0xF1,0xEF, /*0xD0*/
252 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, /*0xE0*/
253 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xDF  /*0xF0*/
254 };
255 
256 static const unsigned char cp855Alt[128] = {
257  0x80,0x81,0x66,0x46,0xF1,0xF0,0x86,0x87,0x73,0x53,0x69,0x49,0x8C,0x8D,0x8E,0x8F, /*0x80*/
258  0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0xEE,0x9E,0xEA,0x9A, /*0x90*/
259  0xA0,0x80,0xA1,0x81,0xE6,0x96,0xA4,0x84,0xA5,0x85,0xE4,0x94,0xA3,0x83,0xAE,0xAF, /*0xA0*/
260  0xB0,0xB1,0xB2,0xB3,0xB4,0xE5,0x95,0xA8,0x88,0xB9,0xBA,0xBB,0xBC,0xA9,0x89,0xBF, /*0xB0*/
261  0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xAA,0x8A,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, /*0xC0*/
262  0xAB,0x8B,0xAC,0x8C,0xAD,0x8D,0xAE,0x8E,0xAF,0xD9,0xDA,0xDB,0xDC,0x8F,0xEF,0xDF, /*0xD0*/
263  0x9F,0xE0,0x90,0xE1,0x91,0xE2,0x92,0xE3,0x93,0xA6,0x86,0xA2,0x82,0xEC,0x9C,0xEF, /*0xE0*/
264  0xF0,0xEB,0x9B,0xA7,0x87,0xE8,0x98,0xED,0x9D,0xE9,0x99,0xE7,0x97,0xFD,0xFE,0xFF, /*0xF0*/
265 };
266 
267 static const unsigned char ISO2Alt[] = {
268 0xf4,0xc3,0xf0,0xf6,0xf1,0xf5,0xf3,0xf2,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,
269 0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xf7,0xc4,0xc5,0xc6,0xc7,
270 0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,
271 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
272 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
273 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
274 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
275 0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
276 };
277 
278 static const unsigned char koi0Alt[128] = {
279  0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, /*0x00*/
280  0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, /*0x10*/
281  0x20,0x21,0x22,0x23,0xfd,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f, /*0x20*/
282  0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, /*0x30*/
283  0xee,0xa0,0xa1,0xe6,0xa4,0xa5,0xe4,0xa3,0xe5,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae, /*0x40*/
284  0xaf,0xef,0xe0,0xe1,0xe2,0xe3,0xa6,0xa2,0xec,0xeb,0xa7,0xe8,0xed,0xe9,0xe7,0xea, /*0x50*/
285  0x9e,0x80,0x81,0x96,0x84,0x85,0x94,0x83,0x95,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e, /*0x60*/
286  0x8f,0x9f,0x90,0x91,0x92,0x93,0x86,0x82,0x9c,0x9b,0x87,0x98,0x9d,0x99,0x97,0x7F, /*0x70*/
287 };
288 
289 static const unsigned char koi7Alt[128] = {
290  0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, /*0x00*/
291  0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, /*0x10*/
292  0x20,0x21,0x22,0x23,0xfd,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f, /*0x20*/
293  0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, /*0x30*/
294  0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, /*0x40*/
295  0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f, /*0x50*/
296  0x9e,0x80,0x81,0x96,0x84,0x85,0x94,0x83,0x95,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e, /*0x60*/
297  0x8f,0x9f,0x90,0x91,0x92,0x93,0x86,0x82,0x9c,0x9b,0x87,0x98,0x9d,0x99,0x97,0x7F, /*0x70*/
298 };
299 
300 static const unsigned char koi8a2Alt[128] = {
301  0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, /*0x80*/
302  0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, /*0x90*/
303  0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, /*0xa0*/
304  0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, /*0xb0*/
305  0xee,0xa0,0xa1,0xe6,0xa4,0xa5,0xe4,0xa3,0xe5,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae, /*0xc0*/
306  0xaf,0xef,0xe0,0xe1,0xe2,0xe3,0xa6,0xa2,0xec,0xeb,0xa7,0xe8,0xed,0xe9,0xe7,0xea, /*0xd0*/
307  0x9e,0x80,0x81,0x96,0x84,0x85,0x94,0x83,0x95,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e, /*0xe0*/
308  0x8f,0x9f,0x90,0x91,0x92,0x93,0x86,0x82,0x9c,0x9b,0x87,0x98,0x9d,0x99,0x97,0xFF, /*0xf0*/
309 };
310 
311 static const unsigned char koi8e2Alt[128] = {
312  0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, /*0x80*/
313  0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, /*0x90*/
314  0xa0,0xa1,0xa2,0xf1,0xf2,0x73,0x69,0xf5,0x6a,0xa9,0xaa,0xab,0xac,0xad,0xf7,0xaf, /*0xa0*/
315  0xfc,0xb1,0xb2,0xf0,0xf3,0x53,0x49,0xf4,0x4a,0xb9,0xba,0xbb,0xbc,0xfd,0xf6,0xbf, /*0xb0*/
316  0xee,0xa0,0xa1,0xe6,0xa4,0xa5,0xe4,0xa3,0xe5,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae, /*0xc0*/
317  0xaf,0xef,0xe0,0xe1,0xe2,0xe3,0xa6,0xa2,0xec,0xeb,0xa7,0xe8,0xed,0xe9,0xe7,0xea, /*0xd0*/
318  0x9e,0x80,0x81,0x96,0x84,0x85,0x94,0x83,0x95,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e, /*0xe0*/
319  0x8f,0x9f,0x90,0x91,0x92,0x93,0x86,0x82,0x9c,0x9b,0x87,0x98,0x9d,0x99,0x97,0x9A, /*0xf0*/
320 };
321 
322 static const unsigned char gost87Alt[128] = {
323  0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, /*0x80*/
324  0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, /*0x90*/
325  0xa0,0xf0,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, /*0xa0*/
326  0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, /*0x80*/
327  0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, /*0x90*/
328  0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, /*0xa0*/
329  0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef, /*0xe0*/
330  0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff, /*0xf0*/
331 };
332 
333 static const unsigned char Mik16Alt[128] = {
334  0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, /*0x80*/
335  0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, /*0x90*/
336  0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, /*0xa0*/
337  0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef, /*0xb0*/
338  0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, /*0xc0*/
339  0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, /*0xd0*/
340  0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, /*0xe0*/
341  0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff, /*0xf0*/
342 };
343 
Unix7Bit(char * str,int size)344 static void __NEAR__ __FASTCALL__ Unix7Bit(char *str,int size)
345 {
346   int i;
347   for(i = 0;i < size;i++) str[i] &= 0x7F;
348 }
349 
Translit7Bit(char * str,int size)350 static void __NEAR__ __FASTCALL__ Translit7Bit(char *str,int size)
351 {
352   int i;
353   for(i = 0;i < size;i++)
354   {
355     unsigned char ch;
356     ch = str[i];
357     switch(ch) /** need some correcting for normal viewing translit */
358     {
359        case 'p': str[i] = '�'; break;
360        case '@': str[i] = '�'; break;
361        case '\\':str[i] = '�'; break;
362        case ']': str[i] = '�'; break;
363        case '[': str[i] = '�'; break;
364        case '^': str[i] = '�'; break;
365        case '|': str[i] = '�'; break;
366        case '~': str[i] = '�'; break;
367        case '{': str[i] = '�'; break;
368        case '}': str[i] = '�'; break;
369        case '_': str[i] = '�'; break;
370        default: if(isalpha((unsigned char)str[i])) str[i] |= 0x80; txt_cvt_hi80(&str[i],1,koi8r2Alt);
371     }
372   }
373 }
374 
ru_convert_buffer(char * buff,unsigned size,tBool use_fs_nls)375 static unsigned __FASTCALL__ ru_convert_buffer(char *buff,unsigned size, tBool use_fs_nls)
376 {
377   switch(cp_mode)
378   {
379       case TXT_7BIT:    Unix7Bit(buff,size); break;
380       case TXT_KOI0:    txt_cvt_lo80(buff,size,koi0Alt); break;
381       case TXT_KOI7:    txt_cvt_lo80(buff,size,koi7Alt); break;
382       case TXT_KOI8A:   txt_cvt_hi80(buff,size,koi8a2Alt); break;
383       case TXT_KOI8E:   txt_cvt_hi80(buff,size,koi8e2Alt); break;
384       case TXT_GOST87:  txt_cvt_hi80(buff,size,gost87Alt); break;
385       case TXT_WIN1251: txt_cvt_hi80(buff,size,Win2Alt); break;
386       case TXT_MIK16:   txt_cvt_hi80(buff,size,Mik16Alt); break;
387       case TXT_KOIR8:   txt_cvt_hi80(buff,size,koi8r2Alt); break;
388       case TXT_KOIR8V2: txt_cvt_hi80(buff,size,koi8r2AltV2); break;
389       case TXT_APPLE:   txt_cvt_hi80(buff,size,mac2Alt); break;
390       case TXT_ISO:     txt_cvt_hi80(buff,size,ISO2Alt); break;
391       case TXT_CP855:   txt_cvt_hi80(buff,size,cp855Alt); break;
392       case TXT_EBCDIC:  txt_cvt_full(buff,size,e2a); break;
393       case TXT_BIG_UNICODE:
394       case TXT_UNICODE: txt_cvt_unicode((unsigned char *)buff,size,cp_mode == TXT_BIG_UNICODE);
395                         break;
396       case TXT_TRANSLIT:Translit7Bit(buff,size); break;
397   };
398   if(cp_mode != TXT_CURRCP)
399   {
400     if(use_fs_nls) __nls_OemToFs((unsigned char *)buff,size);
401     else           __nls_OemToOsdep((unsigned char *)buff,size);
402   }
403   return size / cp_symb_len;
404 }
405 
ru_get_symbol_size(void)406 static unsigned __FASTCALL__ ru_get_symbol_size( void ) { return cp_symb_len; }
407 
ru_select_table(void)408 static tBool __FASTCALL__ ru_select_table( void )
409 {
410   unsigned nModes;
411   int i;
412   nModes = sizeof(ru_cp_names)/sizeof(char *);
413   i = SelBoxA(ru_cp_names,nModes," Select cyrillic code page: ",cp_mode);
414   if(i != -1)
415   {
416     cp_mode = i;
417     if(cp_mode == TXT_UNICODE || cp_mode == TXT_BIG_UNICODE) cp_symb_len = 2;
418     else                                                     cp_symb_len = 1;
419     return True;
420   }
421   return False;
422 }
423 
ru_read_ini(hIniProfile * ini)424 static void __FASTCALL__ ru_read_ini( hIniProfile *ini )
425 {
426   char tmps[10];
427   if(isValidIniArgs())
428   {
429     biewReadProfileString(ini,"Biew","Browser","LastSubMode","0",tmps,sizeof(tmps));
430     cp_mode = (unsigned)strtoul(tmps,NULL,10);
431     if(cp_mode > TXT_MAXMODE) cp_mode = 0;
432  }
433  if(cp_mode == TXT_UNICODE || cp_mode == TXT_BIG_UNICODE) cp_symb_len = 2;
434  else                                                     cp_symb_len = 1;
435 }
436 
ru_save_ini(hIniProfile * ini)437 static void __FASTCALL__ ru_save_ini( hIniProfile *ini )
438 {
439   char tmps[10];
440   sprintf(tmps,"%i",cp_mode);
441   biewWriteProfileString(ini,"Biew","Browser","LastSubMode",tmps);
442 }
443 
444 REGISTRY_NLS RussianNLS =
445 {
446   "Russian set",
447   ru_convert_buffer,
448   ru_get_symbol_size,
449   ru_select_table,
450   ru_read_ini,
451   ru_save_ini,
452   NULL,
453   NULL
454 };
455 
456 
457