ReactOS  0.4.14-dev-49-gfb4591c
precomp.h File Reference
#include <windows.h>
#include <strsafe.h>
Include dependency graph for precomp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _NLS_FILE_HEADER
 
struct  _CPTABLEINFO
 

Macros

#define MAX_STR_LEN   256
 
#define MAXIMUM_LEADBYTES   12
 

Typedefs

typedef struct _NLS_FILE_HEADER NLS_FILE_HEADER
 
typedef struct _NLS_FILE_HEADERPNLS_FILE_HEADER
 
typedef struct _CPTABLEINFO CPTABLEINFO
 
typedef struct _CPTABLEINFOPCPTABLEINFO
 

Functions

int WINAPI GetUName (IN WORD wCharCode, OUT LPWSTR lpBuf)
 
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)
 
BOOL BestFit_FromNLS (const WCHAR *pszNLSFile, const WCHAR *pszBestFitFile)
 

Macro Definition Documentation

◆ MAX_STR_LEN

#define MAX_STR_LEN   256

Definition at line 14 of file precomp.h.

◆ MAXIMUM_LEADBYTES

#define MAXIMUM_LEADBYTES   12

Definition at line 16 of file precomp.h.

Typedef Documentation

◆ CPTABLEINFO

◆ NLS_FILE_HEADER

◆ PCPTABLEINFO

◆ PNLS_FILE_HEADER

Function Documentation

◆ BestFit_FromNLS()

BOOL BestFit_FromNLS ( const WCHAR pszNLSFile,
const WCHAR pszBestFitFile 
)

Definition at line 113 of file bestfit.c.

114 {
116  PUSHORT CodePage;
117  HANDLE hFile;
118  USHORT CodePageChar;
119  ULONG UnicodeChar;
120 
121  CodePage = NLS_ReadFile(pszNLSFile, &CodePageTable);
122  if (CodePage == NULL)
123  return FALSE;
124 
125  hFile = BestFit_CreateFile(pszBestFitFile);
127  {
128  free(CodePage);
129  return FALSE;
130  }
131 
132  /* The only field is the decimal windows code page number for this code page. */
133  BestFit_Write(hFile, L"CODEPAGE %u\r\n\r\n", CodePageTable.CodePage);
134 
136  L"CPINFO %u 0x%02X 0x%04X\r\n\r\n",
137  /* "1" for a single byte code page, "2" for a double byte code page */
139  /* Replacement characters for unassigned Unicode code points when
140  written to this code page */
142  /* Replacement characters for illegal or unassigned code page values
143  when converting to Unicode. */
145 
146  /* This field contains the number of following records of code page to Unicode mappings. */
148 
149  for (CodePageChar = 0; CodePageChar <= 0xFF; CodePageChar++)
150  {
151  if (!NLS_IsDefaultCharForMB(&CodePageTable, CodePageChar))
152  {
153  WCHAR szCharName[MAX_STR_LEN] = { 0 };
154 
155  GetUName(CodePageTable.MultiByteTable[CodePageChar], szCharName);
156 
158  L"0x%02X 0x%04X ;%s\r\n",
159  CodePageChar,
160  CodePageTable.MultiByteTable[CodePageChar],
161  szCharName);
162  }
163  }
164 
165  BestFit_Write(hFile, L"\r\n");
166 
168  {
169  PUSHORT GlyphTable = CodePageTable.MultiByteTable + 256 + 1;
170 
172 
173  for (CodePageChar = 0; CodePageChar <= 0xFF; CodePageChar++)
174  {
175  if (CodePageChar != CodePageTable.UniDefaultChar)
176  {
177  WCHAR szCharName[MAX_STR_LEN] = { 0 };
178 
179  GetUName(GlyphTable[CodePageChar], szCharName);
180 
182  L"0x%02X 0x%04X ;%s\r\n",
183  CodePageChar,
184  GlyphTable[CodePageChar],
185  szCharName);
186  }
187  }
188 
189  BestFit_Write(hFile, L"\r\n");
190  }
191 
193  {
194  PUSHORT LeadByteRanges = (PUSHORT)&CodePageTable.LeadByte[0];
195  USHORT Index;
196  USHORT LeadByte;
197 
199  L"DBCSRANGE %u ;%u DBCS Lead Byte Ranges\r\n\r\n",
202 
203  for (Index = 0; Index < MAXIMUM_LEADBYTES / 2; Index++)
204  {
205  if (!LeadByteRanges[Index])
206  continue;
207 
209  L"0x%X 0x%X ;Lead Byte Range %u\r\n\r\n",
210  LOBYTE(LeadByteRanges[Index]),
211  HIBYTE(LeadByteRanges[Index]),
212  Index + 1);
213 
214  for (LeadByte = LOBYTE(LeadByteRanges[Index]);
215  LeadByte <= HIBYTE(LeadByteRanges[Index]);
216  LeadByte++)
217  {
218  PUSHORT LeadByteInfo = CodePageTable.DBCSOffsets;
219 
221  L"DBCSTABLE %u ;Range = %u, LeadByte = 0x%02X\r\n\r\n",
223  Index + 1,
224  LeadByte);
225 
226  for (CodePageChar = 0; CodePageChar <= 0xFF; CodePageChar++)
227  {
228  USHORT Info = LeadByteInfo[LeadByte];
229 
230  if (Info && LeadByteInfo[Info + CodePageChar] != CodePageTable.UniDefaultChar)
231  {
233  L"0x%02X 0x%04X\r\n",
234  CodePageChar,
235  LeadByteInfo[Info + CodePageChar]);
236  }
237  }
238 
239  BestFit_Write(hFile, L"\r\n");
240  }
241  }
242  }
243 
244  /* This field contains the number of records of Unicode to byte mappings. */
246 
247  for (UnicodeChar = 0; UnicodeChar <= 0xFFFF; UnicodeChar++)
248  {
249  if (!NLS_IsDefaultCharForUnicode(&CodePageTable, UnicodeChar))
250  {
251  WCHAR szCharName[MAX_STR_LEN] = { 0 };
252 
253  GetUName(UnicodeChar, szCharName);
254 
256  {
257  PUSHORT MultiByteTable = (PUSHORT)CodePageTable.WideCharTable;
258 
260  L"0x%04X 0x%04X ;%s\r\n",
261  UnicodeChar,
262  MultiByteTable[UnicodeChar],
263  szCharName);
264  }
265  else
266  {
267  PUCHAR SingleByteTable = (PUCHAR)CodePageTable.WideCharTable;
268 
270  L"0x%04X 0x%02X ;%s\r\n",
271  UnicodeChar,
272  SingleByteTable[UnicodeChar],
273  szCharName);
274  }
275  }
276  }
277 
278  /* This tag marks the end of the code page data. Anything after this marker is ignored. */
279  BestFit_Write(hFile, L"\r\nENDCODEPAGE\r\n");
280 
282  free(CodePage);
283 
284  return TRUE;
285 }
USHORT NLS_RecordsCountForUnicodeTable(PCPTABLEINFO CodePageTable)
Definition: nls.c:149
USHORT NLS_RecordsCountForMBTable(PCPTABLEINFO CodePageTable)
Definition: nls.c:134
#define TRUE
Definition: types.h:120
USHORT UniDefaultChar
Definition: precomp.h:35
PUSHORT DBCSOffsets
Definition: precomp.h:43
#define LOBYTE(W)
Definition: jmemdos.c:487
PUSHORT MultiByteTable
Definition: precomp.h:40
PUSHORT DBCSRanges
Definition: precomp.h:42
unsigned char * PUCHAR
Definition: retypes.h:3
#define free
Definition: debug_ros.c:5
BOOL NLS_IsDefaultCharForMB(PCPTABLEINFO CodePageTable, UCHAR Char)
Definition: nls.c:103
#define HIBYTE(W)
Definition: jmemdos.c:486
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
struct TraceInfo Info
PVOID WideCharTable
Definition: precomp.h:41
USHORT NLS_RecordsCountForDBCSTable(PCPTABLEINFO CodePageTable, UCHAR LeadByte)
Definition: nls.c:186
smooth NULL
Definition: ftsmooth.c:416
BOOL NLS_IsGlyphTablePresent(PCPTABLEINFO CodePageTable)
Definition: nls.c:97
UCHAR LeadByte[MAXIMUM_LEADBYTES]
Definition: precomp.h:39
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL NLS_IsDefaultCharForUnicode(PCPTABLEINFO CodePageTable, USHORT Char)
Definition: nls.c:112
USHORT MaximumCharacterSize
Definition: precomp.h:33
static const UCHAR Index[8]
Definition: usbohci.c:18
static HANDLE BestFit_CreateFile(const WCHAR *pszFile)
Definition: bestfit.c:11
USHORT CodePage
Definition: precomp.h:32
static const WCHAR L[]
Definition: oid.c:1250
#define MAXIMUM_LEADBYTES
Definition: precomp.h:16
USHORT DefaultChar
Definition: precomp.h:34
USHORT NLS_RecordsCountForGlyphTable(PCPTABLEINFO CodePageTable)
Definition: nls.c:164
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned short USHORT
Definition: pedump.c:61
PUSHORT NLS_ReadFile(const WCHAR *pszFile, PCPTABLEINFO CodePageTable)
Definition: nls.c:58
int WINAPI GetUName(IN WORD wCharCode, OUT LPWSTR lpBuf)
Definition: getuname.c:17
#define MAX_STR_LEN
Definition: defines.h:33
BOOL NLS_IsDBCSCodePage(PCPTABLEINFO CodePageTable)
Definition: nls.c:91
unsigned int ULONG
Definition: retypes.h:1
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4113
static VOID BestFit_Write(HANDLE hFile, const WCHAR *pszFormat,...)
Definition: bestfit.c:60
static VOID BestFit_CloseFile(HANDLE hFile)
Definition: bestfit.c:33
unsigned short * PUSHORT
Definition: retypes.h:2

Referenced by wmain().

◆ GetUName()

int WINAPI GetUName ( IN WORD  wCharCode,
OUT LPWSTR  lpBuf 
)

Definition at line 17 of file getuname.c.

19 {
20  WCHAR szDescription[256];
21  int res = LoadStringW(hInstance, wCharCode, szDescription, 256);
22  if (res != 0)
23  {
24  wcscpy(lpBuf, szDescription);
25  return 0;
26  }
27  else
28  {
29  wcscpy(lpBuf, L"Undefined");
30  return 0;
31  }
32 }
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
__wchar_t WCHAR
Definition: xmlstorage.h:180
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
HINSTANCE hInstance
Definition: getuname.c:13
GLuint res
Definition: glext.h:9613
static const WCHAR szDescription[]
Definition: provider.c:52

◆ 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
USHORT DBCSCodePage
Definition: precomp.h:38
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4113

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
USHORT UniDefaultChar
Definition: precomp.h:35
PUSHORT MultiByteTable
Definition: precomp.h:40
char Char
Definition: bzip2.c:161
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4113

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 }
#define TRUE
Definition: types.h:120
unsigned char * PUCHAR
Definition: retypes.h:3
PVOID WideCharTable
Definition: precomp.h:41
char Char
Definition: bzip2.c:161
USHORT DefaultChar
Definition: precomp.h:34
unsigned short USHORT
Definition: pedump.c:61
BOOL NLS_IsDBCSCodePage(PCPTABLEINFO CodePageTable)
Definition: nls.c:91
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4113
unsigned short * PUSHORT
Definition: retypes.h:2

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 }
#define TRUE
Definition: types.h:120
PUSHORT MultiByteTable
Definition: precomp.h:40
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4113

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 {
60  HANDLE hFile;
61 
64  {
65  PUSHORT pData;
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 CloseHandle
Definition: compat.h:398
#define free
Definition: debug_ros.c:5
DWORD dwFileSize
Definition: more.c:36
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_READ
Definition: compat.h:125
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4113
#define malloc
Definition: debug_ros.c:4
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
unsigned short * PUSHORT
Definition: retypes.h:2
static VOID NLS_InitCodePageTable(PUSHORT TableBase, PCPTABLEINFO CodePageTable)
Definition: nls.c:11

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 }
USHORT UniDefaultChar
Definition: precomp.h:35
PUSHORT DBCSOffsets
Definition: precomp.h:43
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
struct TraceInfo Info
unsigned short USHORT
Definition: pedump.c:61
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4113
unsigned short * PUSHORT
Definition: retypes.h:2

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 
178  Count++;
179  }
180  }
181 
182  return Count;
183 }
USHORT UniDefaultChar
Definition: precomp.h:35
PUSHORT MultiByteTable
Definition: precomp.h:40
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
char Char
Definition: bzip2.c:161
BOOL NLS_IsGlyphTablePresent(PCPTABLEINFO CodePageTable)
Definition: nls.c:97
unsigned short USHORT
Definition: pedump.c:61
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4113
unsigned short * PUSHORT
Definition: retypes.h:2

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
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
unsigned short USHORT
Definition: pedump.c:61
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4113

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  {
156  if (!NLS_IsDefaultCharForUnicode(CodePageTable, UnicodeChar))
157  Count++;
158  }
159 
160  return Count;
161 }
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
BOOL NLS_IsDefaultCharForUnicode(PCPTABLEINFO CodePageTable, USHORT Char)
Definition: nls.c:112
unsigned short USHORT
Definition: pedump.c:61
unsigned int ULONG
Definition: retypes.h:1
_Out_ PCPTABLEINFO CodePageTable
Definition: rtlfuncs.h:4113

Referenced by BestFit_FromNLS().