Turn to Regex in ModuleReader.java
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / ModuleReader.java
index 3f379b7256f5a822358d2e30bac50bd30ca811b1..46fb4994bb39c8362308f4d70c1246ca27b912fd 100644 (file)
@@ -18,16 +18,20 @@ import java.util.regex.*;
 import org.tianocore.*;\r
 \r
 public class ModuleReader {\r
-       ModuleReader(String path, ModuleInfo moduleinfo, Database database) {\r
+       ModuleReader(String path, ModuleInfo moduleinfo, Database database, UI u) {\r
                modulepath = path;\r
                mi = moduleinfo;\r
                db = database;\r
+               ui = u;\r
        }\r
        private String modulepath;\r
        private ModuleInfo mi;\r
        private Database db;\r
+       private UI ui;\r
        \r
-       private static Pattern ptninfequation = Pattern.compile("([^ ]*) *= *([^ ]*)");\r
+       private static Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)");\r
+       private static Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE);\r
+       private static Pattern ptnfilename = Pattern.compile("[^\\s]+");\r
        \r
        public void readMsa(String name) throws Exception {\r
                ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(modulepath + File.separator + name));\r
@@ -53,40 +57,48 @@ public class ModuleReader {
                System.out.println("Parsing INF file: " + name);\r
                BufferedReader rd = new BufferedReader(new FileReader(modulepath + File.separator + name));\r
                String line;\r
+               String wholeline;\r
                String[] linecontext;\r
                boolean inSrc = false;\r
                Matcher mtrinfequation;\r
+               Matcher mtrsection;\r
+               Matcher mtrfilename;\r
 \r
-               while ((line = rd.readLine()) != null) {\r
-                       if (line.length() != 0) {\r
-                               if (inSrc) {\r
-                                       if (line.contains("[")) {\r
-                                               inSrc = false;\r
-                                       } else {\r
-                                               linecontext = line.split(" ");\r
-                                               if (linecontext[2].length() != 0) {\r
-                                                       if (!mi.localmodulesources.contains(linecontext[2])) {\r
-                                                               System.out.println("Source File Missing! : " + linecontext[2]);\r
-                                                       }\r
-                                               }\r
+               wholeline = Common.sourcefiletostring(modulepath + File.separator + name);\r
+               mtrsection = ptnsection.matcher(wholeline);\r
+               while (mtrsection.find()) {\r
+                       if (mtrsection.group(1).matches("defines")) {\r
+                               mtrinfequation = ptninfequation.matcher(mtrsection.group(2));\r
+                               while (mtrinfequation.find()) {\r
+                                       if (mtrinfequation.group(1).matches("BASE_NAME")) {\r
+                                               mi.modulename = mtrinfequation.group(2);\r
                                        }\r
-                               } else {\r
-                                       if ((mtrinfequation = ptninfequation.matcher(line)).find()) {\r
-                                               if (mtrinfequation.group(1).matches("BASE_NAME")) {\r
-                                                       mi.modulename = mtrinfequation.group(2);\r
-                                               }\r
-                                               if (mtrinfequation.group(1).matches("FILE_GUID")) {\r
-                                                       mi.guidvalue = mtrinfequation.group(2);\r
-                                               }\r
-                                               if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {\r
-                                                       mi.moduletype = mtrinfequation.group(2);\r
-                                               }\r
-                                               if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {\r
-                                                       mi.entrypoint = mtrinfequation.group(2);\r
+                                       if (mtrinfequation.group(1).matches("FILE_GUID")) {\r
+                                               mi.guidvalue = mtrinfequation.group(2);\r
+                                       }\r
+                                       if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {\r
+                                               mi.moduletype = mtrinfequation.group(2);\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (mtrsection.group(1).matches("nmake.common")) {\r
+                               mtrinfequation = ptninfequation.matcher(mtrsection.group(2));\r
+                               while (mtrinfequation.find()) {\r
+                                       if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {\r
+                                               mi.entrypoint = mtrinfequation.group(2);\r
+                                       }\r
+                                       if (mtrinfequation.group(1).matches("DPX_SOURCE")) {\r
+                                               if (!mi.localmodulesources.contains(mtrinfequation.group(2))) {\r
+                                                       ui.println("DPX File Missing! : " + mtrinfequation.group(2));\r
                                                }\r
                                        }\r
-                                       if (line.contains("sources")) {\r
-                                               inSrc = true;\r
+                               }\r
+                       }\r
+                       if (mtrsection.group(1).contains("sources.")) {\r
+                               mtrfilename = ptnfilename.matcher(mtrsection.group(2));\r
+                               while (mtrfilename.find()) {\r
+                                       if (!mi.localmodulesources.contains(mtrfilename.group())) {\r
+                                               ui.println("Source File Missing! : " + mtrfilename.group());\r
                                        }\r
                                }\r
                        }\r