01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fit;
04:
05: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
06: // Released under the terms of the GNU General Public License version 2 or later.
07:
08: import java.io.*;
09: import java.util.*;
10:
11: public class FileRunner {
12:
13: public String input;
14:
15: public Parse tables;
16:
17: public Fixture fixture = new Fixture();
18:
19: public PrintWriter output;
20:
21: public static void main(String argv[]) {
22: new FileRunner().run(argv);
23: }
24:
25: public void run(String argv[]) {
26: args(argv);
27: process();
28: exit();
29: }
30:
31: public void process() {
32: try {
33: tables = new Parse(input);
34: fixture.doTables(tables);
35: } catch (Exception e) {
36: exception(e);
37: }
38: tables.print(output);
39: }
40:
41: public void args(String[] argv) {
42: if (argv.length != 2) {
43: System.err
44: .println("usage: java fit.FileRunner input-file output-file");
45: System.exit(-1);
46: }
47: File in = new File(argv[0]);
48: File out = new File(argv[1]);
49: fixture.summary.put("input file", in.getAbsolutePath());
50: fixture.summary
51: .put("input update", new Date(in.lastModified()));
52: fixture.summary.put("output file", out.getAbsolutePath());
53: try {
54: input = read(in);
55: output = new PrintWriter(new BufferedWriter(new FileWriter(
56: out)));
57: } catch (IOException e) {
58: System.err.println(e.getMessage());
59: System.exit(-1);
60: }
61: }
62:
63: protected String read(File input) throws IOException {
64: char chars[] = new char[(int) (input.length())];
65: FileReader in = new FileReader(input);
66: in.read(chars);
67: in.close();
68: return new String(chars);
69: }
70:
71: protected void exception(Exception e) {
72: tables = new Parse("body",
73: "Unable to parse input. Input ignored.", null, null);
74: fixture.exception(tables, e);
75: }
76:
77: protected void exit() {
78: output.close();
79: System.err.println(fixture.counts());
80: System.exit(fixture.counts.wrong + fixture.counts.exceptions);
81: }
82:
83: }
|