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