Commit 7303b8c4 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Use callback based printf in cprintf functions family.

parent 056dfb26
...@@ -298,37 +298,30 @@ int CDECL _kbhit(void) ...@@ -298,37 +298,30 @@ int CDECL _kbhit(void)
return retval; return retval;
} }
static int puts_clbk_console_a(void *ctx, int len, const char *str)
{
LOCK_CONSOLE;
if(!WriteConsoleA(MSVCRT_console_out, str, len, NULL, NULL))
len = -1;
UNLOCK_CONSOLE;
return len;
}
static int puts_clbk_console_w(void *ctx, int len, const MSVCRT_wchar_t *str)
{
LOCK_CONSOLE;
if(!WriteConsoleW(MSVCRT_console_out, str, len, NULL, NULL))
len = -1;
UNLOCK_CONSOLE;
return len;
}
/********************************************************************* /*********************************************************************
* _vcprintf (MSVCRT.@) * _vcprintf (MSVCRT.@)
*/ */
int CDECL _vcprintf(const char* format, __ms_va_list valist) int CDECL _vcprintf(const char* format, __ms_va_list valist)
{ {
char buf[2048]; return pf_printf_a(puts_clbk_console_a, NULL, format, NULL, FALSE, FALSE, arg_clbk_valist, NULL, valist);
LPWSTR formatW = NULL;
DWORD sz;
pf_output out;
int retval;
out.unicode = FALSE;
out.buf.A = out.grow.A = buf;
out.used = 0;
out.len = sizeof(buf);
sz = MultiByteToWideChar( CP_ACP, 0, format, -1, NULL, 0 );
formatW = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) );
MultiByteToWideChar( CP_ACP, 0, format, -1, formatW, sz );
if ((retval = pf_vsnprintf( &out, formatW, NULL, FALSE, valist )) > 0)
{
LOCK_CONSOLE;
retval = _cputs( out.buf.A );
UNLOCK_CONSOLE;
}
HeapFree( GetProcessHeap(), 0, formatW );
if (out.buf.A != buf)
MSVCRT_free (out.buf.A);
return retval;
} }
/********************************************************************* /*********************************************************************
...@@ -352,24 +345,7 @@ int CDECL _cprintf(const char* format, ...) ...@@ -352,24 +345,7 @@ int CDECL _cprintf(const char* format, ...)
*/ */
int CDECL _vcwprintf(const MSVCRT_wchar_t* format, __ms_va_list valist) int CDECL _vcwprintf(const MSVCRT_wchar_t* format, __ms_va_list valist)
{ {
MSVCRT_wchar_t buf[2048]; return pf_printf_w(puts_clbk_console_w, NULL, format, NULL, FALSE, FALSE, arg_clbk_valist, NULL, valist);
pf_output out;
int retval;
out.unicode = TRUE;
out.buf.W = out.grow.W = buf;
out.used = 0;
out.len = sizeof(buf) / sizeof(buf[0]);
if ((retval = pf_vsnprintf( &out, format, NULL, FALSE, valist )) >= 0)
{
LOCK_CONSOLE;
retval = _cputws( out.buf.W );
UNLOCK_CONSOLE;
}
if (out.buf.W != buf)
MSVCRT_free (out.buf.W);
return retval;
} }
/********************************************************************* /*********************************************************************
......
...@@ -943,11 +943,12 @@ typedef union _printf_arg ...@@ -943,11 +943,12 @@ typedef union _printf_arg
LONGLONG get_longlong; LONGLONG get_longlong;
double get_double; double get_double;
} printf_arg; } printf_arg;
typedef printf_arg (*args_clbk)(void*, int, size_t, __ms_va_list*); typedef printf_arg (*args_clbk)(void*, int, int, __ms_va_list*);
int pf_printf_a(puts_clbk_a, void*, const char*, MSVCRT__locale_t, int pf_printf_a(puts_clbk_a, void*, const char*, MSVCRT__locale_t,
BOOL, BOOL, args_clbk, void*, __ms_va_list); BOOL, BOOL, args_clbk, void*, __ms_va_list);
int pf_printf_w(puts_clbk_w, void*, const MSVCRT_wchar_t*, MSVCRT__locale_t, int pf_printf_w(puts_clbk_w, void*, const MSVCRT_wchar_t*, MSVCRT__locale_t,
BOOL, BOOL, args_clbk, void*, __ms_va_list); BOOL, BOOL, args_clbk, void*, __ms_va_list);
printf_arg arg_clbk_valist(void*, int, int, __ms_va_list*);
#define MSVCRT__OVERFLOW 3 #define MSVCRT__OVERFLOW 3
#define MSVCRT__UNDERFLOW 4 #define MSVCRT__UNDERFLOW 4
......
...@@ -1091,6 +1091,29 @@ int pf_vsnprintf( pf_output *out, const WCHAR *format, ...@@ -1091,6 +1091,29 @@ int pf_vsnprintf( pf_output *out, const WCHAR *format,
} }
/********************************************************************* /*********************************************************************
* arg_clbk_valist (INTERNAL)
*/
printf_arg arg_clbk_valist(void *ctx, int arg_pos, int type, __ms_va_list *valist)
{
printf_arg ret;
if(type == VT_I8)
ret.get_longlong = va_arg(*valist, LONGLONG);
else if(type == VT_INT)
ret.get_int = va_arg(*valist, int);
else if(type == VT_R8)
ret.get_double = va_arg(*valist, double);
else if(type == VT_PTR)
ret.get_ptr = va_arg(*valist, void*);
else {
ERR("Incorrect type\n");
ret.get_int = 0;
}
return ret;
}
/*********************************************************************
* vsnprintf_internal (INTERNAL) * vsnprintf_internal (INTERNAL)
*/ */
static inline int vsnprintf_internal( char *str, MSVCRT_size_t len, const char *format, static inline int vsnprintf_internal( char *str, MSVCRT_size_t len, const char *format,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment