]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/config/locale/gnu/time_members.cc
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / config / locale / gnu / time_members.cc
1 // std::time_get, std::time_put implementation, GNU version -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 //
32 // ISO C++ 14882: 22.2.5.1.2 - time_get virtual functions
33 // ISO C++ 14882: 22.2.5.3.2 - time_put virtual functions
34 //
35
36 // Written by Benjamin Kosnik <bkoz@redhat.com>
37
38 #include <locale>
39 #include <bits/c++locale_internal.h>
40
41 _GLIBCXX_BEGIN_NAMESPACE(std)
42
43   template<>
44     void
45     __timepunct<char>::
46     _M_put(char* __s, size_t __maxlen, const char* __format, 
47            const tm* __tm) const
48     {
49 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
50       const size_t __len = __strftime_l(__s, __maxlen, __format, __tm,
51                                         _M_c_locale_timepunct);
52 #else
53       char* __old = setlocale(LC_ALL, NULL);
54       const size_t __llen = strlen(__old) + 1;  
55       char* __sav = new char[__llen];
56       memcpy(__sav, __old, __llen);
57       setlocale(LC_ALL, _M_name_timepunct);
58       const size_t __len = strftime(__s, __maxlen, __format, __tm);
59       setlocale(LC_ALL, __sav);
60       delete [] __sav;
61 #endif
62       // Make sure __s is null terminated.
63       if (__len == 0)
64         __s[0] = '\0';
65     }
66
67   template<> 
68     void
69     __timepunct<char>::_M_initialize_timepunct(__c_locale __cloc)
70     {
71       if (!_M_data)
72         _M_data = new __timepunct_cache<char>;
73
74       if (!__cloc)
75         {
76           // "C" locale
77           _M_c_locale_timepunct = _S_get_c_locale();
78
79           _M_data->_M_date_format = "%m/%d/%y";
80           _M_data->_M_date_era_format = "%m/%d/%y";
81           _M_data->_M_time_format = "%H:%M:%S";
82           _M_data->_M_time_era_format = "%H:%M:%S";
83           _M_data->_M_date_time_format = "";
84           _M_data->_M_date_time_era_format = "";
85           _M_data->_M_am = "AM";
86           _M_data->_M_pm = "PM";
87           _M_data->_M_am_pm_format = "";
88
89           // Day names, starting with "C"'s Sunday.
90           _M_data->_M_day1 = "Sunday";
91           _M_data->_M_day2 = "Monday";
92           _M_data->_M_day3 = "Tuesday";
93           _M_data->_M_day4 = "Wednesday";
94           _M_data->_M_day5 = "Thursday";
95           _M_data->_M_day6 = "Friday";
96           _M_data->_M_day7 = "Saturday";
97
98           // Abbreviated day names, starting with "C"'s Sun.
99           _M_data->_M_aday1 = "Sun";
100           _M_data->_M_aday2 = "Mon";
101           _M_data->_M_aday3 = "Tue";
102           _M_data->_M_aday4 = "Wed";
103           _M_data->_M_aday5 = "Thu";
104           _M_data->_M_aday6 = "Fri";
105           _M_data->_M_aday7 = "Sat";
106
107           // Month names, starting with "C"'s January.
108           _M_data->_M_month01 = "January";
109           _M_data->_M_month02 = "February";
110           _M_data->_M_month03 = "March";
111           _M_data->_M_month04 = "April";
112           _M_data->_M_month05 = "May";
113           _M_data->_M_month06 = "June";
114           _M_data->_M_month07 = "July";
115           _M_data->_M_month08 = "August";
116           _M_data->_M_month09 = "September";
117           _M_data->_M_month10 = "October";
118           _M_data->_M_month11 = "November";
119           _M_data->_M_month12 = "December";
120
121           // Abbreviated month names, starting with "C"'s Jan.
122           _M_data->_M_amonth01 = "Jan";
123           _M_data->_M_amonth02 = "Feb";
124           _M_data->_M_amonth03 = "Mar";
125           _M_data->_M_amonth04 = "Apr";
126           _M_data->_M_amonth05 = "May";
127           _M_data->_M_amonth06 = "Jun";
128           _M_data->_M_amonth07 = "Jul";
129           _M_data->_M_amonth08 = "Aug";
130           _M_data->_M_amonth09 = "Sep";
131           _M_data->_M_amonth10 = "Oct";
132           _M_data->_M_amonth11 = "Nov";
133           _M_data->_M_amonth12 = "Dec";
134         }
135       else
136         {
137           _M_c_locale_timepunct = _S_clone_c_locale(__cloc); 
138
139           _M_data->_M_date_format = __nl_langinfo_l(D_FMT, __cloc);
140           _M_data->_M_date_era_format = __nl_langinfo_l(ERA_D_FMT, __cloc);
141           _M_data->_M_time_format = __nl_langinfo_l(T_FMT, __cloc);
142           _M_data->_M_time_era_format = __nl_langinfo_l(ERA_T_FMT, __cloc);
143           _M_data->_M_date_time_format = __nl_langinfo_l(D_T_FMT, __cloc);
144           _M_data->_M_date_time_era_format = __nl_langinfo_l(ERA_D_T_FMT,
145                                                              __cloc);
146           _M_data->_M_am = __nl_langinfo_l(AM_STR, __cloc);
147           _M_data->_M_pm = __nl_langinfo_l(PM_STR, __cloc);
148           _M_data->_M_am_pm_format = __nl_langinfo_l(T_FMT_AMPM, __cloc);
149
150           // Day names, starting with "C"'s Sunday.
151           _M_data->_M_day1 = __nl_langinfo_l(DAY_1, __cloc);
152           _M_data->_M_day2 = __nl_langinfo_l(DAY_2, __cloc);
153           _M_data->_M_day3 = __nl_langinfo_l(DAY_3, __cloc);
154           _M_data->_M_day4 = __nl_langinfo_l(DAY_4, __cloc);
155           _M_data->_M_day5 = __nl_langinfo_l(DAY_5, __cloc);
156           _M_data->_M_day6 = __nl_langinfo_l(DAY_6, __cloc);
157           _M_data->_M_day7 = __nl_langinfo_l(DAY_7, __cloc);
158
159           // Abbreviated day names, starting with "C"'s Sun.
160           _M_data->_M_aday1 = __nl_langinfo_l(ABDAY_1, __cloc);
161           _M_data->_M_aday2 = __nl_langinfo_l(ABDAY_2, __cloc);
162           _M_data->_M_aday3 = __nl_langinfo_l(ABDAY_3, __cloc);
163           _M_data->_M_aday4 = __nl_langinfo_l(ABDAY_4, __cloc);
164           _M_data->_M_aday5 = __nl_langinfo_l(ABDAY_5, __cloc);
165           _M_data->_M_aday6 = __nl_langinfo_l(ABDAY_6, __cloc);
166           _M_data->_M_aday7 = __nl_langinfo_l(ABDAY_7, __cloc);
167
168           // Month names, starting with "C"'s January.
169           _M_data->_M_month01 = __nl_langinfo_l(MON_1, __cloc);
170           _M_data->_M_month02 = __nl_langinfo_l(MON_2, __cloc);
171           _M_data->_M_month03 = __nl_langinfo_l(MON_3, __cloc);
172           _M_data->_M_month04 = __nl_langinfo_l(MON_4, __cloc);
173           _M_data->_M_month05 = __nl_langinfo_l(MON_5, __cloc);
174           _M_data->_M_month06 = __nl_langinfo_l(MON_6, __cloc);
175           _M_data->_M_month07 = __nl_langinfo_l(MON_7, __cloc);
176           _M_data->_M_month08 = __nl_langinfo_l(MON_8, __cloc);
177           _M_data->_M_month09 = __nl_langinfo_l(MON_9, __cloc);
178           _M_data->_M_month10 = __nl_langinfo_l(MON_10, __cloc);
179           _M_data->_M_month11 = __nl_langinfo_l(MON_11, __cloc);
180           _M_data->_M_month12 = __nl_langinfo_l(MON_12, __cloc);
181
182           // Abbreviated month names, starting with "C"'s Jan.
183           _M_data->_M_amonth01 = __nl_langinfo_l(ABMON_1, __cloc);
184           _M_data->_M_amonth02 = __nl_langinfo_l(ABMON_2, __cloc);
185           _M_data->_M_amonth03 = __nl_langinfo_l(ABMON_3, __cloc);
186           _M_data->_M_amonth04 = __nl_langinfo_l(ABMON_4, __cloc);
187           _M_data->_M_amonth05 = __nl_langinfo_l(ABMON_5, __cloc);
188           _M_data->_M_amonth06 = __nl_langinfo_l(ABMON_6, __cloc);
189           _M_data->_M_amonth07 = __nl_langinfo_l(ABMON_7, __cloc);
190           _M_data->_M_amonth08 = __nl_langinfo_l(ABMON_8, __cloc);
191           _M_data->_M_amonth09 = __nl_langinfo_l(ABMON_9, __cloc);
192           _M_data->_M_amonth10 = __nl_langinfo_l(ABMON_10, __cloc);
193           _M_data->_M_amonth11 = __nl_langinfo_l(ABMON_11, __cloc);
194           _M_data->_M_amonth12 = __nl_langinfo_l(ABMON_12, __cloc);
195         }
196     }
197
198 #ifdef _GLIBCXX_USE_WCHAR_T
199   template<>
200     void
201     __timepunct<wchar_t>::
202     _M_put(wchar_t* __s, size_t __maxlen, const wchar_t* __format, 
203            const tm* __tm) const
204     {
205 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
206       const size_t __len = __wcsftime_l(__s, __maxlen, __format, __tm,
207                                         _M_c_locale_timepunct);
208 #else
209       char* __old = setlocale(LC_ALL, NULL);
210       const size_t __llen = strlen(__old) + 1;
211       char* __sav = new char[__llen];
212       memcpy(__sav, __old, __llen);
213       setlocale(LC_ALL, _M_name_timepunct);
214       const size_t __len = wcsftime(__s, __maxlen, __format, __tm);
215       setlocale(LC_ALL, __sav);
216       delete [] __sav;
217 #endif
218       // Make sure __s is null terminated.
219       if (__len == 0)
220         __s[0] = L'\0';
221     }
222
223   template<> 
224     void
225     __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale __cloc)
226     {
227       if (!_M_data)
228         _M_data = new __timepunct_cache<wchar_t>;
229
230       if (!__cloc)
231         {
232           // "C" locale
233           _M_c_locale_timepunct = _S_get_c_locale();
234
235           _M_data->_M_date_format = L"%m/%d/%y";
236           _M_data->_M_date_era_format = L"%m/%d/%y";
237           _M_data->_M_time_format = L"%H:%M:%S";
238           _M_data->_M_time_era_format = L"%H:%M:%S";
239           _M_data->_M_date_time_format = L"";
240           _M_data->_M_date_time_era_format = L"";
241           _M_data->_M_am = L"AM";
242           _M_data->_M_pm = L"PM";
243           _M_data->_M_am_pm_format = L"";
244
245           // Day names, starting with "C"'s Sunday.
246           _M_data->_M_day1 = L"Sunday";
247           _M_data->_M_day2 = L"Monday";
248           _M_data->_M_day3 = L"Tuesday";
249           _M_data->_M_day4 = L"Wednesday";
250           _M_data->_M_day5 = L"Thursday";
251           _M_data->_M_day6 = L"Friday";
252           _M_data->_M_day7 = L"Saturday";
253
254           // Abbreviated day names, starting with "C"'s Sun.
255           _M_data->_M_aday1 = L"Sun";
256           _M_data->_M_aday2 = L"Mon";
257           _M_data->_M_aday3 = L"Tue";
258           _M_data->_M_aday4 = L"Wed";
259           _M_data->_M_aday5 = L"Thu";
260           _M_data->_M_aday6 = L"Fri";
261           _M_data->_M_aday7 = L"Sat";
262
263           // Month names, starting with "C"'s January.
264           _M_data->_M_month01 = L"January";
265           _M_data->_M_month02 = L"February";
266           _M_data->_M_month03 = L"March";
267           _M_data->_M_month04 = L"April";
268           _M_data->_M_month05 = L"May";
269           _M_data->_M_month06 = L"June";
270           _M_data->_M_month07 = L"July";
271           _M_data->_M_month08 = L"August";
272           _M_data->_M_month09 = L"September";
273           _M_data->_M_month10 = L"October";
274           _M_data->_M_month11 = L"November";
275           _M_data->_M_month12 = L"December";
276
277           // Abbreviated month names, starting with "C"'s Jan.
278           _M_data->_M_amonth01 = L"Jan";
279           _M_data->_M_amonth02 = L"Feb";
280           _M_data->_M_amonth03 = L"Mar";
281           _M_data->_M_amonth04 = L"Apr";
282           _M_data->_M_amonth05 = L"May";
283           _M_data->_M_amonth06 = L"Jun";
284           _M_data->_M_amonth07 = L"Jul";
285           _M_data->_M_amonth08 = L"Aug";
286           _M_data->_M_amonth09 = L"Sep";
287           _M_data->_M_amonth10 = L"Oct";
288           _M_data->_M_amonth11 = L"Nov";
289           _M_data->_M_amonth12 = L"Dec";
290         }
291       else
292         {
293           _M_c_locale_timepunct = _S_clone_c_locale(__cloc); 
294
295           union { char *__s; wchar_t *__w; } __u;
296
297           __u.__s = __nl_langinfo_l(_NL_WD_FMT, __cloc);
298           _M_data->_M_date_format = __u.__w;
299           __u.__s = __nl_langinfo_l(_NL_WERA_D_FMT, __cloc);
300           _M_data->_M_date_era_format = __u.__w;
301           __u.__s = __nl_langinfo_l(_NL_WT_FMT, __cloc);
302           _M_data->_M_time_format = __u.__w;
303           __u.__s = __nl_langinfo_l(_NL_WERA_T_FMT, __cloc);
304           _M_data->_M_time_era_format = __u.__w;
305           __u.__s = __nl_langinfo_l(_NL_WD_T_FMT, __cloc);
306           _M_data->_M_date_time_format = __u.__w;
307           __u.__s = __nl_langinfo_l(_NL_WERA_D_T_FMT, __cloc);
308           _M_data->_M_date_time_era_format = __u.__w;
309           __u.__s = __nl_langinfo_l(_NL_WAM_STR, __cloc);
310           _M_data->_M_am = __u.__w;
311           __u.__s = __nl_langinfo_l(_NL_WPM_STR, __cloc);
312           _M_data->_M_pm = __u.__w;
313           __u.__s = __nl_langinfo_l(_NL_WT_FMT_AMPM, __cloc);
314           _M_data->_M_am_pm_format = __u.__w;
315
316           // Day names, starting with "C"'s Sunday.
317           __u.__s = __nl_langinfo_l(_NL_WDAY_1, __cloc);
318           _M_data->_M_day1 = __u.__w;
319           __u.__s = __nl_langinfo_l(_NL_WDAY_2, __cloc);
320           _M_data->_M_day2 = __u.__w;
321           __u.__s = __nl_langinfo_l(_NL_WDAY_3, __cloc);
322           _M_data->_M_day3 = __u.__w;
323           __u.__s = __nl_langinfo_l(_NL_WDAY_4, __cloc);
324           _M_data->_M_day4 = __u.__w;
325           __u.__s = __nl_langinfo_l(_NL_WDAY_5, __cloc);
326           _M_data->_M_day5 = __u.__w;
327           __u.__s = __nl_langinfo_l(_NL_WDAY_6, __cloc);
328           _M_data->_M_day6 = __u.__w;
329           __u.__s = __nl_langinfo_l(_NL_WDAY_7, __cloc);
330           _M_data->_M_day7 = __u.__w;
331
332           // Abbreviated day names, starting with "C"'s Sun.
333           __u.__s = __nl_langinfo_l(_NL_WABDAY_1, __cloc);
334           _M_data->_M_aday1 = __u.__w;
335           __u.__s = __nl_langinfo_l(_NL_WABDAY_2, __cloc);
336           _M_data->_M_aday2 = __u.__w;
337           __u.__s = __nl_langinfo_l(_NL_WABDAY_3, __cloc);
338           _M_data->_M_aday3 = __u.__w;
339           __u.__s = __nl_langinfo_l(_NL_WABDAY_4, __cloc);
340           _M_data->_M_aday4 = __u.__w;
341           __u.__s = __nl_langinfo_l(_NL_WABDAY_5, __cloc);
342           _M_data->_M_aday5 = __u.__w;
343           __u.__s = __nl_langinfo_l(_NL_WABDAY_6, __cloc);
344           _M_data->_M_aday6 = __u.__w;
345           __u.__s = __nl_langinfo_l(_NL_WABDAY_7, __cloc);
346           _M_data->_M_aday7 = __u.__w;
347
348           // Month names, starting with "C"'s January.
349           __u.__s = __nl_langinfo_l(_NL_WMON_1, __cloc);
350           _M_data->_M_month01 = __u.__w;
351           __u.__s = __nl_langinfo_l(_NL_WMON_2, __cloc);
352           _M_data->_M_month02 = __u.__w;
353           __u.__s = __nl_langinfo_l(_NL_WMON_3, __cloc);
354           _M_data->_M_month03 = __u.__w;
355           __u.__s = __nl_langinfo_l(_NL_WMON_4, __cloc);
356           _M_data->_M_month04 = __u.__w;
357           __u.__s = __nl_langinfo_l(_NL_WMON_5, __cloc);
358           _M_data->_M_month05 = __u.__w;
359           __u.__s = __nl_langinfo_l(_NL_WMON_6, __cloc);
360           _M_data->_M_month06 = __u.__w;
361           __u.__s = __nl_langinfo_l(_NL_WMON_7, __cloc);
362           _M_data->_M_month07 = __u.__w;
363           __u.__s = __nl_langinfo_l(_NL_WMON_8, __cloc);
364           _M_data->_M_month08 = __u.__w;
365           __u.__s = __nl_langinfo_l(_NL_WMON_9, __cloc);
366           _M_data->_M_month09 = __u.__w;
367           __u.__s = __nl_langinfo_l(_NL_WMON_10, __cloc);
368           _M_data->_M_month10 = __u.__w;
369           __u.__s = __nl_langinfo_l(_NL_WMON_11, __cloc);
370           _M_data->_M_month11 = __u.__w;
371           __u.__s = __nl_langinfo_l(_NL_WMON_12, __cloc);
372           _M_data->_M_month12 = __u.__w;
373
374           // Abbreviated month names, starting with "C"'s Jan.
375           __u.__s = __nl_langinfo_l(_NL_WABMON_1, __cloc);
376           _M_data->_M_amonth01 = __u.__w;
377           __u.__s = __nl_langinfo_l(_NL_WABMON_2, __cloc);
378           _M_data->_M_amonth02 = __u.__w;
379           __u.__s = __nl_langinfo_l(_NL_WABMON_3, __cloc);
380           _M_data->_M_amonth03 = __u.__w;
381           __u.__s = __nl_langinfo_l(_NL_WABMON_4, __cloc);
382           _M_data->_M_amonth04 = __u.__w;
383           __u.__s = __nl_langinfo_l(_NL_WABMON_5, __cloc);
384           _M_data->_M_amonth05 = __u.__w;
385           __u.__s = __nl_langinfo_l(_NL_WABMON_6, __cloc);
386           _M_data->_M_amonth06 = __u.__w;
387           __u.__s = __nl_langinfo_l(_NL_WABMON_7, __cloc);
388           _M_data->_M_amonth07 = __u.__w;
389           __u.__s = __nl_langinfo_l(_NL_WABMON_8, __cloc);
390           _M_data->_M_amonth08 = __u.__w;
391           __u.__s = __nl_langinfo_l(_NL_WABMON_9, __cloc);
392           _M_data->_M_amonth09 = __u.__w;
393           __u.__s = __nl_langinfo_l(_NL_WABMON_10, __cloc);
394           _M_data->_M_amonth10 = __u.__w;
395           __u.__s = __nl_langinfo_l(_NL_WABMON_11, __cloc);
396           _M_data->_M_amonth11 = __u.__w;
397           __u.__s = __nl_langinfo_l(_NL_WABMON_12, __cloc);
398           _M_data->_M_amonth12 = __u.__w;
399         }
400     }
401 #endif
402
403 _GLIBCXX_END_NAMESPACE