-
Notifications
You must be signed in to change notification settings - Fork 0
/
locale.c
180 lines (156 loc) · 4.52 KB
/
locale.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
Copyright 2012-2014 Infinitycoding all rights reserved
This file is part of the mercury c-library.
The mercury c-library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
The mercury c-library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the mercury c-library. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @author Simon Diepold <simon.diepold@infinitycoding.de>
*/
#include <locale.h>
#include <limits.h>
#include <string.h>
const struct lconv _LC_c =
{
.decimal_point = ".",
.thousands_sep = "",
.grouping = "",
.int_curr_symbol = "",
.currency_symbol = "",
.mon_decimal_point = "",
.mon_thousands_sep = "",
.mon_grouping = "",
.positive_sign = "",
.negative_sign = "0",
.frac_digits = SCHAR_MAX,
.p_cs_precedes = SCHAR_MAX,
.n_cs_precedes = SCHAR_MAX,
.p_sep_by_space = SCHAR_MAX,
.n_sep_by_space = SCHAR_MAX,
.p_sign_posn = SCHAR_MAX,
.n_sign_posn = SCHAR_MAX,
.int_frac_digits = SCHAR_MAX,
.int_p_cs_precedes = SCHAR_MAX,
.int_n_cs_precedes = SCHAR_MAX,
.int_p_sep_by_space = SCHAR_MAX,
.int_n_sep_by_space = SCHAR_MAX,
.int_p_sign_posn = SCHAR_MAX,
.int_n_sign_posn = SCHAR_MAX
};
const struct lconv _LC_en_US =
{
.decimal_point = ".",
.thousands_sep = ",",
.grouping = "",
.int_curr_symbol = "USD",
.currency_symbol = "$",
.mon_decimal_point = ".",
.mon_thousands_sep = ",",
.mon_grouping = "",
.positive_sign = "",
.negative_sign = "-",
.frac_digits = SCHAR_MAX,
.p_cs_precedes = 1,
.n_cs_precedes = 1,
.p_sep_by_space = SCHAR_MAX,
.n_sep_by_space = SCHAR_MAX,
.p_sign_posn = SCHAR_MAX,
.n_sign_posn = SCHAR_MAX,
.int_frac_digits = SCHAR_MAX,
.int_p_cs_precedes = SCHAR_MAX,
.int_n_cs_precedes = SCHAR_MAX,
.int_p_sep_by_space = SCHAR_MAX,
.int_n_sep_by_space = SCHAR_MAX,
.int_p_sign_posn = SCHAR_MAX,
.int_n_sign_posn = SCHAR_MAX
};
struct lconv _LC_STATE =
{
.decimal_point = ".",
.thousands_sep = ",",
.grouping = "",
.int_curr_symbol = "USD",
.currency_symbol = "$",
.mon_decimal_point = ".",
.mon_thousands_sep = ",",
.mon_grouping = "",
.positive_sign = "",
.negative_sign = "-",
.frac_digits = SCHAR_MAX,
.p_cs_precedes = 1,
.n_cs_precedes = 1,
.p_sep_by_space = SCHAR_MAX,
.n_sep_by_space = SCHAR_MAX,
.p_sign_posn = SCHAR_MAX,
.n_sign_posn = SCHAR_MAX,
.int_frac_digits = SCHAR_MAX,
.int_p_cs_precedes = SCHAR_MAX,
.int_n_cs_precedes = SCHAR_MAX,
.int_p_sep_by_space = SCHAR_MAX,
.int_n_sep_by_space = SCHAR_MAX,
.int_p_sign_posn = SCHAR_MAX,
.int_n_sign_posn = SCHAR_MAX
};
const char *setlocale (int category, const char* locale)
{
const struct lconv *mod;
const char *ret;
if(strcmp(locale,""))
{
mod = &DEFAULT_LANG;
ret = DEFAULT_LANG_NAME;
}
else if(strcmp(locale,"C"))
{
mod = &_LC_c;
ret = "C";
}
else if(strcmp(locale,"en_US"))
{
mod = &_LC_en_US;
ret = "English_United States.1252";
}
else
return NULL;
switch(category)
{
case LC_ALL:
_LC_STATE = *mod;
break;
case LC_MONETARY:
_LC_STATE.mon_decimal_point = mod->mon_decimal_point;
_LC_STATE.mon_thousands_sep = mod->mon_thousands_sep;
_LC_STATE.mon_grouping = mod->mon_grouping;
break;
case LC_NUMERIC:
_LC_STATE.decimal_point = mod->decimal_point;
_LC_STATE.thousands_sep = mod->thousands_sep;
_LC_STATE.grouping = mod->grouping;
_LC_STATE.positive_sign = mod->positive_sign;
_LC_STATE.negative_sign = mod->negative_sign;
break;
//Todo: LC_COLLATE, LC_CTYPE, LC_TIME
case LC_COLLATE:
break;
case LC_CTYPE:
break;
case LC_TIME:
break;
default:
return NULL;
break;
}
return ret;
}
struct lconv *localeconv (void)
{
return &_LC_STATE;
}