update for HEAD-2003091401
[reactos.git] / lib / msvcrt / locale / locale.c
1 #include <msvcrt/stdio.h>
2 #include <msvcrt/locale.h>
3 #include <msvcrt/string.h>
4 #include <limits.h>
5
6
7 int _current_category;  /* used by setlocale */
8 const char *_current_locale;
9
10 int parse_locale(char *locale, char *lang, char *country, char *code_page);
11
12 /*
13  * @unimplemented
14  */
15 char *setlocale(int category, const char *locale)
16 {
17         char lang[100];
18         char country[100];
19         char code_page[100];
20         if (NULL != locale) {
21                 parse_locale((char *)locale,lang,country,code_page);
22         }
23
24         //printf("%s %s %s %s\n",locale,lang,country,code_page);
25
26
27         switch ( category )
28         {
29                 case LC_COLLATE:
30                 break;
31                 case LC_CTYPE:
32                 break;
33                 case LC_MONETARY:
34                 break;
35                 case LC_NUMERIC:
36                 break;
37                 case LC_TIME:
38                 break;
39                 case LC_ALL:
40                 break;
41                 default:
42                 break;
43         }
44
45         return "C";
46
47 }
48
49 /*
50
51 locale  "lang[_country[.code_page]]"
52             | ".code_page"
53             | ""
54             | NULL
55             
56 */
57 int parse_locale(char *locale, char *lang, char *country, char *code_page)
58 {
59         while ( *locale != 0 && *locale != '.' && *locale != '_' )
60         {
61                 *lang = *locale;
62                 lang++;
63                 locale++;
64         }
65         *lang = 0;
66         if ( *locale == '_' ) {
67                 locale++;
68                 while ( *locale != 0 && *locale != '.' )
69                 {
70                         *country = *locale;
71                         country++;
72                         locale++;
73                 }
74         }
75         *country = 0;
76         
77         
78         if ( *locale == '.' ) {
79                 locale++;
80                 while ( *locale != 0 && *locale != '.' )
81                 {
82                         *code_page = *locale;
83                         code_page++;
84                         locale++;
85                 }
86         }
87         
88         *code_page = 0;
89         return 0;       
90 }
91
92 const struct map_lcid2str {
93         short            langid;
94         const char      *langname;
95         const char      *country;
96 } languages[]={
97         {0x0409,"English", "United States"},
98         {0x0809,"English", "United Kingdom"},
99         {0x0000,"Unknown", "Unknown"}
100     
101 };
102
103 const struct map_cntr {
104         const char *abrev;
105         const char  *country;
106 } abrev[] = {
107         {"britain", "united kingdom"},
108         {"england", "united kingdom"},
109         {"gbr", "united kingdom"},
110         {"great britain", "united kingdom"},
111         {"uk", "united kingdom"},
112         {"united kingdom", "united kingdom"},
113         {"united-kingdom", "united kingdom"},
114         {"america", "united states" },
115         {"united states", "united states"},
116         {"united-states", "united states"},
117         {"us", "united states"},
118         {"usa" "united states"}
119 };
120
121
122 struct lconv _lconv = {
123 ".",   // decimal_point
124 ",",   // thousands_sep
125 "",    // grouping;
126 "DOL", // int_curr_symbol
127 "$",   // currency_symbol
128 ".",   // mon_decimal_point
129 ",",   // mon_thousands_sep
130 "",    // mon_grouping;
131 "+",   // positive_sign
132 "-",   // negative_sign
133 127,     // int_frac_digits
134 127,     // frac_digits
135 127,     // p_cs_precedes
136 127,     // p_sep_by_space
137 127,     // n_cs_precedes
138 127,     // n_sep_by_space
139 127,     // p_sign_posn;
140 127      // n_sign_posn;
141 };
142
143 /*
144  * @implemented
145  */
146 struct lconv *localeconv(void)
147 {
148   return (struct lconv *) &_lconv;
149 }