]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Expression.c
Refine data copy and data compare logic.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Expression.c
index 27be635e9c7c1b6e21b0c07e530c044564585a8b..d4ab369a4c6c55ec376c69f4d9c59260490e34f4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Utility functions for expression evaluation.\r
 \r
-Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2013, 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
@@ -787,7 +787,7 @@ FORM_BROWSER_FORM *
 IdToForm (\r
   IN FORM_BROWSER_FORMSET  *FormSet,\r
   IN UINT16                FormId\r
-)\r
+  )\r
 {\r
   LIST_ENTRY         *Link;\r
   FORM_BROWSER_FORM  *Form;\r
@@ -1071,7 +1071,7 @@ IfrToString (
       CopyMem (TmpBuf, Value.Buffer, Value.BufferLen * sizeof (CHAR16));\r
       PrintFormat = L"%s";  \r
     }\r
-    UnicodeSPrint (Buffer, MAXIMUM_VALUE_CHARACTERS, PrintFormat, Value.Buffer);  \r
+    UnicodeSPrint (Buffer, sizeof (Buffer), PrintFormat, Value.Buffer);  \r
     String = Buffer; \r
     FreePool (TmpBuf);\r
     FreePool (Value.Buffer);\r
@@ -1446,7 +1446,6 @@ IfrMid (
   UINTN          Base;\r
   UINTN          Length;\r
   CHAR16         *SubString;\r
-  UINT8          *Buffer;\r
   UINT16         BufferLen;\r
 \r
   ZeroMem (Value, sizeof (Value));\r
@@ -1502,7 +1501,6 @@ IfrMid (
 \r
     FreePool (String);\r
   } else {\r
-    Buffer    = Value[2].Buffer;\r
     BufferLen = Value[2].BufferLen;\r
     \r
     Result->Type = EFI_IFR_TYPE_BUFFER;\r
@@ -1801,6 +1799,55 @@ ExtendValueToU64 (
   Value->Value.u64 = Temp;\r
 }\r
 \r
+/**\r
+  Get UINT64 type value.\r
+\r
+  @param  Value                  Input Hii value.\r
+\r
+  @retval UINT64                 Return the UINT64 type value.\r
+\r
+**/\r
+UINT64\r
+HiiValueToUINT64 (\r
+  IN EFI_HII_VALUE      *Value\r
+  )\r
+{\r
+  UINT64  RetVal;\r
+\r
+  RetVal = 0;\r
+\r
+  switch (Value->Type) {\r
+  case EFI_IFR_TYPE_NUM_SIZE_8:\r
+    RetVal = Value->Value.u8;\r
+    break;\r
+\r
+  case EFI_IFR_TYPE_NUM_SIZE_16:\r
+    RetVal = Value->Value.u16;\r
+    break;\r
+\r
+  case EFI_IFR_TYPE_NUM_SIZE_32:\r
+    RetVal = Value->Value.u32;\r
+    break;\r
+\r
+  case EFI_IFR_TYPE_BOOLEAN:\r
+    RetVal = Value->Value.b;\r
+    break;\r
+\r
+  case EFI_IFR_TYPE_DATE:\r
+    RetVal = *(UINT64*) &Value->Value.date;\r
+    break;\r
+\r
+  case EFI_IFR_TYPE_TIME:\r
+    RetVal = (*(UINT64*) &Value->Value.time) & 0xffffff;\r
+    break;\r
+\r
+  default:\r
+    RetVal = Value->Value.u64;\r
+    break;\r
+  }\r
+\r
+  return RetVal;\r
+}\r
 \r
 /**\r
   Compare two Hii value.\r
@@ -1901,7 +1948,7 @@ CompareHiiValue (
   //\r
   // Take remain types(integer, boolean, date/time) as integer\r
   //\r
-  Temp64 = (INT64) (Value1->Value.u64 - Value2->Value.u64);\r
+  Temp64 = HiiValueToUINT64(Value1) - HiiValueToUINT64(Value2);\r
   if (Temp64 > 0) {\r
     *Result = 1;\r
   } else if (Temp64 < 0) {\r
@@ -2038,11 +2085,7 @@ GetQuestionValueFromForm (
   )\r
 {\r
   EFI_STATUS                   Status;\r
-  EFI_HANDLE                   DriverHandle;\r
-  EFI_HANDLE                   Handle;\r
-  EFI_HII_HANDLE               *HiiHandles;\r
   EFI_HII_HANDLE               HiiHandle;\r
-  UINTN                        Index;\r
   FORM_BROWSER_STATEMENT       *Question;\r
   FORM_BROWSER_FORMSET         *FormSet;\r
   FORM_BROWSER_FORM            *Form;\r
@@ -2056,7 +2099,6 @@ GetQuestionValueFromForm (
           (DevicePath == NULL && InputHiiHandle != NULL) );\r
 \r
   GetTheVal    = TRUE;\r
-  DriverHandle = NULL;\r
   HiiHandle    = NULL;\r
   Question     = NULL;\r
   Form         = NULL;\r
@@ -2065,38 +2107,10 @@ GetQuestionValueFromForm (
   // Get HiiHandle.\r
   //\r
   if (DevicePath != NULL) {\r
-    //\r
-    // 1. Get Driver handle.\r
-    //\r
-    Status = gBS->LocateDevicePath (\r
-                    &gEfiDevicePathProtocolGuid,\r
-                    &DevicePath,\r
-                    &DriverHandle\r
-                    );\r
-    if (EFI_ERROR (Status) || (DriverHandle == NULL)) {\r
+    HiiHandle = DevicePathToHiiHandle (DevicePath, FormSetGuid);\r
+    if (HiiHandle == NULL) {\r
       return FALSE;\r
     }\r
-\r
-    //\r
-    // 2. Get Hii handle\r
-    //\r
-    HiiHandles = HiiGetHiiHandles (NULL);\r
-    if (HiiHandles == NULL) {\r
-      return FALSE;\r
-    }\r
-\r
-    for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r
-      Status = mHiiDatabase->GetPackageListHandle (\r
-                               mHiiDatabase,\r
-                               HiiHandles[Index],\r
-                               &Handle\r
-                               );\r
-      if (!EFI_ERROR (Status) && (Handle == DriverHandle)) {\r
-        HiiHandle = HiiHandles[Index];\r
-        break;\r
-      }\r
-    }\r
-    FreePool (HiiHandles);\r
   } else {\r
     HiiHandle = InputHiiHandle;\r
   } \r
@@ -2107,7 +2121,7 @@ GetQuestionValueFromForm (
   //\r
   FormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET));\r
   ASSERT (FormSet != NULL);\r
-  Status = InitializeFormSet(HiiHandle, FormSetGuid, FormSet, FALSE);\r
+  Status = InitializeFormSet(HiiHandle, FormSetGuid, FormSet);\r
   if (EFI_ERROR (Status)) {\r
     GetTheVal = FALSE;\r
     goto Done;\r
@@ -2470,22 +2484,21 @@ EvaluateExpression (
       }\r
 \r
       if (OpCode->DevicePath != 0) {\r
-        StrPtr = GetToken (OpCode->DevicePath, FormSet->HiiHandle);\r
-        if (StrPtr == NULL) {\r
-          Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
-          break;\r
-        }\r
-\r
-        DevicePath = ConvertDevicePathFromText(StrPtr);\r
+        Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
 \r
-        if (!GetQuestionValueFromForm(DevicePath, NULL, &OpCode->Guid, Value->Value.u16, &QuestionVal)){\r
-          Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
-        } else {\r
-          Value = &QuestionVal;\r
+        StrPtr = GetToken (OpCode->DevicePath, FormSet->HiiHandle);\r
+        if (StrPtr != NULL && mPathFromText != NULL) {\r
+          DevicePath = mPathFromText->ConvertTextToDevicePath(StrPtr);\r
+          if (DevicePath != NULL && GetQuestionValueFromForm(DevicePath, NULL, &OpCode->Guid, Value->Value.u16, &QuestionVal)) {\r
+            Value = &QuestionVal;\r
+          }\r
+          if (DevicePath != NULL) {\r
+            FreePool (DevicePath);\r
+          }\r
         }\r
 \r
-        if (DevicePath != NULL) {\r
-          FreePool (DevicePath);\r
+        if (StrPtr != NULL) {\r
+          FreePool (StrPtr);\r
         }\r
       } else if (CompareGuid (&OpCode->Guid, &gZeroGuid) != 0) {\r
         if (!GetQuestionValueFromForm(NULL, FormSet->HiiHandle, &OpCode->Guid, Value->Value.u16, &QuestionVal)){\r
@@ -2803,7 +2816,7 @@ EvaluateExpression (
             for (Index = 0; Index < OpCode->ValueWidth; Index ++, TempBuffer --) {\r
               StrPtr += UnicodeValueToString (StrPtr, PREFIX_ZERO | RADIX_HEX, *TempBuffer, 2);\r
             }\r
-            Status = SetValueByName (OpCode->VarStorage, OpCode->ValueName, NameValue, GetSetValueWithEditBuffer);\r
+            Status = SetValueByName (OpCode->VarStorage, OpCode->ValueName, NameValue, GetSetValueWithEditBuffer, NULL);\r
             FreePool (NameValue);\r
             if (!EFI_ERROR (Status)) {\r
               Data1.Value.b = TRUE;\r