From 3d5aca66b9712758aecb2e80bc5b2fb3df6256a4 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Wed, 16 Dec 2009 18:22:58 +0100 Subject: New model, object-oriented, for applications --- Source/Applications/Shell/Shell.class.cpp | 94 +++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Source/Applications/Shell/Shell.class.cpp (limited to 'Source/Applications/Shell/Shell.class.cpp') diff --git a/Source/Applications/Shell/Shell.class.cpp b/Source/Applications/Shell/Shell.class.cpp new file mode 100644 index 0000000..42743e7 --- /dev/null +++ b/Source/Applications/Shell/Shell.class.cpp @@ -0,0 +1,94 @@ +#include "Shell.class.h" +#include +#include + +APP(Shell); + +Shell::Shell() : ShellApp(), cwd(FS::cwdNode()) { +} + +int Shell::run() { + struct { //Command list + String name; + void (Shell::*cmd)(Vector&); + } commands[] = { + {"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} + }; + + cwd = FS::cwdNode(); + while (1) { + outvt << "{" << cwd.getName() << "}: "; + String s = invt.readLine(); + if (s.empty()) continue; + while (s[0] == WChar(" ") or s[0] == WChar("\t")) { + s = s.substr(1, s.size() - 1); + } + if (s.empty()) continue; + if (s[0] == WChar("#")) continue; + + //Parse string + Vector cmd; + cmd.push(String()); + bool inQuote = false; + for (u32int i = 0; i < s.size(); i++) { + if (s[i] == WChar("'")) { + inQuote = !inQuote; + } else if (s[i] == WChar("\\")) { + i++; + cmd.back() += s[i]; + } else if (s[i] == WChar(" ") and !inQuote) { + cmd.push(String()); + } else { + cmd.back() += s[i]; + } + } + + //Run command + if (cmd[0] == "exit") { + if (cmd.size() == 1) return 0; + return cmd[1].toInt(); + } else if (cmd[0] == "halt") { + Sys::halt(); + outvt << "Something went wrong.\n"; + } else if (cmd[0] == "reboot") { + Sys::reboot(); + outvt << "Something went wrong.\n"; + } else if (cmd[0] == "uptime") { + outvt << "Uptime : " << (s64int)Sys::uptime() << "s\n"; + } 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"; + } else if (cmd[0] == "help") { + while (cmd.size() > 1) cmd.pop(); + cmd.push("/Applications/Shell/Help.txt"); + cat(cmd); + } 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 { + (this->*(commands[i].cmd))(cmd); + } + break; + } + i++; + } + if (!found) outvt << "Unknown command : " << cmd[0] << "\n"; + } + } +} + + -- cgit v1.2.3 From 4f9078c0f06e0cf0cb7bb164fc72fb9918c68e6a Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Thu, 17 Dec 2009 11:18:19 +0100 Subject: Added some option handling featurs to the default ShellApp class --- Source/Applications/Shell/Shell.class.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Applications/Shell/Shell.class.cpp') diff --git a/Source/Applications/Shell/Shell.class.cpp b/Source/Applications/Shell/Shell.class.cpp index 42743e7..4e0f18b 100644 --- a/Source/Applications/Shell/Shell.class.cpp +++ b/Source/Applications/Shell/Shell.class.cpp @@ -4,7 +4,7 @@ APP(Shell); -Shell::Shell() : ShellApp(), cwd(FS::cwdNode()) { +Shell::Shell() : ShellApp("Shell.app", "The Melon command line interpreter"), cwd(FS::cwdNode()) { } int Shell::run() { -- cgit v1.2.3 From 66f21576d9f9dee507995c520463c5fa94b66a49 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Fri, 18 Dec 2009 15:42:27 +0100 Subject: Nothing, really --- Source/Applications/Shell/Shell.class.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Applications/Shell/Shell.class.cpp') diff --git a/Source/Applications/Shell/Shell.class.cpp b/Source/Applications/Shell/Shell.class.cpp index 4e0f18b..3d406c8 100644 --- a/Source/Applications/Shell/Shell.class.cpp +++ b/Source/Applications/Shell/Shell.class.cpp @@ -66,7 +66,7 @@ int Shell::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"); -- cgit v1.2.3