Command Parser.
This commit is contained in:
1 parent
7f31c4c950
commit
a74322459a
3 files changed
+101
-2
No files matched your search
@@ -4,7 +4,7 @@
|
|||||||
<groupId>com.loomcom.j6502</groupId>
|
<groupId>com.loomcom.j6502</groupId>
|
||||||
<artifactId>j6502</artifactId>
|
<artifactId>j6502</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.1.0</version>
|
||||||
<name>j6502</name>
|
<name>j6502</name>
|
||||||
<url>http://www.loomcom.com/j6502</url>
|
<url>http://www.loomcom.com/j6502</url>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -15,4 +15,27 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</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>
|
</project>
|
||||||
@@ -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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,17 @@
|
|||||||
package com.loomcom.j6502;
|
package com.loomcom.j6502;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main control class for the J6502 Simulator.
|
* Main control class for the J6502 Simulator.
|
||||||
*/
|
*/
|
||||||
public class Control {
|
public class Control {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Hello, world!");
|
|
||||||
|
CommandParser parser = new CommandParser(System.in, System.out);
|
||||||
|
parser.run();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user