Welcome to mirror list, hosted at ThFree Co, Russian Federation.

iconvru.c « newlib.iconv « testsuite « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f02ebcbdc91d61feafcff91c4eb67b726e7b537 (plain)
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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
/*
 * Copyright (c) 2003, Artem B. Bityuckiy, SoftMine Corporation.
 * Rights transferred to Franklin Electronic Publishers.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>
#include <errno.h>
#include <newlib.h>
#include "check.h"

#ifdef _ICONV_ENABLED

#if defined(_ICONV_CONVERTER_UTF_8) || \
    defined(_ICONV_CONVERTER_ISO_8859_5) || \
    defined(_ICONV_CONVERTER_KOI8_R)

#ifdef _ICONV_CONVERTER_ISO_8859_5
char iso_8859_5[] =
{
    0xbe,0xdf,0xd5,0xe0,0xd0,0xe2,0xde,0xe0,0xeb,0x20,
    0xd2,0x20,0xde,0xd4,0xdd,0xde,0xd9,0x20,0xe1,0xe2,
    0xe0,0xde,0xda,0xd5,0x20,0xd8,0xdc,0xd5,0xee,0xe2,
    0x20,0xde,0xd4,0xd8,0xdd,0xd0,0xda,0xde,0xd2,0xeb,
    0xd9,0x20,0xdf,0xe0,0xd8,0xde,0xe0,0xd8,0xe2,0xd5,
    0xe2,0x0a,0xc1,0xe2,0xe0,0xde,0xda,0xd8,0x20,0xe3,
    0xdf,0xde,0xe0,0xef,0xd4,0xde,0xe7,0xd5,0xdd,0xeb,
    0x20,0xdf,0xde,0x20,0xe3,0xd1,0xeb,0xd2,0xd0,0xdd,
    0xd8,0xee,0x20,0xdf,0xe0,0xd8,0xde,0xe0,0xd8,0xe2,
    0xd5,0xe2,0xde,0xd2,0x2e,0x0a,0x0a,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x20,0xb2,0xeb,0xdf,0xde,0xdb,
    0xdd,0xd5,0xdd,0xd8,0xd5,0x20,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x0a,0x28,0x29,0x20,0x20,
    0x5b,0x5d,0x20,0x20,0x2d,0x3e,0x20,0x20,0x2e,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x21,
    0x20,0x20,0x20,0x7e,0x20,0x20,0x20,0x2b,0x2b,0x20,
    0x20,0x2d,0x2d,0x20,0x20,0x2b,0x20,0x20,0x2d,0x20,
    0x20,0x2a,0x20,0x20,0x26,0x20,0x20,0x28,0x74,0x79,
    0x70,0x65,0x29,0x20,0x20,0x73,0x69,0x7a,0x65,0x6f,
    0x66,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,
    0x3e,0x0a,0x2a,0x20,0x20,0x2f,0x20,0x20,0x25,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x2d,0x2d,0x2d,0x3e,0x0a,0x2b,0x20,0x20,0x2d,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x3c,0x3c,
    0x20,0x20,0x3e,0x3e,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,
    0x0a,0x3c,0x20,0x20,0x3c,0x3d,0x20,0x20,0x3e,0x20,
    0x20,0x3e,0x3d,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,
    0x2d,0x2d,0x3e,0x0a,0x3d,0x3d,0x20,0x20,0x21,0x3d,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x26,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,
    0x5e,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,
    0x2d,0x3e,0x0a,0x7c,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x26,0x26,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x7c,
    0x7c,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,
    0x3e,0x0a,0x3f,0x3a,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x3c,0x2d,0x2d,0x2d,0x20,0x20,0x20,0x0a,0x3d,0x20,
    0x20,0x2b,0x3d,0x20,0x20,0x2d,0x3d,0x20,0x20,0x2f,
    0x3d,0x20,0x20,0x25,0x3d,0x20,0x20,0x26,0x3d,0x20,
    0x20,0x5e,0x3d,0x20,0x20,0x7c,0x3d,0x20,0x20,0x3c,
    0x3c,0x3d,0x20,0x20,0x3e,0x3e,0x3d,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x2d,0x2d,0x2d,
    0x0a,0x2c,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,
    0x2d,0x2d,0x3e,0x0a
};
#endif /* #ifdef _ICONV_CONVERTER_ISO_8859_5 */

#ifdef _ICONV_CONVERTER_KOI8_R
char koi8_r[] = 
{
    0xef,0xd0,0xc5,0xd2,0xc1,0xd4,0xcf,0xd2,0xd9,0x20,
    0xd7,0x20,0xcf,0xc4,0xce,0xcf,0xca,0x20,0xd3,0xd4,
    0xd2,0xcf,0xcb,0xc5,0x20,0xc9,0xcd,0xc5,0xc0,0xd4,
    0x20,0xcf,0xc4,0xc9,0xce,0xc1,0xcb,0xcf,0xd7,0xd9,
    0xca,0x20,0xd0,0xd2,0xc9,0xcf,0xd2,0xc9,0xd4,0xc5,
    0xd4,0x0a,0xf3,0xd4,0xd2,0xcf,0xcb,0xc9,0x20,0xd5,
    0xd0,0xcf,0xd2,0xd1,0xc4,0xcf,0xde,0xc5,0xce,0xd9,
    0x20,0xd0,0xcf,0x20,0xd5,0xc2,0xd9,0xd7,0xc1,0xce,
    0xc9,0xc0,0x20,0xd0,0xd2,0xc9,0xcf,0xd2,0xc9,0xd4,
    0xc5,0xd4,0xcf,0xd7,0x2e,0x0a,0x0a,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x20,0xf7,0xd9,0xd0,0xcf,0xcc,
    0xce,0xc5,0xce,0xc9,0xc5,0x20,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x0a,0x28,0x29,0x20,0x20,
    0x5b,0x5d,0x20,0x20,0x2d,0x3e,0x20,0x20,0x2e,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x21,
    0x20,0x20,0x20,0x7e,0x20,0x20,0x20,0x2b,0x2b,0x20,
    0x20,0x2d,0x2d,0x20,0x20,0x2b,0x20,0x20,0x2d,0x20,
    0x20,0x2a,0x20,0x20,0x26,0x20,0x20,0x28,0x74,0x79,
    0x70,0x65,0x29,0x20,0x20,0x73,0x69,0x7a,0x65,0x6f,
    0x66,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,
    0x3e,0x0a,0x2a,0x20,0x20,0x2f,0x20,0x20,0x25,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x2d,0x2d,0x2d,0x3e,0x0a,0x2b,0x20,0x20,0x2d,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x3c,0x3c,
    0x20,0x20,0x3e,0x3e,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,
    0x0a,0x3c,0x20,0x20,0x3c,0x3d,0x20,0x20,0x3e,0x20,
    0x20,0x3e,0x3d,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,
    0x2d,0x2d,0x3e,0x0a,0x3d,0x3d,0x20,0x20,0x21,0x3d,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x26,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,
    0x5e,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,
    0x2d,0x3e,0x0a,0x7c,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x26,0x26,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x7c,
    0x7c,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,
    0x3e,0x0a,0x3f,0x3a,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x3c,0x2d,0x2d,0x2d,0x20,0x20,0x20,0x0a,0x3d,0x20,
    0x20,0x2b,0x3d,0x20,0x20,0x2d,0x3d,0x20,0x20,0x2f,
    0x3d,0x20,0x20,0x25,0x3d,0x20,0x20,0x26,0x3d,0x20,
    0x20,0x5e,0x3d,0x20,0x20,0x7c,0x3d,0x20,0x20,0x3c,
    0x3c,0x3d,0x20,0x20,0x3e,0x3e,0x3d,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x2d,0x2d,0x2d,
    0x0a,0x2c,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,
    0x2d,0x2d,0x3e,0x0a
};
#endif /* #ifdef _ICONV_CONVERTER_KOI8_R */

#ifdef _ICONV_CONVERTER_UTF_8
char utf8[] =
{
    0xd0,0x9e,0xd0,0xbf,0xd0,0xb5,0xd1,0x80,0xd0,0xb0,
    0xd1,0x82,0xd0,0xbe,0xd1,0x80,0xd1,0x8b,0x20,0xd0,
    0xb2,0x20,0xd0,0xbe,0xd0,0xb4,0xd0,0xbd,0xd0,0xbe,
    0xd0,0xb9,0x20,0xd1,0x81,0xd1,0x82,0xd1,0x80,0xd0,
    0xbe,0xd0,0xba,0xd0,0xb5,0x20,0xd0,0xb8,0xd0,0xbc,
    0xd0,0xb5,0xd1,0x8e,0xd1,0x82,0x20,0xd0,0xbe,0xd0,
    0xb4,0xd0,0xb8,0xd0,0xbd,0xd0,0xb0,0xd0,0xba,0xd0,
    0xbe,0xd0,0xb2,0xd1,0x8b,0xd0,0xb9,0x20,0xd0,0xbf,
    0xd1,0x80,0xd0,0xb8,0xd0,0xbe,0xd1,0x80,0xd0,0xb8,
    0xd1,0x82,0xd0,0xb5,0xd1,0x82,0x0a,0xd0,0xa1,0xd1,
    0x82,0xd1,0x80,0xd0,0xbe,0xd0,0xba,0xd0,0xb8,0x20,
    0xd1,0x83,0xd0,0xbf,0xd0,0xbe,0xd1,0x80,0xd1,0x8f,
    0xd0,0xb4,0xd0,0xbe,0xd1,0x87,0xd0,0xb5,0xd0,0xbd,
    0xd1,0x8b,0x20,0xd0,0xbf,0xd0,0xbe,0x20,0xd1,0x83,
    0xd0,0xb1,0xd1,0x8b,0xd0,0xb2,0xd0,0xb0,0xd0,0xbd,
    0xd0,0xb8,0xd1,0x8e,0x20,0xd0,0xbf,0xd1,0x80,0xd0,
    0xb8,0xd0,0xbe,0xd1,0x80,0xd0,0xb8,0xd1,0x82,0xd0,
    0xb5,0xd1,0x82,0xd0,0xbe,0xd0,0xb2,0x2e,0x0a,0x0a,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x20,0xd0,0x92,
    0xd1,0x8b,0xd0,0xbf,0xd0,0xbe,0xd0,0xbb,0xd0,0xbd,
    0xd0,0xb5,0xd0,0xbd,0xd0,0xb8,0xd0,0xb5,0x20,0x2d,
    0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x2d,0x0a,0x28,
    0x29,0x20,0x20,0x5b,0x5d,0x20,0x20,0x2d,0x3e,0x20,
    0x20,0x2e,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,
    0x3e,0x0a,0x21,0x20,0x20,0x20,0x7e,0x20,0x20,0x20,
    0x2b,0x2b,0x20,0x20,0x2d,0x2d,0x20,0x20,0x2b,0x20,
    0x20,0x2d,0x20,0x20,0x2a,0x20,0x20,0x26,0x20,0x20,
    0x28,0x74,0x79,0x70,0x65,0x29,0x20,0x20,0x73,0x69,
    0x7a,0x65,0x6f,0x66,0x20,0x20,0x20,0x20,0x20,0x20,
    0x2d,0x2d,0x2d,0x3e,0x0a,0x2a,0x20,0x20,0x2f,0x20,
    0x20,0x25,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x2b,0x20,
    0x20,0x2d,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,
    0x0a,0x3c,0x3c,0x20,0x20,0x3e,0x3e,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,
    0x2d,0x2d,0x3e,0x0a,0x3c,0x20,0x20,0x3c,0x3d,0x20,
    0x20,0x3e,0x20,0x20,0x3e,0x3d,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x3d,0x3d,0x20,
    0x20,0x21,0x3d,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,
    0x26,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,
    0x2d,0x3e,0x0a,0x5e,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x7c,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a,0x26,
    0x26,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x2d,0x2d,0x2d,
    0x3e,0x0a,0x7c,0x7c,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x2d,0x2d,0x2d,0x3e,0x0a,0x3f,0x3a,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x3c,0x2d,0x2d,0x2d,0x20,0x20,0x20,
    0x0a,0x3d,0x20,0x20,0x2b,0x3d,0x20,0x20,0x2d,0x3d,
    0x20,0x20,0x2f,0x3d,0x20,0x20,0x25,0x3d,0x20,0x20,
    0x26,0x3d,0x20,0x20,0x5e,0x3d,0x20,0x20,0x7c,0x3d,
    0x20,0x20,0x3c,0x3c,0x3d,0x20,0x20,0x3e,0x3e,0x3d,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,
    0x2d,0x2d,0x2d,0x0a,0x2c,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
    0x20,0x20,0x2d,0x2d,0x2d,0x3e,0x0a
};
#endif

struct iconv_data
{
    int len;
    char *name;
    char *data;
};

#define CONVERSIONS 3

struct iconv_data data[] = 
{
#ifdef _ICONV_CONVERTER_ISO_8859_5
    {sizeof(iso_8859_5), "ISO-8859-5", (char *)iso_8859_5},
#endif
#ifdef _ICONV_CONVERTER_KOI8_R
    {sizeof(koi8_r), "KOI8-R", (char *)koi8_r},
#endif
#ifdef _ICONV_CONVERTER_UTF_8
    {sizeof(utf8), "UTF-8", (char *)utf8},
#endif
    {0, NULL, NULL}
};

#define OUTBUF_LEN 1500
char ob[OUTBUF_LEN];

iconv_t descs[CONVERSIONS*CONVERSIONS];

#define ERROR 0

int main(int argc, char **argv)
{
    int i, j, k, d = 0;
    size_t n;
    char *outbuf, *inbuf;
    int conversions = sizeof(data)/sizeof(struct iconv_data) - 1;

    puts("RU iconv test");
    
    for (i = 0; i < conversions; i++)
    {
        for (j = 0; j < conversions; j++)
	{
	    descs[d] = iconv_open(data[j].name, data[i].name);
	    if (descs[d++] == (iconv_t)-1)
	    {
	        printf("iconv_open(%s, %s)\n", data[i].name, data[j].name);
	        perror("");
                CHECK(ERROR);
	    }
	}
    }
    
    d = 0;
    for (i = 0; i < conversions; i++)
    {
        for (j = 0; j < conversions; j++)
	{
	    size_t inbytes = data[i].len;
	    size_t outbytes = OUTBUF_LEN;
	    inbuf = data[i].data;
	    outbuf = (char *)ob;

	    if (iconv(descs[d], NULL, NULL, (char **)&outbuf, &outbytes)                                                                       == (size_t)-1)
            {
                perror("Can't reset shift state");
                CHECK(ERROR);
            }
	    
            n = iconv(descs[d++], (const char **)&(inbuf), &inbytes, 
	                          (char **)&outbuf, &outbytes);
            if (n == (size_t)-1)
            {
	        printf("Conversion from %s to %s FAILED - iconv() "
                       "returned -1\n", data[i].name, data[j].name);
		perror("");
                CHECK(ERROR);
            }
	    
	    if (data[j].len != OUTBUF_LEN - outbytes)
	    {
                printf("Conversion from %s to %s FAILED",
                       data[i].name, data[j].name);
	        printf(" - bad output buffer length (%d instead of %d)\n",
		       OUTBUF_LEN - outbytes, data[j].len);
                CHECK(ERROR);
	    }
	    
	    for (k = 0; k < data[j].len; k++)
	    {
	        if (ob[k] != data[j].data[k])
		{
                    printf("Conversion from %s to %s FAILED",
                           data[i].name, data[j].name);
   	            printf("Error: byte %d is wrong\n", k);
		    printf("outbuf value: %#x, inbuf value %#x, "
		           "right value: %#x\n",
          	           (int)ob[k], (int)(data[i].data[k]), 
		           (int)(data[j].data[k]));
                    CHECK(ERROR);
		}
	    }

	    printf("iconv from %s to %s was successfully done\n",
                   data[i].name, data[j].name); 
            
	}
    }
    
    d = 0;
    for (i = 0; i < conversions; i++)
        for (j = 0; j < conversions; j++)
            CHECK(iconv_close(descs[d++]) != -1);

    exit(0);
}

#else /* #if defined(_ICONV_CONVERTER_UTF_8) || ... */
int main(int argc, char **argv)
{
    puts("None of ISO-8859-5, KOI8-R and UTF-8 converters linked, SKIP test");
    exit(0);
}
#endif /* #if defined(_ICONV_CONVERTER_UTF_8) || ... */

#else /* #ifdef _ICONV_ENABLED */
int main(int argc, char **argv)
{
    puts("iconv library is disabled, SKIP test");
    exit(0);
}
#endif /* #ifdef _ICONV_ENABLED */