]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/stdall.c
make access for virtuals match base
[wxWidgets.git] / src / palmos / stdall.c
1
2 #include <Preferences.h> // Core/System/
3 #include <DateTime.h> //Core/System/, DateToAscii() etc.
4 #include <TimeMgr.h> //Core/System/, TimGetTicks()
5
6 #include "wx/defs.h"
7
8 #if __WXPALMOS6__
9 void
10 exit (int exitno)
11 {
12 }
13
14 #else
15
16 #define SEC_1904_1970 2082844800LU//0x7C25B080 // 0x7C25B080 == 2082844800LU
17
18 time_t
19 time (time_t *T)
20 {
21 UInt32 sec;
22 // UInt32 TimGetSeconds(void); // seconds since 1/1/1904
23 // void TimSetSeconds (UInt32 seconds); // seconds since 1/1/1904
24 // UInt32 TimGetTicks(void); // ticks since power on
25 sec = TimGetSeconds ();
26 if (T) {
27 *T = sec - SEC_1904_1970;
28 }
29 return (sec - SEC_1904_1970);
30 }
31
32 static struct tm *
33 palmtimet2unixtm (const time_t t, struct tm *ptm)
34 {
35 DateTimeType dt;
36 memset (&dt, 0, sizeof (dt));
37 memset (ptm, 0, sizeof (*ptm));
38 TimSecondsToDateTime (t, &dt);
39 ptm->tm_sec = dt.second;
40 ptm->tm_min = dt.minute;
41 ptm->tm_hour = dt.hour;
42 ptm->tm_mday = dt.day;
43 ptm->tm_mon = dt.month;
44 ptm->tm_year = dt.year;
45 ptm->tm_wday = dt.weekDay;
46
47 //ptm->tm_wday = DayOfWeek (dt.month, dt.day, dt.year);
48 //ptm->tm_mday = DayOfMonth (dt.month, dt.day, dt.year);
49 return ptm;
50 }
51
52 struct tm *
53 gmtime_r (const time_t *pt, struct tm *ptm)
54 {
55 UInt32 utcTime;
56 Int16 timeZone = PrefGetPreference(prefTimeZone);
57 Int16 daylightSavingAdjustment = PrefGetPreference(prefDaylightSavingAdjustment);
58
59 if ((NULL == pt) || (NULL == ptm)) {
60 return NULL;
61 }
62 utcTime = TimTimeZoneToUTC (*pt + SEC_1904_1970, timeZone, daylightSavingAdjustment);
63 palmtimet2unixtm (utcTime, ptm);
64 return ptm;
65 }
66
67 struct tm *
68 localtime_r (const time_t *pt, struct tm *ptm)
69 {
70 UInt32 utcTime;
71 Int16 timeZone = PrefGetPreference(prefTimeZone);
72 Int16 daylightSavingAdjustment = PrefGetPreference(prefDaylightSavingAdjustment);
73 if ((NULL == pt) || (NULL == ptm)) {
74 return NULL;
75 }
76 utcTime = TimUTCToTimeZone (*pt + SEC_1904_1970, timeZone, daylightSavingAdjustment);
77 palmtimet2unixtm (utcTime, ptm);
78 return ptm;
79 }
80 /*
81 static struct tm g_gmtime_info;
82
83 struct tm *
84 gmtime (const time_t *CLOCK)
85 {
86 if (NULL == CLOCK) {
87 return NULL;
88 }
89 if (NULL == gmtime_r (CLOCK, &g_gmtime_info)) {
90 return NULL;
91 }
92 return &g_gmtime_info;
93 }
94 */
95 static struct tm g_localtime_info;
96
97 struct tm *
98 localtime (const time_t *CLOCK)
99 {
100 if (NULL == CLOCK) {
101 return NULL;
102 }
103 if (NULL == localtime_r (CLOCK, &g_localtime_info)) {
104 return NULL;
105 }
106 return &g_localtime_info;
107 }
108
109 static char * g_strftime_wdayconv[][2] = {
110 {"Sun", "Sunday"},
111 {"Mon", "Monday"},
112 {"Tue", "Tuesday"},
113 {"Wed", "Wednesday"},
114 {"Thu", "Thursday"},
115 {"Fri", "Friday"},
116 {"Sat", "Saturday"},
117 };
118
119 static char * g_strftime_monconv[][2] = {
120 {"Jan", "January"},
121 {"Feb", "Febuary"},
122 {"Mar", "March"},
123 {"Apr", "April"},
124 {"May", "May"},
125 {"Jun", "June"},
126 {"Jul", "July"},
127 {"Aug", "August"},
128 {"Sep", "September"},
129 {"Oct", "October"},
130 {"Nov", "November"},
131 {"Dec", "December"},
132 };
133 #define SFCONV_ABBR 0
134 #define SFCONV_FULL 1
135
136 size_t
137 strftime (char *buf, size_t sz_buf, const char *fmt, const struct tm *ptm)
138 {
139 char *p;
140 char *pret;
141 if ((timeStringLength > sz_buf) || (strlen (fmt) < 1)) {
142 return 0;
143 }
144 memset (buf, 0, sz_buf);
145 p = fmt;
146 pret = buf;
147 for (; *p != '\0';) {
148 if ('%' == *p) {
149 p ++;
150 if (*p == '\0') {
151 break;
152 }
153 // FIXME: Åжϻº³åÊÇ·ñÒç³ö
154 switch (*p) {
155 case 'a':
156 strcpy (pret, g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_ABBR]);
157 pret += 3;
158 break;
159 case 'A':
160 strcpy (pret, g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_FULL]);
161 pret += strlen (g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_FULL]);
162 break;
163 case 'b':
164 strcpy (pret, g_strftime_monconv[ptm->tm_mon % 12][SFCONV_ABBR]);
165 pret += 3;
166 break;
167 case 'B':
168 strcpy (pret, g_strftime_monconv[ptm->tm_mon % 12][SFCONV_FULL]);
169 pret += strlen (g_strftime_monconv[ptm->tm_mon % 12][SFCONV_FULL]);
170 break;
171 case 'c':
172 strcpy (pret, g_strftime_wdayconv[ptm->tm_wday % 7][SFCONV_ABBR]);
173 pret += 3;
174 *pret = ' ';
175 pret ++;
176 strcpy (pret, g_strftime_monconv[ptm->tm_mon % 12][SFCONV_ABBR]);
177 pret += 3;
178 *pret = ' ';
179 pret ++;
180 sprintf (pret, "%d %02d:%02d:%02d %d", ptm->tm_mday,
181 ptm->tm_hour, ptm->tm_min, ptm->tm_sec, ptm->tm_year);
182 pret += strlen (pret);
183 break;
184 case 'd':
185 sprintf (pret, "%02d", ptm->tm_mday % 31);
186 pret += 2;
187 break;
188 case 'H':
189 sprintf (pret, "%02d", ptm->tm_hour % 24);
190 pret += 2;
191 break;
192 case 'I':
193 sprintf (pret, "%02d", (ptm->tm_hour % 12) + 1);
194 pret += 2;
195 break;
196 case 'j':
197 sprintf (pret, "%03d", ptm->tm_year % 400);
198 pret += 3;
199 break;
200 case 'm':
201 sprintf (pret, "%02d", (ptm->tm_mon % 12) + 1);
202 pret += 2;
203 break;
204 case 'M':
205 sprintf (pret, "%02d", ptm->tm_min % 60);
206 pret += 2;
207 break;
208 case 'p':
209 if (ptm->tm_hour > 12) {
210 strcpy (pret, "PM");
211 break;
212 }
213 strcpy (pret, "AM");
214 pret += 2;
215 break;
216 case 'S':
217 sprintf (pret, "%02d", ptm->tm_sec % 61);
218 pret += 2;
219 break;
220 case 'U':
221 // FIXME: Week number with the first Sunday as the first day of week one (00-53)
222 sprintf (pret, "%02d", ptm->tm_yday / 7);
223 pret += 2;
224 break;
225 case 'w':
226 sprintf (pret, "%d", ptm->tm_wday % 7);
227 pret += 1;
228 break;
229 case 'W':
230 // FIXME: Week number with the first Sunday as the first day of week one (00-53)
231 sprintf (pret, "%02d", ptm->tm_yday / 7);
232 pret += 2;
233 break;
234 case 'x':
235 sprintf (pret, "%02d/%02d/%02d",
236 ptm->tm_mon, ptm->tm_mday, ptm->tm_year - 1900);
237 pret += strlen (pret);
238 break;
239 case 'X':
240 sprintf (pret, "%02d:%02d:%02d",
241 ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
242 pret += strlen (pret);
243 break;
244 case 'y':
245 sprintf (pret, "%02d", ptm->tm_year - 1900);
246 pret += 2;
247 break;
248 case 'Y':
249 sprintf (pret, "%02d", ptm->tm_year);
250 pret += strlen (pret);
251 break;
252 case 'Z':
253 {
254 LmLocaleType ll;
255 ll.language = lmAnyLanguage;
256 ll.country = 0;
257 TimeZoneToAscii (ptm->tm_gmtoff, &ll, pret);
258 }
259 pret += strlen (pret);
260 break;
261 case '%':
262 *pret = *p;
263 pret ++;
264 break;
265 }
266 } else {
267 *pret = *p;
268 pret ++;
269 }
270 p ++;
271 }
272 return 0;
273 }
274
275 time_t
276 mktime (struct tm *ptm)
277 {
278 DateTimeType dt;
279 if (NULL == ptm) {
280 return 0;
281 }
282 memset (&dt, 0, sizeof (dt));
283 dt.second = ptm->tm_sec;
284 dt.minute = ptm->tm_min;
285 dt.hour = ptm->tm_hour;
286 dt.day = ptm->tm_mday;
287 dt.month = ptm->tm_mon;
288 dt.year = ptm->tm_year;
289 dt.weekDay = ptm->tm_wday;
290 return TimDateTimeToSeconds (&dt);
291 }
292
293 int
294 vsscanf (const char *s, const char *format, va_list param)
295 {
296 return -1;
297 }
298
299 FILE * fopen (const char *_name, const char *_type) {return NULL;}
300 int fclose (FILE *fp) {return 0;}
301 size_t fread (void *buf, size_t _size, size_t _n, FILE *fp) {return 0;}
302 size_t fwrite (const void *buf , size_t _size, size_t _n, FILE *fp) {return 0;}
303 int fseek (FILE *fp, long offset, int whence) {return -1;}
304 long ftell (FILE *fp) {return -1;}
305 int feof (FILE *fp) {return -1;}
306 int ferror (FILE *fp) {return -1;}
307 void clearerr (FILE *fp) {}
308
309 #endif // __WXPALMOS6__
310
311 #define _BIT_ALPHA 0X0001
312 #define _BIT_BLANK 0X0002
313 #define _BIT_CNTRL 0X0004
314 #define _BIT_DIGIT 0X0008
315 #define _BIT_GRAPH 0X0010
316 #define _BIT_LOWER 0X0020
317 #define _BIT_PRINT 0X0040
318 #define _BIT_PUNCT 0X0080
319 #define _BIT_SPACE 0X0100
320 #define _BIT_UPPER 0X0200
321 #define _BIT_XDIGIT 0X0400
322
323 int iswalnum(wint_t C) {return 0;}
324 int iswalpha(wint_t C) {return 0;}
325 int iswcntrl(wint_t C) {return 0;}
326 int iswdigit(wint_t C) {return 0;}
327 int iswgraph(wint_t C) {return 0;}
328 int iswlower(wint_t C) {return 0;}
329 int iswprint(wint_t C) {return 0;}
330 int iswpunct(wint_t C) {return 0;}
331 int iswspace(wint_t C) {return 0;}
332 int iswupper(wint_t C) {return 0;}
333 int iswxdigit(wint_t C) {return 0;}
334
335 wint_t towlower(wint_t C) {return 0;}
336 wint_t towupper(wint_t C) {return 0;}
337 size_t wcsftime(wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr) {return 0;}
338
339 size_t wcslen (const wchar_t * str) {return 0;}
340 wchar_t * wcscpy (wchar_t * dst, const wchar_t * src) {return NULL;}
341 wchar_t * wcsncpy (wchar_t * dst, const wchar_t * src, size_t n) {return NULL;}
342 wchar_t * wcscat (wchar_t * dst, const wchar_t * src) {return NULL;}
343 wchar_t * wcsncat (wchar_t * dst, const wchar_t * src, size_t n) {return NULL;}
344 int wcscmp (const wchar_t * str1, const wchar_t * str2) {return 0;}
345 int wcsncmp (const wchar_t * str1, const wchar_t * str2, size_t n) {return 0;}
346 wchar_t * wcschr (const wchar_t * str, const wchar_t chr) {return NULL;}
347 int wcscoll (const wchar_t *str1, const wchar_t * str2) {return 0;}
348 size_t wcsxfrm (wchar_t * str1, const wchar_t * str2, size_t n) {return 0;}
349 wchar_t * wcsrchr (const wchar_t * str, wchar_t chr) {return NULL;}
350 wchar_t * wcspbrk (const wchar_t * str, const wchar_t * set) {return NULL;}
351 size_t wcsspn (const wchar_t * str, const wchar_t * set) {return 0;}
352 size_t wcscspn (const wchar_t * str, const wchar_t * set) {return 0;}
353 wchar_t * wcsstr (const wchar_t * str, const wchar_t * pat) {return NULL;}
354 wchar_t * wcstok (wchar_t * str, const wchar_t * set, wchar_t ** a) {return NULL;}
355
356 unsigned long wcstoul (const wchar_t * a, wchar_t ** b, int c) {return 0;}
357 double wcstod (const wchar_t * a, wchar_t ** b) {return 0.0;}
358
359 long wcstol (const wchar_t * str, wchar_t ** end, int base) {return 0;}
360 char * setlocale (int category, const char *locale) {return NULL;}