Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4921 | Serge | 1 | /*- |
2 | * Copyright (c) 2001 Alexey Zelkin |
||
3 | * Copyright (c) 1997 FreeBSD Inc. |
||
4 | * All rights reserved. |
||
5 | * |
||
6 | * Redistribution and use in source and binary forms, with or without |
||
7 | * modification, are permitted provided that the following conditions |
||
8 | * are met: |
||
9 | * 1. Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * 2. Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * |
||
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
||
16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
||
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
||
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
||
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
||
25 | * SUCH DAMAGE. |
||
26 | */ |
||
27 | |||
28 | #include |
||
29 | |||
30 | #include |
||
31 | |||
32 | #include "ldpart.h" |
||
33 | #include "timelocal.h" |
||
34 | |||
35 | static struct lc_time_T _time_locale; |
||
36 | static int _time_using_locale; |
||
37 | static char *time_locale_buf; |
||
38 | |||
39 | #define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *)) |
||
40 | |||
41 | static const struct lc_time_T _C_time_locale = { |
||
42 | { |
||
43 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
||
44 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
||
45 | }, { |
||
46 | "January", "February", "March", "April", "May", "June", |
||
47 | "July", "August", "September", "October", "November", "December" |
||
48 | }, { |
||
49 | "Sun", "Mon", "Tue", "Wed", |
||
50 | "Thu", "Fri", "Sat" |
||
51 | }, { |
||
52 | "Sunday", "Monday", "Tuesday", "Wednesday", |
||
53 | "Thursday", "Friday", "Saturday" |
||
54 | }, |
||
55 | |||
56 | /* X_fmt */ |
||
57 | "%H:%M:%S", |
||
58 | |||
59 | /* |
||
60 | * x_fmt |
||
61 | * Since the C language standard calls for |
||
62 | * "date, using locale's date format," anything goes. |
||
63 | * Using just numbers (as here) makes Quakers happier; |
||
64 | * it's also compatible with SVR4. |
||
65 | */ |
||
66 | "%m/%d/%y", |
||
67 | |||
68 | /* |
||
69 | * c_fmt |
||
70 | */ |
||
71 | "%a %b %e %H:%M:%S %Y", |
||
72 | |||
73 | /* am pm */ |
||
74 | { "AM", "PM" }, |
||
75 | |||
76 | /* date_fmt */ |
||
77 | "%a %b %e %H:%M:%S %Z %Y", |
||
78 | |||
79 | /* alt_month |
||
80 | * Standalone months forms for %OB |
||
81 | */ |
||
82 | { |
||
83 | "January", "February", "March", "April", "May", "June", |
||
84 | "July", "August", "September", "October", "November", "December" |
||
85 | }, |
||
86 | |||
87 | /* md_order |
||
88 | * Month / day order in dates |
||
89 | */ |
||
90 | "md", |
||
91 | |||
92 | /* ampm_fmt |
||
93 | * To determine 12-hour clock format time (empty, if N/A) |
||
94 | */ |
||
95 | "%I:%M:%S %p", |
||
96 | |||
97 | /* era |
||
98 | * Era. This and the following entries are used if the alternative |
||
99 | * date format is specified in strftime |
||
100 | */ |
||
101 | "", |
||
102 | |||
103 | /* era_d_fmt |
||
104 | * Era date format used with the %Ex |
||
105 | */ |
||
106 | "", |
||
107 | |||
108 | /* era_d_t_fmt |
||
109 | * Era date/time format (%Ec) |
||
110 | */ |
||
111 | "", |
||
112 | |||
113 | /* era_t_fmt |
||
114 | * Era time format (%EX) |
||
115 | */ |
||
116 | "", |
||
117 | |||
118 | /* alt_digits |
||
119 | * Alternate digits used if %O format prefix is specified |
||
120 | */ |
||
121 | "" |
||
122 | #ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
||
123 | , "ASCII", /* codeset */ |
||
124 | { |
||
125 | L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", |
||
126 | L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" |
||
127 | }, { |
||
128 | L"January", L"February", L"March", L"April", L"May", L"June", |
||
129 | L"July", L"August", L"September", L"October", L"November", |
||
130 | L"December" |
||
131 | }, { |
||
132 | L"Sun", L"Mon", L"Tue", L"Wed", |
||
133 | L"Thu", L"Fri", L"Sat" |
||
134 | }, { |
||
135 | L"Sunday", L"Monday", L"Tuesday", L"Wednesday", |
||
136 | L"Thursday", L"Friday", L"Saturday" |
||
137 | }, |
||
138 | L"%H:%M:%S", |
||
139 | L"%m/%d/%y", |
||
140 | L"%a %b %e %H:%M:%S %Y", |
||
141 | { L"AM", L"PM" }, |
||
142 | L"%a %b %e %H:%M:%S %Z %Y", |
||
143 | L"%I:%M:%S %p", |
||
144 | L"", |
||
145 | L"", |
||
146 | L"", |
||
147 | L"", |
||
148 | L"" |
||
149 | #endif |
||
150 | }; |
||
151 | |||
152 | struct lc_time_T * |
||
153 | __get_current_time_locale(void) { |
||
154 | return (_time_using_locale |
||
155 | ? &_time_locale |
||
156 | : (struct lc_time_T *)&_C_time_locale); |
||
157 | } |
||
158 | |||
159 | int |
||
160 | __time_load_locale(const char *name, void *f_wctomb, const char *charset) { |
||
161 | |||
162 | int ret; |
||
163 | |||
164 | #ifdef __CYGWIN__ |
||
165 | extern int __set_lc_time_from_win (const char *, |
||
166 | const struct lc_time_T *, |
||
167 | struct lc_time_T *, |
||
168 | char **, void *, const char *); |
||
169 | int old_time_using_locale = _time_using_locale; |
||
170 | _time_using_locale = 0; |
||
171 | ret = __set_lc_time_from_win (name, &_C_time_locale, &_time_locale, |
||
172 | &time_locale_buf, f_wctomb, charset); |
||
173 | /* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */ |
||
174 | if (ret < 0) |
||
175 | _time_using_locale = old_time_using_locale; |
||
176 | else |
||
177 | { |
||
178 | _time_using_locale = ret; |
||
179 | ret = 0; |
||
180 | } |
||
181 | #else |
||
182 | ret = __part_load_locale(name, &_time_using_locale, |
||
183 | time_locale_buf, "LC_TIME", |
||
184 | LCTIME_SIZE, LCTIME_SIZE, |
||
185 | (const char **)&_time_locale); |
||
186 | #endif |
||
187 | return (ret); |
||
188 | }> |