// If we should call System.exit or not
//@todo make this settable for use inside other java progs
boolean systemExitOK = true;
// This is the stream we'll set as our System.in
InputStream input = null;
// The number of arguments
final int argc = args.length;
// The arguments we'll pass to the real '_main()'
String[] new_args = new String[argc - 2];
int new_argc = 0;
// Parse all parameters passed to this class
for (int i = 0; i < argc; i++) {
// Parse option '-stdin <filename>'
if (args[i].equals("-stdin")) {
// This option must have an argument
if ((++i >= argc) || (args[i].startsWith("-"))) {
System.err.println(ERRMSG);
doSystemExit(systemExitOK);
}
try {
input = new FileInputStream(args[i]);
}
catch (FileNotFoundException e) {
System.err.println("Could not open file "+args[i]);
doSystemExit(systemExitOK);
}
catch (SecurityException e) {
System.err.println("No permission to file "+args[i]);
doSystemExit(systemExitOK);
}
}
else {
if (new_argc == new_args.length) {
System.err.println("Missing -stdin option!");
doSystemExit(systemExitOK);
}
new_args[new_argc++] = args[i];
}
}
System.setIn(input);
try {
com.sun.java_cup.internal.Main.main(new_args);
}
catch (Exception e) {
System.err.println("Error running JavaCUP:");
e.printStackTrace();
doSystemExit(systemExitOK);
}