return args->args[nr - 1];
}
-
/**********************************************************************
- * format_insertA (internal)
+ * format_insert (internal)
*/
-static LPCWSTR format_insertA( int insert, LPCWSTR format, DWORD flags,
- struct format_args *args, LPWSTR *result )
+static LPCWSTR format_insert( BOOL unicode_caller, int insert, LPCWSTR format,
+ DWORD flags, struct format_args *args,
+ LPWSTR *result )
{
static const WCHAR fmt_lu[] = {'%','l','u',0};
WCHAR *wstring = NULL, *p, fmt[256];
if (*format != '!') /* simple string */
{
- char *str = (char *)get_arg( insert, flags, args );
- DWORD length = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
- *result = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) );
- MultiByteToWideChar(CP_ACP, 0, str, -1, *result, length);
- return format;
- }
-
- format++;
- p = fmt;
- *p++ = '%';
-
- while (*format == '0' ||
- *format == '+' ||
- *format == '-' ||
- *format == ' ' ||
- *format == '*' ||
- *format == '#')
- {
- if (*format == '*')
+ arg = get_arg( insert, flags, args );
+ if (unicode_caller)
{
- p += sprintfW( p, fmt_lu, get_arg( insert, flags, args ));
- insert = -1;
- format++;
- }
- else *p++ = *format++;
- }
- while (isdigit(*format)) *p++ = *format++;
-
- if (*format == '.')
- {
- *p++ = *format++;
- if (*format == '*')
- {
- p += sprintfW( p, fmt_lu, get_arg( insert, flags, args ));
- insert = -1;
- format++;
- }
- else
- while (isdigit(*format)) *p++ = *format++;
- }
-
- /* replicate MS bug: drop an argument when using va_list with width/precision */
- if (insert == -1 && args->list) args->last--;
- arg = get_arg( insert, flags, args );
-
- /* check for wide string format */
- if ((format[0] == 'l' && format[1] == 's') ||
- (format[0] == 'l' && format[1] == 'S') ||
- (format[0] == 'w' && format[1] == 's') ||
- (format[0] == 'S'))
- {
- *p++ = 's';
- }
- /* check for wide character format */
- else if ((format[0] == 'l' && format[1] == 'c') ||
- (format[0] == 'l' && format[1] == 'C') ||
- (format[0] == 'w' && format[1] == 'c') ||
- (format[0] == 'C'))
- {
- *p++ = 'c';
- }
- /* check for ascii string format */
- else if ((format[0] == 'h' && format[1] == 's') ||
- (format[0] == 'h' && format[1] == 'S') ||
- (format[0] == 's'))
- {
- DWORD len = MultiByteToWideChar( CP_ACP, 0, (char *)arg, -1, NULL, 0 );
- wstring = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
- MultiByteToWideChar( CP_ACP, 0, (char *)arg, -1, wstring, len );
- arg = (ULONG_PTR)wstring;
- *p++ = 's';
- }
- /* check for ascii character format */
- else if ((format[0] == 'h' && format[1] == 'c') ||
- (format[0] == 'h' && format[1] == 'C') ||
- (format[0] == 'c'))
- {
- char ch = arg;
- wstring = HeapAlloc( GetProcessHeap(), 0, 2 * sizeof(WCHAR) );
- MultiByteToWideChar( CP_ACP, 0, &ch, 1, wstring, 1 );
- wstring[1] = 0;
- arg = (ULONG_PTR)wstring;
- *p++ = 's';
- }
- /* FIXME: handle I64 etc. */
- else while (*format && *format != '!') *p++ = *format++;
-
- *p = 0;
- size = 256;
- for (;;)
- {
- WCHAR *ret = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR));
- int needed = snprintfW( ret, size, fmt, arg );
- if (needed == -1 || needed >= size)
- {
- HeapFree( GetProcessHeap(), 0, ret );
- size = max( needed + 1, size * 2 );
+ WCHAR *str = (WCHAR *)arg;
+ *result = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1) * sizeof(WCHAR) );
+ strcpyW( *result, str );
}
else
{
- *result = ret;
- break;
+ char *str = (char *)get_arg( insert, flags, args );
+ DWORD length = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
+ *result = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) );
+ MultiByteToWideChar( CP_ACP, 0, str, -1, *result, length );
}
- }
-
- while (*format && *format != '!') format++;
- if (*format == '!') format++;
-
- HeapFree( GetProcessHeap(), 0, wstring );
- return format;
-}
-
-
-/**********************************************************************
- * format_insertW (internal)
- */
-static LPCWSTR format_insertW( int insert, LPCWSTR format, DWORD flags,
- struct format_args *args, LPWSTR *result )
-{
- static const WCHAR fmt_lu[] = {'%','l','u',0};
- WCHAR *wstring = NULL, *p, fmt[256];
- ULONG_PTR arg;
- int size;
-
- if (*format != '!') /* simple string */
- {
- WCHAR *str = (WCHAR *)get_arg( insert, flags, args );
- *result = HeapAlloc( GetProcessHeap(), 0, (strlenW(str) + 1) * sizeof(WCHAR) );
- strcpyW( *result, str );
return format;
}
/* check for ascii string format */
if ((format[0] == 'h' && format[1] == 's') ||
(format[0] == 'h' && format[1] == 'S') ||
- (format[0] == 'S'))
+ (unicode_caller && format[0] == 'S') ||
+ (!unicode_caller && format[0] == 's'))
{
- DWORD len = MultiByteToWideChar( CP_ACP, 0, (char *)arg, -1, /*FIXME*/ NULL, 0 );
+ DWORD len = MultiByteToWideChar( CP_ACP, 0, (char *)arg, -1, NULL, 0 );
wstring = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, (char *)arg, -1, wstring, len );
arg = (ULONG_PTR)wstring;
/* check for ascii character format */
else if ((format[0] == 'h' && format[1] == 'c') ||
(format[0] == 'h' && format[1] == 'C') ||
- (format[0] == 'C'))
+ (unicode_caller && format[0] == 'C') ||
+ (!unicode_caller && format[0] == 'c'))
{
char ch = arg;
wstring = HeapAlloc( GetProcessHeap(), 0, 2 * sizeof(WCHAR) );
/* check for wide string format */
else if ((format[0] == 'l' && format[1] == 's') ||
(format[0] == 'l' && format[1] == 'S') ||
- (format[0] == 'w' && format[1] == 's'))
+ (format[0] == 'w' && format[1] == 's') ||
+ (!unicode_caller && format[0] == 'S'))
{
*p++ = 's';
}
/* check for wide character format */
else if ((format[0] == 'l' && format[1] == 'c') ||
(format[0] == 'l' && format[1] == 'C') ||
- (format[0] == 'w' && format[1] == 'c'))
+ (format[0] == 'w' && format[1] == 'c') ||
+ (!unicode_caller && format[0] == 'C'))
{
*p++ = 'c';
}
f++;
break;
}
- f = format_insertA( insertnr, f, dwFlags, format_args, &str );
+ f = format_insert( FALSE, insertnr, f, dwFlags, format_args, &str );
for (x = str; *x; x++) ADD_TO_T(*x);
HeapFree( GetProcessHeap(), 0, str );
break;
f++;
break;
}
- f = format_insertW( insertnr, f, dwFlags, format_args, &str );
+ f = format_insert( TRUE, insertnr, f, dwFlags, format_args, &str );
for (x = str; *x; x++) ADD_TO_T(*x);
HeapFree( GetProcessHeap(), 0, str );
break;