From 408a2860249b1b85c919e0bf60c06a9ef7967387 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Sun, 29 Mar 2020 21:06:43 +0100 Subject: [PATCH] Adapt argument handling to process only first batch of dash arguments Signed-off-by: Stefan Marr --- src/som/vm/Universe.java | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/som/vm/Universe.java b/src/som/vm/Universe.java index 6bc5463..54478f0 100644 --- a/src/som/vm/Universe.java +++ b/src/som/vm/Universe.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.math.BigInteger; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.StringTokenizer; @@ -127,13 +128,15 @@ public void errorExit(final String message) { exit(1); } - private String[] handleArguments(String[] arguments) { + private String[] handleArguments(final String[] arguments) { boolean gotClasspath = false; - String[] remainingArgs = new String[arguments.length]; - int cnt = 0; + ArrayList remainingArgs = new ArrayList<>(); + + // read dash arguments only while we haven't seen other kind of arguments + boolean sawOthers = false; for (int i = 0; i < arguments.length; i++) { - if (arguments[i].equals("-cp")) { + if (arguments[i].equals("-cp") && !sawOthers) { if (i + 1 >= arguments.length) { printUsageAndExit(); } @@ -142,10 +145,11 @@ private String[] handleArguments(String[] arguments) { ++i; // skip class path // Checkstyle: resume gotClasspath = true; - } else if (arguments[i].equals("-d")) { + } else if (arguments[i].equals("-d") && !sawOthers) { dumpBytecodes = true; } else { - remainingArgs[cnt++] = arguments[i]; + sawOthers = true; + remainingArgs.add(arguments[i]); } } @@ -154,14 +158,10 @@ private String[] handleArguments(String[] arguments) { classPath = setupDefaultClassPath(0); } - // Copy the remaining elements from the original array into the new - // array - arguments = new String[cnt]; - System.arraycopy(remainingArgs, 0, arguments, 0, cnt); + // check first of remaining args for class paths, and strip file extension - // check remaining args for class paths, and strip file extension - for (int i = 0; i < arguments.length; i++) { - String[] split = getPathClassExt(arguments[i]); + if (!remainingArgs.isEmpty()) { + String[] split = getPathClassExt(remainingArgs.get(0)); if (!("".equals(split[0]))) { // there was a path String[] tmp = new String[classPath.length + 1]; @@ -169,10 +169,10 @@ private String[] handleArguments(String[] arguments) { tmp[0] = split[0]; classPath = tmp; } - arguments[i] = split[1]; + remainingArgs.set(0, split[1]); } - return arguments; + return remainingArgs.toArray(new String[remainingArgs.size()]); } // take argument of the form "../foo/Test.som" and return