update for HEAD-2003021201
[reactos.git] / lib / kernel32 / nls / codepage.c
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3                     Addition copyrights might be specified in LGPL.c
4  * PROJECT:         ReactOS system libraries
5  * FILE:            lib/kernel32/nls/codepage.c
6  * PURPOSE:         National language support functions
7  * PROGRAMMER:      Boudewijn ( ariadne@xs4all.nl)
8  * UPDATE HISTORY:  Modified from Onno Hovers wfc. ( 08/02/99 )
9                     Modified from wine. ( 08/02/99 )
10  *                  
11  */
12
13 /*
14  * nls/codepage.c ( Onno Hovers )
15  *
16  *
17  */
18
19 /*
20  * Win32 kernel functions
21  *
22  * Copyright 1995 Martin von Loewis and Cameron Heide
23  */
24 #include <windows.h>
25 #include <kernel32/nls.h>
26 #include <kernel32/thread.h>
27 #include <string.h>
28
29 #define NDEBUG
30 #include <kernel32/kernel32.h>
31
32
33 extern PLOCALE  __TebLocale;
34
35 #define GetTebLocale() __TebLocale
36  
37
38 UINT STDCALL GetACP(void)
39 {
40    DPRINT("GetACP()\n");
41    
42    /* XXX: read from registry, take this as default */
43    return GetTebLocale()->AnsiCodePage->Id;
44 }
45
46 UINT STDCALL GetOEMCP(void)
47 {
48    DPRINT("GetOEMCP()\n");
49    /* XXX: read from registry, take this as default */
50    return GetTebLocale()->OemCodePage->Id;
51 }
52
53 WINBOOL STDCALL IsValidCodePage(UINT codepage)
54 {
55    PCODEPAGE pcp;
56  
57    DPRINT("IsValidCodePage( %u )\n", codepage);  
58    
59    switch(codepage)
60    {
61       case CP_ACP:   return TRUE;
62       case CP_OEMCP: return TRUE; 
63       case CP_MACCP: return TRUE;
64       default:
65          pcp=__CPFirst;
66          while((pcp)&&(pcp->Id!=codepage))
67             pcp=pcp->Next;
68          return pcp ? TRUE : FALSE;      
69    }
70 }
71
72 WINBOOL
73 STDCALL
74 GetCPInfo(UINT codepage, LPCPINFO pcpinfo)
75 {
76     PCODEPAGE pcp;
77    
78     DPRINT("GetCPInfo( %u, 0x%lX )\n", codepage, (ULONG) pcpinfo);
79     
80     pcp=__CPFirst;
81     while((pcp)&&(pcp->Id!=codepage))
82             pcp=pcp->Next;  
83     if(!pcp) {
84         SetLastError(ERROR_INVALID_PARAMETER);
85         return FALSE;
86     }
87     if(!pcp->Info) {
88         SetLastError(ERROR_INVALID_PARAMETER);
89         return FALSE;
90     }
91        
92     *pcpinfo = *pcp->Info;
93     return TRUE;
94 }
95
96
97
98 WINBOOL 
99 STDCALL 
100 IsDBCSLeadByteEx( UINT codepage, BYTE testchar )
101 {
102     CPINFO cpinfo;
103     int i;
104
105     GetCPInfo(codepage, &cpinfo);
106     for (i = 0 ; i < sizeof(cpinfo.LeadByte)/sizeof(cpinfo.LeadByte[0]); i+=2)
107     {
108         if (cpinfo.LeadByte[i] == 0)
109             return FALSE;
110         if (cpinfo.LeadByte[i] <= testchar && testchar <= cpinfo.LeadByte[i+1])
111             return TRUE;
112     }
113     return FALSE;
114 }
115
116
117
118
119 WINBOOL 
120 STDCALL 
121 IsDBCSLeadByte( BYTE testchar )
122 {
123     return IsDBCSLeadByteEx(GetACP(), testchar);
124 }