1
0
mirror of https://github.com/sethm/symon.git synced 2024-06-01 08:41:32 +00:00

Command Parser.

This commit is contained in:
Seth J. Morabito 2008-12-05 18:03:00 -08:00
parent 7f31c4c950
commit a74322459a
3 changed files with 101 additions and 2 deletions

25
pom.xml
View File

@ -4,7 +4,7 @@
<groupId>com.loomcom.j6502</groupId>
<artifactId>j6502</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<version>0.1.0</version>
<name>j6502</name>
<url>http://www.loomcom.com/j6502</url>
<dependencies>
@ -15,4 +15,27 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Set up Main-Class in the JAR manifest -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.loomcom.j6502.Control</mainClass>
<packageName>com.loomcom.j6502</packageName>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${pom.url}</url>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,70 @@
package com.loomcom.j6502;
import java.io.*;
public class CommandParser {
private BufferedReader m_in;
private BufferedWriter m_out;
public CommandParser(InputStream in, OutputStream out) {
m_in = new BufferedReader(new InputStreamReader(in));
m_out = new BufferedWriter(new OutputStreamWriter(out));
}
public void run() {
try {
String command = null;
greeting();
prompt();
while (!shouldQuit(command = readLine())) {
dispatch(command);
prompt();
}
writeLine("Goodbye!");
} catch (IOException ex) {
System.err.println("Error: " + ex.toString());
System.exit(1);
}
}
/**
* Dispatch the command.
*/
public void dispatch(String command) throws IOException {
writeLine("You entered: " + command);
}
/*******************************************************************
* Private
*******************************************************************/
private void greeting() throws IOException {
writeLine("Welcome to the j6502 Simulator!");
}
private void prompt() throws IOException {
m_out.write("> ");
m_out.flush();
}
private String readLine() throws IOException {
String line = m_in.readLine();
if (line == null) { return null; }
return line.trim();
}
private void writeLine(String line) throws IOException {
m_out.write(line);
m_out.newLine();
m_out.flush();
}
/**
* Returns true if the line is a quit.
*/
private boolean shouldQuit(String line) {
return (line == null || "q".equals(line.toLowerCase()));
}
}

View File

@ -1,11 +1,17 @@
package com.loomcom.j6502;
import java.io.IOException;
/**
* Main control class for the J6502 Simulator.
*/
public class Control {
public static void main(String[] args) {
System.out.println("Hello, world!");
CommandParser parser = new CommandParser(System.in, System.out);
parser.run();
}
}