summaryrefslogtreecommitdiff
path: root/Source/Applications/Shell
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Applications/Shell')
-rw-r--r--Source/Applications/Shell/Makefile5
-rw-r--r--Source/Applications/Shell/Shell-fs.class.cpp (renamed from Source/Applications/Shell/Shell-fs.ns.cpp)22
-rw-r--r--Source/Applications/Shell/Shell.class.cpp (renamed from Source/Applications/Shell/Shell.ns.cpp)34
-rw-r--r--Source/Applications/Shell/Shell.class.h28
-rw-r--r--Source/Applications/Shell/Shell.ns.h18
5 files changed, 55 insertions, 52 deletions
diff --git a/Source/Applications/Shell/Makefile b/Source/Applications/Shell/Makefile
index bf81af6..d546a15 100644
--- a/Source/Applications/Shell/Makefile
+++ b/Source/Applications/Shell/Makefile
@@ -6,9 +6,8 @@ CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I .
LD = ld
LDFLAGS = -T ../../Library/Link.ld -L ../../Library
-Objects = main.o \
- Shell.ns.o \
- Shell-fs.ns.o
+Objects = Shell.class.o \
+ Shell-fs.class.o
OutFile = Shell
all: $(OutFile)
diff --git a/Source/Applications/Shell/Shell-fs.ns.cpp b/Source/Applications/Shell/Shell-fs.class.cpp
index 0b51299..150b877 100644
--- a/Source/Applications/Shell/Shell-fs.ns.cpp
+++ b/Source/Applications/Shell/Shell-fs.class.cpp
@@ -1,10 +1,8 @@
-#include "Shell.ns.h"
+#include "Shell.class.h"
#include <TextFile.class.h>
#include <Binding/Process.class.h>
-namespace Shell {
-
-void ls(Vector<String>& args) {
+void Shell::ls(Vector<String>& args) {
FSNode d = cwd;
if (args.size() == 2) {
FSNode n = FS::find(args[1], cwd);
@@ -41,7 +39,7 @@ void ls(Vector<String>& args) {
}
}
-void cd(Vector<String>& args) {
+void Shell::cd(Vector<String>& args) {
if (args.size() != 2) {
outvt << "Invalid argument count.\n";
} else {
@@ -57,11 +55,11 @@ void cd(Vector<String>& args) {
}
}
-void pwd(Vector<String>& args) {
+void Shell::pwd(Vector<String>& args) {
outvt << "Current directory : " << cwd.path() << "\n";
}
-void rm(Vector<String>& args) {
+void Shell::rm(Vector<String>& args) {
if (args.size() == 1) outvt << "No file to remove.\n";
for (u32int i = 1; i < args.size(); i++) {
if (!FS::find(args[i], cwd).remove()) {
@@ -70,7 +68,7 @@ void rm(Vector<String>& args) {
}
}
-void mkdir(Vector<String>& args) {
+void Shell::mkdir(Vector<String>& args) {
if (args.size() == 1) outvt << "No directory to create.\n";
for (u32int i = 1; i < args.size(); i++) {
if (!FS::mkdir(args[i], cwd).valid()) {
@@ -79,7 +77,7 @@ void mkdir(Vector<String>& args) {
}
}
-void cat(Vector<String>& args) {
+void Shell::cat(Vector<String>& args) {
if (args.size() == 1) outvt << "Meow.\n";
for (u32int i = 1; i < args.size(); i++) {
TextFile f(args[i], FM_READ, cwd);
@@ -94,7 +92,7 @@ void cat(Vector<String>& args) {
}
}
-void wf(Vector<String>& args) {
+void Shell::wf(Vector<String>& args) {
if (args.size() == 1) {
outvt << "No file to write !\n";
} else {
@@ -113,7 +111,7 @@ void wf(Vector<String>& args) {
}
}
-void run(Vector<String>& args) {
+void Shell::run(Vector<String>& args) {
if (args.size() == 1) {
outvt << "Nothing to run...\n";
} else {
@@ -132,5 +130,3 @@ void run(Vector<String>& args) {
}
}
}
-
-}
diff --git a/Source/Applications/Shell/Shell.ns.cpp b/Source/Applications/Shell/Shell.class.cpp
index 56a6b5f..3d406c8 100644
--- a/Source/Applications/Shell/Shell.ns.cpp
+++ b/Source/Applications/Shell/Shell.class.cpp
@@ -1,25 +1,25 @@
-#include "Shell.ns.h"
+#include "Shell.class.h"
#include <Binding/Sys.ns.h>
#include <Binding/Process.class.h>
-namespace Shell {
-
-FSNode cwd(0);
+APP(Shell);
+Shell::Shell() : ShellApp("Shell.app", "The Melon command line interpreter"), cwd(FS::cwdNode()) {
+}
-u32int run() {
+int Shell::run() {
struct { //Command list
String name;
- void (*cmd)(Vector<String>&);
+ void (Shell::*cmd)(Vector<String>&);
} commands[] = {
- {"ls", ls},
- {"cd", cd},
- {"pwd", pwd},
- {"rm", rm},
- {"mkdir", mkdir},
- {"cat", cat},
- {"wf", wf},
- {"run", run},
+ {"ls", &Shell::ls},
+ {"cd", &Shell::cd},
+ {"pwd", &Shell::pwd},
+ {"rm", &Shell::rm},
+ {"mkdir", &Shell::mkdir},
+ {"cat", &Shell::cat},
+ {"wf", &Shell::wf},
+ {"run", &Shell::run},
{"", 0}
};
@@ -66,7 +66,7 @@ u32int run() {
} else if (cmd[0] == "free") {
outvt << "Free RAM : " << (s64int)Sys::freeRam() << " Kio of " << (s64int)Sys::totalRam() << " Kio\n";
} else if (cmd[0] == "uid") {
- outvt << "User ID : " << (s64int)(Process::get().getUid()) << "\n";
+ outvt << "User ID : " << (s64int)(pr.getUid()) << "\n";
} else if (cmd[0] == "help") {
while (cmd.size() > 1) cmd.pop();
cmd.push("/Applications/Shell/Help.txt");
@@ -80,7 +80,7 @@ u32int run() {
if (commands[i].cmd == 0) {
outvt << "Not implemented yet.\n";
} else {
- commands[i].cmd(cmd);
+ (this->*(commands[i].cmd))(cmd);
}
break;
}
@@ -91,6 +91,4 @@ u32int run() {
}
}
-}
-
diff --git a/Source/Applications/Shell/Shell.class.h b/Source/Applications/Shell/Shell.class.h
new file mode 100644
index 0000000..7c0c324
--- /dev/null
+++ b/Source/Applications/Shell/Shell.class.h
@@ -0,0 +1,28 @@
+#ifndef DEF_SHELL_CLASS_H
+#define DEF_SHELL_CLASS_H
+
+#include <Binding/VirtualTerminal.class.h>
+#include <Binding/FSNode.class.h>
+#include <String.class.h>
+
+#include <App/ShellApp.proto.h>
+
+class Shell : public ShellApp {
+ public:
+ Shell();
+
+ int run();
+
+ FSNode cwd;
+
+ void ls(Vector<String>& args);
+ void cd(Vector<String>& args);
+ void pwd(Vector<String>& args);
+ void rm(Vector<String>& args);
+ void mkdir(Vector<String>& args);
+ void cat(Vector<String>& args);
+ void wf(Vector<String>& args);
+ void run(Vector<String>& args);
+};
+
+#endif
diff --git a/Source/Applications/Shell/Shell.ns.h b/Source/Applications/Shell/Shell.ns.h
deleted file mode 100644
index b2dd587..0000000
--- a/Source/Applications/Shell/Shell.ns.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#include <Binding/VirtualTerminal.class.h>
-#include <Binding/FSNode.class.h>
-#include <String.class.h>
-
-namespace Shell {
- u32int run();
-
- extern FSNode cwd;
-
- extern void ls(Vector<String>& args);
- extern void cd(Vector<String>& args);
- extern void pwd(Vector<String>& args);
- extern void rm(Vector<String>& args);
- extern void mkdir(Vector<String>& args);
- extern void cat(Vector<String>& args);
- extern void wf(Vector<String>& args);
- extern void run(Vector<String>& args);
-}