1 20 21 package cpmake; 22 23 import java.io.*; 24 import java.util.regex.*; 25 import java.util.*; 26 27 class CDependencyParser 28 implements DependencyParser, Serializable 29 { 30 public boolean canRecurse() 31 { 32 return (true); 33 } 34 35 public String [] parseFile(File file) 36 throws IOException 37 { 38 BufferedReader srcFile = new BufferedReader(new FileReader(file)); 39 String line; 40 boolean inComment = false; 41 int index; 42 Pattern pattern = Pattern.compile("#\\s*include.+[<\"](.+)[>\"]"); 43 Matcher matcher; 44 Vector dependency = new Vector(); 45 46 while ((line = srcFile.readLine()) != null) 47 { 48 if (inComment && ((index = line.indexOf("*/")) != -1) && 49 ((line.indexOf("/*", index)) == -1)) 50 { 51 inComment = false; 52 continue; 53 } 54 55 line = line.trim(); 56 57 if (line.startsWith("#")) 58 { 59 matcher = pattern.matcher(line); 61 if (matcher.find()) 62 dependency.add(matcher.group(1)); 63 } 64 65 if (((index = line.indexOf("/*")) != -1) && ((line.indexOf("*/", index)) == -1)) 66 inComment = true; 67 } 68 69 return ((String [])dependency.toArray(new String [0])); 70 } 71 } 72 | Popular Tags |