]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/Database.java
add MigrationTool
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Database.java
1 /** @file
2
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
8
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.
11
12 **/
13 package org.tianocore.migration;
14
15 import java.io.*;
16 import java.util.*;
17 import java.util.regex.*;
18
19 public final class Database {
20 Database(String path) throws Exception {
21 DatabasePath = path;
22
23 importDBLib("Library.csv");
24 importDBGuid("Guid.csv", "Guid");
25 importDBGuid("Ppi.csv", "Ppi");
26 importDBGuid("Protocol.csv", "Protocol");
27 importDBMacro("Macro.csv");
28 importListR8Only();
29 }
30
31 public String DatabasePath;
32 public Set<String> error = new HashSet<String>();
33 public Set<String> r8only = new HashSet<String>();
34
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>();
38
39 //-------------------------------------import------------------------------------------//
40
41 private void importDBLib(String filename) throws Exception {
42 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
43 String line;
44 String[] linecontext;
45 Func lf;
46
47 if (rd.ready()) {
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);
54 }
55 }
56 }
57 }
58
59 private void importDBGuid(String filename, String type) throws Exception {
60 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
61 String line;
62 String[] linecontext;
63 Guid gu;
64
65 if (rd.ready()) {
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);
72 }
73 }
74 }
75 }
76
77 private void importDBMacro(String filename) throws Exception {
78 BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));
79 String line;
80 String[] linecontext;
81 Macro mc;
82
83 if (rd.ready()) {
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);
90 }
91 }
92 }
93 }
94
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));
102 }
103 }
104
105 //-------------------------------------import------------------------------------------//
106
107 //-------------------------------------get------------------------------------------//
108
109 public String getR9Lib(String r8funcname) {
110 String temp = null;
111 if (hashfunc.containsKey(r8funcname)) {
112 temp = hashfunc.get(r8funcname).r9libname;
113 }
114 return temp;
115 }
116
117 public String getR9Func(String r8funcname) {
118 String temp = null;
119 if (hashfunc.containsKey(r8funcname)) {
120 temp = hashfunc.get(r8funcname).r9funcname;
121 }
122 return temp;
123 }
124
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
127 }
128
129 public String getR9Guidname(String r8Guid) {
130 String temp = null;
131 try {
132 temp = hashguid.get(r8Guid).r9name;
133 } catch (NullPointerException e) {
134 error.add("getR9Guidname :" + r8Guid);
135 }
136 return temp;
137 }
138
139 public String getGuidType(String r8Guid) {
140 String temp = null;
141 try {
142 temp = hashguid.get(r8Guid).type;
143 } catch (NullPointerException e) {
144 error.add("getR9Guidname :" + r8Guid);
145 }
146 return temp;
147 }
148
149 //-------------------------------------get------------------------------------------//
150
151 //-------------------------------------has------------------------------------------//
152
153 public boolean hasFunc(String r8lib) {
154 return hashfunc.containsKey(r8lib);
155 }
156
157 public boolean hasGuid(String r8guid) {
158 return hashguid.containsKey(r8guid);
159 }
160
161 public boolean hasMacro(String r8macro) {
162 return hashmacro.containsKey(r8macro);
163 }
164
165 //-------------------------------------has------------------------------------------//
166
167 //-------------------------------------init------------------------------------------//
168
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");
172 } else {
173 return new Database(System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration");
174 }
175 }
176 }