[MKHIVE/USETUP]
[reactos.git] / reactos / base / shell / cmd / locale.c
1 /*
2 * LOCALE.C - locale handling.
3 *
4 *
5 * History:
6 *
7 * 09-Jan-1999 (Eric Kohl)
8 * Started.
9 *
10 * 20-Jan-1999 (Eric Kohl)
11 * Unicode safe!
12 */
13
14 #include <precomp.h>
15
16
17 TCHAR cDateSeparator;
18 TCHAR cTimeSeparator;
19 TCHAR cThousandSeparator;
20 TCHAR cDecimalSeparator;
21 INT nDateFormat;
22 INT nTimeFormat;
23 INT nNumberGroups;
24
25
26 VOID InitLocale (VOID)
27 {
28 TCHAR szBuffer[256];
29
30 /* date settings */
31 GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDATE, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
32 cDateSeparator = szBuffer[0];
33 GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_IDATE | LOCALE_RETURN_NUMBER, (LPTSTR)&nDateFormat, sizeof(nDateFormat) / sizeof(TCHAR));
34
35 /* time settings */
36 GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STIME, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
37 cTimeSeparator = szBuffer[0];
38 GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITIME | LOCALE_RETURN_NUMBER, (LPTSTR)&nTimeFormat, sizeof(nTimeFormat) / sizeof(TCHAR));
39
40 /* number settings */
41 GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
42 cThousandSeparator = szBuffer[0];
43 GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
44 cDecimalSeparator = szBuffer[0];
45 GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SGROUPING, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
46 nNumberGroups = _ttoi(szBuffer);
47 #if 0
48 /* days of week */
49 for (i = 0; i < 7; i++)
50 {
51 GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SABBREVDAYNAME1 + i, szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]));
52 _tcscpy (aszDayNames[(i+1)%7], szBuffer); /* little hack */
53 }
54 #endif
55 }
56
57 /* Return date string including weekday. Used for $D in prompt and %DATE% */
58 LPTSTR
59 GetDateString(VOID)
60 {
61 static TCHAR szDate[32];
62 SYSTEMTIME t;
63 INT len;
64 GetLocalTime(&t);
65
66 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &t, _T("ddd"), szDate, sizeof szDate);
67 szDate[len - 1] = _T(' ');
68 FormatDate(&szDate[len], &t, TRUE);
69 return szDate;
70 }
71
72 /* Return time in hh:mm:ss.xx format. Used for $T in prompt and %TIME% */
73 LPTSTR
74 GetTimeString(VOID)
75 {
76 static TCHAR szTime[12];
77 SYSTEMTIME t;
78 GetLocalTime(&t);
79 _stprintf(szTime, _T("%2d%c%02d%c%02d%c%02d"),
80 t.wHour, cTimeSeparator, t.wMinute, cTimeSeparator,
81 t.wSecond, cDecimalSeparator, t.wMilliseconds / 10);
82 return szTime;
83 }