-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal.java
75 lines (70 loc) · 1.99 KB
/
terminal.java
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
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Terminal {
public static void main(String[] args) throws FileNotFoundException {
String path = "src/doritOS";
File doritOS = new File(path);
Scanner inFile = new Scanner(doritOS);
String dir = inFile.nextLine();
inFile.close();
FileSystem fs = new FileSystem(dir);
Scanner inUser = new Scanner(System.in);
System.out.print("computer:" + fs.currentDirName() + " user$ ");
String commandLine = inUser.nextLine();
commandLine = commandLine.replace("\\ ", "\\");
StringTokenizer st = new StringTokenizer(commandLine);
String command = st.nextToken();
while (!command.equals("exit")) {
switch (command) {
case "cd":
if (st.countTokens() >= 1) {
fs.cd(st.nextToken().replace("\\", " "));
}
break;
case "edit":
if (st.countTokens() >= 2) {
fs.edit(st.nextToken().replace("\\", " "), st.nextToken().replace("\\", " "));
}
break;
case "ls":
fs.ls();
break;
case "mkdir":
if (st.countTokens() >= 1) {
fs.mkdir(st.nextToken().replace("\\", " "));
}
break;
case "rm":
if (st.countTokens() >= 1) {
fs.rm(st.nextToken().replace("\\", " "));
}
break;
case "rmdir":
if (st.countTokens() >= 1) {
fs.rmdir(st.nextToken().replace("\\", " "));
}
break;
case "touch":
if (st.countTokens() >= 1) {
fs.touch(st.nextToken().replace("\\", " "));
}
break;
default:
System.out.println("-doritOS: " + command + ": command not found");
}
System.out.print("computer:" + fs.currentDirName() + " user$ ");
commandLine = inUser.nextLine();
commandLine = commandLine.replace("\\ ", "\\");
st = new StringTokenizer(commandLine);
command = st.nextToken();
}
doritOS.delete();
PrintWriter pw = new PrintWriter(path);
pw.println(fs.dir);
pw.close();
inUser.close();
}
}