1 /* $Header: /cvsroot/lesstif/lesstif/test/Xm/xmstring/test5.c,v 1.3 2002/04/17 16:32:01 amai Exp $ */
2
3 #include <stdlib.h>
4 #include <stdio.h>
5
6 #include <Xm/XmP.h>
7
8 #ifdef LESSTIF_VERSION
9 typedef struct __XmStringRec {
10 unsigned char tag;
11 unsigned char len;
12 unsigned char data[1];
13 } XmStringRec;
14
15 struct __XmStringContextRec {
16 struct __XmStringRec *string;
17 unsigned char data[4];
18 };
19
20 #define XmSTRING_COMPONENT_XMSTRING (XmSTRING_COMPONENT_LOCALE_TEXT + 1)
21 #define XmSTRING_TAG 0xDFU
22 #define XmSTRING_LENGTH 0x80U
23
24
25 int
asn1_dump(unsigned char * string)26 asn1_dump(unsigned char *string)
27 {
28 unsigned length, i, nlen, j;
29 struct __XmStringRec *str = (struct __XmStringRec *)string;
30 unsigned char *next;
31
32 printf("STRING: TAG: %02x LEN: %02x\n", str->tag, str->len);
33 fflush(stdout);
34
35 if (str->tag != XmSTRING_TAG || str->len != XmSTRING_LENGTH) {
36 printf("IS NOT AN XmSTRING\n");
37 fflush(stdout);
38 return 0;
39 }
40
41 next = str->data;
42 str = (struct __XmStringRec *)next;
43
44 if (str->tag != XmSTRING_COMPONENT_XMSTRING) {
45 printf("IS NOT AN XmSTRING: %d\n", __LINE__);
46 fflush(stdout);
47 return 0;
48 }
49
50 length = 0;
51
52 if (str->len > XmSTRING_LENGTH) {
53
54 for (i = 0; i < (str->len & ~XmSTRING_LENGTH); i++) {
55 length <<= 8;
56 length |= str->data[i];
57 if (i > sizeof(unsigned)) {
58 printf("Invalid XmString\n");
59 fflush(stdout);
60 exit (0);
61 }
62 }
63 }
64 else {
65 i = 0;
66 length = str->len & ~XmSTRING_LENGTH;
67 }
68
69 next = &str->data[i];
70
71 if (length < 0) {
72 printf("String is malformed\n");
73 fflush(stdout);
74 return 0;
75 }
76 else if (length == 0)
77 return 0;
78
79 for (;;) {
80 str = (struct __XmStringRec *)next;
81
82 /* primitive type -- doesn't recurse */
83 nlen = 0;
84
85 if (str->len > XmSTRING_LENGTH) {
86
87 for (i = 0; i < (str->len & ~XmSTRING_LENGTH); i++) {
88 nlen <<= 8;
89 nlen |= str->data[i];
90 if (i > sizeof(unsigned)) {
91 printf("Invalid XmString\n");
92 fflush(stdout);
93 exit (0);
94 }
95 }
96 }
97 else {
98 i = 0;
99 nlen = str->len & ~XmSTRING_LENGTH;
100 }
101
102 switch (str->tag) {
103 case XmSTRING_COMPONENT_UNKNOWN:
104 printf("UNKNOWN COMPONENT: length %d\n", nlen);
105 fflush(stdout);
106 break;
107
108 case XmSTRING_COMPONENT_CHARSET:
109 printf("CHARSET:\n");
110 fflush(stdout);
111 for (j = 0; j < nlen; j++)
112 putchar(str->data[i + j]);
113 putchar('\n');
114 fflush(stdout);
115 nlen += i + 2;
116 break;
117
118 case XmSTRING_COMPONENT_TEXT:
119 printf("TEXT: %d\n", nlen);
120 fflush(stdout);
121 for (j = 0; j < nlen; j++)
122 putchar(str->data[i + j]);
123 putchar('\n');
124 fflush(stdout);
125 nlen += i + 2;
126 break;
127
128 case XmSTRING_COMPONENT_DIRECTION:
129 printf("DIRECTION: %d\n", nlen);
130 fflush(stdout);
131 for (j = 0; j < nlen; j++)
132 printf("%d ", str->data[i + j]);
133 putchar('\n');
134 fflush(stdout);
135 nlen += i + 2;
136 break;
137
138 case XmSTRING_COMPONENT_SEPARATOR:
139 printf("SEPARATOR: %d\n", nlen);
140 fflush(stdout);
141 for (j = 0; j < nlen; j++)
142 printf("%d ", str->data[i + j]);
143 putchar('\n');
144 fflush(stdout);
145 nlen += i + 2;
146 break;
147
148 case XmSTRING_COMPONENT_LOCALE_TEXT:
149 printf("LOCALE TEXT: %d\n", nlen);
150 fflush(stdout);
151 for (j = 0; j < nlen; j++)
152 putchar(str->data[i + j]);
153 putchar('\n');
154 fflush(stdout);
155 nlen += i + 2;
156 break;
157 default:
158 printf("invalid tag: %02x\n", str->tag);
159 fflush(stdout);
160 nlen = 1;
161 }
162
163 next += nlen;
164 length -= nlen;
165 if (length < 0) {
166 printf("String is malformed\n");
167 fflush(stdout);
168 return 0;
169 }
170 else if (length == 0)
171 return 0;
172 }
173 }
174 #endif
175
176 int
main(int argc,char ** argv)177 main(int argc,
178 char **argv)
179 {
180 #ifdef LESSTIF_VERSION
181 Widget toplevel;
182 XtAppContext app;
183 Dimension width, height;
184 XmFontList fl;
185 XmString xmstr, xmstr1, xmstr2, xmstr3, xmstr4, xmstr5, xmstr6, xmstr7;
186 XmFontList fontlist;
187 char buf[] = { 0xdf, 0x80, 0x06, 0x00, 0x01, 0x00 };
188
189 printf("SIZEOF CONTEXT: %d\n", sizeof(struct __XmStringContextRec));
190 fflush(stdout);
191
192 toplevel = XtVaAppInitialize(&app, "XmString", NULL, 0, &argc, argv, NULL, NULL);
193
194 fl = _XmGetDefaultFontList(toplevel, XmTEXT_FONTLIST);
195
196 xmstr3 = XmStringSeparatorCreate();
197 asn1_dump((unsigned char *)xmstr3);
198 printf("*************************************************\n");
199 fflush(stdout);
200
201
202 xmstr = XmStringCreateSimple("Hello World this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test this is a long test");
203 asn1_dump((unsigned char *)xmstr);
204 printf("*************************************************\n");
205 fflush(stdout);
206
207 xmstr2 = XmStringCreateLtoR("H�llo\nW�rld", XmFONTLIST_DEFAULT_TAG);
208 asn1_dump((unsigned char *)xmstr2);
209 printf("*************************************************\n");
210 fflush(stdout);
211
212 xmstr4 = XmStringDirectionCreate(XmSTRING_DIRECTION_R_TO_L);
213 asn1_dump((unsigned char *)xmstr4);
214 printf("@@@@@@@@*************************************************\n");
215 fflush(stdout);
216
217 xmstr5 = XmStringSegmentCreate("Hello World", XmFONTLIST_DEFAULT_TAG,
218 XmSTRING_DIRECTION_R_TO_L, True);
219 asn1_dump((unsigned char *)xmstr5);
220 printf("#######*************************************************\n");
221 fflush(stdout);
222
223 xmstr6 = XmStringCreate("Hello World", XmFONTLIST_DEFAULT_TAG);
224 asn1_dump((unsigned char *)xmstr6);
225 printf("*************************************************\n");
226 fflush(stdout);
227
228 xmstr7 = XmStringCreateLocalized("Hello World");
229 asn1_dump((unsigned char *)xmstr7);
230 printf("*************************************************\n");
231 fflush(stdout);
232
233 XmStringExtent(fl, xmstr, &width, &height);
234
235 printf ("String 'Hello World' has dimensions %dx%d\n", width, height);
236
237 XmStringExtent(fl, xmstr2, &width, &height);
238
239 printf ("String 'Hello\\nWorld' has dimensions %dx%d\n", width, height);
240
241 xmstr1 = XmStringCreate("Here is a ", "MY_FONT1");
242 xmstr2 = XmStringCreate("different font", "MY_FONT");
243 xmstr = XmStringConcat(xmstr1, xmstr2);
244
245 fontlist = XmFontListAppendEntry(NULL,
246 XmFontListEntryCreate("MY_FONT",
247 XmFONT_IS_FONT,
248 XLoadQueryFont(XtDisplay(toplevel),
249 "-adobe-helvetica-bold-o-normal--17-0-75-75-p-*-iso8859-1")));
250
251 fontlist = XmFontListAppendEntry(fontlist,
252 XmFontListEntryCreate("MY_FONT1",
253 XmFONT_IS_FONT,
254 XLoadQueryFont(XtDisplay(toplevel),
255 "-adobe-helvetica-bold-r-normal--17-0-75-75-p-*-iso8859-1")));
256
257 asn1_dump((unsigned char *)xmstr);
258 printf("*************************************************\n");
259 fflush(stdout);
260
261 if (_XmStringIsXmString((XmString)buf))
262 printf("IS STRING\n");
263 else
264 printf("ISN'T STRING\n");
265
266 asn1_dump((unsigned char *)buf);
267 printf("*************************************************\n");
268 fflush(stdout);
269
270 #endif
271 exit(0);
272 }
273