-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShell.java
More file actions
78 lines (70 loc) · 1.96 KB
/
Shell.java
File metadata and controls
78 lines (70 loc) · 1.96 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
class Shell extends Thread
{
private String name = "none";
public Shell()
{
SysLib.cout("Starting");
}
public boolean checkExit(String commands[])
{
return commands[0].compareTo("exit") == 0;
}
public void run()
{
boolean exit = false;
int count = 1;
while(!exit)
{
SysLib.cout("Shell["+ count +"]: ");
StringBuffer userCommand = new StringBuffer();
SysLib.cin(userCommand);
String[] commands = SysLib.stringToArgs(userCommand.toString());
if(commands.length < 1)
{
continue;
}
exit = checkExit(commands);
if(exit)
break;
SysLib.cout("\n");
count += 1;
String command = userCommand.toString();
execute(command);
}
SysLib.cout("Exitting");
SysLib.sync();
SysLib.exit();
}
public void execConc(String [] args)
{
int processCount = 0;
for (int i = 0; i < args.length; i++){
String[] commands = SysLib.stringToArgs(args[i]);
SysLib.cout(commands[0] + "\n\t");
if (SysLib.exec(commands) < 0)
processCount--;
processCount++;
}
for (int j = 0; j < processCount; j++)
SysLib.join();
}
public void execute(String args)
{
String[] seqTasks = args.toString().split(";");
for (int i = 0; i < seqTasks.length; i++)
{
SysLib.cout(seqTasks[i]+"\n");
String[] concTasks = seqTasks[i].split("&");
if (concTasks.length == 1)
execCMD(seqTasks[i]);
else
execConc(concTasks);
}
}
public void execCMD(String argument)
{
String [] args = SysLib.stringToArgs(argument);
if (SysLib.exec(args) > 0)
SysLib.join();
}
}