Debian Codegraph @

terps/tads/tads3/test/test_chr.cpp

raw symbols SCIP
1 #ifdef RCSID
2 static char RCSid[] =
3 "$Header: d:/cvsroot/tads/tads3/test/test_chr.cpp,v 1.2 1999/05/17 02:52:31 MJRoberts Exp $";
4 #endif
5
6 /*
7 * Copyright (c) 1998, 2002 Michael J. Roberts. All Rights Reserved.
8 *
9 * Please see the accompanying license file, LICENSE.TXT, for information
10 * on using and copying this software.
11 */
12 /*
13 Name
14 test_chr.cpp - character mapper test
15 Function
16
17 Notes
18
19 Modified
20 10/17/98 MJRoberts - Creation
21 */
22
23 #include "charmap.h"
24 #include "resload.h"
25 #include "vmimage.h"
26 #include "t3test.h"
27
28 int main(int argc, char **argv)
29 {
30 CResLoader *loader;
31 CCharmapToLocal *map;
32 static wchar_t teststr[] =
33 {
34 0xA9, /* copyright sign */
35 0xA1, /* inverted exclamation mark */
36 0xA2, /* cent sign */
37 0xD0, /* eth */
38 0x17A, /* small letter z with acute */
39 0x102, /* capital letter a with breve */
40 0x401, /* cyrillic capital letter IO */
41 0x622, /* arabic alef */
42 0x3B1, /* greek small alpha */
43 0x3B2, /* greek small beta */
44 0x30, /* digit 0 */
45 0x31, /* digit 1 */
46 0x32, /* digit 2 */
47 0x33, /* digit 3 */
48 0x34, /* digit 4 */
49 0x35, /* digit 5 */
50 0x36, /* digit 6 */
51 0x37, /* digit 7 */
52 0x38, /* digit 8 */
53 0x39, /* digit 9 */
54 0x41, /* capital A */
55 0x42, /* capital B */
56 0x43, /* capital C */
57 0x44, /* capital D */
58 0x45, /* capital E */
59 0x2248, /* almost equal sign */
60 0x2264, /* less than or equal to sign */
61 0
62 };
63 char buf[256];
64 char mapbuf[256];
65 utf8_ptr up;
66 size_t len;
67 size_t i;
68 char pathbuf[OSFNMAX];
69
70 /* initialize for testing */
71 test_init();
72
73 /* create a resource loader */
74 os_get_special_path(pathbuf, sizeof(pathbuf), argv[0], OS_GSP_T3_RES);
75 loader = new CResLoader(pathbuf);
76
77 /* create a single-byte translator and load it with DOS code page 437 */
78 map = CCharmapToLocal::load(loader, "charmap/cp437");
79 if (map == 0)
80 {
81 printf("unable to load cp437 mapping file\n");
82 exit(1);
83 }
84
85 /* create a UTF-8 string to map */
86 up.set(buf);
87 up.setwcharsz(teststr, sizeof(buf));
88
89 /* check how much space we need */
90 up.set(buf);
91 len = map->map_utf8z(0, 0, up);
92 printf("space needed for mapping to cp437: %lu\n", (unsigned long)len);
93
94 /* map it for real this time */
95 map->map_utf8z(mapbuf, sizeof(mapbuf), up);
96
97 /* display the result */
98 for (i = 0 ; i < len ; ++i)
99 printf("%02x ", (unsigned char)mapbuf[i]);
100 printf("\n");
101
102 printf("%s\n", mapbuf);
103
104 /* success */
105 exit(0);
106 }
107