01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.util.make;
12:
13: import java.io.File;
14: import java.io.FileReader;
15: import java.util.HashSet;
16:
17: public class MakefileReader {
18:
19: /** stores found rules */
20: private HashSet hset;
21:
22: /** the makefile */
23: private File file;
24:
25: public MakefileReader(File file) {
26: this .file = file;
27: }
28:
29: private void gotoNextLine(FileReader fr) {
30: try {
31: while (fr.read() != (int) '\n') {
32: }
33: } catch (Exception e) {
34: System.out.println("Error reading file.");
35: }
36: }
37:
38: private void read(FileReader fr) {
39: try {
40: String readStr = "";
41: int read = fr.read();
42: while (read != -1) {
43: if (read == (int) '\n' || read == (int) '\r') {
44: readStr = "";
45: } else if (read == (int) '\t') {
46: readStr = "";
47: gotoNextLine(fr);
48: } else {
49: if (read != (int) ':') {
50: readStr = readStr + (char) read;
51: } else {
52: hset.add(readStr);
53: readStr = "";
54: gotoNextLine(fr);
55: }
56: }
57: read = fr.read();
58: }
59: } catch (Exception e) {
60: System.err.println("Error reading file.");
61: }
62: }
63:
64: public HashSet getRules() {
65: hset = new HashSet();
66: try {
67: FileReader fr = new FileReader(file);
68: if (hset.size() == 0)
69: read(fr);
70: fr.close();
71: } catch (Exception e) {
72: // if does not exist => empty hashset
73: System.out
74: .println("No rules exist. Will create new ones...");
75: }
76: return hset;
77: }
78:
79: public static void main(String[] args) {
80: HashSet set = new MakefileReader(new File(args[0])).getRules();
81: System.out.println("Read " + set.size() + " rules.");
82: }
83:
84: }
|