mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-10 09:40:53 +01:00
parsing float values in plists
Signed-off-by: SergeySlice <sergey.slice@gmail.com>
This commit is contained in:
parent
15a9eebae6
commit
d3da5e1a21
@ -2653,6 +2653,11 @@ GetEarlyUserSettings (
|
||||
if (IsPropertyTrue (Prop)) {
|
||||
gSettings.NoCaches = TRUE;
|
||||
}
|
||||
//test float
|
||||
Prop = GetProperty (DictPointer, "BlueValue");
|
||||
float tmpF = GetPropertyFloat(Prop, 1.2f);
|
||||
DBG(" get BlueValue=%f\n", tmpF);
|
||||
|
||||
}
|
||||
|
||||
// KernelAndKextPatches
|
||||
|
@ -166,7 +166,8 @@ typedef enum {
|
||||
kTagTypeDate,
|
||||
kTagTypeFalse,
|
||||
kTagTypeTrue,
|
||||
kTagTypeArray
|
||||
kTagTypeArray,
|
||||
kTagTypeFloat
|
||||
} TAG_TYPE;
|
||||
|
||||
typedef struct DEV_PROPERTY DEV_PROPERTY; //yyyy
|
||||
|
@ -30,6 +30,8 @@
|
||||
//Slice - rewrite for UEFI with more functions like Copyright (c) 2003 Apple Computer
|
||||
#include "Platform.h"
|
||||
#include "b64cdecode.h"
|
||||
#include "plist.h"
|
||||
#include "../libeg/FloatLib.h"
|
||||
|
||||
#ifndef DEBUG_ALL
|
||||
#define DEBUG_PLIST 0
|
||||
@ -45,44 +47,19 @@
|
||||
|
||||
|
||||
|
||||
/* XML Tags */
|
||||
#define kXMLTagPList "plist"
|
||||
#define kXMLTagDict "dict"
|
||||
#define kXMLTagKey "key"
|
||||
#define kXMLTagString "string"
|
||||
#define kXMLTagInteger "integer"
|
||||
#define kXMLTagData "data"
|
||||
#define kXMLTagDate "date"
|
||||
#define kXMLTagFalse "false/"
|
||||
#define kXMLTagTrue "true/"
|
||||
#define kXMLTagArray "array"
|
||||
#define kXMLTagReference "reference"
|
||||
#define kXMLTagID "ID="
|
||||
#define kXMLTagIDREF "IDREF="
|
||||
|
||||
|
||||
struct Symbol {
|
||||
UINTN refCount;
|
||||
struct Symbol *next;
|
||||
CHAR8 string[1];
|
||||
};
|
||||
|
||||
typedef struct Symbol Symbol, *SymbolPtr;
|
||||
|
||||
|
||||
|
||||
SymbolPtr gSymbolsHead = NULL;
|
||||
TagPtr gTagsFree = NULL;
|
||||
CHAR8* buffer_start = NULL;
|
||||
|
||||
// Forward declarations
|
||||
EFI_STATUS ParseTagList( CHAR8* buffer, TagPtr * tag, UINT32 type, UINT32 empty, UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagKey( char * buffer, TagPtr * tag,UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagString(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagInteger(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagData(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagDate(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagBoolean(CHAR8* buffer, TagPtr * tag, UINT32 type,UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagKey( char * buffer, TagPtr * tag, UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagString(CHAR8* buffer, TagPtr * tag, UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagInteger(CHAR8* buffer, TagPtr * tag, UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagFloat(CHAR8* buffer, TagPtr * tag, UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagData(CHAR8* buffer, TagPtr * tag, UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagDate(CHAR8* buffer, TagPtr * tag, UINT32* lenPtr);
|
||||
EFI_STATUS ParseTagBoolean(CHAR8* buffer, TagPtr * tag, UINT32 type, UINT32* lenPtr);
|
||||
//defined in Platform.h
|
||||
//EFI_STATUS GetElement( TagPtr dict, INTN id, TagPtr *dict1);
|
||||
//INTN GetTagCount( TagPtr dict );
|
||||
@ -135,22 +112,17 @@ XMLDecode(CHAR8* src)
|
||||
s = src;
|
||||
while (s <= src+len) /* Make sure the terminator is also copied */
|
||||
{
|
||||
if ( *s == '&' )
|
||||
{
|
||||
if ( *s == '&' ) {
|
||||
BOOLEAN entFound = FALSE;
|
||||
UINTN i;
|
||||
|
||||
s++;
|
||||
for ( i = 0; i < sizeof(ents)/sizeof(ents[0]); i++)
|
||||
{
|
||||
if ( AsciiStrnCmp(s, ents[i].name, ents[i].nameLen) == 0 )
|
||||
{
|
||||
for (i = 0; i < sizeof(ents)/sizeof(ents[0]); i++) {
|
||||
if ( AsciiStrnCmp(s, ents[i].name, ents[i].nameLen) == 0 ) {
|
||||
entFound = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( entFound )
|
||||
{
|
||||
if ( entFound ) {
|
||||
*o++ = ents[i].value;
|
||||
s += ents[i].nameLen;
|
||||
continue;
|
||||
@ -414,7 +386,15 @@ EFI_STATUS XMLParseNextTag(CHAR8* buffer, TagPtr* tag, UINT32* lenPtr)
|
||||
{
|
||||
Status = ParseTagInteger(buffer + pos, tag, &length);
|
||||
}
|
||||
|
||||
/***** float ****/
|
||||
else if (!AsciiStrCmp(tagName, kXMLTagFloat))
|
||||
{
|
||||
Status = ParseTagFloat(buffer + pos, tag, &length);
|
||||
}
|
||||
else if (!AsciiStrnCmp(tagName, kXMLTagFloat " ", 8))
|
||||
{
|
||||
Status = ParseTagFloat(buffer + pos, tag, &length);
|
||||
}
|
||||
/***** data ****/
|
||||
else if (!AsciiStrCmp(tagName, kXMLTagData))
|
||||
{
|
||||
@ -637,7 +617,7 @@ EFI_STATUS ParseTagString(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr)
|
||||
//==========================================================================
|
||||
// ParseTagInteger
|
||||
|
||||
EFI_STATUS ParseTagInteger(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr)
|
||||
EFI_STATUS ParseTagInteger(CHAR8* buffer, TagPtr * tag, UINT32* lenPtr)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 length = 0;
|
||||
@ -647,7 +627,7 @@ EFI_STATUS ParseTagInteger(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr)
|
||||
CHAR8* val = buffer;
|
||||
TagPtr tmpTag;
|
||||
|
||||
Status = FixDataMatchingTag(buffer, kXMLTagInteger,&length);
|
||||
Status = FixDataMatchingTag(buffer, kXMLTagInteger, &length);
|
||||
if (EFI_ERROR(Status)) {
|
||||
return Status;
|
||||
}
|
||||
@ -726,6 +706,43 @@ EFI_STATUS ParseTagInteger(CHAR8* buffer, TagPtr * tag,UINT32* lenPtr)
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
// ParseTagFloat
|
||||
|
||||
EFI_STATUS ParseTagFloat(CHAR8* buffer, TagPtr * tag, UINT32* lenPtr)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 length = 0; //unused?
|
||||
// BOOLEAN negative = FALSE;
|
||||
// CHAR8* val = buffer;
|
||||
TagPtr tmpTag;
|
||||
FlMix fVar;
|
||||
fVar.B.fNum = 0.f;
|
||||
fVar.B.pad = 0;
|
||||
|
||||
Status = FixDataMatchingTag(buffer, kXMLTagFloat, &length);
|
||||
if (EFI_ERROR(Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
tmpTag = NewTag();
|
||||
if (tmpTag == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
//----
|
||||
AsciiStrToFloat(buffer, NULL, &fVar.B.fNum);
|
||||
//----
|
||||
tmpTag->type = kTagTypeFloat;
|
||||
tmpTag->string = fVar.string;
|
||||
tmpTag->tag = NULL;
|
||||
tmpTag->offset = (UINT32)(buffer_start ? buffer - buffer_start: 0);
|
||||
tmpTag->tagNext = NULL;
|
||||
|
||||
*tag = tmpTag;
|
||||
*lenPtr = length;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
// ParseTagData
|
||||
|
||||
@ -1140,3 +1157,21 @@ GetPropertyInteger (
|
||||
}
|
||||
return Default;
|
||||
}
|
||||
|
||||
float GetPropertyFloat (TagPtr Prop, float Default)
|
||||
{
|
||||
if (Prop == NULL) {
|
||||
return Default;
|
||||
}
|
||||
if (Prop->type == kTagTypeFloat) {
|
||||
FlMix fVar;
|
||||
fVar.string = Prop->string;
|
||||
return fVar.B.fNum; //this is union char* or float
|
||||
} else if ((Prop->type == kTagTypeString) && Prop->string) {
|
||||
float fVar = 0.f;
|
||||
if(!AsciiStrToFloat(Prop->string, NULL, &fVar)) //if success then return 0
|
||||
return fVar;
|
||||
}
|
||||
|
||||
return Default;
|
||||
}
|
||||
|
@ -9,6 +9,30 @@
|
||||
#define PLATFORM_PLIST_H_
|
||||
|
||||
|
||||
/* XML Tags */
|
||||
#define kXMLTagPList "plist"
|
||||
#define kXMLTagDict "dict"
|
||||
#define kXMLTagKey "key"
|
||||
#define kXMLTagString "string"
|
||||
#define kXMLTagInteger "integer"
|
||||
#define kXMLTagData "data"
|
||||
#define kXMLTagDate "date"
|
||||
#define kXMLTagFalse "false/"
|
||||
#define kXMLTagTrue "true/"
|
||||
#define kXMLTagArray "array"
|
||||
#define kXMLTagReference "reference"
|
||||
#define kXMLTagID "ID="
|
||||
#define kXMLTagIDREF "IDREF="
|
||||
#define kXMLTagFloat "real"
|
||||
|
||||
|
||||
struct Symbol {
|
||||
UINTN refCount;
|
||||
struct Symbol *next;
|
||||
CHAR8 string[1];
|
||||
};
|
||||
typedef struct Symbol Symbol, *SymbolPtr;
|
||||
|
||||
|
||||
typedef struct TagStruct {
|
||||
|
||||
@ -22,6 +46,13 @@ typedef struct TagStruct {
|
||||
|
||||
} TagStruct, *TagPtr;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
float fNum; //4 bytes
|
||||
UINT32 pad; // else 4
|
||||
} B;
|
||||
CHAR8 *string;
|
||||
} FlMix;
|
||||
|
||||
|
||||
CHAR8*
|
||||
@ -93,5 +124,7 @@ GetPropertyInteger (
|
||||
INTN Default
|
||||
);
|
||||
|
||||
float GetPropertyFloat (TagPtr Prop, float Default);
|
||||
|
||||
|
||||
#endif /* PLATFORM_PLIST_H_ */
|
||||
|
@ -2475,7 +2475,9 @@ VOID CreateMenuProps(REFIT_MENU_SCREEN *SubScreen, DEV_PROPERTY *Prop)
|
||||
case kTagTypeTrue:
|
||||
SubScreen->AddMenuInfo_f((" value: true"));
|
||||
break;
|
||||
|
||||
case kTagTypeFloat:
|
||||
SubScreen->AddMenuInfo_f(" value: %f", *(float*)Prop->Value);
|
||||
break;
|
||||
default: //type data, print first 24 bytes
|
||||
//CHAR8* Bytes2HexStr(UINT8 *data, UINTN len)
|
||||
SubScreen->AddMenuInfo_f(" value[%llu]: %24s", Prop->ValueLen, Bytes2HexStr((UINT8*)Prop->Value, MIN(24, Prop->ValueLen)));
|
||||
|
Loading…
Reference in New Issue
Block a user