[337] | 1 | #include <locale.h>
|
---|
| 2 | #include <langinfo.h>
|
---|
| 3 | #include "locale_impl.h"
|
---|
| 4 | #include "libc.h"
|
---|
| 5 |
|
---|
| 6 | static const char c_time[] =
|
---|
| 7 | "Sun\0" "Mon\0" "Tue\0" "Wed\0" "Thu\0" "Fri\0" "Sat\0"
|
---|
| 8 | "Sunday\0" "Monday\0" "Tuesday\0" "Wednesday\0"
|
---|
| 9 | "Thursday\0" "Friday\0" "Saturday\0"
|
---|
| 10 | "Jan\0" "Feb\0" "Mar\0" "Apr\0" "May\0" "Jun\0"
|
---|
| 11 | "Jul\0" "Aug\0" "Sep\0" "Oct\0" "Nov\0" "Dec\0"
|
---|
| 12 | "January\0" "February\0" "March\0" "April\0"
|
---|
| 13 | "May\0" "June\0" "July\0" "August\0"
|
---|
| 14 | "September\0" "October\0" "November\0" "December\0"
|
---|
| 15 | "AM\0" "PM\0"
|
---|
| 16 | "%a %b %e %T %Y\0"
|
---|
| 17 | "%m/%d/%y\0"
|
---|
| 18 | "%H:%M:%S\0"
|
---|
| 19 | "%I:%M:%S %p\0"
|
---|
| 20 | "\0"
|
---|
| 21 | "\0"
|
---|
| 22 | "%m/%d/%y\0"
|
---|
| 23 | "0123456789\0"
|
---|
| 24 | "%a %b %e %T %Y\0"
|
---|
| 25 | "%H:%M:%S";
|
---|
| 26 |
|
---|
| 27 | static const char c_messages[] = "^[yY]\0" "^[nN]\0" "yes\0" "no";
|
---|
| 28 | static const char c_numeric[] = ".\0" "";
|
---|
| 29 |
|
---|
| 30 | char *__nl_langinfo_l(nl_item item, locale_t loc)
|
---|
| 31 | {
|
---|
| 32 | int cat = item >> 16;
|
---|
| 33 | int idx = item & 65535;
|
---|
| 34 | const char *str;
|
---|
| 35 |
|
---|
| 36 | if (item == CODESET) return MB_CUR_MAX==1 ? "ASCII" : "UTF-8";
|
---|
| 37 |
|
---|
| 38 | /* _NL_LOCALE_NAME extension */
|
---|
| 39 | if (idx == 65535 && cat < LC_ALL)
|
---|
| 40 | return loc->cat[cat] ? (char *)loc->cat[cat]->name : "C";
|
---|
| 41 |
|
---|
| 42 | switch (cat) {
|
---|
| 43 | case LC_NUMERIC:
|
---|
| 44 | if (idx > 1) return "";
|
---|
| 45 | str = c_numeric;
|
---|
| 46 | break;
|
---|
| 47 | case LC_TIME:
|
---|
| 48 | if (idx > 0x31) return "";
|
---|
| 49 | str = c_time;
|
---|
| 50 | break;
|
---|
| 51 | case LC_MONETARY:
|
---|
| 52 | if (idx > 0) return "";
|
---|
| 53 | str = "";
|
---|
| 54 | break;
|
---|
| 55 | case LC_MESSAGES:
|
---|
| 56 | if (idx > 3) return "";
|
---|
| 57 | str = c_messages;
|
---|
| 58 | break;
|
---|
| 59 | default:
|
---|
| 60 | return "";
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | for (; idx; idx--, str++) for (; *str; str++);
|
---|
| 64 | if (cat != LC_NUMERIC && *str) str = LCTRANS(str, cat, loc);
|
---|
| 65 | return (char *)str;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | char *__nl_langinfo(nl_item item)
|
---|
| 69 | {
|
---|
| 70 | return __nl_langinfo_l(item, CURRENT_LOCALE);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | weak_alias(__nl_langinfo, nl_langinfo);
|
---|
| 74 | weak_alias(__nl_langinfo_l, nl_langinfo_l);
|
---|