Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
langinfo.c
Go to the documentation of this file.
1 #include <assert.h>
2 #include <langinfo.h>
3 #include <locale.h>
4 #include <stdint.h>
5 
6 static const char c_time[] = "Sun\0"
7  "Mon\0"
8  "Tue\0"
9  "Wed\0"
10  "Thu\0"
11  "Fri\0"
12  "Sat\0"
13  "Sunday\0"
14  "Monday\0"
15  "Tuesday\0"
16  "Wednesday\0"
17  "Thursday\0"
18  "Friday\0"
19  "Saturday\0"
20  "Jan\0"
21  "Feb\0"
22  "Mar\0"
23  "Apr\0"
24  "May\0"
25  "Jun\0"
26  "Jul\0"
27  "Aug\0"
28  "Sep\0"
29  "Oct\0"
30  "Nov\0"
31  "Dec\0"
32  "January\0"
33  "February\0"
34  "March\0"
35  "April\0"
36  "May\0"
37  "June\0"
38  "July\0"
39  "August\0"
40  "September\0"
41  "October\0"
42  "November\0"
43  "December\0"
44  "AM\0"
45  "PM\0"
46  "%a %b %e %T %Y\0"
47  "%m/%d/%y\0"
48  "%H:%M:%S\0"
49  "%I:%M:%S %p\0"
50  "\0"
51  "\0"
52  "%m/%d/%y\0"
53  "0123456789\0"
54  "%a %b %e %T %Y\0"
55  "%H:%M:%S";
56 
57 static const char c_messages[] = "^[yY]\0"
58  "^[nN]\0"
59  "yes\0"
60  "no";
61 static const char c_numeric[] = ".\0"
62  "";
63 
64 char* nl_langinfo(nl_item item)
65 {
66  int cat = item >> 16;
67  int idx = item & 65535;
68  const char* str;
69 
70  if(item == CODESET)
71  {
72  assert(0 /*"Codeset langinfo not implemented"*/);
73  // return loc->cat[LC_CTYPE] ? "UTF-8" : "ASCII";
74  }
75 
76  /* _NL_LOCALE_NAME extension */
77  if(idx == 65535 && cat < LC_ALL)
78  {
79  assert(0 /*"LOCALE_NAME langinfo not implemented"*/);
80  // return loc->cat[cat] ? (char *)loc->cat[cat]->name : "C";
81  }
82 
83  switch(cat)
84  {
85  case LC_NUMERIC:
86  if(idx > 1)
87  {
88  return (char*)(uintptr_t) "";
89  }
90  str = c_numeric;
91  break;
92  case LC_TIME:
93  if(idx > 0x31)
94  {
95  return (char*)(uintptr_t) "";
96  }
97  str = c_time;
98  break;
99  case LC_MONETARY:
100  if(idx > 0)
101  {
102  return (char*)(uintptr_t) "";
103  }
104  str = "";
105  break;
106  case LC_MESSAGES:
107  if(idx > 3)
108  {
109  return (char*)(uintptr_t) "";
110  }
111  str = c_messages;
112  break;
113  default:
114  return (char*)(uintptr_t) "";
115  }
116 
117  for(; idx; idx--, str++)
118  {
119  for(; *str; str++)
120  {
121  }
122  }
123 
124 #if 0
125  if (cat != LC_NUMERIC && *str)
126  {
127  str = LCTRANS(str, cat, loc);
128  }
129 #endif
130 
131  return (char*)(uintptr_t)str;
132 }
int nl_item
Definition: nl_types.h:11
static const char c_time[]
Definition: langinfo.c:6
#define assert(x)
Definition: assert.h:11
static const char c_numeric[]
Definition: langinfo.c:61
char * nl_langinfo(nl_item item)
Definition: langinfo.c:64
#define CODESET
Definition: langinfo.h:83
static const char c_messages[]
Definition: langinfo.c:57
#define LC_MONETARY
Definition: locale.h:14
#define LC_ALL
Definition: locale.h:16
#define LC_TIME
Definition: locale.h:12
#define LC_NUMERIC
Definition: locale.h:11
#define LC_MESSAGES
Definition: locale.h:15