KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cpmake > CDependencyParser


1 /*
2  * Copyright (c) 2005, Brian Hawkins
3  * brianhks@activeclickweb.com
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation; either version 2 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

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 JavaDoc[] parseFile(File file)
36             throws IOException
37         {
38         BufferedReader srcFile = new BufferedReader(new FileReader(file));
39         String JavaDoc 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                 //System.out.println(line);
60
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 JavaDoc[])dependency.toArray(new String JavaDoc[0]));
70         }
71     }
72
Popular Tags