summaryrefslogtreecommitdiffstats
path: root/private/os2/client/dllnls.c
blob: 884342faccd6c573792cd94f04eec9ff3190e06a (plain) (blame)
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
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    dllnls.c

Abstract:

    This module implements the NLS OS/2 V2.0 API Calls

Author:

    Steve Wood (stevewo) 20-Sep-1989 (Adapted from URTL\alloc.c)

Revision History:

    3/31/93 - MJarus - Moved the NLS string function for the OS2SS to ssrtl

--*/


#define INCL_OS2V20_TASKING
#define INCL_OS2V20_ERRORS
#define INCL_OS2V20_NLS
#include "os2dll.h"
#include "conrqust.h"
#include "os2nls.h"
#include "os2win.h"

ULONG Or2ProcessCodePage;
ULONG Or2CurrentCodePageIsOem;

extern OD2_COUNTRY_ENTRY     OD2_COUNTRY_TABLE[];
extern OD2_CODEPAGE_ENTRY    OD2_CODEPAGE_TABLE[];
extern OD2_DBCS_VECTOR_ENTRY OD2_DBCS_VECTOR_TABLE[];
extern OD2_COLLATE_CTRY_ENTRY OD2_COLLATE_CTRY_TABLE[];
extern PUCHAR OD2_CASEMAP_TABLE[];
extern PUCHAR OD2_COLLATE_CP_TABLE[];
extern PUCHAR OD2_FIX_CASEMAP_TABLE[];
extern UCHAR  Od2BaseCaseMapTable[];
extern UCHAR  Od2BaseCollateTable[];



APIRET
DosQueryCtryInfo(
    IN ULONG MaxCountryInfoLength,
    IN PCOUNTRYCODE CountryCode,
    OUT PCOUNTRYINFO CountryInfo,
    OUT PULONG ActualCountryInfoLength
    )
{
    COUNTRYINFO DefaultInformation;
    APIRET      RetCode;
#if DBG
    PSZ         FuncName;

    FuncName = "DosQueryCtryInfo";
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("%s: Country %lu, CP %lu, (current Ctry %lu, CP %lu), Length %lu\n",
            FuncName, CountryCode->country, CountryCode->codepage,
            SesGrp->CountryCode, SesGrp->DosCP, MaxCountryInfoLength ));
    }
#endif

    //
    // zero buffer.  probe parms.
    //

    try
    {
        RtlZeroMemory( (PVOID)CountryInfo, MaxCountryInfoLength );
        Od2ProbeForRead (CountryCode, sizeof(COUNTRYCODE),1);
        *ActualCountryInfoLength = 0;
    }
    except( EXCEPTION_EXECUTE_HANDLER )
    {
       Od2ExitGP();
    }

    RetCode = Od2GetCtryInfo(
        CountryCode->country,
        CountryCode->codepage,
        &DefaultInformation
        );

    if ( !CountryCode->country && CountryCode->codepage)
    {
        CountryCode->country = SesGrp->CountryCode;
    }

    if ( RetCode )
    {
        return (RetCode);
    }

    if (MaxCountryInfoLength < sizeof( COUNTRYINFO ))
    {
#if DBG
        IF_OD2_DEBUG(NLS)
        {
            KdPrint(("%s: Table trunc (%lu instead of %lu)\n",
                FuncName, MaxCountryInfoLength, sizeof( COUNTRYINFO )));
        }
#endif
        *ActualCountryInfoLength = MaxCountryInfoLength;
        RetCode = ERROR_NLS_TABLE_TRUNCATED;
    } else
    {
        *ActualCountryInfoLength = sizeof( COUNTRYINFO );
    }

    RtlMoveMemory( (PVOID)CountryInfo,
                   (PVOID)&DefaultInformation,
                   *ActualCountryInfoLength
                 );
    return (RetCode);
}


APIRET
DosQueryDBCSEnv(
    IN ULONG MaxDBCSEvLength,
    IN PCOUNTRYCODE CountryCode,
    OUT PCHAR DBCSEv
    )
{
    CHAR    LocalDBCSEv[12];
    APIRET  RetCode;
    ULONG   BufLength;
#if DBG
    PSZ     FuncName;

    FuncName = "DosQueryDBCSEnv";
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("%s: Country %lu, CP %lu, (current Ctry %lu, CP %lu), Length %lu\n",
            FuncName, CountryCode->country, CountryCode->codepage,
            SesGrp->CountryCode, SesGrp->DosCP, MaxDBCSEvLength ));
    }
#endif

    //
    // zero buffer.  probe parms.
    //

    try
    {
        Od2ProbeForRead( CountryCode, sizeof(COUNTRYCODE), 1 );
        RtlZeroMemory( (PVOID)DBCSEv, MaxDBCSEvLength );
    } except( EXCEPTION_EXECUTE_HANDLER )
    {
       Od2ExitGP();
    }

    RetCode = Od2GetDBCSEv(
        CountryCode->country,
        CountryCode->codepage,
        &LocalDBCSEv[0],
        &BufLength
        );

    if ( !CountryCode->country && CountryCode->codepage)
    {
        CountryCode->country = SesGrp->CountryCode;
    }

    if ( RetCode )
    {
        return (RetCode);
    }

    if ( MaxDBCSEvLength < BufLength )
    {
#if DBG
        IF_OD2_DEBUG(NLS)
        {
            KdPrint(("%s: Table trunc (%lu instead of %lu)\n",
                FuncName, MaxDBCSEvLength, BufLength));
        }
#endif
        BufLength = MaxDBCSEvLength;
        RetCode = ERROR_NLS_TABLE_TRUNCATED;
    }

    RtlMoveMemory( (PVOID)DBCSEv,
                   (PVOID)LocalDBCSEv,
                   BufLength
                 );
    return (RetCode);
}


APIRET
DosMapCase(
    IN     ULONG        StringLength,
    IN     PCOUNTRYCODE CountryCode,
    IN OUT PUCHAR       String
    )
{
    UCHAR           CaseMapTable[256];
    ULONG           CharNum;
    APIRET          RetCode;
#if DBG
    PSZ             FuncName;

    FuncName = "DosMapCase";
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("%s: Country %lu, CP %lu, (current Ctry %lu, CP %lu), Length %lu, String %c...\n",
            FuncName, CountryCode->country, CountryCode->codepage,
            SesGrp->CountryCode, SesGrp->DosCP, StringLength, *String ));
    }
#endif

    //
    // probe parms.
    //

    try
    {
        Od2ProbeForRead (CountryCode, sizeof(COUNTRYCODE), 1);
        Od2ProbeForWrite (String, StringLength, 1);
    } except( EXCEPTION_EXECUTE_HANDLER )
    {
       Od2ExitGP();
    }

    RetCode = Od2GetCaseMapTable(
            CountryCode->country,
            CountryCode->codepage,
            CaseMapTable);

    if ( !CountryCode->country && CountryCode->codepage)
    {
        CountryCode->country = SesGrp->CountryCode;
    }

    if ( RetCode )
    {
        return (RetCode);
    }

    for ( CharNum = 0 ; CharNum < StringLength ; CharNum++ )
    {
#ifdef DBCS
// MSKK Apr.18.1993 V-AkihiS
// Support DBCS for DosCaseMap API.
        if (IsDBCSLeadByte(String[CharNum]))
        {
            CharNum++;
        } else
        {
            String[CharNum] = CaseMapTable[String[CharNum]];
        }
#else
        String[CharNum] = CaseMapTable[String[CharNum]];
#endif
    }
    return( NO_ERROR );
}


APIRET
DosQueryCollate(
    IN  ULONG        MaxCollateInfoLength,
    IN  PCOUNTRYCODE CountryCode,
    OUT PUCHAR       CollateInfo,
    OUT PULONG       ActualCollateInfoLength
    )
{
    UCHAR           CollateTable[256];
    APIRET          RetCode;
#if DBG
    PSZ             FuncName;

    FuncName = "DosQueryCollate";
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("%s: Country %lu, CP %lu, (current Ctry %lu, CP %lu), Length %lu\n",
            FuncName, CountryCode->country, CountryCode->codepage,
            SesGrp->CountryCode, SesGrp->DosCP, MaxCollateInfoLength ));
    }
#endif

    //
    // probe parms.
    //

    try
    {
        Od2ProbeForRead (CountryCode, sizeof(COUNTRYCODE),1);
        RtlZeroMemory(CollateInfo, MaxCollateInfoLength);
        *ActualCollateInfoLength = 0;
    } except( EXCEPTION_EXECUTE_HANDLER )
    {
       Od2ExitGP();
    }

    RetCode = Od2GetCollateTable(
            CountryCode->country,
            CountryCode->codepage,
            CollateTable);

    if ( !CountryCode->country && CountryCode->codepage)
    {
        CountryCode->country = SesGrp->CountryCode;
    }

    if ( RetCode )
    {
        return (RetCode);
    }

    if ( MaxCollateInfoLength > 256 )
    {
        MaxCollateInfoLength = 256;
    }

    memmove( CollateInfo, CollateTable, MaxCollateInfoLength);

    *ActualCollateInfoLength = MaxCollateInfoLength;

    if ( MaxCollateInfoLength < 256 )
    {
        return( ERROR_NLS_TABLE_TRUNCATED );
    }

    return( NO_ERROR );
}


APIRET
DosSetProcessCp(
    IN  ULONG  ulCodePage,
    IN  ULONG  ulReserved
    )
{
#if DBG
    PSZ            FuncName;

    FuncName = "DosSetProcessCp";
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("%s: CP %lu, Reserved %lu, (current %lu)\n",
            FuncName, ulCodePage, ulReserved, SesGrp->DosCP));
    }
#endif

    if ( ulReserved != 0 )
    {
        return (ERROR_INVALID_PARAMETER);
    }

    //
    // Validate the CodePage parameter against the list of installed code
    // pages.
    //

    if (( ulCodePage == 0 ) ||
        (( ulCodePage != SesGrp->PrimaryCP ) &&
         ( ulCodePage != SesGrp->SecondaryCP )))
    {
        return (ERROR_INVALID_CODE_PAGE);
    }

    //
    // Store the code page in the process structure
    //

    Od2ProcessCodePage = ulCodePage;

    if (Od2ProcessCodePage != SesGrp->Win32OEMCP)
    {
        Od2CurrentCodePageIsOem = FALSE;
    } else
    {
        Od2CurrentCodePageIsOem = TRUE;
    }

    return( NO_ERROR );
}


APIRET
DosQueryCp(
    IN  ULONG  MaxLengthCodePageList,
    OUT ULONG  CodePages[],
    OUT PULONG CountCodePages
    )
{
    ULONG Count, TotalCount;
    APIRET rc = NO_ERROR;
#if DBG
    PSZ            FuncName;

    FuncName = "DosQueryCp";
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("%s: Length %lu, (current CP %lu)\n",
            FuncName, MaxLengthCodePageList, SesGrp->DosCP));
    }
#endif

    try
    {
        Od2ProbeForWrite( CountCodePages, sizeof( USHORT ), 1);
        Od2ProbeForWrite( CodePages, MaxLengthCodePageList * sizeof( USHORT ), 1);
    }
    except( EXCEPTION_EXECUTE_HANDLER )
    {
       Od2ExitGP();
    }

    if ( MaxLengthCodePageList < sizeof(ULONG) )
    {
        *CountCodePages = 0;
        return (ERROR_CPLIST_TOO_SMALL);
    }

    //
    // Determine the number of code pages to return.  This is at least one
    // for the code page associated with the current process, plus N for the
    // N installed code pages.
    //

    Count = (SesGrp->SecondaryCP) ? 2 : 1;

    //
    // Determine the maximum number of code pages the caller can accept in
    // their buffer.  This is just the buffer length divided by sizeof( ULONG )
    //

    TotalCount = MaxLengthCodePageList / sizeof( ULONG ) - 1;

    //
    // Determine how many we will actually return and setup to return
    // an error status if the list will be truncated.
    //

    if (Count > TotalCount)
    {
        Count = TotalCount;
        rc = ERROR_CPLIST_TOO_SMALL;
    }

    //
    // Return the actual length of code page information returned in the
    // caller's buffer.
    //

    *CountCodePages = (Count + 1) * sizeof( ULONG );

    //
    // Return the code page for the process always.
    //

    *CodePages++ = Od2ProcessCodePage;

    //
    // Return the installed code pages.
    //

    RtlMoveMemory( CodePages, &SesGrp->PrimaryCP, Count * sizeof(ULONG) );

    //
    // Return success or error code.
    //

    return( rc );
}



APIRET
Od2InitNls( IN  ULONG        CodePage,
            IN  BOOLEAN      StartBySM)
/*++

Routine Description:

    This routine initialize NLS parms

Arguments:

    CodePage - parent proess code-page identifier

    StartBySm - flag indicates if start by SM (new session) or by
            another process DosExecPgm

Return Value:


Note:
    CodePage is relevamt only if (!StartBySM). Otherwise - codepage
    is what os2.exe put in SesGrp->DosCp

--*/

{
    if ( StartBySM )
    {
        Od2ProcessCodePage = SesGrp->DosCP;
    } else
    {
        Od2ProcessCodePage = CodePage;
    }

    if (Od2ProcessCodePage != SesGrp->Win32OEMCP)
    {
        Od2CurrentCodePageIsOem = FALSE;
    } else
    {
        Od2CurrentCodePageIsOem = TRUE;
    }
#if DBG
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("InitNLS: Code Page %lu (OEM flag %lu, StartBySM %lu, SesGrp->DosCp %lu, Arg CP %lu)\n",
            Od2ProcessCodePage, Od2CurrentCodePageIsOem, StartBySM, SesGrp->DosCP, CodePage ));
    }
#endif

    Od2SystemRoot = &SesGrp->SystemDirectory[0];

    return (NO_ERROR);
}


CHAR Spain437CurrencyStr[] = "\236\0\0\0";
CHAR Arabic864CurrencyStr[] = "\244\0\0\0";

APIRET
Od2GetCtryInfo( IN  ULONG        Country,
                IN  ULONG        CodePage,
                OUT PCOUNTRYINFO CountryInfo)
/*++

Routine Description:

    This routine fill country info struct after checking the parms

Arguments:

    Country - country code ( 0 - current )

    CodePage - code-page identifier ( 0 - current )

    CountryInfo - where to store COUNTRYINFO


Return Value:

    ERROR_NLS_BAD_TYPE - ?
    ERROR_NLS_NO_CTRY_CODE - ?
    ERROR_NLS_TYPE_NOT_FOUND - ?
    ( ERROR_NLS_TABLE_TRUNCATED - by DosGet/QueryCtryInfo )

Note:

--*/

{
    ULONG           CountryIndex, CodePageIndex;
    PCOUNTRYINFO    SrcCountryInfo;
    APIRET          RetCode;
    BOOLEAN         FromOriginalTable = FALSE;
    APIRET          Rc;
    COUNTRYINFO     LocalCountryInfo;
#if DBG
    PSZ             FuncName;

    FuncName = "Od2GetCtryInfo";
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("%s: Country %u, CodePage %u\n",
            FuncName, Country, CodePage));
    }
#endif

    RetCode = Od2GetCtryCp( &Country, &CodePage, &CountryIndex, &CodePageIndex );

    if ((Country == SesGrp->CountryCode) &&
        ((CodePage == SesGrp->PrimaryCP) || (CodePage == SesGrp->SecondaryCP)))
    {
        SrcCountryInfo = &SesGrp->CountryInfo;
    } else if (RetCode)
    {
        Rc = Ow2NlsGetCtryInfo(
                              CodePage,
                              Country,
                              &LocalCountryInfo
                             );
        if ( Rc )
        {
#if DBG
            IF_OD2_DEBUG( NLS )
            {
                KdPrint(("%s: RetCode from LPC %lu\n", FuncName, Rc));
            }
#endif
            return( RetCode );
        }
        SrcCountryInfo = &LocalCountryInfo;
    } else
    {
        SrcCountryInfo = OD2_COUNTRY_TABLE[CountryIndex].pCtryInfo;
        FromOriginalTable = TRUE;
    }

    RtlMoveMemory(CountryInfo,
                  SrcCountryInfo,
                  sizeof(COUNTRYINFO));

    CountryInfo->codepage = CodePage;
    CountryInfo->country = Country;

    if (FromOriginalTable)
    {
        if ((Country == COUNTRY_SPAIN) &&
            (CodePage == CODEPAGE_US))
        {
            RtlMoveMemory(CountryInfo->szCurrency,
                          Spain437CurrencyStr,
                          5);
        } else if ((Country == COUNTRY_ARABIC) &&
                   (CodePage == CODEPAGE_ARABIC))
        {
            RtlMoveMemory(CountryInfo->szCurrency,
                          Arabic864CurrencyStr,
                          5);
        }
    }

    return (NO_ERROR);
}


APIRET
Od2GetDBCSEv( IN   ULONG      Country,
              IN   ULONG      CodePage,
              IN OUT PUCHAR   DBCSEv,
              OUT  PULONG     StringLength)
/*++

Routine Description:

    This routine fill DBCS environment vector after checking the parms

Arguments:

    Country - country code ( 0 - current )

    CodePage - code-page identifier ( 0 - current )

    DBVSEv - where to store the vector

    StringLength - where to retutn the actual length of the output vector


Return Value:

    ERROR_NLS_BAD_TYPE - ?
    ERROR_NLS_NO_CTRY_CODE - ?
    ERROR_NLS_TYPE_NOT_FOUND - ?
    ( ERROR_NLS_NO_COUNTRY_FILE - we don't keep info in file )
    ( ERROR_NLS_OPEN_FAILED - we don't keep info in file )
    ( ERROR_NLS_TABLE_TRUNCATED - by DosGet/QueryDBCSEv )

Note:

--*/

{
    ULONG           CountryIndex, CodePageIndex;
    APIRET          RetCode;
    POD2_DBCS_VECTOR_ENTRY SrcDBCSVec;
    OD2_DBCS_VECTOR_ENTRY  LocalDBCSVec;
    APIRET          Rc;
#if DBG
    PSZ             FuncName;

    FuncName = "Od2GetDBCSEv";
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("%s: Country %u, CodePage %u\n",
            FuncName, Country, CodePage));
    }
#endif
    RetCode = Od2GetCtryCp( &Country, &CodePage, &CountryIndex, &CodePageIndex );

    if (((CodePage == SesGrp->PrimaryCP) || (CodePage == SesGrp->SecondaryCP)) &&
        ((Country == SesGrp->CountryCode) || !RetCode))
    {
        if(CodePage == SesGrp->PrimaryCP)
        {
            SrcDBCSVec = &SesGrp->PriDBCSVec;
        } else
        {
            SrcDBCSVec = &SesGrp->SecDBCSVec;
        }
    } else if (RetCode)
    {
#ifdef JAPAN
// MSKK Jul.02.1993 V-AkihiS
// Chechk country code, because Ow2NlsGetDBCSEn does not check country code.
        if (Country != SesGrp->CountryCode)
        {
            return( RetCode );
        }
#endif
        Rc = Ow2NlsGetDBCSEn(
                            CodePage,
                            &LocalDBCSVec
                           );
        if ( Rc )
        {
#if DBG
            IF_OD2_DEBUG( NLS )
            {
                KdPrint(("%s: RetCode from LPC %lu\n", FuncName, Rc));
            }
#endif
            return( RetCode );
        }
        SrcDBCSVec = &LocalDBCSVec;
    } else
    {
        SrcDBCSVec = &OD2_DBCS_VECTOR_TABLE[OD2_CODEPAGE_TABLE[CodePageIndex].DBCSVecIndex];
    }

    *StringLength = SrcDBCSVec->VectorSize;

    RtlMoveMemory(DBCSEv,
                  SrcDBCSVec->Vector,
                  *StringLength);

    return (NO_ERROR);
}


APIRET
Od2GetCaseMapTable(
              IN   ULONG      Country,
              IN   ULONG      CodePage,
              OUT  PUCHAR     CaseMapTable)
/*++

Routine Description:

    This routine fill creates a case map table for the CP after
    checking the parms

Arguments:

    Country - country code ( 0 - current )

    CodePage - code-page identifier ( 0 - current )

    CaseMapTable - where to store the case map table


Return Value:

    ERROR_NLS_BAD_TYPE - ?
    ERROR_NLS_NO_CTRY_CODE - ?
    ERROR_NLS_TYPE_NOT_FOUND - ?
    ( ERROR_NLS_NO_COUNTRY_FILE - we don't keep info in file )
    ( ERROR_NLS_OPEN_FAILED - we don't keep info in file )
    ( ERROR_NLS_TABLE_TRUNCATED - by DosGet/QueryDBCSEv )

Note:

--*/

{
    ULONG           CountryIndex, i, CodePageIndex;
    PUCHAR          SrcTable, CPFixTable = NULL, CtryFixTable = NULL;
    APIRET          RetCode;
    UCHAR           LocalTable[256];
    APIRET          Rc;
#if DBG
    PSZ             FuncName;

    FuncName = "Od2GetCaseMapTable";
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("%s: Country %u, CodePage %u\n",
            FuncName, Country, CodePage));
    }
#endif
    RetCode = Od2GetCtryCp( &Country, &CodePage, &CountryIndex, &CodePageIndex );

    if ((Country == SesGrp->CountryCode) &&
        ((CodePage == SesGrp->PrimaryCP) || (CodePage == SesGrp->SecondaryCP)))
    {
        if(CodePage == SesGrp->PrimaryCP)
        {
            SrcTable = SesGrp->PriCaseMapTable;
        } else
        {
            SrcTable = SesGrp->SecCaseMapTable;
        }
    } else
           if (RetCode)
    {
        Rc = Ow2NlsGetCaseMapTable(
                                  CodePage,
                                  Country,
                                  &LocalTable[0]
                                 );
        if ( Rc )
        {
#if DBG
            IF_OD2_DEBUG( NLS )
            {
                KdPrint(("%s: RetCode from LPC %lu\n", FuncName, Rc));
            }
#endif
            return( RetCode );
        }
        SrcTable = &LocalTable[0];
    } else
    {
        SrcTable = Od2BaseCaseMapTable;
        CPFixTable = OD2_CASEMAP_TABLE[OD2_CODEPAGE_TABLE[CodePageIndex].CaseMapIndex];
        if (CodePage == 437)
        {
            CtryFixTable = OD2_FIX_CASEMAP_TABLE[OD2_COUNTRY_TABLE[CountryIndex].CaseMapFixTableIndex];
        }
    }

    RtlMoveMemory(CaseMapTable,
                  SrcTable,
                  256);

    if (CPFixTable)
    {
        for ( i = 0 ; (CPFixTable[i]  || CPFixTable[i + 1]) ; i += 2 )
        {
            CaseMapTable[CPFixTable[i]] = CPFixTable[i + 1];
        }
    }

    if (CtryFixTable)
    {
        for ( i = 0 ; (CtryFixTable[i]  || CtryFixTable[i + 1]) ; i += 2 )
        {
            CaseMapTable[CtryFixTable[i]] = CtryFixTable[i + 1];
        }
    }

    return (NO_ERROR);
}


APIRET
Od2GetCollateTable(
              IN   ULONG      Country,
              IN   ULONG      CodePage,
              OUT  PUCHAR     CollateTable)
/*++

Routine Description:

    This routine fill creates a Collate table for the CP after
    checking the parms

Arguments:

    Country - country code ( 0 - current )

    CodePage - code-page identifier ( 0 - current )

    CollateTable - where to store the Collate table


Return Value:

    ERROR_NLS_BAD_TYPE - ?
    ERROR_NLS_NO_CTRY_CODE - ?
    ERROR_NLS_TYPE_NOT_FOUND - ?
    ( ERROR_NLS_NO_COUNTRY_FILE - we don't keep info in file )
    ( ERROR_NLS_OPEN_FAILED - we don't keep info in file )
    ( ERROR_NLS_TABLE_TRUNCATED - by DosGet/QueryDBCSEv )

Note:

--*/

{
    ULONG           CountryIndex, i, CodePageIndex;
    PUCHAR          SrcTable, CPFixTable = NULL, CtryFixTable = NULL;
    APIRET          RetCode;
//    UCHAR           LocalTable[256];
#if DBG
    APIRET	    Rc=0;
    PSZ             FuncName;

    FuncName = "Od2GetCollateTable";
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("%s: Country %u, CodePage %u\n",
            FuncName, Country, CodePage));
    }
#endif // DBG
    RetCode = Od2GetCtryCp( &Country, &CodePage, &CountryIndex, &CodePageIndex );

//    if ((Country == SesGrp->CountryCode) &&
//        ((CodePage == SesGrp->PrimaryCP) || (CodePage == SesGrp->SecondaryCP)))
//    {
//        if(CodePage == SesGrp->PrimaryCP)
//        {
//            SrcTable = SesGrp->PriCollateTable;
//        } else
//        {
//            SrcTable = SesGrp->SecCollateTable;
//        }
//    } else
           if (RetCode)
    {
//        Rc = Ow2NlsGetCollateTable(
//                                  CodePage,
//                                  Country,
//                                  &LocalTable[0]
//                                 );
//        if ( Rc )
//        {
#if DBG

            // BUGBUG: debug statement below prints random Rc value
            IF_OD2_DEBUG( NLS )
            {
                KdPrint(("%s: RetCode from LPC %lu\n", FuncName, Rc));
            }
#endif
            return( RetCode );
//        }
//        SrcTable = &LocalTable[0];
    } else
    {
        SrcTable = Od2BaseCollateTable;
        CPFixTable = OD2_COLLATE_CP_TABLE[OD2_CODEPAGE_TABLE[CodePageIndex].CollateIndex];

        for ( i = 0 ; OD2_COLLATE_CTRY_TABLE[i].Country ; i++ )
        {
            if ((OD2_COLLATE_CTRY_TABLE[i].Country == Country) &&
                (OD2_COLLATE_CTRY_TABLE[i].CodePage == CodePage))
            {
                CtryFixTable = OD2_COLLATE_CTRY_TABLE[i].FixTable;
                break;
            }
        }
    }

    RtlMoveMemory(CollateTable,
                  SrcTable,
                  256);

    if (CPFixTable)
    {
        for ( i = 0 ; (CPFixTable[i] || CPFixTable[i + 1]) ; i += 2 )
        {
            CollateTable[CPFixTable[i]] = CPFixTable[i + 1];
        }
    }

    if (CtryFixTable)
    {
        for ( i = 0 ; (CtryFixTable[i] || CtryFixTable[i + 1]) ; i += 2 )
        {
            CollateTable[CtryFixTable[i]] = CtryFixTable[i + 1];
        }
    }

    return (NO_ERROR);
}


APIRET
Od2GetCtryCp( IN OUT PULONG      Country,
              IN OUT PULONG      CodePage,
              OUT    PULONG      CountryTableIndex,
              OUT    PULONG      CodePageTableIndex)
/*++

Routine Description:

    This routine checks the country and code-page parms.
    If zero (default) it set them properly.
    If exist in table, return index.

Arguments:

    Country - where to read from and update the country code ( 0 - current )

    CodePage - where to read from and update the code-page identifier ( 0 - current )

    CountryTableIndex - where to store the index for the language

    CodePageTableIndex - where to store the index for the code page

Return Value:

    ERROR_NLS_BAD_TYPE - ?
    ERROR_NLS_NO_CTRY_CODE - illegal country code or illegal code page
    ERROR_NLS_TYPE_NOT_FOUND - ?
    ( ERROR_NLS_NO_COUNTRY_FILE - we don't keep info in file )
    ( ERROR_NLS_OPEN_FAILED - we don't keep info in file )
    ( ERROR_NLS_TABLE_TRUNCATED - by DosGet/QueryCtryInfo )

Note:

--*/

{
    ULONG       CountryIndex;
#if DBG
    PSZ         FuncName;

    FuncName = "Od2GetCtryCp";
    IF_OD2_DEBUG(NLS)
    {
        KdPrint(("%s: enter\n", FuncName));
    }
#endif

    if ( !*Country )
    {
        *Country = SesGrp->CountryCode;
#if DBG
        IF_OD2_DEBUG(NLS)
        {
            KdPrint(("%s: country set to current %lu\n",
                FuncName, SesGrp->CountryCode));
        }
#endif
    }

    if ( !*CodePage )
    {
        *CodePage = Od2ProcessCodePage;
#if DBG
        IF_OD2_DEBUG(NLS)
        {
            KdPrint(("%s: code page set to current %lu\n",
                FuncName, Od2ProcessCodePage));
        }
#endif
    }

    for ( CountryIndex = 0 ; ( OD2_COUNTRY_TABLE[CountryIndex].Country &&
                             ( OD2_COUNTRY_TABLE[CountryIndex].Country != *Country )) ;
                             CountryIndex++ );

    if ( !OD2_COUNTRY_TABLE[CountryIndex].Country )
    {
#if DBG
        IF_OD2_DEBUG(NLS)
        {
            KdPrint(("%s: no such country %lu\n",
                FuncName, *Country));
        }
#endif
        return (ERROR_NLS_NO_CTRY_CODE);
    }

    if ( *CodePage == OD2_CODEPAGE_TABLE[OD2_COUNTRY_TABLE[CountryIndex].CodePageIndex1].CodePage )
    {
        *CodePageTableIndex = OD2_COUNTRY_TABLE[CountryIndex].CodePageIndex1;
    } else if ( *CodePage == OD2_CODEPAGE_TABLE[OD2_COUNTRY_TABLE[CountryIndex].CodePageIndex2].CodePage )
    {
        *CodePageTableIndex = OD2_COUNTRY_TABLE[CountryIndex].CodePageIndex2;
#ifdef DBCS
// MSKK Apr.19.1993 V-AkihiS
// Support CodePage 850(CODEPAGE_MULTI)
    } else if ( *CodePage == CODEPAGE_MULTI )
    {
        *CodePageTableIndex = INDEX_CODEPAGE_MULTI;
#endif
    } else
    {
#if DBG
        IF_OD2_DEBUG(NLS)
        {
            KdPrint(("%s: no such code page %lu\n",
                FuncName, *CodePage));
        }
#endif
        return (ERROR_NLS_NO_CTRY_CODE);
    }

    /*  In DBCS countries, when CP == US then info is according to USA. */

    if ((( *Country == COUNTRY_JAPAN ) ||
         ( *Country == COUNTRY_TAIWAN ) ||
         ( *Country == COUNTRY_PRCHINA ) ||
         ( *Country == COUNTRY_SOUTH_KOREA )) &&
#ifdef DBCS
// MSKK Apr.24.1993
// Support CodePage 850(CODEPAGE_MULTI)
        (( *CodePage == CODEPAGE_US ) || ( *CodePage == CODEPAGE_MULTI)))
#else
        ( *CodePage == CODEPAGE_US ))
#endif
    {
        CountryIndex = 0;       // US must be first in OD2_COUNTRY_TABLE
    }

    *CountryTableIndex = CountryIndex;

    return (NO_ERROR);
}