summaryrefslogtreecommitdiff
path: root/Source/Applications
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-23 19:40:08 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-23 19:40:08 +0200
commit48de0cd029b52f64f76345b6e1fdf3cde5c58de3 (patch)
tree792061381c556bef6639b327716cca107f6168c5 /Source/Applications
parentf0556ed7f051fb101dc68752526696365bf79a11 (diff)
downloadMelon-48de0cd029b52f64f76345b6e1fdf3cde5c58de3.tar.gz
Melon-48de0cd029b52f64f76345b6e1fdf3cde5c58de3.zip
More work on syscalls and shell
Diffstat (limited to 'Source/Applications')
-rw-r--r--Source/Applications/Shell/Makefile3
-rw-r--r--Source/Applications/Shell/Shell-fs.ns.cpp52
-rw-r--r--Source/Applications/Shell/Shell.ns.cpp32
-rw-r--r--Source/Applications/Shell/Shell.ns.h3
4 files changed, 86 insertions, 4 deletions
diff --git a/Source/Applications/Shell/Makefile b/Source/Applications/Shell/Makefile
index f93d80d..0eeb620 100644
--- a/Source/Applications/Shell/Makefile
+++ b/Source/Applications/Shell/Makefile
@@ -7,7 +7,8 @@ LD = ld
LDFLAGS = -T ../../Library/Link.ld
Objects = main.o \
- Shell.ns.o
+ Shell.ns.o \
+ Shell-fs.ns.o
OutFile = Shell
all: $(OutFile)
diff --git a/Source/Applications/Shell/Shell-fs.ns.cpp b/Source/Applications/Shell/Shell-fs.ns.cpp
new file mode 100644
index 0000000..33bc94e
--- /dev/null
+++ b/Source/Applications/Shell/Shell-fs.ns.cpp
@@ -0,0 +1,52 @@
+#include "Shell.ns.h"
+
+namespace Shell {
+
+void ls(Vector<String>& args) {
+ FSNode d = cwd;
+ if (args.size() == 2) {
+ FSNode n = cwd.findFrom(args[1]);
+ d = FSNode(0);
+ if (!n.valid())
+ outvt << "No such directory : " << args[1] << "\n";
+ else if (n.type() != NT_DIRECTORY)
+ outvt << "Not a directory : " << args[1] << "\n";
+ else
+ d = n;
+ }
+ if (d.valid()) outvt << "Contents of directory " << d.path() << " :\n";
+ for (u32int i = 0; i < d.getLength(); i++) {
+ FSNode n = d.getChild(i);
+ if (n.type() == NT_FILE) {
+ outvt << " - FILE\t" << n.getName();
+ outvt.setCsrCol(30);
+ outvt << (s32int)n.getLength() << " bytes.\n";
+ } else if (n.type() == NT_DIRECTORY) {
+ outvt << " - DIR\t" << n.getName() << "/";
+ outvt.setCsrCol(30);
+ outvt << (s32int)n.getLength() << " items.\n";
+ }
+ }
+}
+
+void cd(Vector<String>& args) {
+ if (args.size() != 2) {
+ outvt << "Invalid argument count.\n";
+ } else {
+ FSNode ncwd = cwd.findFrom(args[1]);
+ if (!ncwd.valid()) {
+ outvt << "No such directory : " << args[1] << "\n";
+ } else if (ncwd.type() == NT_DIRECTORY) {
+ ncwd.setCwd();
+ cwd = ncwd;
+ } else {
+ outvt << "Not a directory.\n";
+ }
+ }
+}
+
+void pwd(Vector<String>& args) {
+ outvt << "Current directory : " << cwd.path() << "\n";
+}
+
+}
diff --git a/Source/Applications/Shell/Shell.ns.cpp b/Source/Applications/Shell/Shell.ns.cpp
index d34f516..4afc6b7 100644
--- a/Source/Applications/Shell/Shell.ns.cpp
+++ b/Source/Applications/Shell/Shell.ns.cpp
@@ -3,12 +3,23 @@
namespace Shell {
-FSNode node(0);
+FSNode cwd(0);
+
u32int run() {
- node = FSNode::getRoot();
+ struct { //Command list
+ String name;
+ void (*cmd)(Vector<String>&);
+ } commands[] = {
+ {"ls", ls},
+ {"cd", cd},
+ {"pwd", pwd},
+ {"", 0}
+ };
+
+ cwd = FSNode::getCwd();
while (1) {
- outvt << node.getName() << " : ";
+ outvt << "{" << cwd.getName() << "}: ";
String s = invt.readLine();
while (s[0] == WChar(" ") or s[0] == WChar("\t")) {
s = s.substr(1, s.size() - 1);
@@ -44,6 +55,21 @@ u32int run() {
Sys::reboot();
outvt << "Something went wrong.\n";
} else {
+ u32int i = 0;
+ bool found = false;
+ while (!commands[i].name.empty()) {
+ if (commands[i].name == cmd[0]) {
+ found = true;
+ if (commands[i].cmd == 0) {
+ outvt << "Not implemented yet.\n";
+ } else {
+ commands[i].cmd(cmd);
+ }
+ break;
+ }
+ i++;
+ }
+ if (!found) outvt << "Unknown command : " << cmd[0] << "\n";
}
}
}
diff --git a/Source/Applications/Shell/Shell.ns.h b/Source/Applications/Shell/Shell.ns.h
index 3be1e0d..8d7067a 100644
--- a/Source/Applications/Shell/Shell.ns.h
+++ b/Source/Applications/Shell/Shell.ns.h
@@ -7,4 +7,7 @@ namespace Shell {
extern FSNode cwd;
+ extern void ls(Vector<String>& args);
+ extern void cd(Vector<String>& args);
+ extern void pwd(Vector<String>& args);
}