//============================================================================== // TestParser.java //============================================================================== package tribble.net.ftp.shell; // System imports import java.io.FileReader; import java.io.InputStreamReader; import java.io.IOException; import java.io.Reader; import java.io.PrintWriter; import java.lang.Exception; import java.lang.String; import java.lang.System; import java.text.ParseException; /******************************************************************************* * Test driver for class {@link CommandParser}. * * * @version $Revision: 1.3 $ $Date: 2007/03/17 03:40:19 $ * @since API 1.0, 2007-03-14 * @author David R. Tribble (david@tribble.com). *
* Copyright ©2007 by David R. Tribble, all rights reserved.
* Permission is granted to any person or entity except those designated by
* by the United States Department of State as a terrorist, or terrorist
* government or agency, to use and distribute this source code provided
* that the original copyright notice remains present and unaltered.
*/
abstract class TestParser
{
// Identification
/** Revision information. */
static final String REV =
"@(#)tribble/net/ftp/shell/TestParser.java $Revision: 1.3 $ $Date: 2007/03/17 03:40:19 $\n";
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Static variables
/** Standard output stream. */
private static PrintWriter s_stdout =
new PrintWriter(System.out, true);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Static methods
/***************************************************************************
* Test driver for class {@link CommandParser}.
*
*
* Usage *
* * java tribble.net.ftp.shell.TestParser [-e] file * * *
* Options: *
* The file is a script containing FTP commands.
*
* @since 1.1, 2007-03-14
*/
public static void main(String[] args)
throws Exception
{
String fname = null;
Reader in = null;
boolean exprOnly = false;
int i;
// Check args
for (i = 0; i < args.length && args[i].charAt(0) == '-'; i++)
{
if (args[i].equals("-c"))
exprOnly = false;
else if (args[i].equals("-e"))
exprOnly = true;
else if (args[i].equals("-"))
break;
else
i = args.length;
}
// Check usage
if (i >= args.length)
{
// Display a usage message
s_stdout.println("Parse an FTP command script file.");
s_stdout.println();
s_stdout.println("usage: java " + TestParser.class.getName()
+ " [-e] file");
System.exit(255);
}
try
{
CommandParser parser;
CommandNode cmds;
// Open the command input stream
fname = args[i];
if (fname.equals("-"))
in = new InputStreamReader(System.in);
else
in = new FileReader(fname);
// Parse the command script file
parser = new CommandParser(in, s_stdout);
if (exprOnly)
cmds = parser.parseAnExpr();
else
cmds = parser.parse();
// Print the resulting parse tree
s_stdout.println("Parse tree:");
if (cmds != null)
cmds.print(s_stdout);
else
s_stdout.println("