Piotr Caban : msvcrt: Use callback based printf in cprintf functions family .

Alexandre Julliard julliard at winehq.org
Mon Apr 25 12:47:14 CDT 2011


Module: wine
Branch: master
Commit: 7303b8c4dbae5dc8d0904aefc7c4ef4bd524225b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=7303b8c4dbae5dc8d0904aefc7c4ef4bd524225b

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Wed Apr 20 14:42:26 2011 +0200

msvcrt: Use callback based printf in cprintf functions family.

---

 dlls/msvcrt/console.c |   62 +++++++++++++++----------------------------------
 dlls/msvcrt/msvcrt.h  |    3 +-
 dlls/msvcrt/wcs.c     |   23 ++++++++++++++++++
 3 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/dlls/msvcrt/console.c b/dlls/msvcrt/console.c
index e23ff3e..41e5e0d 100644
--- a/dlls/msvcrt/console.c
+++ b/dlls/msvcrt/console.c
@@ -298,37 +298,30 @@ int CDECL _kbhit(void)
   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.@)
  */
 int CDECL _vcprintf(const char* format, __ms_va_list valist)
 {
-  char buf[2048];
-  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;
+    return pf_printf_a(puts_clbk_console_a, NULL, format, NULL, FALSE, FALSE, arg_clbk_valist, NULL, valist);
 }
 
 /*********************************************************************
@@ -352,24 +345,7 @@ int CDECL _cprintf(const char* format, ...)
  */
 int CDECL _vcwprintf(const MSVCRT_wchar_t* format, __ms_va_list valist)
 {
-  MSVCRT_wchar_t buf[2048];
-  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;
+    return pf_printf_w(puts_clbk_console_w, NULL, format, NULL, FALSE, FALSE, arg_clbk_valist, NULL, valist);
 }
 
 /*********************************************************************
diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h
index 677bb57..979a05b 100644
--- a/dlls/msvcrt/msvcrt.h
+++ b/dlls/msvcrt/msvcrt.h
@@ -943,11 +943,12 @@ typedef union _printf_arg
     LONGLONG get_longlong;
     double get_double;
 } 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,
         BOOL, BOOL, args_clbk, void*, __ms_va_list);
 int pf_printf_w(puts_clbk_w, void*, const MSVCRT_wchar_t*, MSVCRT__locale_t,
         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__UNDERFLOW 4
diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c
index a4c817b..a7cec7c 100644
--- a/dlls/msvcrt/wcs.c
+++ b/dlls/msvcrt/wcs.c
@@ -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)
  */
 static inline int vsnprintf_internal( char *str, MSVCRT_size_t len, const char *format,




More information about the wine-cvs mailing list