Skip to content

Commit

Permalink
Adapt argument handling to process only first batch of dash arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Mar 29, 2020
1 parent c6e9e25 commit 408a286
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/som/vm/Universe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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();
}
Expand All @@ -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]);
}
}

Expand All @@ -154,25 +158,21 @@ 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];
System.arraycopy(classPath, 0, tmp, 1, classPath.length);
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
Expand Down

0 comments on commit 408a286

Please sign in to comment.