]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java
r8lib in database
[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 final class ModuleReader {
21 private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");
22 private static final Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);
23 private static final Pattern ptnfilename = Pattern.compile("[^\\s]+");
24
25 public static final void readMsa(String name, ModuleInfo mi) throws Exception {
26 ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name));
27 ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();
28 MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();
29
30 mi.modulename = msaheader.getModuleName();
31 mi.guidvalue = msaheader.getGuidValue();
32 mi.moduletype = msaheader.getModuleType().toString(); // ???
33
34 SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();
35
36 String temp;
37 Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList().iterator();
38 while (li.hasNext()) {
39 if (!mi.localmodulesources.contains(temp = li.next().toString())) {
40 System.out.println("Source File Missing! : " + temp);
41 }
42 }
43 }
44
45 public static final void readInf(String name, ModuleInfo mi) throws Exception {
46 System.out.println("\nParsing INF file: " + name);
47 String wholeline;
48 Matcher mtrinfequation;
49 Matcher mtrsection;
50 Matcher mtrfilename;
51
52 wholeline = Common.file2string(mi.modulepath + File.separator + name);
53 mtrsection = ptnsection.matcher(wholeline);
54 while (mtrsection.find()) {
55 if (mtrsection.group(1).matches("defines")) {
56 mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
57 while (mtrinfequation.find()) {
58 if (mtrinfequation.group(1).matches("BASE_NAME")) {
59 mi.modulename = mtrinfequation.group(2);
60 }
61 if (mtrinfequation.group(1).matches("FILE_GUID")) {
62 mi.guidvalue = mtrinfequation.group(2);
63 }
64 if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {
65 mi.moduletype = mtrinfequation.group(2);
66 }
67 }
68 }
69 if (mtrsection.group(1).matches("nmake.common")) {
70 mtrinfequation = ptninfequation.matcher(mtrsection.group(2));
71 while (mtrinfequation.find()) {
72 if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {
73 mi.entrypoint = mtrinfequation.group(2);
74 }
75 if (mtrinfequation.group(1).matches("DPX_SOURCE")) {
76 if (!mi.localmodulesources.contains(mtrinfequation.group(2))) {
77 MigrationTool.ui.println("DPX File Missing! : " + mtrinfequation.group(2));
78 }
79 }
80 }
81 }
82 if (mtrsection.group(1).contains("sources.")) {
83 mtrfilename = ptnfilename.matcher(mtrsection.group(2));
84 while (mtrfilename.find()) {
85 if (!mi.localmodulesources.contains(mtrfilename.group())) {
86 MigrationTool.ui.println("Source File Missing! : " + mtrfilename.group());
87 }
88 }
89 }
90 }
91 }
92 }