]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/Database.java
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.migration
;
17 import java
.util
.regex
.*;
19 public final class Database
{
20 Database(String path
) throws Exception
{
23 importDBLib("Library.csv");
24 importDBGuid("Guid.csv", "Guid");
25 importDBGuid("Ppi.csv", "Ppi");
26 importDBGuid("Protocol.csv", "Protocol");
27 importDBMacro("Macro.csv");
31 public String DatabasePath
;
32 public Set
<String
> error
= new HashSet
<String
>();
33 public Set
<String
> r8only
= new HashSet
<String
>();
35 private Map
<String
,Guid
> hashguid
= new HashMap
<String
,Guid
>();
36 private Map
<String
,Func
> hashfunc
= new HashMap
<String
,Func
>();
37 private Map
<String
,Macro
> hashmacro
= new HashMap
<String
,Macro
>();
39 //-------------------------------------import------------------------------------------//
41 private void importDBLib(String filename
) throws Exception
{
42 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
48 System
.out
.println("Found " + filename
+ ", Importing Library Database.");
49 while ((line
= rd
.readLine()) != null) {
50 if (line
.length() != 0) {
51 linecontext
= line
.split(",");
52 lf
= new Func(linecontext
);
53 hashfunc
.put(lf
.r8funcname
,lf
);
59 private void importDBGuid(String filename
, String type
) throws Exception
{
60 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
66 System
.out
.println("Found " + filename
+ ", Importing " + type
+ " Database.");
67 while ((line
= rd
.readLine()) != null) {
68 if (line
.length() != 0) {
69 linecontext
= line
.split(",");
70 gu
= new Guid(linecontext
, type
);
71 hashguid
.put(gu
.r8name
,gu
);
77 private void importDBMacro(String filename
) throws Exception
{
78 BufferedReader rd
= new BufferedReader(new FileReader(DatabasePath
+ File
.separator
+ filename
));
84 System
.out
.println("Found " + filename
+ ", Importing Macro Database.");
85 while ((line
= rd
.readLine()) != null) {
86 if (line
.length() != 0) {
87 linecontext
= line
.split(",");
88 mc
= new Macro(linecontext
);
89 hashmacro
.put(mc
.r8name
,mc
);
95 private void importListR8Only() throws Exception
{
96 Pattern ptnr8only
= Pattern
.compile("////#?(\\w*)?.*?R8_(.*?)\\s*\\(.*?////~", Pattern
.DOTALL
);
97 String wholeline
= Common
.file2string(DatabasePath
+ File
.separator
+ "R8Lib.c");
98 System
.out
.println("Found " + "R8Lib.c" + ", Importing R8Lib Database.");
99 Matcher mtrr8only
= ptnr8only
.matcher(wholeline
);
100 while (mtrr8only
.find()) {
101 r8only
.add(mtrr8only
.group(2));
105 //-------------------------------------import------------------------------------------//
107 //-------------------------------------get------------------------------------------//
109 public String
getR9Lib(String r8funcname
) {
111 if (hashfunc
.containsKey(r8funcname
)) {
112 temp
= hashfunc
.get(r8funcname
).r9libname
;
117 public String
getR9Func(String r8funcname
) {
119 if (hashfunc
.containsKey(r8funcname
)) {
120 temp
= hashfunc
.get(r8funcname
).r9funcname
;
125 public String
getR9Macro(String r8macro
) {
126 return hashmacro
.get(r8macro
).r9name
; // the verification job of if the macro exists in the database is done when registering it
129 public String
getR9Guidname(String r8Guid
) {
132 temp
= hashguid
.get(r8Guid
).r9name
;
133 } catch (NullPointerException e
) {
134 error
.add("getR9Guidname :" + r8Guid
);
139 public String
getGuidType(String r8Guid
) {
142 temp
= hashguid
.get(r8Guid
).type
;
143 } catch (NullPointerException e
) {
144 error
.add("getR9Guidname :" + r8Guid
);
149 //-------------------------------------get------------------------------------------//
151 //-------------------------------------has------------------------------------------//
153 public boolean hasFunc(String r8lib
) {
154 return hashfunc
.containsKey(r8lib
);
157 public boolean hasGuid(String r8guid
) {
158 return hashguid
.containsKey(r8guid
);
161 public boolean hasMacro(String r8macro
) {
162 return hashmacro
.containsKey(r8macro
);
165 //-------------------------------------has------------------------------------------//
167 //-------------------------------------init------------------------------------------//
169 public static Database
init() throws Exception
{
170 if (System
.getenv("WORKSPACE") == null) {
171 return new Database("C:" + File
.separator
+ "tianocore" + File
.separator
+ "edk2" + File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ "Migration");
173 return new Database(System
.getenv("WORKSPACE") + File
.separator
+ "Tools" + File
.separator
+ "Conf" + File
.separator
+ "Migration");