+++ /dev/null
-/** @file\r
- CommonDefinition class.\r
-\r
- This class is to define some common marcos and funcions, which used by AutoGen.\r
-\r
- Copyright (c) 2006, Intel Corporation\r
- All rights reserved. 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
-\r
- **/\r
-package org.tianocore.pcd.entity;\r
-\r
-import java.util.Iterator;\r
-import java.util.LinkedHashSet;\r
-import java.util.Set;\r
-\r
-/**\r
- CommonDefinition\r
-\r
- This class is to define some common marcos, which used by AutoGen.\r
-\r
-**/\r
-public class CommonDefinition {\r
- public final static String spdSuffix = ".spd";\r
- public final static String mbdSuffix = ".mbd";\r
- public final static String msaSuffix = ".msa";\r
- public final static String LibraryStr = "LIBRARY";\r
- public final static String autoGenHbegin = "extern int __make_me_compile_correctly;\r\n";\r
- public final static String include = "#include";\r
- public final static String autoGenCLine1 = "\r\n";\r
-\r
- public final static String autoGenCLine2 = "const UINT8 _gDebugPropertyMask "\r
- + "= DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED"\r
- + " | DEBUG_PROPERTY_DEBUG_PRINT_ENABLED"\r
- + " | DEBUG_PROPERTY_DEBUG_CODE_ENABLED;\r\n";\r
-\r
- public final static String autoGenCLine3 = "const UINTN _gModuleDefaultErrorLevel"\r
- + " = EFI_D_ERROR | EFI_D_LOAD;\r\n";\r
-\r
- public final static String autoGenHLine1 = "#define EFI_SPECIFICATION_VERSION 0x00020000\r\n";\r
- public final static String autoGenHVersionDefault = "#define EFI_SPECIFICATION_VERSION 0x00000000\r\n";\r
- public final static String autoGenHLine2 = "#define EDK_RELEASE_VERSION 0x00090000\r\n";\r
- public final static String autoGenHReleaseDefault = "#define EDK_RELEASE_VERSION 0x00000000\r\n";\r
-\r
- public final static String includeAutogenH = "#include <AutoGen.h>\r\n" ;\r
- public final static String marcDefineStr = "#define ";\r
-\r
- public final static String gEfi = "gEfi";\r
- public final static String protocolGuid = "ProtocolGuid";\r
- public final static String ppiGuid = "PpiGuid";\r
- public final static String guidGuid = "Guid";\r
-\r
- public final static String tianoR8FlashMapH = "TianoR8FlashMap.h";\r
- public final static String flashMapH = "FlashMap.h";\r
-\r
- //\r
- // AutoGen.h and AutoGen.c file's header\r
- //\r
- public final static String autogenHNotation =\r
- "/**\r\n" +\r
- " DO NOT EDIT\r\n" +\r
- " FILE auto-generated by GenBuild tasks\r\n" +\r
- " Module name:\r\n" +\r
- " AutoGen.h\r\n" +\r
- " Abstract:" +\r
- " Auto-generated AutoGen.h for building module or library.\r\n" +\r
- "**/\r\n\r\n";\r
-\r
- public final static String autogenCNotation =\r
- "/**\r\n" +\r
- " DO NOT EDIT\r\n" +\r
- " FILE auto-generated by GenBuild tasks\r\n" +\r
- " Module name:\r\n" +\r
- " AutoGen.c\r\n" +\r
- " Abstract:" +\r
- " Auto-generated AutoGen.c for building module or library.\r\n" +\r
- "**/\r\n\r\n";\r
-\r
- //\r
- // module type\r
- //\r
- public final static int ModuleTypeBase = 0;\r
- public final static int ModuleTypeSec = 1;\r
- public final static int ModuleTypePeiCore = 2;\r
- public final static int ModuleTypePeim = 3;\r
- public final static int ModuleTypeDxeCore = 4;\r
- public final static int ModuleTypeDxeDriver = 5;\r
- public final static int ModuleTypeDxeRuntimeDriver = 6;\r
- public final static int ModuleTypeDxeSmmDriver = 7;\r
- public final static int ModuleTypeDxeSalDriver = 8;\r
- public final static int ModuleTypeUefiDriver = 9;\r
- public final static int ModuleTypeUefiApplication = 10;\r
- public final static int ModuleTypeUnknown = 11;\r
-\r
-\r
- //\r
- // component type\r
- //\r
- public final static int ComponentTypeNull = 0;\r
- public final static int ComponentTypeApriori = 1;\r
- public final static int ComponentTypeSec = 2;\r
- public final static int ComponentTypeLibrary = 3;\r
- public final static int ComponentTypeFvImageFile = 4;\r
- public final static int ComponentTypeBsDriver = 5;\r
- public final static int ComponentTypeRtDriver = 6;\r
- public final static int ComponentTypeSalRtDriver =7;\r
- public final static int ComponentTypePe32Peim = 8;\r
- public final static int ComponentTypePicPeim =9;\r
- public final static int ComponentTypeCombinedPeimDriver =10;\r
- public final static int ComponentTypePeiCore = 11;\r
- public final static int ComponentTypeDxeCore = 12;\r
- public final static int ComponentTypeApplication = 13;\r
- public final static int ComponentTypeBsDriverEfi = 14;\r
- public final static int ComponentTypeShellApp = 15;\r
- public final static int ComponentTypeBinary =16;\r
- public final static int ComponentTypeLogo = 17;\r
- public final static int ComponentTypeCustomBuild = 18;\r
- public final static int ComponentTypeUnknown = 19;\r
-\r
-\r
- //\r
- // Usaged style\r
- //\r
- public final static String AlwaysConsumed = "ALWAYS_CONSUMED";\r
- public final static String AlwaysProduced = "ALWAYS_PRODUCED";\r
-\r
-\r
- public static class MyEnum {\r
- String moduleTypeStr;\r
- int type;\r
-\r
- MyEnum (String str, int type) {\r
- this.type = type;\r
- this.moduleTypeStr = str;\r
- }\r
-\r
- int ForInt(String str) {\r
- if (str.equals(this.moduleTypeStr)) {\r
- return this.type;\r
- } else\r
- return -1;\r
- }\r
- }\r
-\r
- //\r
- // Module type\r
- //\r
- public static final MyEnum[] moduleEnum = new MyEnum[] {\r
- new MyEnum("BASE", ModuleTypeBase),\r
- new MyEnum("SEC", ModuleTypeSec),\r
- new MyEnum("PEI_CORE", ModuleTypePeiCore),\r
- new MyEnum("PEIM", ModuleTypePeim),\r
- new MyEnum("DXE_CORE", ModuleTypeDxeCore),\r
- new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver),\r
- new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),\r
- new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),\r
- new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),\r
- new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver),\r
- new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication) };\r
-\r
- //\r
- // Component type\r
- //\r
- public static final MyEnum[] componentEnum = new MyEnum[]{\r
- new MyEnum("APRIORI", ComponentTypeApriori),\r
- new MyEnum("SEC", ComponentTypeSec),\r
- new MyEnum("LIBRARY", ComponentTypeLibrary),\r
- new MyEnum("FV_IMAGE_FILE", ComponentTypeFvImageFile),\r
- new MyEnum("BS_DRIVER", ComponentTypeBsDriver),\r
- new MyEnum("RT_DRIVER", ComponentTypeRtDriver),\r
- new MyEnum("SAL_RT_DRIVER", ComponentTypeSalRtDriver),\r
- new MyEnum("PE32_PEIM", ComponentTypePe32Peim),\r
- new MyEnum("PIC_PEIM", ComponentTypePicPeim),\r
- new MyEnum("COMBINED_PEIM_DRIVER", ComponentTypeCombinedPeimDriver),\r
- new MyEnum("PEI_CORE", ComponentTypePeiCore),\r
- new MyEnum("DXE_CORE", ComponentTypeDxeCore),\r
- new MyEnum("APPLICATION", ComponentTypeApplication),\r
- new MyEnum("BS_DRIVER_EFI", ComponentTypeBsDriverEfi),\r
- new MyEnum("SHELLAPP", ComponentTypeShellApp),\r
- new MyEnum("BINARY", ComponentTypeBinary),\r
- new MyEnum("LOGO", ComponentTypeLogo),\r
- new MyEnum("CUSTOM_BUILD", ComponentTypeCustomBuild)\r
- };\r
-\r
- /**\r
- getModuleType\r
-\r
- This function get the module type value according module type string.\r
-\r
- @param moduleTypeStr String of modlue type.\r
- @return\r
- **/\r
- static public int getModuleType(String moduleTypeStr) {\r
- int returnValue = -1;\r
- for (int i = 0; i < CommonDefinition.moduleEnum.length; i++) {\r
- returnValue = CommonDefinition.moduleEnum[i].ForInt(moduleTypeStr);\r
- if (returnValue != -1) {\r
- return returnValue;\r
- }\r
- }\r
- return CommonDefinition.ModuleTypeUnknown;\r
- }\r
-\r
- /**\r
- getComponentType\r
-\r
- This function get the component type value according commponet type\r
- string.\r
-\r
- @param componentTypeStr String of component type.\r
- @return\r
- **/\r
- static public int getComponentType (String componentTypeStr){\r
- int returnValue = -1;\r
- for (int i = 0; i < CommonDefinition.componentEnum.length; i++) {\r
- returnValue = CommonDefinition.componentEnum[i].ForInt(componentTypeStr);\r
- if (returnValue != -1) {\r
- return returnValue;\r
- }\r
- }\r
- return CommonDefinition.ComponentTypeUnknown;\r
- }\r
-\r
- /**\r
- getComponentTypeString\r
-\r
- This function get the commponet type string according component type value.\r
-\r
- @param componentType Integer value of component type.\r
- @return\r
- **/\r
- static public String getComponentTypeString (int componentType) {\r
- if ((componentType > CommonDefinition.ComponentTypeUnknown) ||\r
- (componentType < CommonDefinition.ComponentTypeNull)) {\r
- return null;\r
- }\r
- for (int index = 0; index < CommonDefinition.componentEnum.length; index++) {\r
- if (componentType == CommonDefinition.componentEnum[index].type) {\r
- return CommonDefinition.componentEnum[index].moduleTypeStr;\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- /**\r
- isLibraryComponent\r
-\r
- This function is to check does componet is library according to commponet\r
- type value.\r
-\r
- @param componentType Integer value of component type.\r
- @return\r
- **/\r
- static public boolean isLibraryComponent (int componentType) {\r
- if (ComponentTypeLibrary == componentType) {\r
- return true;\r
- }\r
- return false;\r
- }\r
-\r
- /**\r
- * formateGuidName\r
- *\r
- * This function is to formate GUID to ANSI c form.\r
- *\r
- * @param guidNameCon\r
- * String of GUID.\r
- * @return Formated GUID.\r
- */\r
- public static String formatGuidName(String guidNameConv) {\r
- String[] strList;\r
- String guid = "";\r
- int index = 0;\r
- if (guidNameConv\r
- .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {\r
- strList = guidNameConv.split("-");\r
- guid = "0x" + strList[0] + ", ";\r
- guid = guid + "0x" + strList[1] + ", ";\r
- guid = guid + "0x" + strList[2] + ", ";\r
- guid = guid + "{";\r
- guid = guid + "0x" + strList[3].substring(0, 2) + ", ";\r
- guid = guid + "0x" + strList[3].substring(2, 4);\r
-\r
- while (index < strList[4].length()) {\r
- guid = guid + ", ";\r
- guid = guid + "0x" + strList[4].substring(index, index + 2);\r
- index = index + 2;\r
- }\r
- guid = guid + "}";\r
- return guid;\r
- } else if (guidNameConv\r
- .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) {\r
- strList = guidNameConv.split(",");\r
-\r
- //\r
- // chang Microsoft specific form to ANSI c form\r
- //\r
- for (int i = 0; i < 3; i++) {\r
- guid = guid + strList[i] + ",";\r
- }\r
- guid = guid + "{";\r
-\r
- for (int i = 3; i < strList.length; i++) {\r
- if (i == strList.length - 1) {\r
- guid = guid + strList[i];\r
- } else {\r
- guid = guid + strList[i] + ",";\r
- }\r
- }\r
- guid = guid + "}";\r
- return guid;\r
- } else {\r
- System.out\r
- .println("Check GUID Value, it doesn't conform to the registry format specified by the schema!!!");\r
- return "0";\r
-\r
- }\r
- }\r
-\r
- /**\r
- * Remove deuplicat string in list\r
- *\r
- * This function is to duplicat string in list\r
- *\r
- * @param String[]\r
- * String list.\r
- * @return String[] String list which remove the duplicate string.\r
- */\r
- public static String[] remDupString (String[] orgList){\r
- Set<String> strList = new LinkedHashSet<String>();\r
- String[] desList ;\r
- if (orgList == null){\r
- return new String[0];\r
- }\r
- for (int i = 0; i < orgList.length; i++){\r
- strList.add(orgList[i]);\r
- }\r
- desList = new String[strList.size()];\r
- Iterator item = strList.iterator();\r
- int index = 0;\r
- while (item.hasNext()){\r
- desList[index] = (String)item.next();\r
- index++;\r
- }\r
- return desList;\r
- }\r
-\r
-}\r