01: /*
02: * @(#)Main.java 1.11 06/10/25
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.tools.jdwpgen;
28:
29: import java.util.*;
30: import java.io.*;
31:
32: class Main {
33:
34: static String specSource;
35: static Map nameMap = new HashMap();
36: static boolean genDebug = true;
37:
38: static void usage() {
39: System.err.println();
40: System.err.println("java Main <spec_input> <options>...");
41: System.err.println();
42: System.err.println("Options:");
43: System.err.println("-doc <doc_output>");
44: System.err.println("-jdi <java_output>");
45: System.err.println("-include <include_file_output>");
46: System.exit(1);
47: }
48:
49: public static void main(String args[]) throws IOException {
50: Reader reader = null;
51: PrintWriter doc = null;
52: PrintWriter jdi = null;
53: PrintWriter include = null;
54:
55: // Parse arguments
56: for (int i = 0; i < args.length; ++i) {
57: String arg = args[i];
58: if (arg.startsWith("-")) {
59: String fn = args[++i];
60: if (arg.equals("-doc")) {
61: doc = new PrintWriter(new FileWriter(fn));
62: } else if (arg.equals("-jdi")) {
63: jdi = new PrintWriter(new FileWriter(fn));
64: } else if (arg.equals("-include")) {
65: include = new PrintWriter(new FileWriter(fn));
66: } else {
67: System.err.println("Invalid option: " + arg);
68: usage();
69: }
70: } else {
71: specSource = arg;
72: reader = new FileReader(specSource);
73: }
74: }
75: if (reader == null) {
76: System.err.println("<spec_input> must be specified");
77: usage();
78: }
79:
80: Parse parse = new Parse(reader);
81: RootNode root = parse.items();
82: root.parentAndExtractComments();
83: root.prune();
84: root.constrain(new Context());
85: if (doc != null) {
86: root.document(doc);
87: doc.close();
88: }
89: if (jdi != null) {
90: root.genJava(jdi, 0);
91: jdi.close();
92: }
93: if (include != null) {
94: root.genCInclude(include);
95: include.close();
96: }
97: }
98: }
|