0N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.tools.jar;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.io.Reader;
0N/Aimport java.io.FileReader;
0N/Aimport java.io.BufferedReader;
0N/Aimport java.io.StreamTokenizer;
0N/Aimport java.util.List;
0N/Aimport java.util.ArrayList;
0N/A
0N/A/**
0N/A * Various utility methods for processing Java tool command line arguments.
0N/A *
2917N/A * <p><b>This is NOT part of any API supported by Oracle. If
0N/A * you write code that depends on this, you do so at your own risk.
0N/A * This code and its internal interfaces are subject to change or
0N/A * deletion without notice.</b>
0N/A */
0N/Apublic class CommandLine {
0N/A /**
0N/A * Process Win32-style command files for the specified command line
0N/A * arguments and return the resulting arguments. A command file argument
0N/A * is of the form '@file' where 'file' is the name of the file whose
0N/A * contents are to be parsed for additional arguments. The contents of
0N/A * the command file are parsed using StreamTokenizer and the original
0N/A * '@file' argument replaced with the resulting tokens. Recursive command
0N/A * files are not supported. The '@' character itself can be quoted with
0N/A * the sequence '@@'.
0N/A */
0N/A public static String[] parse(String[] args)
0N/A throws IOException
0N/A {
0N/A ArrayList newArgs = new ArrayList(args.length);
0N/A for (int i = 0; i < args.length; i++) {
0N/A String arg = args[i];
0N/A if (arg.length() > 1 && arg.charAt(0) == '@') {
0N/A arg = arg.substring(1);
0N/A if (arg.charAt(0) == '@') {
0N/A newArgs.add(arg);
0N/A } else {
0N/A loadCmdFile(arg, newArgs);
0N/A }
0N/A } else {
0N/A newArgs.add(arg);
0N/A }
0N/A }
0N/A return (String[])newArgs.toArray(new String[newArgs.size()]);
0N/A }
0N/A
0N/A private static void loadCmdFile(String name, List args)
0N/A throws IOException
0N/A {
0N/A Reader r = new BufferedReader(new FileReader(name));
0N/A StreamTokenizer st = new StreamTokenizer(r);
0N/A st.resetSyntax();
0N/A st.wordChars(' ', 255);
0N/A st.whitespaceChars(0, ' ');
0N/A st.commentChar('#');
0N/A st.quoteChar('"');
0N/A st.quoteChar('\'');
0N/A while (st.nextToken() != st.TT_EOF) {
0N/A args.add(st.sval);
0N/A }
0N/A r.close();
0N/A }
0N/A}