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