From f2ccc0eaa3db7366787e2fa76ae52554e93b71f1 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sat, 26 Dec 2009 12:34:27 +0100 Subject: More work on the same stuff, all shell aplets are now external bins --- Source/Applications/Shell/Applets/mkdir.cpp | 17 ++++++++++++ Source/Applications/Shell/Applets/rm.cpp | 17 ++++++++++++ Source/Applications/Shell/Makefile | 5 ++-- Source/Applications/Shell/Shell-fs.class.cpp | 41 ---------------------------- Source/Applications/Shell/Shell.class.cpp | 40 ++++----------------------- Source/Applications/Shell/Shell.class.h | 4 --- 6 files changed, 42 insertions(+), 82 deletions(-) create mode 100644 Source/Applications/Shell/Applets/mkdir.cpp create mode 100644 Source/Applications/Shell/Applets/rm.cpp delete mode 100644 Source/Applications/Shell/Shell-fs.class.cpp (limited to 'Source') 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 +#include + +class mkdir : public ShellApp { + public: + mkdir() : ShellApp("mkdir", "Create a/some directory/ies") {} + int run() { + if (args.size() == 0) outvt << "Usage: mkdir [ ...]\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 +#include + +class rm : public ShellApp { + public: + rm() : ShellApp("rm", "Remove a/some file(s)/directorie(s)") {} + int run() { + if (args.size() == 0) outvt << "Usage : rm [ ...]\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 -#include - -void Shell::rm(Vector& 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& 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& 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 .\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&); - } 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& 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& args); - - void rm(Vector& args); - void mkdir(Vector& args); - void wf(Vector& args); }; #endif -- cgit v1.2.3