/** @file\r
Utility functions for expression evaluation.\r
\r
-Copyright (c) 2007 - 2015, 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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
(*StackPtr)->Buffer = AllocateCopyPool(Data->BufferLen, Data->Buffer);\r
ASSERT ((*StackPtr)->Buffer != NULL);\r
}\r
- \r
+\r
*StackPtr = *StackPtr + 1;\r
\r
return EFI_SUCCESS;\r
mCurrentExpressionPointer = mCurrentExpressionStack;\r
mFormExpressionPointer = mFormExpressionStack;\r
mStatementExpressionPointer = mStatementExpressionStack;\r
- mOptionExpressionPointer = mOptionExpressionStack; \r
+ mOptionExpressionPointer = mOptionExpressionStack;\r
}\r
\r
\r
pointer\r
@param StackEnd On input: old stack end; On output: new stack end\r
@param MemberSize The stack member size.\r
- \r
+\r
@retval EFI_SUCCESS Grow stack success.\r
@retval EFI_OUT_OF_RESOURCES No enough memory for stack space.\r
\r
//\r
// Push the item onto the stack\r
//\r
- CopyMem (*StackPtr, Data, sizeof (FORM_EXPRESSION *)); \r
+ CopyMem (*StackPtr, Data, sizeof (FORM_EXPRESSION *));\r
*StackPtr = *StackPtr + 1;\r
\r
return EFI_SUCCESS;\r
\r
/**\r
Get the expression list count.\r
- \r
- @param Level Which type this expression belong to. Form, \r
+\r
+ @param Level Which type this expression belong to. Form,\r
statement or option?\r
\r
@retval >=0 The expression count\r
@retval -1 Input parameter error.\r
\r
**/\r
-INTN \r
+INTN\r
GetConditionalExpressionCount (\r
IN EXPRESS_LEVEL Level\r
)\r
default:\r
ASSERT (FALSE);\r
return -1;\r
- } \r
+ }\r
}\r
\r
/**\r
Get the expression Buffer pointer.\r
- \r
- @param Level Which type this expression belong to. Form, \r
+\r
+ @param Level Which type this expression belong to. Form,\r
statement or option?\r
\r
@retval The start pointer of the expression buffer or NULL.\r
default:\r
ASSERT (FALSE);\r
return NULL;\r
- } \r
+ }\r
}\r
\r
\r
Push the expression options onto the Stack.\r
\r
@param Pointer Pointer to the current expression.\r
- @param Level Which type this expression belong to. Form, \r
+ @param Level Which type this expression belong to. Form,\r
statement or option?\r
\r
@retval EFI_SUCCESS The value was pushed onto the stack.\r
/**\r
Pop the expression options from the Stack\r
\r
- @param Level Which type this expression belong to. Form, \r
+ @param Level Which type this expression belong to. Form,\r
statement or option?\r
\r
@retval EFI_SUCCESS The value was pushed onto the stack.\r
**/\r
UINTN\r
SaveExpressionEvaluationStackOffset (\r
+ VOID\r
)\r
{\r
UINTN TempStackOffset;\r
/**\r
Check whether this value type can be transfer to EFI_IFR_TYPE_BUFFER type.\r
\r
- EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to \r
+ EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to\r
EFI_IFR_TYPE_BUFFER when do the value compare.\r
\r
@param Value Expression value to compare on.\r
/**\r
Return the buffer length for this value.\r
\r
- EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to \r
+ EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to\r
EFI_IFR_TYPE_BUFFER when do the value compare.\r
\r
@param Value Expression value to compare on.\r
- \r
+\r
@retval BufLen Return the buffer length.\r
\r
**/\r
/**\r
Return the buffer pointer for this value.\r
\r
- EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to \r
+ EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to\r
EFI_IFR_TYPE_BUFFER when do the value compare.\r
\r
@param Value Expression value to compare on.\r
case EFI_IFR_TYPE_BOOLEAN:\r
String = (Value.Value.b) ? L"True" : L"False";\r
break;\r
- \r
+\r
case EFI_IFR_TYPE_BUFFER:\r
case EFI_IFR_TYPE_DATE:\r
case EFI_IFR_TYPE_TIME:\r
case EFI_IFR_TYPE_REF:\r
//\r
- // + 3 is base on the unicode format, the length may be odd number, \r
+ // + 3 is base on the unicode format, the length may be odd number,\r
// so need 1 byte to align, also need 2 bytes for L'\0'.\r
//\r
if (Value.Type == EFI_IFR_TYPE_BUFFER) {\r
ASSERT (TmpBuf != NULL);\r
if (Format == EFI_IFR_STRING_ASCII) {\r
CopyMem (TmpBuf, SrcBuf, SrcLen);\r
- PrintFormat = L"%a"; \r
+ PrintFormat = L"%a";\r
} else {\r
// Format == EFI_IFR_STRING_UNICODE\r
CopyMem (TmpBuf, SrcBuf, SrcLen * sizeof (CHAR16));\r
- PrintFormat = L"%s"; \r
+ PrintFormat = L"%s";\r
}\r
UnicodeSPrint (Buffer, sizeof (Buffer), PrintFormat, TmpBuf);\r
- String = Buffer; \r
+ String = Buffer;\r
FreePool (TmpBuf);\r
if (Value.Type == EFI_IFR_TYPE_BUFFER) {\r
FreePool (Value.Buffer);\r
}\r
break;\r
- \r
+\r
default:\r
Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
return EFI_SUCCESS;\r
Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
return EFI_SUCCESS;\r
}\r
+\r
+ ASSERT (GetBufferForValue (&Value) != NULL);\r
Result->Value.u64 = *(UINT64*) GetBufferForValue (&Value);\r
+\r
if (Value.Type == EFI_IFR_TYPE_BUFFER) {\r
FreePool (Value.Buffer);\r
}\r
UINT16 Length0;\r
UINT16 Length1;\r
UINT8 *TmpBuf;\r
+ UINTN MaxLen;\r
\r
//\r
// String[0] - The second string\r
\r
if (Value[0].Type == EFI_IFR_TYPE_STRING) {\r
Size = StrSize (String[0]);\r
- StringPtr= AllocatePool (StrSize (String[1]) + Size);\r
+ MaxLen = (StrSize (String[1]) + Size) / sizeof (CHAR16);\r
+ StringPtr= AllocatePool (MaxLen * sizeof (CHAR16));\r
ASSERT (StringPtr != NULL);\r
- StrCpy (StringPtr, String[1]);\r
- StrCat (StringPtr, String[0]);\r
+ StrCpyS (StringPtr, MaxLen, String[1]);\r
+ StrCatS (StringPtr, MaxLen, String[0]);\r
\r
Result->Type = EFI_IFR_TYPE_STRING;\r
Result->Value.string = NewString (StringPtr, FormSet->HiiHandle);\r
&BufferSize,\r
HandleBuffer);\r
\r
- } else if (EFI_ERROR (Status)) {\r
- Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
Status = EFI_SUCCESS;\r
goto Done;\r
}\r
\r
+ ASSERT (HandleBuffer != NULL);\r
for ( Index = 0; Index < BufferSize / sizeof(EFI_HANDLE); Index ++) {\r
Status = gBS->HandleProtocol (\r
HandleBuffer[Index],\r
RegExSyntaxTypeList = NULL;\r
\r
Status = RegularExpressionProtocol->GetInfo (\r
- RegularExpressionProtocol, \r
- &RegExSyntaxTypeListSize, \r
+ RegularExpressionProtocol,\r
+ &RegExSyntaxTypeListSize,\r
RegExSyntaxTypeList\r
);\r
if (Status == EFI_BUFFER_TOO_SMALL) {\r
goto Done;\r
}\r
Status = RegularExpressionProtocol->GetInfo (\r
- RegularExpressionProtocol, \r
- &RegExSyntaxTypeListSize, \r
+ RegularExpressionProtocol,\r
+ &RegExSyntaxTypeListSize,\r
RegExSyntaxTypeList\r
);\r
} else if (EFI_ERROR (Status)) {\r
//\r
Result->Type = EFI_IFR_TYPE_BOOLEAN;\r
Status = RegularExpressionProtocol->MatchString (\r
- RegularExpressionProtocol, \r
+ RegularExpressionProtocol,\r
String[0],\r
String[1],\r
SyntaxType,\r
}\r
\r
//\r
- // Type specified by SyntaxType is not supported \r
+ // Type specified by SyntaxType is not supported\r
// in any of the EFI_REGULAR_EXPRESSION_PROTOCOL instances.\r
//\r
- Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
+ Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
Status = EFI_SUCCESS;\r
\r
Done:\r
Status = PopExpression (&Value[2]);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
- } \r
+ }\r
\r
if (Value[0].Type > EFI_IFR_TYPE_NUM_SIZE_64) {\r
Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
Status = PopExpression (&Value[2]);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
- } \r
+ }\r
\r
if (Value[0].Type > EFI_IFR_TYPE_NUM_SIZE_64) {\r
Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
Result->BufferLen = 0;\r
Result->Buffer = NULL;\r
} else {\r
- Result->BufferLen = (UINT16)((BufferLen - Base) < Length ? (BufferLen - Base) : Length); \r
+ Result->BufferLen = (UINT16)((BufferLen - Base) < Length ? (BufferLen - Base) : Length);\r
Result->Buffer = AllocateZeroPool (Result->BufferLen);\r
ASSERT (Result->Buffer != NULL);\r
CopyMem (Result->Buffer, &Buffer[Base], Result->BufferLen);\r
FreePool (Value[2].Buffer);\r
}\r
}\r
- \r
+\r
return Status;\r
}\r
\r
Status = PopExpression (&Value[2]);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
- } \r
+ }\r
\r
- if (Value[0].Type > EFI_IFR_TYPE_NUM_SIZE_64) { \r
+ if (Value[0].Type > EFI_IFR_TYPE_NUM_SIZE_64) {\r
Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
return EFI_SUCCESS;\r
}\r
for (Index = 0; Index < 2; Index++) {\r
if (Value[Index + 1].Type != EFI_IFR_TYPE_STRING) {\r
Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
- Status = EFI_SUCCESS; \r
+ Status = EFI_SUCCESS;\r
goto Done;\r
}\r
\r
Status = PopExpression (&Value[2]);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
- } \r
+ }\r
\r
if (Value[0].Type > EFI_IFR_TYPE_NUM_SIZE_64) {\r
Result->Type = EFI_IFR_TYPE_UNDEFINED;\r
Buf1Len = GetLengthForValue(Value1);\r
Buf2 = GetBufferForValue(Value2);\r
Buf2Len = GetLengthForValue(Value2);\r
- \r
+\r
Len = Buf1Len > Buf2Len ? Buf2Len : Buf1Len;\r
*Result = CompareMem (Buf1, Buf2, Len);\r
if ((*Result == 0) && (Buf1Len != Buf2Len)) {\r
*Result = Buf1Len > Buf2Len ? 1 : -1;\r
}\r
return EFI_SUCCESS;\r
- } \r
+ }\r
\r
//\r
// Take types(integer, boolean) as integer\r
/// Enumerate all user information of the current user profile\r
/// to look for any EFI_USER_INFO_ACCESS_SETUP record.\r
///\r
- \r
+\r
for (UserInfoHandle = NULL;;) {\r
Status = mUserManager->GetNextInfo (mUserManager, UserProfileHandle, &UserInfoHandle);\r
if (EFI_ERROR (Status)) {\r
@param FormSetGuid The formset guid which include the question.\r
@param QuestionId The question id which need to get value from.\r
@param Value The return data about question's value.\r
- \r
+\r
@retval TRUE Get the question value success.\r
@retval FALSE Get the question value failed.\r
**/\r
-BOOLEAN \r
+BOOLEAN\r
GetQuestionValueFromForm (\r
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
IN EFI_HII_HANDLE InputHiiHandle,\r
BOOLEAN GetTheVal;\r
LIST_ENTRY *Link;\r
\r
- // \r
- // The input parameter DevicePath or InputHiiHandle must have one valid input. \r
//\r
- ASSERT ((DevicePath != NULL && InputHiiHandle == NULL) || \r
+ // The input parameter DevicePath or InputHiiHandle must have one valid input.\r
+ //\r
+ ASSERT ((DevicePath != NULL && InputHiiHandle == NULL) ||\r
(DevicePath == NULL && InputHiiHandle != NULL) );\r
\r
GetTheVal = TRUE;\r
}\r
} else {\r
HiiHandle = InputHiiHandle;\r
- } \r
+ }\r
ASSERT (HiiHandle != NULL);\r
\r
//\r
\r
//\r
// Base on the Question Id to get the question info.\r
- // \r
+ //\r
Question = IdToQuestion(FormSet, NULL, QuestionId);\r
if (Question == NULL) {\r
GetTheVal = FALSE;\r
Form = NULL;\r
}\r
ASSERT (Form != NULL);\r
- \r
+\r
//\r
// Get the question value.\r
//\r
- Status = GetQuestionValue(FormSet, Form, Question, GetSetValueWithHiiDriver);\r
+ Status = GetQuestionValue(FormSet, Form, Question, GetSetValueWithEditBuffer);\r
if (EFI_ERROR (Status)) {\r
GetTheVal = FALSE;\r
goto Done;\r
}\r
\r
CopyMem (Value, &Question->HiiValue, sizeof (EFI_HII_VALUE));\r
- \r
+\r
Done:\r
//\r
// Clean the formset structure and restore the global parameter.\r
if (FormSet != NULL) {\r
DestroyFormSet (FormSet);\r
}\r
- \r
+\r
return GetTheVal;\r
}\r
\r
TempBuffer [Index/2] = (UINT8) ((DigitUint8 << 4) + TempBuffer [Index/2]);\r
}\r
}\r
- } \r
+ }\r
}\r
}\r
break;\r
if (EFI_ERROR (Status)) {\r
goto Done;\r
}\r
- \r
+\r
//\r
// Validate the expression value\r
//\r
if (StrPtr != NULL) {\r
FreePool (StrPtr);\r
}\r
- } else if (CompareGuid (&OpCode->Guid, &gZeroGuid) != 0) {\r
+ } else if (IsZeroGuid (&OpCode->Guid)) {\r
if (!GetQuestionValueFromForm(NULL, FormSet->HiiHandle, &OpCode->Guid, Value->Value.u16, &QuestionVal)){\r
Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
break;\r
//\r
// When converting from a string, if case-insensitive compare\r
// with "true" is True, then push True. If a case-insensitive compare\r
- // with "false" is True, then push False. Otherwise, push Undefined. \r
+ // with "false" is True, then push False. Otherwise, push Undefined.\r
//\r
StrPtr = GetToken (Value->Value.string, FormSet->HiiHandle);\r
if (StrPtr == NULL) {\r
Status = EFI_INVALID_PARAMETER;\r
goto Done;\r
}\r
- \r
+\r
IfrStrToUpper (StrPtr);\r
if (StrCmp (StrPtr, L"TRUE") == 0){\r
Value->Value.b = TRUE;\r
FreePool (StrPtr);\r
} else if (Value->Type == EFI_IFR_TYPE_BUFFER) {\r
//\r
- // When converting from a buffer, if the buffer is all zeroes, \r
- // then push False. Otherwise push True. \r
+ // When converting from a buffer, if the buffer is all zeroes,\r
+ // then push False. Otherwise push True.\r
//\r
for (Index =0; Index < Value->BufferLen; Index ++) {\r
- if (Value->Buffer[Index] != 0) { \r
+ if (Value->Buffer[Index] != 0) {\r
break;\r
}\r
}\r
case EFI_HII_VARSTORE_NAME_VALUE:\r
if (OpCode->ValueType != EFI_IFR_TYPE_STRING) {\r
NameValue = AllocateZeroPool ((OpCode->ValueWidth * 2 + 1) * sizeof (CHAR16));\r
- ASSERT (Value != NULL);\r
+ ASSERT (NameValue != NULL);\r
//\r
// Convert Buffer to Hex String\r
//\r
TempBuffer = (UINT8 *) &Value->Value + OpCode->ValueWidth - 1;\r
StrPtr = NameValue;\r
for (Index = 0; Index < OpCode->ValueWidth; Index ++, TempBuffer --) {\r
- StrPtr += UnicodeValueToString (StrPtr, PREFIX_ZERO | RADIX_HEX, *TempBuffer, 2);\r
+ UnicodeValueToStringS (\r
+ StrPtr,\r
+ (OpCode->ValueWidth * 2 + 1) * sizeof (CHAR16) - ((UINTN)StrPtr - (UINTN)NameValue),\r
+ PREFIX_ZERO | RADIX_HEX,\r
+ *TempBuffer,\r
+ 2\r
+ );\r
+ StrPtr += StrnLenS (StrPtr, OpCode->ValueWidth * 2 + 1 - ((UINTN)StrPtr - (UINTN)NameValue) / sizeof (CHAR16));\r
}\r
Status = SetValueByName (OpCode->VarStorage, OpCode->ValueName, NameValue, GetSetValueWithEditBuffer, NULL);\r
FreePool (NameValue);\r
//\r
Status = EFI_UNSUPPORTED;\r
goto Done;\r
- break;\r
}\r
} else {\r
//\r
goto Done;\r
}\r
\r
- if (Data2.Type > EFI_IFR_TYPE_BOOLEAN && \r
- Data2.Type != EFI_IFR_TYPE_STRING && \r
+ if (Data2.Type > EFI_IFR_TYPE_BOOLEAN &&\r
+ Data2.Type != EFI_IFR_TYPE_STRING &&\r
!IsTypeInBuffer(&Data2)) {\r
Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
break;\r
}\r
\r
- if (Data1.Type > EFI_IFR_TYPE_BOOLEAN && \r
- Data1.Type != EFI_IFR_TYPE_STRING && \r
+ if (Data1.Type > EFI_IFR_TYPE_BOOLEAN &&\r
+ Data1.Type != EFI_IFR_TYPE_STRING &&\r
!IsTypeInBuffer(&Data1)) {\r
Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
break;\r
if (Data2.Type == EFI_IFR_TYPE_BUFFER) {\r
FreePool (Data2.Buffer);\r
}\r
- \r
+\r
if (Status == EFI_UNSUPPORTED) {\r
Value->Type = EFI_IFR_TYPE_UNDEFINED;\r
Status = EFI_SUCCESS;\r
if (EFI_ERROR (Status)) {\r
goto Done;\r
}\r
- \r
+\r
Status = IfrMatch (FormSet, Value);\r
break;\r
\r
\r
/**\r
Check whether the result is TRUE or FALSE.\r
- \r
+\r
For the EFI_HII_VALUE value type is numeric, return TRUE if the\r
value is not 0.\r
\r
}\r
\r
/**\r
- Return the result of the expression list. Check the expression list and \r
- return the highest priority express result. \r
+ Return the result of the expression list. Check the expression list and\r
+ return the highest priority express result.\r
Priority: DisableIf > SuppressIf > GrayOutIf > FALSE\r
\r
@param ExpList The input expression list.\r
@param Evaluate Whether need to evaluate the expression first.\r
@param FormSet FormSet associated with this expression.\r
- @param Form Form associated with this expression. \r
+ @param Form Form associated with this expression.\r
\r
- @retval EXPRESS_RESULT Return the higher priority express result. \r
+ @retval EXPRESS_RESULT Return the higher priority express result.\r
DisableIf > SuppressIf > GrayOutIf > FALSE\r
\r
**/\r
-EXPRESS_RESULT \r
+EXPRESS_RESULT\r
EvaluateExpressionList (\r
IN FORM_EXPRESSION_LIST *ExpList,\r
IN BOOLEAN Evaluate,\r
//\r
// Check whether need to evaluate the expression first.\r
//\r
- if (Evaluate) { \r
+ if (Evaluate) {\r
while (ExpList->Count > Index) {\r
Status = EvaluateExpression (FormSet, Form, ExpList->Expression[Index++]);\r
if (EFI_ERROR (Status)) {\r
break;\r
\r
default:\r
- return ExpressFalse; \r
+ return ExpressFalse;\r
}\r
\r
ReturnVal = ReturnVal < CompareOne ? CompareOne : ReturnVal;\r
}\r
}\r
- \r
+\r
return ReturnVal;\r
}\r