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