1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
|
/*
* Copyright 1992, 1993 by TOSHIBA Corp.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of TOSHIBA not be used in advertising
* or publicity pertaining to distribution of the software without specific,
* written prior permission. TOSHIBA make no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
* TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*
* Author: Katsuhisa Yano TOSHIBA Corp.
* mopi@osa.ilab.toshiba.co.jp
*/
/*
* A Japanese JIS locale.
* Supports: all locales with codeset JIS7.
* How: Provides converters for JIS.
* Platforms: Only those defining X_LOCALE (only Lynx, Linux-libc5, OS/2).
*/
#ifdef X_LOCALE
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "Xlibint.h"
#include "XlcGeneric.h"
#include <stdio.h>
#if !defined(macII) && !defined(X_LOCALE)
#define STDCVT
#endif
typedef struct _StateRec {
XLCd lcd;
XlcCharSet charset;
XlcCharSet GL_charset;
XlcCharSet GR_charset;
} StateRec, *State;
static void
init_state(
XlcConv conv)
{
State state = (State) conv->state;
XLCdGenericPart *gen = XLC_GENERIC_PART(state->lcd);
CodeSet codeset;
codeset = gen->initial_state_GL;
if (codeset && codeset->charset_list)
state->GL_charset = *codeset->charset_list;
codeset = gen->initial_state_GR;
if (codeset && codeset->charset_list)
state->GR_charset = *codeset->charset_list;
if (state->GL_charset == NULL)
if ((codeset = *gen->codeset_list) != NULL)
state->GL_charset = *codeset->charset_list;
}
static int
compare(
const char *src,
const char *encoding,
int length)
{
const char *start = src;
while (length-- > 0) {
if (*src++ != *encoding++)
return 0;
if (*encoding == '\0')
return src - start;
}
return 0;
}
static int
mbtocs(
XlcConv conv,
XPointer *from,
int *from_left,
XPointer *to,
int *to_left,
XPointer *args,
int num_args)
{
State state = (State) conv->state;
XLCd lcd = state->lcd;
const char *src;
char *dst;
unsigned char *mb_parse_table;
ParseInfo *parse_list, parse_info;
XlcCharSet charset;
int length, number, encoding_len = 0;
int i;
src = *((const char **) from);
dst = *((char **) to);
mb_parse_table = XLC_GENERIC(lcd, mb_parse_table);
if (mb_parse_table != NULL) {
number = mb_parse_table[(unsigned char) *src];
if (number > 0) {
parse_list = XLC_GENERIC(lcd, mb_parse_list) + number - 1;
for ( ; (parse_info = *parse_list) != NULL; parse_list++) {
encoding_len = compare(src, parse_info->encoding, *from_left);
if (encoding_len > 0) {
switch (parse_info->type) {
case E_SS:
src += encoding_len;
charset = *parse_info->codeset->charset_list;
goto found;
case E_LSL:
case E_LSR:
src += encoding_len;
charset = *parse_info->codeset->charset_list;
if (parse_info->type == E_LSL)
state->GL_charset = charset;
else
state->GR_charset = charset;
length = 0;
goto end;
case E_GL:
charset = state->GL_charset;
goto found;
case E_GR:
charset = state->GR_charset;
goto found;
default:
break;
}
}
}
}
}
if ((*src & 0x80) && state->GR_charset)
charset = state->GR_charset;
else
charset = state->GL_charset;
found:
if (charset == NULL ||
(num_args == 2 && (XlcCharSet) args[1] != charset))
return -1;
length = charset->char_size;
if (length > *from_left - encoding_len)
return -1;
if (dst) {
if (length > *to_left)
return -1;
if (charset->side == XlcGL) {
for (i = 0; i < length; i++)
*dst++ = *src++ & 0x7f;
} else if (charset->side == XlcGR) {
for (i = 0; i < length; i++)
*dst++ = *src++ | 0x80;
} else {
for (i = 0; i < length; i++)
*dst++ = *src++;
}
*to = (XPointer) dst;
*to_left -= length;
}
end:
*from = (XPointer) src;
*from_left -= encoding_len + length;
state->charset = charset;
if (num_args == 1)
*((XlcCharSet *) args[0]) = charset;
return 0;
}
static int
mbstocs(
XlcConv conv,
XPointer *from,
int *from_left,
XPointer *to,
int *to_left,
XPointer *args,
int num_args)
{
XlcCharSet charset = NULL;
XPointer tmp_args[2], save_from = *from;
int ret, unconv_num = 0, tmp_num = 1;
tmp_args[0] = (XPointer) &charset;
while (*from_left > 0 && *to_left > 0) {
ret = mbtocs(conv, from, from_left, to, to_left, tmp_args, tmp_num);
if (ret < 0)
break;
unconv_num += ret;
if (tmp_num == 1 && charset) {
tmp_args[1] = (XPointer) charset;
tmp_num = 2;
}
}
if (save_from == *from)
return -1;
if (num_args > 0)
*((XlcCharSet *) args[0]) = charset;
return unconv_num;
}
static CodeSet
wc_parse_codeset(
XLCd lcd,
const wchar_t *wcstr)
{
CodeSet *codeset;
unsigned long wc_encoding;
int num;
wc_encoding = *wcstr & XLC_GENERIC(lcd, wc_encode_mask);
num = XLC_GENERIC(lcd, codeset_num);
codeset = XLC_GENERIC(lcd, codeset_list);
while (num-- > 0) {
if (wc_encoding == (*codeset)->wc_encoding)
return *codeset;
codeset++;
}
return NULL;
}
static int
wcstocs(
XlcConv conv,
XPointer *from,
int *from_left,
XPointer *to,
int *to_left,
XPointer *args,
int num_args)
{
State state = (State) conv->state;
XLCd lcd = state->lcd;
const wchar_t *wcptr;
char *bufptr;
wchar_t wch;
char *tmpptr;
int length;
CodeSet codeset;
unsigned long wc_encoding;
int wcstr_len, buf_len;
if (from == NULL || *from == NULL)
return 0;
wcptr = *((const wchar_t **) from);
bufptr = *((char **) to);
wcstr_len = *from_left;
buf_len = *to_left;
codeset = wc_parse_codeset(lcd, wcptr);
if (codeset == NULL)
return -1;
wc_encoding = codeset->wc_encoding;
if (wcstr_len < buf_len / codeset->length)
buf_len = wcstr_len * codeset->length;
for ( ; wcstr_len > 0 && buf_len > 0; wcptr++, wcstr_len--) {
wch = *wcptr;
if ((wch & XLC_GENERIC(lcd, wc_encode_mask)) != wc_encoding)
break;
length = codeset->length;
buf_len -= length;
bufptr += length;
tmpptr = bufptr - 1;
if ((*codeset->charset_list)->side == XlcGL) {
while (length--) {
*tmpptr-- = (unsigned char) (wch & 0x7f);
wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
}
} else if ((*codeset->charset_list)->side == XlcGR) {
while (length--) {
*tmpptr-- = (unsigned char) (wch | 0x80);
wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
}
} else {
while (length--) {
*tmpptr-- = (unsigned char) wch;
wch >>= (wchar_t)XLC_GENERIC(lcd, wc_shift_bits);
}
}
}
if (num_args > 0)
*((XlcCharSet *) args[0]) = *codeset->charset_list;
*from_left -= wcptr - *((wchar_t **) from);
*from = (XPointer) wcptr;
*to_left -= bufptr - *((char **) to);
*to = bufptr;
return 0;
}
static CodeSet
GetCodeSetFromCharSet(
XLCd lcd,
XlcCharSet charset)
{
CodeSet *codeset = XLC_GENERIC(lcd, codeset_list);
XlcCharSet *charset_list;
int codeset_num, num_charsets;
codeset_num = XLC_GENERIC(lcd, codeset_num);
for ( ; codeset_num-- > 0; codeset++) {
num_charsets = (*codeset)->num_charsets;
charset_list = (*codeset)->charset_list;
for ( ; num_charsets-- > 0; charset_list++)
if (*charset_list == charset)
return *codeset;
}
return (CodeSet) NULL;
}
static int
cstombs(
XlcConv conv,
XPointer *from,
int *from_left,
XPointer *to,
int *to_left,
XPointer *args,
int num_args)
{
State state = (State) conv->state;
const char *csptr;
char *bufptr;
int csstr_len;
int buf_len;
int num, encoding_len = 0;
CodeSet codeset;
XlcCharSet charset;
EncodingType type;
int cvt_length;
csptr = *((const char **) from);
bufptr = *((char **) to);
csstr_len = *from_left;
buf_len = *to_left;
if (num_args < 1)
return -1;
charset = (XlcCharSet) args[0];
codeset = GetCodeSetFromCharSet(state->lcd, charset);
if (codeset == NULL)
return -1;
cvt_length = 0;
if (codeset->parse_info) {
switch (type = codeset->parse_info->type) {
case E_SS:
encoding_len = strlen(codeset->parse_info->encoding);
break;
case E_LSL:
case E_LSR:
if (type == E_LSL) {
if (charset == state->GL_charset)
break;
} else {
if (charset == state->GR_charset)
break;
}
encoding_len = strlen(codeset->parse_info->encoding);
if (encoding_len > buf_len)
return -1;
cvt_length += encoding_len;
if (bufptr) {
strcpy(bufptr, codeset->parse_info->encoding);
bufptr += encoding_len;
}
buf_len -= encoding_len;
encoding_len = 0;
if (type == E_LSL)
state->GL_charset = charset;
else
state->GR_charset = charset;
break;
default:
break;
}
}
csstr_len /= codeset->length;
buf_len /= codeset->length + encoding_len;
if (csstr_len < buf_len)
buf_len = csstr_len;
cvt_length += buf_len * (encoding_len + codeset->length);
if (bufptr) {
while (buf_len--) {
if (encoding_len) {
strcpy(bufptr, codeset->parse_info->encoding);
bufptr += encoding_len;
}
num = codeset->length;
if (codeset->side == XlcGL) {
while (num--)
*bufptr++ = *csptr++ & 0x7f;
} else if (codeset->side == XlcGR) {
while (num--)
*bufptr++ = *csptr++ | 0x80;
} else {
while (num--)
*bufptr++ = *csptr++;
}
}
}
*from_left -= csptr - *((char **) from);
*from = (XPointer) csptr;
if (bufptr)
*to = (XPointer) bufptr;
*to_left -= cvt_length;
return 0;
}
static int
cstowcs(
XlcConv conv,
XPointer *from,
int *from_left,
XPointer *to,
int *to_left,
XPointer *args,
int num_args)
{
State state = (State) conv->state;
XLCd lcd = state->lcd;
const char *csptr;
wchar_t *bufptr;
int csstr_len;
int buf_len;
wchar_t wch;
unsigned long code_mask, wc_encoding;
int num, length, wc_shift_bits;
CodeSet codeset;
csptr = *((const char **) from);
bufptr = *((wchar_t **) to);
csstr_len = *from_left;
buf_len = *to_left;
if (num_args < 1)
return -1;
codeset = GetCodeSetFromCharSet(lcd, (XlcCharSet) args[0]);
if (codeset == NULL)
return -1;
length = codeset->length;
csstr_len /= length;
if (csstr_len < buf_len)
buf_len = csstr_len;
code_mask = ~XLC_GENERIC(lcd, wc_encode_mask);
wc_encoding = codeset->wc_encoding;
wc_shift_bits = XLC_GENERIC(lcd, wc_shift_bits);
*to_left -= buf_len;
if (bufptr) {
while (buf_len--) {
wch = (wchar_t) (*csptr++ & 0x7f);
num = length - 1;
while (num--)
wch = (wch << wc_shift_bits) | (*csptr++ & 0x7f);
*bufptr++ = (wch & code_mask) | wc_encoding;
}
}
*from_left -= csptr - *((char **) from);
*from = (XPointer) csptr;
if (bufptr)
*to = (XPointer) bufptr;
return 0;
}
static void
close_converter(
XlcConv conv)
{
if (conv->state) {
Xfree((char *) conv->state);
}
Xfree((char *) conv);
}
static XlcConv
create_conv(
XLCd lcd,
XlcConvMethods methods)
{
XlcConv conv;
State state;
conv = (XlcConv) Xmalloc(sizeof(XlcConvRec));
if (conv == NULL)
return (XlcConv) NULL;
conv->methods = (XlcConvMethods) Xmalloc(sizeof(XlcConvMethodsRec));
if (conv->methods == NULL)
goto err;
*conv->methods = *methods;
if (XLC_PUBLIC(lcd, is_state_depend))
conv->methods->reset = init_state;
conv->state = (XPointer) Xmalloc(sizeof(StateRec));
if (conv->state == NULL)
goto err;
bzero((char *) conv->state, sizeof(StateRec));
state = (State) conv->state;
state->lcd = lcd;
init_state(conv);
return conv;
err:
close_converter(conv);
return (XlcConv) NULL;
}
static XlcConvMethodsRec mbstocs_methods = {
close_converter,
mbstocs,
NULL
};
static XlcConv
open_mbstocs(
XLCd from_lcd,
const char *from_type,
XLCd to_lcd,
const char *to_type)
{
return create_conv(from_lcd, &mbstocs_methods);
}
static XlcConvMethodsRec wcstocs_methods = {
close_converter,
wcstocs,
NULL
};
static XlcConv
open_wcstocs(
XLCd from_lcd,
const char *from_type,
XLCd to_lcd,
const char *to_type)
{
return create_conv(from_lcd, &wcstocs_methods);
}
static XlcConvMethodsRec mbtocs_methods = {
close_converter,
mbtocs,
NULL
};
static XlcConv
open_mbtocs(
XLCd from_lcd,
const char *from_type,
XLCd to_lcd,
const char *to_type)
{
return create_conv(from_lcd, &mbtocs_methods);
}
static XlcConvMethodsRec cstombs_methods = {
close_converter,
cstombs,
NULL
};
static XlcConv
open_cstombs(
XLCd from_lcd,
const char *from_type,
XLCd to_lcd,
const char *to_type)
{
return create_conv(from_lcd, &cstombs_methods);
}
static XlcConvMethodsRec cstowcs_methods = {
close_converter,
cstowcs,
NULL
};
static XlcConv
open_cstowcs(
XLCd from_lcd,
const char *from_type,
XLCd to_lcd,
const char *to_type)
{
return create_conv(from_lcd, &cstowcs_methods);
}
#ifdef STDCVT
static int
stdc_mbstowcs(
XlcConv conv,
XPointer *from,
int *from_left,
XPointer *to,
int *to_left,
XPointer *args,
int num_args)
{
const char *src = *((const char **) from);
wchar_t *dst = *((wchar_t **) to);
int src_left = *from_left;
int dst_left = *to_left;
int length;
while (src_left > 0 && dst_left > 0) {
length = mbtowc(dst, src, src_left);
if (length < 0)
break;
src += length;
src_left -= length;
if (dst)
dst++;
dst_left--;
if (length == 0) {
src++;
src_left--;
break;
}
}
if (*from_left == src_left)
return -1;
*from = (XPointer) src;
if (dst)
*to = (XPointer) dst;
*from_left = src_left;
*to_left = dst_left;
return 0;
}
static int
stdc_wcstombs(
XlcConv conv,
XPointer *from,
int *from_left,
XPointer *to,
int *to_left,
XPointer *args,
int num_args)
{
const wchar_t *src = *((const wchar_t **) from);
char *dst = *((char **) to);
int src_left = *from_left;
int dst_left = *to_left;
int length;
while (src_left > 0 && dst_left > 0) {
length = wctomb(dst, *src); /* XXX */
if (length < 0 || dst_left < length)
break;
src++;
src_left--;
dst += length;
dst_left -= length;
if (length == 0) {
dst++;
dst_left--;
break;
}
}
if (*from_left == src_left)
return -1;
*from = (XPointer) src;
*to = (XPointer) dst;
*from_left = src_left;
*to_left = dst_left;
return 0;
}
static int
stdc_wcstocs(
XlcConv conv,
XPointer *from,
int *from_left,
XPointer *to,
int *to_left,
XPointer *args,
int num_args)
{
const wchar_t *src = *((const wchar_t **) from);
wchar_t wch;
XlcCharSet charset = NULL;
XPointer tmp_args[2], tmp_from, save_from = *from;
char tmp[32];
int length, ret, src_left = *from_left;
int unconv_num = 0, tmp_num = 1;
tmp_args[0] = (XPointer) &charset;
while (src_left > 0 && *to_left > 0) {
if (wch = *src) {
length = wctomb(tmp, wch);
} else {
length = 1;
*tmp = '\0';
}
if (length < 0)
break;
tmp_from = (XPointer) tmp;
ret = mbtocs(conv, &tmp_from, &length, to, to_left, tmp_args, tmp_num);
if (ret < 0)
break;
unconv_num += ret;
if (tmp_num == 1 && charset) {
tmp_args[1] = (XPointer) charset;
tmp_num = 2;
}
src++;
src_left--;
}
if (save_from == (XPointer) src)
return -1;
*from = (XPointer) src;
*from_left = src_left;
if (num_args > 0)
*((XlcCharSet *) args[0]) = charset;
return unconv_num;
}
#define DefineLocalBuf char local_buf[BUFSIZ]
#define AllocLocalBuf(length) (length > BUFSIZ ? (char*) Xmalloc(length) : local_buf)
#define FreeLocalBuf(ptr) if (ptr != local_buf) Xfree(ptr)
static int
stdc_cstowcs(
XlcConv conv,
XPointer *from,
int *from_left,
XPointer *to,
int *to_left,
XPointer *args,
int num_args)
{
XLCd lcd = ((State) conv->state)->lcd;
DefineLocalBuf;
XPointer buf, save_buf;
int length, left, ret;
left = length = *to_left * XLC_PUBLIC(lcd, mb_cur_max);
buf = save_buf = (XPointer) AllocLocalBuf(length);
if (buf == NULL)
return -1;
ret = cstombs(conv, from, from_left, &buf, &left, args, num_args);
if (ret < 0)
goto err;
buf = save_buf;
length -= left;
if (stdc_mbstowcs(conv, &buf, &length, to, to_left, args, num_args) < 0)
ret = -1;
err:
FreeLocalBuf(save_buf);
return ret;
}
static XlcConvMethodsRec stdc_mbstowcs_methods = {
close_converter,
stdc_mbstowcs,
NULL
};
static XlcConv
open_stdc_mbstowcs(
XLCd from_lcd,
const char *from_type,
XLCd to_lcd,
const char *to_type)
{
return create_conv(from_lcd, &stdc_mbstowcs_methods);
}
static XlcConvMethodsRec stdc_wcstombs_methods = {
close_converter,
stdc_wcstombs,
NULL
};
static XlcConv
open_stdc_wcstombs(
XLCd from_lcd,
const char *from_type,
XLCd to_lcd,
const char *to_type)
{
return create_conv(from_lcd, &stdc_wcstombs_methods);
}
static XlcConvMethodsRec stdc_wcstocs_methods = {
close_converter,
stdc_wcstocs,
NULL
};
static XlcConv
open_stdc_wcstocs(
XLCd from_lcd,
const char *from_type,
XLCd to_lcd,
const char *to_type)
{
return create_conv(from_lcd, &stdc_wcstocs_methods);
}
static XlcConvMethodsRec stdc_cstowcs_methods = {
close_converter,
stdc_cstowcs,
NULL
};
static XlcConv
open_stdc_cstowcs(
XLCd from_lcd,
const char *from_type,
XLCd to_lcd,
const char *to_type)
{
return create_conv(from_lcd, &stdc_cstowcs_methods);
}
#endif /* STDCVT */
XLCd
_XlcJisLoader(
const char *name)
{
XLCd lcd;
#ifdef STDCVT
XLCdGenericPart *gen;
#endif
lcd = _XlcCreateLC(name, _XlcGenericMethods);
if (lcd == NULL)
return lcd;
if (!XLC_PUBLIC_PART(lcd)->codeset ||
(_XlcCompareISOLatin1(XLC_PUBLIC_PART(lcd)->codeset, "JIS7"))) {
_XlcDestroyLC(lcd);
return (XLCd) NULL;
}
_XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNChar, open_mbtocs);
_XlcSetConverter(lcd, XlcNMultiByte, lcd, XlcNCharSet, open_mbstocs);
_XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNMultiByte, open_cstombs);
#ifdef STDCVT
gen = XLC_GENERIC_PART(lcd);
if (gen->use_stdc_env == True) {
_XlcSetConverter(lcd,XlcNMultiByte,lcd,XlcNWideChar,open_stdc_mbstowcs);
_XlcSetConverter(lcd,XlcNWideChar,lcd,XlcNMultiByte,open_stdc_wcstombs);
}
if (gen->force_convert_to_mb == True) {
_XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet,open_stdc_wcstocs);
_XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar,open_stdc_cstowcs);
} else {
#endif
_XlcSetConverter(lcd, XlcNWideChar, lcd, XlcNCharSet, open_wcstocs);
_XlcSetConverter(lcd, XlcNCharSet, lcd, XlcNWideChar, open_cstowcs);
#ifdef STDCVT
}
#endif
_XlcAddUtf8Converters(lcd);
return lcd;
}
#else
typedef int dummy;
#endif /* X_LOCALE */
|