source: trunk/pin/src/ppdenc.c@ 2

Last change on this file since 2 was 2, checked in by bart, 18 years ago

addition of ppdenc
modify makefile accordingly

File size: 56.4 KB
Line 
1/*DDK*************************************************************************/
2/* */
3/* COPYRIGHT Copyright (C) 1991, 2003 IBM Corporation */
4/* */
5/* The following IBM OS/2 source code is provided to you solely for */
6/* the purpose of assisting you in your development of OS/2 device */
7/* drivers. You may use this code in accordance with the IBM License */
8/* Agreement provided in the IBM Developer Connection Device Driver */
9/* Source Kit for OS/2. This Copyright statement may not be removed. */
10/* */
11/*****************************************************************************/
12/**************************************************************************
13 *
14 * SOURCE FILE NAME = PPDENC.C
15 *
16 * DESCRIPTIVE NAME = Convert PPD encoding to OS/2 codepage
17 *
18 *
19 * VERSION = V1.0
20 *
21 * DATE
22 *
23 * DESCRIPTION PPD Encoding converter main file.
24 *
25 *
26 * FUNCTIONS
27 *
28 *
29 *
30 * NOTES
31 *
32 *
33 * STRUCTURES
34 *
35 * EXTERNAL REFERENCES
36 *
37 * EXTERNAL FUNCTIONS
38 *
39
40 * bvl: Added UTF-8 Support, we simply substitute the ISOLatin table for it, supposedly the first 256 chars of UTF are ISOLatin, it at least solves our problems
41*/
42
43
44#include <os2.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <string.h>
48
49#include "listfls.h"
50
51//#define FALSE 0
52//#define TRUE 1
53
54
55
56#define CONVERT_ISOLATIN1 0
57#define CONVERT_WINDOWSANSI 1
58#define CONVERT_MAC 2
59#define CONVERT_UTF8 3
60#define CONVERT_UNKNOWN 1000
61
62
63char *MRI_LANG = NULL;
64
65
66// copy pathname from source to dest, and add trailing slash, if missing
67static
68void copy_pathname( char *dest, char *src)
69{
70 strcpy(dest,src);
71
72 // add slash as last character, if it's not present
73 if(dest[strlen(dest)-1]!='\\')
74 strcat(dest,"\\");
75}
76
77
78
79
80// charset conversion tables
81
82
83char FromIso[256] =
84{
85 /* Code */ /* source character name */ /* destionation code */
86 /* 0 */ /* -unused- */ 0x00,
87 /* 1 */ /* -unused- */ 0x01,
88 /* 2 */ /* -unused- */ 0x02,
89 /* 3 */ /* -unused- */ 0x03,
90 /* 4 */ /* -unused- */ 0x04,
91 /* 5 */ /* -unused- */ 0x05,
92 /* 6 */ /* -unused- */ 0x06,
93 /* 7 */ /* -unused- */ 0x07,
94 /* 8 */ /* -unused- */ 0x08,
95 /* 9 */ /* -unused- */ 0x09,
96 /* 10 */ /* -unused- */ 0x0A,
97 /* 11 */ /* -unused- */ 0x0B,
98 /* 12 */ /* -unused- */ 0x0C,
99 /* 13 */ /* -unused- */ 0x0D,
100 /* 14 */ /* -unused- */ 0x0E,
101 /* 15 */ /* -unused- */ 0x0F,
102 /* 16 */ /* -unused- */ 0x10,
103 /* 17 */ /* -unused- */ 0x11,
104 /* 18 */ /* -unused- */ 0x12,
105 /* 19 */ /* -unused- */ 0x13,
106 /* 20 */ /* -unused- */ 0x14,
107 /* 21 */ /* -unused- */ 0x15,
108 /* 22 */ /* -unused- */ 0x16,
109 /* 23 */ /* -unused- */ 0x17,
110 /* 24 */ /* -unused- */ 0x18,
111 /* 25 */ /* -unused- */ 0x19,
112 /* 26 */ /* -unused- */ 0x1A,
113 /* 27 */ /* -unused- */ 0x1B,
114 /* 28 */ /* -unused- */ 0x1C,
115 /* 29 */ /* -unused- */ 0x1D,
116 /* 30 */ /* -unused- */ 0x1E,
117 /* 31 */ /* -unused- */ 0x1F,
118 /* 32 */ /* space */ 0x20,
119 /* 33 */ /* exclam */ 0x21,
120 /* 34 */ /* quotedbl */ 0x22,
121 /* 35 */ /* numbersign */ 0x23,
122 /* 36 */ /* dollar */ 0x24,
123 /* 37 */ /* percent */ 0x25,
124 /* 38 */ /* ampersand */ 0x26,
125 /* 39 x*/ /* quoteright */ 0x27,
126 /* 40 */ /* parenleft */ 0x28,
127 /* 41 */ /* parenright */ 0x29,
128 /* 42 */ /* asterisk */ 0x2A,
129 /* 43 */ /* plus */ 0x2B,
130 /* 44 */ /* comma */ 0x2C,
131 /* 45 x*/ /* minus */ 0x2D,
132 /* 46 */ /* period */ 0x2E,
133 /* 47 */ /* slash */ 0x2F,
134 /* 48 */ /* zero */ 0x30,
135 /* 49 */ /* one */ 0x31,
136 /* 50 */ /* two */ 0x32,
137 /* 51 */ /* three */ 0x33,
138 /* 52 */ /* four */ 0x34,
139 /* 53 */ /* five */ 0x35,
140 /* 54 */ /* six */ 0x36,
141 /* 55 */ /* seven */ 0x37,
142 /* 56 */ /* eight */ 0x38,
143 /* 57 */ /* nine */ 0x39,
144 /* 58 */ /* colon */ 0x3A,
145 /* 59 */ /* semicolon */ 0x3B,
146 /* 60 */ /* less */ 0x3C,
147 /* 61 */ /* equal */ 0x3D,
148 /* 62 */ /* greater */ 0x3E,
149 /* 63 */ /* question */ 0x3F,
150 /* 64 */ /* at */ 0x40,
151 /* 65 */ /* A */ 0x41,
152 /* 66 */ /* B */ 0x42,
153 /* 67 */ /* C */ 0x43,
154 /* 68 */ /* D */ 0x44,
155 /* 69 */ /* E */ 0x45,
156 /* 70 */ /* F */ 0x46,
157 /* 71 */ /* G */ 0x47,
158 /* 72 */ /* H */ 0x48,
159 /* 73 */ /* I */ 0x49,
160 /* 74 */ /* J */ 0x4A,
161 /* 75 */ /* K */ 0x4B,
162 /* 76 */ /* L */ 0x4C,
163 /* 77 */ /* M */ 0x4D,
164 /* 78 */ /* N */ 0x4E,
165 /* 79 */ /* O */ 0x4F,
166 /* 80 */ /* P */ 0x50,
167 /* 81 */ /* Q */ 0x51,
168 /* 82 */ /* R */ 0x52,
169 /* 83 */ /* S */ 0x53,
170 /* 84 */ /* T */ 0x54,
171 /* 85 */ /* U */ 0x55,
172 /* 86 */ /* V */ 0x56,
173 /* 87 */ /* W */ 0x57,
174 /* 88 */ /* X */ 0x58,
175 /* 89 */ /* Y */ 0x59,
176 /* 90 */ /* Z */ 0x5A,
177 /* 91 */ /* bracketleft */ 0x5B,
178 /* 92 */ /* backslash */ 0x5C,
179 /* 93 */ /* bracketright */ 0x5D,
180 /* 94 */ /* asciicircum */ 0x5E,
181 /* 95 */ /* underscore */ 0x5F,
182 /* 96 x*/ /* quoteleft */ 0x60,
183 /* 97 */ /* a */ 0x61,
184 /* 98 */ /* b */ 0x62,
185 /* 99 */ /* c */ 0x63,
186 /* 100 */ /* d */ 0x64,
187 /* 101 */ /* e */ 0x65,
188 /* 102 */ /* f */ 0x66,
189 /* 103 */ /* g */ 0x67,
190 /* 104 */ /* h */ 0x68,
191 /* 105 */ /* i */ 0x69,
192 /* 106 */ /* j */ 0x6A,
193 /* 107 */ /* k */ 0x6B,
194 /* 108 */ /* l */ 0x6C,
195 /* 109 */ /* m */ 0x6D,
196 /* 110 */ /* n */ 0x6E,
197 /* 111 */ /* o */ 0x6F,
198 /* 112 */ /* p */ 0x70,
199 /* 113 */ /* q */ 0x71,
200 /* 114 */ /* r */ 0x72,
201 /* 115 */ /* s */ 0x73,
202 /* 116 */ /* t */ 0x74,
203 /* 117 */ /* u */ 0x75,
204 /* 118 */ /* v */ 0x76,
205 /* 119 */ /* w */ 0x77,
206 /* 120 */ /* x */ 0x78,
207 /* 121 */ /* y */ 0x79,
208 /* 122 */ /* z */ 0x7A,
209 /* 123 */ /* braceleft */ 0x7B,
210 /* 124 */ /* bar */ 0x7C,
211 /* 125 */ /* braceright */ 0x7D,
212 /* 126 */ /* asciitilde */ 0x7E,
213 /* 127 */ /* -unused- */ 0x7F,
214 /* 128 */ /* -unused- */ 0x80,
215 /* 129 */ /* -unused- */ 0x81,
216 /* 130 */ /* -unused- */ 0x82,
217 /* 131 */ /* -unused- */ 0x83,
218 /* 132 */ /* -unused- */ 0x84,
219 /* 133 */ /* -unused- */ 0x85,
220 /* 134 */ /* -unused- */ 0x86,
221 /* 135 */ /* -unused- */ 0x87,
222 /* 136 */ /* -unused- */ 0x88,
223 /* 137 */ /* -unused- */ 0x89,
224 /* 138 */ /* -unused- */ 0x90,
225 /* 139 */ /* -unused- */ 0x91,
226 /* 140 */ /* -unused- */ 0x92,
227 /* 141 */ /* -unused- */ 0x93,
228 /* 142 */ /* -unused- */ 0x94,
229 /* 143 */ /* -unused- */ 0x95,
230
231// unclear
232 /* 144 x*/ /* dotlessi */ 0x96,
233 /* 145 */ /* grave */ 0x60,
234 /* 146 */ /* acute */ 0xEF,
235 /* 147 x*/ /* circumflex */ 0x99,
236 /* 148 x*/ /* tilde */ 0x9A,
237 /* 149 x*/ /* macron */ 0x9B,
238 /* 150 x*/ /* breve */ 0x9C,
239 /* 151 x*/ /* dotaccent */ 0x9E,
240 /* 152 */ /* dieresis */ 0xF9,
241 /* 153 */ /* -unused- */ 0xA0,
242 /* 154 x*/ /* ring */ 0xA1,
243 /* 155 */ /* cedilla */ 0xF7,
244 /* 156 */ /* -unused- */ 0xA3,
245 /* 157 x*/ /* hungarumlaut */ 0xA4,
246 /* 158 x*/ /* ogonek */ 0xA5,
247 /* 159 x*/ /* caron */ 0xA6,
248 /* 160 */ /* space [reqspace] */ 0xFF,
249// unclear
250
251 /* 161 */ /* exclamdown */ 0xAD,
252 /* 162 */ /* cent */ 0xBD,
253 /* 163 */ /* sterling */ 0x9C,
254 /* 164 */ /* currency */ 0xCF,
255 /* 165 */ /* yen */ 0xBE,
256 /* 166 */ /* brokenbar */ 0xDD,
257 /* 167 */ /* section */ 0xF5,
258 /* 168 */ /* dieresis */ 0xF9,
259 /* 169 */ /* copyright */ 0xB8,
260 /* 170 */ /* ordfeminine */ 0xA6,
261 /* 171 */ /* guillemotleft */ 0xAE,
262 /* 172 */ /* logicalnot */ 0xAA,
263 /* 173 */ /* hyphen [syllable] */ 0xF0,
264 /* 174 */ /* registered */ 0xA9,
265 /* 175 */ /* macron [overline] */ 0xEE,
266 /* 176 */ /* degree */ 0xF8,
267 /* 177 */ /* plusminus */ 0xF1,
268 /* 178 */ /* twosuperior */ 0xFD,
269 /* 179 */ /* threesuperior */ 0xFC,
270 /* 180 */ /* acute */ 0xEF,
271 /* 181 */ /* mu */ 0xE6,
272 /* 182 */ /* paragraph */ 0xF4,
273 /* 183 */ /* periodcentered */ 0xFA,
274 /* 184 */ /* cedilla */ 0xF7,
275 /* 185 */ /* onesuperior */ 0xFB,
276 /* 186 */ /* ordmasculine */ 0xA7,
277 /* 187 */ /* guillemotright */ 0xAF,
278 /* 188 */ /* onequarter */ 0xAC,
279 /* 189 */ /* onehalf */ 0xAB,
280 /* 190 */ /* threequarters */ 0xF3,
281 /* 191 */ /* questiondown */ 0xA8,
282 /* 192 */ /* Agrave */ 0xB7,
283 /* 193 */ /* Aacute */ 0xB5,
284 /* 194 */ /* Acircumflex */ 0xB6,
285 /* 195 */ /* Atilde */ 0xC7,
286 /* 196 */ /* Adieresis */ 0x8E,
287 /* 197 */ /* Aring */ 0x8F,
288 /* 198 */ /* AE */ 0x92,
289 /* 199 */ /* Ccedilla */ 0x80,
290 /* 200 */ /* Egrave */ 0xD4,
291 /* 201 */ /* Eacute */ 0x90,
292 /* 202 */ /* Ecircumflex */ 0xD2,
293 /* 203 */ /* Edieresis */ 0xD3,
294 /* 204 */ /* Igrave */ 0xDE,
295 /* 205 */ /* Iacute */ 0xD6,
296 /* 206 */ /* Icircumflex */ 0xD7,
297 /* 207 */ /* Idieresis */ 0xD8,
298 /* 208 */ /* Eth */ 0xD1,
299 /* 209 */ /* Ntilde */ 0xA5,
300 /* 210 */ /* Ograve */ 0xE3,
301 /* 211 */ /* Oacute */ 0xE0,
302 /* 212 */ /* Ocircumflex */ 0xE2,
303 /* 213 */ /* Otilde */ 0xE5,
304 /* 214 */ /* Odieresis */ 0x99,
305 /* 215 */ /* multiply */ 0x9E,
306 /* 216 */ /* Oslash */ 0x9D,
307 /* 217 */ /* Ugrave */ 0xEB,
308 /* 218 */ /* Uacute */ 0xE9,
309 /* 219 */ /* Ucircumflex */ 0xEA,
310 /* 220 */ /* Udieresis */ 0x9A,
311 /* 221 */ /* Yacute */ 0xED,
312 /* 222 */ /* Thorn */ 0xE8,
313 /* 223 */ /* germandbls */ 0xE1,
314 /* 224 */ /* agrave */ 0x85,
315 /* 225 */ /* aacute */ 0xA0,
316 /* 226 */ /* acircumflex */ 0x83,
317 /* 227 */ /* atilde */ 0xC6,
318 /* 228 */ /* adieresis */ 0x84,
319 /* 229 */ /* aring */ 0x86,
320 /* 230 */ /* ae */ 0x91,
321 /* 231 */ /* ccedilla */ 0x87,
322 /* 232 */ /* egrave */ 0x8A,
323 /* 233 */ /* eacute */ 0x82,
324 /* 234 */ /* ecircumflex */ 0x88,
325 /* 235 */ /* edieresis */ 0x89,
326 /* 236 */ /* igrave */ 0x8D,
327 /* 237 */ /* iacute */ 0xA1,
328 /* 238 */ /* icircumflex */ 0x8C,
329 /* 239 */ /* idieresis */ 0x8B,
330 /* 240 */ /* eth */ 0xD0,
331 /* 241 */ /* ntilde */ 0xA4,
332 /* 242 */ /* ograve */ 0x95,
333 /* 243 */ /* oacute */ 0xA2,
334 /* 244 */ /* ocircumflex */ 0x93,
335 /* 245 */ /* otilde */ 0xE4,
336 /* 246 */ /* odieresis */ 0x94,
337 /* 247 */ /* divide */ 0xF6,
338 /* 248 */ /* oslash */ 0x9B,
339 /* 249 */ /* ugrave */ 0x97,
340 /* 250 */ /* uacute */ 0xA3,
341 /* 251 */ /* ucircumflex */ 0x96,
342 /* 252 */ /* udieresis */ 0x81,
343 /* 253 */ /* yacute */ 0xEC,
344 /* 254 */ /* thorn */ 0xE7,
345 /* 255 */ /* ydieresis */ 0x98
346};
347
348char FromUTF8[256] =
349{
350 /* Code */ /* source character name */ /* destionation code */
351 /* 0 */ /* -unused- */ 0x00,
352 /* 1 */ /* -unused- */ 0x01,
353 /* 2 */ /* -unused- */ 0x02,
354 /* 3 */ /* -unused- */ 0x03,
355 /* 4 */ /* -unused- */ 0x04,
356 /* 5 */ /* -unused- */ 0x05,
357 /* 6 */ /* -unused- */ 0x06,
358 /* 7 */ /* -unused- */ 0x07,
359 /* 8 */ /* -unused- */ 0x08,
360 /* 9 */ /* -unused- */ 0x09,
361 /* 10 */ /* -unused- */ 0x0A,
362 /* 11 */ /* -unused- */ 0x0B,
363 /* 12 */ /* -unused- */ 0x0C,
364 /* 13 */ /* -unused- */ 0x0D,
365 /* 14 */ /* -unused- */ 0x0E,
366 /* 15 */ /* -unused- */ 0x0F,
367 /* 16 */ /* -unused- */ 0x10,
368 /* 17 */ /* -unused- */ 0x11,
369 /* 18 */ /* -unused- */ 0x12,
370 /* 19 */ /* -unused- */ 0x13,
371 /* 20 */ /* -unused- */ 0x14,
372 /* 21 */ /* -unused- */ 0x15,
373 /* 22 */ /* -unused- */ 0x16,
374 /* 23 */ /* -unused- */ 0x17,
375 /* 24 */ /* -unused- */ 0x18,
376 /* 25 */ /* -unused- */ 0x19,
377 /* 26 */ /* -unused- */ 0x1A,
378 /* 27 */ /* -unused- */ 0x1B,
379 /* 28 */ /* -unused- */ 0x1C,
380 /* 29 */ /* -unused- */ 0x1D,
381 /* 30 */ /* -unused- */ 0x1E,
382 /* 31 */ /* -unused- */ 0x1F,
383 /* 32 */ /* space */ 0x20,
384 /* 33 */ /* exclam */ 0x21,
385 /* 34 */ /* quotedbl */ 0x22,
386 /* 35 */ /* numbersign */ 0x23,
387 /* 36 */ /* dollar */ 0x24,
388 /* 37 */ /* percent */ 0x25,
389 /* 38 */ /* ampersand */ 0x26,
390 /* 39 x*/ /* quoteright */ 0x27,
391 /* 40 */ /* parenleft */ 0x28,
392 /* 41 */ /* parenright */ 0x29,
393 /* 42 */ /* asterisk */ 0x2A,
394 /* 43 */ /* plus */ 0x2B,
395 /* 44 */ /* comma */ 0x2C,
396 /* 45 x*/ /* minus */ 0x2D,
397 /* 46 */ /* period */ 0x2E,
398 /* 47 */ /* slash */ 0x2F,
399 /* 48 */ /* zero */ 0x30,
400 /* 49 */ /* one */ 0x31,
401 /* 50 */ /* two */ 0x32,
402 /* 51 */ /* three */ 0x33,
403 /* 52 */ /* four */ 0x34,
404 /* 53 */ /* five */ 0x35,
405 /* 54 */ /* six */ 0x36,
406 /* 55 */ /* seven */ 0x37,
407 /* 56 */ /* eight */ 0x38,
408 /* 57 */ /* nine */ 0x39,
409 /* 58 */ /* colon */ 0x3A,
410 /* 59 */ /* semicolon */ 0x3B,
411 /* 60 */ /* less */ 0x3C,
412 /* 61 */ /* equal */ 0x3D,
413 /* 62 */ /* greater */ 0x3E,
414 /* 63 */ /* question */ 0x3F,
415 /* 64 */ /* at */ 0x40,
416 /* 65 */ /* A */ 0x41,
417 /* 66 */ /* B */ 0x42,
418 /* 67 */ /* C */ 0x43,
419 /* 68 */ /* D */ 0x44,
420 /* 69 */ /* E */ 0x45,
421 /* 70 */ /* F */ 0x46,
422 /* 71 */ /* G */ 0x47,
423 /* 72 */ /* H */ 0x48,
424 /* 73 */ /* I */ 0x49,
425 /* 74 */ /* J */ 0x4A,
426 /* 75 */ /* K */ 0x4B,
427 /* 76 */ /* L */ 0x4C,
428 /* 77 */ /* M */ 0x4D,
429 /* 78 */ /* N */ 0x4E,
430 /* 79 */ /* O */ 0x4F,
431 /* 80 */ /* P */ 0x50,
432 /* 81 */ /* Q */ 0x51,
433 /* 82 */ /* R */ 0x52,
434 /* 83 */ /* S */ 0x53,
435 /* 84 */ /* T */ 0x54,
436 /* 85 */ /* U */ 0x55,
437 /* 86 */ /* V */ 0x56,
438 /* 87 */ /* W */ 0x57,
439 /* 88 */ /* X */ 0x58,
440 /* 89 */ /* Y */ 0x59,
441 /* 90 */ /* Z */ 0x5A,
442 /* 91 */ /* bracketleft */ 0x5B,
443 /* 92 */ /* backslash */ 0x5C,
444 /* 93 */ /* bracketright */ 0x5D,
445 /* 94 */ /* asciicircum */ 0x5E,
446 /* 95 */ /* underscore */ 0x5F,
447 /* 96 x*/ /* quoteleft */ 0x60,
448 /* 97 */ /* a */ 0x61,
449 /* 98 */ /* b */ 0x62,
450 /* 99 */ /* c */ 0x63,
451 /* 100 */ /* d */ 0x64,
452 /* 101 */ /* e */ 0x65,
453 /* 102 */ /* f */ 0x66,
454 /* 103 */ /* g */ 0x67,
455 /* 104 */ /* h */ 0x68,
456 /* 105 */ /* i */ 0x69,
457 /* 106 */ /* j */ 0x6A,
458 /* 107 */ /* k */ 0x6B,
459 /* 108 */ /* l */ 0x6C,
460 /* 109 */ /* m */ 0x6D,
461 /* 110 */ /* n */ 0x6E,
462 /* 111 */ /* o */ 0x6F,
463 /* 112 */ /* p */ 0x70,
464 /* 113 */ /* q */ 0x71,
465 /* 114 */ /* r */ 0x72,
466 /* 115 */ /* s */ 0x73,
467 /* 116 */ /* t */ 0x74,
468 /* 117 */ /* u */ 0x75,
469 /* 118 */ /* v */ 0x76,
470 /* 119 */ /* w */ 0x77,
471 /* 120 */ /* x */ 0x78,
472 /* 121 */ /* y */ 0x79,
473 /* 122 */ /* z */ 0x7A,
474 /* 123 */ /* braceleft */ 0x7B,
475 /* 124 */ /* bar */ 0x7C,
476 /* 125 */ /* braceright */ 0x7D,
477 /* 126 */ /* asciitilde */ 0x7E,
478 /* 127 */ /* -unused- */ 0x7F,
479 /* 128 */ /* -unused- */ 0x80,
480 /* 129 */ /* -unused- */ 0x81,
481 /* 130 */ /* -unused- */ 0x82,
482 /* 131 */ /* -unused- */ 0x83,
483 /* 132 */ /* -unused- */ 0x84,
484 /* 133 */ /* -unused- */ 0x85,
485 /* 134 */ /* -unused- */ 0x86,
486 /* 135 */ /* -unused- */ 0x87,
487 /* 136 */ /* -unused- */ 0x88,
488 /* 137 */ /* -unused- */ 0x89,
489 /* 138 */ /* -unused- */ 0x90,
490 /* 139 */ /* -unused- */ 0x91,
491 /* 140 */ /* -unused- */ 0x92,
492 /* 141 */ /* -unused- */ 0x93,
493 /* 142 */ /* -unused- */ 0x94,
494 /* 143 */ /* -unused- */ 0x95,
495
496// unclear
497 /* 144 x*/ /* dotlessi */ 0x96,
498 /* 145 */ /* grave */ 0x60,
499 /* 146 */ /* acute */ 0xEF,
500 /* 147 x*/ /* circumflex */ 0x99,
501 /* 148 x*/ /* tilde */ 0x9A,
502 /* 149 x*/ /* macron */ 0x9B,
503 /* 150 x*/ /* breve */ 0x9C,
504 /* 151 x*/ /* dotaccent */ 0x9E,
505 /* 152 */ /* dieresis */ 0xF9,
506 /* 153 */ /* -unused- */ 0xA0,
507 /* 154 x*/ /* ring */ 0xA1,
508 /* 155 */ /* cedilla */ 0xF7,
509 /* 156 */ /* -unused- */ 0xA3,
510 /* 157 x*/ /* hungarumlaut */ 0xA4,
511 /* 158 x*/ /* ogonek */ 0xA5,
512 /* 159 x*/ /* caron */ 0xA6,
513 /* 160 */ /* space [reqspace] */ 0xFF,
514// unclear
515
516 /* 161 */ /* exclamdown */ 0xAD,
517 /* 162 */ /* cent */ 0xBD,
518 /* 163 */ /* sterling */ 0x9C,
519 /* 164 */ /* currency */ 0xCF,
520 /* 165 */ /* yen */ 0xBE,
521 /* 166 */ /* brokenbar */ 0xDD,
522 /* 167 */ /* section */ 0xF5,
523 /* 168 */ /* dieresis */ 0xF9,
524 /* 169 */ /* copyright */ 0xB8,
525 /* 170 */ /* ordfeminine */ 0xA6,
526 /* 171 */ /* guillemotleft */ 0xAE,
527 /* 172 */ /* logicalnot */ 0xAA,
528 /* 173 */ /* hyphen [syllable] */ 0xF0,
529 /* 174 */ /* registered */ 0xA9,
530 /* 175 */ /* macron [overline] */ 0xEE,
531 /* 176 */ /* degree */ 0xF8,
532 /* 177 */ /* plusminus */ 0xF1,
533 /* 178 */ /* twosuperior */ 0xFD,
534 /* 179 */ /* threesuperior */ 0xFC,
535 /* 180 */ /* acute */ 0xEF,
536 /* 181 */ /* mu */ 0xE6,
537 /* 182 */ /* paragraph */ 0xF4,
538 /* 183 */ /* periodcentered */ 0xFA,
539 /* 184 */ /* cedilla */ 0xF7,
540 /* 185 */ /* onesuperior */ 0xFB,
541 /* 186 */ /* ordmasculine */ 0xA7,
542 /* 187 */ /* guillemotright */ 0xAF,
543 /* 188 */ /* onequarter */ 0xAC,
544 /* 189 */ /* onehalf */ 0xAB,
545 /* 190 */ /* threequarters */ 0xF3,
546 /* 191 */ /* questiondown */ 0xA8,
547 /* 192 */ /* Agrave */ 0xB7,
548 /* 193 */ /* Aacute */ 0xB5,
549 /* 194 */ /* Acircumflex */ 0xB6,
550 /* 195 */ /* Atilde */ 0xC7,
551 /* 196 */ /* Adieresis */ 0x8E,
552 /* 197 */ /* Aring */ 0x8F,
553 /* 198 */ /* AE */ 0x92,
554 /* 199 */ /* Ccedilla */ 0x80,
555 /* 200 */ /* Egrave */ 0xD4,
556 /* 201 */ /* Eacute */ 0x90,
557 /* 202 */ /* Ecircumflex */ 0xD2,
558 /* 203 */ /* Edieresis */ 0xD3,
559 /* 204 */ /* Igrave */ 0xDE,
560 /* 205 */ /* Iacute */ 0xD6,
561 /* 206 */ /* Icircumflex */ 0xD7,
562 /* 207 */ /* Idieresis */ 0xD8,
563 /* 208 */ /* Eth */ 0xD1,
564 /* 209 */ /* Ntilde */ 0xA5,
565 /* 210 */ /* Ograve */ 0xE3,
566 /* 211 */ /* Oacute */ 0xE0,
567 /* 212 */ /* Ocircumflex */ 0xE2,
568 /* 213 */ /* Otilde */ 0xE5,
569 /* 214 */ /* Odieresis */ 0x99,
570 /* 215 */ /* multiply */ 0x9E,
571 /* 216 */ /* Oslash */ 0x9D,
572 /* 217 */ /* Ugrave */ 0xEB,
573 /* 218 */ /* Uacute */ 0xE9,
574 /* 219 */ /* Ucircumflex */ 0xEA,
575 /* 220 */ /* Udieresis */ 0x9A,
576 /* 221 */ /* Yacute */ 0xED,
577 /* 222 */ /* Thorn */ 0xE8,
578 /* 223 */ /* germandbls */ 0xE1,
579 /* 224 */ /* agrave */ 0x85,
580 /* 225 */ /* aacute */ 0xA0,
581 /* 226 */ /* acircumflex */ 0x83,
582 /* 227 */ /* atilde */ 0xC6,
583 /* 228 */ /* adieresis */ 0x84,
584 /* 229 */ /* aring */ 0x86,
585 /* 230 */ /* ae */ 0x91,
586 /* 231 */ /* ccedilla */ 0x87,
587 /* 232 */ /* egrave */ 0x8A,
588 /* 233 */ /* eacute */ 0x82,
589 /* 234 */ /* ecircumflex */ 0x88,
590 /* 235 */ /* edieresis */ 0x89,
591 /* 236 */ /* igrave */ 0x8D,
592 /* 237 */ /* iacute */ 0xA1,
593 /* 238 */ /* icircumflex */ 0x8C,
594 /* 239 */ /* idieresis */ 0x8B,
595 /* 240 */ /* eth */ 0xD0,
596 /* 241 */ /* ntilde */ 0xA4,
597 /* 242 */ /* ograve */ 0x95,
598 /* 243 */ /* oacute */ 0xA2,
599 /* 244 */ /* ocircumflex */ 0x93,
600 /* 245 */ /* otilde */ 0xE4,
601 /* 246 */ /* odieresis */ 0x94,
602 /* 247 */ /* divide */ 0xF6,
603 /* 248 */ /* oslash */ 0x9B,
604 /* 249 */ /* ugrave */ 0x97,
605 /* 250 */ /* uacute */ 0xA3,
606 /* 251 */ /* ucircumflex */ 0x96,
607 /* 252 */ /* udieresis */ 0x81,
608 /* 253 */ /* yacute */ 0xEC,
609 /* 254 */ /* thorn */ 0xE7,
610 /* 255 */ /* ydieresis */ 0x98
611};
612
613
614// WindowsAnsi to Ibm850
615char FromWindows[256] =
616{
617 /* Code */ /* source character name */ /* destionation code */
618 /* 0 */ /* -unused- */ 0x00,
619 /* 1 */ /* -unused- */ 0x01,
620 /* 2 */ /* -unused- */ 0x02,
621 /* 3 */ /* -unused- */ 0x03,
622 /* 4 */ /* -unused- */ 0x04,
623 /* 5 */ /* -unused- */ 0x05,
624 /* 6 */ /* -unused- */ 0x06,
625 /* 7 */ /* -unused- */ 0x07,
626 /* 8 */ /* -unused- */ 0x08,
627 /* 9 */ /* -unused- */ 0x09,
628 /* 10 */ /* -unused- */ 0x0A,
629 /* 11 */ /* -unused- */ 0x0B,
630 /* 12 */ /* -unused- */ 0x0C,
631 /* 13 */ /* -unused- */ 0x0D,
632 /* 14 */ /* -unused- */ 0x0E,
633 /* 15 */ /* -unused- */ 0x0F,
634 /* 16 */ /* -unused- */ 0x10,
635 /* 17 */ /* -unused- */ 0x11,
636 /* 18 */ /* -unused- */ 0x12,
637 /* 19 */ /* -unused- */ 0x13,
638 /* 20 */ /* -unused- */ 0x14,
639 /* 21 */ /* -unused- */ 0x15,
640 /* 22 */ /* -unused- */ 0x16,
641 /* 23 */ /* -unused- */ 0x17,
642 /* 24 */ /* -unused- */ 0x18,
643 /* 25 */ /* -unused- */ 0x19,
644 /* 26 */ /* -unused- */ 0x1A,
645 /* 27 */ /* -unused- */ 0x1B,
646 /* 28 */ /* -unused- */ 0x1C,
647 /* 29 */ /* -unused- */ 0x1D,
648 /* 30 */ /* -unused- */ 0x1E,
649 /* 31 */ /* -unused- */ 0x1F,
650 /* 32 */ /* space */ 0x20,
651 /* 33 */ /* exclam */ 0x21,
652 /* 34 */ /* quotedbl */ 0x22,
653 /* 35 */ /* numbersign */ 0x23,
654 /* 36 */ /* dollar */ 0x24,
655 /* 37 */ /* percent */ 0x25,
656 /* 38 */ /* ampersand */ 0x26,
657 /* 39 x*/ /* quoteright */ 0x27,
658 /* 40 */ /* parenleft */ 0x28,
659 /* 41 */ /* parenright */ 0x29,
660 /* 42 */ /* asterisk */ 0x2A,
661 /* 43 */ /* plus */ 0x2B,
662 /* 44 */ /* comma */ 0x2C,
663 /* 45 x*/ /* hyphen */ 0x2D,
664 /* 46 */ /* period */ 0x2E,
665 /* 47 */ /* slash */ 0x2F,
666 /* 48 */ /* zero */ 0x30,
667 /* 49 */ /* one */ 0x31,
668 /* 50 */ /* two */ 0x32,
669 /* 51 */ /* three */ 0x33,
670 /* 52 */ /* four */ 0x34,
671 /* 53 */ /* five */ 0x35,
672 /* 54 */ /* six */ 0x36,
673 /* 55 */ /* seven */ 0x37,
674 /* 56 */ /* eight */ 0x38,
675 /* 57 */ /* nine */ 0x39,
676 /* 58 */ /* colon */ 0x3A,
677 /* 59 */ /* semicolon */ 0x3B,
678 /* 60 */ /* less */ 0x3C,
679 /* 61 */ /* equal */ 0x3D,
680 /* 62 */ /* greater */ 0x3E,
681 /* 63 */ /* question */ 0x3F,
682 /* 64 */ /* at */ 0x40,
683 /* 65 */ /* A */ 0x41,
684 /* 66 */ /* B */ 0x42,
685 /* 67 */ /* C */ 0x43,
686 /* 68 */ /* D */ 0x44,
687 /* 69 */ /* E */ 0x45,
688 /* 70 */ /* F */ 0x46,
689 /* 71 */ /* G */ 0x47,
690 /* 72 */ /* H */ 0x48,
691 /* 73 */ /* I */ 0x49,
692 /* 74 */ /* J */ 0x4A,
693 /* 75 */ /* K */ 0x4B,
694 /* 76 */ /* L */ 0x4C,
695 /* 77 */ /* M */ 0x4D,
696 /* 78 */ /* N */ 0x4E,
697 /* 79 */ /* O */ 0x4F,
698 /* 80 */ /* P */ 0x50,
699 /* 81 */ /* Q */ 0x51,
700 /* 82 */ /* R */ 0x52,
701 /* 83 */ /* S */ 0x53,
702 /* 84 */ /* T */ 0x54,
703 /* 85 */ /* U */ 0x55,
704 /* 86 */ /* V */ 0x56,
705 /* 87 */ /* W */ 0x57,
706 /* 88 */ /* X */ 0x58,
707 /* 89 */ /* Y */ 0x59,
708 /* 90 */ /* Z */ 0x5A,
709 /* 91 */ /* bracketleft */ 0x5B,
710 /* 92 */ /* backslash */ 0x5C,
711 /* 93 */ /* bracketright */ 0x5D,
712 /* 94 */ /* asciicircum */ 0x5E,
713 /* 95 */ /* underscore */ 0x5F,
714 /* 96 */ /* grave */ 0x60,
715 /* 97 */ /* a */ 0x61,
716 /* 98 */ /* b */ 0x62,
717 /* 99 */ /* c */ 0x63,
718 /* 100 */ /* d */ 0x64,
719 /* 101 */ /* e */ 0x65,
720 /* 102 */ /* f */ 0x66,
721 /* 103 */ /* g */ 0x67,
722 /* 104 */ /* h */ 0x68,
723 /* 105 */ /* i */ 0x69,
724 /* 106 */ /* j */ 0x6A,
725 /* 107 */ /* k */ 0x6B,
726 /* 108 */ /* l */ 0x6C,
727 /* 109 */ /* m */ 0x6D,
728 /* 110 */ /* n */ 0x6E,
729 /* 111 */ /* o */ 0x6F,
730 /* 112 */ /* p */ 0x70,
731 /* 113 */ /* q */ 0x71,
732 /* 114 */ /* r */ 0x72,
733 /* 115 */ /* s */ 0x73,
734 /* 116 */ /* t */ 0x74,
735 /* 117 */ /* u */ 0x75,
736 /* 118 */ /* v */ 0x76,
737 /* 119 */ /* w */ 0x77,
738 /* 120 */ /* x */ 0x78,
739 /* 121 */ /* y */ 0x79,
740 /* 122 */ /* z */ 0x7A,
741 /* 123 */ /* braceleft */ 0x7B,
742 /* 124 */ /* bar */ 0x7C,
743 /* 125 */ /* braceright */ 0x7D,
744 /* 126 */ /* asciitilde */ 0x7E,
745 /* 127 */ /* -unused- */ 0x7F,
746 /* 128 */ /* -unused- [euro] */ 0xD5,
747 /* 129 */ /* -unused- */ 0x81,
748 /* 130 */ /* quotesinglbase */ 0x2C, // unsupported, comm
749 /* 131 */ /* florin */ 0x9F,
750 /* 132 */ /* quotedblbase */ 0xFF, // unsupported
751 /* 133 */ /* ellipsis */ 0xFF, // unsupported
752 /* 134 */ /* dagger */ 0xFF, // unsupported
753 /* 135 */ /* daggerdbl */ 0xFF, // unsupported
754 /* 136 */ /* circumflex */ 0xFF, // unsupported
755 /* 137 */ /* perthousand */ 0xFF, // unsupported
756 /* 138 */ /* Scaron */ 0x53, // unsupported, S
757 /* 139 */ /* guilsinglleft */ 0x3C, // unsupported, less
758 /* 140 */ /* OE */ 0xFF, // unsupported
759 /* 141 */ /* -unused- */ 0x8D,
760 /* 142 */ /* -unused- [zcaron] */ 0x5A, // unsupported, Z
761 /* 143 */ /* -unused- */ 0x8F,
762 /* 144 */ /* -unused- */ 0x90,
763 /* 145 */ /* quoteleft */ 0x60, // unsupported, grave
764 /* 146 */ /* quoteright */ 0x27, // unsupported, quotesingle
765 /* 147 */ /* quotedblleft */ 0x22, // unsupported, quotedbl
766 /* 148 */ /* quotedblright */ 0x22, // unsupported, quotedbl
767 /* 149 */ /* bullet [bullet1] */ 0x07,
768 /* 150 */ /* endash */ 0x2D, // unsupported, hyphen
769 /* 151 */ /* emdash */ 0x2D, // unsupported, hyphen
770 /* 152 */ /* tilde */ 0x7E, // unsupported, asciitilde
771 /* 153 */ /* trademark */ 0xFF, // unsupported
772 /* 154 */ /* scaron */ 0x73, // unsupported, s
773 /* 155 */ /* guilsinglright */ 0x3E, // unsupported, greater
774 /* 156 */ /* oe */ 0xFF, // unsupported
775 /* 157 */ /* -unused- */ 0x9D, // unsupported
776 /* 158 */ /* -unused- [zcaron] */ 0x7A, // unsupported, z
777 /* 159 */ /* Ydieresis */ 0x98, // unsupported, ydieresis
778
779// 160-255 - same as in IsoLatin1
780
781 /* 160 */ /* space [reqspace] */ 0xFF,
782 /* 161 */ /* exclamdown */ 0xAD,
783 /* 162 */ /* cent */ 0xBD,
784 /* 163 */ /* sterling */ 0x9C,
785 /* 164 */ /* currency */ 0xCF,
786 /* 165 */ /* yen */ 0xBE,
787 /* 166 */ /* brokenbar */ 0xDD,
788 /* 167 */ /* section */ 0xF5,
789 /* 168 */ /* dieresis */ 0xF9,
790 /* 169 */ /* copyright */ 0xB8,
791 /* 170 */ /* ordfeminine */ 0xA6,
792 /* 171 */ /* guillemotleft */ 0xAE,
793 /* 172 */ /* logicalnot */ 0xAA,
794 /* 173 */ /* hyphen [syllable] */ 0xF0,
795 /* 174 */ /* registered */ 0xA9,
796 /* 175 */ /* macron [overline] */ 0xEE,
797 /* 176 */ /* degree */ 0xF8,
798 /* 177 */ /* plusminus */ 0xF1,
799 /* 178 */ /* twosuperior */ 0xFD,
800 /* 179 */ /* threesuperior */ 0xFC,
801 /* 180 */ /* acute */ 0xEF,
802 /* 181 */ /* mu */ 0xE6,
803 /* 182 */ /* paragraph */ 0xF4,
804 /* 183 */ /* periodcentered */ 0xFA,
805 /* 184 */ /* cedilla */ 0xF7,
806 /* 185 */ /* onesuperior */ 0xFB,
807 /* 186 */ /* ordmasculine */ 0xA7,
808 /* 187 */ /* guillemotright */ 0xAF,
809 /* 188 */ /* onequarter */ 0xAC,
810 /* 189 */ /* onehalf */ 0xAB,
811 /* 190 */ /* threequarters */ 0xF3,
812 /* 191 */ /* questiondown */ 0xA8,
813 /* 192 */ /* Agrave */ 0xB7,
814 /* 193 */ /* Aacute */ 0xB5,
815 /* 194 */ /* Acircumflex */ 0xB6,
816 /* 195 */ /* Atilde */ 0xC7,
817 /* 196 */ /* Adieresis */ 0x8E,
818 /* 197 */ /* Aring */ 0x8F,
819 /* 198 */ /* AE */ 0x92,
820 /* 199 */ /* Ccedilla */ 0x80,
821 /* 200 */ /* Egrave */ 0xD4,
822 /* 201 */ /* Eacute */ 0x90,
823 /* 202 */ /* Ecircumflex */ 0xD2,
824 /* 203 */ /* Edieresis */ 0xD3,
825 /* 204 */ /* Igrave */ 0xDE,
826 /* 205 */ /* Iacute */ 0xD6,
827 /* 206 */ /* Icircumflex */ 0xD7,
828 /* 207 */ /* Idieresis */ 0xD8,
829 /* 208 */ /* Eth */ 0xD1,
830 /* 209 */ /* Ntilde */ 0xA5,
831 /* 210 */ /* Ograve */ 0xE3,
832 /* 211 */ /* Oacute */ 0xE0,
833 /* 212 */ /* Ocircumflex */ 0xE2,
834 /* 213 */ /* Otilde */ 0xE5,
835 /* 214 */ /* Odieresis */ 0x99,
836 /* 215 */ /* multiply */ 0x9E,
837 /* 216 */ /* Oslash */ 0x9D,
838 /* 217 */ /* Ugrave */ 0xEB,
839 /* 218 */ /* Uacute */ 0xE9,
840 /* 219 */ /* Ucircumflex */ 0xEA,
841 /* 220 */ /* Udieresis */ 0x9A,
842 /* 221 */ /* Yacute */ 0xED,
843 /* 222 */ /* Thorn */ 0xE8,
844 /* 223 */ /* germandbls */ 0xE1,
845 /* 224 */ /* agrave */ 0x85,
846 /* 225 */ /* aacute */ 0xA0,
847 /* 226 */ /* acircumflex */ 0x83,
848 /* 227 */ /* atilde */ 0xC6,
849 /* 228 */ /* adieresis */ 0x84,
850 /* 229 */ /* aring */ 0x86,
851 /* 230 */ /* ae */ 0x91,
852 /* 231 */ /* ccedilla */ 0x87,
853 /* 232 */ /* egrave */ 0x8A,
854 /* 233 */ /* eacute */ 0x82,
855 /* 234 */ /* ecircumflex */ 0x88,
856 /* 235 */ /* edieresis */ 0x89,
857 /* 236 */ /* igrave */ 0x8D,
858 /* 237 */ /* iacute */ 0xA1,
859 /* 238 */ /* icircumflex */ 0x8C,
860 /* 239 */ /* idieresis */ 0x8B,
861 /* 240 */ /* eth */ 0xD0,
862 /* 241 */ /* ntilde */ 0xA4,
863 /* 242 */ /* ograve */ 0x95,
864 /* 243 */ /* oacute */ 0xA2,
865 /* 244 */ /* ocircumflex */ 0x93,
866 /* 245 */ /* otilde */ 0xE4,
867 /* 246 */ /* odieresis */ 0x94,
868 /* 247 */ /* divide */ 0xF6,
869 /* 248 */ /* oslash */ 0x9B,
870 /* 249 */ /* ugrave */ 0x97,
871 /* 250 */ /* uacute */ 0xA3,
872 /* 251 */ /* ucircumflex */ 0x96,
873 /* 252 */ /* udieresis */ 0x81,
874 /* 253 */ /* yacute */ 0xEC,
875 /* 254 */ /* thorn */ 0xE7,
876 /* 255 */ /* ydieresis */ 0x98
877};
878
879
880//
881// ConvertCharset
882//
883// convert string charset
884//
885
886void ConvertCharset( char *str_in, int in_len , char *str_out, int *out_len, int iSrcCharset )
887{
888 int i,j;
889 char *convtab = NULL;
890
891 int fInHex; // flag, if we currently are processing hex string
892
893 // these variables keep state in case we have to abort hex string conversion
894 // (if it's actually not hex string, just <some string>...
895 int iHexRollbackSrc;
896 int iHexRollbackDest;
897 int iHexDigits;
898
899 char chHex;
900
901
902 // validate params
903 if( str_in == NULL || str_out == NULL )
904 return;
905
906 // here we process the src/dest charset requests
907 // should create something more elaborate, but for now...
908
909 if( iSrcCharset == CONVERT_ISOLATIN1 )
910 convtab = FromIso;
911 else if( iSrcCharset == CONVERT_WINDOWSANSI )
912 convtab = FromWindows;
913 else if( iSrcCharset == CONVERT_UTF8 )
914 convtab = FromUTF8;
915 else
916 {
917 // just copy over the data and pretend it's OK
918 memcpy( str_out, str_in, in_len );
919 *out_len = in_len;
920 return;
921 }
922
923 //
924 // convert the string (main loop)
925 //
926
927 i = 0;
928 j = 0;
929 fInHex = FALSE;
930
931 while( i < in_len && j < *out_len )
932 {
933
934 //
935 // note: very similar code is countained in p2putil.ch::CopyString
936 // if you fix a here, don't forget to fix it there too.
937 //
938
939 if( !fInHex && str_in[i]=='<' )
940 {
941 // this might be the beginning of <hex> string
942
943 fInHex = TRUE;
944 iHexRollbackSrc = i+1;
945 iHexRollbackDest = j+1;
946 iHexDigits = 0;
947 }
948 else if( fInHex && str_in[i]=='>' )
949 {
950 // hex string is terminated
951
952 if( iHexDigits )
953 {
954 // this string is error, rollback
955 i = iHexRollbackSrc;
956 j = iHexRollbackDest;
957 // just go on copying
958 }
959
960 fInHex = FALSE;
961 iHexDigits = 0;
962 }
963 else if( fInHex )
964 {
965 // processing the hex string
966
967 char ch = str_in[i];
968
969 // check if it's acceptable hex char
970
971 if( ch >= '0' && ch<='9' )
972 {
973 chHex = (chHex << 4) | (ch - '0');
974 iHexDigits++;
975 }
976 else if( ch >= 'a' && ch<='f' )
977 {
978 chHex = (chHex << 4) | (ch - 'a' + 0xA);
979 iHexDigits++;
980 }
981 else if( ch >= 'A' && ch<='F' )
982 {
983 chHex = (chHex << 4) | (ch - 'A' + 0xA);
984 iHexDigits++;
985 }
986 else if( ch == ' ' || ch == '\t' )
987 {
988 // these are acceptable chars
989 // just copy them over verbatim
990 // (note: this is different from p2putil.ch processing!)
991 str_out[j]=convtab[ str_in[i] ];
992 i++;
993 j++;
994 continue;
995 }
996 else
997 {
998 // illegal character encountered!
999 // just bail, return to copying the string as if hex mode never happened
1000 i = iHexRollbackSrc;
1001 j = iHexRollbackDest;
1002 fInHex = FALSE;
1003 iHexDigits = 0;
1004 continue;
1005 }
1006
1007 // must be 2 or more(even nr) hex characters
1008 if( iHexDigits == 2 )
1009 {
1010 char tch;
1011 // convert and output the char
1012 ch = convtab[ chHex ];
1013
1014 // convert this to hex and output
1015 tch = (ch & 0xF0) >> 4;
1016 if(tch > 9) tch += 'A' - 0xA; else tch+= '0';
1017
1018 str_out[j] = tch;
1019 j++;
1020
1021
1022 tch = (ch & 0xF);
1023 if(tch > 9) tch += 'A' - 0xA; else tch+= '0';
1024 str_out[j] = tch;
1025 j++;
1026
1027 iHexDigits = 0;
1028 }
1029
1030 i++;
1031 continue;
1032 }
1033
1034 // copy current character over to destination string
1035 // (this is done almost everytime, after processing code is executed)
1036 str_out[j]=convtab[ str_in[i] ];
1037 i++;
1038 j++;
1039 }
1040
1041 *out_len = j;
1042
1043 // and we're done...
1044 return;
1045}
1046
1047//
1048// reading file to memory
1049//
1050// text line structure
1051//
1052
1053typedef struct LIST_LINE_
1054{
1055 char *pStr;
1056 int iStrSize;
1057 struct LIST_LINE_ *pNext;
1058} LIST_LINE, *PLIST_LINE;
1059
1060PLIST_LINE list_head = NULL;
1061PLIST_LINE list_tail = NULL;
1062
1063char *PpdBuf = NULL;
1064int biggest_line_size;
1065
1066//
1067// read in file and parse lines into list
1068//
1069int ReadFileToList( FILE *in )
1070{
1071 char *buf = NULL;
1072 int buf_size = 0;
1073 int line_length = 0;
1074 int line_begin_offset = 0;
1075
1076 int i = 0, j = 0;
1077 int fForever = TRUE;
1078
1079 biggest_line_size = 0;
1080
1081 PpdBuf = NULL;
1082
1083 // read everything
1084 fseek( in, 0L, SEEK_END);
1085 buf_size = ftell( in );
1086 fseek( in, 0L, SEEK_SET);
1087
1088 buf = malloc ( buf_size + 4 ); // 4 kb
1089 if( buf == NULL )
1090 {
1091 printf(" out of memory reading input file (asked for %d bytes)\n", buf_size );
1092 return FALSE; // fail
1093 }
1094
1095 if( !fread(buf, buf_size, 1, in) )
1096 {
1097 printf(" error reading input file\n" );
1098 free( buf );
1099 return FALSE; // fail
1100 }
1101
1102 line_length = 0;
1103 line_begin_offset = 0;
1104
1105 while( i < buf_size )
1106 {
1107 while( buf[i] != '\n' && i < buf_size ) i++;
1108
1109 if( buf[i] == '\n' || i == buf_size ) // found the sacred end of line
1110 {
1111 PLIST_LINE node;
1112 // put the line in list!
1113 // i is length of line
1114
1115 if( i < buf_size )
1116 i++; // include the \n
1117
1118 line_length = i - line_begin_offset;
1119
1120 if( line_length > biggest_line_size ) biggest_line_size = line_length; // find the biggest buffer we will need
1121
1122 node = malloc( sizeof( LIST_LINE ) );
1123
1124 node->iStrSize = line_length;
1125 node->pStr = &buf[ line_begin_offset ];
1126
1127//debug
1128// node->pStr[ node->iStrSize ] = 0;
1129// printf( "%s", node->pStr );
1130//debug
1131
1132 node->pNext = NULL;
1133
1134 if( list_tail != NULL )
1135 list_tail->pNext = node;
1136
1137 list_tail = node;
1138 if( list_head == NULL ) list_head = node;
1139
1140 // reset to fill buffer
1141 line_length = 0;
1142 line_begin_offset = i;
1143
1144 }
1145 }
1146
1147
1148 PpdBuf = buf;
1149
1150 return TRUE;
1151}
1152
1153//
1154// Go through lines to find LanguageEncoding of PPD
1155// Also change LanguageEncoding to OS2-850, so that when PPD is converted
1156// we can see it.
1157//
1158int GetCharset( void )
1159{
1160 PLIST_LINE node = NULL;
1161 int iCharset = CONVERT_UNKNOWN;
1162 char key[19] = "*LanguageEncoding:";
1163 char word[19] = "";
1164 int enc_offset;
1165 char os2cp_str[] = " OS2-850\r\n";
1166
1167 for( node = list_head ; node != NULL ; node = node->pNext )
1168 {
1169 // check if string
1170 int i = 0, j = 0;
1171 char *str = node->pStr;
1172
1173 while( (str[i] == ' ' || str[i] == '\t') && i < node->iStrSize ) i++;
1174 if( i == node->iStrSize ) continue; // next
1175
1176 while( i < node->iStrSize && j < 18 )
1177 {
1178 word[j] = str[i];
1179 i++;
1180 j++;
1181 }
1182 word[j] = 0;
1183
1184 if( i == node->iStrSize ) continue; // next
1185
1186 enc_offset = i;
1187
1188 if(!stricmp( key, word ))
1189 {
1190 // gee, found just the string!
1191
1192 // read the keyword again
1193 while( (str[i] == ' ' || str[i] == '\t' || str[i]=='\"') && i < node->iStrSize ) i++;
1194 if( i == node->iStrSize ) continue; // next
1195
1196 j = 0;
1197 while( i < node->iStrSize && j < 18 && str[i]!='\"' && str[i]!=' ' && str[i]!='\t' && str[i]!='\r' && str[i]!='\n' )
1198 {
1199 word[j] = str[i];
1200 i++;
1201 j++;
1202 }
1203 word[j] = 0;
1204
1205 if( !stricmp( word, "IsoLatin1") )
1206 {
1207 iCharset = CONVERT_ISOLATIN1;
1208 printf( "(IsoLatin1)" );
1209
1210 strcpy( &str[ enc_offset ], os2cp_str );
1211 node->iStrSize = enc_offset + strlen( os2cp_str );
1212 break;
1213 }
1214 else if( !stricmp( word, "WindowsANSI") )
1215 {
1216 iCharset = CONVERT_WINDOWSANSI;
1217 printf( "(WindowsAnsi)" );
1218
1219 strcpy( &str[ enc_offset ], os2cp_str );
1220 node->iStrSize = enc_offset + strlen( os2cp_str ) - 1;
1221 break;
1222 }
1223 else if( !stricmp( word, "UTF-8") )
1224 {
1225 iCharset = CONVERT_UTF8;
1226 printf( "(UTF-8)" );
1227
1228 strcpy( &str[ enc_offset ], os2cp_str );
1229 node->iStrSize = enc_offset + strlen( os2cp_str ) - 1;
1230 break;
1231 }
1232 else if( !stricmp( word, os2cp_str ) )
1233 {
1234 printf( "(%s already)", os2cp_str );
1235 break;
1236 }
1237 else
1238 {
1239 printf( "(%s: unsupported)", word );
1240 break;
1241 }
1242 }
1243 }
1244
1245 if( iCharset == CONVERT_UNKNOWN ) printf( "(copying only)" );
1246
1247 return iCharset;
1248}
1249
1250
1251// debug: dump statistics
1252int DumpList( void )
1253{
1254 PLIST_LINE node = NULL;
1255 int line_number = 0;
1256 int byte_count = 0;
1257
1258 node = list_head;
1259
1260 while( node )
1261 {
1262// printf( "line %04d: %s (%d)\n",line_number,node->pStr,node->iStrSize );
1263
1264 line_number++;
1265 byte_count+=node->iStrSize;
1266
1267 node = node->pNext;
1268 }
1269
1270 printf( "read %d lines, %d bytes\n",line_number, byte_count );
1271
1272 return TRUE;
1273}
1274
1275
1276// clean list, free all memory, delete all nodes
1277
1278int FreeList( void )
1279{
1280 PLIST_LINE node1 = NULL;
1281 PLIST_LINE node2 = NULL;
1282
1283 node1 = list_head;
1284
1285 while( node1 )
1286 {
1287 node2 = node1->pNext;
1288
1289 free( node1 );
1290
1291 node1 = node2;
1292 }
1293
1294 list_head = NULL;
1295 list_tail = NULL;
1296
1297 if( PpdBuf )
1298 {
1299 free( PpdBuf );
1300 PpdBuf = NULL;
1301 }
1302 biggest_line_size = 0;
1303
1304 return TRUE;
1305}
1306
1307//
1308// ConvertFile
1309//
1310// convert charset in source file, create destination file
1311// reads in file line-by-line, converts charset, output the lines
1312//
1313
1314int ConvertFile( char *file_in, char *file_out )
1315{
1316 FILE *in = NULL;
1317 FILE *out = NULL;
1318 int iCharset = CONVERT_UNKNOWN;
1319 PLIST_LINE node = NULL;
1320 char *buf;
1321
1322 // validate params
1323 if( file_in == NULL || file_out == NULL )
1324 return FALSE;
1325
1326 in = fopen( file_in,"rb" );
1327 if( in == NULL )
1328 {
1329 printf(" could not open input file '%s' for reading\n", file_in );
1330 return FALSE;
1331 }
1332
1333 // read in the whole file
1334 if( !ReadFileToList( in ) )
1335 {
1336 printf(" %s: error reading file\n", file_in );
1337
1338 FreeList();
1339 return FALSE;
1340 }
1341
1342 fclose( in );
1343
1344 // find out it's encoding
1345 iCharset = GetCharset();
1346
1347 buf = malloc( biggest_line_size * 2 ); // yeah, paranoia...
1348 if( buf == NULL )
1349 {
1350 printf(" out of memory writing output file\n" );
1351 FreeList();
1352 return FALSE;
1353 }
1354
1355//debug
1356// DumpList();
1357
1358 out = fopen( file_out,"wb" );
1359 if( out == NULL )
1360 {
1361 printf(" could not open output file '%s' for writing\n", file_in );
1362
1363 free( buf );
1364 FreeList();
1365 return FALSE;
1366 }
1367
1368 node = list_head;
1369 while(node)
1370 {
1371 int out_len = biggest_line_size * 2; // yeah, paranoia...
1372
1373 ConvertCharset( node->pStr, node->iStrSize, buf, &out_len, iCharset);
1374
1375 fwrite(buf, out_len, 1, out);
1376
1377 node = node->pNext;
1378 }
1379
1380 free( buf );
1381 FreeList();
1382
1383 fclose(out);
1384
1385 // success
1386 return TRUE;
1387}
1388
1389void print_usage( void )
1390{
1391 printf( "Usage:\n"
1392 " * to convert one file:\n"
1393 " ppdenc <input_ppd_file> <output_ppd_file>\n"
1394 " * do convert all *.PPD files in directory\n"
1395 " ppdenc -d <source_directory> <dest_directory>\n"
1396 " (destination directory must exist!)\n\n"
1397 "Example:\n"
1398 " * to convert all files in directory c:\\src_ppd run:\n"
1399 " ppdenc -d c:\\src_ppd c:\\dest_ppd\n"
1400 " (diretory c:\\dest_ppd must exist)\n"
1401 );
1402}
1403
1404int main(int argc, char *argv[])
1405{
1406 char SOURCE_PATH[CCHMAXPATH];
1407 char DEST_PATH[CCHMAXPATH];
1408 char *pszInFile;
1409 char szInFilePath[CCHMAXPATH];
1410 char szOutFilePath[CCHMAXPATH];
1411 int iCharset;
1412
1413 printf("PPD encoding conversion utility version 1.00\n");
1414 printf("Copyright (c) IBM Corp. 2001. All rights reserved.\n");
1415
1416
1417 // check that arg count is right
1418 if( argc<3 || argc>4 )
1419 {
1420 print_usage();
1421 return 1;
1422 }
1423
1424 // check what exactly we should convert
1425 if( argc == 4 && !strcmp( argv[1], "-d" ) )
1426 {
1427 // user is asking us to convert directory full of PPD files
1428
1429 copy_pathname( SOURCE_PATH, argv[2] );
1430 copy_pathname( DEST_PATH, argv[3] );
1431
1432 printf(" searching PPD files in directory %s\n", SOURCE_PATH );
1433 FilenameList_ReadFromDirectory( SOURCE_PATH, "*.ppd" );
1434
1435 pszInFile = FilenameList_GetName(1);
1436 while(pszInFile)
1437 {
1438 strcpy( szInFilePath, SOURCE_PATH );
1439 strcat( szInFilePath, pszInFile );
1440
1441 strcpy( szOutFilePath, DEST_PATH );
1442 strcat( szOutFilePath, pszInFile );
1443
1444 printf(" converting file %s: ", pszInFile );
1445
1446 if( !ConvertFile( szInFilePath, szOutFilePath ) )
1447 printf(" FAILED\n");
1448 else
1449 printf(" OK\n");
1450
1451 pszInFile = FilenameList_GetName(0);
1452 }
1453
1454 }
1455 else if( argc == 3 )
1456 {
1457 // user is asking us to convert only one file
1458
1459 strcpy( szInFilePath, argv[1] );
1460 strcpy( szOutFilePath, argv[2] );
1461
1462 printf(" converting file %s: ", szInFilePath );
1463
1464 if( !ConvertFile( szInFilePath, szOutFilePath ) )
1465 printf(" FAILED\n");
1466 else
1467 printf(" OK\n");
1468 }
1469 else
1470 {
1471 print_usage();
1472 return 1;
1473 }
1474
1475 printf( "done\n" );
1476
1477
1478 return 0; // success
1479}
Note: See TracBrowser for help on using the repository browser.