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    
027    package com.sun.tools.javah;
028    
029    
030    import java.io.*;
031    
032    /**
033     * Javah generates support files for native methods.
034     * Parse commandline options & Invokes javadoc to execute those commands.
035     *
036     * @author Sucheta Dambalkar
037     */
038    public class Main{
039        /*
040         * Parse arguments given for javah to give proper error messages.
041         */
042        public static void main(String[] args){
043    
044            if (args.length == 0) {
045                Util.usage(1);
046            }
047            for ( int i = 0; i < args.length; i++) {
048                if (args[i].equals("-o")) {
049                    i++;
050                    if(i >= args.length){
051                        Util.usage(1);
052                    }else if(args[i].charAt(0) == '-'){
053                        Util.error("no.outputfile.specified");
054                    }else if((i+1) >= args.length){
055                        Util.error("no.classes.specified");
056                    }
057                } else if (args[i].equals("-d")) {
058                    i++;
059                    if(i >= args.length){
060                        Util.usage(1);
061                    }else if(args[i].charAt(0) == '-')  {
062                        Util.error("no.outputdir.specified");
063                    }else if((i+1) >= args.length){
064                        Util.error("no.classes.specified");
065                    }
066                } else if (args[i].equals("-td")) {
067                    /* Ignored.  Generate tmp files to memory. */
068                    i++;
069                    if (i == args.length)
070                        Util.usage(1);
071                } else if (args[i].equals("-stubs")) {
072                    if((i+1) >= args.length){
073                        Util.error("no.classes.specified");
074                    }
075                } else if (args[i].equals("-v") || args[i].equals("-verbose")) {
076                    if((i+1) >= args.length){
077                        Util.error("no.classes.specified");
078                    }
079                    args[i] = "-verbose";
080                } else if ((args[i].equals("-help")) || (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.getText("tracing.not.supported"));
085                } else if (args[i].equals("-version")) {
086                    if((i+1) >= args.length){
087                        Util.version();
088                    }
089                } else if (args[i].equals("-jni")) {
090                    if((i+1) >= args.length){
091                        Util.error("no.classes.specified");
092                    }
093                } else if (args[i].equals("-force")) {
094                    if((i+1) >= args.length){
095                        Util.error("no.classes.specified");
096                    }
097                } else if (args[i].equals("-Xnew")) {
098                    // we're already using the new javah
099                } else if (args[i].equals("-old")) {
100                    System.err.println(Util.getText("old.not.supported"));
101                    Util.usage(1);
102                } else if (args[i].equals("-Xllni")) {
103                    if((i+1) >= args.length){
104                        Util.error("no.classes.specified");
105                    }
106                } else if (args[i].equals("-llni")) {
107                    if((i+1) >= args.length){
108                        Util.error("no.classes.specified");
109                    }
110                } else if (args[i].equals("-llniDouble")) {
111                    if((i+1) >= args.length){
112                        Util.error("no.classes.specified");
113                    }
114                } else if (args[i].equals("-classpath")) {
115                    i++;
116                    if(i >= args.length){
117                        Util.usage(1);
118                    }else if(args[i].charAt(0) == '-') {
119                        Util.error("no.classpath.specified");
120                    }else if((i+1) >= args.length){
121                        Util.error("no.classes.specified");
122                    }
123                } else if (args[i].equals("-bootclasspath")) {
124                    i++;
125                    if(i >= args.length){
126                        Util.usage(1);
127                    }else if(args[i].charAt(0) == '-'){
128                        Util.error("no.bootclasspath.specified");
129                    }else if((i+1) >= args.length){
130                        Util.error("no.classes.specified");
131                    }
132                } else if (args[i].charAt(0) == '-') {
133                    Util.error("unknown.option", args[i], null, true);
134    
135                } else {
136                    //break; /* The rest must be classes. */
137                }
138            }
139    
140            /* Invoke javadoc */
141    
142            String[] javadocargs = new String[args.length + 2];
143            int i = 0;
144    
145            for(; i < args.length; i++) {
146                javadocargs[i] = args[i];
147            }
148    
149            javadocargs[i] = "-private";
150            i++;
151            javadocargs[i] = "-Xclasses";
152    
153            int rc = com.sun.tools.javadoc.Main.execute("javadoc", "com.sun.tools.javah.MainDoclet", javadocargs);
154            System.exit(rc);
155        }
156    }