## @file\r
# Common routines used by all tools\r
#\r
-# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2017, 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
from Parsing import GetSplitValueList\r
from Common.LongFilePathSupport import OpenLongFilePath as open\r
from Common.MultipleWorkspace import MultipleWorkspace as mws\r
+import uuid\r
\r
## Regular expression used to find out place holders in string template\r
gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)\r
if (firstline.startswith("Archive member included ") and\r
firstline.endswith(" file (symbol)")):\r
return _parseForGCC(lines, efifilepath, varnames)\r
+ if firstline.startswith("# Path:"):\r
+ return _parseForXcode(lines, efifilepath, varnames)\r
return _parseGeneral(lines, efifilepath, varnames)\r
\r
+def _parseForXcode(lines, efifilepath, varnames):\r
+ status = 0\r
+ ret = []\r
+ for index, line in enumerate(lines):\r
+ line = line.strip()\r
+ if status == 0 and line == "# Symbols:":\r
+ status = 1\r
+ continue\r
+ if status == 1 and len(line) != 0:\r
+ for varname in varnames:\r
+ if varname in line:\r
+ m = re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*%s)$' % varname, line)\r
+ if m != None:\r
+ ret.append((varname, m.group(1)))\r
+ return ret\r
+\r
def _parseForGCC(lines, efifilepath, varnames):\r
""" Parse map file generated by GCC linker """\r
status = 0\r
sections = []\r
varoffset = []\r
- for line in lines:\r
+ for index, line in enumerate(lines):\r
line = line.strip()\r
# status machine transection\r
if status == 0 and line == "Memory Configuration":\r
continue\r
\r
# status handler\r
- if status == 2:\r
+ if status == 3:\r
m = re.match('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$', line)\r
if m != None:\r
sections.append(m.groups(0))\r
for varname in varnames:\r
- m = re.match("^([\da-fA-Fx]+) +[_]*(%s)$" % varname, line)\r
+ Str = ''\r
+ m = re.match("^.data.(%s)" % varname, line)\r
if m != None:\r
- varoffset.append((varname, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))\r
+ m = re.match(".data.(%s)$" % varname, line)\r
+ if m != None:\r
+ Str = lines[index + 1]\r
+ else:\r
+ Str = line[len(".data.%s" % varname):]\r
+ if Str:\r
+ m = re.match('^([\da-fA-Fx]+) +([\da-fA-Fx]+)', Str.strip())\r
+ if m != None:\r
+ varoffset.append((varname, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))\r
\r
if not varoffset:\r
return []\r
#\r
# @param CName The CName of the GUID\r
# @param PackageList List of packages looking-up in\r
+# @param Inffile The driver file\r
#\r
# @retval GuidValue if the CName is found in any given package\r
# @retval None if the CName is not found in all given packages\r
#\r
-def GuidValue(CName, PackageList):\r
+def GuidValue(CName, PackageList, Inffile = None):\r
for P in PackageList:\r
- if CName in P.Guids:\r
+ GuidKeys = P.Guids.keys()\r
+ if Inffile and P._PrivateGuids:\r
+ if not Inffile.startswith(P.MetaFile.Dir):\r
+ GuidKeys = (dict.fromkeys(x for x in P.Guids if x not in P._PrivateGuids)).keys()\r
+ if CName in GuidKeys:\r
return P.Guids[CName]\r
return None\r
\r
#\r
# @param CName The CName of the GUID\r
# @param PackageList List of packages looking-up in\r
+# @param Inffile The driver file\r
#\r
# @retval GuidValue if the CName is found in any given package\r
# @retval None if the CName is not found in all given packages\r
#\r
-def ProtocolValue(CName, PackageList):\r
+def ProtocolValue(CName, PackageList, Inffile = None):\r
for P in PackageList:\r
- if CName in P.Protocols:\r
+ ProtocolKeys = P.Protocols.keys()\r
+ if Inffile and P._PrivateProtocols:\r
+ if not Inffile.startswith(P.MetaFile.Dir):\r
+ ProtocolKeys = (dict.fromkeys(x for x in P.Protocols if x not in P._PrivateProtocols)).keys()\r
+ if CName in ProtocolKeys:\r
return P.Protocols[CName]\r
return None\r
\r
#\r
# @param CName The CName of the GUID\r
# @param PackageList List of packages looking-up in\r
+# @param Inffile The driver file\r
#\r
# @retval GuidValue if the CName is found in any given package\r
# @retval None if the CName is not found in all given packages\r
#\r
-def PpiValue(CName, PackageList):\r
+def PpiValue(CName, PackageList, Inffile = None):\r
for P in PackageList:\r
- if CName in P.Ppis:\r
+ PpiKeys = P.Ppis.keys()\r
+ if Inffile and P._PrivatePpis:\r
+ if not Inffile.startswith(P.MetaFile.Dir):\r
+ PpiKeys = (dict.fromkeys(x for x in P.Ppis if x not in P._PrivatePpis)).keys()\r
+ if CName in PpiKeys:\r
return P.Ppis[CName]\r
return None\r
\r
Opr.close()\r
Opw.close()\r
\r
-## AnalyzeDscPcd\r
-#\r
-# Analyze DSC PCD value, since there is no data type info in DSC\r
-# This fuction is used to match functions (AnalyzePcdData, AnalyzeHiiPcdData, AnalyzeVpdPcdData) used for retrieving PCD value from database\r
-# 1. Feature flag: TokenSpace.PcdCName|PcdValue\r
-# 2. Fix and Patch:TokenSpace.PcdCName|PcdValue[|MaxSize]\r
-# 3. Dynamic default:\r
-# TokenSpace.PcdCName|PcdValue[|VOID*[|MaxSize]]\r
-# TokenSpace.PcdCName|PcdValue\r
-# 4. Dynamic VPD:\r
-# TokenSpace.PcdCName|VpdOffset[|VpdValue]\r
-# TokenSpace.PcdCName|VpdOffset[|MaxSize[|VpdValue]]\r
-# 5. Dynamic HII:\r
-# TokenSpace.PcdCName|HiiString|VaiableGuid|VariableOffset[|HiiValue]\r
-# PCD value needs to be located in such kind of string, and the PCD value might be an expression in which\r
-# there might have "|" operator, also in string value.\r
-#\r
-# @param Setting: String contain information described above with "TokenSpace.PcdCName|" stripped\r
-# @param PcdType: PCD type: feature, fixed, dynamic default VPD HII\r
-# @param DataType: The datum type of PCD: VOID*, UNIT, BOOL\r
-# @retval:\r
-# ValueList: A List contain fields described above\r
-# IsValid: True if conforming EBNF, otherwise False\r
-# Index: The index where PcdValue is in ValueList\r
-#\r
-def AnalyzeDscPcd(Setting, PcdType, DataType=''):\r
+def AnalyzePcdExpression(Setting):\r
Setting = Setting.strip()\r
# There might be escaped quote in a string: \", \\\"\r
Data = Setting.replace('\\\\', '//').replace('\\\"', '\\\'')\r
FieldList.append(Setting[StartPos:Pos].strip())\r
StartPos = Pos + 1\r
\r
+ return FieldList\r
+\r
+def ParseFieldValue (Value):\r
+ if type(Value) == type(0):\r
+ return Value, (Value.bit_length() + 7) / 8\r
+ if type(Value) <> type(''):\r
+ raise ValueError\r
+ Value = Value.strip()\r
+ if Value.startswith('UINT8') and Value.endswith(')'):\r
+ Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])\r
+ if Size > 1:\r
+ raise ValueError\r
+ return Value, 1\r
+ if Value.startswith('UINT16') and Value.endswith(')'):\r
+ Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])\r
+ if Size > 2:\r
+ raise ValueError\r
+ return Value, 2\r
+ if Value.startswith('UINT32') and Value.endswith(')'):\r
+ Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])\r
+ if Size > 4:\r
+ raise ValueError\r
+ return Value, 4\r
+ if Value.startswith('UINT64') and Value.endswith(')'):\r
+ Value, Size = ParseFieldValue(Value.split('(', 1)[1][:-1])\r
+ if Size > 8:\r
+ raise ValueError\r
+ return Value, 8\r
+ if Value.startswith('GUID') and Value.endswith(')'):\r
+ Value = Value.split('(', 1)[1][:-1].strip()\r
+ if Value[0] == '{' and Value[-1] == '}':\r
+ Value = Value[1:-1].strip()\r
+ Value = Value.split('{', 1)\r
+ Value = [Item.strip()[2:] for Item in (Value[0] + Value[1][:-1]).split(',')]\r
+ Value = '-'.join(Value[0:3]) + '-' + ''.join(Value[3:5]) + '-' + ''.join(Value[5:11])\r
+ if Value[0] == '"' and Value[-1] == '"':\r
+ Value = Value[1:-1]\r
+ Value = "'" + uuid.UUID(Value).get_bytes_le() + "'"\r
+ Value, Size = ParseFieldValue(Value)\r
+ return Value, 16\r
+ if Value.startswith('L"') and Value.endswith('"'):\r
+ # Unicode String\r
+ List = list(Value[2:-1])\r
+ List.reverse()\r
+ Value = 0\r
+ for Char in List:\r
+ Value = (Value << 16) | ord(Char)\r
+ return Value, (len(List) + 1) * 2\r
+ if Value.startswith('"') and Value.endswith('"'):\r
+ # ASCII String\r
+ List = list(Value[1:-1])\r
+ List.reverse()\r
+ Value = 0\r
+ for Char in List:\r
+ Value = (Value << 8) | ord(Char)\r
+ return Value, len(List) + 1\r
+ if Value.startswith("L'") and Value.endswith("'"):\r
+ # Unicode Character Constant\r
+ List = list(Value[2:-1])\r
+ List.reverse()\r
+ Value = 0\r
+ for Char in List:\r
+ Value = (Value << 16) | ord(Char)\r
+ return Value, len(List) * 2\r
+ if Value.startswith("'") and Value.endswith("'"):\r
+ # Character constant\r
+ List = list(Value[1:-1])\r
+ List.reverse()\r
+ Value = 0\r
+ for Char in List:\r
+ Value = (Value << 8) | ord(Char)\r
+ return Value, len(List)\r
+ if Value.startswith('{') and Value.endswith('}'):\r
+ # Byte array\r
+ Value = Value[1:-1]\r
+ List = [Item.strip() for Item in Value.split(',')]\r
+ List.reverse()\r
+ Value = 0\r
+ for Item in List:\r
+ ItemValue, Size = ParseFieldValue(Item)\r
+ if Size > 1:\r
+ raise ValueError\r
+ Value = (Value << 8) | ItemValue\r
+ return Value, len(List)\r
+ if Value.lower().startswith('0x'):\r
+ Value = int(Value, 16)\r
+ return Value, (Value.bit_length() + 7) / 8\r
+ if Value[0].isdigit():\r
+ Value = int(Value, 10)\r
+ return Value, (Value.bit_length() + 7) / 8\r
+ if Value.lower() == 'true':\r
+ return 1, 1\r
+ if Value.lower() == 'false':\r
+ return 0, 1\r
+ return Value, 1\r
+\r
+## AnalyzeDscPcd\r
+#\r
+# Analyze DSC PCD value, since there is no data type info in DSC\r
+# This fuction is used to match functions (AnalyzePcdData, AnalyzeHiiPcdData, AnalyzeVpdPcdData) used for retrieving PCD value from database\r
+# 1. Feature flag: TokenSpace.PcdCName|PcdValue\r
+# 2. Fix and Patch:TokenSpace.PcdCName|PcdValue[|MaxSize]\r
+# 3. Dynamic default:\r
+# TokenSpace.PcdCName|PcdValue[|VOID*[|MaxSize]]\r
+# TokenSpace.PcdCName|PcdValue\r
+# 4. Dynamic VPD:\r
+# TokenSpace.PcdCName|VpdOffset[|VpdValue]\r
+# TokenSpace.PcdCName|VpdOffset[|MaxSize[|VpdValue]]\r
+# 5. Dynamic HII:\r
+# TokenSpace.PcdCName|HiiString|VaiableGuid|VariableOffset[|HiiValue]\r
+# PCD value needs to be located in such kind of string, and the PCD value might be an expression in which\r
+# there might have "|" operator, also in string value.\r
+#\r
+# @param Setting: String contain information described above with "TokenSpace.PcdCName|" stripped\r
+# @param PcdType: PCD type: feature, fixed, dynamic default VPD HII\r
+# @param DataType: The datum type of PCD: VOID*, UNIT, BOOL\r
+# @retval:\r
+# ValueList: A List contain fields described above\r
+# IsValid: True if conforming EBNF, otherwise False\r
+# Index: The index where PcdValue is in ValueList\r
+#\r
+def AnalyzeDscPcd(Setting, PcdType, DataType=''):\r
+ FieldList = AnalyzePcdExpression(Setting)\r
+\r
IsValid = True\r
if PcdType in (MODEL_PCD_FIXED_AT_BUILD, MODEL_PCD_PATCHABLE_IN_MODULE, MODEL_PCD_FEATURE_FLAG):\r
Value = FieldList[0]\r
Size = ''\r
if len(FieldList) > 1:\r
- Type = FieldList[1]\r
- # Fix the PCD type when no DataType input\r
- if Type == 'VOID*':\r
- DataType = 'VOID*'\r
- else:\r
+ if FieldList[1].upper().startswith("0X") or FieldList[1].isdigit():\r
Size = FieldList[1]\r
+ else:\r
+ DataType = FieldList[1]\r
+\r
if len(FieldList) > 2:\r
Size = FieldList[2]\r
- if DataType == 'VOID*':\r
- IsValid = (len(FieldList) <= 3)\r
- else:\r
+ if DataType == "":\r
IsValid = (len(FieldList) <= 1)\r
- return [Value, '', Size], IsValid, 0\r
+ else:\r
+ IsValid = (len(FieldList) <= 3)\r
+# Value, Size = ParseFieldValue(Value)\r
+ if Size:\r
+ try:\r
+ int(Size,16) if Size.upper().startswith("0X") else int(Size)\r
+ except:\r
+ IsValid = False\r
+ Size = -1\r
+ return [str(Value), '', str(Size)], IsValid, 0\r
elif PcdType in (MODEL_PCD_DYNAMIC_DEFAULT, MODEL_PCD_DYNAMIC_EX_DEFAULT):\r
Value = FieldList[0]\r
Size = Type = ''\r
Size = str(len(Value.split(",")))\r
else:\r
Size = str(len(Value) -2 + 1 )\r
- if DataType == 'VOID*':\r
- IsValid = (len(FieldList) <= 3)\r
- else:\r
+ if DataType == "":\r
IsValid = (len(FieldList) <= 1)\r
- return [Value, Type, Size], IsValid, 0\r
+ else:\r
+ IsValid = (len(FieldList) <= 3)\r
+\r
+ if Size:\r
+ try:\r
+ int(Size,16) if Size.upper().startswith("0X") else int(Size)\r
+ except:\r
+ IsValid = False\r
+ Size = -1\r
+ return [Value, Type, str(Size)], IsValid, 0\r
elif PcdType in (MODEL_PCD_DYNAMIC_VPD, MODEL_PCD_DYNAMIC_EX_VPD):\r
VpdOffset = FieldList[0]\r
Value = Size = ''\r
Size = FieldList[1]\r
if len(FieldList) > 2:\r
Value = FieldList[2]\r
- if DataType == 'VOID*':\r
- IsValid = (len(FieldList) <= 3)\r
+ if DataType == "":\r
+ IsValid = (len(FieldList) <= 1)\r
else:\r
- IsValid = (len(FieldList) <= 2)\r
- return [VpdOffset, Size, Value], IsValid, 2\r
+ IsValid = (len(FieldList) <= 3)\r
+ if Size:\r
+ try:\r
+ int(Size,16) if Size.upper().startswith("0X") else int(Size)\r
+ except:\r
+ IsValid = False\r
+ Size = -1\r
+ return [VpdOffset, str(Size), Value], IsValid, 2\r
elif PcdType in (MODEL_PCD_DYNAMIC_HII, MODEL_PCD_DYNAMIC_EX_HII):\r
HiiString = FieldList[0]\r
Guid = Offset = Value = Attribute = ''\r
return False, "Invalid value [%s] of type [%s];"\\r
" must be a hexadecimal, decimal or octal in C language format." % (Value, Type)\r
else:\r
- return False, "Invalid type [%s]; must be one of VOID*, BOOLEAN, UINT8, UINT16, UINT32, UINT64." % (Type)\r
+ return True, "StructurePcd"\r
\r
return True, ""\r
\r
Value = (Value << 8) | int(ByteList[index])\r
return Value\r
\r
+class DefaultStore():\r
+ def __init__(self,DefaultStores ):\r
\r
+ self.DefaultStores = DefaultStores\r
+ def DefaultStoreID(self,DefaultStoreName):\r
+ for key,value in self.DefaultStores.items():\r
+ if value == DefaultStoreName:\r
+ return key\r
+ return None\r
+ def GetDefaultDefault(self):\r
+ if not self.DefaultStores or "0" in self.DefaultStores:\r
+ return "0",TAB_DEFAULT_STORES_DEFAULT\r
+ else:\r
+ minvalue = min([int(value_str) for value_str in self.DefaultStores.keys()])\r
+ return (str(minvalue), self.DefaultStores[str(minvalue)])\r
+ def GetMin(self,DefaultSIdList):\r
+ if not DefaultSIdList:\r
+ return "STANDARD"\r
+ storeidset = {storeid for storeid, storename in self.DefaultStores.values() if storename in DefaultSIdList}\r
+ if not storeidset:\r
+ return ""\r
+ minid = min(storeidset )\r
+ for sid,name in self.DefaultStores.values():\r
+ if sid == minid:\r
+ return name\r
class SkuClass():\r
\r
DEFAULT = 0\r
SINGLE = 1\r
MULTIPLE =2\r
\r
- def __init__(self,SkuIdentifier='', SkuIds={}):\r
+ def __init__(self,SkuIdentifier='', SkuIds=None):\r
+ if SkuIds is None:\r
+ SkuIds = {}\r
\r
self.AvailableSkuIds = sdict()\r
self.SkuIdSet = []\r
self.SkuIdNumberSet = []\r
+ self.SkuData = SkuIds\r
+ self.__SkuInherit = {}\r
if SkuIdentifier == '' or SkuIdentifier is None:\r
self.SkuIdSet = ['DEFAULT']\r
self.SkuIdNumberSet = ['0U']\r
elif SkuIdentifier == 'ALL':\r
self.SkuIdSet = SkuIds.keys()\r
- self.SkuIdNumberSet = [num.strip() + 'U' for num in SkuIds.values()]\r
+ self.SkuIdNumberSet = [num[0].strip() + 'U' for num in SkuIds.values()]\r
else:\r
r = SkuIdentifier.split('|') \r
- self.SkuIdSet=[r[k].strip() for k in range(len(r))] \r
+ self.SkuIdSet=[(r[k].strip()).upper() for k in range(len(r))]\r
k = None\r
try: \r
- self.SkuIdNumberSet = [SkuIds[k].strip() + 'U' for k in self.SkuIdSet] \r
+ self.SkuIdNumberSet = [SkuIds[k][0].strip() + 'U' for k in self.SkuIdSet]\r
except Exception:\r
EdkLogger.error("build", PARAMETER_INVALID,\r
ExtraData = "SKU-ID [%s] is not supported by the platform. [Valid SKU-ID: %s]"\r
- % (k, " ".join(SkuIds.keys())))\r
- if len(self.SkuIdSet) == 2 and 'DEFAULT' in self.SkuIdSet and SkuIdentifier != 'ALL':\r
- self.SkuIdSet.remove('DEFAULT')\r
- self.SkuIdNumberSet.remove('0U')\r
+ % (k, " | ".join(SkuIds.keys())))\r
for each in self.SkuIdSet:\r
if each in SkuIds:\r
- self.AvailableSkuIds[each] = SkuIds[each]\r
+ self.AvailableSkuIds[each] = SkuIds[each][0]\r
else:\r
EdkLogger.error("build", PARAMETER_INVALID,\r
ExtraData="SKU-ID [%s] is not supported by the platform. [Valid SKU-ID: %s]"\r
- % (each, " ".join(SkuIds.keys())))\r
+ % (each, " | ".join(SkuIds.keys())))\r
+ if self.SkuUsageType != self.SINGLE:\r
+ self.AvailableSkuIds.update({'DEFAULT':0, 'COMMON':0})\r
+ if self.SkuIdSet:\r
+ GlobalData.gSkuids = (self.SkuIdSet)\r
+ if 'COMMON' in GlobalData.gSkuids:\r
+ GlobalData.gSkuids.remove('COMMON')\r
+ if GlobalData.gSkuids:\r
+ GlobalData.gSkuids.sort()\r
+\r
+ def GetNextSkuId(self, skuname):\r
+ if not self.__SkuInherit:\r
+ self.__SkuInherit = {}\r
+ for item in self.SkuData.values():\r
+ self.__SkuInherit[item[1]]=item[2] if item[2] else "DEFAULT"\r
+ return self.__SkuInherit.get(skuname,"DEFAULT")\r
\r
def __SkuUsageType(self): \r
\r
return SkuClass.SINGLE\r
else:\r
return SkuClass.MULTIPLE\r
+ def DumpSkuIdArrary(self):\r
\r
+ ArrayStrList = []\r
+ if self.SkuUsageType == SkuClass.SINGLE:\r
+ ArrayStr = "{0x0}"\r
+ else:\r
+ for skuname in self.AvailableSkuIds:\r
+ if skuname == "COMMON":\r
+ continue\r
+ while skuname != "DEFAULT":\r
+ ArrayStrList.append(hex(int(self.AvailableSkuIds[skuname])))\r
+ skuname = self.GetNextSkuId(skuname)\r
+ ArrayStrList.append("0x0")\r
+ ArrayStr = "{" + ",".join(ArrayStrList) + "}"\r
+ return ArrayStr\r
def __GetAvailableSkuIds(self):\r
return self.AvailableSkuIds\r
\r
int(Guid[4][-2:], 16)\r
)\r
\r
+def BuildOptionPcdValueFormat(TokenSpaceGuidCName, TokenCName, PcdDatumType, Value):\r
+ if PcdDatumType == 'VOID*':\r
+ if Value.startswith('L'):\r
+ if not Value[1]:\r
+ EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')\r
+ Value = Value[0] + '"' + Value[1:] + '"'\r
+ elif Value.startswith('H'):\r
+ if not Value[1]:\r
+ EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')\r
+ Value = Value[1:]\r
+ else:\r
+ if not Value[0]:\r
+ EdkLogger.error("build", FORMAT_INVALID, 'For Void* type PCD, when specify the Value in the command line, please use the following format: "string", L"string", H"{...}"')\r
+ Value = '"' + Value + '"'\r
+\r
+ IsValid, Cause = CheckPcdDatum(PcdDatumType, Value)\r
+ if not IsValid:\r
+ EdkLogger.error("build", FORMAT_INVALID, Cause, ExtraData="%s.%s" % (TokenSpaceGuidCName, TokenCName))\r
+ if PcdDatumType == 'BOOLEAN':\r
+ Value = Value.upper()\r
+ if Value == 'TRUE' or Value == '1':\r
+ Value = '1'\r
+ elif Value == 'FALSE' or Value == '0':\r
+ Value = '0'\r
+ return Value\r
+## Get the integer value from string like "14U" or integer like 2\r
+#\r
+# @param Input The object that may be either a integer value or a string\r
+#\r
+# @retval Value The integer value that the input represents\r
+#\r
+def GetIntegerValue(Input):\r
+ if type(Input) in (int, long):\r
+ return Input\r
+ String = Input\r
+ if String.endswith("U"):\r
+ String = String[:-1]\r
+ if String.endswith("ULL"):\r
+ String = String[:-3]\r
+ if String.endswith("LL"):\r
+ String = String[:-2]\r
+\r
+ if String.startswith("0x") or String.startswith("0X"):\r
+ return int(String, 16)\r
+ elif String == '':\r
+ return 0\r
+ else:\r
+ return int(String)\r
+\r
##\r
#\r
# This acts like the main() function for the script, unless it is 'import'ed into another\r