Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/tools/util/CommandLine.java
38918 views
/*1* Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.util;2627import java.io.IOException;28import java.io.Reader;29import java.io.FileReader;30import java.io.BufferedReader;31import java.io.StreamTokenizer;32import java.util.List;33import java.util.ArrayList;3435/**36* Various utility methods for processing Java tool command line arguments.37*38* WARNING: The contents of this source file are not part of any39* supported API. Code that depends on them does so at its own risk:40* they are subject to change or removal without notice.41*/42public class CommandLine {43/**44* Process Win32-style command files for the specified command line45* arguments and return the resulting arguments. A command file argument46* is of the form '@file' where 'file' is the name of the file whose47* contents are to be parsed for additional arguments. The contents of48* the command file are parsed using StreamTokenizer and the original49* '@file' argument replaced with the resulting tokens. Recursive command50* files are not supported. The '@' character itself can be quoted with51* the sequence '@@'.52*/53public static String[] parse(String[] args)54throws IOException55{56ArrayList newArgs = new ArrayList(args.length);57for (int i = 0; i < args.length; i++) {58String arg = args[i];59if (arg.length() > 1 && arg.charAt(0) == '@') {60arg = arg.substring(1);61if (arg.charAt(0) == '@') {62newArgs.add(arg);63} else {64loadCmdFile(arg, newArgs);65}66} else {67newArgs.add(arg);68}69}70return (String[])newArgs.toArray(new String[newArgs.size()]);71}7273private static void loadCmdFile(String name, List args)74throws IOException75{76Reader r = new BufferedReader(new FileReader(name));77StreamTokenizer st = new StreamTokenizer(r);78st.resetSyntax();79st.wordChars(' ', 255);80st.whitespaceChars(0, ' ');81st.commentChar('#');82st.quoteChar('"');83st.quoteChar('\'');84while (st.nextToken() != st.TT_EOF) {85args.add(st.sval);86}87r.close();88}89}909192