Revision: 17571
          http://sourceforge.net/p/edk2/code/17571
Author:   shenshushi
Date:     2015-06-08 05:37:31 +0000 (Mon, 08 Jun 2015)
Log Message:
-----------
MdePkg: Add %u and %lu support for PrintLib and DebugLib.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin....@intel.com>
Reviewed-by: Liming Gao <liming....@intel.com>

Modified Paths:
--------------
    trunk/edk2/MdePkg/Include/Library/PrintLib.h
    trunk/edk2/MdePkg/Library/BasePrintLib/PrintLibInternal.c
    trunk/edk2/MdePkg/Library/BasePrintLib/PrintLibInternal.h

Modified: trunk/edk2/MdePkg/Include/Library/PrintLib.h
===================================================================
--- trunk/edk2/MdePkg/Include/Library/PrintLib.h        2015-06-08 05:34:08 UTC 
(rev 17570)
+++ trunk/edk2/MdePkg/Include/Library/PrintLib.h        2015-06-08 05:37:31 UTC 
(rev 17571)
@@ -2,7 +2,7 @@
   Provides services to print a formatted string to a buffer. All combinations 
of
   Unicode and ASCII strings are supported.
 
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials are licensed and made available 
under 
 the terms and conditions of the BSD License that accompanies this 
distribution.  
 The full text of the license may be found at
@@ -89,6 +89,9 @@
     - d
       - The argument is a signed decimal number.  If the flag 'L' is not 
specified, 
         then the argument is assumed to be size int.  
+    - u
+      - The argument is a unsigned decimal number.  If the flag 'L' is not 
specified, 
+        then the argument is assumed to be size int.
     - p
       - The argument is a pointer that is a (VOID *), and it is printed as an 
         unsigned hexadecimal number  The characters used are 0..9 and A..F.

Modified: trunk/edk2/MdePkg/Library/BasePrintLib/PrintLibInternal.c
===================================================================
--- trunk/edk2/MdePkg/Library/BasePrintLib/PrintLibInternal.c   2015-06-08 
05:34:08 UTC (rev 17570)
+++ trunk/edk2/MdePkg/Library/BasePrintLib/PrintLibInternal.c   2015-06-08 
05:37:31 UTC (rev 17571)
@@ -1,7 +1,7 @@
 /** @file
   Print Library internal worker functions.
 
-  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -547,10 +547,18 @@
         //
         // break skipped on purpose
         //
+      case 'u':
+        if ((Flags & RADIX_HEX) == 0) {
+          Flags &= ~((UINTN) (PREFIX_SIGN));
+          Flags |= UNSIGNED_TYPE;
+        }
+        //
+        // break skipped on purpose
+        //
       case 'd':
         if ((Flags & LONG_TYPE) == 0) {
           //
-          // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed 
to be type "int".
+          // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are 
assumed to be type "int".
           // This assumption is made so the format string definition is 
compatible with the ANSI C
           // Specification for formatted strings.  It is recommended that the 
Base Types be used 
           // everywhere, but in this one case, compliance with ANSI C is more 
important, and 
@@ -584,17 +592,27 @@
             Flags &= ~((UINTN) PREFIX_ZERO);
             Precision = 1;
           }
-          if (Value < 0) {
+          if (Value < 0 && (Flags & UNSIGNED_TYPE) == 0) {
             Flags |= PREFIX_SIGN;
             Prefix = '-';
             Value = -Value;
+          } else if ((Flags & UNSIGNED_TYPE) != 0 && (Flags & LONG_TYPE) == 0) 
{
+            //
+            // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are 
assumed to be type "int".
+            // This assumption is made so the format string definition is 
compatible with the ANSI C
+            // Specification for formatted strings.  It is recommended that 
the Base Types be used 
+            // everywhere, but in this one case, compliance with ANSI C is 
more important, and 
+            // provides an implementation that is compatible with that largest 
possible set of CPU 
+            // architectures.  This is why the type "unsigned int" is used in 
this one case.
+            //
+            Value = (unsigned int)Value;
           }
         } else {
           Radix = 16;
           Comma = FALSE;
           if ((Flags & LONG_TYPE) == 0 && Value < 0) {
             //
-            // 'd','x', and 'X' that are not preceded by 'l' or 'L' are 
assumed to be type "int".
+            // 'd', 'u', 'x', and 'X' that are not preceded by 'l' or 'L' are 
assumed to be type "int".
             // This assumption is made so the format string definition is 
compatible with the ANSI C
             // Specification for formatted strings.  It is recommended that 
the Base Types be used 
             // everywhere, but in this one case, compliance with ANSI C is 
more important, and 

Modified: trunk/edk2/MdePkg/Library/BasePrintLib/PrintLibInternal.h
===================================================================
--- trunk/edk2/MdePkg/Library/BasePrintLib/PrintLibInternal.h   2015-06-08 
05:34:08 UTC (rev 17570)
+++ trunk/edk2/MdePkg/Library/BasePrintLib/PrintLibInternal.h   2015-06-08 
05:37:31 UTC (rev 17571)
@@ -1,7 +1,7 @@
 /** @file
   Base Print Library instance Internal Functions definition.
 
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -34,6 +34,7 @@
 #define PRECISION             BIT11
 #define ARGUMENT_REVERSED     BIT12
 #define COUNT_ONLY_NO_PRINT   BIT13
+#define UNSIGNED_TYPE         BIT14
 
 //
 // Record date and time information


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
edk2-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to