]> git.cworth.org Git - tar/blob - gnu/nl_langinfo.c
a709942976c4443b6711af7ae4e35559bd1bac1e
[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_ERA
73     case ERA:
74       /* The format is not standardized.  In glibc it is a sequence of strings
75          of the form "direction:offset:start_date:end_date:era_name:era_format"
76          with an empty string at the end.  */
77       return "";
78     case ERA_D_FMT:
79       /* The %Ex conversion in strftime behaves like %x if the locale does not
80          have an alternative time format.  */
81       item = D_FMT;
82       break;
83     case ERA_D_T_FMT:
84       /* The %Ec conversion in strftime behaves like %c if the locale does not
85          have an alternative time format.  */
86       item = D_T_FMT;
87       break;
88     case ERA_T_FMT:
89       /* The %EX conversion in strftime behaves like %X if the locale does not
90          have an alternative time format.  */
91       item = T_FMT;
92       break;
93     case ALT_DIGITS:
94       /* The format is not standardized.  In glibc it is a sequence of 10
95          strings, appended in memory.  */
96       return "\0\0\0\0\0\0\0\0\0\0";
97 # endif
98     default:
99       break;
100     }
101   return nl_langinfo (item);
102 }
103
104 #else
105
106 /* Provide nl_langinfo from scratch.  */
107
108 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
109
110 /* Native Windows platforms.  */
111
112 #  define WIN32_LEAN_AND_MEAN  /* avoid including junk */
113 #  include <windows.h>
114
115 #  include <stdio.h>
116
117 # else
118
119 /* An old Unix platform without locales, such as Linux libc5 or BeOS.  */
120
121 # endif
122
123 # include <locale.h>
124
125 char *
126 nl_langinfo (nl_item item)
127 {
128   switch (item)
129     {
130     /* nl_langinfo items of the LC_CTYPE category */
131     case CODESET:
132 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
133       {
134         static char buf[2 + 10 + 1];
135
136         /* Woe32 has a function returning the locale's codepage as a number.  */
137         sprintf (buf, "CP%u", GetACP ());
138         return buf;
139       }
140 # elif defined __BEOS__
141       return "UTF-8";
142 # else
143       return "ISO-8859-1";
144 # endif
145     /* nl_langinfo items of the LC_NUMERIC category */
146     case RADIXCHAR:
147       return localeconv () ->decimal_point;
148     case THOUSEP:
149       return localeconv () ->thousands_sep;
150     /* nl_langinfo items of the LC_TIME category.
151        TODO: Really use the locale.  */
152     case D_T_FMT:
153     case ERA_D_T_FMT:
154       return "%a %b %e %H:%M:%S %Y";
155     case D_FMT:
156     case ERA_D_FMT:
157       return "%m/%d/%y";
158     case T_FMT:
159     case ERA_T_FMT:
160       return "%H:%M:%S";
161     case T_FMT_AMPM:
162       return "%I:%M:%S %p";
163     case AM_STR:
164       return "AM";
165     case PM_STR:
166       return "PM";
167     case DAY_1:
168       return "Sunday";
169     case DAY_2:
170       return "Monday";
171     case DAY_3:
172       return "Tuesday";
173     case DAY_4:
174       return "Wednesday";
175     case DAY_5:
176       return "Thursday";
177     case DAY_6:
178       return "Friday";
179     case DAY_7:
180       return "Saturday";
181     case ABDAY_1:
182       return "Sun";
183     case ABDAY_2:
184       return "Mon";
185     case ABDAY_3:
186       return "Tue";
187     case ABDAY_4:
188       return "Wed";
189     case ABDAY_5:
190       return "Thu";
191     case ABDAY_6:
192       return "Fri";
193     case ABDAY_7:
194       return "Sat";
195     case MON_1:
196       return "January";
197     case MON_2:
198       return "February";
199     case MON_3:
200       return "March";
201     case MON_4:
202       return "April";
203     case MON_5:
204       return "May";
205     case MON_6:
206       return "June";
207     case MON_7:
208       return "July";
209     case MON_8:
210       return "August";
211     case MON_9:
212       return "September";
213     case MON_10:
214       return "October";
215     case MON_11:
216       return "November";
217     case MON_12:
218       return "December";
219     case ABMON_1:
220       return "Jan";
221     case ABMON_2:
222       return "Feb";
223     case ABMON_3:
224       return "Mar";
225     case ABMON_4:
226       return "Apr";
227     case ABMON_5:
228       return "May";
229     case ABMON_6:
230       return "Jun";
231     case ABMON_7:
232       return "Jul";
233     case ABMON_8:
234       return "Aug";
235     case ABMON_9:
236       return "Sep";
237     case ABMON_10:
238       return "Oct";
239     case ABMON_11:
240       return "Nov";
241     case ABMON_12:
242       return "Dec";
243     case ERA:
244       return "";
245     case ALT_DIGITS:
246       return "\0\0\0\0\0\0\0\0\0\0";
247     /* nl_langinfo items of the LC_MONETARY category
248        TODO: Really use the locale. */
249     case CRNCYSTR:
250       return "-";
251     /* nl_langinfo items of the LC_MESSAGES category
252        TODO: Really use the locale. */
253     case YESEXPR:
254       return "^[yY]";
255     case NOEXPR:
256       return "^[nN]";
257     default:
258       return "";
259     }
260 }
261
262 #endif