1 /* Copyright 2011 Kevin Ryde
2
3 This file is part of X11-Protocol-Other.
4
5 X11-Protocol-Other is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your option)
8 any later version.
9
10 X11-Protocol-Other is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>. */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <locale.h>
21 #include <string.h>
22 #include <X11/Xlib.h>
23 #include <X11/Xutil.h>
24
25 int
main(void)26 main (void)
27 {
28 Display *display;
29 static XTextProperty text_prop;
30 FILE *fp;
31 char buf[128];
32 int good = 1;
33 int count = 0;
34
35 display = XOpenDisplay(NULL);
36 if (! display) { printf ("cannot open DISPLAY\n"); abort(); }
37
38 fp = fopen ("../tempfile.txt","r");
39 if (! fp) { printf ("cannot open tempfile.utf8\n"); abort(); }
40
41 while (fgets (buf, 128, fp)) {
42 char *part;
43 int blen = 0;
44 int u;
45 char bytes[128];
46 int ret;
47 char **tlist;
48 int tcount;
49 char utf8[128];
50 int utf8len = 0;
51
52 count++;
53 part = strtok (buf, " ");
54 u = strtol (part, NULL, 0);
55 /* printf ("U+%04X\n", u); */
56
57 while ((part = strtok (NULL, " "))) {
58 bytes[blen++] = strtol (part, NULL, 16);
59 }
60 bytes[blen] = '\0';
61 /* printf ("blen %d\n", blen); */
62
63
64 fgets (buf, 128, fp);
65 part = strtok (buf, " ");
66 utf8[utf8len++] = strtol (part, NULL, 16);
67 while ((part = strtok (NULL, " "))) {
68 utf8[utf8len++] = strtol (part, NULL, 16);
69 }
70 utf8[utf8len] = '\0';
71
72
73
74 text_prop.encoding = XInternAtom(display,"COMPOUND_TEXT",0);
75 text_prop.format = 8;
76 text_prop.nitems = blen;
77 text_prop.value = (unsigned char *) bytes;
78
79 ret = Xutf8TextPropertyToTextList (display,
80 &text_prop,
81 &tlist,
82 &tcount);
83 if (ret != Success) {
84 int i;
85 printf ("U+%04X\n", u);
86 printf (" Xutf8TextPropertyToTextList ret %d\n", ret);
87
88 printf (" bytes ");
89 for (i = 0; i < blen; i++) {
90 printf (" %02X", (int) (unsigned char) bytes[i]);
91 }
92 printf ("\n");
93 continue;
94 }
95
96 if (strcmp (utf8, tlist[0]) != 0) {
97 int i;
98 printf ("U+%04X\n", u);
99 printf (" Xutf8TextPropertyToTextList different\n");
100
101 printf (" got utf8 ");
102 for (i = 0; i < strlen(tlist[0]); i++) {
103 printf (" %02X", (int) (unsigned char) tlist[0][i]);
104 }
105 printf ("\n");
106
107 printf (" want utf8 ");
108 for (i = 0; i < utf8len; i++) {
109 printf (" %02X", (int) (unsigned char) utf8[i]);
110 }
111 printf ("\n");
112 }
113 }
114
115 printf ("total count %d\n", count);
116 if (! good) {
117 abort();
118 }
119
120 return 0;
121 }
122
123 /* printf ("text nitems %lu\n", text_prop.nitems); */
124 /* printf ("text value: "); */
125