| 1 |
/* |
| 2 |
* The contents of this file are subject to the Interbase Public |
| 3 |
* License Version 1.0 (the "License"); you may not use this file |
| 4 |
* except in compliance with the License. You may obtain a copy |
| 5 |
* of the License at http://www.Inprise.com/IPL.html |
| 6 |
* |
| 7 |
* Software distributed under the License is distributed on an |
| 8 |
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express |
| 9 |
* or implied. See the License for the specific language governing |
| 10 |
* rights and limitations under the License. |
| 11 |
* |
| 12 |
* The Original Code was created by Inprise Corporation |
| 13 |
* and its predecessors. Portions created by Inprise Corporation are |
| 14 |
* Copyright (C) Inprise Corporation. |
| 15 |
* |
| 16 |
* All Rights Reserved. |
| 17 |
* Contributor(s): ______________________________________. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "firebird.h" |
| 21 |
|
| 22 |
|
| 23 |
/* |
| 24 |
fixed |
| 25 |
#include "cs_w1254.h" |
| 26 |
#include "cs_cyrl.h" |
| 27 |
#include "cs_865.h" |
| 28 |
#include "cs_863.h" |
| 29 |
#include "cs_861.h" |
| 30 |
#include "cs_860.h" |
| 31 |
#include "cs_857.h" |
| 32 |
#include "cs_w1251.h" |
| 33 |
#include "cs_437.h" |
| 34 |
#include "cs_850.h" |
| 35 |
#include "cs_852.h" |
| 36 |
#include "cs_w1250.h" |
| 37 |
#include "cs_w1252.h" |
| 38 |
#include "cs_w1253.h" |
| 39 |
|
| 40 |
fixed with errors |
| 41 |
#include "cs_next.h" -- NeXT has two characters mapping to the same |
| 42 |
Unicode (FE & FF). So round trip is not possible. |
| 43 |
They map to FFFD, which is the replacement character |
| 44 |
so this is not an error |
| 45 |
|
| 46 |
No errors |
| 47 |
#include "../intl/cs_iso8859_1.h" |
| 48 |
*/ |
| 49 |
|
| 50 |
/* |
| 51 |
-- Multibyte character sets -- |
| 52 |
#include "../intl/cs_big5.h" |
| 53 |
#include "../intl/cs_gb2312.h" |
| 54 |
#include "../intl/cs_jis_0208_1990.h" |
| 55 |
#include "../intl/cs_ksc5601.h" |
| 56 |
#include "../intl/csjis2_p.h" |
| 57 |
*/ |
| 58 |
|
| 59 |
|
| 60 |
#define UNICODE_INDEX(u) (((u) % 256) + from_unicode_map [((u) / 256)]) |
| 61 |
#define UNICODE_LOOKUP(u) from_unicode_mapping_array [ UNICODE_INDEX(u) ] |
| 62 |
|
| 63 |
int main() |
| 64 |
{ |
| 65 |
if (sizeof(to_unicode_map) != 256 * sizeof(to_unicode_map[0])) |
| 66 |
printf("The to_unicode_map is too small! %d entries!\n", |
| 67 |
sizeof(to_unicode_map) / sizeof(to_unicode_map[0])); |
| 68 |
|
| 69 |
if (sizeof(from_unicode_map) != 256 * sizeof(from_unicode_map[0])) |
| 70 |
printf("The from_unicode_map is too small! %d entries!\n", |
| 71 |
sizeof(from_unicode_map) / sizeof(from_unicode_map[0])); |
| 72 |
|
| 73 |
for (int i = 0; i <= 255; i++) |
| 74 |
{ |
| 75 |
const unsigned short uch = to_unicode_map[i]; |
| 76 |
if (uch == CANT_MAP_CHARACTER) |
| 77 |
continue; |
| 78 |
const unsigned char ch2 = UNICODE_LOOKUP(uch); |
| 79 |
if (ch2 != i) |
| 80 |
{ |
| 81 |
printf("Mapping error: Character %02x -> Unicode %04x (index %3d) -> Char %02x\n", |
| 82 |
i, uch, UNICODE_INDEX(uch), ch2); |
| 83 |
|
| 84 |
// Find the Character in the from_unicode_mapping_array |
| 85 |
int j; |
| 86 |
for (j = 0; j < sizeof(from_unicode_mapping_array); j++) |
| 87 |
{ |
| 88 |
if (from_unicode_mapping_array[j] == i) |
| 89 |
{ |
| 90 |
// Mapping table is wrong - recommend a fix for it |
| 91 |
printf("Recommend from_unicode_map[0x%02x] be set to %d\n", |
| 92 |
uch / 256, j - (uch % 256)); |
| 93 |
break; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
if (j == sizeof(from_unicode_mapping_array)) |
| 98 |
{ |
| 99 |
// Oops - found a character that does exists in the character set |
| 100 |
// but not in unicode - an obvious error! |
| 101 |
|
| 102 |
printf("Error: Character %d does not exist in the from_unicode_mapping_array\n", i); |
| 103 |
|
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
for (int i = 0; i <= 255; i++) |
| 109 |
{ |
| 110 |
if (from_unicode_map[i] + 0xFF >= sizeof(from_unicode_mapping_array)) |
| 111 |
{ |
| 112 |
printf("From_unicode array bounds error at position %02x00\n", i); |
| 113 |
continue; |
| 114 |
} |
| 115 |
|
| 116 |
for (int j = 0; j <= 255; j++) |
| 117 |
{ |
| 118 |
const unsigned short uch = i * 256 + j; |
| 119 |
const unsigned char ch2 = UNICODE_LOOKUP(uch); |
| 120 |
if (ch2 == CANT_MAP_CHARACTER) |
| 121 |
continue; |
| 122 |
const unsigned short uch2 = to_unicode_map[ch2]; |
| 123 |
if (uch != uch2) |
| 124 |
{ |
| 125 |
printf("Mapping error: Unicode %04x -> ch %02x -> Unicode %04x\n", |
| 126 |
uch, ch2, uch2); |
| 127 |
|
| 128 |
int k; |
| 129 |
for (k = 0; k <= 255; k++) |
| 130 |
if (to_unicode_map[k] == uch) { |
| 131 |
// Can map this character from charset to unicode |
| 132 |
// Assume fix was printed out above |
| 133 |
} |
| 134 |
if (k > 255) { |
| 135 |
// This unicode doesn't exist in charset |
| 136 |
// Mapping table is wrong - recommend a fix for it |
| 137 |
printf("Recommend from_unicode_map[0x%02x] be set to %d\n", uch / 256, 0); |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
printf("Test completed\n"); |
| 144 |
return 0; |
| 145 |
} |
| 146 |
|