001: /*
002: * Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.javah;
027:
028: import java.io.*;
029:
030: /**
031: * Javah generates support files for native methods.
032: * Parse commandline options & Invokes javadoc to execute those commands.
033: *
034: * @author Sucheta Dambalkar
035: */
036: public class Main {
037: /*
038: * Parse arguments given for javah to give proper error messages.
039: */
040: public static void main(String[] args) {
041:
042: if (args.length == 0) {
043: Util.usage(1);
044: }
045: for (int i = 0; i < args.length; i++) {
046: if (args[i].equals("-o")) {
047: i++;
048: if (i >= args.length) {
049: Util.usage(1);
050: } else if (args[i].charAt(0) == '-') {
051: Util.error("no.outputfile.specified");
052: } else if ((i + 1) >= args.length) {
053: Util.error("no.classes.specified");
054: }
055: } else if (args[i].equals("-d")) {
056: i++;
057: if (i >= args.length) {
058: Util.usage(1);
059: } else if (args[i].charAt(0) == '-') {
060: Util.error("no.outputdir.specified");
061: } else if ((i + 1) >= args.length) {
062: Util.error("no.classes.specified");
063: }
064: } else if (args[i].equals("-td")) {
065: /* Ignored. Generate tmp files to memory. */
066: i++;
067: if (i == args.length)
068: Util.usage(1);
069: } else if (args[i].equals("-stubs")) {
070: if ((i + 1) >= args.length) {
071: Util.error("no.classes.specified");
072: }
073: } else if (args[i].equals("-v")
074: || args[i].equals("-verbose")) {
075: if ((i + 1) >= args.length) {
076: Util.error("no.classes.specified");
077: }
078: args[i] = "-verbose";
079: } else if ((args[i].equals("-help"))
080: || (args[i].equals("--help"))
081: || (args[i].equals("-?")) || (args[i].equals("-h"))) {
082: Util.usage(0);
083: } else if (args[i].equals("-trace")) {
084: System.err.println(Util
085: .getText("tracing.not.supported"));
086: } else if (args[i].equals("-version")) {
087: if ((i + 1) >= args.length) {
088: Util.version();
089: }
090: } else if (args[i].equals("-jni")) {
091: if ((i + 1) >= args.length) {
092: Util.error("no.classes.specified");
093: }
094: } else if (args[i].equals("-force")) {
095: if ((i + 1) >= args.length) {
096: Util.error("no.classes.specified");
097: }
098: } else if (args[i].equals("-Xnew")) {
099: // we're already using the new javah
100: } else if (args[i].equals("-old")) {
101: System.err.println(Util.getText("old.not.supported"));
102: Util.usage(1);
103: } else if (args[i].equals("-Xllni")) {
104: if ((i + 1) >= args.length) {
105: Util.error("no.classes.specified");
106: }
107: } else if (args[i].equals("-llni")) {
108: if ((i + 1) >= args.length) {
109: Util.error("no.classes.specified");
110: }
111: } else if (args[i].equals("-llniDouble")) {
112: if ((i + 1) >= args.length) {
113: Util.error("no.classes.specified");
114: }
115: } else if (args[i].equals("-classpath")) {
116: i++;
117: if (i >= args.length) {
118: Util.usage(1);
119: } else if (args[i].charAt(0) == '-') {
120: Util.error("no.classpath.specified");
121: } else if ((i + 1) >= args.length) {
122: Util.error("no.classes.specified");
123: }
124: } else if (args[i].equals("-bootclasspath")) {
125: i++;
126: if (i >= args.length) {
127: Util.usage(1);
128: } else if (args[i].charAt(0) == '-') {
129: Util.error("no.bootclasspath.specified");
130: } else if ((i + 1) >= args.length) {
131: Util.error("no.classes.specified");
132: }
133: } else if (args[i].charAt(0) == '-') {
134: Util.error("unknown.option", args[i], null, true);
135:
136: } else {
137: //break; /* The rest must be classes. */
138: }
139: }
140:
141: /* Invoke javadoc */
142:
143: String[] javadocargs = new String[args.length + 2];
144: int i = 0;
145:
146: for (; i < args.length; i++) {
147: javadocargs[i] = args[i];
148: }
149:
150: javadocargs[i] = "-private";
151: i++;
152: javadocargs[i] = "-Xclasses";
153:
154: com.sun.tools.javadoc.Main.execute("javadoc",
155: "com.sun.tools.javah.MainDoclet", javadocargs);
156: }
157: }
|