File: | modules/lc/gen/lcGenConv.c |
Location: | line 1131, column 13 |
Description: | Value stored to 'name_len' is never read |
1 | /* |
2 | * Copyright 1992, 1993 by TOSHIBA Corp. |
3 | * |
4 | * Permission to use, copy, modify, and distribute this software and its |
5 | * documentation for any purpose and without fee is hereby granted, provided |
6 | * that the above copyright notice appear in all copies and that both that |
7 | * copyright notice and this permission notice appear in supporting |
8 | * documentation, and that the name of TOSHIBA not be used in advertising |
9 | * or publicity pertaining to distribution of the software without specific, |
10 | * written prior permission. TOSHIBA make no representations about the |
11 | * suitability of this software for any purpose. It is provided "as is" |
12 | * without express or implied warranty. |
13 | * |
14 | * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING |
15 | * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL |
16 | * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR |
17 | * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
18 | * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
19 | * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
20 | * SOFTWARE. |
21 | * |
22 | * Author: Katsuhisa Yano TOSHIBA Corp. |
23 | * mopi@osa.ilab.toshiba.co.jp |
24 | */ |
25 | /* |
26 | * (c) Copyright 1995 FUJITSU LIMITED |
27 | * This is source code modified by FUJITSU LIMITED under the Joint |
28 | * Development Agreement for the CDE/Motif PST. |
29 | * |
30 | * Modifier: Masayoshi Shimamura FUJITSU LIMITED |
31 | * |
32 | */ |
33 | /* |
34 | * 2000 |
35 | * Modifier: Ivan Pascal The XFree86 Project |
36 | */ |
37 | |
38 | /* |
39 | * A generic locale loader for all kinds of ISO-2022 based codesets. |
40 | * Supports: all locales. |
41 | * How: Provides generic converters for ISO-2022 based codesets. Extensible as |
42 | * far as ISO-2022 is extensible: codesets can be given by name in the |
43 | * stream. Overall distinction between GL (0x00..0x7f) and GR (0x80..0xff). |
44 | * In every chunk between escape sequences, the number of bytes per |
45 | * character (char_size) is constant. |
46 | * Platforms: all systems. |
47 | */ |
48 | |
49 | #ifdef HAVE_CONFIG_H1 |
50 | #include <config.h> |
51 | #endif |
52 | #include "Xlibint.h" |
53 | #include "XlcGeneric.h" |
54 | #include <stdio.h> |
55 | |
56 | #if !defined(Lynx_22) && !defined(X_LOCALE) |
57 | #define STDCVT |
58 | #endif |
59 | |
60 | typedef struct _CTDataRec { |
61 | const char *name; |
62 | const char *encoding; /* Compound Text encoding */ |
63 | } CTDataRec, *CTData; |
64 | |
65 | static CTDataRec directionality_data[] = |
66 | { |
67 | { "BEGIN_LEFT-TO-RIGHT_TEXT", "\2331]" }, |
68 | { "BEGIN_RIGHT-TO-LEFT_TEXT", "\2332]" }, |
69 | { "END_OF_STRING", "\233]" }, |
70 | }; |
71 | |
72 | typedef struct _StateRec { |
73 | XLCd lcd; |
74 | /* CT state */ |
75 | XlcCharSet charset; /* charset of current state */ |
76 | XlcCharSet GL_charset; /* charset of initial state in GL */ |
77 | XlcCharSet GR_charset; /* charset of initial state in GR */ |
78 | /* MB shift state */ |
79 | CodeSet GL_codeset; |
80 | CodeSet GR_codeset; |
81 | } StateRec, *State; |
82 | |
83 | #define GR0x80 0x80 /* begins right-side (non-ascii) region */ |
84 | #define GL0x7f 0x7f /* ends left-side (ascii) region */ |
85 | #define ESC0x1b 0x1b |
86 | #define CSI0x9b 0x9b |
87 | #define STX0x02 0x02 |
88 | |
89 | #define isrightside(c)((c) & 0x80) ((c) & GR0x80) |
90 | #define isleftside(c)(!((c) & 0x80)) (!isrightside(c)((c) & 0x80)) |
91 | |
92 | /* Forward declarations for local routines. */ |
93 | static int mbstocts (XlcConv conv, XPointer *from, int *from_left, |
94 | XPointer *to, int *to_left, XPointer *args, int num_args); |
95 | static int ctstombs (XlcConv conv, XPointer *from, int *from_left, |
96 | XPointer *to, int *to_left, XPointer *args, int num_args); |
97 | static int cstombs (XlcConv conv, XPointer *from, int *from_left, |
98 | XPointer *to, int *to_left, XPointer *args, int num_args); |
99 | |
100 | /* ------------------------------------------------------------------------- */ |
101 | /* Misc */ |
102 | /* ------------------------------------------------------------------------- */ |
103 | |
104 | static int |
105 | compare( |
106 | const char *src, |
107 | const char *encoding, |
108 | int length) |
109 | { |
110 | const char *start = src; |
111 | |
112 | while (length-- > 0) { |
113 | if (*src++ != *encoding++) |
114 | return 0; |
115 | if (*encoding == '\0') |
116 | return src - start; |
117 | } |
118 | |
119 | return 0; |
120 | } |
121 | |
122 | static unsigned long |
123 | conv_to_dest( |
124 | Conversion conv, |
125 | unsigned long code) |
126 | { |
127 | int i; |
128 | int conv_num = conv->conv_num; |
129 | FontScope convlist = conv->convlist; |
130 | |
131 | for (i = 0; i < conv_num; i++) { |
132 | if (convlist[i].start <= code && code <= convlist[i].end) { |
133 | switch (convlist[i].shift_direction) { |
134 | case '+': |
135 | return(code + convlist[i].shift); |
136 | case '-': |
137 | return(code - convlist[i].shift); |
138 | default: |
139 | return(code); |
140 | } |
141 | } |
142 | } |
143 | |
144 | return(code); |
145 | } |
146 | |
147 | static unsigned long |
148 | conv_to_source( |
149 | Conversion conv, |
150 | unsigned long code) |
151 | { |
152 | int i; |
153 | int conv_num; |
154 | FontScope convlist; |
155 | unsigned long start_p; |
156 | unsigned long start_m; |
157 | unsigned long end_p; |
158 | unsigned long end_m; |
159 | |
160 | if (!conv) |
161 | return(code); |
162 | |
163 | conv_num = conv->conv_num; |
164 | convlist = conv->convlist; |
165 | |
166 | for (i = 0; i < conv_num; i++) { |
167 | switch (convlist[i].shift_direction) { |
168 | case '+': |
169 | start_p = convlist[i].start + convlist[i].shift; |
170 | end_p = convlist[i].end + convlist[i].shift; |
171 | if (start_p <= code && code <= end_p) |
172 | return(code - convlist[i].shift); |
173 | break; |
174 | case '-': |
175 | start_m = convlist[i].start - convlist[i].shift; |
176 | end_m = convlist[i].end - convlist[i].shift; |
177 | if (start_m <= code && code <= end_m) |
178 | return(code + convlist[i].shift); |
179 | break; |
180 | default: |
181 | continue; |
182 | } |
183 | } |
184 | |
185 | return(code); |
186 | } |
187 | |
188 | static unsigned long |
189 | mb_to_gi( |
190 | unsigned long mb, |
191 | CodeSet codeset) |
192 | { |
193 | int i; |
194 | unsigned long mb_tmp, mask = 0; |
195 | |
196 | if (codeset->mbconv) { |
197 | mb_tmp = conv_to_dest(codeset->mbconv, mb); |
198 | if (mb_tmp != mb) |
199 | return(mb_tmp); |
200 | } |
201 | |
202 | if (codeset->side == XlcC0 || codeset->side == XlcGL || |
203 | codeset->side == XlcC1 || codeset->side == XlcGR) { |
204 | |
205 | for (i = 0; i < codeset->length; i++) |
206 | mask = (mask << 8) | GL0x7f; |
207 | mb = mb & mask; |
208 | } |
209 | |
210 | return(mb); |
211 | } |
212 | |
213 | static unsigned long |
214 | gi_to_mb( |
215 | unsigned long glyph_index, |
216 | CodeSet codeset) |
217 | { |
218 | int i; |
219 | unsigned long mask = 0; |
220 | |
221 | if (codeset->side == XlcC1 || codeset->side == XlcGR) { |
222 | for (i = 0; i < codeset->length; i++) |
223 | mask = (mask << 8) | GR0x80; |
224 | glyph_index = glyph_index | mask; |
225 | } |
226 | |
227 | if (codeset->mbconv) |
228 | return( conv_to_source(codeset->mbconv, glyph_index) ); |
229 | |
230 | return(glyph_index); |
231 | } |
232 | |
233 | static Boolint |
234 | gi_to_wc( |
235 | XLCd lcd, |
236 | unsigned long glyph_index, |
237 | CodeSet codeset, |
238 | wchar_t *wc) |
239 | { |
240 | unsigned char mask = 0; |
241 | unsigned long wc_encoding = codeset->wc_encoding; |
242 | int length = codeset->length; |
243 | unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits)(((XLCdGeneric) lcd->core)->gen.wc_shift_bits); |
244 | |
245 | mask = (1 << wc_shift_bits) - 1 ; |
246 | |
247 | for (*wc = 0, length--; length >= 0; length--) |
248 | *wc = (*wc << wc_shift_bits) | ((glyph_index >> (length * 8 )) & mask); |
249 | |
250 | *wc = *wc | wc_encoding; |
251 | |
252 | return(True1); |
253 | } |
254 | |
255 | static Boolint |
256 | wc_to_gi( |
257 | XLCd lcd, |
258 | wchar_t wc, |
259 | unsigned long *glyph_index, |
260 | CodeSet *codeset) |
261 | { |
262 | int i; |
263 | unsigned char mask = 0; |
264 | unsigned long wc_encoding; |
265 | unsigned long wc_encode_mask = XLC_GENERIC(lcd, wc_encode_mask)(((XLCdGeneric) lcd->core)->gen.wc_encode_mask); |
266 | unsigned long wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits)(((XLCdGeneric) lcd->core)->gen.wc_shift_bits); |
267 | int codeset_num = XLC_GENERIC(lcd, codeset_num)(((XLCdGeneric) lcd->core)->gen.codeset_num); |
268 | CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list)(((XLCdGeneric) lcd->core)->gen.codeset_list); |
269 | |
270 | wc_encoding = wc & wc_encode_mask; |
271 | for (*codeset = NULL((void*)0), i = 0; i < codeset_num; i++) { |
272 | if (wc_encoding == codeset_list[i]->wc_encoding) { |
273 | *codeset = codeset_list[i]; |
274 | break; |
275 | } |
276 | } |
277 | if (*codeset == NULL((void*)0)) |
278 | return(False0); |
279 | |
280 | mask = (1 << wc_shift_bits) - 1 ; |
281 | |
282 | wc = wc & ~wc_encode_mask; |
283 | for (*glyph_index = 0, i = (*codeset)->length - 1; i >= 0; i--) |
284 | *glyph_index = (*glyph_index << 8) | |
285 | ( ((unsigned long)wc >> (i * wc_shift_bits)) & mask ); |
286 | |
287 | return(True1); |
288 | } |
289 | |
290 | static CodeSet |
291 | mb_parse_codeset( |
292 | State state, |
293 | int num, |
294 | const char **inbufptr, |
295 | int *from_left) |
296 | { |
297 | int len; |
298 | int from_len = (*from_left) + 1; |
299 | const char *src = (*inbufptr) - 1; |
300 | ParseInfo *mb_parse_list = XLC_GENERIC(state->lcd, mb_parse_list)(((XLCdGeneric) state->lcd->core)->gen.mb_parse_list ); |
301 | ParseInfo parse_info; |
302 | CodeSet codeset; |
303 | |
304 | for (--num ; (parse_info = mb_parse_list[num]) != NULL((void*)0); num++) { |
305 | len = compare(src, parse_info->encoding, from_len); |
306 | if (len > 0) { |
307 | codeset = parse_info->codeset; |
308 | if (parse_info->type == E_LSL) |
309 | state->GL_codeset = codeset; |
310 | else if (parse_info->type == E_LSR) |
311 | state->GR_codeset = codeset; |
312 | --len; |
313 | *inbufptr += len; |
314 | *from_left -= len; |
315 | return codeset; |
316 | } |
317 | } |
318 | return (CodeSet) NULL((void*)0); |
319 | } |
320 | |
321 | static CodeSet |
322 | byteM_parse_codeset( |
323 | XLCd lcd, |
324 | const char *inbufptr) |
325 | { |
326 | unsigned char ch; |
327 | CodeSet codeset; |
328 | ByteInfoList byteM; |
329 | ByteInfoListRec byteM_rec; |
330 | ByteInfo byteinfo; |
331 | ByteInfoRec byteinfo_rec; |
332 | Boolint hit = False0; |
333 | int i, j, k; |
334 | |
335 | int codeset_num = XLC_GENERIC(lcd, codeset_num)(((XLCdGeneric) lcd->core)->gen.codeset_num); |
336 | CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list)(((XLCdGeneric) lcd->core)->gen.codeset_list); |
337 | |
338 | for (i = 0; i < codeset_num; i++) { |
339 | codeset = codeset_list[i]; |
340 | byteM = codeset->byteM; |
341 | if (codeset->side != XlcNONE || byteM == NULL((void*)0)) |
342 | continue; |
343 | |
344 | for (j = 0; j < codeset->length; j++) { |
345 | ch = *((unsigned char *)(inbufptr + j)); |
346 | byteM_rec = byteM[j]; |
347 | byteinfo = byteM_rec.byteinfo; |
348 | |
349 | for (hit = False0, k = 0; k < byteM_rec.byteinfo_num; k++) { |
350 | byteinfo_rec = byteinfo[k]; |
351 | if (byteinfo_rec.start <= ch && ch <= byteinfo_rec.end) { |
352 | hit = True1; |
353 | break; |
354 | } |
355 | } |
356 | |
357 | if (!hit) |
358 | break; |
359 | } |
360 | |
361 | if (hit) |
362 | return(codeset); |
363 | } |
364 | |
365 | return(NULL((void*)0)); |
366 | } |
367 | |
368 | #define GLGR_parse_codeset(ch)(((ch) & 0x80) ? (state->GR_codeset) : (state->GL_codeset ) ) \ |
369 | (isrightside(ch)((ch) & 0x80) ? (state->GR_codeset) : \ |
370 | (state->GL_codeset) ) |
371 | |
372 | static XlcCharSet |
373 | gi_parse_charset( |
374 | unsigned long glyph_index, |
375 | CodeSet codeset) |
376 | { |
377 | int i; |
378 | XlcCharSet *charset_list = codeset->charset_list; |
379 | int num_charsets = codeset->num_charsets; |
380 | ExtdSegment ctextseg = codeset->ctextseg; |
381 | XlcCharSet charset = NULL((void*)0); |
382 | int area_num; |
383 | FontScope area; |
384 | |
385 | /* lockup ct sequence */ |
386 | for (i = 0; i < num_charsets; i++) { |
387 | charset = charset_list[i]; |
388 | if (*charset->ct_sequence != '\0') |
389 | break; |
390 | } |
391 | if (i >= num_charsets) |
392 | return(NULL((void*)0)); |
393 | |
394 | if (charset->source != CSsrcStd) |
395 | return (charset); |
396 | |
397 | if (!ctextseg) |
398 | return(charset); |
399 | |
400 | area = ctextseg->area; |
401 | area_num = ctextseg->area_num; |
402 | |
403 | for (i = 0; i < area_num; i++) { |
404 | |
405 | if (area[i].start <= glyph_index && glyph_index <= area[i].end) { |
406 | |
407 | charset = ctextseg->charset; |
408 | |
409 | if (*charset->ct_sequence == '\0') |
410 | return(NULL((void*)0)); |
411 | |
412 | break; |
413 | } |
414 | } |
415 | |
416 | return(charset); |
417 | } |
418 | |
419 | static Boolint |
420 | ct_parse_csi( |
421 | const char *inbufptr, |
422 | int *ctr_seq_len) |
423 | { |
424 | int i; |
425 | int num = sizeof(directionality_data) / sizeof(directionality_data[0]); |
426 | |
427 | for (i = 0; i < num; i++) { |
428 | if ( !(*ctr_seq_len = strlen(directionality_data[i].encoding)) ) |
429 | continue; |
430 | |
431 | if ( strncmp(inbufptr, directionality_data[i].encoding, |
432 | *ctr_seq_len) == 0) |
433 | return(True1); |
434 | } |
435 | |
436 | return(False0); |
437 | } |
438 | |
439 | static int |
440 | cmp_esc_sequence( |
441 | const char *inbufptr, |
442 | XlcCharSet charset) |
443 | { |
444 | int seq_len, name_len, total_len; |
445 | unsigned char byte_m, byte_l; |
446 | const char *ct_sequence = charset->ct_sequence; |
447 | const char *encoding_name = charset->encoding_name; |
448 | |
449 | /* check esc sequence */ |
450 | if ( !(seq_len = strlen(ct_sequence) ) ) |
451 | return(0); |
452 | if ( strncmp(inbufptr, ct_sequence, seq_len) != 0) |
453 | return(0); |
454 | |
455 | /* Standard Character Set Encoding ? */ |
456 | if (charset->source == CSsrcStd) |
457 | return(seq_len); |
458 | |
459 | /* |
460 | * Non-Standard Character Set Encoding |
461 | * |
462 | * +--- ---+-----+-----+-----+---- ----+-----+-----+------- ------+ |
463 | * | ctseq | M | L | encoding name | STX | contents | |
464 | * +--- ---+-----+-----+-----+---- ----+-----+-----+------- ------+ |
465 | * 4bytes 1byte 1byte variable length 1byte variable length |
466 | * | | |
467 | * +----------------------------------------------+ |
468 | * rest length = ((M - 128) * 128) + (L - 128) |
469 | */ |
470 | |
471 | /* get length of encoding name */ |
472 | inbufptr += seq_len; |
473 | byte_m = *inbufptr++; |
474 | byte_l = *inbufptr++; |
475 | name_len = strlen(encoding_name); |
476 | |
477 | if (((byte_m - 128) * 128 + (byte_l - 128) - 1) < name_len) |
478 | return(0); |
479 | |
480 | if ( _XlcNCompareISOLatin1(inbufptr, encoding_name, name_len) != 0 ) |
481 | return(0); |
482 | |
483 | /* check STX (Start of Text) */ |
484 | inbufptr = inbufptr + name_len; |
485 | if ( *inbufptr != STX0x02 ) |
486 | return(0); |
487 | |
488 | total_len = seq_len + name_len + 3; |
489 | return(total_len); |
490 | } |
491 | |
492 | static Boolint |
493 | ct_parse_charset( |
494 | XLCd lcd, |
495 | const char *inbufptr, |
496 | XlcCharSet *charset, |
497 | int *ctr_seq_len) |
498 | { |
499 | int i, j; |
500 | ExtdSegment ctextseg; |
501 | int num_charsets; |
502 | XlcCharSet *charset_list; |
503 | CodeSet codeset; |
504 | int codeset_num = XLC_GENERIC(lcd, codeset_num)(((XLCdGeneric) lcd->core)->gen.codeset_num); |
505 | CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list)(((XLCdGeneric) lcd->core)->gen.codeset_list); |
506 | int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num)(((XLCdGeneric) lcd->core)->gen.segment_conv_num); |
507 | SegConv segment_conv = XLC_GENERIC(lcd, segment_conv)(((XLCdGeneric) lcd->core)->gen.segment_conv); |
508 | |
509 | /* get charset from XLC_XLOCALE by escape sequence */ |
510 | |
511 | for (i = 0; i < codeset_num; i++) { |
512 | codeset = codeset_list[i]; |
513 | |
514 | num_charsets = codeset->num_charsets; |
515 | charset_list = codeset->charset_list; |
516 | ctextseg = codeset->ctextseg; |
517 | |
518 | for (j = 0; j < num_charsets; j++) { |
519 | *charset = charset_list[j]; |
520 | if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset))) |
521 | return(True1); |
522 | } |
523 | |
524 | if (ctextseg) { |
525 | *charset = ctextseg->charset; |
526 | if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset))) |
527 | return(True1); |
528 | } |
529 | } |
530 | |
531 | /* get charset from XLC_SEGMENTCONVERSION by escape sequence */ |
532 | |
533 | if (!segment_conv) |
534 | return(False0); |
535 | |
536 | for (i = 0; i < segment_conv_num; i++) { |
537 | *charset = segment_conv[i].source; |
538 | if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset))) |
539 | return(True1); |
540 | *charset = segment_conv[i].dest; |
541 | if ((*ctr_seq_len = cmp_esc_sequence(inbufptr, *charset))) |
542 | return(True1); |
543 | } |
544 | |
545 | return(False0); |
546 | } |
547 | |
548 | static Boolint |
549 | segment_conversion( |
550 | XLCd lcd, |
551 | XlcCharSet *charset, |
552 | unsigned long *glyph_index) |
553 | { |
554 | int i; |
555 | int segment_conv_num = XLC_GENERIC(lcd, segment_conv_num)(((XLCdGeneric) lcd->core)->gen.segment_conv_num); |
556 | SegConv segment_conv = XLC_GENERIC(lcd, segment_conv)(((XLCdGeneric) lcd->core)->gen.segment_conv); |
557 | FontScopeRec range; |
558 | ConversionRec conv_rec; |
559 | |
560 | if (!segment_conv) |
561 | return(True1); |
562 | |
563 | for (i = 0; i < segment_conv_num; i++) { |
564 | if (segment_conv[i].source == *charset) |
565 | break; |
566 | } |
567 | |
568 | if (i >= segment_conv_num) |
569 | return(True1); |
570 | |
571 | range = segment_conv[i].range; |
572 | if (*glyph_index < range.start || range.end < *glyph_index) |
573 | return(True1); |
574 | |
575 | *charset = segment_conv[i].dest; |
576 | conv_rec.conv_num = segment_conv[i].conv_num; |
577 | conv_rec.convlist = segment_conv[i].conv; |
578 | *glyph_index = conv_to_dest(&conv_rec, *glyph_index); |
579 | |
580 | return(True1); |
581 | } |
582 | |
583 | static CodeSet |
584 | _XlcGetCodeSetFromName( |
585 | XLCd lcd, |
586 | const char *name) |
587 | { |
588 | int i, j; |
589 | XlcCharSet charset; |
590 | int num_charsets; |
591 | XlcCharSet *charset_list; |
592 | CodeSet codeset; |
593 | |
594 | int codeset_num = XLC_GENERIC(lcd, codeset_num)(((XLCdGeneric) lcd->core)->gen.codeset_num); |
595 | CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list)(((XLCdGeneric) lcd->core)->gen.codeset_list); |
596 | |
597 | for (i = 0; i < codeset_num; i++) { |
598 | codeset = codeset_list[i]; |
599 | |
600 | num_charsets = codeset->num_charsets; |
601 | charset_list = codeset->charset_list; |
602 | |
603 | for (j = 0; j < num_charsets; j++) { |
604 | charset = charset_list[j]; |
605 | |
606 | if (!strlen(charset->name)) |
607 | continue; |
608 | if ( strcmp(charset->name, name) == 0) |
609 | return(codeset); |
610 | } |
611 | } |
612 | |
613 | return(NULL((void*)0)); |
614 | } |
615 | |
616 | static Boolint |
617 | _XlcGetCodeSetFromCharSet( |
618 | XLCd lcd, |
619 | XlcCharSet charset, |
620 | CodeSet *codeset, |
621 | unsigned long *glyph_index) |
622 | { |
623 | int j, num; |
624 | CodeSet *codeset_list = XLC_GENERIC(lcd, codeset_list)(((XLCdGeneric) lcd->core)->gen.codeset_list); |
625 | XlcCharSet *charset_list; |
626 | int codeset_num, num_charsets; |
627 | Conversion ctconv; |
628 | unsigned long glyph_index_tmp = 0; |
629 | ExtdSegment ctextseg; |
630 | |
631 | codeset_num = XLC_GENERIC(lcd, codeset_num)(((XLCdGeneric) lcd->core)->gen.codeset_num); |
632 | |
633 | for (num = 0 ; num < codeset_num; num++) { |
634 | *codeset = codeset_list[num]; |
635 | ctconv = (*codeset)->ctconv; |
636 | ctextseg = (*codeset)->ctextseg; |
637 | |
638 | num_charsets = (*codeset)->num_charsets; |
639 | charset_list = (*codeset)->charset_list; |
640 | |
641 | glyph_index_tmp = conv_to_source(ctconv, *glyph_index); |
642 | |
643 | if (charset->source == CSsrcStd) { |
644 | |
645 | /* Standard Character Set Encoding */ |
646 | if (glyph_index_tmp == *glyph_index) { |
647 | for (j = 0; j < num_charsets; j++) { |
648 | if (charset_list[j] == charset) { |
649 | goto end_loop; |
650 | } |
651 | } |
652 | } |
653 | |
654 | } else { |
655 | |
656 | /* Non-Standard Character Set Encoding */ |
657 | for (j = 0; j < num_charsets; j++) { |
658 | if (charset_list[j] == charset) { |
659 | goto end_loop; |
660 | } |
661 | } |
662 | |
663 | if (glyph_index_tmp != *glyph_index) { |
664 | if (ctextseg && ctextseg->charset == charset) { |
665 | goto end_loop; |
666 | } |
667 | } |
668 | |
669 | } |
670 | |
671 | } |
672 | |
673 | end_loop: |
674 | if (num < codeset_num) { |
675 | *glyph_index = glyph_index_tmp; |
676 | return(True1); |
677 | } |
678 | |
679 | return(False0); |
680 | } |
681 | |
682 | #define check_string_encoding(codeset)(codeset->string_encoding) (codeset->string_encoding) |
683 | |
684 | static void |
685 | output_ulong_value( |
686 | char *outbufptr, |
687 | unsigned long code, |
688 | int length, |
689 | XlcSide side) |
690 | { |
691 | int i; |
692 | |
693 | for (i = (length - 1) * 8; i >= 0; i -= 8) { |
694 | *outbufptr = ( code >> i) & 0xff; |
695 | |
696 | if (side == XlcC0 || side == XlcGL) { |
697 | *outbufptr = *outbufptr & GL0x7f; |
698 | } else if (side == XlcC1 || side == XlcGR) { |
699 | *outbufptr = *outbufptr | GR0x80; |
700 | } |
701 | |
702 | outbufptr++; |
703 | } |
704 | } |
705 | |
706 | /* -------------------------------------------------------------------------- */ |
707 | /* Init */ |
708 | /* -------------------------------------------------------------------------- */ |
709 | |
710 | static XlcCharSet default_GL_charset = 0; |
711 | static XlcCharSet default_GR_charset = 0; |
712 | |
713 | static void |
714 | init_state( |
715 | XlcConv conv) |
716 | { |
717 | State state = (State) conv->state; |
718 | |
719 | /* for CT */ |
720 | state->charset = NULL((void*)0); |
721 | state->GL_charset = default_GL_charset; |
722 | state->GR_charset = default_GR_charset; |
723 | |
724 | /* for MB shift state */ |
725 | state->GL_codeset = XLC_GENERIC(state->lcd, initial_state_GL)(((XLCdGeneric) state->lcd->core)->gen.initial_state_GL ); |
726 | state->GR_codeset = XLC_GENERIC(state->lcd, initial_state_GR)(((XLCdGeneric) state->lcd->core)->gen.initial_state_GR ); |
727 | } |
728 | |
729 | /* -------------------------------------------------------------------------- */ |
730 | /* Convert */ |
731 | /* -------------------------------------------------------------------------- */ |
732 | |
733 | static int |
734 | mbstowcs_org( |
735 | XlcConv conv, |
736 | XPointer *from, |
737 | int *from_left, |
738 | XPointer *to, |
739 | int *to_left, |
740 | XPointer *args, |
741 | int num_args) |
742 | { |
743 | State state = (State) conv->state; |
744 | XLCd lcd = state->lcd; |
745 | |
746 | unsigned char ch; |
747 | unsigned long mb = 0; |
748 | wchar_t wc; |
749 | |
750 | int length = 0, len_left = 0; |
751 | int unconv_num = 0; |
752 | int num; |
753 | |
754 | CodeSet codeset = NULL((void*)0); |
755 | |
756 | const char *inbufptr = *from; |
757 | wchar_t *outbufptr = (wchar_t *) *to; |
758 | int from_size = *from_left; |
759 | |
760 | unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table)(((XLCdGeneric) lcd->core)->gen.mb_parse_table); |
761 | |
762 | if (from == NULL((void*)0) || *from == NULL((void*)0)) { |
763 | _XlcResetConverter(conv); |
764 | return( 0 ); |
765 | } |
766 | |
767 | if (*from_left > *to_left) |
768 | *from_left = *to_left; |
769 | |
770 | while (*from_left && *to_left) { |
771 | |
772 | ch = *inbufptr++; |
773 | (*from_left)--; |
774 | |
775 | /* null ? */ |
776 | if (!ch) { |
777 | if (outbufptr) {*outbufptr++ = L'\0';} |
778 | (*to_left)--; |
779 | |
780 | /* error check */ |
781 | if (len_left) { |
782 | unconv_num += (length - len_left); |
783 | len_left = 0; |
784 | } |
785 | |
786 | continue; |
787 | } |
788 | |
789 | /* same mb char data */ |
790 | if (len_left) |
791 | goto output_one_wc; |
792 | |
793 | /* next mb char data for single shift ? */ |
794 | if (mb_parse_table && (num = mb_parse_table[ch]) ) { |
795 | codeset = mb_parse_codeset(state, num, &inbufptr, from_left); |
796 | if (codeset != NULL((void*)0)) { |
797 | length = len_left = codeset->length; |
798 | mb = 0; |
799 | continue; |
800 | } |
801 | } |
802 | |
803 | /* next mb char data for byteM ? */ |
804 | if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1)))) |
805 | goto next_mb_char; |
806 | |
807 | /* next mb char data for GL or GR side ? */ |
808 | if ((codeset = GLGR_parse_codeset(ch)(((ch) & 0x80) ? (state->GR_codeset) : (state->GL_codeset ) ))) |
809 | goto next_mb_char; |
810 | |
811 | /* can't find codeset for the ch */ |
812 | unconv_num++; |
813 | continue; |
814 | |
815 | next_mb_char: |
816 | length = len_left = codeset->length; |
817 | mb = 0; |
818 | |
819 | output_one_wc: |
820 | mb = (mb << 8) | ch; /* 1 byte left shift */ |
821 | len_left--; |
822 | |
823 | /* last of one mb char data */ |
824 | if (!len_left) { |
825 | gi_to_wc(lcd, mb_to_gi(mb, codeset), codeset, &wc); |
826 | if (outbufptr) {*outbufptr++ = wc;} |
827 | (*to_left)--; |
828 | } |
829 | |
830 | } /* end of while */ |
831 | |
832 | /* error check on last char */ |
833 | if (len_left) { |
834 | inbufptr -= (length - len_left); |
835 | (*from_left) += (length - len_left); |
836 | unconv_num += (length - len_left); |
837 | } |
838 | |
839 | *from = (XPointer) ((const char *) *from + from_size); |
840 | *from_left = 0; |
841 | *to = (XPointer) outbufptr; |
842 | |
843 | return unconv_num; |
844 | } |
845 | |
846 | static int |
847 | stdc_mbstowcs( |
848 | XlcConv conv, |
849 | XPointer *from, |
850 | int *from_left, |
851 | XPointer *to, |
852 | int *to_left, |
853 | XPointer *args, |
854 | int num_args) |
855 | { |
856 | const char *src = *((const char **) from); |
857 | wchar_t *dst = *((wchar_t **) to); |
858 | int src_left = *from_left; |
859 | int dst_left = *to_left; |
860 | int length, unconv_num = 0; |
861 | |
862 | while (src_left > 0 && dst_left > 0) { |
863 | length = mbtowc(dst, src, src_left); |
864 | |
865 | if (length > 0) { |
866 | src += length; |
867 | src_left -= length; |
868 | if (dst) |
869 | dst++; |
870 | dst_left--; |
871 | } else if (length < 0) { |
872 | src++; |
873 | src_left--; |
874 | unconv_num++; |
875 | } else { |
876 | /* null ? */ |
877 | src++; |
878 | src_left--; |
879 | if (dst) |
880 | *dst++ = L'\0'; |
881 | dst_left--; |
882 | } |
883 | } |
884 | |
885 | *from = (XPointer) src; |
886 | if (dst) |
887 | *to = (XPointer) dst; |
888 | *from_left = src_left; |
889 | *to_left = dst_left; |
890 | |
891 | return unconv_num; |
892 | } |
893 | |
894 | static int |
895 | wcstombs_org( |
896 | XlcConv conv, |
897 | XPointer *from, |
898 | int *from_left, |
899 | XPointer *to, |
900 | int *to_left, |
901 | XPointer *args, |
902 | int num_args) |
903 | { |
904 | State state = (State) conv->state; |
905 | XLCd lcd = state->lcd; |
906 | |
907 | char *encoding; |
908 | unsigned long mb, glyph_index; |
909 | wchar_t wc; |
910 | |
911 | int length; |
912 | int unconv_num = 0; |
913 | |
914 | CodeSet codeset; |
915 | |
916 | const wchar_t *inbufptr = (const wchar_t *) *from; |
917 | char *outbufptr = *to; |
918 | int from_size = *from_left; |
919 | |
920 | const char *default_string = XLC_PUBLIC(lcd, default_string)(((XLCdPublic) lcd->core)->pub.default_string); |
921 | int defstr_len = strlen(default_string); |
922 | |
923 | |
924 | if (*from_left > *to_left) |
925 | *from_left = *to_left; |
926 | |
927 | while (*from_left && *to_left) { |
928 | |
929 | wc = *inbufptr++; |
930 | (*from_left)--; |
931 | |
932 | /* null ? */ |
933 | if (!wc) { |
934 | if (outbufptr) {*outbufptr++ = '\0';} |
935 | (*to_left)--; |
936 | |
937 | continue; |
938 | } |
939 | |
940 | /* convert */ |
941 | if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) { |
942 | |
943 | /* output default_string of XDefaultString() */ |
944 | if (*to_left < defstr_len) |
945 | break; |
946 | if (outbufptr) { |
947 | strncpy((char *)outbufptr, default_string, defstr_len); |
948 | outbufptr += defstr_len; |
949 | } |
950 | (*to_left) -= defstr_len; |
951 | |
952 | unconv_num++; |
953 | |
954 | } else { |
955 | mb = gi_to_mb(glyph_index, codeset); |
956 | if (codeset->parse_info) { |
957 | Boolint need_shift = False0; |
958 | switch (codeset->parse_info->type) { |
959 | case E_LSL : |
960 | if (codeset != state->GL_codeset) { |
961 | need_shift = True1; |
962 | state->GL_codeset = codeset; |
963 | } |
964 | break; |
965 | case E_LSR : |
966 | if (codeset != state->GR_codeset) { |
967 | need_shift = True1; |
968 | state->GR_codeset = codeset; |
969 | } |
970 | break; |
971 | /* case E_SS */ |
972 | default: |
973 | need_shift = True1; |
974 | } |
975 | |
976 | /* output shift sequence */ |
977 | if (need_shift) { |
978 | encoding = codeset->parse_info->encoding; |
979 | length = strlen(encoding); |
980 | if (*to_left < length) |
981 | break; |
982 | if (outbufptr) { |
983 | strncpy((char *)outbufptr, encoding, length); |
984 | outbufptr += length; |
985 | } |
986 | (*to_left) -= length; |
987 | } |
988 | } |
989 | |
990 | /* output characters */ |
991 | length = codeset->length; |
992 | if (*to_left < length) |
993 | break; |
994 | |
995 | if (outbufptr) { |
996 | output_ulong_value(outbufptr, mb, length, XlcNONE); |
997 | outbufptr += length; |
998 | } |
999 | |
1000 | (*to_left) -= length; |
1001 | } |
1002 | |
1003 | } /* end of while */ |
1004 | |
1005 | *from = (XPointer) ((const wchar_t *) *from + from_size); |
1006 | *from_left = 0; |
1007 | *to = (XPointer) outbufptr; |
1008 | |
1009 | return unconv_num; |
1010 | } |
1011 | |
1012 | static int |
1013 | stdc_wcstombs( |
1014 | XlcConv conv, |
1015 | XPointer *from, |
1016 | int *from_left, |
1017 | XPointer *to, |
1018 | int *to_left, |
1019 | XPointer *args, |
1020 | int num_args) |
1021 | { |
1022 | const wchar_t *src = *((const wchar_t **) from); |
1023 | char *dst = *((char **) to); |
1024 | int src_left = *from_left; |
1025 | int dst_left = *to_left; |
1026 | int length, unconv_num = 0; |
1027 | |
1028 | while (src_left > 0 && dst_left >= MB_CUR_MAX(__ctype_get_mb_cur_max ())) { |
1029 | length = wctomb(dst, *src); /* XXX */ |
1030 | |
1031 | if (length > 0) { |
1032 | src++; |
1033 | src_left--; |
1034 | if (dst) |
1035 | dst += length; |
1036 | dst_left -= length; |
1037 | } else if (length < 0) { |
1038 | src++; |
1039 | src_left--; |
1040 | unconv_num++; |
1041 | } |
1042 | } |
1043 | |
1044 | *from = (XPointer) src; |
1045 | if (dst) |
1046 | *to = (XPointer) dst; |
1047 | *from_left = src_left; |
1048 | *to_left = dst_left; |
1049 | |
1050 | return unconv_num; |
1051 | } |
1052 | |
1053 | static int |
1054 | wcstocts( |
1055 | XlcConv conv, |
1056 | XPointer *from, |
1057 | int *from_left, |
1058 | XPointer *to, |
1059 | int *to_left, |
1060 | XPointer *args, |
1061 | int num_args) |
1062 | { |
1063 | State state = (State) conv->state; |
1064 | XLCd lcd = state->lcd; |
1065 | |
1066 | unsigned long glyph_index; |
1067 | wchar_t wc; |
1068 | |
1069 | int total_len, seq_len, name_len; |
1070 | int unconv_num = 0; |
1071 | Boolint first_flag = True1, standard_flag; |
1072 | XlcSide side; |
1073 | |
1074 | CodeSet codeset; |
1075 | XlcCharSet charset, old_charset = NULL((void*)0); |
1076 | const char *ct_sequence; |
1077 | |
1078 | const wchar_t *inbufptr = (const wchar_t *) *from; |
1079 | char *outbufptr = *to; |
1080 | int from_size = *from_left; |
1081 | char *ext_seg_len = NULL((void*)0); |
1082 | |
1083 | if (*from_left > *to_left) |
1084 | *from_left = *to_left; |
1085 | |
1086 | while (*from_left && *to_left) { |
1087 | |
1088 | wc = *inbufptr++; |
1089 | (*from_left)--; |
1090 | |
1091 | /* null ? */ |
1092 | if (!wc) { |
1093 | if (outbufptr) {*outbufptr++ = '\0';} |
1094 | (*to_left)--; |
1095 | |
1096 | continue; |
1097 | } |
1098 | |
1099 | /* convert */ |
1100 | if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) { |
1101 | unconv_num++; |
1102 | continue; |
1103 | } |
1104 | |
1105 | /* parse charset */ |
1106 | if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) { |
1107 | unconv_num++; |
1108 | continue; |
1109 | } |
1110 | |
1111 | /* Standard Character Set Encoding ? */ |
1112 | standard_flag = charset->source == CSsrcStd ? True1 : False0; |
1113 | |
1114 | /* |
1115 | * Non-Standard Character Set Encoding |
1116 | * |
1117 | * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+ |
1118 | * | esc sequence | M | L | encoding name | STX | |
1119 | * +-----+-----+-----+-----+-----+-----+-----+---- ----+-----+-----+ |
1120 | * 4bytes 1byte 1byte variable length 1byte |
1121 | * | | |
1122 | * +-----------------------------------------+ |
1123 | * name length = ((M - 128) * 128) + (L - 128) |
1124 | */ |
1125 | |
1126 | /* make encoding data */ |
1127 | ct_sequence = charset->ct_sequence; |
1128 | side = charset->side; |
1129 | seq_len = strlen(ct_sequence); |
1130 | if (standard_flag) { |
1131 | name_len = 0; |
Value stored to 'name_len' is never read | |
1132 | total_len = seq_len; |
1133 | } else { |
1134 | name_len = strlen(charset->encoding_name) + 1; |
1135 | total_len = seq_len + name_len + 2; |
1136 | } |
1137 | |
1138 | /* output escape sequence of CT */ |
1139 | if ( (charset != old_charset) && |
1140 | !(first_flag && charset->string_encoding) ){ |
1141 | |
1142 | if ( (ext_seg_len != NULL((void*)0)) && outbufptr) { |
1143 | int i = (outbufptr - ext_seg_len) - 2; |
1144 | *ext_seg_len++ = i / 128 + 128; |
1145 | *ext_seg_len = i % 128 + 128; |
1146 | ext_seg_len = NULL((void*)0); |
1147 | } |
1148 | |
1149 | if (*to_left < total_len + 1) { |
1150 | unconv_num++; |
1151 | break; |
1152 | } |
1153 | |
1154 | if (outbufptr) { |
1155 | strcpy((char *)outbufptr, ct_sequence); |
1156 | outbufptr += seq_len; |
1157 | |
1158 | if (!standard_flag) { |
1159 | const char *i = charset->encoding_name; |
1160 | ext_seg_len = outbufptr; |
1161 | outbufptr += 2; |
1162 | for (; *i ; i++) |
1163 | *outbufptr++ = ((*i >= 'A') && (*i <= 'Z')) ? |
1164 | *i - 'A' + 'a' : *i; |
1165 | *outbufptr++ = STX0x02; |
1166 | } |
1167 | } |
1168 | |
1169 | (*to_left) -= total_len; |
1170 | |
1171 | first_flag = False0; |
1172 | old_charset = charset; |
1173 | } |
1174 | |
1175 | /* output glyph index */ |
1176 | if (codeset->ctconv) |
1177 | glyph_index = conv_to_dest(codeset->ctconv, glyph_index); |
1178 | if (*to_left < charset->char_size) { |
1179 | unconv_num++; |
1180 | break; |
1181 | } |
1182 | |
1183 | if (outbufptr) { |
1184 | output_ulong_value(outbufptr, glyph_index, charset->char_size, side); |
1185 | outbufptr += charset->char_size; |
1186 | } |
1187 | |
1188 | (*to_left) -= charset->char_size; |
1189 | |
1190 | } /* end of while */ |
1191 | |
1192 | if ( (ext_seg_len != NULL((void*)0)) && outbufptr) { |
1193 | int i = (outbufptr - ext_seg_len) - 2; |
1194 | *ext_seg_len++ = i / 128 + 128; |
1195 | *ext_seg_len = i % 128 + 128; |
1196 | } |
1197 | |
1198 | *from = (XPointer) ((const wchar_t *) *from + from_size); |
1199 | *from_left = 0; |
1200 | *to = (XPointer) outbufptr; |
1201 | |
1202 | return unconv_num; |
1203 | } |
1204 | |
1205 | static int |
1206 | stdc_wcstocts( |
1207 | XlcConv conv, |
1208 | XPointer *from, |
1209 | int *from_left, |
1210 | XPointer *to, |
1211 | int *to_left, |
1212 | XPointer *args, |
1213 | int num_args) |
1214 | { |
1215 | XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX)malloc((((*from_left) * (__ctype_get_mb_cur_max ())) == 0 ? 1 : ((*from_left) * (__ctype_get_mb_cur_max ())))); |
1216 | char *buf_ptr1 = buf; |
1217 | int buf_left1 = (*from_left) * MB_CUR_MAX(__ctype_get_mb_cur_max ()); |
1218 | char *buf_ptr2 = buf_ptr1; |
1219 | int buf_left2; |
1220 | int unconv_num1 = 0, unconv_num2 = 0; |
1221 | |
1222 | unconv_num1 = stdc_wcstombs(conv, |
1223 | from, from_left, &buf_ptr1, &buf_left1, args, num_args); |
1224 | if (unconv_num1 < 0) |
1225 | goto ret; |
1226 | |
1227 | buf_left2 = buf_ptr1 - buf_ptr2; |
1228 | |
1229 | unconv_num2 = mbstocts(conv, |
1230 | &buf_ptr2, &buf_left2, to, to_left, args, num_args); |
1231 | if (unconv_num2 < 0) |
1232 | goto ret; |
1233 | |
1234 | ret: |
1235 | if (buf) |
1236 | Xfree((char *)buf)free(((char *)buf)); |
1237 | |
1238 | return (unconv_num1 + unconv_num2); |
1239 | } |
1240 | |
1241 | static int |
1242 | ctstowcs( |
1243 | XlcConv conv, |
1244 | XPointer *from, |
1245 | int *from_left, |
1246 | XPointer *to, |
1247 | int *to_left, |
1248 | XPointer *args, |
1249 | int num_args) |
1250 | { |
1251 | State state = (State) conv->state; |
1252 | XLCd lcd = state->lcd; |
1253 | |
1254 | unsigned char ch; |
1255 | unsigned long glyph_index = 0; |
1256 | wchar_t wc; |
1257 | |
1258 | int ctr_seq_len = 0, gi_len_left = 0, gi_len = 0; |
1259 | int unconv_num = 0; |
1260 | |
1261 | CodeSet codeset = NULL((void*)0); |
1262 | XlcCharSet charset_tmp; |
1263 | |
1264 | const char *inbufptr = *from; |
1265 | wchar_t *outbufptr = (wchar_t *) *to; |
1266 | int from_size = *from_left; |
1267 | |
1268 | _XlcResetConverter(conv); /* ??? */ |
1269 | |
1270 | if (from == NULL((void*)0) || *from == NULL((void*)0)) { |
1271 | _XlcResetConverter(conv); |
1272 | return( 0 ); |
1273 | } |
1274 | |
1275 | if (*from_left > *to_left) |
1276 | *from_left = *to_left; |
1277 | |
1278 | while (*from_left && *to_left) { |
1279 | |
1280 | ch = *inbufptr++; |
1281 | (*from_left)--; |
1282 | |
1283 | /* null ? */ |
1284 | if (!ch) { |
1285 | if (outbufptr) {*outbufptr++ = L'\0';} |
1286 | (*to_left)--; |
1287 | |
1288 | /* error check */ |
1289 | if (gi_len_left) { |
1290 | unconv_num += (gi_len - gi_len_left); |
1291 | gi_len_left = 0; |
1292 | } |
1293 | |
1294 | continue; |
1295 | } |
1296 | |
1297 | /* same glyph_index data */ |
1298 | if (gi_len_left) |
1299 | goto output_one_wc; |
1300 | |
1301 | /* control sequence ? */ |
1302 | if (ch == CSI0x9b) { |
1303 | if ( !ct_parse_csi(inbufptr - 1, &ctr_seq_len) ) |
1304 | goto skip_the_seg; |
1305 | |
1306 | if (*from_left + 1 < ctr_seq_len) { |
1307 | inbufptr--; |
1308 | (*from_left)++; |
1309 | unconv_num += *from_left; |
1310 | break; |
1311 | } |
1312 | |
1313 | /* skip the control sequence */ |
1314 | inbufptr += (ctr_seq_len - 1); |
1315 | *from_left -= (ctr_seq_len - 1); |
1316 | |
1317 | continue; |
1318 | } |
1319 | |
1320 | /* escape sequence ? */ |
1321 | if (ch == ESC0x1b) { |
1322 | if ( !ct_parse_charset(lcd, |
1323 | inbufptr - 1, &state->charset, &ctr_seq_len) ) |
1324 | goto skip_the_seg; |
1325 | |
1326 | if (state->charset->side == XlcC0 || |
1327 | state->charset->side == XlcGL) |
1328 | { |
1329 | state->GL_charset = state->charset; |
1330 | } |
1331 | else if (state->charset->side == XlcC1 || |
1332 | state->charset->side == XlcGR) |
1333 | { |
1334 | state->GR_charset = state->charset; |
1335 | } |
1336 | else if (state->charset->side == XlcGLGR) |
1337 | { |
1338 | state->GL_charset = state->charset; |
1339 | state->GR_charset = state->charset; |
1340 | } |
1341 | |
1342 | if (*from_left + 1 < ctr_seq_len) { |
1343 | inbufptr--; |
1344 | (*from_left)++; |
1345 | unconv_num += *from_left; |
1346 | break; |
1347 | } |
1348 | |
1349 | /* skip the escape sequence */ |
1350 | inbufptr += (ctr_seq_len - 1); |
1351 | *from_left -= (ctr_seq_len - 1); |
1352 | |
1353 | continue; |
1354 | } |
1355 | |
1356 | /* check current state */ |
1357 | if (isleftside(ch)(!((ch) & 0x80))) |
1358 | state->charset = state->GL_charset; |
1359 | else |
1360 | state->charset = state->GR_charset; |
1361 | |
1362 | gi_len = gi_len_left = state->charset->char_size; |
1363 | glyph_index = 0; |
1364 | |
1365 | output_one_wc: |
1366 | if (state->charset->side == XlcC1 || state->charset->side == XlcGR) |
1367 | glyph_index = (glyph_index << 8) | (ch & GL0x7f); |
1368 | else |
1369 | glyph_index = (glyph_index << 8) | ch; |
1370 | |
1371 | gi_len_left--; |
1372 | |
1373 | /* last of one glyph_index data */ |
1374 | if (!gi_len_left) { |
1375 | |
1376 | /* segment conversion */ |
1377 | charset_tmp = state->charset; |
1378 | segment_conversion(lcd, &charset_tmp, &glyph_index); |
1379 | |
1380 | /* get codeset */ |
1381 | if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp, |
1382 | &codeset, &glyph_index) ) { |
1383 | unconv_num += gi_len; |
1384 | continue; |
1385 | } |
1386 | |
1387 | /* convert glyph index to wicd char */ |
1388 | gi_to_wc(lcd, glyph_index, codeset, &wc); |
1389 | if (outbufptr) {*outbufptr++ = wc;} |
1390 | (*to_left)--; |
1391 | } |
1392 | |
1393 | continue; |
1394 | |
1395 | skip_the_seg: |
1396 | /* skip until next escape or control sequence */ |
1397 | while ( *from_left ) { |
1398 | ch = *inbufptr++; |
1399 | (*from_left)--; |
1400 | unconv_num++; |
1401 | |
1402 | if (ch == ESC0x1b || ch == CSI0x9b) { |
1403 | inbufptr--; |
1404 | (*from_left)++; |
1405 | unconv_num--; |
1406 | break; |
1407 | } |
1408 | } |
1409 | |
1410 | if ( !(*from_left) ) |
1411 | break; |
1412 | |
1413 | } /* end of while */ |
1414 | |
1415 | /* error check on last char */ |
1416 | if (gi_len_left) { |
1417 | inbufptr -= (gi_len - gi_len_left); |
1418 | (*from_left) += (gi_len - gi_len_left); |
1419 | unconv_num += (gi_len - gi_len_left); |
1420 | } |
1421 | |
1422 | *from = (XPointer) ((const char *) *from + from_size); |
1423 | *from_left = 0; |
1424 | *to = (XPointer) outbufptr; |
1425 | |
1426 | return unconv_num; |
1427 | } |
1428 | |
1429 | static int |
1430 | cstowcs( |
1431 | XlcConv conv, |
1432 | XPointer *from, |
1433 | int *from_left, |
1434 | XPointer *to, |
1435 | int *to_left, |
1436 | XPointer *args, |
1437 | int num_args) |
1438 | { |
1439 | State state = (State) conv->state; |
1440 | XLCd lcd = state->lcd; |
1441 | |
1442 | unsigned char ch; |
1443 | unsigned long glyph_index = 0; |
1444 | wchar_t wc; |
1445 | int gi_len_left = 0, gi_len = 0; |
1446 | |
1447 | int unconv_num = 0; |
1448 | |
1449 | CodeSet codeset = NULL((void*)0); |
1450 | XlcCharSet charset, charset_tmp; |
1451 | |
1452 | const char *inbufptr = *from; |
1453 | wchar_t *outbufptr = (wchar_t *) *to; |
1454 | int from_size = *from_left; |
1455 | |
1456 | if (from == NULL((void*)0) || *from == NULL((void*)0)) { |
1457 | return( 0 ); |
1458 | } |
1459 | |
1460 | charset = (XlcCharSet) args[0]; |
1461 | |
1462 | while (*from_left && *to_left) { |
1463 | |
1464 | if (!gi_len_left) { |
1465 | gi_len_left = gi_len = charset->char_size; |
1466 | glyph_index = 0; |
1467 | } |
1468 | |
1469 | ch = *inbufptr++; |
1470 | (*from_left)--; |
1471 | |
1472 | /* null ? */ |
1473 | if (!ch) { |
1474 | if (outbufptr) {*outbufptr++ = L'\0';} |
1475 | (*to_left)--; |
1476 | |
1477 | /* error check */ |
1478 | if (gi_len_left) { |
1479 | unconv_num += (gi_len - gi_len_left); |
1480 | gi_len_left = 0; |
1481 | } |
1482 | continue; |
1483 | } |
1484 | |
1485 | if (charset->side == XlcC1 || charset->side == XlcGR) |
1486 | glyph_index = (glyph_index << 8) | (ch & GL0x7f); |
1487 | else |
1488 | glyph_index = (glyph_index << 8) | ch; |
1489 | |
1490 | gi_len_left--; |
1491 | |
1492 | /* last of one glyph_index data */ |
1493 | if (!gi_len_left) { |
1494 | |
1495 | /* segment conversion */ |
1496 | charset_tmp = charset; |
1497 | segment_conversion(lcd, &charset_tmp, &glyph_index); |
1498 | |
1499 | /* get codeset */ |
1500 | if ( !_XlcGetCodeSetFromCharSet(lcd, charset_tmp, |
1501 | &codeset, &glyph_index) ) { |
1502 | unconv_num += gi_len; |
1503 | continue; |
1504 | } |
1505 | |
1506 | /* convert glyph index to wicd char */ |
1507 | gi_to_wc(lcd, glyph_index, codeset, &wc); |
1508 | if (outbufptr) {*outbufptr++ = wc;} |
1509 | (*to_left)--; |
1510 | } |
1511 | |
1512 | } /* end of while */ |
1513 | |
1514 | /* error check on last char */ |
1515 | if (gi_len_left) { |
1516 | inbufptr -= (gi_len - gi_len_left); |
1517 | (*from_left) += (gi_len - gi_len_left); |
1518 | unconv_num += (gi_len - gi_len_left); |
1519 | } |
1520 | |
1521 | *from = (XPointer) ((const char *) *from + from_size); |
1522 | *from_left = 0; |
1523 | *to = (XPointer) outbufptr; |
1524 | |
1525 | return unconv_num; |
1526 | } |
1527 | |
1528 | static int |
1529 | stdc_ctstowcs( |
1530 | XlcConv conv, |
1531 | XPointer *from, |
1532 | int *from_left, |
1533 | XPointer *to, |
1534 | int *to_left, |
1535 | XPointer *args, |
1536 | int num_args) |
1537 | { |
1538 | XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX)malloc((((*from_left) * (__ctype_get_mb_cur_max ())) == 0 ? 1 : ((*from_left) * (__ctype_get_mb_cur_max ())))); |
1539 | char *buf_ptr1 = buf; |
1540 | int buf_left1 = (*from_left) * MB_CUR_MAX(__ctype_get_mb_cur_max ()); |
1541 | char *buf_ptr2 = buf_ptr1; |
1542 | int buf_left2; |
1543 | int unconv_num1 = 0, unconv_num2 = 0; |
1544 | |
1545 | unconv_num1 = ctstombs(conv, |
1546 | from, from_left, &buf_ptr1, &buf_left1, args, num_args); |
1547 | if (unconv_num1 < 0) |
1548 | goto ret; |
1549 | |
1550 | buf_left2 = buf_ptr1 - buf_ptr2; |
1551 | |
1552 | unconv_num2 = stdc_mbstowcs(conv, |
1553 | &buf_ptr2, &buf_left2, to, to_left, args, num_args); |
1554 | if (unconv_num2 < 0) |
1555 | goto ret; |
1556 | |
1557 | ret: |
1558 | if (buf) |
1559 | Xfree((char *)buf)free(((char *)buf)); |
1560 | |
1561 | return (unconv_num1 + unconv_num2); |
1562 | } |
1563 | |
1564 | static int |
1565 | stdc_cstowcs( |
1566 | XlcConv conv, |
1567 | XPointer *from, |
1568 | int *from_left, |
1569 | XPointer *to, |
1570 | int *to_left, |
1571 | XPointer *args, |
1572 | int num_args) |
1573 | { |
1574 | XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX)malloc((((*from_left) * (__ctype_get_mb_cur_max ())) == 0 ? 1 : ((*from_left) * (__ctype_get_mb_cur_max ())))); |
1575 | char *buf_ptr1 = buf; |
1576 | int buf_left1 = (*from_left) * MB_CUR_MAX(__ctype_get_mb_cur_max ()); |
1577 | char *buf_ptr2 = buf_ptr1; |
1578 | int buf_left2; |
1579 | int unconv_num1 = 0, unconv_num2 = 0; |
1580 | |
1581 | unconv_num1 = cstombs(conv, |
1582 | from, from_left, &buf_ptr1, &buf_left1, args, num_args); |
1583 | if (unconv_num1 < 0) |
1584 | goto ret; |
1585 | |
1586 | buf_left2 = buf_ptr1 - buf_ptr2; |
1587 | |
1588 | unconv_num2 = stdc_mbstowcs(conv, |
1589 | &buf_ptr2, &buf_left2, to, to_left, args, num_args); |
1590 | if (unconv_num2 < 0) |
1591 | goto ret; |
1592 | |
1593 | ret: |
1594 | if (buf) |
1595 | Xfree((char *)buf)free(((char *)buf)); |
1596 | |
1597 | return (unconv_num1 + unconv_num2); |
1598 | } |
1599 | |
1600 | static int |
1601 | mbstocts( |
1602 | XlcConv conv, |
1603 | XPointer *from, |
1604 | int *from_left, |
1605 | XPointer *to, |
1606 | int *to_left, |
1607 | XPointer *args, |
1608 | int num_args) |
1609 | { |
1610 | XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t))malloc((((*from_left) * sizeof(wchar_t)) == 0 ? 1 : ((*from_left ) * sizeof(wchar_t)))); |
1611 | char *buf_ptr1 = buf; |
1612 | int buf_left1 = (*from_left); |
1613 | char *buf_ptr2 = buf_ptr1; |
1614 | int buf_left2; |
1615 | int unconv_num1 = 0, unconv_num2 = 0; |
1616 | |
1617 | unconv_num1 = mbstowcs_org(conv, |
1618 | from, from_left, &buf_ptr1, &buf_left1, args, num_args); |
1619 | if (unconv_num1 < 0) |
1620 | goto ret; |
1621 | |
1622 | buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t); |
1623 | |
1624 | unconv_num2 += wcstocts(conv, |
1625 | &buf_ptr2, &buf_left2, to, to_left, args, num_args); |
1626 | if (unconv_num2 < 0) |
1627 | goto ret; |
1628 | |
1629 | ret: |
1630 | if (buf) |
1631 | Xfree((char *)buf)free(((char *)buf)); |
1632 | |
1633 | return (unconv_num1 + unconv_num2); |
1634 | } |
1635 | |
1636 | static int |
1637 | mbstostr( |
1638 | XlcConv conv, |
1639 | XPointer *from, |
1640 | int *from_left, |
1641 | XPointer *to, |
1642 | int *to_left, |
1643 | XPointer *args, |
1644 | int num_args) |
1645 | { |
1646 | State state = (State) conv->state; |
1647 | XLCd lcd = state->lcd; |
1648 | |
1649 | unsigned char ch; |
1650 | unsigned long mb = 0; |
1651 | |
1652 | int length = 0, len_left = 0; |
1653 | int unconv_num = 0; |
1654 | int num; |
1655 | |
1656 | CodeSet codeset = NULL((void*)0); |
1657 | |
1658 | const char *inbufptr = *from; |
1659 | char *outbufptr = *to; |
1660 | int from_size = *from_left; |
1661 | |
1662 | unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table)(((XLCdGeneric) lcd->core)->gen.mb_parse_table); |
1663 | |
1664 | if (from == NULL((void*)0) || *from == NULL((void*)0)) { |
1665 | _XlcResetConverter(conv); |
1666 | return( 0 ); |
1667 | } |
1668 | |
1669 | if (*from_left > *to_left) |
1670 | *from_left = *to_left; |
1671 | |
1672 | while (*from_left && *to_left) { |
1673 | |
1674 | ch = *inbufptr++; |
1675 | (*from_left)--; |
1676 | |
1677 | /* null ? */ |
1678 | if (!ch) { |
1679 | if (outbufptr) {*outbufptr++ = '\0';} |
1680 | (*to_left)--; |
1681 | |
1682 | /* error check */ |
1683 | if (len_left) { |
1684 | unconv_num += (length - len_left); |
1685 | len_left = 0; |
1686 | } |
1687 | |
1688 | continue; |
1689 | } |
1690 | |
1691 | /* same mb char data */ |
1692 | if (len_left) |
1693 | goto output_one_mb; |
1694 | |
1695 | /* next mb char data for single shift ? */ |
1696 | if (mb_parse_table && (num = mb_parse_table[ch]) ) { |
1697 | codeset = mb_parse_codeset(state, num, &inbufptr, from_left); |
1698 | if (codeset != NULL((void*)0)) { |
1699 | length = len_left = codeset->length; |
1700 | mb = 0; |
1701 | continue; |
1702 | } |
1703 | } |
1704 | |
1705 | /* next char data : byteM ? */ |
1706 | if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1)))) |
1707 | goto next_mb_char; |
1708 | |
1709 | /* next char data : GL or GR side ? */ |
1710 | if ((codeset = GLGR_parse_codeset(ch)(((ch) & 0x80) ? (state->GR_codeset) : (state->GL_codeset ) ))) |
1711 | goto next_mb_char; |
1712 | |
1713 | /* can't find codeset for the ch */ |
1714 | unconv_num++; |
1715 | continue; |
1716 | |
1717 | next_mb_char: |
1718 | length = len_left = codeset->length; |
1719 | mb = 0; |
1720 | |
1721 | output_one_mb: |
1722 | mb = (mb << 8) | ch; /* 1 byte left shift */ |
1723 | len_left--; |
1724 | |
1725 | /* last of one mb char data */ |
1726 | if (!len_left) { |
1727 | if (check_string_encoding(codeset)(codeset->string_encoding)) { |
1728 | if (outbufptr) {*outbufptr++ = mb & 0xff;} |
1729 | (*to_left)--; |
1730 | } else { |
1731 | unconv_num++; |
1732 | } |
1733 | } |
1734 | |
1735 | } /* end of while */ |
1736 | |
1737 | /* error check on last char */ |
1738 | if (len_left) { |
1739 | inbufptr -= (length - len_left); |
1740 | (*from_left) += (length - len_left); |
1741 | unconv_num += (length - len_left); |
1742 | } |
1743 | |
1744 | *from = (XPointer) ((const char *) *from + from_size); |
1745 | *from_left = 0; |
1746 | *to = (XPointer) outbufptr; |
1747 | |
1748 | return unconv_num; |
1749 | } |
1750 | |
1751 | static int |
1752 | mbtocs( |
1753 | XlcConv conv, |
1754 | XPointer *from, |
1755 | int *from_left, |
1756 | XPointer *to, |
1757 | int *to_left, |
1758 | XPointer *args, |
1759 | int num_args) |
1760 | { |
1761 | State state = (State) conv->state; |
1762 | XLCd lcd = state->lcd; |
1763 | |
1764 | unsigned char ch; |
1765 | unsigned long mb = 0; |
1766 | unsigned long glyph_index; |
1767 | |
1768 | int length = 0, len_left = 0, char_len; |
1769 | int unconv_num = 0; |
1770 | int num; |
1771 | XlcSide side; |
1772 | |
1773 | CodeSet codeset = NULL((void*)0); |
1774 | XlcCharSet charset = NULL((void*)0); |
1775 | |
1776 | const char *inbufptr = *from; |
1777 | char *outbufptr = *to; |
1778 | int from_size = *from_left; |
1779 | |
1780 | unsigned char *mb_parse_table = XLC_GENERIC(lcd, mb_parse_table)(((XLCdGeneric) lcd->core)->gen.mb_parse_table); |
1781 | |
1782 | if (from == NULL((void*)0) || *from == NULL((void*)0)) { |
1783 | _XlcResetConverter(conv); |
1784 | return( 0 ); |
1785 | } |
1786 | |
1787 | while (*from_left && *to_left) { |
1788 | |
1789 | ch = *inbufptr++; |
1790 | (*from_left)--; |
1791 | |
1792 | /* null ? */ |
1793 | if (!ch) { |
1794 | unconv_num = 1; |
1795 | if (len_left) |
1796 | unconv_num += (length - len_left); |
1797 | break; |
1798 | } |
1799 | |
1800 | /* same mb char data */ |
1801 | if (len_left) |
1802 | goto output; |
1803 | |
1804 | /* next mb char data for single shift ? */ |
1805 | if (mb_parse_table && (num = mb_parse_table[ch]) ) { |
1806 | codeset = mb_parse_codeset(state, num, &inbufptr, from_left); |
1807 | if (codeset != NULL((void*)0)) { |
1808 | length = len_left = codeset->length; |
1809 | mb = 0; |
1810 | continue; |
1811 | } |
1812 | } |
1813 | |
1814 | /* next mb char data for byteM ? */ |
1815 | if ((codeset = byteM_parse_codeset(lcd, (inbufptr - 1)))) |
1816 | goto next_mb_char; |
1817 | |
1818 | /* next mb char data for GL or GR side ? */ |
1819 | if ((codeset = GLGR_parse_codeset(ch)(((ch) & 0x80) ? (state->GR_codeset) : (state->GL_codeset ) ))) |
1820 | goto next_mb_char; |
1821 | |
1822 | /* can't find codeset for the ch */ |
1823 | unconv_num = 1; |
1824 | break; |
1825 | |
1826 | next_mb_char: |
1827 | length = len_left = codeset->length; |
1828 | mb = 0; |
1829 | |
1830 | output: |
1831 | mb = (mb << 8) | ch; /* 1 byte left shift */ |
1832 | len_left--; |
1833 | |
1834 | /* last of one mb char data */ |
1835 | if (!len_left) { |
1836 | glyph_index = mb_to_gi(mb, codeset); |
1837 | if (!(charset = gi_parse_charset(glyph_index, codeset))) { |
1838 | unconv_num = length; |
1839 | break; |
1840 | } |
1841 | char_len = charset->char_size; |
1842 | side = charset->side; |
1843 | |
1844 | /* output glyph index */ |
1845 | if (codeset->ctconv) |
1846 | glyph_index = conv_to_dest(codeset->ctconv, glyph_index); |
1847 | if (*to_left < char_len) { |
1848 | unconv_num = length; |
1849 | break; |
1850 | } |
1851 | |
1852 | if (outbufptr) { |
1853 | output_ulong_value(outbufptr, glyph_index, char_len, side); |
1854 | outbufptr += char_len; |
1855 | } |
1856 | |
1857 | (*to_left) -= char_len; |
1858 | |
1859 | break; |
1860 | } |
1861 | |
1862 | } /* end of while */ |
1863 | |
1864 | /* error end */ |
1865 | if (unconv_num) { |
1866 | *from = (XPointer) ((const char *) *from + from_size); |
1867 | *from_left = 0; |
1868 | *to = (XPointer) outbufptr; |
1869 | return -1; |
1870 | } |
1871 | |
1872 | /* normal end */ |
1873 | *from = (XPointer) inbufptr; |
1874 | *to = (XPointer) outbufptr; |
1875 | |
1876 | if (num_args > 0) |
1877 | *((XlcCharSet *) args[0]) = charset; |
1878 | |
1879 | return 0; |
1880 | } |
1881 | |
1882 | static int |
1883 | mbstocs( |
1884 | XlcConv conv, |
1885 | XPointer *from, |
1886 | int *from_left, |
1887 | XPointer *to, |
1888 | int *to_left, |
1889 | XPointer *args, |
1890 | int num_args) |
1891 | { |
1892 | int ret; |
1893 | XlcCharSet charset_old, charset = NULL((void*)0); |
1894 | XPointer tmp_args[1]; |
1895 | |
1896 | const char *inbufptr; |
1897 | int in_left; |
1898 | char *outbufptr; |
1899 | int out_left; |
1900 | tmp_args[0] = (XPointer) &charset; |
1901 | |
1902 | ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1); |
1903 | charset_old = charset; |
1904 | |
1905 | while ( ret == 0 && *from_left && *to_left) { |
1906 | inbufptr = *from; |
1907 | in_left = *from_left; |
1908 | outbufptr = *to; |
1909 | out_left = *to_left; |
1910 | ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, 1); |
1911 | if (charset_old != charset) { |
1912 | *from = (XPointer) inbufptr; |
1913 | *from_left = in_left; |
1914 | *to = (XPointer) outbufptr; |
1915 | *to_left = out_left; |
1916 | break; |
1917 | } |
1918 | } |
1919 | |
1920 | if (num_args > 0) |
1921 | *((XlcCharSet *) args[0]) = charset_old; |
1922 | |
1923 | /* error end */ |
1924 | if (ret != 0) |
1925 | return( -1 ); |
1926 | |
1927 | return(0); |
1928 | } |
1929 | |
1930 | static int |
1931 | wcstostr( |
1932 | XlcConv conv, |
1933 | XPointer *from, |
1934 | int *from_left, |
1935 | XPointer *to, |
1936 | int *to_left, |
1937 | XPointer *args, |
1938 | int num_args) |
1939 | { |
1940 | State state = (State) conv->state; |
1941 | XLCd lcd = state->lcd; |
1942 | |
1943 | char *encoding; |
1944 | unsigned long mb, glyph_index; |
1945 | wchar_t wc; |
1946 | |
1947 | int length; |
1948 | int unconv_num = 0; |
1949 | |
1950 | CodeSet codeset; |
1951 | |
1952 | const wchar_t *inbufptr = (const wchar_t *) *from; |
1953 | char *outbufptr = *to; |
1954 | int from_size = *from_left; |
1955 | |
1956 | const char *default_string = XLC_PUBLIC(lcd, default_string)(((XLCdPublic) lcd->core)->pub.default_string); |
1957 | int defstr_len = strlen(default_string); |
1958 | |
1959 | |
1960 | if (*from_left > *to_left) |
1961 | *from_left = *to_left; |
1962 | |
1963 | while (*from_left && *to_left) { |
1964 | |
1965 | wc = *inbufptr++; |
1966 | (*from_left)--; |
1967 | |
1968 | /* null ? */ |
1969 | if (!wc) { |
1970 | if (outbufptr) {*outbufptr++ = '\0';} |
1971 | (*to_left)--; |
1972 | |
1973 | continue; |
1974 | } |
1975 | |
1976 | /* convert */ |
1977 | if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) { |
1978 | |
1979 | /* output default_string of XDefaultString() */ |
1980 | if (*to_left < defstr_len) |
1981 | break; |
1982 | if (outbufptr) { |
1983 | strncpy((char *)outbufptr, default_string, defstr_len); |
1984 | outbufptr += defstr_len; |
1985 | } |
1986 | (*to_left) -= defstr_len; |
1987 | |
1988 | unconv_num++; |
1989 | |
1990 | } else { |
1991 | mb = gi_to_mb(glyph_index, codeset); |
1992 | |
1993 | if (check_string_encoding(codeset)(codeset->string_encoding)) { |
1994 | if (codeset->parse_info) { |
1995 | Boolint need_shift = False0; |
1996 | switch (codeset->parse_info->type) { |
1997 | case E_LSL : |
1998 | if (codeset != state->GL_codeset) { |
1999 | need_shift = True1; |
2000 | state->GL_codeset = codeset; |
2001 | } |
2002 | break; |
2003 | case E_LSR : |
2004 | if (codeset != state->GR_codeset) { |
2005 | need_shift = True1; |
2006 | state->GR_codeset = codeset; |
2007 | } |
2008 | break; |
2009 | /* case E_SS */ |
2010 | default: |
2011 | need_shift = True1; |
2012 | } |
2013 | |
2014 | /* output shift sequence */ |
2015 | if (need_shift) { |
2016 | encoding = codeset->parse_info->encoding; |
2017 | length = strlen(encoding); |
2018 | if (*to_left < length) |
2019 | break; |
2020 | |
2021 | if (outbufptr) { |
2022 | strncpy((char *)outbufptr, encoding, length); |
2023 | outbufptr += length; |
2024 | } |
2025 | (*to_left) -= length; |
2026 | } |
2027 | } |
2028 | |
2029 | /* output characters */ |
2030 | length = codeset->length; |
2031 | if (*to_left < length) |
2032 | break; |
2033 | |
2034 | if (outbufptr) { |
2035 | output_ulong_value(outbufptr, mb, length, XlcNONE); |
2036 | outbufptr += length; |
2037 | } |
2038 | |
2039 | (*to_left) -= length; |
2040 | } else { |
2041 | unconv_num++; |
2042 | } |
2043 | } |
2044 | |
2045 | } /* end of while */ |
2046 | |
2047 | *from = (XPointer) ((const wchar_t *) *from + from_size); |
2048 | *from_left = 0; |
2049 | *to = (XPointer) outbufptr; |
2050 | |
2051 | return unconv_num; |
2052 | } |
2053 | |
2054 | static int |
2055 | stdc_wcstostr( |
2056 | XlcConv conv, |
2057 | XPointer *from, |
2058 | int *from_left, |
2059 | XPointer *to, |
2060 | int *to_left, |
2061 | XPointer *args, |
2062 | int num_args) |
2063 | { |
2064 | XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX)malloc((((*from_left) * (__ctype_get_mb_cur_max ())) == 0 ? 1 : ((*from_left) * (__ctype_get_mb_cur_max ())))); |
2065 | char *buf_ptr1 = buf; |
2066 | int buf_left1 = (*from_left) * MB_CUR_MAX(__ctype_get_mb_cur_max ()); |
2067 | char *buf_ptr2 = buf_ptr1; |
2068 | int buf_left2; |
2069 | int unconv_num1 = 0, unconv_num2 = 0; |
2070 | |
2071 | unconv_num1 = stdc_wcstombs(conv, |
2072 | from, from_left, &buf_ptr1, &buf_left1, args, num_args); |
2073 | if (unconv_num1 < 0) |
2074 | goto ret; |
2075 | |
2076 | buf_left2 = buf_ptr1 - buf_ptr2; |
2077 | |
2078 | unconv_num2 = mbstostr(conv, |
2079 | &buf_ptr2, &buf_left2, to, to_left, args, num_args); |
2080 | if (unconv_num2 < 0) |
2081 | goto ret; |
2082 | |
2083 | ret: |
2084 | if (buf) |
2085 | Xfree((char *)buf)free(((char *)buf)); |
2086 | |
2087 | return (unconv_num1 + unconv_num2); |
2088 | } |
2089 | |
2090 | static int |
2091 | wctocs( |
2092 | XlcConv conv, |
2093 | XPointer *from, |
2094 | int *from_left, |
2095 | XPointer *to, |
2096 | int *to_left, |
2097 | XPointer *args, |
2098 | int num_args) |
2099 | { |
2100 | State state = (State) conv->state; |
2101 | XLCd lcd = state->lcd; |
2102 | |
2103 | wchar_t wc; |
2104 | unsigned long glyph_index; |
2105 | |
2106 | int char_len; |
2107 | int unconv_num = 0; |
2108 | XlcSide side; |
2109 | |
2110 | CodeSet codeset; |
2111 | XlcCharSet charset = NULL((void*)0); |
2112 | |
2113 | const wchar_t *inbufptr = (const wchar_t *) *from; |
2114 | char *outbufptr = *to; |
2115 | int from_size = *from_left; |
2116 | |
2117 | if (*from_left > *to_left) |
2118 | *from_left = *to_left; |
2119 | |
2120 | if (*from_left && *to_left) { |
2121 | |
2122 | wc = *inbufptr++; |
2123 | (*from_left)--; |
2124 | |
2125 | /* null ? */ |
2126 | if (!wc) { |
2127 | unconv_num = 1; |
2128 | goto end; |
2129 | } |
2130 | |
2131 | /* convert */ |
2132 | if ( !wc_to_gi(lcd, wc, &glyph_index, &codeset) ) { |
2133 | unconv_num = 1; |
2134 | goto end; |
2135 | } |
2136 | |
2137 | if ( !(charset = gi_parse_charset(glyph_index, codeset)) ) { |
2138 | unconv_num = 1; |
2139 | goto end; |
2140 | } |
2141 | char_len = charset->char_size; |
2142 | side = charset->side; |
2143 | |
2144 | /* output glyph index */ |
2145 | if (codeset->ctconv) |
2146 | glyph_index = conv_to_dest(codeset->ctconv, glyph_index); |
2147 | if (*to_left < char_len) { |
2148 | unconv_num++; |
2149 | goto end; |
2150 | } |
2151 | |
2152 | if (outbufptr) { |
2153 | output_ulong_value(outbufptr, glyph_index, char_len, side); |
2154 | outbufptr += char_len; |
2155 | } |
2156 | |
2157 | (*to_left) -= char_len; |
2158 | |
2159 | } |
2160 | |
2161 | end: |
2162 | |
2163 | /* error end */ |
2164 | if (unconv_num) { |
2165 | *from = (XPointer) ((const wchar_t *) *from + from_size); |
2166 | *from_left = 0; |
2167 | *to = (XPointer) outbufptr; |
2168 | return -1; |
2169 | } |
2170 | |
2171 | /* normal end */ |
2172 | *from = (XPointer) inbufptr; |
2173 | *to = (XPointer) outbufptr; |
2174 | |
2175 | if (num_args > 0) |
2176 | *((XlcCharSet *) args[0]) = charset; |
2177 | |
2178 | return 0; |
2179 | } |
2180 | |
2181 | static int |
2182 | stdc_wctocs( |
2183 | XlcConv conv, |
2184 | XPointer *from, |
2185 | int *from_left, |
2186 | XPointer *to, |
2187 | int *to_left, |
2188 | XPointer *args, |
2189 | int num_args) |
2190 | { |
2191 | const wchar_t *src = *((const wchar_t **) from); |
2192 | wchar_t wch; |
2193 | XPointer tmp_from, save_from = *from; |
2194 | char tmp[32]; |
2195 | int length, ret, src_left = *from_left; |
2196 | int from_size = *from_left; |
2197 | |
2198 | if (src_left > 0 && *to_left > 0) { |
2199 | if ((wch = *src)) { |
2200 | length = wctomb(tmp, wch); |
2201 | } else { |
2202 | goto end; |
2203 | } |
2204 | |
2205 | if (length < 0) |
2206 | goto end; |
2207 | |
2208 | tmp_from = (XPointer) tmp; |
2209 | ret = mbtocs(conv, &tmp_from, &length, to, to_left, args, num_args); |
2210 | if (ret < 0) |
2211 | goto end; |
2212 | |
2213 | src++; |
2214 | src_left--; |
2215 | } |
2216 | |
2217 | end: |
2218 | /* error end */ |
2219 | if (save_from == (XPointer) src) { |
2220 | *from = (XPointer) ((const wchar_t *) *from + from_size); |
2221 | *from_left = 0; |
2222 | return -1; |
2223 | } |
2224 | |
2225 | /* normal end */ |
2226 | *from = (XPointer) src; |
2227 | *from_left = src_left; |
2228 | |
2229 | return 0; |
2230 | } |
2231 | |
2232 | static int |
2233 | wcstocs( |
2234 | XlcConv conv, |
2235 | XPointer *from, |
2236 | int *from_left, |
2237 | XPointer *to, |
2238 | int *to_left, |
2239 | XPointer *args, |
2240 | int num_args) |
2241 | { |
2242 | int ret; |
2243 | XlcCharSet charset_old, charset = NULL((void*)0); |
2244 | XPointer tmp_args[1]; |
2245 | |
2246 | const wchar_t *inbufptr; |
2247 | int in_left; |
2248 | XPointer outbufptr; |
2249 | int out_left; |
2250 | tmp_args[0] = (XPointer) &charset; |
2251 | |
2252 | ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1); |
2253 | charset_old = charset; |
2254 | |
2255 | while ( ret == 0 && *from_left && *to_left) { |
2256 | inbufptr = (const wchar_t *) *from; |
2257 | in_left = *from_left; |
2258 | outbufptr = *to; |
2259 | out_left = *to_left; |
2260 | ret = wctocs(conv, from, from_left, to, to_left, tmp_args, 1); |
2261 | if (charset_old != charset) { |
2262 | *from = (XPointer) inbufptr; |
2263 | *from_left = in_left; |
2264 | *to = (XPointer) outbufptr; |
2265 | *to_left = out_left; |
2266 | break; |
2267 | } |
2268 | } |
2269 | |
2270 | if (num_args > 0) |
2271 | *((XlcCharSet *) args[0]) = charset_old; |
2272 | |
2273 | /* error end */ |
2274 | if (ret != 0) |
2275 | return( -1 ); |
2276 | |
2277 | return(0); |
2278 | } |
2279 | |
2280 | #ifdef STDCVT |
2281 | |
2282 | static int |
2283 | stdc_wcstocs( |
2284 | XlcConv conv, |
2285 | XPointer *from, |
2286 | int *from_left, |
2287 | XPointer *to, |
2288 | int *to_left, |
2289 | XPointer *args, |
2290 | int num_args) |
2291 | { |
2292 | int ret; |
2293 | XlcCharSet charset_old, charset = NULL((void*)0); |
2294 | XPointer tmp_args[1]; |
2295 | |
2296 | const wchar_t *inbufptr; |
2297 | int in_left; |
2298 | XPointer outbufptr; |
2299 | int out_left; |
2300 | tmp_args[0] = (XPointer) &charset; |
2301 | |
2302 | ret = stdc_wctocs(conv, from, from_left, to, to_left, tmp_args, 1); |
2303 | charset_old = charset; |
2304 | |
2305 | while ( ret == 0 && *from_left && *to_left ) { |
2306 | inbufptr = (const wchar_t *) *from; |
2307 | in_left = *from_left; |
2308 | outbufptr = *to; |
2309 | out_left = *to_left; |
2310 | ret = stdc_wctocs(conv, from, from_left, to, to_left, tmp_args, 1); |
2311 | if (charset_old != charset) { |
2312 | *from = (XPointer) inbufptr; |
2313 | *from_left = in_left; |
2314 | *to = (XPointer) outbufptr; |
2315 | *to_left = out_left; |
2316 | break; |
2317 | } |
2318 | } |
2319 | |
2320 | if (num_args > 0) |
2321 | *((XlcCharSet *) args[0]) = charset_old; |
2322 | |
2323 | /* error end */ |
2324 | if (ret != 0) |
2325 | return( -1 ); |
2326 | |
2327 | return(0); |
2328 | } |
2329 | |
2330 | #endif |
2331 | |
2332 | static int |
2333 | ctstombs( |
2334 | XlcConv conv, |
2335 | XPointer *from, |
2336 | int *from_left, |
2337 | XPointer *to, |
2338 | int *to_left, |
2339 | XPointer *args, |
2340 | int num_args) |
2341 | { |
2342 | XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t))malloc((((*from_left) * sizeof(wchar_t)) == 0 ? 1 : ((*from_left ) * sizeof(wchar_t)))); |
2343 | char *buf_ptr1 = buf; |
2344 | int buf_left1 = (*from_left); |
2345 | char *buf_ptr2 = buf_ptr1; |
2346 | int buf_left2; |
2347 | int unconv_num1 = 0, unconv_num2 = 0; |
2348 | |
2349 | unconv_num1 = ctstowcs(conv, |
2350 | from, from_left, &buf_ptr1, &buf_left1, args, num_args); |
2351 | if (unconv_num1 < 0) |
2352 | goto ret; |
2353 | |
2354 | buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t); |
2355 | |
2356 | unconv_num2 += wcstombs_org(conv, |
2357 | &buf_ptr2, &buf_left2, to, to_left, args, num_args); |
2358 | if (unconv_num2 < 0) |
2359 | goto ret; |
2360 | |
2361 | ret: |
2362 | if (buf) |
2363 | Xfree((char *)buf)free(((char *)buf)); |
2364 | |
2365 | return (unconv_num1 + unconv_num2); |
2366 | } |
2367 | |
2368 | static int |
2369 | cstombs( |
2370 | XlcConv conv, |
2371 | XPointer *from, |
2372 | int *from_left, |
2373 | XPointer *to, |
2374 | int *to_left, |
2375 | XPointer *args, |
2376 | int num_args) |
2377 | { |
2378 | XPointer buf = Xmalloc((*from_left) * sizeof(wchar_t))malloc((((*from_left) * sizeof(wchar_t)) == 0 ? 1 : ((*from_left ) * sizeof(wchar_t)))); |
2379 | char *buf_ptr1 = buf; |
2380 | int buf_left1 = (*from_left); |
2381 | char *buf_ptr2 = buf_ptr1; |
2382 | int buf_left2; |
2383 | int unconv_num1 = 0, unconv_num2 = 0; |
2384 | |
2385 | unconv_num1 = cstowcs(conv, |
2386 | from, from_left, &buf_ptr1, &buf_left1, args, num_args); |
2387 | if (unconv_num1 < 0) |
2388 | goto ret; |
2389 | |
2390 | buf_left2 = (buf_ptr1 - buf_ptr2) / sizeof(wchar_t); |
2391 | |
2392 | unconv_num2 += wcstombs_org(conv, |
2393 | &buf_ptr2, &buf_left2, to, to_left, args, num_args); |
2394 | if (unconv_num2 < 0) |
2395 | goto ret; |
2396 | |
2397 | ret: |
2398 | if (buf) |
2399 | Xfree((char *)buf)free(((char *)buf)); |
2400 | |
2401 | return (unconv_num1 + unconv_num2); |
2402 | } |
2403 | |
2404 | static int |
2405 | strtombs( |
2406 | XlcConv conv, |
2407 | XPointer *from, |
2408 | int *from_left, |
2409 | XPointer *to, |
2410 | int *to_left, |
2411 | XPointer *args, |
2412 | int num_args) |
2413 | { |
2414 | State state = (State) conv->state; |
2415 | XLCd lcd = state->lcd; |
2416 | |
2417 | char *encoding; |
2418 | unsigned long mb, glyph_index; |
2419 | unsigned char ch; |
2420 | |
2421 | int length; |
2422 | int unconv_num = 0; |
2423 | |
2424 | CodeSet codeset; |
2425 | |
2426 | const char *inbufptr = *from; |
2427 | char *outbufptr = *to; |
2428 | int from_size = *from_left; |
2429 | |
2430 | if (*from_left > *to_left) |
2431 | *from_left = *to_left; |
2432 | |
2433 | while (*from_left && *to_left) { |
2434 | |
2435 | ch = *inbufptr++; |
2436 | (*from_left)--; |
2437 | |
2438 | /* null ? */ |
2439 | if (!ch) { |
2440 | if (outbufptr) {*outbufptr++ = '\0';} |
2441 | (*to_left)--; |
2442 | |
2443 | continue; |
2444 | } |
2445 | |
2446 | /* convert */ |
2447 | if (isleftside(ch)(!((ch) & 0x80))) { |
2448 | glyph_index = ch; |
2449 | codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GL"); |
2450 | } else { |
2451 | glyph_index = ch & GL0x7f; |
2452 | codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GR"); |
2453 | } |
2454 | |
2455 | if (!codeset) { |
2456 | unconv_num++; |
2457 | continue; |
2458 | } |
2459 | |
2460 | mb = gi_to_mb(glyph_index, codeset); |
2461 | if (codeset->parse_info) { |
2462 | Boolint need_shift = False0; |
2463 | switch (codeset->parse_info->type) { |
2464 | case E_LSL : |
2465 | if (codeset != state->GL_codeset) { |
2466 | need_shift = True1; |
2467 | state->GL_codeset = codeset; |
2468 | } |
2469 | break; |
2470 | case E_LSR : |
2471 | if (codeset != state->GR_codeset) { |
2472 | need_shift = True1; |
2473 | state->GR_codeset = codeset; |
2474 | } |
2475 | break; |
2476 | /* case E_SS */ |
2477 | default: |
2478 | need_shift = True1; |
2479 | } |
2480 | |
2481 | /* output shift sequence */ |
2482 | if (need_shift) { |
2483 | encoding = codeset->parse_info->encoding; |
2484 | length = strlen(encoding); |
2485 | if (*to_left < length) |
2486 | break; |
2487 | if (outbufptr) { |
2488 | strncpy((char *)outbufptr, encoding, length); |
2489 | outbufptr += length; |
2490 | } |
2491 | (*to_left) -= length; |
2492 | } |
2493 | } |
2494 | |
2495 | /* output characters */ |
2496 | length = codeset->length; |
2497 | if (*to_left < length) |
2498 | break; |
2499 | |
2500 | if (outbufptr) { |
2501 | output_ulong_value(outbufptr, mb, length, XlcNONE); |
2502 | outbufptr += length; |
2503 | } |
2504 | |
2505 | (*to_left) -= length; |
2506 | |
2507 | } /* end of while */ |
2508 | |
2509 | *from = (XPointer) ((const char *) *from + from_size); |
2510 | *from_left = 0; |
2511 | *to = (XPointer) outbufptr; |
2512 | |
2513 | return unconv_num; |
2514 | } |
2515 | |
2516 | static int |
2517 | strtowcs( |
2518 | XlcConv conv, |
2519 | XPointer *from, |
2520 | int *from_left, |
2521 | XPointer *to, |
2522 | int *to_left, |
2523 | XPointer *args, |
2524 | int num_args) |
2525 | { |
2526 | State state = (State) conv->state; |
2527 | XLCd lcd = state->lcd; |
2528 | |
2529 | unsigned char ch; |
2530 | unsigned long glyph_index; |
2531 | wchar_t wc; |
2532 | |
2533 | int unconv_num = 0; |
2534 | CodeSet codeset; |
2535 | |
2536 | const char *inbufptr = *from; |
2537 | wchar_t *outbufptr = (wchar_t *)*to; |
2538 | int from_size = *from_left; |
2539 | |
2540 | if (*from_left > *to_left) |
2541 | *from_left = *to_left; |
2542 | |
2543 | while (*from_left && *to_left) { |
2544 | |
2545 | ch = *inbufptr++; |
2546 | (*from_left)--; |
2547 | |
2548 | /* null ? */ |
2549 | if (!ch) { |
2550 | if (outbufptr) {*outbufptr++ = L'\0';} |
2551 | (*to_left)--; |
2552 | |
2553 | continue; |
2554 | } |
2555 | |
2556 | /* convert */ |
2557 | if (isleftside(ch)(!((ch) & 0x80))) { |
2558 | glyph_index = ch; |
2559 | codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GL"); |
2560 | } else { |
2561 | glyph_index = ch & GL0x7f; |
2562 | codeset = _XlcGetCodeSetFromName(lcd, "ISO8859-1:GR"); |
2563 | } |
2564 | |
2565 | if (!codeset) { |
2566 | unconv_num++; |
2567 | continue; |
2568 | } |
2569 | |
2570 | gi_to_wc(lcd, glyph_index, codeset, &wc); |
2571 | if (outbufptr) {*outbufptr++ = wc;} |
2572 | (*to_left)--; |
2573 | |
2574 | } /* end of while */ |
2575 | |
2576 | *from = (XPointer) ((const char *) *from + from_size); |
2577 | *from_left = 0; |
2578 | *to = (XPointer) outbufptr; |
2579 | |
2580 | return unconv_num; |
2581 | } |
2582 | |
2583 | static int |
2584 | stdc_strtowcs( |
2585 | XlcConv conv, |
2586 | XPointer *from, |
2587 | int *from_left, |
2588 | XPointer *to, |
2589 | int *to_left, |
2590 | XPointer *args, |
2591 | int num_args) |
2592 | { |
2593 | XPointer buf = Xmalloc((*from_left) * MB_CUR_MAX)malloc((((*from_left) * (__ctype_get_mb_cur_max ())) == 0 ? 1 : ((*from_left) * (__ctype_get_mb_cur_max ())))); |
2594 | char *buf_ptr1 = buf; |
2595 | int buf_left1 = (*from_left) * MB_CUR_MAX(__ctype_get_mb_cur_max ()); |
2596 | char *buf_ptr2 = buf_ptr1; |
2597 | int buf_left2; |
2598 | int unconv_num1 = 0, unconv_num2 = 0; |
2599 | |
2600 | unconv_num1 = strtombs(conv, |
2601 | from, from_left, &buf_ptr1, &buf_left1, args, num_args); |
2602 | if (unconv_num1 < 0) |
2603 | goto ret; |
2604 | |
2605 | buf_left2 = buf_ptr1 - buf_ptr2; |
2606 | |
2607 | unconv_num2 = stdc_mbstowcs(conv, |
2608 | &buf_ptr2, &buf_left2, to, to_left, args, num_args); |
2609 | if (unconv_num2 < 0) |
2610 | goto ret; |
2611 | |
2612 | ret: |
2613 | if (buf) |
2614 | Xfree((char *)buf)free(((char *)buf)); |
2615 | |
2616 | return (unconv_num1 + unconv_num2); |
2617 | } |
2618 | |
2619 | /* -------------------------------------------------------------------------- */ |
2620 | /* Close */ |
2621 | /* -------------------------------------------------------------------------- */ |
2622 | |
2623 | static void |
2624 | close_converter( |
2625 | XlcConv conv) |
2626 | { |
2627 | if (conv->state) { |
2628 | Xfree((char *) conv->state)free(((char *) conv->state)); |
2629 | } |
2630 | |
2631 | if (conv->methods) { |
2632 | Xfree((char *) conv->methods)free(((char *) conv->methods)); |
2633 | } |
2634 | |
2635 | Xfree((char *) conv)free(((char *) conv)); |
2636 | } |
2637 | |
2638 | /* -------------------------------------------------------------------------- */ |
2639 | /* Open */ |
2640 | /* -------------------------------------------------------------------------- */ |
2641 | |
2642 | static XlcConv |
2643 | create_conv( |
2644 | XLCd lcd, |
2645 | XlcConvMethods methods) |
2646 | { |
2647 | XlcConv conv; |
2648 | State state; |
2649 | |
2650 | conv = (XlcConv) Xcalloc(1, sizeof(XlcConvRec))calloc(((1) == 0 ? 1 : (1)), (sizeof(XlcConvRec))); |
2651 | if (conv == NULL((void*)0)) |
2652 | return (XlcConv) NULL((void*)0); |
2653 | |
2654 | conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec))malloc(((sizeof(XlcConvMethodsRec)) == 0 ? 1 : (sizeof(XlcConvMethodsRec )))); |
2655 | if (conv->methods == NULL((void*)0)) |
2656 | goto err; |
2657 | *conv->methods = *methods; |
2658 | conv->methods->reset = init_state; |
2659 | |
2660 | conv->state = Xcalloc(1, sizeof(StateRec))calloc(((1) == 0 ? 1 : (1)), (sizeof(StateRec))); |
2661 | if (conv->state == NULL((void*)0)) |
2662 | goto err; |
2663 | |
2664 | state = (State) conv->state; |
2665 | state->lcd = lcd; |
2666 | |
2667 | _XlcResetConverter(conv); |
2668 | |
2669 | return conv; |
2670 | |
2671 | err: |
2672 | close_converter(conv); |
2673 | |
2674 | return (XlcConv) NULL((void*)0); |
2675 | } |
2676 | |
2677 | static XlcConvMethodsRec mbstocts_methods = { |
2678 | close_converter, |
2679 | mbstocts, |
2680 | NULL((void*)0) |
2681 | }; |
2682 | |
2683 | static XlcConv |
2684 | open_mbstocts( |
2685 | XLCd from_lcd, |
2686 | const char *from_type, |
2687 | XLCd to_lcd, |
2688 | const char *to_type) |
2689 | { |
2690 | return create_conv(from_lcd, &mbstocts_methods); |
2691 | } |
2692 | |
2693 | static XlcConvMethodsRec mbstostr_methods = { |
2694 | close_converter, |
2695 | mbstostr, |
2696 | NULL((void*)0) |
2697 | }; |
2698 | |
2699 | static XlcConv |
2700 | open_mbstostr( |
2701 | XLCd from_lcd, |
2702 | const char *from_type, |
2703 | XLCd to_lcd, |
2704 | const char *to_type) |
2705 | { |
2706 | return create_conv(from_lcd, &mbstostr_methods); |
2707 | } |
2708 | |
2709 | static XlcConvMethodsRec mbstocs_methods = { |
2710 | close_converter, |
2711 | mbstocs, |
2712 | NULL((void*)0) |
2713 | }; |
2714 | |
2715 | static XlcConv |
2716 | open_mbstocs( |
2717 | XLCd from_lcd, |
2718 | const char *from_type, |
2719 | XLCd to_lcd, |
2720 | const char *to_type) |
2721 | { |
2722 | return create_conv(from_lcd, &mbstocs_methods); |
2723 | } |
2724 | |
2725 | static XlcConvMethodsRec mbtocs_methods = { |
2726 | close_converter, |
2727 | mbtocs, |
2728 | NULL((void*)0) |
2729 | }; |
2730 | |
2731 | static XlcConv |
2732 | open_mbtocs( |
2733 | XLCd from_lcd, |
2734 | const char *from_type, |
2735 | XLCd to_lcd, |
2736 | const char *to_type) |
2737 | { |
2738 | return create_conv(from_lcd, &mbtocs_methods); |
2739 | } |
2740 | |
2741 | static XlcConvMethodsRec ctstombs_methods = { |
2742 | close_converter, |
2743 | ctstombs, |
2744 | NULL((void*)0) |
2745 | }; |
2746 | |
2747 | static XlcConv |
2748 | open_ctstombs( |
2749 | XLCd from_lcd, |
2750 | const char *from_type, |
2751 | XLCd to_lcd, |
2752 | const char *to_type) |
2753 | { |
2754 | return create_conv(from_lcd, &ctstombs_methods); |
2755 | } |
2756 | |
2757 | static XlcConvMethodsRec cstombs_methods = { |
2758 | close_converter, |
2759 | cstombs, |
2760 | NULL((void*)0) |
2761 | }; |
2762 | |
2763 | static XlcConv |
2764 | open_cstombs( |
2765 | XLCd from_lcd, |
2766 | const char *from_type, |
2767 | XLCd to_lcd, |
2768 | const char *to_type) |
2769 | { |
2770 | return create_conv(from_lcd, &cstombs_methods); |
2771 | } |
2772 | |
2773 | static XlcConvMethodsRec strtombs_methods = { |
2774 | close_converter, |
2775 | strtombs, |
2776 | NULL((void*)0) |
2777 | }; |
2778 | |
2779 | static XlcConv |
2780 | open_strtombs( |
2781 | XLCd from_lcd, |
2782 | const char *from_type, |
2783 | XLCd to_lcd, |
2784 | const char *to_type) |
2785 | { |
2786 | return create_conv(from_lcd, &strtombs_methods); |
2787 | } |
2788 | |
2789 | #ifdef STDCVT |
2790 | |
2791 | static XlcConvMethodsRec stdc_mbstowcs_methods = { |
2792 | close_converter, |
2793 | stdc_mbstowcs, |
2794 | NULL((void*)0) |
2795 | }; |
2796 | |
2797 | static XlcConv |
2798 | open_stdc_mbstowcs( |
2799 | XLCd from_lcd, |
2800 | const char *from_type, |
2801 | XLCd to_lcd, |
2802 | const char *to_type) |
2803 | { |
2804 | return create_conv(from_lcd, &stdc_mbstowcs_methods); |
2805 | } |
2806 | |
2807 | static XlcConvMethodsRec stdc_wcstombs_methods = { |
2808 | close_converter, |
2809 | stdc_wcstombs, |
2810 | NULL((void*)0) |
2811 | }; |
2812 | |
2813 | static XlcConv |
2814 | open_stdc_wcstombs( |
2815 | XLCd from_lcd, |
2816 | const char *from_type, |
2817 | XLCd to_lcd, |
2818 | const char *to_type) |
2819 | { |
2820 | return create_conv(from_lcd, &stdc_wcstombs_methods); |
2821 | } |
2822 | |
2823 | static XlcConvMethodsRec stdc_wcstocts_methods = { |
2824 | close_converter, |
2825 | stdc_wcstocts, |
2826 | NULL((void*)0) |
2827 | }; |
2828 | |
2829 | static XlcConv |
2830 | open_stdc_wcstocts( |
2831 | XLCd from_lcd, |
2832 | const char *from_type, |
2833 | XLCd to_lcd, |
2834 | const char *to_type) |
2835 | { |
2836 | return create_conv(from_lcd, &stdc_wcstocts_methods); |
2837 | } |
2838 | |
2839 | static XlcConvMethodsRec stdc_wcstostr_methods = { |
2840 | close_converter, |
2841 | stdc_wcstostr, |
2842 | NULL((void*)0) |
2843 | }; |
2844 | |
2845 | static XlcConv |
2846 | open_stdc_wcstostr( |
2847 | XLCd from_lcd, |
2848 | const char *from_type, |
2849 | XLCd to_lcd, |
2850 | const char *to_type) |
2851 | { |
2852 | return create_conv(from_lcd, &stdc_wcstostr_methods); |
2853 | } |
2854 | |
2855 | static XlcConvMethodsRec stdc_wcstocs_methods = { |
2856 | close_converter, |
2857 | stdc_wcstocs, |
2858 | NULL((void*)0) |
2859 | }; |
2860 | |
2861 | static XlcConv |
2862 | open_stdc_wcstocs( |
2863 | XLCd from_lcd, |
2864 | const char *from_type, |
2865 | XLCd to_lcd, |
2866 | const char *to_type) |
2867 | { |
2868 | return create_conv(from_lcd, &stdc_wcstocs_methods); |
2869 | } |
2870 | |
2871 | static XlcConvMethodsRec stdc_wctocs_methods = { |
2872 | close_converter, |
2873 | stdc_wctocs, |
2874 | NULL((void*)0) |
2875 | }; |
2876 | |
2877 | static XlcConv |
2878 | open_stdc_wctocs( |
2879 | XLCd from_lcd, |
2880 | const char *from_type, |
2881 | XLCd to_lcd, |
2882 | const char *to_type) |
2883 | { |
2884 | return create_conv(from_lcd, &stdc_wctocs_methods); |
2885 | } |
2886 | |
2887 | static XlcConvMethodsRec stdc_ctstowcs_methods = { |
2888 | close_converter, |
2889 | stdc_ctstowcs, |
2890 | NULL((void*)0) |
2891 | }; |
2892 | |
2893 | static XlcConv |
2894 | open_stdc_ctstowcs( |
2895 | XLCd from_lcd, |
2896 | const char *from_type, |
2897 | XLCd to_lcd, |
2898 | const char *to_type) |
2899 | { |
2900 | return create_conv(from_lcd, &stdc_ctstowcs_methods); |
2901 | } |
2902 | |
2903 | static XlcConvMethodsRec stdc_cstowcs_methods = { |
2904 | close_converter, |
2905 | stdc_cstowcs, |
2906 | NULL((void*)0) |
2907 | }; |
2908 | |
2909 | static XlcConv |
2910 | open_stdc_cstowcs( |
2911 | XLCd from_lcd, |
2912 | const char *from_type, |
2913 | XLCd to_lcd, |
2914 | const char *to_type) |
2915 | { |
2916 | return create_conv(from_lcd, &stdc_cstowcs_methods); |
2917 | } |
2918 | |
2919 | static XlcConvMethodsRec stdc_strtowcs_methods = { |
2920 | close_converter, |
2921 | stdc_strtowcs, |
2922 | NULL((void*)0) |
2923 | }; |
2924 | |
2925 | static XlcConv |
2926 | open_stdc_strtowcs( |
2927 | XLCd from_lcd, |
2928 | const char *from_type, |
2929 | XLCd to_lcd, |
2930 | const char *to_type) |
2931 | { |
2932 | return create_conv(from_lcd, &stdc_strtowcs_methods); |
2933 | } |
2934 | |
2935 | #endif /* STDCVT */ |
2936 | |
2937 | static XlcConvMethodsRec mbstowcs_methods = { |
2938 | close_converter, |
2939 | mbstowcs_org, |
2940 | NULL((void*)0) |
2941 | }; |
2942 | |
2943 | static XlcConv |
2944 | open_mbstowcs( |
2945 | XLCd from_lcd, |
2946 | const char *from_type, |
2947 | XLCd to_lcd, |
2948 | const char *to_type) |
2949 | { |
2950 | return create_conv(from_lcd, &mbstowcs_methods); |
2951 | } |
2952 | |
2953 | static XlcConvMethodsRec wcstombs_methods = { |
2954 | close_converter, |
2955 | wcstombs_org, |
2956 | NULL((void*)0) |
2957 | }; |
2958 | |
2959 | static XlcConv |
2960 | open_wcstombs( |
2961 | XLCd from_lcd, |
2962 | const char *from_type, |
2963 | XLCd to_lcd, |
2964 | const char *to_type) |
2965 | { |
2966 | return create_conv(from_lcd, &wcstombs_methods); |
2967 | } |
2968 | |
2969 | static XlcConvMethodsRec wcstocts_methods = { |
2970 | close_converter, |
2971 | wcstocts, |
2972 | NULL((void*)0) |
2973 | }; |
2974 | |
2975 | static XlcConv |
2976 | open_wcstocts( |
2977 | XLCd from_lcd, |
2978 | const char *from_type, |
2979 | XLCd to_lcd, |
2980 | const char *to_type) |
2981 | { |
2982 | return create_conv(from_lcd, &wcstocts_methods); |
2983 | } |
2984 | |
2985 | static XlcConvMethodsRec wcstostr_methods = { |
2986 | close_converter, |
2987 | wcstostr, |
2988 | NULL((void*)0) |
2989 | }; |
2990 | |
2991 | static XlcConv |
2992 | open_wcstostr( |
2993 | XLCd from_lcd, |
2994 | const char *from_type, |
2995 | XLCd to_lcd, |
2996 | const char *to_type) |
2997 | { |
2998 | return create_conv(from_lcd, &wcstostr_methods); |
2999 | } |
3000 | |
3001 | static XlcConvMethodsRec wcstocs_methods = { |
3002 | close_converter, |
3003 | wcstocs, |
3004 | NULL((void*)0) |
3005 | }; |
3006 | |
3007 | static XlcConv |
3008 | open_wcstocs( |
3009 | XLCd from_lcd, |
3010 | const char *from_type, |
3011 | XLCd to_lcd, |
3012 | const char *to_type) |
3013 | { |
3014 | return create_conv(from_lcd, &wcstocs_methods); |
3015 | } |
3016 | |
3017 | static XlcConvMethodsRec wctocs_methods = { |
3018 | close_converter, |
3019 | wctocs, |
3020 | NULL((void*)0) |
3021 | }; |
3022 | |
3023 | static XlcConv |
3024 | open_wctocs( |
3025 | XLCd from_lcd, |
3026 | const char *from_type, |
3027 | XLCd to_lcd, |
3028 | const char *to_type) |
3029 | { |
3030 | return create_conv(from_lcd, &wctocs_methods); |
3031 | } |
3032 | |
3033 | static XlcConvMethodsRec ctstowcs_methods = { |
3034 | close_converter, |
3035 | ctstowcs, |
3036 | NULL((void*)0) |
3037 | }; |
3038 | |
3039 | static XlcConv |
3040 | open_ctstowcs( |
3041 | XLCd from_lcd, |
3042 | const char *from_type, |
3043 | XLCd to_lcd, |
3044 | const char *to_type) |
3045 | { |
3046 | return create_conv(from_lcd, &ctstowcs_methods); |
3047 | } |
3048 | |
3049 | static XlcConvMethodsRec cstowcs_methods = { |
3050 | close_converter, |
3051 | cstowcs, |
3052 | NULL((void*)0) |
3053 | }; |
3054 | |
3055 | static XlcConv |
3056 | open_cstowcs( |
3057 | XLCd from_lcd, |
3058 | const char *from_type, |
3059 | XLCd to_lcd, |
3060 | const char *to_type) |
3061 | { |
3062 | return create_conv(from_lcd, &cstowcs_methods); |
3063 | } |
3064 | |
3065 | static XlcConvMethodsRec strtowcs_methods = { |
3066 | close_converter, |
3067 | strtowcs, |
3068 | NULL((void*)0) |
3069 | }; |
3070 | |
3071 | static XlcConv |
3072 | open_strtowcs( |
3073 | XLCd from_lcd, |
3074 | const char *from_type, |
3075 | XLCd to_lcd, |
3076 | const char *to_type) |
3077 | { |
3078 | return create_conv(from_lcd, &strtowcs_methods); |
3079 | } |
3080 | |
3081 | /* -------------------------------------------------------------------------- */ |
3082 | /* Loader */ |
3083 | /* -------------------------------------------------------------------------- */ |
3084 | |
3085 | XLCd |
3086 | _XlcGenericLoader( |
3087 | const char *name) |
3088 | { |
3089 | XLCd lcd; |
3090 | #ifdef STDCVT |
3091 | XLCdGenericPart *gen; |
3092 | #endif |
3093 | |
3094 | lcd = _XlcCreateLC(name, _XlcGenericMethods); |
3095 | |
3096 | if (lcd == NULL((void*)0)) |
3097 | return lcd; |
3098 | |
3099 | default_GL_charset = _XlcGetCharSet("ISO8859-1:GL"); |
3100 | default_GR_charset = _XlcGetCharSet("ISO8859-1:GR"); |
3101 | |
3102 | _XlcSetConverter(lcd, XlcNMultiByte"multiByte", lcd, XlcNCompoundText"compoundText", open_mbstocts); |
3103 | _XlcSetConverter(lcd, XlcNMultiByte"multiByte", lcd, XlcNString"string", open_mbstostr); |
3104 | _XlcSetConverter(lcd, XlcNMultiByte"multiByte", lcd, XlcNCharSet"charSet", open_mbstocs); |
3105 | _XlcSetConverter(lcd, XlcNMultiByte"multiByte", lcd, XlcNChar"char", open_mbtocs); |
3106 | _XlcSetConverter(lcd, XlcNCompoundText"compoundText", lcd, XlcNMultiByte"multiByte", open_ctstombs); |
3107 | _XlcSetConverter(lcd, XlcNString"string", lcd, XlcNMultiByte"multiByte", open_strtombs); |
3108 | _XlcSetConverter(lcd, XlcNCharSet"charSet", lcd, XlcNMultiByte"multiByte", open_cstombs); |
3109 | |
3110 | #ifdef STDCVT |
3111 | gen = XLC_GENERIC_PART(lcd)(&(((XLCdGeneric) lcd->core)->gen)); |
3112 | |
3113 | if (gen->use_stdc_env != True1) { |
3114 | #endif |
3115 | _XlcSetConverter(lcd, XlcNMultiByte"multiByte", lcd, XlcNWideChar"wideChar", open_mbstowcs); |
3116 | _XlcSetConverter(lcd, XlcNWideChar"wideChar", lcd, XlcNMultiByte"multiByte", open_wcstombs); |
3117 | _XlcSetConverter(lcd, XlcNWideChar"wideChar", lcd, XlcNCompoundText"compoundText", open_wcstocts); |
3118 | _XlcSetConverter(lcd, XlcNWideChar"wideChar", lcd, XlcNString"string", open_wcstostr); |
3119 | _XlcSetConverter(lcd, XlcNWideChar"wideChar", lcd, XlcNCharSet"charSet", open_wcstocs); |
3120 | _XlcSetConverter(lcd, XlcNWideChar"wideChar", lcd, XlcNChar"char", open_wctocs); |
3121 | _XlcSetConverter(lcd, XlcNCompoundText"compoundText", lcd, XlcNWideChar"wideChar", open_ctstowcs); |
3122 | _XlcSetConverter(lcd, XlcNString"string", lcd, XlcNWideChar"wideChar", open_strtowcs); |
3123 | _XlcSetConverter(lcd, XlcNCharSet"charSet", lcd, XlcNWideChar"wideChar", open_cstowcs); |
3124 | #ifdef STDCVT |
3125 | } |
3126 | #endif |
3127 | |
3128 | #ifdef STDCVT |
3129 | if (gen->use_stdc_env == True1) { |
3130 | _XlcSetConverter(lcd, XlcNMultiByte"multiByte", lcd, XlcNWideChar"wideChar", open_stdc_mbstowcs); |
3131 | _XlcSetConverter(lcd, XlcNWideChar"wideChar", lcd, XlcNMultiByte"multiByte", open_stdc_wcstombs); |
3132 | _XlcSetConverter(lcd, XlcNWideChar"wideChar", lcd, XlcNCompoundText"compoundText", open_stdc_wcstocts); |
3133 | _XlcSetConverter(lcd, XlcNWideChar"wideChar", lcd, XlcNString"string", open_stdc_wcstostr); |
3134 | _XlcSetConverter(lcd, XlcNWideChar"wideChar", lcd, XlcNCharSet"charSet", open_stdc_wcstocs); |
3135 | _XlcSetConverter(lcd, XlcNWideChar"wideChar", lcd, XlcNChar"char", open_stdc_wctocs); |
3136 | _XlcSetConverter(lcd, XlcNCompoundText"compoundText", lcd, XlcNWideChar"wideChar", open_stdc_ctstowcs); |
3137 | _XlcSetConverter(lcd, XlcNString"string", lcd, XlcNWideChar"wideChar", open_stdc_strtowcs); |
3138 | _XlcSetConverter(lcd, XlcNCharSet"charSet", lcd, XlcNWideChar"wideChar", open_stdc_cstowcs); |
3139 | } |
3140 | #endif |
3141 | |
3142 | _XlcAddUtf8Converters(lcd); |
3143 | |
3144 | return lcd; |
3145 | } |