Commit cb32ce27 authored by Edoardo Putti's avatar Edoardo Putti Committed by Mart Lubbers

clean some trash formatting in runnner

parent 1377da8a
...@@ -19,25 +19,22 @@ import javax.swing.UIManager; ...@@ -19,25 +19,22 @@ import javax.swing.UIManager;
import nl.uu.cs.ssm.Config; import nl.uu.cs.ssm.Config;
public class Runner extends Thread public class Runner extends Thread {
{
protected int delay = 50 ; protected int delay = 50 ;
SSMRunner ssmRunner;
SSMRunner ssmRunner ; public Runner(int delay) {
public Runner(int delay)
{
this.delay = delay; this.delay = delay;
try { try {
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} }
catch (Exception e) { catch (Exception e) {
} System.out.println("Could not set GUI appearance from system");
ssmRunner = new SSMRunner( this ); }
ssmRunner.initComponents(); ssmRunner = new SSMRunner(this);
ssmRunner.setVisible(true); ssmRunner.initComponents();
ssmRunner.requestFocus() ; ssmRunner.setVisible(true);
ssmRunner.requestFocus() ;
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -66,13 +63,11 @@ public class Runner extends Thread ...@@ -66,13 +63,11 @@ public class Runner extends Thread
System.exit(1); System.exit(1);
} }
public void run() public void run() {
{ while (true) {
while( true )
{
int steppingState = ssmRunner.steppingState() ; int steppingState = ssmRunner.steppingState() ;
if ( steppingState != SSMRunner.STEP_BY_STEP ) // handle emulation direction
{ if (steppingState != SSMRunner.STEP_BY_STEP) {
if ( ssmRunner.hasBreakpointAtPC() ) if ( ssmRunner.hasBreakpointAtPC() )
ssmRunner.stopContinuouslyDoingSteps() ; ssmRunner.stopContinuouslyDoingSteps() ;
else if ( steppingState == SSMRunner.STEP_CONT_FORWARD ) else if ( steppingState == SSMRunner.STEP_CONT_FORWARD )
...@@ -80,17 +75,22 @@ public class Runner extends Thread ...@@ -80,17 +75,22 @@ public class Runner extends Thread
else if ( steppingState == SSMRunner.STEP_CONT_BACKWARD ) else if ( steppingState == SSMRunner.STEP_CONT_BACKWARD )
ssmRunner.doAStepBack() ; ssmRunner.doAStepBack() ;
} }
try { sleep( delay ) ; } catch ( InterruptedException e ) {} // try to wait for the delay
try {
sleep(delay);
} catch ( InterruptedException e ) {
System.err.println("-- woke up too early");
}
} }
} }
// Main entry point
static public void main(String[] args) throws IOException { static public void main(String[] args) throws IOException {
File initialFile = null; File initialFile = null;
long steps = -1; long steps = -1;
boolean stdin = false; boolean stdin = false;
boolean cli = false; boolean cli = false;
int guiDelay =50; int guiDelay = 50;
for (int i = 0; i< args.length; i++) { for (int i = 0; i< args.length; i++) {
String key = args[i]; String key = args[i];
switch(key) { switch(key) {
...@@ -106,15 +106,15 @@ public class Runner extends Thread ...@@ -106,15 +106,15 @@ public class Runner extends Thread
steps = Long.parseLong(args[i]); steps = Long.parseLong(args[i]);
break; break;
case "--stdin": case "--stdin":
if(initialFile != null) { stdin = true;
System.out.println("--stdin cannot be used with --file"); if (initialFile != null) {
System.err.println("--stdin cannot be used with --file");
usage(); usage();
} }
stdin=true;
break; break;
case "--file": case "--file":
if(stdin) { if (stdin) {
System.out.println("--file cannot be used with --stdin"); System.err.println("--file cannot be used with --stdin");
usage(); usage();
} else { } else {
i++; i++;
...@@ -133,36 +133,35 @@ public class Runner extends Thread ...@@ -133,36 +133,35 @@ public class Runner extends Thread
} }
} }
if(initialFile != null && !initialFile.exists()) { if (initialFile != null && !initialFile.exists()) {
System.out.println("Input file does not exist"); System.err.println("No input file" + initialFile);
usage(); usage();
} }
if(cli) { if (cli) {
CliRunner cliRunner = new CliRunner( steps); CliRunner cliRunner = new CliRunner(steps);
if(stdin) { if (stdin) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
cliRunner.load(reader); cliRunner.load(reader);
reader.close(); reader.close();
} else { } else {
if(!stdin && initialFile == null) { if (!stdin && initialFile == null) {
System.out.println("Need some input in CLI mode"); System.err.println("Need some input in CLI mode");
} }
FileReader fr = new FileReader( initialFile ) ; FileReader fr = new FileReader( initialFile ) ;
cliRunner.load(fr); cliRunner.load(fr);
fr.close(); fr.close();
} }
cliRunner.run(); cliRunner.run();
} else { } else {
Runner r = new Runner(guiDelay); Runner r = new Runner(guiDelay);
if(stdin) { if(stdin) {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
r.loadReader(reader); r.loadReader(reader);
reader.close(); reader.close();
} else if(initialFile != null) { } else if (initialFile != null) {
r.loadFile(initialFile); r.loadFile(initialFile);
} }
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment