diff options
Diffstat (limited to 'Source/Applications/Shell')
-rw-r--r-- | Source/Applications/Shell/Applets/mkdir.cpp | 17 | ||||
-rw-r--r-- | Source/Applications/Shell/Applets/rm.cpp | 17 | ||||
-rw-r--r-- | Source/Applications/Shell/Makefile | 5 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell-fs.class.cpp | 41 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell.class.cpp | 40 | ||||
-rw-r--r-- | Source/Applications/Shell/Shell.class.h | 4 |
6 files changed, 42 insertions, 82 deletions
diff --git a/Source/Applications/Shell/Applets/mkdir.cpp b/Source/Applications/Shell/Applets/mkdir.cpp new file mode 100644 index 0000000..56908d3 --- /dev/null +++ b/Source/Applications/Shell/Applets/mkdir.cpp @@ -0,0 +1,17 @@ +#include <App/ShellApp.proto.h> +#include <Binding/FSNode.class.h> + +class mkdir : public ShellApp { + public: + mkdir() : ShellApp("mkdir", "Create a/some directory/ies") {} + int run() { + if (args.size() == 0) outvt << "Usage: mkdir <name> [<name> ...]\n"; + for (u32int i = 0; i < args.size(); i++) { + if (!FS::mkdir(args[i], FS::cwdNode()).valid()) { + outvt << "Error while creating directory " << args[i] << "\n"; + } + } + } +}; + +APP(mkdir); diff --git a/Source/Applications/Shell/Applets/rm.cpp b/Source/Applications/Shell/Applets/rm.cpp new file mode 100644 index 0000000..4dbb4ed --- /dev/null +++ b/Source/Applications/Shell/Applets/rm.cpp @@ -0,0 +1,17 @@ +#include <App/ShellApp.proto.h> +#include <Binding/FSNode.class.h> + +class rm : public ShellApp { + public: + rm() : ShellApp("rm", "Remove a/some file(s)/directorie(s)") {} + int run() { + if (args.size() == 0) outvt << "Usage : rm <file> [<file> ...]\n"; + for (u32int i = 0; i < args.size(); i++) { + if (!FS::find(args[i], FS::cwdNode()).remove()) { + outvt << "Error while removing file " << args[i] << "\n"; + } + } + } +}; + +APP(rm); diff --git a/Source/Applications/Shell/Makefile b/Source/Applications/Shell/Makefile index dff539c..867939f 100644 --- a/Source/Applications/Shell/Makefile +++ b/Source/Applications/Shell/Makefile @@ -6,12 +6,11 @@ CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I . LD = ld LDFLAGS = -T ../../Library/App.ld -L ../../Library -Objects = Shell.class.o \ - Shell-fs.class.o +Objects = Shell.class.o OutFile = Shell Applets = Applets/cat Applets/halt Applets/reboot Applets/uptime Applets/free Applets/ls \ - Applets/pwd + Applets/pwd Applets/rm Applets/mkdir all: $(OutFile) $(Applets) echo "* Done with $(OutFile)." diff --git a/Source/Applications/Shell/Shell-fs.class.cpp b/Source/Applications/Shell/Shell-fs.class.cpp deleted file mode 100644 index 7607f34..0000000 --- a/Source/Applications/Shell/Shell-fs.class.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "Shell.class.h" -#include <TextFile.class.h> -#include <Binding/Process.class.h> - -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()) { - outvt << "Error while removing file " << args[i] << "\n"; - } - } -} - -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()) { - outvt << "Error while creating directory " << args[i] << "\n"; - } - } -} - -void Shell::wf(Vector<String>& args) { - if (args.size() == 1) { - outvt << "No file to write !\n"; - } else { - TextFile f(args[1], FM_TRUNCATE, cwd); - if (f.valid() && f.validOpened()) { - outvt << "Enter contents for file " << args[1] << " and end your entry with <CR>.<CR>\n"; - String t = invt.readLine(); - while (t != ".") { - f.write(t, true); - t = invt.readLine(); - } - f.close(); - } else { - outvt << "Error opening file.\n"; - } - } -} - diff --git a/Source/Applications/Shell/Shell.class.cpp b/Source/Applications/Shell/Shell.class.cpp index 971b913..bc9ba93 100644 --- a/Source/Applications/Shell/Shell.class.cpp +++ b/Source/Applications/Shell/Shell.class.cpp @@ -19,16 +19,6 @@ void Shell::setupVars() { } int Shell::run() { - struct { //Command list - String name; - void (Shell::*cmd)(Vector<String>&); - } commands[] = { - {"rm", &Shell::rm}, - {"mkdir", &Shell::mkdir}, - {"wf", &Shell::wf}, - {"", 0} - }; - String dn = FS::dirname(pr.argv(0)); FSNode shellDir = (dn.empty() ? FS::cwdNode() : FS::find(dn, FS::cwdNode())); String appletsDir = FS::find("Applets", shellDir).path() + "/"; @@ -111,35 +101,17 @@ int Shell::run() { } } } else { // * * * CALL AN EXTERNAL COMMAND * * * // - 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) { - if (FS::basename(cmd[0]) != cmd[0]) { - if (!appRun(cmd[0], cmd)) - outvt << "No such file : " << cmd[0] << "\n"; - } else { - if (!appRun(appletsDir + cmd[0], cmd)) - outvt << "Unknown command : " << cmd[0] << "\n"; - } + if (FS::basename(cmd[0]) != cmd[0]) { + if (!appRun(cmd[0], cmd)) + outvt << "No such file : " << cmd[0] << "\n"; + } else { + if (!appRun(appletsDir + cmd[0], cmd)) + outvt << "Unknown command : " << cmd[0] << "\n"; } } } } - - bool Shell::appRun(const String& app, Vector<String>& args) { Process p = Process::run(app); if (p.valid()) { diff --git a/Source/Applications/Shell/Shell.class.h b/Source/Applications/Shell/Shell.class.h index 49208fe..9bd6524 100644 --- a/Source/Applications/Shell/Shell.class.h +++ b/Source/Applications/Shell/Shell.class.h @@ -31,10 +31,6 @@ class Shell : public ShellApp { FSNode cwd; bool appRun(const String& name, Vector<String>& args); - - void rm(Vector<String>& args); - void mkdir(Vector<String>& args); - void wf(Vector<String>& args); }; #endif |