public static void main(String args[]) { // 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); throw new RuntimeException(ERRMSG); } try { input = new FileInputStream(args[i]); } catch (FileNotFoundException e) { System.err.println("Could not open file " + args[i]); throw new RuntimeException(e.getMessage()); } catch (SecurityException e) { System.err.println("No permission to file " + args[i]); throw new RuntimeException(e.getMessage()); } } else { if (new_argc == new_args.length) { System.err.println("Missing -stdin option!"); throw new RuntimeException(); } new_args[new_argc++] = args[i]; } } System.setIn(input); try { java_cup.Main.main(new_args); } catch (Exception e) { System.err.println("Error running JavaCUP:"); e.printStackTrace(); } }
protected static void saveToDataFile(Object obj, String name) { ObjectOutputStream o = null; try { FileOutputStream out = new FileOutputStream(Main.getDataFilePath(name)); o = new ObjectOutputStream(out); o.writeObject(obj); } catch (IOException ioex) { throw new RuntimeException(ioex); } finally { if (o != null) { try { o.close(); } catch (Exception e) { } } } }