1 16 19 20 package org.apache.xalan.xsltc.util; 21 22 import java.io.FileInputStream ; 23 import java.io.FileNotFoundException ; 24 import java.io.InputStream ; 25 26 35 public class JavaCupRedirect { 36 37 private final static String ERRMSG = 38 "You must supply a filename with the -stdin option."; 39 40 public static void main (String args[]) { 41 42 boolean systemExitOK = true; 45 46 InputStream input = null; 48 49 final int argc = args.length; 51 52 String [] new_args = new String [argc - 2]; 54 int new_argc = 0; 55 56 for (int i = 0; i < argc; i++) { 58 if (args[i].equals("-stdin")) { 60 if ((++i >= argc) || (args[i].startsWith("-"))) { 62 System.err.println(ERRMSG); 63 doSystemExit(systemExitOK); 64 } 65 try { 66 input = new FileInputStream (args[i]); 67 } 68 catch (FileNotFoundException e) { 69 System.err.println("Could not open file "+args[i]); 70 doSystemExit(systemExitOK); 71 } 72 catch (SecurityException e) { 73 System.err.println("No permission to file "+args[i]); 74 doSystemExit(systemExitOK); 75 } 76 } 77 else { 78 if (new_argc == new_args.length) { 79 System.err.println("Missing -stdin option!"); 80 doSystemExit(systemExitOK); 81 } 82 new_args[new_argc++] = args[i]; 83 } 84 } 85 86 System.setIn(input); 87 try { 88 java_cup.Main.main(new_args); 89 } 90 catch (Exception e) { 91 System.err.println("Error running JavaCUP:"); 92 e.printStackTrace(); 93 doSystemExit(systemExitOK); 94 } 95 } 96 public static void doSystemExit (boolean doExit) { 97 if (doExit) 98 System.exit(-1); 99 } 100 } 101 | Popular Tags |