source: trunk/src/kernel32/time.cpp@ 3588

Last change on this file since 3588 was 3588, checked in by sandervl, 25 years ago

GetFileTime bugfix + FindResource(Ex)A/W changes + setup thread security objects during creation

File size: 42.8 KB
Line 
1/* $Id: time.cpp,v 1.8 2000-05-22 19:07:59 sandervl Exp $ */
2
3/*
4 * Win32 time/date API functions
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999 Christoph Bratschi (cbratschi@datacomm.ch)
8 *
9 * Copyright 1996 Alexandre Julliard
10 * Copyright 1995 Martin von Loewis
11 * Copyright 1998 David Lee Lambert
12
13 *
14 * Project Odin Software License can be found in LICENSE.TXT
15 */
16#include <os2win.h>
17#include <winnls.h>
18#include "winuser.h"
19#include <stdlib.h>
20#include <string.h>
21#include <stdio.h>
22#include "unicode.h"
23
24#define DBG_LOCALLOG DBG_time
25#include "dbglocal.h"
26
27#define lstrcpynAtoW(unicode,ascii,asciilen) AsciiToUnicodeN(ascii,unicode,asciilen);
28
29#define WPRINTF_LEFTALIGN 0x0001 /* Align output on the left ('-' prefix) */
30#define WPRINTF_PREFIX_HEX 0x0002 /* Prefix hex with 0x ('#' prefix) */
31#define WPRINTF_ZEROPAD 0x0004 /* Pad with zeros ('0' prefix) */
32#define WPRINTF_LONG 0x0008 /* Long arg ('l' prefix) */
33#define WPRINTF_SHORT 0x0010 /* Short arg ('h' prefix) */
34#define WPRINTF_UPPER_HEX 0x0020 /* Upper-case hex ('X' specifier) */
35#define WPRINTF_WIDE 0x0040 /* Wide arg ('w' prefix) */
36
37typedef enum
38{
39 WPR_UNKNOWN,
40 WPR_CHAR,
41 WPR_WCHAR,
42 WPR_STRING,
43 WPR_WSTRING,
44 WPR_SIGNED,
45 WPR_UNSIGNED,
46 WPR_HEXA
47} WPRINTF_TYPE;
48
49typedef struct
50{
51 UINT flags;
52 UINT width;
53 UINT precision;
54 WPRINTF_TYPE type;
55} WPRINTF_FORMAT;
56
57typedef union {
58 WCHAR wchar_view;
59 CHAR char_view;
60 LPCSTR lpcstr_view;
61 LPCWSTR lpcwstr_view;
62 INT int_view;
63} WPRINTF_DATA;
64
65static const CHAR null_stringA[] = "(null)";
66static const WCHAR null_stringW[] = { '(', 'n', 'u', 'l', 'l', ')', 0 };
67
68//******************************************************************************
69//******************************************************************************
70VOID WIN32API GetLocalTime( LPSYSTEMTIME arg1)
71{
72/// dprintf(("KERNEL32: GetLocalTime\n"));
73 O32_GetLocalTime(arg1);
74}
75//******************************************************************************
76//******************************************************************************
77BOOL WIN32API SetLocalTime( const SYSTEMTIME * arg1)
78{
79 dprintf(("KERNEL32: SetLocalTime\n"));
80 return O32_SetLocalTime(arg1);
81}
82//******************************************************************************
83//******************************************************************************
84BOOL WIN32API FileTimeToDosDateTime(const FILETIME * arg1, LPWORD arg2, LPWORD arg3)
85{
86 dprintf(("KERNEL32: FileTimeToDosDateTime\n"));
87 return O32_FileTimeToDosDateTime(arg1, arg2, arg3);
88}
89//******************************************************************************
90//******************************************************************************
91BOOL WIN32API FileTimeToLocalFileTime(const FILETIME * arg1, LPFILETIME arg2)
92{
93 dprintf(("KERNEL32: FileTimeToLocalFileTime\n"));
94 return O32_FileTimeToLocalFileTime(arg1, arg2);
95}
96//******************************************************************************
97//******************************************************************************
98BOOL WIN32API LocalFileTimeToFileTime(const FILETIME * arg1, LPFILETIME arg2)
99{
100 dprintf(("KERNEL32: LocalFileTimeToFileTime\n"));
101 return O32_LocalFileTimeToFileTime(arg1, arg2);
102}
103//******************************************************************************
104//******************************************************************************
105BOOL WIN32API FileTimeToSystemTime(const FILETIME * arg1, LPSYSTEMTIME arg2)
106{
107 dprintf(("KERNEL32: FileTimeToSystemTime"));
108 return O32_FileTimeToSystemTime(arg1, arg2);
109}
110//******************************************************************************
111//******************************************************************************
112BOOL WIN32API DosDateTimeToFileTime( WORD arg1, WORD arg2, LPFILETIME arg3)
113{
114 dprintf(("KERNEL32: DosDateTimeToFileTime\n"));
115 return O32_DosDateTimeToFileTime(arg1, arg2, arg3);
116}
117//******************************************************************************
118//******************************************************************************
119DWORD WIN32API GetTimeZoneInformation( LPTIME_ZONE_INFORMATION arg1)
120{
121 dprintf(("KERNEL32: GetTimeZoneInformation\n"));
122 return O32_GetTimeZoneInformation(arg1);
123}
124//******************************************************************************
125//******************************************************************************
126DWORD WIN32API GetTickCount(void)
127{
128//// dprintf(("KERNEL32: GetTickCount\n"));
129 return O32_GetTickCount();
130}
131//******************************************************************************
132//******************************************************************************
133VOID WIN32API GetSystemTime( LPSYSTEMTIME arg1)
134{
135 dprintf(("KERNEL32: OS2GetSystemTime\n"));
136 O32_GetSystemTime(arg1);
137}
138//******************************************************************************
139//******************************************************************************
140BOOL WIN32API SystemTimeToFileTime( const SYSTEMTIME * arg1, LPFILETIME arg2)
141{
142 dprintf(("KERNEL32: OS2SystemTimeToFileTime\n"));
143 return O32_SystemTimeToFileTime(arg1, arg2);
144}
145//******************************************************************************
146//******************************************************************************
147BOOL WIN32API SystemTimeToTzSpecificLocalTime( LPTIME_ZONE_INFORMATION arg1, LPSYSTEMTIME arg2, LPSYSTEMTIME arg3)
148{
149 dprintf(("KERNEL32: OS2SystemTimeToTzSpecificLocalTime\n"));
150 return O32_SystemTimeToTzSpecificLocalTime(arg1, arg2, arg3);
151}
152//******************************************************************************
153//******************************************************************************
154BOOL WIN32API SetTimeZoneInformation( const LPTIME_ZONE_INFORMATION arg1)
155{
156 dprintf(("KERNEL32: OS2SetTimeZoneInformation\n"));
157 return O32_SetTimeZoneInformation(arg1);
158}
159//******************************************************************************
160//******************************************************************************
161BOOL WIN32API SetSystemTime(const SYSTEMTIME * arg1)
162{
163 dprintf(("KERNEL32: OS2SetSystemTime\n"));
164 return O32_SetSystemTime(arg1);
165}
166
167/***********************************************************************
168 * WPRINTF_ParseFormatA
169 *
170 * Parse a format specification. A format specification has the form:
171 *
172 * [-][#][0][width][.precision]type
173 *
174 * Return value is the length of the format specification in characters.
175 */
176static INT WPRINTF_ParseFormatA( LPCSTR format, WPRINTF_FORMAT *res )
177{
178 LPCSTR p = format;
179
180 res->flags = 0;
181 res->width = 0;
182 res->precision = 0;
183 if (*p == '-') { res->flags |= WPRINTF_LEFTALIGN; p++; }
184 if (*p == '#') { res->flags |= WPRINTF_PREFIX_HEX; p++; }
185 if (*p == '0') { res->flags |= WPRINTF_ZEROPAD; p++; }
186 while ((*p >= '0') && (*p <= '9')) /* width field */
187 {
188 res->width = res->width * 10 + *p - '0';
189 p++;
190 }
191 if (*p == '.') /* precision field */
192 {
193 p++;
194 while ((*p >= '0') && (*p <= '9'))
195 {
196 res->precision = res->precision * 10 + *p - '0';
197 p++;
198 }
199 }
200 if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
201 else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
202 else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
203 switch(*p)
204 {
205 case 'c':
206 res->type = (res->flags & WPRINTF_LONG) ? WPR_WCHAR : WPR_CHAR;
207 break;
208 case 'C':
209 res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR;
210 break;
211 case 'd':
212 case 'i':
213 res->type = WPR_SIGNED;
214 break;
215 case 's':
216 res->type = (res->flags & (WPRINTF_LONG |WPRINTF_WIDE))
217 ? WPR_WSTRING : WPR_STRING;
218 break;
219 case 'S':
220 res->type = (res->flags & (WPRINTF_SHORT|WPRINTF_WIDE))
221 ? WPR_STRING : WPR_WSTRING;
222 break;
223 case 'u':
224 res->type = WPR_UNSIGNED;
225 break;
226 case 'X':
227 res->flags |= WPRINTF_UPPER_HEX;
228 /* fall through */
229 case 'x':
230 res->type = WPR_HEXA;
231 break;
232 default: /* unknown format char */
233 res->type = WPR_UNKNOWN;
234 p--; /* print format as normal char */
235 break;
236 }
237 return (INT)(p - format) + 1;
238}
239
240
241/***********************************************************************
242 * WPRINTF_ParseFormatW
243 *
244 * Parse a format specification. A format specification has the form:
245 *
246 * [-][#][0][width][.precision]type
247 *
248 * Return value is the length of the format specification in characters.
249 */
250static INT WPRINTF_ParseFormatW( LPCWSTR format, WPRINTF_FORMAT *res )
251{
252 LPCWSTR p = format;
253
254 res->flags = 0;
255 res->width = 0;
256 res->precision = 0;
257 if (*p == '-') { res->flags |= WPRINTF_LEFTALIGN; p++; }
258 if (*p == '#') { res->flags |= WPRINTF_PREFIX_HEX; p++; }
259 if (*p == '0') { res->flags |= WPRINTF_ZEROPAD; p++; }
260 while ((*p >= '0') && (*p <= '9')) /* width field */
261 {
262 res->width = res->width * 10 + *p - '0';
263 p++;
264 }
265 if (*p == '.') /* precision field */
266 {
267 p++;
268 while ((*p >= '0') && (*p <= '9'))
269 {
270 res->precision = res->precision * 10 + *p - '0';
271 p++;
272 }
273 }
274 if (*p == 'l') { res->flags |= WPRINTF_LONG; p++; }
275 else if (*p == 'h') { res->flags |= WPRINTF_SHORT; p++; }
276 else if (*p == 'w') { res->flags |= WPRINTF_WIDE; p++; }
277 switch((CHAR)*p)
278 {
279 case 'c':
280 res->type = (res->flags & WPRINTF_SHORT) ? WPR_CHAR : WPR_WCHAR;
281 break;
282 case 'C':
283 res->type = (res->flags & WPRINTF_LONG) ? WPR_WCHAR : WPR_CHAR;
284 break;
285 case 'd':
286 case 'i':
287 res->type = WPR_SIGNED;
288 break;
289 case 's':
290 res->type = ((res->flags & WPRINTF_SHORT) && !(res->flags & WPRINTF_WIDE)) ? WPR_STRING : WPR_WSTRING;
291 break;
292 case 'S':
293 res->type = (res->flags & (WPRINTF_LONG|WPRINTF_WIDE)) ? WPR_WSTRING : WPR_STRING;
294 break;
295 case 'u':
296 res->type = WPR_UNSIGNED;
297 break;
298 case 'X':
299 res->flags |= WPRINTF_UPPER_HEX;
300 /* fall through */
301 case 'x':
302 res->type = WPR_HEXA;
303 break;
304 default:
305 res->type = WPR_UNKNOWN;
306 p--; /* print format as normal char */
307 break;
308 }
309 return (INT)(p - format) + 1;
310}
311
312
313/***********************************************************************
314 * WPRINTF_GetLen
315 */
316static UINT WPRINTF_GetLen( WPRINTF_FORMAT *format, WPRINTF_DATA *arg,
317 LPSTR number, UINT maxlen )
318{
319 UINT len;
320
321 if (format->flags & WPRINTF_LEFTALIGN) format->flags &= ~WPRINTF_ZEROPAD;
322 if (format->width > maxlen) format->width = maxlen;
323 switch(format->type)
324 {
325 case WPR_CHAR:
326 case WPR_WCHAR:
327 return (format->precision = 1);
328 case WPR_STRING:
329 if (!arg->lpcstr_view) arg->lpcstr_view = null_stringA;
330 for (len = 0; !format->precision || (len < format->precision); len++)
331 if (!*(arg->lpcstr_view + len)) break;
332 if (len > maxlen) len = maxlen;
333 return (format->precision = len);
334 case WPR_WSTRING:
335 if (!arg->lpcwstr_view) arg->lpcwstr_view = null_stringW;
336 for (len = 0; !format->precision || (len < format->precision); len++)
337 if (!*(arg->lpcwstr_view + len)) break;
338 if (len > maxlen) len = maxlen;
339 return (format->precision = len);
340 case WPR_SIGNED:
341 len = sprintf( number, "%d", arg->int_view );
342 break;
343 case WPR_UNSIGNED:
344 len = sprintf( number, "%u", (UINT)arg->int_view );
345 break;
346 case WPR_HEXA:
347 len = sprintf( number,
348 (format->flags & WPRINTF_UPPER_HEX) ? "%X" : "%x",
349 (UINT)arg->int_view);
350 if (format->flags & WPRINTF_PREFIX_HEX) len += 2;
351 break;
352 default:
353 return 0;
354 }
355 if (len > maxlen) len = maxlen;
356 if (format->precision < len) format->precision = len;
357 if (format->precision > maxlen) format->precision = maxlen;
358 if ((format->flags & WPRINTF_ZEROPAD) && (format->width > format->precision))
359 format->precision = format->width;
360 return len;
361}
362
363/***********************************************************************
364 * WPRINTF_ExtractVAPtr (Not a Windows API)
365 */
366static WPRINTF_DATA WPRINTF_ExtractVAPtr( WPRINTF_FORMAT *format, va_list* args )
367{
368 WPRINTF_DATA result;
369 switch(format->type)
370 {
371 case WPR_WCHAR:
372 result.wchar_view = va_arg( *args, WCHAR ); break;
373 case WPR_CHAR:
374 result.char_view = va_arg( *args, CHAR ); break;
375 case WPR_STRING:
376 result.lpcstr_view = va_arg( *args, LPCSTR); break;
377 case WPR_WSTRING:
378 result.lpcwstr_view = va_arg( *args, LPCWSTR); break;
379 case WPR_HEXA:
380 case WPR_SIGNED:
381 case WPR_UNSIGNED:
382 result.int_view = va_arg( *args, INT ); break;
383 default:
384 result.wchar_view = 0; break;
385 }
386 return result;
387}
388
389/***********************************************************************
390 * wvsnprintfA (Not a Windows API)
391 */
392INT WINAPI wvsnprintfA( LPSTR buffer, UINT maxlen, LPCSTR spec,
393 va_list args )
394{
395 WPRINTF_FORMAT format;
396 LPSTR p = buffer;
397 UINT i, len;
398 CHAR number[20];
399 WPRINTF_DATA argData;
400
401 while (*spec && (maxlen > 1))
402 {
403 if (*spec != '%') { *p++ = *spec++; maxlen--; continue; }
404 spec++;
405 if (*spec == '%') { *p++ = *spec++; maxlen--; continue; }
406 spec += WPRINTF_ParseFormatA( spec, &format );
407 argData = WPRINTF_ExtractVAPtr( &format, &args );
408 len = WPRINTF_GetLen( &format, &argData, number, maxlen - 1 );
409 if (!(format.flags & WPRINTF_LEFTALIGN))
410 for (i = format.precision; i < format.width; i++, maxlen--)
411 *p++ = ' ';
412 switch(format.type)
413 {
414 case WPR_WCHAR:
415 *p = argData.wchar_view;
416 if (*p != '\0') p++;
417 else if (format.width > 1) *p++ = ' ';
418 else len = 0;
419 break;
420 case WPR_CHAR:
421 *p = argData.char_view;
422 if (*p != '\0') p++;
423 else if (format.width > 1) *p++ = ' ';
424 else len = 0;
425 break;
426 case WPR_STRING:
427 memcpy( p, argData.lpcstr_view, len );
428 p += len;
429 break;
430 case WPR_WSTRING:
431 {
432 LPCWSTR ptr = argData.lpcwstr_view;
433 for (i = 0; i < len; i++) *p++ = (CHAR)*ptr++;
434 }
435 break;
436 case WPR_HEXA:
437 if ((format.flags & WPRINTF_PREFIX_HEX) && (maxlen > 3))
438 {
439 *p++ = '0';
440 *p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x';
441 maxlen -= 2;
442 len -= 2;
443 format.precision -= 2;
444 format.width -= 2;
445 }
446 /* fall through */
447 case WPR_SIGNED:
448 case WPR_UNSIGNED:
449 for (i = len; i < format.precision; i++, maxlen--) *p++ = '0';
450 memcpy( p, number, len );
451 p += len;
452 /* Go to the next arg */
453 break;
454 case WPR_UNKNOWN:
455 continue;
456 }
457 if (format.flags & WPRINTF_LEFTALIGN)
458 for (i = format.precision; i < format.width; i++, maxlen--)
459 *p++ = ' ';
460 maxlen -= len;
461 }
462 *p = 0;
463 //TRACE("%s\n",buffer);
464 return (maxlen > 1) ? (INT)(p - buffer) : -1;
465}
466
467
468/***********************************************************************
469 * wvsnprintfW (Not a Windows API)
470 */
471INT WINAPI wvsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec,
472 va_list args )
473{
474 WPRINTF_FORMAT format;
475 LPWSTR p = buffer;
476 UINT i, len;
477 CHAR number[20];
478
479 while (*spec && (maxlen > 1))
480 {
481 if (*spec != '%') { *p++ = *spec++; maxlen--; continue; }
482 spec++;
483 if (*spec == '%') { *p++ = *spec++; maxlen--; continue; }
484 spec += WPRINTF_ParseFormatW( spec, &format );
485 len = WPRINTF_GetLen( &format, (WPRINTF_DATA*)args, number, maxlen - 1 );
486 if (!(format.flags & WPRINTF_LEFTALIGN))
487 for (i = format.precision; i < format.width; i++, maxlen--)
488 *p++ = ' ';
489 switch(format.type)
490 {
491 case WPR_WCHAR:
492 *p = va_arg( args, WCHAR );
493 if (*p != '\0') p++;
494 else if (format.width > 1) *p++ = ' ';
495 else len = 0;
496 break;
497 case WPR_CHAR:
498 *p = (WCHAR)va_arg( args, CHAR );
499 if (*p != '\0') p++;
500 else if (format.width > 1) *p++ = ' ';
501 else len = 0;
502 break;
503 case WPR_STRING:
504 {
505 LPCSTR ptr = va_arg( args, LPCSTR );
506 for (i = 0; i < len; i++) *p++ = (WCHAR)*ptr++;
507 }
508 break;
509 case WPR_WSTRING:
510 if (len) memcpy( p, va_arg( args, LPCWSTR ), len * sizeof(WCHAR) );
511 p += len;
512 break;
513 case WPR_HEXA:
514 if ((format.flags & WPRINTF_PREFIX_HEX) && (maxlen > 3))
515 {
516 *p++ = '0';
517 *p++ = (format.flags & WPRINTF_UPPER_HEX) ? 'X' : 'x';
518 maxlen -= 2;
519 len -= 2;
520 format.precision -= 2;
521 format.width -= 2;
522 }
523 /* fall through */
524 case WPR_SIGNED:
525 case WPR_UNSIGNED:
526 for (i = len; i < format.precision; i++, maxlen--) *p++ = '0';
527 for (i = 0; i < len; i++) *p++ = (WCHAR)number[i];
528 (void)va_arg( args, INT ); /* Go to the next arg */
529 break;
530 case WPR_UNKNOWN:
531 continue;
532 }
533 if (format.flags & WPRINTF_LEFTALIGN)
534 for (i = format.precision; i < format.width; i++, maxlen--)
535 *p++ = ' ';
536 maxlen -= len;
537 }
538 *p = 0;
539 return (maxlen > 1) ? (INT)(p - buffer) : -1;
540}
541
542/***********************************************************************
543 * wsnprintfA (Not a Windows API)
544 */
545INT WINAPIV wsnprintfA( LPSTR buffer, UINT maxlen, LPCSTR spec, ... )
546{
547 va_list valist;
548 INT res;
549
550 va_start( valist, spec );
551 res = wvsnprintfA( buffer, maxlen, spec, valist );
552 va_end( valist );
553 return res;
554}
555
556/***********************************************************************
557 * wsnprintfW (Not a Windows API)
558 */
559INT WINAPIV wsnprintfW( LPWSTR buffer, UINT maxlen, LPCWSTR spec, ... )
560{
561 va_list valist;
562 INT res;
563
564 va_start( valist, spec );
565 res = wvsnprintfW( buffer, maxlen, spec, valist );
566 va_end( valist );
567 return res;
568}
569
570/******************************************************************************
571 * OLE2NLS_CheckLocale [intern]
572 */
573static LCID OLE2NLS_CheckLocale (LCID locale)
574{
575 if (!locale)
576 { locale = LOCALE_SYSTEM_DEFAULT;
577 }
578
579 if (locale == LOCALE_SYSTEM_DEFAULT)
580 { return GetSystemDefaultLCID();
581 }
582 else if (locale == LOCALE_USER_DEFAULT)
583 { return GetUserDefaultLCID();
584 }
585 else
586 { return locale;
587 }
588}
589
590/******************************************************************************
591 * OLE_GetFormatA [Internal]
592 *
593 * FIXME
594 * If datelen == 0, it should return the reguired string length.
595 *
596 This function implements stuff for GetDateFormat() and
597 GetTimeFormat().
598 d single-digit (no leading zero) day (of month)
599 dd two-digit day (of month)
600 ddd short day-of-week name
601 dddd long day-of-week name
602 M single-digit month
603 MM two-digit month
604 MMM short month name
605 MMMM full month name
606 y two-digit year, no leading 0
607 yy two-digit year
608 yyyy four-digit year
609 gg era string
610 h hours with no leading zero (12-hour)
611 hh hours with full two digits
612 H hours with no leading zero (24-hour)
613 HH hours with full two digits
614 m minutes with no leading zero
615 mm minutes with full two digits
616 s seconds with no leading zero
617 ss seconds with full two digits
618 t time marker (A or P)
619 tt time marker (AM, PM)
620 '' used to quote literal characters
621 '' (within a quoted string) indicates a literal '
622 These functions REQUIRE valid locale, date, and format.
623 */
624static INT OLE_GetFormatA(LCID locale,
625 DWORD flags,
626 DWORD tflags,
627 LPSYSTEMTIME xtime,
628 LPCSTR _format, /*in*/
629 LPSTR date, /*out*/
630 INT datelen)
631{
632 INT inpos, outpos;
633 int count, type, inquote, Overflow;
634 char buf[40];
635 char format[40];
636 char * pos;
637 int buflen;
638 const char * _dgfmt[] = { "%d", "%02d" };
639 const char ** dgfmt = _dgfmt - 1;
640 dprintf(("KERNEL32: OLE_GetFormatA"));
641
642 if(datelen == 0) {
643 //FIXME_(ole)("datelen = 0, returning 255\n");
644 return 255;
645 }
646 /* initalize state variables and output buffer */
647 inpos = outpos = 0;
648 count = 0; inquote = 0; Overflow = 0;
649 type = '\0';
650 date[0] = buf[0] = '\0';
651
652 strcpy(format,_format);
653 /* alter the formatstring, while it works for all languages now in wine
654 its possible that it fails when the time looks like ss:mm:hh as example*/
655 if (tflags & (TIME_NOMINUTESORSECONDS))
656 { if ((pos = strstr ( format, ":mm")) != 0)
657 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
658 }
659 }
660 if (tflags & (TIME_NOSECONDS))
661 { if ((pos = strstr ( format, ":ss")) != 0)
662 { memcpy ( pos, pos+3, strlen(format)-(pos-format)-2 );
663 }
664 }
665
666 for (inpos = 0;; inpos++) {
667 /* TRACE(ole, "STATE inpos=%2d outpos=%2d count=%d inquote=%d type=%c buf,date = %c,%c\n", inpos, outpos, count, inquote, type, buf[inpos], date[outpos]); */
668 if (inquote) {
669 if (format[inpos] == '\'') {
670 if (format[inpos+1] == '\'') {
671 inpos += 1;
672 date[outpos++] = '\'';
673 } else {
674 inquote = 0;
675 continue; /* we did nothing to the output */
676 }
677 } else if (format[inpos] == '\0') {
678 date[outpos++] = '\0';
679 if (outpos > datelen) Overflow = 1;
680 break;
681 } else {
682 date[outpos++] = format[inpos];
683 if (outpos > datelen) {
684 Overflow = 1;
685 date[outpos-1] = '\0'; /* this is the last place where
686 it's safe to write */
687 break;
688 }
689 }
690 } else if ( (count && (format[inpos] != type))
691 || count == 4
692 || (count == 2 && strchr("ghHmst", type)) )
693 {
694 if (type == 'd') {
695 if (count == 4) {
696 GetLocaleInfoA(locale,
697 LOCALE_SDAYNAME1
698 + xtime->wDayOfWeek - 1,
699 buf, sizeof(buf));
700 } else if (count == 3) {
701 GetLocaleInfoA(locale,
702 LOCALE_SABBREVDAYNAME1
703 + xtime->wDayOfWeek - 1,
704 buf, sizeof(buf));
705 } else {
706 sprintf(buf, dgfmt[count], xtime->wDay);
707 }
708 } else if (type == 'M') {
709 if (count == 3) {
710 GetLocaleInfoA(locale,
711 LOCALE_SABBREVMONTHNAME1
712 + xtime->wMonth - 1,
713 buf, sizeof(buf));
714 } else if (count == 4) {
715 GetLocaleInfoA(locale,
716 LOCALE_SMONTHNAME1
717 + xtime->wMonth - 1,
718 buf, sizeof(buf));
719 } else {
720 sprintf(buf, dgfmt[count], xtime->wMonth);
721 }
722 } else if (type == 'y') {
723 if (count == 4) {
724 sprintf(buf, "%d", xtime->wYear);
725 } else if (count == 3) {
726 strcpy(buf, "yyy");
727 //WARN_(ole)("unknown format, c=%c, n=%d\n", type, count);
728 } else {
729 sprintf(buf, dgfmt[count], xtime->wYear % 100);
730 }
731 } else if (type == 'g') {
732 if (count == 2) {
733 //FIXME_(ole)("LOCALE_ICALENDARTYPE unimp.\n");
734 strcpy(buf, "AD");
735 } else {
736 strcpy(buf, "g");
737 //WARN_(ole)("unknown format, c=%c, n=%d\n", type, count);
738 }
739 } else if (type == 'h') {
740 /* gives us hours 1:00 -- 12:00 */
741 sprintf(buf, dgfmt[count], (xtime->wHour-1)%12 +1);
742 } else if (type == 'H') {
743 /* 24-hour time */
744 sprintf(buf, dgfmt[count], xtime->wHour);
745 } else if ( type == 'm') {
746 sprintf(buf, dgfmt[count], xtime->wMinute);
747 } else if ( type == 's') {
748 sprintf(buf, dgfmt[count], xtime->wSecond);
749 } else if (type == 't') {
750 if (count == 1) {
751 sprintf(buf, "%c", (xtime->wHour < 12) ? 'A' : 'P');
752 } else if (count == 2) {
753 /* sprintf(buf, "%s", (xtime->wHour < 12) ? "AM" : "PM"); */
754 GetLocaleInfoA(locale,
755 (xtime->wHour<12)
756 ? LOCALE_S1159 : LOCALE_S2359,
757 buf, sizeof(buf));
758 }
759 };
760 /* we need to check the next char in the format string
761 again, no matter what happened */
762 inpos--;
763
764 /* add the contents of buf to the output */
765 buflen = strlen(buf);
766 if (outpos + buflen < datelen) {
767 date[outpos] = '\0'; /* for strcat to hook onto */
768 strcat(date, buf);
769 outpos += buflen;
770 } else {
771 date[outpos] = '\0';
772 strncat(date, buf, datelen - outpos);
773 date[datelen - 1] = '\0';
774 SetLastError(ERROR_INSUFFICIENT_BUFFER);
775 //WARN_(ole)("insufficient buffer\n");
776 return 0;
777 }
778 /* reset the variables we used to keep track of this item */
779 count = 0;
780 type = '\0';
781 } else if (format[inpos] == '\0') {
782 /* we can't check for this at the loop-head, because
783 that breaks the printing of the last format-item */
784 date[outpos] = '\0';
785 break;
786 } else if (count) {
787 /* continuing a code for an item */
788 count +=1;
789 continue;
790 } else if (strchr("hHmstyMdg", format[inpos])) {
791 type = format[inpos];
792 count = 1;
793 continue;
794 } else if (format[inpos] == '\'') {
795 inquote = 1;
796 continue;
797 } else {
798 date[outpos++] = format[inpos];
799 }
800 /* now deal with a possible buffer overflow */
801 if (outpos >= datelen) {
802 date[datelen - 1] = '\0';
803 SetLastError(ERROR_INSUFFICIENT_BUFFER);
804 return 0;
805 }
806 }
807
808 if (Overflow) {
809 SetLastError(ERROR_INSUFFICIENT_BUFFER);
810 };
811 /* finish it off with a string terminator */
812 outpos++;
813 /* sanity check */
814 if (outpos > datelen-1) outpos = datelen-1;
815 date[outpos] = '\0';
816
817 //TRACE_(ole)("OLE_GetFormatA returns string '%s', len %d\n",
818 // date, outpos);
819 return outpos;
820}
821
822/******************************************************************************
823 * OLE_GetFormatW [INTERNAL]
824 */
825static INT OLE_GetFormatW(LCID locale, DWORD flags, DWORD tflags,
826 LPSYSTEMTIME xtime,
827 LPCWSTR format,
828 LPWSTR output, INT outlen)
829{
830 INT inpos, outpos;
831 int count, type=0, inquote;
832 int Overflow; /* loop check */
833 WCHAR buf[40];
834 int buflen=0;
835 WCHAR arg0[] = {0}, arg1[] = {'%','d',0};
836 WCHAR arg2[] = {'%','0','2','d',0};
837 WCHAR *argarr[3];
838 int datevars=0, timevars=0;
839 argarr[0] = arg0;
840 argarr[1] = arg1;
841 argarr[2] = arg2;
842
843 dprintf(("KERNEL32: OLE_GetFormatW"));
844
845 if(outlen == 0) {
846 //FIXME_(ole)("outlen = 0, returning 255\n");
847 return 255;
848 }
849 /* initialize state variables */
850 inpos = outpos = 0;
851 count = 0;
852 inquote = Overflow = 0;
853 /* this is really just a sanity check */
854 output[0] = buf[0] = 0;
855
856 /* this loop is the core of the function */
857 for (inpos = 0; /* we have several break points */ ; inpos++) {
858 if (inquote) {
859 if (format[inpos] == (WCHAR) '\'') {
860 if (format[inpos+1] == '\'') {
861 inpos++;
862 output[outpos++] = '\'';
863 } else {
864 inquote = 0;
865 continue;
866 }
867 } else if (format[inpos] == 0) {
868 output[outpos++] = 0;
869 if (outpos > outlen) Overflow = 1;
870 break; /* normal exit (within a quote) */
871 } else {
872 output[outpos++] = format[inpos]; /* copy input */
873 if (outpos > outlen) {
874 Overflow = 1;
875 output[outpos-1] = 0;
876 break;
877 }
878 }
879 } else if ( (count && (format[inpos] != type))
880 || ( (count==4 && type =='y') ||
881 (count==4 && type =='M') ||
882 (count==4 && type =='d') ||
883 (count==2 && type =='g') ||
884 (count==2 && type =='h') ||
885 (count==2 && type =='H') ||
886 (count==2 && type =='m') ||
887 (count==2 && type =='s') ||
888 (count==2 && type =='t') ) ) {
889 if (type == 'd') {
890 if (count == 3) {
891 GetLocaleInfoW(locale,
892 LOCALE_SDAYNAME1 + xtime->wDayOfWeek -1,
893 buf, sizeof(buf)/sizeof(WCHAR) );
894 } else if (count == 3) {
895 GetLocaleInfoW(locale,
896 LOCALE_SABBREVDAYNAME1 +
897 xtime->wDayOfWeek -1,
898 buf, sizeof(buf)/sizeof(WCHAR) );
899 } else {
900 wsnprintfW(buf, 5, argarr[count], xtime->wDay );
901 };
902 } else if (type == 'M') {
903 if (count == 4) {
904 GetLocaleInfoW(locale, LOCALE_SMONTHNAME1 +
905 xtime->wMonth -1, buf,
906 sizeof(buf)/sizeof(WCHAR) );
907 } else if (count == 3) {
908 GetLocaleInfoW(locale, LOCALE_SABBREVMONTHNAME1 +
909 xtime->wMonth -1, buf,
910 sizeof(buf)/sizeof(WCHAR) );
911 } else {
912 wsnprintfW(buf, 5, argarr[count], xtime->wMonth);
913 }
914 } else if (type == 'y') {
915 if (count == 4) {
916 wsnprintfW(buf, 6, argarr[1] /* "%d" */,
917 xtime->wYear);
918 } else if (count == 3) {
919 lstrcpynAtoW(buf, "yyy", 5);
920 } else {
921 wsnprintfW(buf, 6, argarr[count],
922 xtime->wYear % 100);
923 }
924 } else if (type == 'g') {
925 if (count == 2) {
926 //FIXME_(ole)("LOCALE_ICALENDARTYPE unimplemented\n");
927 lstrcpynAtoW(buf, "AD", 5);
928 } else {
929 /* Win API sez we copy it verbatim */
930 lstrcpynAtoW(buf, "g", 5);
931 }
932 } else if (type == 'h') {
933 /* hours 1:00-12:00 --- is this right? */
934 wsnprintfW(buf, 5, argarr[count],
935 (xtime->wHour-1)%12 +1);
936 } else if (type == 'H') {
937 wsnprintfW(buf, 5, argarr[count],
938 xtime->wHour);
939 } else if (type == 'm' ) {
940 wsnprintfW(buf, 5, argarr[count],
941 xtime->wMinute);
942 } else if (type == 's' ) {
943 wsnprintfW(buf, 5, argarr[count],
944 xtime->wSecond);
945 } else if (type == 't') {
946 GetLocaleInfoW(locale, (xtime->wHour < 12) ?
947 LOCALE_S1159 : LOCALE_S2359,
948 buf, sizeof(buf) );
949 if (count == 1) {
950 buf[1] = 0;
951 }
952}
953 /* no matter what happened, we need to check this next
954 character the next time we loop through */
955 inpos--;
956 /* cat buf onto the output */
957 outlen = lstrlenW(buf);
958 if (outpos + buflen < outlen) {
959 lstrcpyW( output + outpos, buf );
960 outpos += buflen;
961 } else {
962 lstrcpynW( output + outpos, buf, outlen - outpos );
963 Overflow = 1;
964 break; /* Abnormal exit */
965 }
966 /* reset the variables we used this time */
967 count = 0;
968 type = '\0';
969 } else if (format[inpos] == 0) {
970 /* we can't check for this at the beginning, because that
971 would keep us from printing a format spec that ended the
972 string */
973 output[outpos] = 0;
974 break; /* NORMAL EXIT */
975 } else if (count) {
976 /* how we keep track of the middle of a format spec */
977 count++;
978 continue;
979 } else if ( (datevars && (format[inpos]=='d' ||
980 format[inpos]=='M' ||
981 format[inpos]=='y' ||
982 format[inpos]=='g') ) ||
983 (timevars && (format[inpos]=='H' ||
984 format[inpos]=='h' ||
985 format[inpos]=='m' ||
986 format[inpos]=='s' ||
987 format[inpos]=='t') ) ) {
988 type = format[inpos];
989 count = 1;
990 continue;
991 } else if (format[inpos] == '\'') {
992 inquote = 1;
993 continue;
994 } else {
995 /* unquoted literals */
996 output[outpos++] = format[inpos];
997 }
998 }
999 if (Overflow) {
1000 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1001 //WARN_(ole)(" buffer overflow\n");
1002 };
1003 /* final string terminator and sanity check */
1004 outpos++;
1005 if (outpos > outlen-1) outpos = outlen-1;
1006 output[outpos] = '0';
1007 //TRACE_(ole)(" returning %s\n", debugstr_w(output));
1008
1009 return (!Overflow) ? outlen : 0;
1010
1011}
1012
1013/******************************************************************************
1014 * GetTimeFormat32A [KERNEL32.422]
1015 * Makes an ASCII string of the time
1016 *
1017 * Formats date according to format, or locale default if format is
1018 * NULL. The format consists of literal characters and fields as follows:
1019 *
1020 * h hours with no leading zero (12-hour)
1021 * hh hours with full two digits
1022 * H hours with no leading zero (24-hour)
1023 * HH hours with full two digits
1024 * m minutes with no leading zero
1025 * mm minutes with full two digits
1026 * s seconds with no leading zero
1027 * ss seconds with full two digits
1028 * t time marker (A or P)
1029 * tt time marker (AM, PM)
1030 *
1031 */
1032INT WINAPI
1033GetTimeFormatA(LCID locale, /* in */
1034 DWORD flags, /* in */
1035 LPSYSTEMTIME xtime, /* in */
1036 LPCSTR format, /* in */
1037 LPSTR timestr, /* out */
1038 INT timelen /* in */)
1039{ char format_buf[40];
1040 LPCSTR thisformat;
1041 SYSTEMTIME t;
1042 LPSYSTEMTIME thistime;
1043 LCID thislocale=0;
1044 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
1045 INT ret;
1046
1047 dprintf(("KERNEL32: GetTimeFormatA"));
1048 //TRACE_(ole)("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,xtime,format,timestr,timelen);
1049 thislocale = OLE2NLS_CheckLocale ( locale );
1050 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
1051 { //FIXME_(ole)("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
1052 }
1053
1054 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
1055 if (format == NULL)
1056 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
1057 { thislocale = GetSystemDefaultLCID();
1058 }
1059 GetLocaleInfoA(thislocale, thisflags, format_buf, sizeof(format_buf));
1060 thisformat = format_buf;
1061 }
1062 else
1063 { thisformat = format;
1064 }
1065
1066 if (xtime == NULL) /* NULL means use the current local time*/
1067 { GetLocalTime(&t);
1068 thistime = &t;
1069 }
1070 else
1071 { thistime = xtime;
1072 }
1073 ret = OLE_GetFormatA(thislocale, thisflags, flags, thistime, thisformat,
1074 timestr, timelen);
1075 return ret;
1076}
1077
1078/******************************************************************************
1079 * GetTimeFormat32W [KERNEL32.423]
1080 * Makes a Unicode string of the time
1081 */
1082INT WINAPI
1083GetTimeFormatW(LCID locale, /* in */
1084 DWORD flags, /* in */
1085 LPSYSTEMTIME xtime, /* in */
1086 LPCWSTR format, /* in */
1087 LPWSTR timestr, /* out */
1088 INT timelen /* in */)
1089{ WCHAR format_buf[40];
1090 LPCWSTR thisformat;
1091 SYSTEMTIME t;
1092 LPSYSTEMTIME thistime;
1093 LCID thislocale=0;
1094 DWORD thisflags=LOCALE_STIMEFORMAT; /* standart timeformat */
1095 INT ret;
1096
1097 dprintf(("KERNEL32: GetTimeFormatW"));
1098 //TRACE_(ole)("GetTimeFormat(0x%04lx,0x%08lx,%p,%s,%p,%d)\n",locale,flags,
1099 //xtime,debugstr_w(format),timestr,timelen);
1100 thislocale = OLE2NLS_CheckLocale ( locale );
1101 if ( flags & (TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT ))
1102 { //FIXME_(ole)("TIME_NOTIMEMARKER or TIME_FORCE24HOURFORMAT not implemented\n");
1103 }
1104
1105 flags &= (TIME_NOSECONDS | TIME_NOMINUTESORSECONDS); /* mask for OLE_GetFormatA*/
1106 if (format == NULL)
1107 { if (flags & LOCALE_NOUSEROVERRIDE) /*use system default*/
1108 { thislocale = GetSystemDefaultLCID();
1109 }
1110 GetLocaleInfoW(thislocale, thisflags, format_buf, 40);
1111 thisformat = format_buf;
1112 }
1113 else
1114 { thisformat = format;
1115 }
1116
1117 if (xtime == NULL) /* NULL means use the current local time*/
1118 { GetSystemTime(&t);
1119 thistime = &t;
1120 }
1121 else
1122 { thistime = xtime;
1123 }
1124 ret = OLE_GetFormatW(thislocale, thisflags, flags, thistime, thisformat,
1125 timestr, timelen);
1126 return ret;
1127}
1128
1129/******************************************************************************
1130 * GetDateFormat32A [KERNEL32.310]
1131 * Makes an ASCII string of the date
1132 *
1133 * This function uses format to format the date, or, if format
1134 * is NULL, uses the default for the locale. format is a string
1135 * of literal fields and characters as follows:
1136 *
1137 * - d single-digit (no leading zero) day (of month)
1138 * - dd two-digit day (of month)
1139 * - ddd short day-of-week name
1140 * - dddd long day-of-week name
1141 * - M single-digit month
1142 * - MM two-digit month
1143 * - MMM short month name
1144 * - MMMM full month name
1145 * - y two-digit year, no leading 0
1146 * - yy two-digit year
1147 * - yyyy four-digit year
1148 * - gg era string
1149 *
1150 */
1151INT WINAPI GetDateFormatA(LCID locale,DWORD flags,
1152 LPSYSTEMTIME xtime,
1153 LPCSTR format, LPSTR date,INT datelen)
1154{
1155 char format_buf[40];
1156 LPCSTR thisformat;
1157 SYSTEMTIME t;
1158 LPSYSTEMTIME thistime;
1159 LCID thislocale;
1160 INT ret;
1161
1162 dprintf(("KERNEL32: GetDateFormatA\n"));
1163
1164 if (!locale) {
1165 locale = LOCALE_SYSTEM_DEFAULT;
1166 };
1167
1168 if (locale == LOCALE_SYSTEM_DEFAULT) {
1169 thislocale = GetSystemDefaultLCID();
1170 } else if (locale == LOCALE_USER_DEFAULT) {
1171 thislocale = GetUserDefaultLCID();
1172 } else {
1173 thislocale = locale;
1174 };
1175 if (xtime == NULL) {
1176 GetSystemTime(&t);
1177 thistime = &t;
1178 } else {
1179 thistime = xtime;
1180 };
1181 if (format == NULL) {
1182 GetLocaleInfoA(thislocale, ((flags&DATE_LONGDATE)
1183 ? LOCALE_SLONGDATE
1184 : LOCALE_SSHORTDATE),
1185 format_buf, sizeof(format_buf));
1186 thisformat = format_buf;
1187 } else {
1188 thisformat = format;
1189 };
1190
1191 ret = OLE_GetFormatA(thislocale, flags, 0, thistime, thisformat,
1192 date, datelen);
1193
1194 return ret;
1195}
1196/******************************************************************************
1197 * GetDateFormat32W [KERNEL32.311]
1198 * Makes a Unicode string of the date
1199 *
1200 * Acts the same as GetDateFormat32A(), except that it's Unicode.
1201 * Accepts & returns sizes as counts of Unicode characters.
1202 *
1203 */
1204INT WINAPI GetDateFormatW(LCID locale,DWORD flags,
1205 LPSYSTEMTIME xtime,
1206 LPCWSTR format,
1207 LPWSTR date, INT datelen)
1208{
1209 WCHAR format_buf[40];
1210 LPWSTR thisformat;
1211 SYSTEMTIME t;
1212 LPSYSTEMTIME thistime;
1213 LCID thislocale;
1214 INT ret;
1215
1216 dprintf(("KERNEL32: GetDateFormatW\n"));
1217
1218 if (!locale) {
1219 locale = LOCALE_SYSTEM_DEFAULT;
1220 };
1221
1222 if (locale == LOCALE_SYSTEM_DEFAULT) {
1223 thislocale = GetSystemDefaultLCID();
1224 } else if (locale == LOCALE_USER_DEFAULT) {
1225 thislocale = GetUserDefaultLCID();
1226 } else {
1227 thislocale = locale;
1228 };
1229 if (xtime == NULL) {
1230 GetSystemTime(&t);
1231 thistime = &t;
1232 } else {
1233 thistime = xtime;
1234 };
1235 if (format == NULL) {
1236 GetLocaleInfoW(thislocale, ((flags&DATE_LONGDATE)
1237 ? LOCALE_SLONGDATE
1238 : LOCALE_SSHORTDATE),
1239 format_buf, sizeof(format_buf));
1240 thisformat = format_buf;
1241 } else {
1242 thisformat = (WCHAR*)format;
1243 };
1244
1245 ret = OLE_GetFormatW(thislocale, flags, 0, thistime, thisformat,
1246 date, datelen);
1247
1248 return ret;
1249}
1250/**************************************************************************
1251 * EnumTimeFormats32A (KERNEL32.210)
1252 */
1253BOOL WINAPI EnumTimeFormatsA(
1254 TIMEFMT_ENUMPROCA lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
1255{
1256 dprintf(("KERNEL32: EnumTimeFormatsA: only US English supported\n"));
1257
1258 if(!lpTimeFmtEnumProc)
1259 {
1260 SetLastError(ERROR_INVALID_PARAMETER);
1261 return FALSE;
1262 }
1263 if(dwFlags)
1264 {
1265 //FIXME_(ole)("Unknown time format (%ld)\n", dwFlags);
1266 }
1267
1268 if(!(*lpTimeFmtEnumProc)("h:mm:ss tt")) return TRUE;
1269 if(!(*lpTimeFmtEnumProc)("hh:mm:ss tt")) return TRUE;
1270 if(!(*lpTimeFmtEnumProc)("H:mm:ss")) return TRUE;
1271 if(!(*lpTimeFmtEnumProc)("HH:mm:ss")) return TRUE;
1272
1273 return TRUE;
1274}
1275/**************************************************************************
1276 * EnumTimeFormats32W (KERNEL32.211)
1277 */
1278BOOL WINAPI EnumTimeFormatsW(
1279 TIMEFMT_ENUMPROCW lpTimeFmtEnumProc, LCID Locale, DWORD dwFlags)
1280{
1281 WCHAR buf[20];
1282
1283 dprintf(("KERNEL32: EnumTimeFormatsW: only US English supported\n"));
1284
1285 if(!lpTimeFmtEnumProc)
1286 {
1287 SetLastError(ERROR_INVALID_PARAMETER);
1288 return FALSE;
1289 }
1290 if(dwFlags)
1291 {
1292 //FIXME_(ole)("Unknown time format (%ld)\n", dwFlags);
1293 }
1294
1295 AsciiToUnicode("h:mm:ss tt",buf);
1296 if(!(*lpTimeFmtEnumProc)(buf)) return TRUE;
1297 AsciiToUnicode("hh:mm:ss tt",buf);
1298 if(!(*lpTimeFmtEnumProc)(buf)) return TRUE;
1299 AsciiToUnicode("H:mm:ss",buf);
1300 if(!(*lpTimeFmtEnumProc)(buf)) return TRUE;
1301 AsciiToUnicode("HH:mm:ss",buf);
1302 if(!(*lpTimeFmtEnumProc)(buf)) return TRUE;
1303
1304 return TRUE;
1305}
1306/*****************************************************************************
1307 * Name : DWORD GetSystemTimeAsFileTime
1308 * Purpose : The GetSystemTimeAsFileTime function obtains the current system
1309 * date and time. The information is in Coordinated Universal Time (UTC) format.
1310 * Parameters: LLPFILETIME lLPSYSTEMTIMEAsFileTime
1311 * Variables :
1312 * Result :
1313 * Remark :
1314 * Status : UNTESTED
1315 *
1316 * Author : Patrick Haller [Mon, 1998/06/15 08:00]
1317 *****************************************************************************/
1318
1319VOID WIN32API GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)
1320{
1321 FILETIME ft; /* code sequence from WIN32.HLP */
1322 SYSTEMTIME st;
1323
1324 dprintf(("KERNEL32: GetSystemTimeAsFileTime(%08xh)\n", lpSystemTimeAsFileTime));
1325
1326 GetSystemTime(&st);
1327 SystemTimeToFileTime(&st, &ft);
1328}
1329/**************************************************************************
1330 * EnumDateFormats32A (KERNEL32.198)
1331 */
1332BOOL WINAPI EnumDateFormatsA(
1333 DATEFMT_ENUMPROCA lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
1334{
1335 dprintf(("KERNEL32: EnumDateFormatsA: only US English supported\n"));
1336
1337 if(!lpDateFmtEnumProc)
1338 {
1339 SetLastError(ERROR_INVALID_PARAMETER);
1340 return FALSE;
1341 }
1342 switch(dwFlags)
1343 {
1344 case DATE_SHORTDATE:
1345 if(!(*lpDateFmtEnumProc)("M/d/yy")) return TRUE;
1346 if(!(*lpDateFmtEnumProc)("M/d/yyyy")) return TRUE;
1347 if(!(*lpDateFmtEnumProc)("MM/dd/yy")) return TRUE;
1348 if(!(*lpDateFmtEnumProc)("MM/dd/yyyy")) return TRUE;
1349 if(!(*lpDateFmtEnumProc)("yy/MM/dd")) return TRUE;
1350 if(!(*lpDateFmtEnumProc)("dd-MMM-yy")) return TRUE;
1351 return TRUE;
1352 case DATE_LONGDATE:
1353 if(!(*lpDateFmtEnumProc)("dddd, MMMM dd, yyyy")) return TRUE;
1354 if(!(*lpDateFmtEnumProc)("MMMM dd, yyyy")) return TRUE;
1355 if(!(*lpDateFmtEnumProc)("dddd, dd MMMM, yyyy")) return TRUE;
1356 if(!(*lpDateFmtEnumProc)("dd MMMM, yyyy")) return TRUE;
1357 return TRUE;
1358 default:
1359 //FIXME_(ole)("Unknown date format (%ld)\n", dwFlags);
1360 SetLastError(ERROR_INVALID_PARAMETER);
1361 return FALSE;
1362 }
1363}
1364/**************************************************************************
1365 * EnumDateFormats32W (KERNEL32.199)
1366 */
1367BOOL WINAPI EnumDateFormatsW(
1368 DATEFMT_ENUMPROCW lpDateFmtEnumProc, LCID Locale, DWORD dwFlags)
1369{
1370 WCHAR buf[50];
1371
1372 dprintf(("KERNEL32: EnumDateFormatsW: only US English supported\n"));
1373
1374 if(!lpDateFmtEnumProc)
1375 {
1376 SetLastError(ERROR_INVALID_PARAMETER);
1377 return FALSE;
1378 }
1379 switch(dwFlags)
1380 {
1381 case DATE_SHORTDATE:
1382 AsciiToUnicode("M/d/yy",buf);
1383 if(!(*lpDateFmtEnumProc)(buf)) return TRUE;
1384 AsciiToUnicode("M/d/yyyy",buf);
1385 if(!(*lpDateFmtEnumProc)(buf)) return TRUE;
1386 AsciiToUnicode("MM/dd/yy",buf);
1387 if(!(*lpDateFmtEnumProc)(buf)) return TRUE;
1388 AsciiToUnicode("MM/dd/yyyy",buf);
1389 if(!(*lpDateFmtEnumProc)(buf)) return TRUE;
1390 AsciiToUnicode("yy/MM/dd",buf);
1391 if(!(*lpDateFmtEnumProc)(buf)) return TRUE;
1392 AsciiToUnicode("dd-MMM-yy",buf);
1393 if(!(*lpDateFmtEnumProc)(buf)) return TRUE;
1394 return TRUE;
1395 case DATE_LONGDATE:
1396 AsciiToUnicode("dddd, MMMM dd, yyyy",buf);
1397 if(!(*lpDateFmtEnumProc)(buf)) return TRUE;
1398 AsciiToUnicode("MMMM dd, yyyy",buf);
1399 if(!(*lpDateFmtEnumProc)(buf)) return TRUE;
1400 AsciiToUnicode("dddd, dd MMMM, yyyy",buf);
1401 if(!(*lpDateFmtEnumProc)(buf)) return TRUE;
1402 AsciiToUnicode("dd MMMM, yyyy",buf);
1403 if(!(*lpDateFmtEnumProc)(buf)) return TRUE;
1404 return TRUE;
1405 default:
1406 //FIXME_(ole)("Unknown date format (%ld)\n", dwFlags);
1407 SetLastError(ERROR_INVALID_PARAMETER);
1408 return FALSE;
1409 }
1410}
1411
Note: See TracBrowser for help on using the repository browser.