]> git.cworth.org Git - tar/blob - gnu/nl_langinfo.c
Imported Upstream version 1.24
[tar] / gnu / nl_langinfo.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* nl_langinfo() replacement: query locale dependent information.
4
5    Copyright (C) 2007-2010 Free Software Foundation, Inc.
6
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program 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
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #include <config.h>
21
22 /* Specification.  */
23 #include <langinfo.h>
24
25 #if REPLACE_NL_LANGINFO
26
27 /* Override nl_langinfo with support for added nl_item values.  */
28
29 # include <locale.h>
30 # include <string.h>
31
32 # undef nl_langinfo
33
34 char *
35 rpl_nl_langinfo (nl_item item)
36 {
37   switch (item)
38     {
39 # if GNULIB_defined_CODESET
40     case CODESET:
41       {
42         const char *locale;
43         static char buf[2 + 10 + 1];
44
45         locale = setlocale (LC_CTYPE, NULL);
46         if (locale != NULL && locale[0] != '\0')
47           {
48             /* If the locale name contains an encoding after the dot, return
49                it.  */
50             const char *dot = strchr (locale, '.');
51
52             if (dot != NULL)
53               {
54                 const char *modifier;
55
56                 dot++;
57                 /* Look for the possible @... trailer and remove it, if any.  */
58                 modifier = strchr (dot, '@');
59                 if (modifier == NULL)
60                   return dot;
61                 if (modifier - dot < sizeof (buf))
62                   {
63                     memcpy (buf, dot, modifier - dot);
64                     buf [modifier - dot] = '\0';
65                     return buf;
66                   }
67               }
68           }
69         return "";
70       }
71 # endif
72 # if GNULIB_defined_T_FMT_AMPM
73     case T_FMT_AMPM:
74       return "%I:%M:%S %p";
75 # endif
76 # if GNULIB_defined_ERA
77     case ERA:
78       /* The format is not standardized.  In glibc it is a sequence of strings
79          of the form "direction:offset:start_date:end_date:era_name:era_format"
80          with an empty string at the end.  */
81       return "";
82     case ERA_D_FMT:
83       /* The %Ex conversion in strftime behaves like %x if the locale does not
84          have an alternative time format.  */
85       item = D_FMT;
86       break;
87     case ERA_D_T_FMT:
88       /* The %Ec conversion in strftime behaves like %c if the locale does not
89          have an alternative time format.  */
90       item = D_T_FMT;
91       break;
92     case ERA_T_FMT:
93       /* The %EX conversion in strftime behaves like %X if the locale does not
94          have an alternative time format.  */
95       item = T_FMT;
96       break;
97     case ALT_DIGITS:
98       /* The format is not standardized.  In glibc it is a sequence of 10
99          strings, appended in memory.  */
100       return "\0\0\0\0\0\0\0\0\0\0";
101 # endif
102 # if GNULIB_defined_YESEXPR
103     case YESEXPR:
104       return "^[yY]";
105     case NOEXPR:
106       return "^[nN]";
107 # endif
108     default:
109       break;
110     }
111   return nl_langinfo (item);
112 }
113
114 #else
115
116 /* Provide nl_langinfo from scratch.  */
117
118 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
119
120 /* Native Windows platforms.  */
121
122 #  define WIN32_LEAN_AND_MEAN  /* avoid including junk */
123 #  include <windows.h>
124
125 #  include <stdio.h>
126
127 # else
128
129 /* An old Unix platform without locales, such as Linux libc5 or BeOS.  */
130
131 # endif
132
133 # include <locale.h>
134
135 char *
136 nl_langinfo (nl_item item)
137 {
138   switch (item)
139     {
140     /* nl_langinfo items of the LC_CTYPE category */
141     case CODESET:
142 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
143       {
144         static char buf[2 + 10 + 1];
145
146         /* Woe32 has a function returning the locale's codepage as a number.  */
147         sprintf (buf, "CP%u", GetACP ());
148         return buf;
149       }
150 # elif defined __BEOS__
151       return "UTF-8";
152 # else
153       return "ISO-8859-1";
154 # endif
155     /* nl_langinfo items of the LC_NUMERIC category */
156     case RADIXCHAR:
157       return localeconv () ->decimal_point;
158     case THOUSEP:
159       return localeconv () ->thousands_sep;
160     /* nl_langinfo items of the LC_TIME category.
161        TODO: Really use the locale.  */
162     case D_T_FMT:
163     case ERA_D_T_FMT:
164       return "%a %b %e %H:%M:%S %Y";
165     case D_FMT:
166     case ERA_D_FMT:
167       return "%m/%d/%y";
168     case T_FMT:
169     case ERA_T_FMT:
170       return "%H:%M:%S";
171     case T_FMT_AMPM:
172       return "%I:%M:%S %p";
173     case AM_STR:
174       return "AM";
175     case PM_STR:
176       return "PM";
177     case DAY_1:
178       return "Sunday";
179     case DAY_2:
180       return "Monday";
181     case DAY_3:
182       return "Tuesday";
183     case DAY_4:
184       return "Wednesday";
185     case DAY_5:
186       return "Thursday";
187     case DAY_6:
188       return "Friday";
189     case DAY_7:
190       return "Saturday";
191     case ABDAY_1:
192       return "Sun";
193     case ABDAY_2:
194       return "Mon";
195     case ABDAY_3:
196       return "Tue";
197     case ABDAY_4:
198       return "Wed";
199     case ABDAY_5:
200       return "Thu";
201     case ABDAY_6:
202       return "Fri";
203     case ABDAY_7:
204       return "Sat";
205     case MON_1:
206       return "January";
207     case MON_2:
208       return "February";
209     case MON_3:
210       return "March";
211     case MON_4:
212       return "April";
213     case MON_5:
214       return "May";
215     case MON_6:
216       return "June";
217     case MON_7:
218       return "July";
219     case MON_8:
220       return "August";
221     case MON_9:
222       return "September";
223     case MON_10:
224       return "October";
225     case MON_11:
226       return "November";
227     case MON_12:
228       return "December";
229     case ABMON_1:
230       return "Jan";
231     case ABMON_2:
232       return "Feb";
233     case ABMON_3:
234       return "Mar";
235     case ABMON_4:
236       return "Apr";
237     case ABMON_5:
238       return "May";
239     case ABMON_6:
240       return "Jun";
241     case ABMON_7:
242       return "Jul";
243     case ABMON_8:
244       return "Aug";
245     case ABMON_9:
246       return "Sep";
247     case ABMON_10:
248       return "Oct";
249     case ABMON_11:
250       return "Nov";
251     case ABMON_12:
252       return "Dec";
253     case ERA:
254       return "";
255     case ALT_DIGITS:
256       return "\0\0\0\0\0\0\0\0\0\0";
257     /* nl_langinfo items of the LC_MONETARY category
258        TODO: Really use the locale. */
259     case CRNCYSTR:
260       return "-";
261     /* nl_langinfo items of the LC_MESSAGES category
262        TODO: Really use the locale. */
263     case YESEXPR:
264       return "^[yY]";
265     case NOEXPR:
266       return "^[nN]";
267     default:
268       return "";
269     }
270 }
271
272 #endif