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
.*;
18 import org
.tianocore
.*;
20 public class ModuleReader
{
21 ModuleReader(String path
, ModuleInfo moduleinfo
, Database database
, UI u
) {
27 private String modulepath
;
28 private ModuleInfo mi
;
32 private static Pattern ptninfequation
= Pattern
.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");
33 private static Pattern ptnsection
= Pattern
.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern
.MULTILINE
);
34 private static Pattern ptnfilename
= Pattern
.compile("[^\\s]+");
36 public void readMsa(String name
) throws Exception
{
37 ModuleSurfaceAreaDocument msadoc
= ModuleSurfaceAreaDocument
.Factory
.parse(new File(modulepath
+ File
.separator
+ name
));
38 ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= msadoc
.getModuleSurfaceArea();
39 MsaHeaderDocument
.MsaHeader msaheader
= msa
.getMsaHeader();
41 mi
.modulename
= msaheader
.getModuleName();
42 mi
.guidvalue
= msaheader
.getGuidValue();
43 mi
.moduletype
= msaheader
.getModuleType().toString(); // ???
45 SourceFilesDocument
.SourceFiles sourcefiles
= msa
.getSourceFiles();
48 Iterator
<FilenameDocument
.Filename
> li
= sourcefiles
.getFilenameList().iterator();
49 while (li
.hasNext()) {
50 if (!mi
.localmodulesources
.contains(temp
= li
.next().toString())) {
51 System
.out
.println("Source File Missing! : " + temp
);
56 public void readInf(String name
) throws Exception
{
57 System
.out
.println("Parsing INF file: " + name
);
58 BufferedReader rd
= new BufferedReader(new FileReader(modulepath
+ File
.separator
+ name
));
62 boolean inSrc
= false;
63 Matcher mtrinfequation
;
67 wholeline
= Common
.sourcefiletostring(modulepath
+ File
.separator
+ name
);
68 mtrsection
= ptnsection
.matcher(wholeline
);
69 while (mtrsection
.find()) {
70 if (mtrsection
.group(1).matches("defines")) {
71 mtrinfequation
= ptninfequation
.matcher(mtrsection
.group(2));
72 while (mtrinfequation
.find()) {
73 if (mtrinfequation
.group(1).matches("BASE_NAME")) {
74 mi
.modulename
= mtrinfequation
.group(2);
76 if (mtrinfequation
.group(1).matches("FILE_GUID")) {
77 mi
.guidvalue
= mtrinfequation
.group(2);
79 if (mtrinfequation
.group(1).matches("COMPONENT_TYPE")) {
80 mi
.moduletype
= mtrinfequation
.group(2);
84 if (mtrsection
.group(1).matches("nmake.common")) {
85 mtrinfequation
= ptninfequation
.matcher(mtrsection
.group(2));
86 while (mtrinfequation
.find()) {
87 if (mtrinfequation
.group(1).matches("IMAGE_ENTRY_POINT")) {
88 mi
.entrypoint
= mtrinfequation
.group(2);
90 if (mtrinfequation
.group(1).matches("DPX_SOURCE")) {
91 if (!mi
.localmodulesources
.contains(mtrinfequation
.group(2))) {
92 ui
.println("DPX File Missing! : " + mtrinfequation
.group(2));
97 if (mtrsection
.group(1).contains("sources.")) {
98 mtrfilename
= ptnfilename
.matcher(mtrsection
.group(2));
99 while (mtrfilename
.find()) {
100 if (!mi
.localmodulesources
.contains(mtrfilename
.group())) {
101 ui
.println("Source File Missing! : " + mtrfilename
.group());