-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
93 lines (81 loc) · 2.77 KB
/
Main.java
File metadata and controls
93 lines (81 loc) · 2.77 KB
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
import java.io.File;
import java.io.FileFilter;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import treeutils.ReverseEngineer;
import treeutils.data.EAST;
import util.ResultRecorder;
import util.ResultRecorder.Statistics;
/**
* This module hides how the program begins its execution, and how the user
* input from the command line is used to determine the input Fortran files
* to be reverse engineered.
*
* @author Olivier Dragon <dragonoe@mcmaster.ca>
*/
public class Main
{
public static void main(String[] args)
{
long starttime = System.currentTimeMillis();
ReverseEngineer eng = new ReverseEngineer();
SortedMap<File, EAST> files = new TreeMap<File,EAST>();
for (String arg : args)
getFiles(arg, files);
if (files.isEmpty())
System.out.println(
"You must specify at least one file to be parsed.");
else
eng.start(files);
printStatistics(starttime, files.size());
}
private static void printStatistics(long starttime, int filesCount)
{
// Statistics for fun
double time = (System.currentTimeMillis() - starttime) / 1000;
System.out.println("\n" + filesCount + " files processed.");
for (Map.Entry<Statistics,Integer> e
: ResultRecorder.getStats().entrySet())
System.out.println(e.getKey() + ": " + e.getValue());
System.out.println("Execution took " + time + " sec, on average "
+ (time / filesCount) + " sec per file.");
System.out.println("System used "
+ (Runtime.getRuntime().totalMemory() / 1024)
+ "KB of memory.");
}
/**
* Obtain a sorted collection of files from an input specified by the user.
* If <code>filename</code> is a file, then the collection only contains
* that file. If it is a directory then all the fortran files in that
* directory are
*
* @param filename
* @return
*/
private static void getFiles(String filename,
Map<File, EAST> fileSet)
{
File f = new File(filename);
if (f.exists())
{
if (f.isDirectory())
{
for (File file : f.listFiles(new Filter()))
fileSet.put(file, null);
}
else if (f.isFile())
fileSet.put(f, null);
}
}
private static class Filter implements FileFilter
{
public boolean accept(File f)
{
return f.getName().endsWith(".f") ||
f.getName().endsWith(".F") ||
f.getName().endsWith(".for") ||
f.getName().endsWith(".FOR");
}
}
}