Turn to Regex in ModuleReader.java
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / ModuleReader.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 import org.tianocore.*;
19
20 public class ModuleReader {
21 ModuleReader(String path, ModuleInfo moduleinfo, Database database, UI u) {
22 modulepath = path;
23 mi = moduleinfo;
24 db = database;
25 ui = u;
26 }
27 private String modulepath;
28 private ModuleInfo mi;
29 private Database db;
30 private UI ui;
31
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]+");
35
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();
40
41 mi.modulename = msaheader.getModuleName();
42 mi.guidvalue = msaheader.getGuidValue();
43 mi.moduletype = msaheader.getModuleType().toString(); // ???
44
45 SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();
46
47 String temp;
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);
52 }
53 }
54 }
55
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));
59 String line;
60 String wholeline;
61 String[] linecontext;
62 boolean inSrc = false;
63 Matcher mtrinfequation;
64 Matcher mtrsection;
65 Matcher mtrfilename;
66
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);
75 }
76 if (mtrinfequation.group(1).matches("FILE_GUID")) {
77 mi.guidvalue = mtrinfequation.group(2);
78 }
79 if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {
80 mi.moduletype = mtrinfequation.group(2);
81 }
82 }
83 }
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);
89 }
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));
93 }
94 }
95 }
96 }
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());
102 }
103 }
104 }
105 }
106 }
107 }