ReactOS 0.4.15-dev-7942-gd23573b
nls.c File Reference
#include "precomp.h"
Include dependency graph for nls.c:

Go to the source code of this file.

Functions

static VOID NLS_InitCodePageTable (PUSHORT TableBase, PCPTABLEINFO CodePageTable)
 
PUSHORT NLS_ReadFile (const WCHAR *pszFile, PCPTABLEINFO CodePageTable)
 
BOOL NLS_IsDBCSCodePage (PCPTABLEINFO CodePageTable)
 
BOOL NLS_IsGlyphTablePresent (PCPTABLEINFO CodePageTable)
 
BOOL NLS_IsDefaultCharForMB (PCPTABLEINFO CodePageTable, UCHAR Char)
 
BOOL NLS_IsDefaultCharForUnicode (PCPTABLEINFO CodePageTable, USHORT Char)
 
USHORT NLS_RecordsCountForMBTable (PCPTABLEINFO CodePageTable)
 
USHORT NLS_RecordsCountForUnicodeTable (PCPTABLEINFO CodePageTable)
 
USHORT NLS_RecordsCountForGlyphTable (PCPTABLEINFO CodePageTable)
 
USHORT NLS_RecordsCountForDBCSTable (PCPTABLEINFO CodePageTable, UCHAR LeadByte)
 

Function Documentation

◆ NLS_InitCodePageTable()

static VOID NLS_InitCodePageTable ( PUSHORT  TableBase,
PCPTABLEINFO  CodePageTable 
)
static

Definition at line 11 of file nls.c.

12{
13 PNLS_FILE_HEADER NlsFileHeader;
14
15 NlsFileHeader = (PNLS_FILE_HEADER)TableBase;
16
17 /* Copy header fields first */
18 CodePageTable->CodePage = NlsFileHeader->CodePage;
20 CodePageTable->DefaultChar = NlsFileHeader->DefaultChar;
24
26
27 /* Offset to wide char table is after the header */
28 CodePageTable->WideCharTable = TableBase + NlsFileHeader->HeaderSize + 1 +
29 TableBase[NlsFileHeader->HeaderSize];
30
31 /* Then multibyte table (256 wchars) follows */
32 CodePageTable->MultiByteTable = TableBase + NlsFileHeader->HeaderSize + 1;
33
34 /* Check the presence of glyph table (256 wchars) */
36 {
38 }
39 else
40 {
42 }
43
44 /* Is this double-byte code page? */
46 {
49 }
50 else
51 {
54 }
55}
#define NULL
Definition: types.h:112
#define MAXIMUM_LEADBYTES
Definition: precomp.h:16
struct _NLS_FILE_HEADER * PNLS_FILE_HEADER
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4316
USHORT DefaultChar
Definition: precomp.h:34
PUSHORT DBCSRanges
Definition: precomp.h:42
USHORT DBCSCodePage
Definition: precomp.h:38
USHORT TransDefaultChar
Definition: precomp.h:36
PUSHORT MultiByteTable
Definition: precomp.h:40
UCHAR LeadByte[MAXIMUM_LEADBYTES]
Definition: precomp.h:39
USHORT CodePage
Definition: precomp.h:32
PUSHORT DBCSOffsets
Definition: precomp.h:43
USHORT UniDefaultChar
Definition: precomp.h:35
USHORT MaximumCharacterSize
Definition: precomp.h:33
PVOID WideCharTable
Definition: precomp.h:41
USHORT TransUniDefaultChar
Definition: precomp.h:37
USHORT MaximumCharacterSize
Definition: precomp.h:22
UCHAR LeadByte[MAXIMUM_LEADBYTES]
Definition: precomp.h:27
USHORT TransDefaultChar
Definition: precomp.h:25
USHORT HeaderSize
Definition: precomp.h:20
USHORT CodePage
Definition: precomp.h:21
USHORT TransUniDefaultChar
Definition: precomp.h:26
USHORT DefaultChar
Definition: precomp.h:23
USHORT UniDefaultChar
Definition: precomp.h:24
#define CopyMemory
Definition: winbase.h:1710

Referenced by NLS_ReadFile().

◆ NLS_IsDBCSCodePage()

BOOL NLS_IsDBCSCodePage ( PCPTABLEINFO  CodePageTable)

Definition at line 91 of file nls.c.

92{
94}
unsigned int BOOL
Definition: ntddk_ex.h:94

Referenced by BestFit_FromNLS(), and NLS_IsDefaultCharForUnicode().

◆ NLS_IsDefaultCharForMB()

BOOL NLS_IsDefaultCharForMB ( PCPTABLEINFO  CodePageTable,
UCHAR  Char 
)

Definition at line 103 of file nls.c.

104{
106 return FALSE;
107
108 return TRUE;
109}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117

Referenced by BestFit_FromNLS(), and NLS_RecordsCountForMBTable().

◆ NLS_IsDefaultCharForUnicode()

BOOL NLS_IsDefaultCharForUnicode ( PCPTABLEINFO  CodePageTable,
USHORT  Char 
)

Definition at line 112 of file nls.c.

113{
114 USHORT CodePageChar;
115
117 {
118 PUSHORT MultiByteTable = (PUSHORT)CodePageTable->WideCharTable;
119 CodePageChar = MultiByteTable[Char];
120 }
121 else
122 {
123 PUCHAR SingleByteTable = (PUCHAR)CodePageTable->WideCharTable;
124 CodePageChar = SingleByteTable[Char];
125 }
126
127 if (CodePageChar != CodePageTable->DefaultChar)
128 return FALSE;
129
130 return TRUE;
131}
BOOL NLS_IsDBCSCodePage(PCPTABLEINFO CodePageTable)
Definition: nls.c:91
unsigned short USHORT
Definition: pedump.c:61
uint16_t * PUSHORT
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by BestFit_FromNLS(), and NLS_RecordsCountForUnicodeTable().

◆ NLS_IsGlyphTablePresent()

BOOL NLS_IsGlyphTablePresent ( PCPTABLEINFO  CodePageTable)

Definition at line 97 of file nls.c.

98{
99 return (CodePageTable->MultiByteTable[256]) ? TRUE : FALSE;
100}

Referenced by BestFit_FromNLS(), and NLS_RecordsCountForGlyphTable().

◆ NLS_ReadFile()

PUSHORT NLS_ReadFile ( const WCHAR pszFile,
PCPTABLEINFO  CodePageTable 
)

Definition at line 58 of file nls.c.

59{
61
64 {
66 DWORD dwRead;
68
71 if (pData != NULL)
72 {
73 if (ReadFile(hFile, pData, dwFileSize, &dwRead, NULL) != FALSE)
74 {
77
78 return pData;
79 }
80
81 free(pData);
82 }
83
85 }
86
87 return NULL;
88}
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
unsigned long DWORD
Definition: ntddk_ex.h:95
static VOID NLS_InitCodePageTable(PUSHORT TableBase, PCPTABLEINFO CodePageTable)
Definition: nls.c:11
DWORD dwFileSize
Definition: more.c:40
_In_ HANDLE hFile
Definition: mswsock.h:90
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
#define CreateFile
Definition: winbase.h:3749

Referenced by BestFit_FromNLS().

◆ NLS_RecordsCountForDBCSTable()

USHORT NLS_RecordsCountForDBCSTable ( PCPTABLEINFO  CodePageTable,
UCHAR  LeadByte 
)

Definition at line 186 of file nls.c.

187{
188 PUSHORT LeadByteInfo = CodePageTable->DBCSOffsets;
189 USHORT CodePageChar;
190 USHORT Count = 0;
191
192 for (CodePageChar = 0; CodePageChar <= 0xFF; CodePageChar++)
193 {
194 USHORT Info = LeadByteInfo[LeadByte];
195
196 if (Info && LeadByteInfo[Info + CodePageChar] != CodePageTable->UniDefaultChar)
197 {
198 Count++;
199 }
200 }
201
202 return Count;
203}
int Count
Definition: noreturn.cpp:7
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690

Referenced by BestFit_FromNLS().

◆ NLS_RecordsCountForGlyphTable()

USHORT NLS_RecordsCountForGlyphTable ( PCPTABLEINFO  CodePageTable)

Definition at line 164 of file nls.c.

165{
166 USHORT Count = 0;
167
169 {
170 PUSHORT GlyphTable = CodePageTable->MultiByteTable + 256 + 1;
171 USHORT CodePageChar;
172
173 for (CodePageChar = 0; CodePageChar <= 0xFF; CodePageChar++)
174 {
175 USHORT Char = GlyphTable[CodePageChar];
176
177 if (Char != CodePageTable->UniDefaultChar)
178 Count++;
179 }
180 }
181
182 return Count;
183}
BOOL NLS_IsGlyphTablePresent(PCPTABLEINFO CodePageTable)
Definition: nls.c:97

Referenced by BestFit_FromNLS().

◆ NLS_RecordsCountForMBTable()

USHORT NLS_RecordsCountForMBTable ( PCPTABLEINFO  CodePageTable)

Definition at line 134 of file nls.c.

135{
136 USHORT CodePageChar;
137 USHORT Count = 0;
138
139 for (CodePageChar = 0; CodePageChar <= 0xFF; CodePageChar++)
140 {
141 if (!NLS_IsDefaultCharForMB(CodePageTable, CodePageChar))
142 Count++;
143 }
144
145 return Count;
146}
BOOL NLS_IsDefaultCharForMB(PCPTABLEINFO CodePageTable, UCHAR Char)
Definition: nls.c:103

Referenced by BestFit_FromNLS().

◆ NLS_RecordsCountForUnicodeTable()

USHORT NLS_RecordsCountForUnicodeTable ( PCPTABLEINFO  CodePageTable)

Definition at line 149 of file nls.c.

150{
151 ULONG UnicodeChar;
152 USHORT Count = 0;
153
154 for (UnicodeChar = 0; UnicodeChar <= 0xFFFF; UnicodeChar++)
155 {
157 Count++;
158 }
159
160 return Count;
161}
BOOL NLS_IsDefaultCharForUnicode(PCPTABLEINFO CodePageTable, USHORT Char)
Definition: nls.c:112
uint32_t ULONG
Definition: typedefs.h:59

Referenced by BestFit_FromNLS().