summaryrefslogtreecommitdiff
path: root/Source/Applications
diff options
context:
space:
mode:
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)31
-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
9 files changed, 96 insertions, 72 deletions
diff --git a/Source/Applications/Demos/GOL.cpp b/Source/Applications/Demos/GOL.cpp
index e6da3a6..675c159 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("GOL.app", "Melon's Game of Life simulator \\o/") {}
+ 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..36cfd27 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("CPPDemo.app", "A demo application using the C++ Melon framework") {}
+ 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..4f9cb0e 100644
--- a/Source/Applications/PaperWork/main.cpp
+++ b/Source/Applications/PaperWork/PaperWork.cpp
@@ -1,17 +1,22 @@
-#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) {
- String act = "init";
- if (args.size() == 2) {
- if (args[1] == "login") {
- act = "login";
- } else if (args[1] == "init") {
- act = "init";
- }
+class PaperWork : public ShellApp {
+ public:
+ PaperWork() : ShellApp("PaperWork.app", "Melon's init/login manager") {
+ addFlag("s", "shell", "Define the default shell to launch", FT_STR, DEFAULT_SHELL);
+ addFlag("l", "login", "Act as a login manager");
+ addFlag("i", "init", "Act as a init manager", FT_BOOL, "on");
}
+ int run();
+};
+
+APP(PaperWork);
+
+int PaperWork::run() {
+ String act = "init";
+ if (bFlag("login")) act = "login";
if (act == "init") {
while (1) {
@@ -19,7 +24,7 @@ int main(Vector<String> args) {
if (p.valid()) {
p.setInVT(invt);
p.setOutVT(outvt);
- p.pushArg("login");
+ p.pushArg("--login");
p.start();
p.wait();
} else {
@@ -38,9 +43,9 @@ int main(Vector<String> args) {
outvt << "Authentication failed.\n\n";
continue;
}
- outvt << "What shell to run [" << DEFAULT_SHELL << "]? ";
+ outvt << "What shell to run [" << sFlag("shell") << "]? ";
String sh = invt.readLine();
- if (sh == "") sh = DEFAULT_SHELL;
+ if (sh == "") sh = sFlag("shell");
Process p = Process::run(sh);
if (p.valid()) {
p.setInVT(invt);
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);
-}