]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Sync FrameworkUefiLib with the MdePkg UefiLib
authormdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 14 Jun 2010 23:32:07 +0000 (23:32 +0000)
committermdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 14 Jun 2010 23:32:07 +0000 (23:32 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10583 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkPkg/Library/FrameworkUefiLib/Console.c
IntelFrameworkPkg/Library/FrameworkUefiLib/UefiDriverModel.c
IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c
IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibInternal.h
IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibPrint.c

index fa14135cc8d3dbe7b2a828c61385738124c23d4c..a8ecc27e64d97731703fe2ba7407d1a3dd409ce0 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   This module provide help function for displaying unicode string.\r
 \r
-  Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials                          \r
   are licensed and made available under the terms and conditions of the BSD License         \r
   which accompanies this distribution.  The full text of the license may be found at        \r
@@ -12,6 +12,9 @@
 \r
 **/\r
 \r
+\r
+\r
+\r
 #include "UefiLibInternal.h"\r
 \r
 typedef struct {\r
@@ -196,6 +199,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[] = {
   @retval 0             The width if UnicodeChar could not be determined.\r
   @retval 1             UnicodeChar is a narrow glyph.\r
   @retval 2             UnicodeChar is a wide glyph.\r
+\r
 **/\r
 UINTN\r
 EFIAPI\r
@@ -211,7 +215,6 @@ GetGlyphWidth (
   Item  = NULL;\r
   Low   = 0;\r
   High  = (sizeof (mUnicodeWidthTable)) / (sizeof (UNICODE_WIDTH_ENTRY)) - 1;\r
-  \r
   while (Low <= High) {    \r
     Index = (Low + High) >> 1;\r
     Item  = &(mUnicodeWidthTable[Index]);\r
@@ -219,6 +222,7 @@ GetGlyphWidth (
       if (UnicodeChar <= Item->WChar) {\r
         break;\r
       }\r
+\r
       return 0;\r
     }\r
 \r
@@ -255,6 +259,7 @@ GetGlyphWidth (
   @param  String   A pointer to a Null-terminated Unicode string.\r
 \r
   @return          The display length of the Null-terminated Unicode string specified by String.\r
+  \r
 **/\r
 UINTN\r
 EFIAPI\r
@@ -282,3 +287,177 @@ UnicodeStringDisplayLength (
 \r
   return Length;\r
 }\r
+\r
+/**\r
+  Draws a dialog box to the console output device specified by \r
+  ConOut defined in the EFI_SYSTEM_TABLE and waits for a keystroke\r
+  from the console input device specified by ConIn defined in the \r
+  EFI_SYSTEM_TABLE.\r
+\r
+  If there are no strings in the variable argument list, then ASSERT().\r
+  If all the strings in the variable argument list are empty, then ASSERT().\r
+\r
+  @param[in]   Attribute  Specifies the foreground and background color of the popup.\r
+  @param[out]  Key        A pointer to the EFI_KEY value of the key that was \r
+                          pressed.  This is an optional parameter that may be NULL.\r
+                          If it is NULL then no wait for a keypress will be performed.\r
+  @param[in]  ...         The variable argument list that contains pointers to Null-\r
+                          terminated Unicode strings to display in the dialog box.  \r
+                          The variable argument list is terminated by a NULL.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+CreatePopUp (\r
+  IN  UINTN          Attribute,                \r
+  OUT EFI_INPUT_KEY  *Key,      OPTIONAL\r
+  ...\r
+  )\r
+{\r
+  VA_LIST                          Args;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *ConOut;\r
+  EFI_SIMPLE_TEXT_OUTPUT_MODE      SavedConsoleMode;\r
+  UINTN                            Columns;\r
+  UINTN                            Rows;\r
+  UINTN                            Column;\r
+  UINTN                            Row;\r
+  UINTN                            NumberOfLines;\r
+  UINTN                            MaxLength;\r
+  CHAR16                           *String;\r
+  UINTN                            Length;\r
+  CHAR16                           *Line;\r
+  UINTN                            EventIndex;\r
+\r
+  //\r
+  // Determine the length of the longest line in the popup and the the total \r
+  // number of lines in the popup\r
+  //\r
+  VA_START (Args, Key);\r
+  MaxLength = 0;\r
+  NumberOfLines = 0;\r
+  while ((String = VA_ARG (Args, CHAR16 *)) != NULL) {\r
+    MaxLength = MAX (MaxLength, StrLen (String));\r
+    NumberOfLines++;\r
+  }\r
+  VA_END (Args);\r
+\r
+  //\r
+  // If the total number of lines in the popup is zero, then ASSERT()\r
+  //\r
+  ASSERT (NumberOfLines != 0);\r
+\r
+  //\r
+  // If the maximum length of all the strings is zero, then ASSERT()\r
+  //\r
+  ASSERT (MaxLength != 0);\r
+\r
+  //\r
+  // Cache a pointer to the Simple Text Output Protocol in the EFI System Table\r
+  //\r
+  ConOut = gST->ConOut;\r
+  \r
+  //\r
+  // Save the current console cursor position and attributes\r
+  //\r
+  CopyMem (&SavedConsoleMode, ConOut->Mode, sizeof (SavedConsoleMode));\r
+\r
+  //\r
+  // Retrieve the number of columns and rows in the current console mode\r
+  //\r
+  ConOut->QueryMode (ConOut, SavedConsoleMode.Mode, &Columns, &Rows);\r
+\r
+  //\r
+  // Disable cursor and set the foreground and background colors specified by Attribute\r
+  //\r
+  ConOut->EnableCursor (ConOut, FALSE);\r
+  ConOut->SetAttribute (ConOut, Attribute);\r
+\r
+  //\r
+  // Limit NumberOfLines to height of the screen minus 3 rows for the box itself\r
+  //\r
+  NumberOfLines = MIN (NumberOfLines, Rows - 3);\r
+\r
+  //\r
+  // Limit MaxLength to width of the screen minus 2 columns for the box itself\r
+  //\r
+  MaxLength = MIN (MaxLength, Columns - 2);\r
+\r
+  //\r
+  // Compute the starting row and starting column for the popup\r
+  //\r
+  Row    = (Rows - (NumberOfLines + 3)) / 2;\r
+  Column = (Columns - (MaxLength + 2)) / 2;\r
+\r
+  //\r
+  // Allocate a buffer for a single line of the popup with borders and a Null-terminator\r
+  //\r
+  Line = AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16));\r
+  ASSERT (Line != NULL);\r
+\r
+  //\r
+  // Draw top of popup box   \r
+  //\r
+  SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL);\r
+  Line[0]             = BOXDRAW_DOWN_RIGHT;\r
+  Line[MaxLength + 1] = BOXDRAW_DOWN_LEFT;\r
+  Line[MaxLength + 2] = L'\0';\r
+  ConOut->SetCursorPosition (ConOut, Column, Row++);\r
+  ConOut->OutputString (ConOut, Line);\r
+\r
+  //\r
+  // Draw middle of the popup with strings\r
+  //\r
+  VA_START (Args, Key);\r
+  while ((String = VA_ARG (Args, CHAR16 *)) != NULL && NumberOfLines > 0) {\r
+    Length = StrLen (String);\r
+    SetMem16 (Line, (MaxLength + 2) * 2, L' ');\r
+    if (Length <= MaxLength) {\r
+      //\r
+      // Length <= MaxLength\r
+      //\r
+      CopyMem (Line + 1 + (MaxLength - Length) / 2, String , Length * sizeof (CHAR16));\r
+    } else {\r
+      //\r
+      // Length > MaxLength\r
+      //\r
+      CopyMem (Line + 1, String + (Length - MaxLength) / 2 , MaxLength * sizeof (CHAR16));\r
+    }\r
+    Line[0]             = BOXDRAW_VERTICAL;\r
+    Line[MaxLength + 1] = BOXDRAW_VERTICAL;\r
+    Line[MaxLength + 2] = L'\0';\r
+    ConOut->SetCursorPosition (ConOut, Column, Row++);\r
+    ConOut->OutputString (ConOut, Line);\r
+    NumberOfLines--;\r
+  }\r
+  VA_END (Args);\r
+\r
+  //\r
+  // Draw bottom of popup box\r
+  //\r
+  SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL);\r
+  Line[0]             = BOXDRAW_UP_RIGHT;\r
+  Line[MaxLength + 1] = BOXDRAW_UP_LEFT;\r
+  Line[MaxLength + 2] = L'\0';\r
+  ConOut->SetCursorPosition (ConOut, Column, Row++);\r
+  ConOut->OutputString (ConOut, Line);\r
+\r
+  //\r
+  // Free the allocated line buffer\r
+  //\r
+  FreePool (Line);\r
+\r
+  //\r
+  // Restore the cursor visibility, position, and attributes\r
+  //\r
+  ConOut->EnableCursor      (ConOut, SavedConsoleMode.CursorVisible);\r
+  ConOut->SetCursorPosition (ConOut, SavedConsoleMode.CursorColumn, SavedConsoleMode.CursorRow);\r
+  ConOut->SetAttribute      (ConOut, SavedConsoleMode.Attribute);\r
+\r
+  //\r
+  // Wait for a keystroke\r
+  //\r
+  if (Key != NULL) {\r
+    gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
+    gST->ConIn->ReadKeyStroke (gST->ConIn, Key);\r
+  }\r
+}\r
index 6b36f3d78fd39e2d76bf03141c33a0617ea35a2e..39ab8deb4904c3153cf0b231e07f3775364e209a 100644 (file)
@@ -13,6 +13,7 @@
 \r
 **/ \r
 \r
+\r
 #include "UefiLibInternal.h"\r
 \r
 /**\r
@@ -35,6 +36,7 @@
   @retval EFI_SUCCESS           The protocol installation is completed successfully.\r
   @retval EFI_OUT_OF_RESOURCES  There was not enough system resources to install the protocol.\r
   @retval Others                Status from gBS->InstallMultipleProtocolInterfaces().\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -54,6 +56,9 @@ EfiLibInstallDriverBinding (
                   &gEfiDriverBindingProtocolGuid, DriverBinding,\r
                   NULL\r
                   );\r
+  //\r
+  // ASSERT if the call to InstallMultipleProtocolInterfaces() failed\r
+  //\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
@@ -65,6 +70,7 @@ EfiLibInstallDriverBinding (
   return Status;\r
 }\r
 \r
+\r
 /**\r
   Installs and completes the initialization of a Driver Binding Protocol instance and\r
   optionally installs the Component Name, Driver Configuration and Driver Diagnostics Protocols.\r
@@ -105,9 +111,7 @@ EfiLibInstallAllDriverProtocols (
 {\r
   EFI_STATUS                                  Status;\r
 \r
-  if (DriverBinding == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
+  ASSERT (DriverBinding != NULL);\r
 \r
   if (DriverDiagnostics == NULL || FeaturePcdGet(PcdDriverDiagnosticsDisable)) {\r
     if (DriverConfiguration == NULL) {\r
@@ -291,17 +295,18 @@ EfiLibInstallDriverBindingComponentName2 (
   Configuration, Driver Configuration 2, Driver Diagnostics, and Driver Diagnostics 2 Protocols.\r
 \r
   Initializes a driver by installing the Driver Binding Protocol together with the optional\r
-  Component Name, optional Component Name 2, optional Driver Configuration, optional Driver\r
-  Configuration 2, optional Driver Diagnostic, and optional Driver Diagnostic 2 Protocols\r
-  onto the driver's DriverBindingHandle. DriverBindingHandle is typically the same as the\r
-  driver's ImageHandle, but it can be different if the driver produces multiple Driver Binding Protocols. \r
+  Component Name, optional Component Name 2, optional Driver Configuration, optional Driver Configuration 2,\r
+  optional Driver Diagnostic, and optional Driver Diagnostic 2 Protocols onto the driver's DriverBindingHandle.\r
+  DriverBindingHandle is typically the same as the driver's ImageHandle, but it can be different if the driver\r
+  produces multiple Driver Binding Protocols. \r
   If DriverBinding is NULL, then ASSERT(). \r
   If the installation fails, then ASSERT().  \r
 \r
+\r
   @param  ImageHandle           The image handle of the driver.\r
   @param  SystemTable           The EFI System Table that was passed to the driver's entry point.\r
   @param  DriverBinding         A Driver Binding Protocol instance that this driver is producing.\r
-  @param  DriverBindingHandle   The handle that DriverBinding is to be installe onto.  If this\r
+  @param  DriverBindingHandle   The handle that DriverBinding is to be installed onto.  If this\r
                                 parameter is NULL, then a new handle is created.\r
   @param  ComponentName         A Component Name Protocol instance that this driver is producing.\r
   @param  ComponentName2        A Component Name 2 Protocol instance that this driver is producing.\r
index 7d28b700dc6acde9fc4b4ac666a7a063e0f0e64e..554af2281e1c84d578e39518c538a5d4f2032c37 100644 (file)
@@ -5,7 +5,7 @@
   EFI Driver Model related protocols, manage Unicode string tables for UEFI Drivers, \r
   and print messages on the console output and standard error devices.\r
 \r
-  Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -92,15 +92,17 @@ EfiGetSystemConfigurationTable (
   instances specified by ProtocolGuid.\r
 \r
   This function causes the notification function to be executed for every protocol of type\r
-  ProtocolGuid instance that exists in the system when this function is invoked.\r
-  In addition, every time a protocol of type ProtocolGuid instance is installed or reinstalled,\r
-  the notification function is also executed.  This function returns the notification event\r
-  that was created. \r
+  ProtocolGuid instance that exists in the system when this function is invoked. If there are\r
+  no instances of ProtocolGuid in the handle database at the time this function is invoked,\r
+  then the notification function is still executed one time. In addition, every time a protocol\r
+  of type ProtocolGuid instance is installed or reinstalled, the notification function is also\r
+  executed. This function returns the notification event that was created. \r
   If ProtocolGuid is NULL, then ASSERT().\r
   If NotifyTpl is not a legal TPL value, then ASSERT().\r
   If NotifyFunction is NULL, then ASSERT().\r
   If Registration is NULL, then ASSERT().\r
 \r
+\r
   @param  ProtocolGuid    Supplies GUID of the protocol upon whose installation the event is fired.\r
   @param  NotifyTpl       Supplies the task priority level of the event notifications.\r
   @param  NotifyFunction  Supplies the function to notify when the event is signaled.\r
@@ -143,7 +145,7 @@ EfiCreateProtocolNotifyEvent(
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Register for protocol notifactions on this event\r
+  // Register for protocol notifications on this event\r
   //\r
 \r
   Status = gBS->RegisterProtocolNotify (\r
@@ -454,9 +456,9 @@ EfiReleaseLock (
                                function.\r
 \r
   @retval EFI_SUCCESS          ControllerHandle is managed by the driver\r
-                               specifed by DriverBindingHandle.\r
+                               specified by DriverBindingHandle.\r
   @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the driver\r
-                               specifed by DriverBindingHandle.\r
+                               specified by DriverBindingHandle.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -579,7 +581,7 @@ EfiTestChildHandle (
 \r
   @retval EFI_SUCCESS             The Unicode string that matches the language \r
                                   specified by Language was found\r
-                                  in the table of Unicoide strings UnicodeStringTable, \r
+                                  in the table of Unicode strings UnicodeStringTable, \r
                                   and it was returned in UnicodeString.\r
   @retval EFI_INVALID_PARAMETER   Language is NULL.\r
   @retval EFI_INVALID_PARAMETER   UnicodeString is NULL.\r
@@ -659,7 +661,7 @@ LookupUnicodeString (
                                RFC 4646 language code for the Unicode string to look up and\r
                                return. If Iso639Language is TRUE, then this ASCII string is\r
                                not assumed to be Null-terminated, and only the first three\r
-                               chacters are used. If Iso639Language is FALSE, then this ASCII\r
+                               characters are used. If Iso639Language is FALSE, then this ASCII\r
                                string must be Null-terminated. \r
   @param  SupportedLanguages   A pointer to a Null-terminated ASCII string that contains a\r
                                set of ISO 639-2 or RFC 4646 language codes that the Unicode\r
@@ -689,7 +691,6 @@ LookupUnicodeString (
 \r
 **/\r
 EFI_STATUS\r
-\r
 EFIAPI\r
 LookupUnicodeString2 (\r
   IN CONST CHAR8                     *Language,\r
@@ -1188,3 +1189,229 @@ FreeUnicodeStringTable (
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
+/**\r
+  Returns a pointer to an allocated buffer that contains the contents of a \r
+  variable retrieved through the UEFI Runtime Service GetVariable().  The \r
+  returned buffer is allocated using AllocatePool().  The caller is responsible\r
+  for freeing this buffer with FreePool().\r
+\r
+  If Name is NULL, then ASSERT().\r
+  If Guid is NULL, then ASSERT().\r
+\r
+  @param[in]  Name  Pointer to a Null-terminated Unicode string.\r
+  @param[in]  Guid  Pointer to an EFI_GUID structure\r
+\r
+  @retval NULL   The variable could not be retrieved.\r
+  @retval NULL   There are not enough resources available for the variable contents.\r
+  @retval Other  A pointer to allocated buffer containing the variable contents.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetVariable (\r
+  IN CONST CHAR16    *Name,\r
+  IN CONST EFI_GUID  *Guid\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       Size;\r
+  VOID        *Value;\r
+\r
+  ASSERT (Name != NULL);\r
+  ASSERT (Guid != NULL);\r
+\r
+  //\r
+  // Try to get the variable size.\r
+  //\r
+  Value = NULL;\r
+  Size = 0;\r
+  Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &Size, Value);\r
+  if (Status != EFI_BUFFER_TOO_SMALL) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Allocate buffer to get the variable.\r
+  //\r
+  Value = AllocatePool (Size);\r
+  if (Value == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Get the variable data.\r
+  //\r
+  Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &Size, Value);\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool(Value);\r
+    return NULL;\r
+  }\r
+\r
+  return Value;\r
+}\r
+\r
+\r
+/**\r
+  Returns a pointer to an allocated buffer that contains the contents of a \r
+  variable retrieved through the UEFI Runtime Service GetVariable().  This \r
+  function always uses the EFI_GLOBAL_VARIABLE GUID to retrieve variables.\r
+  The returned buffer is allocated using AllocatePool().  The caller is \r
+  responsible for freeing this buffer with FreePool().\r
+\r
+  If Name is NULL, then ASSERT().\r
+\r
+  @param[in]  Name  Pointer to a Null-terminated Unicode string.\r
+\r
+  @retval NULL   The variable could not be retrieved.\r
+  @retval NULL   There are not enough resources available for the variable contents.\r
+  @retval Other  A pointer to allocated buffer containing the variable contents.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+GetEfiGlobalVariable (\r
+  IN CONST CHAR16  *Name\r
+  )\r
+{\r
+  return GetVariable (Name, &gEfiGlobalVariableGuid);\r
+}\r
+\r
+\r
+/**\r
+  Returns a pointer to an allocated buffer that contains the best matching language \r
+  from a set of supported languages.  \r
+  \r
+  This function supports both ISO 639-2 and RFC 4646 language codes, but language \r
+  code types may not be mixed in a single call to this function.  The language \r
+  code returned is allocated using AllocatePool().  The caller is responsible for \r
+  freeing the allocated buffer using FreePool().  This function supports a variable\r
+  argument list that allows the caller to pass in a prioritized list of language \r
+  codes to test against all the language codes in SupportedLanguages. \r
+\r
+  If SupportedLanguages is NULL, then ASSERT().\r
+\r
+  @param[in]  SupportedLanguages  A pointer to a Null-terminated ASCII string that\r
+                                  contains a set of language codes in the format \r
+                                  specified by Iso639Language.\r
+  @param[in]  Iso639Language      If TRUE, then all language codes are assumed to be\r
+                                  in ISO 639-2 format.  If FALSE, then all language\r
+                                  codes are assumed to be in RFC 4646 language format\r
+  @param[in]  ...                 A variable argument list that contains pointers to \r
+                                  Null-terminated ASCII strings that contain one or more\r
+                                  language codes in the format specified by Iso639Language.\r
+                                  The first language code from each of these language\r
+                                  code lists is used to determine if it is an exact or\r
+                                  close match to any of the language codes in \r
+                                  SupportedLanguages.  Close matches only apply to RFC 4646\r
+                                  language codes, and the matching algorithm from RFC 4647\r
+                                  is used to determine if a close match is present.  If \r
+                                  an exact or close match is found, then the matching\r
+                                  language code from SupportedLanguages is returned.  If\r
+                                  no matches are found, then the next variable argument\r
+                                  parameter is evaluated.  The variable argument list \r
+                                  is terminated by a NULL.\r
+\r
+  @retval NULL   The best matching language could not be found in SupportedLanguages.\r
+  @retval NULL   There are not enough resources available to return the best matching \r
+                 language.\r
+  @retval Other  A pointer to a Null-terminated ASCII string that is the best matching \r
+                 language in SupportedLanguages.\r
+\r
+**/\r
+CHAR8 *\r
+EFIAPI\r
+GetBestLanguage (\r
+  IN CONST CHAR8  *SupportedLanguages, \r
+  IN BOOLEAN      Iso639Language,\r
+  ...\r
+  )\r
+{\r
+  VA_LIST      Args;\r
+  CHAR8        *Language;\r
+  UINTN        CompareLength;\r
+  UINTN        LanguageLength;\r
+  CONST CHAR8  *Supported;\r
+  CHAR8        *BestLanguage;\r
+\r
+  ASSERT (SupportedLanguages != NULL);\r
+\r
+  VA_START (Args, Iso639Language);\r
+  while ((Language = VA_ARG (Args, CHAR8 *)) != NULL) {\r
+    //\r
+    // Default to ISO 639-2 mode\r
+    //\r
+    CompareLength  = 3;\r
+    LanguageLength = MIN (3, AsciiStrLen (Language));\r
+\r
+    //\r
+    // If in RFC 4646 mode, then determine the length of the first RFC 4646 language code in Language\r
+    //\r
+    if (!Iso639Language) {\r
+      for (LanguageLength = 0; Language[LanguageLength] != 0 && Language[LanguageLength] != ';'; LanguageLength++);\r
+    }\r
+\r
+    //\r
+    // Trim back the length of Language used until it is empty\r
+    //\r
+    while (LanguageLength > 0) {\r
+      //\r
+      // Loop through all language codes in SupportedLanguages\r
+      //\r
+      for (Supported = SupportedLanguages; *Supported != '\0'; Supported += CompareLength) {\r
+        //\r
+        // In RFC 4646 mode, then Loop through all language codes in SupportedLanguages\r
+        //\r
+        if (!Iso639Language) {\r
+          //\r
+          // Skip ';' characters in Supported\r
+          //\r
+          for (; *Supported != '\0' && *Supported == ';'; Supported++);\r
+          //\r
+          // Determine the length of the next language code in Supported\r
+          //\r
+          for (CompareLength = 0; Supported[CompareLength] != 0 && Supported[CompareLength] != ';'; CompareLength++);\r
+          //\r
+          // If Language is longer than the Supported, then skip to the next language\r
+          //\r
+          if (LanguageLength > CompareLength) {\r
+            continue;\r
+          }\r
+        }\r
+        //\r
+        // See if the first LanguageLength characters in Supported match Language\r
+        //\r
+        if (AsciiStrnCmp (Supported, Language, LanguageLength) == 0) {\r
+          VA_END (Args);\r
+          //\r
+          // Allocate, copy, and return the best matching language code from SupportedLanguages\r
+          //\r
+          BestLanguage = AllocateZeroPool (CompareLength + 1);\r
+          if (BestLanguage == NULL) {\r
+            return NULL;\r
+          }\r
+          return CopyMem (BestLanguage, Supported, CompareLength);\r
+        }\r
+      }\r
+\r
+      if (Iso639Language) {\r
+        //\r
+        // If ISO 639 mode, then each language can only be tested once\r
+        //\r
+        LanguageLength = 0;\r
+      } else {\r
+        //\r
+        // If RFC 4646 mode, then trim Language from the right to the next '-' character \r
+        //\r
+        for (LanguageLength--; LanguageLength > 0 && Language[LanguageLength] != '-'; LanguageLength--);\r
+      }\r
+    }\r
+  }\r
+  VA_END (Args);\r
+\r
+  //\r
+  // No matches were found \r
+  //\r
+  return NULL;\r
+}\r
+\r
index 60767a0dbbb1d3271abb027a136be1138d8cebb5..e4bc433be47f00283ee0a1a37f628a555fd829ae 100644 (file)
 \r
 #include <Guid/EventGroup.h>\r
 #include <Guid/EventLegacyBios.h>\r
+#include <Guid/GlobalVariable.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
index 6d1fda6dc2f72e166e7b0701ea3300515fe9d17a..3f4f4f5f57ec70085a5e0eb3a0bfab335bf27aae 100644 (file)
@@ -59,12 +59,14 @@ InternalPrint (
   IN  VA_LIST                          Marker\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
   UINTN   Return;\r
   CHAR16  *Buffer;\r
   UINTN   BufferSize;\r
 \r
   ASSERT (Format != NULL);\r
   ASSERT (((UINTN) Format & BIT0) == 0);\r
+  ASSERT (Console != NULL);\r
 \r
   BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
 \r
@@ -77,7 +79,10 @@ InternalPrint (
     //\r
     // To be extra safe make sure Console has been initialized\r
     //\r
-    Console->OutputString (Console, Buffer);\r
+    Status = Console->OutputString (Console, Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      Return = 0;\r
+    }\r
   }\r
 \r
   FreePool (Buffer);\r
@@ -96,6 +101,7 @@ InternalPrint (
   PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
   If Format is NULL, then ASSERT().\r
   If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+  If gST->ConOut is NULL, then ASSERT().\r
 \r
   @param Format   Null-terminated Unicode format string.\r
   @param ...      Variable argument list whose contents are accessed based \r
@@ -134,6 +140,7 @@ Print (
   PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
   If Format is NULL, then ASSERT().\r
   If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+  If gST->StdErr is NULL, then ASSERT().\r
 \r
   @param Format   Null-terminated Unicode format string.\r
   @param ...      Variable argument list whose contents are accessed based \r
@@ -188,11 +195,13 @@ AsciiInternalPrint (
   IN  VA_LIST                          Marker\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
   UINTN   Return;\r
   CHAR16  *Buffer;\r
   UINTN   BufferSize;\r
 \r
   ASSERT (Format != NULL);\r
+  ASSERT (Console != NULL);\r
 \r
   BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
 \r
@@ -205,7 +214,10 @@ AsciiInternalPrint (
     //\r
     // To be extra safe make sure Console has been initialized\r
     //\r
-    Console->OutputString (Console, Buffer);\r
+    Status = Console->OutputString (Console, Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      Return = 0;\r
+    }\r
   }\r
 \r
   FreePool (Buffer);\r
@@ -223,6 +235,7 @@ AsciiInternalPrint (
   string is greater than PcdUefiLibMaxPrintBufferSize, then only the first \r
   PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
   If Format is NULL, then ASSERT().\r
+  If gST->ConOut is NULL, then ASSERT().\r
 \r
   @param Format   Null-terminated ASCII format string.\r
   @param ...      Variable argument list whose contents are accessed based \r
@@ -261,6 +274,7 @@ AsciiPrint (
   string is greater than PcdUefiLibMaxPrintBufferSize, then only the first \r
   PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
   If Format is NULL, then ASSERT().\r
+  If gST->StdErr is NULL, then ASSERT().\r
 \r
   @param Format   Null-terminated ASCII format string.\r
   @param ...      Variable argument list whose contents are accessed based \r
@@ -347,6 +361,9 @@ InternalPrintGraphic (
   EFI_UGA_DRAW_PROTOCOL               *UgaDraw;\r
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL     *Sto;\r
   EFI_HANDLE                          ConsoleHandle;\r
+  UINTN                               Width;\r
+  UINTN                               Height;\r
+  UINTN                               Delta;\r
 \r
   HorizontalResolution  = 0;\r
   VerticalResolution    = 0;\r
@@ -355,6 +372,8 @@ InternalPrintGraphic (
 \r
   ConsoleHandle = gST->ConsoleOutHandle;\r
 \r
+  ASSERT( ConsoleHandle != NULL);\r
+\r
   Status = gBS->HandleProtocol (\r
                   ConsoleHandle,\r
                   &gEfiGraphicsOutputProtocolGuid,\r
@@ -464,7 +483,9 @@ InternalPrintGraphic (
     //\r
     Status = HiiFont->StringToImage (\r
                          HiiFont,\r
-                         EFI_HII_IGNORE_IF_NO_GLYPH,\r
+                         EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |\r
+                         EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |\r
+                         EFI_HII_IGNORE_LINE_BREAK,\r
                          Buffer,\r
                          &FontInfo,\r
                          &Blt,\r
@@ -478,11 +499,20 @@ InternalPrintGraphic (
     if (!EFI_ERROR (Status)) {\r
       ASSERT (RowInfoArray != NULL);\r
       //\r
-      // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will\r
+      // Explicit Line break characters are ignored, so the updated parameter RowInfoArraySize by StringToImage will\r
       // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.\r
       //\r
       ASSERT (RowInfoArraySize <= 1);\r
 \r
+      if (RowInfoArraySize != 0) {\r
+        Width  = RowInfoArray[0].LineWidth;\r
+        Height = RowInfoArray[0].LineHeight;\r
+        Delta  = Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
+      } else {\r
+        Width  = 0;\r
+        Height = 0;\r
+        Delta  = 0;\r
+      }\r
       Status = UgaDraw->Blt (\r
                           UgaDraw,\r
                           (EFI_UGA_PIXEL *) Blt->Image.Bitmap,\r
@@ -491,9 +521,9 @@ InternalPrintGraphic (
                           PointY,\r
                           PointX,\r
                           PointY,\r
-                          RowInfoArray[0].LineWidth,\r
-                          RowInfoArray[0].LineHeight,\r
-                          Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                          Width,\r
+                          Height,\r
+                          Delta\r
                           );\r
     } else {\r
       goto Error;\r
@@ -505,7 +535,11 @@ InternalPrintGraphic (
   //\r
   // Calculate the number of actual printed characters\r
   //\r
+  if (RowInfoArraySize != 0) {\r
   PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1;\r
+  } else {\r
+    PrintNum = 0;\r
+  }\r
 \r
   FreePool (RowInfoArray);\r
   FreePool (Blt);\r
@@ -540,6 +574,7 @@ Error:
   string is printed, and 0 is returned.\r
   If Format is NULL, then ASSERT().\r
   If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+  If gST->ConsoleOutputHandle is NULL, then ASSERT().\r
 \r
   @param  PointX       X coordinate to print the string.\r
   @param  PointY       Y coordinate to print the string.\r
@@ -616,6 +651,7 @@ PrintXY (
   If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no \r
   string is printed, and 0 is returned.\r
   If Format is NULL, then ASSERT().\r
+  If gST->ConsoleOutputHandle is NULL, then ASSERT().\r
 \r
   @param  PointX       X coordinate to print the string.\r
   @param  PointY       Y coordinate to print the string.\r