blob: ed305ba74bce0ec759407938e1bb888f44df53fc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package org.gnunet.seaspider;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.gnunet.seaspider.parser.CParser;
import org.gnunet.seaspider.parser.ParseException;
import org.gnunet.seaspider.parser.nodes.Node;
public class Seaspider {
static final boolean DEBUG = true;
public static void main(String args[])
{
CParser parser = null;
boolean isFirstFile = true;
int fileNotFoundCount = 0;
int successCount = 0;
int failureCount = 0;
if (args.length != 2)
{
System.err.println("Invoke seaspider with database filename and source path!");
System.exit(1);
}
System.out.println("Seaspider 0.0\n");
System.out.println("Reading from " + args[1] + " source directory...");
String gnunetSourcePath = args[1];
/* Filtering out files */
FileFilter filter = new FileFilter() {
public boolean accept(File file) {
return file.isDirectory();
}
};
/* File filter to get only source and header files */
FileFilter sourceFilter = new FileFilter() {
public boolean accept(File file) {
String fileName = file.getName();
System.out.println ("Found file " + fileName);
return (fileName.endsWith(".c") || fileName.endsWith(".h"));
}
};
/* Create the Expressions Database */
ExpressionDatabaseHandler.createExpressionDatabase(args[0]);
File[] dirArr = (new File(gnunetSourcePath)).listFiles(filter);
for (int i = 0; i < dirArr.length; i++) {
File dir = dirArr[i];
File[] fileArr = dir.listFiles(sourceFilter);
for (int j = 0; j < fileArr.length; j++) {
try {
if (isFirstFile) {
parser = new CParser(new FileInputStream(fileArr[j].getPath()));
isFirstFile = false;
}
else
parser.ReInit(new FileInputStream(fileArr[j].getPath()));
}
catch (FileNotFoundException e) {
fileNotFoundCount++;
e.printStackTrace();
}
try {
System.out.println("Parsing file: " + dir + "/" + fileArr[j].getName());
Node root = parser.TranslationUnit();
root.accept(new ExpressionExtractorVisitor(fileArr[j].getName()));
System.out.println("File " + dir + "/" + fileArr[j].getName() + " parsed successfully.");
successCount++;
}
catch (ParseException e) {
System.out.println("Encountered errors during parsing file " + fileArr[j].getName());
failureCount++;
if (DEBUG)
e.printStackTrace();
}
}
}
/* We're done with the Expression Database, close it */
ExpressionDatabaseHandler.closeDatabase();
System.out.println(successCount + " parsed successfully.");
System.out.println("Failed to parse " + failureCount + " files.");
System.out.println(fileNotFoundCount + " files not found.");
}
}
|