Repository navigation
Expand file tree
/
Copy pathLoader.java
More file actions
79 lines (73 loc) · 1.84 KB
/
Copy pathLoader.java
File metadata and controls
79 lines (73 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.io.*;
/**
* Is the very first ThreadOS thread tid[0] that launches a user
* thread and waits for its termination.
*/
public class Loader extends Thread
{
static final int OK = 0;
static final int ERROR = -1;
/**
* Is a default constructor.
*/
public Loader( ) {
}
/**
* Is a constructor that receives arguments but the current
* version does not care about arguments.
*
* @param args[] is not used at present.
*/
public Loader( String args[] ) {
}
/**
* Is a help function to summarize what commands the loader can accept.
*/
private static void help( ) {
SysLib.cout( "?: print a help message\n" );
SysLib.cout( "q: exit from threadOS\n" );
SysLib.cout( "l prog: load prog\n" );
}
/**
* Is the Loader thread's body. It repeatedly prints out a prompt
* (-->); interprets a given command such as '?', 'q', 'l', and 'r';
* and launch a user application as a child thead if 'l' was
* given.
*/
public void run( ) {
String cmdLine = "";
char cmd = ' ';
while ( true ) {
do {
StringBuffer inputBuf = new StringBuffer( );
SysLib.cerr( "-->" );
SysLib.cin( inputBuf );
cmdLine = inputBuf.toString( );
} while ( cmdLine.length( ) == 0 );
System.out.println( cmdLine );
cmd = cmdLine.charAt( 0 );
switch( cmd ) {
case '?': // help
help( );
break;
case 'q': // quit
SysLib.sync( );
System.exit( 1 );
break;
case 'l': // launch a thread
try {
String intrArgs[]
= SysLib.stringToArgs( cmdLine.substring( 2 ) );
if ( SysLib.exec( intrArgs ) == ERROR ) {
SysLib.cerr( intrArgs[0] + " failed in loading\n" );
break;
}
SysLib.join( );
} catch( Exception e ) { e.printStackTrace( ); }
break;
case 'r': // repeat
break;
}
}
}
}