summaryrefslogtreecommitdiff
path: root/Source/Applications
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-12-16 18:22:58 +0100
committerAlexis211 <alexis211@gmail.com>2009-12-16 18:22:58 +0100
commit3d5aca66b9712758aecb2e80bc5b2fb3df6256a4 (patch)
tree817e945218dbca029244315f36b960dd288b3cff /Source/Applications
parent5f87c447bdcb82beacbfb930942fe9995dcdb60f (diff)
downloadMelon-3d5aca66b9712758aecb2e80bc5b2fb3df6256a4.tar.gz
Melon-3d5aca66b9712758aecb2e80bc5b2fb3df6256a4.zip
New model, object-oriented, for applications
Diffstat (limited to 'Source/Applications')
-rw-r--r--Source/Applications/Demos/GOL.cpp14
-rw-r--r--Source/Applications/Demos/cxxdemo.cpp14
-rw-r--r--Source/Applications/PaperWork/Makefile2
-rw-r--r--Source/Applications/PaperWork/PaperWork.cpp (renamed from Source/Applications/PaperWork/main.cpp)13
-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)32
-rw-r--r--Source/Applications/Shell/Shell.class.h28
-rw-r--r--Source/Applications/Shell/Shell.ns.h18
9 files changed, 87 insertions, 61 deletions
diff --git a/Source/Applications/Demos/GOL.cpp b/Source/Applications/Demos/GOL.cpp
index e6da3a6..cd6e719 100644
--- a/Source/Applications/Demos/GOL.cpp
+++ b/Source/Applications/Demos/GOL.cpp
@@ -1,10 +1,18 @@
-#include <Binding/VirtualTerminal.class.h>
#include <Binding/Thread.class.h>
-#include <String.class.h>
#include <ByteArray.class.h>
#include <Rand.ns.h>
-int main(Vector<String> args) {
+#include <App/ShellApp.proto.h>
+
+class GOL : public ShellApp {
+ public:
+ GOL() : ShellApp() {}
+ int run();
+};
+
+APP(GOL);
+
+int GOL::run() {
if (!outvt.isBoxed()) {
outvt << "Error : cannot display GOL on a non-boxed terminal.\n";
return 1;
diff --git a/Source/Applications/Demos/cxxdemo.cpp b/Source/Applications/Demos/cxxdemo.cpp
index 3d452e7..372e69f 100644
--- a/Source/Applications/Demos/cxxdemo.cpp
+++ b/Source/Applications/Demos/cxxdemo.cpp
@@ -1,10 +1,18 @@
#include <Syscall/Syscall.wtf.h>
-#include <String.class.h>
-#include <Binding/VirtualTerminal.class.h>
#include <Binding/Thread.class.h>
#include <Binding/File.class.h>
-int main(const Vector<String>& args) {
+#include <App/ShellApp.proto.h>
+
+class CPPDemo : public ShellApp {
+ public:
+ CPPDemo() : ShellApp() {}
+ int run();
+};
+
+APP(CPPDemo);
+
+int CPPDemo::run() {
outvt << "Enter some text plz : ";
String s = invt.readLine();
outvt << s;
diff --git a/Source/Applications/PaperWork/Makefile b/Source/Applications/PaperWork/Makefile
index fe8d564..d3203cf 100644
--- a/Source/Applications/PaperWork/Makefile
+++ b/Source/Applications/PaperWork/Makefile
@@ -6,7 +6,7 @@ CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I .
LD = ld
LDFLAGS = -T ../../Library/Link.ld -L ../../Library
-Objects = main.o
+Objects = PaperWork.o
OutFile = PaperWork
all: $(OutFile)
diff --git a/Source/Applications/PaperWork/main.cpp b/Source/Applications/PaperWork/PaperWork.cpp
index 2fb40df..0d6a821 100644
--- a/Source/Applications/PaperWork/main.cpp
+++ b/Source/Applications/PaperWork/PaperWork.cpp
@@ -1,9 +1,16 @@
-#include <Binding/Process.class.h>
-#include <String.class.h>
+#include <App/ShellApp.proto.h>
#define DEFAULT_SHELL "/Applications/Shell/Shell.app"
-int main(Vector<String> args) {
+class PaperWork : public ShellApp {
+ public:
+ PaperWork() : ShellApp() {}
+ int run();
+};
+
+APP(PaperWork);
+
+int PaperWork::run() {
String act = "init";
if (args.size() == 2) {
if (args[1] == "login") {
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..42743e7 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(), 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}
};
@@ -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);
-}