1 59 60 package com.sun.org.apache.xalan.internal.xsltc.util; 61 62 import java.io.FileInputStream ; 63 import java.io.FileNotFoundException ; 64 import java.io.InputStream ; 65 66 75 public class JavaCupRedirect { 76 77 private final static String ERRMSG = 78 "You must supply a filename with the -stdin option."; 79 80 public static void _main (String args[]) { 81 82 boolean systemExitOK = true; 85 86 InputStream input = null; 88 89 final int argc = args.length; 91 92 String [] new_args = new String [argc - 2]; 94 int new_argc = 0; 95 96 for (int i = 0; i < argc; i++) { 98 if (args[i].equals("-stdin")) { 100 if ((++i >= argc) || (args[i].startsWith("-"))) { 102 System.err.println(ERRMSG); 103 doSystemExit(systemExitOK); 104 } 105 try { 106 input = new FileInputStream (args[i]); 107 } 108 catch (FileNotFoundException e) { 109 System.err.println("Could not open file "+args[i]); 110 doSystemExit(systemExitOK); 111 } 112 catch (SecurityException e) { 113 System.err.println("No permission to file "+args[i]); 114 doSystemExit(systemExitOK); 115 } 116 } 117 else { 118 if (new_argc == new_args.length) { 119 System.err.println("Missing -stdin option!"); 120 doSystemExit(systemExitOK); 121 } 122 new_args[new_argc++] = args[i]; 123 } 124 } 125 126 System.setIn(input); 127 try { 128 com.sun.java_cup.internal.Main.main(new_args); 129 } 130 catch (Exception e) { 131 System.err.println("Error running JavaCUP:"); 132 e.printStackTrace(); 133 doSystemExit(systemExitOK); 134 } 135 } 136 public static void doSystemExit (boolean doExit) { 137 if (doExit) 138 System.exit(-1); 139 } 140 } 141 142 | Popular Tags |