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 --- CopyToFDD.sh | 8 +++--- CopyToHDD.sh | 2 +- Grub-menu-fdd.cfg | 4 +-- Makefile | 2 ++ 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 --- 10 files changed, 51 insertions(+), 89 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 diff --git a/CopyToFDD.sh b/CopyToFDD.sh index 9818735..d30e324 100755 --- a/CopyToFDD.sh +++ b/CopyToFDD.sh @@ -17,10 +17,6 @@ mkdir Mount/{System,Volumes,Sandbox} mkdir Mount/System/{Applications,Logs,Configuration} mkdir Mount/Volumes/{HDD,InitRFS} -# Copy kernel and ramfs -cp Source/Kernel/Melon.ke Mount/System -cp Init.rfs Mount/System - # Copy system files cp Source/Kernel/Ressources/Configuration/* Mount/System/Configuration cp Source/Applications/PaperWork/FloppyWelcome.txt Mount/System/Configuration/Welcome @@ -28,6 +24,10 @@ cp Source/Applications/PaperWork/FloppyWelcome.txt Mount/System/Configuration/We # Copy system apps cp Source/Applications/PaperWork/PaperWork Mount/System/Applications/PaperWork.app +# Copy kernel and ramfs +cp Source/Kernel/Melon.ke Mount/System +cp Init.rfs Mount/System + # Create mount configuration file echo "/Sandbox:ramfs:0" > Mount/System/Configuration/Mount echo "/Volumes/HDD:block.ata:0:1" >> Mount/System/Configuration/Mount diff --git a/CopyToHDD.sh b/CopyToHDD.sh index 03ad494..8c56e6b 100755 --- a/CopyToHDD.sh +++ b/CopyToHDD.sh @@ -24,7 +24,7 @@ cp Source/Kernel/Ressources/Configuration/* Mount/System/Configuration cp Source/Kernel/Ressources/Keymaps/*.mkm Mount/System/Keymaps cp Source/Applications/PaperWork/PaperWork Mount/System/Applications/PaperWork.app cp Source/Applications/Shell/Shell Mount/Applications/Shell/Shell.app -cp Source/Applications/Shell/Applets/{cat,free,halt,reboot,uptime,ls,pwd} Mount/Applications/Shell/Applets +cp Source/Applications/Shell/Applets/{cat,free,halt,reboot,uptime,ls,pwd,rm,mkdir} Mount/Applications/Shell/Applets cp Source/Applications/Shell/Help.txt Mount/Applications/Shell # Create mount configuration file diff --git a/Grub-menu-fdd.cfg b/Grub-menu-fdd.cfg index e759628..7ecd802 100644 --- a/Grub-menu-fdd.cfg +++ b/Grub-menu-fdd.cfg @@ -17,11 +17,11 @@ module /System/Init.rfs title Melon without init, boot on initramfs root (fd0) -kernel /System/Melon.ke init:/Shell.app root:ramfs:0 +kernel /System/Melon.ke init: root:ramfs:0 module /System/Init.rfs title Game of life simulator root (fd0) -kernel /System/Melon.ke init:/Applications/Demos/GOL.app root:block.floppy:0:0 +kernel /System/Melon.ke init:/Sandbox/GOL.app root:block.floppy:0:0 module /System/Init.rfs diff --git a/Makefile b/Makefile index b59b87b..7a20bdb 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,8 @@ RamFSFiles = :/System :/System/Configuration :/System/Keymaps :/Applets \ Source/Applications/Shell/Applets/uptime:/Applets/uptime \ Source/Applications/Shell/Applets/free:/Applets/free \ Source/Applications/Shell/Applets/ls:/Applets/ls \ + Source/Applications/Shell/Applets/rm:/Applets/rm \ + Source/Applications/Shell/Applets/mkdir:/Applets/mkdir \ Source/Applications/Shell/Applets/pwd:/Applets/pwd \ Source/Applications/Demos/GOL:/GOL.app \ Source/Kernel/Ressources/Graphics/logo.text.cxd:/Melon-logo 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