FileDocCategorySizeDatePackage
JavaCupRedirect.javaAPI DocJava SE 5 API5085Fri Aug 26 14:55:42 BST 2005com.sun.org.apache.xalan.internal.xsltc.util

JavaCupRedirect

public class JavaCupRedirect extends Object
Utility class to redirect input to JavaCup program. Usage-command line: java com.sun.org.apache.xalan.internal.xsltc.utils.JavaCupRedirect [args] -stdin filename.ext
author
Morten Jorgensen
version
$Id: JavaCupRedirect.java,v 1.2 2003/01/27 18:44:55 mkwan Exp $

Fields Summary
private static final String
ERRMSG
Constructors Summary
Methods Summary
public static void_main(java.lang.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);
		 		     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);
		 }
    
public static voiddoSystemExit(boolean doExit)

        if (doExit)
            System.exit(-1);