Implemented:
[reactos.git] / reactos / lib / ntdll / rtl / nls.c
1 /* $Id: nls.c,v 1.4 2000/05/25 15:52:53 ekohl Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: lib/ntdll/rtl/nls.c
6 * PURPOSE: National Language Support (NLS) functions
7 * UPDATE HISTORY:
8 * 20/08/99 Created by Emanuele Aliberti
9 * 10/11/99 Added translation functions.
10 *
11 * NOTE:
12 * Multi-byte code pages are not supported yet. Even single-byte code
13 * pages are not supported properly. Only stupid CHAR->WCHAR and
14 * WCHAR->CHAR (Attention: data loss!!!) translation is done.
15 *
16 * TODO:
17 * 1) Implement code to initialize the translation tables.
18 * 2) Use fixed translation table for translation.
19 * 3) Add loading of translation tables (NLS files).
20 * 4) Implement unicode upcase and downcase handling.
21 * 5) Add multi-byte translation code.
22 */
23
24 #include <ddk/ntddk.h>
25 //#include <internal/nls.h>
26
27
28 BOOLEAN
29 NlsMbCodePageTag = FALSE;
30
31 BOOLEAN
32 NlsMbOemCodePageTag = FALSE;
33
34 BYTE
35 NlsLeadByteInfo = 0; /* ? */
36
37 USHORT
38 NlsOemLeadByteInfo = 0;
39
40 USHORT
41 NlsAnsiCodePage = 0;
42
43 USHORT
44 NlsOemCodePage = 0; /* not exported */
45
46 #if 0
47 PWCHAR NlsAnsiToUnicodeTable = NULL;
48 PWCHAR NlsOemToUnicodeTable = NULL;
49
50 PCHAR NlsUnicodeToAnsiTable = NULL;
51 PCHAR NlsUnicodeToOemTable = NULL;
52
53 PWCHAR NlsUnicodeUpcaseTable = NULL;
54 PWCHAR NlsUnicodeLowercaseTable = NULL;
55 #endif
56
57
58 /* FUNCTIONS *****************************************************************/
59
60 /*
61 * Missing functions:
62 * RtlInitCodePageTable
63 * RtlInitNlsTables
64 * RtlResetRtlTranslations
65 */
66
67 /*
68 * RtlConsoleMultiByteToUnicodeN@24
69 */
70
71 NTSTATUS
72 STDCALL
73 RtlCustomCPToUnicodeN (
74 PRTL_NLS_DATA NlsData,
75 PWCHAR UnicodeString,
76 ULONG UnicodeSize,
77 PULONG ResultSize,
78 PCHAR CustomString,
79 ULONG CustomSize)
80 {
81 ULONG Size = 0;
82 ULONG i;
83
84 if (NlsData->DbcsFlag == FALSE)
85 {
86 /* single-byte code page */
87 if (CustomSize > (UnicodeSize / sizeof(WCHAR)))
88 Size = UnicodeSize / sizeof(WCHAR);
89 else
90 Size = CustomSize;
91
92 if (ResultSize != NULL)
93 *ResultSize = Size * sizeof(WCHAR);
94
95 for (i = 0; i < Size; i++)
96 {
97 *UnicodeString = NlsData->MultiByteToUnicode[(int)*CustomString];
98 UnicodeString++;
99 CustomString++;
100 }
101 }
102 else
103 {
104 /* multi-byte code page */
105 /* FIXME */
106
107 }
108
109 return STATUS_SUCCESS;
110 }
111
112
113 VOID
114 STDCALL
115 RtlGetDefaultCodePage (
116 PUSHORT AnsiCodePage,
117 PUSHORT OemCodePage
118 )
119 {
120 *AnsiCodePage = NlsAnsiCodePage;
121 *OemCodePage = NlsOemCodePage;
122 }
123
124
125 NTSTATUS
126 STDCALL
127 RtlMultiByteToUnicodeN (
128 PWCHAR UnicodeString,
129 ULONG UnicodeSize,
130 PULONG ResultSize,
131 PCHAR MbString,
132 ULONG MbSize
133 )
134 {
135 ULONG Size = 0;
136 ULONG i;
137
138 if (NlsMbCodePageTag == FALSE)
139 {
140 /* single-byte code page */
141 if (MbSize > (UnicodeSize / sizeof(WCHAR)))
142 Size = UnicodeSize / sizeof(WCHAR);
143 else
144 Size = MbSize;
145
146 if (ResultSize != NULL)
147 *ResultSize = Size * sizeof(WCHAR);
148
149 for (i = 0; i < Size; i++)
150 {
151 *UnicodeString = *MbString;
152 #if 0
153 *UnicodeString = NlsAnsiToUnicodeTable[*MbString];
154 #endif
155
156 UnicodeString++;
157 MbString++;
158 }
159 }
160 else
161 {
162 /* multi-byte code page */
163 /* FIXME */
164
165 }
166
167 return STATUS_SUCCESS;
168 }
169
170
171 NTSTATUS
172 STDCALL
173 RtlMultiByteToUnicodeSize (
174 PULONG UnicodeSize,
175 PCHAR MbString,
176 ULONG MbSize
177 )
178 {
179 if (NlsMbCodePageTag == FALSE)
180 {
181 /* single-byte code page */
182 *UnicodeSize = MbSize * sizeof (WCHAR);
183 }
184 else
185 {
186 /* multi-byte code page */
187 /* FIXME */
188
189 }
190
191 return STATUS_SUCCESS;
192 }
193
194
195 NTSTATUS
196 STDCALL
197 RtlOemToUnicodeN (
198 PWCHAR UnicodeString,
199 ULONG UnicodeSize,
200 PULONG ResultSize,
201 PCHAR OemString,
202 ULONG OemSize
203 )
204 {
205 ULONG Size = 0;
206 ULONG i;
207
208 if (NlsMbOemCodePageTag == FALSE)
209 {
210 /* single-byte code page */
211 if (OemSize > (UnicodeSize / sizeof(WCHAR)))
212 Size = UnicodeSize / sizeof(WCHAR);
213 else
214 Size = OemSize;
215
216 if (ResultSize != NULL)
217 *ResultSize = Size * sizeof(WCHAR);
218
219 for (i = 0; i < Size; i++)
220 {
221 *UnicodeString = *OemString;
222 #if 0
223 *UnicodeString = NlsOemToUnicodeTable[*OemString];
224 #endif
225
226 UnicodeString++;
227 OemString++;
228 };
229 }
230 else
231 {
232 /* multi-byte code page */
233 /* FIXME */
234
235 }
236
237 return STATUS_SUCCESS;
238 }
239
240
241 NTSTATUS
242 STDCALL
243 RtlUnicodeToCustomCPN (
244 PRTL_NLS_DATA NlsData,
245 PCHAR CustomString,
246 ULONG CustomSize,
247 PULONG ResultSize,
248 PWCHAR UnicodeString,
249 ULONG UnicodeSize
250 )
251 {
252 ULONG Size = 0;
253 ULONG i;
254
255 if (NlsData->DbcsFlag == 0)
256 {
257 /* single-byte code page */
258 if (UnicodeSize > (CustomSize * sizeof(WCHAR)))
259 Size = CustomSize;
260 else
261 Size = UnicodeSize / sizeof(WCHAR);
262
263 if (ResultSize != NULL)
264 *ResultSize = Size;
265
266 for (i = 0; i < Size; i++)
267 {
268 *CustomString = NlsData->UnicodeToMultiByte[*UnicodeString];
269 CustomString++;
270 UnicodeString++;
271 }
272 }
273 else
274 {
275 /* multi-byte code page */
276 /* FIXME */
277
278 }
279
280 return STATUS_SUCCESS;
281 }
282
283
284 NTSTATUS
285 STDCALL
286 RtlUnicodeToMultiByteN (
287 PCHAR MbString,
288 ULONG MbSize,
289 PULONG ResultSize,
290 PWCHAR UnicodeString,
291 ULONG UnicodeSize
292 )
293 {
294 ULONG Size = 0;
295 ULONG i;
296
297 if (NlsMbCodePageTag == FALSE)
298 {
299 /* single-byte code page */
300 if (UnicodeSize > (MbSize * sizeof(WCHAR)))
301 Size = MbSize;
302 else
303 Size = UnicodeSize / sizeof(WCHAR);
304
305 if (ResultSize != NULL)
306 *ResultSize = Size;
307
308 for (i = 0; i < Size; i++)
309 {
310 *MbString = *UnicodeString;
311 #if 0
312 *MbString = UnicodeToAnsiTable[*UnicodeString];
313 #endif
314
315 MbString++;
316 UnicodeString++;
317 }
318 }
319 else
320 {
321 /* multi-byte code page */
322 /* FIXME */
323
324 }
325
326 return STATUS_SUCCESS;
327 }
328
329
330 NTSTATUS
331 STDCALL
332 RtlUnicodeToMultiByteSize (
333 PULONG MbSize,
334 PWCHAR UnicodeString,
335 ULONG UnicodeSize
336 )
337 {
338 if (NlsMbCodePageTag == FALSE)
339 {
340 /* single-byte code page */
341 *MbSize = UnicodeSize / sizeof (WCHAR);
342 }
343 else
344 {
345 /* multi-byte code page */
346 /* FIXME */
347
348 }
349
350 return STATUS_SUCCESS;
351 }
352
353
354 NTSTATUS
355 STDCALL
356 RtlUnicodeToOemN (
357 PCHAR OemString,
358 ULONG OemSize,
359 PULONG ResultSize,
360 PWCHAR UnicodeString,
361 ULONG UnicodeSize
362 )
363 {
364 ULONG Size = 0;
365 ULONG i;
366
367 if (NlsMbOemCodePageTag == FALSE)
368 {
369 /* single-byte code page */
370 if (UnicodeSize > (OemSize * sizeof(WCHAR)))
371 Size = OemSize;
372 else
373 Size = UnicodeSize / sizeof(WCHAR);
374
375 if (ResultSize != NULL)
376 *ResultSize = Size;
377
378 for (i = 0; i < Size; i++)
379 {
380 *OemString = *UnicodeString;
381 #if 0
382 *OemString = UnicodeToOemTable[*UnicodeString];
383 #endif
384
385 OemString++;
386 UnicodeString++;
387 };
388 }
389 else
390 {
391 /* multi-byte code page */
392 /* FIXME */
393
394 }
395
396 return STATUS_SUCCESS;
397 }
398
399
400 NTSTATUS
401 STDCALL
402 RtlUpcaseUnicodeToCustomCPN (
403 PRTL_NLS_DATA NlsData,
404 PCHAR CustomString,
405 ULONG CustomSize,
406 PULONG ResultSize,
407 PWCHAR UnicodeString,
408 ULONG UnicodeSize
409 )
410 {
411 WCHAR UpcaseChar;
412 ULONG Size = 0;
413 ULONG i;
414
415 if (NlsData->DbcsFlag == 0)
416 {
417 /* single-byte code page */
418 if (UnicodeSize > (CustomSize * sizeof(WCHAR)))
419 Size = CustomSize;
420 else
421 Size = UnicodeSize / sizeof(WCHAR);
422
423 if (ResultSize != NULL)
424 *ResultSize = Size;
425
426 for (i = 0; i < Size; i++)
427 {
428 *CustomString = NlsData->UnicodeToMultiByte[*UnicodeString];
429 #if 0
430 UpcaseChar = NlsUnicodeUpcaseTable[*UnicodeString];
431 *CustomString = NlsData->UnicodeToMultiByte[UpcaseChar];
432 #endif
433 CustomString++;
434 UnicodeString++;
435 }
436 }
437 else
438 {
439 /* multi-byte code page */
440 /* FIXME */
441
442 }
443
444 return STATUS_SUCCESS;
445 }
446
447
448 NTSTATUS
449 STDCALL
450 RtlUpcaseUnicodeToMultiByteN (
451 PCHAR MbString,
452 ULONG MbSize,
453 PULONG ResultSize,
454 PWCHAR UnicodeString,
455 ULONG UnicodeSize
456 )
457 {
458 WCHAR UpcaseChar;
459 ULONG Size = 0;
460 ULONG i;
461
462 if (NLS_MB_CODE_PAGE_TAG == FALSE)
463 {
464 /* single-byte code page */
465 if (UnicodeSize > (MbSize * sizeof(WCHAR)))
466 Size = MbSize;
467 else
468 Size = UnicodeSize / sizeof(WCHAR);
469
470 if (ResultSize != NULL)
471 *ResultSize = Size;
472
473 for (i = 0; i < Size; i++)
474 {
475 *MbString = *UnicodeString;
476 #if 0
477 UpcaseChar = NlsUnicodeUpcaseTable[*UnicodeString];
478 *MbString = NlsUnicodeToAnsiTable[UpcaseChar];
479 #endif
480
481 MbString++;
482 UnicodeString++;
483 }
484 }
485 else
486 {
487 /* multi-byte code page */
488 /* FIXME */
489
490 }
491
492 return STATUS_SUCCESS;
493 }
494
495
496 NTSTATUS
497 STDCALL
498 RtlUpcaseUnicodeToOemN (
499 PCHAR OemString,
500 ULONG OemSize,
501 PULONG ResultSize,
502 PWCHAR UnicodeString,
503 ULONG UnicodeSize
504 )
505 {
506 WCHAR UpcaseChar;
507 ULONG Size = 0;
508 ULONG i;
509
510 if (NLS_MB_OEM_CODE_PAGE_TAG == FALSE)
511 {
512 /* single-byte code page */
513 if (UnicodeSize > (OemSize * sizeof(WCHAR)))
514 Size = OemSize;
515 else
516 Size = UnicodeSize / sizeof(WCHAR);
517
518 if (ResultSize != NULL)
519 *ResultSize = Size;
520
521 for (i = 0; i < Size; i++)
522 {
523 *OemString = *UnicodeString;
524 #if 0
525 UpcaseChar = NlsUnicodeUpcaseTable[*UnicodeString];
526 *OemString = UnicodeToOemTable[UpcaseChar];
527 #endif
528
529 OemString++;
530 UnicodeString++;
531 }
532 }
533 else
534 {
535 /* multi-byte code page */
536 /* FIXME */
537
538 }
539
540 return STATUS_SUCCESS;
541 }
542
543 /* EOF */