You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2007/07/13 00:00:36 UTC

svn commit: r555789 - in /incubator/stdcxx/trunk/tests/src: fmt_bits.cpp fmt_defs.h printf.cpp

Author: sebor
Date: Thu Jul 12 15:00:35 2007
New Revision: 555789

URL: http://svn.apache.org/viewvc?view=rev&rev=555789
Log:
2007-07-12  Martin Sebor  <se...@roguewave.com>

	* fmt_defs.h (_rw_fmtlasterror): Declared new function to format
	Windows GetLastError() messages. 
	* fmt_bits.cpp (_rw_fmtlasterror): Defined.
	* printf.cpp (_rw_vasnprintf_ext): Called _rw_fmtlasterror() to process
	the %{E} directive. Set spec.param.int_ to the argument value in the
	the %{m} directive handler to allow it to be referenced in subsequent
	paramno directives.

Modified:
    incubator/stdcxx/trunk/tests/src/fmt_bits.cpp
    incubator/stdcxx/trunk/tests/src/fmt_defs.h
    incubator/stdcxx/trunk/tests/src/printf.cpp

Modified: incubator/stdcxx/trunk/tests/src/fmt_bits.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/fmt_bits.cpp?view=diff&rev=555789&r1=555788&r2=555789
==============================================================================
--- incubator/stdcxx/trunk/tests/src/fmt_bits.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/fmt_bits.cpp Thu Jul 12 15:00:35 2007
@@ -48,6 +48,10 @@
 #  include <wctype.h>   // for iswalpha(), ...
 #endif   // _RWSTD_NO_WCTYPE_H
 
+#ifdef _WIN32
+#  include <windows.h>   // for FormatMessage()
+#endif   // _WIN32
+
 #include <ios>
 #include <iostream>
 #include <locale>
@@ -1000,6 +1004,40 @@
     newspec.fl_pound = 0;
 
     return _rw_fmtstr (newspec, buf, str, _RWSTD_SIZE_MAX);
+}
+
+/********************************************************************/
+
+/* extern */ int
+_rw_fmtlasterror (const FmtSpec &spec, Buffer &buf, int val)
+{
+#ifdef _WIN32
+
+    LPVOID pmsg;
+    FormatMessage (  FORMAT_MESSAGE_ALLOCATE_BUFFER
+                   | FORMAT_MESSAGE_FROM_SYSTEM
+                   | FORMAT_MESSAGE_IGNORE_INSERTS,
+                   0, (DWORD)val,
+                   MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+                   (LPTSTR)&pmsg,
+                   0, 0);
+
+    FmtSpec newspec (spec);
+    newspec.width    = 0;
+    newspec.fl_pound = 0;
+
+    const int result = _rw_fmtstr (newspec, buf, pmsg, _RWSTD_SIZE_MAX);
+
+    LocalFree (pmsg);
+
+    return result;
+
+#else   // if !defined (_WIN32)
+
+    return _rw_fmterrno (spec, buf, val);
+
+#endif   // _WIN32
+
 }
 
 /********************************************************************/

Modified: incubator/stdcxx/trunk/tests/src/fmt_defs.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/fmt_defs.h?view=diff&rev=555789&r1=555788&r2=555789
==============================================================================
--- incubator/stdcxx/trunk/tests/src/fmt_defs.h (original)
+++ incubator/stdcxx/trunk/tests/src/fmt_defs.h Thu Jul 12 15:00:35 2007
@@ -186,6 +186,10 @@
 extern int
 _rw_fmterrno (const FmtSpec&, Buffer&, int);
 
+// format Windows GetLastError(), or errno value/name
+extern int
+_rw_fmtlasterror (const FmtSpec&, Buffer&, int);
+
 // format the name/value of an LC_XXX constant/environment variable
 extern int
 _rw_fmtlc (const FmtSpec&, Buffer&, int);

Modified: incubator/stdcxx/trunk/tests/src/printf.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/src/printf.cpp?view=diff&rev=555789&r1=555788&r2=555789
==============================================================================
--- incubator/stdcxx/trunk/tests/src/printf.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/printf.cpp Thu Jul 12 15:00:35 2007
@@ -57,7 +57,7 @@
    // define macros to enable Win98 + WinNT support in <windows.h>
 #  define _WIN32_WINNT 0x0410
 #  define WINVER       0x400
-#  include <windows.h>   // for IsDebuggerPresent()
+#  include <windows.h>   // for GetLastError(), IsDebuggerPresent()
 #else
 #  include <dlfcn.h>
 #endif   // _WIN{32,64}
@@ -2694,6 +2694,15 @@
         }
         break;
 
+    case 'E':   // %{E} -- Windows GetLastError(), errno elsewhere
+#ifdef _WIN32
+        spec.param.int_ = -1 == spec.width ? GetLastError () : spec.width;
+#else   // if !defined (_WIN32)
+        spec.param.int_ = -1 == spec.width ? errno : spec.width;
+#endif   // _WIN32
+        len = _rw_fmtlasterror (spec, buf, spec.param.int_);
+        break;
+
     case 'e':   // %{e}, %{Ae}
         if (spec.mod == spec.mod_ext_A) {   // array of floating point values
             spec.param.ptr_ = PARAM (ptr_, pva);
@@ -2771,7 +2780,8 @@
         break;
 
     case 'm':   // %{m} -- errno
-        len = _rw_fmterrno (spec, buf, -1 == spec.width ? errno : spec.width);
+        spec.param.int_ = -1 == spec.width ? errno : spec.width;
+        len = _rw_fmterrno (spec, buf, spec.param.int_);
         break;
 
     case 'M':   // %{M}, %{LM}