From 66630e4154b7c1c47d6223fe5a8607cd269446a0 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Fri, 23 Oct 2009 20:43:48 +0200 Subject: Some changes, and implemented rm in userland shell. --- Source/Applications/SampleApps/cxxdemo.cpp | 1 + Source/Applications/Shell/Shell-fs.ns.cpp | 22 ++++++++++++++++++---- Source/Applications/Shell/Shell.ns.cpp | 3 ++- Source/Applications/Shell/Shell.ns.h | 1 + 4 files changed, 22 insertions(+), 5 deletions(-) (limited to 'Source/Applications') diff --git a/Source/Applications/SampleApps/cxxdemo.cpp b/Source/Applications/SampleApps/cxxdemo.cpp index cf297ec..b9439ce 100644 --- a/Source/Applications/SampleApps/cxxdemo.cpp +++ b/Source/Applications/SampleApps/cxxdemo.cpp @@ -4,6 +4,7 @@ #include int main() { + outvt << "Enter some text plz : "; String s = invt.readLine(); outvt << s; Thread t = Thread::get(); diff --git a/Source/Applications/Shell/Shell-fs.ns.cpp b/Source/Applications/Shell/Shell-fs.ns.cpp index 33bc94e..5e6ae4f 100644 --- a/Source/Applications/Shell/Shell-fs.ns.cpp +++ b/Source/Applications/Shell/Shell-fs.ns.cpp @@ -5,7 +5,7 @@ namespace Shell { void ls(Vector& args) { FSNode d = cwd; if (args.size() == 2) { - FSNode n = cwd.findFrom(args[1]); + FSNode n = FS::find(args[1], cwd); d = FSNode(0); if (!n.valid()) outvt << "No such directory : " << args[1] << "\n"; @@ -17,12 +17,17 @@ void ls(Vector& args) { if (d.valid()) outvt << "Contents of directory " << d.path() << " :\n"; for (u32int i = 0; i < d.getLength(); i++) { FSNode n = d.getChild(i); + String perm = "rwxrwxrwx"; + u32int p = n.getPerm(); + for (u32int i = 0; i < 9; i++) { + if (((p >> i) & 1) == 0) perm[9 - i] = "-"; + } if (n.type() == NT_FILE) { - outvt << " - FILE\t" << n.getName(); + outvt << " FILE " << perm << " " << n.getName(); outvt.setCsrCol(30); outvt << (s32int)n.getLength() << " bytes.\n"; } else if (n.type() == NT_DIRECTORY) { - outvt << " - DIR\t" << n.getName() << "/"; + outvt << " DIR " << perm << " " << n.getName() << "/"; outvt.setCsrCol(30); outvt << (s32int)n.getLength() << " items.\n"; } @@ -33,7 +38,7 @@ void cd(Vector& args) { if (args.size() != 2) { outvt << "Invalid argument count.\n"; } else { - FSNode ncwd = cwd.findFrom(args[1]); + FSNode ncwd = FS::find(args[1], cwd); if (!ncwd.valid()) { outvt << "No such directory : " << args[1] << "\n"; } else if (ncwd.type() == NT_DIRECTORY) { @@ -49,4 +54,13 @@ void pwd(Vector& args) { outvt << "Current directory : " << cwd.path() << "\n"; } +void 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"; + } + } +} + } diff --git a/Source/Applications/Shell/Shell.ns.cpp b/Source/Applications/Shell/Shell.ns.cpp index 4afc6b7..1f8acae 100644 --- a/Source/Applications/Shell/Shell.ns.cpp +++ b/Source/Applications/Shell/Shell.ns.cpp @@ -14,10 +14,11 @@ u32int run() { {"ls", ls}, {"cd", cd}, {"pwd", pwd}, + {"rm", rm}, {"", 0} }; - cwd = FSNode::getCwd(); + cwd = FS::cwdNode(); while (1) { outvt << "{" << cwd.getName() << "}: "; String s = invt.readLine(); diff --git a/Source/Applications/Shell/Shell.ns.h b/Source/Applications/Shell/Shell.ns.h index 8d7067a..5cf4509 100644 --- a/Source/Applications/Shell/Shell.ns.h +++ b/Source/Applications/Shell/Shell.ns.h @@ -10,4 +10,5 @@ namespace Shell { extern void ls(Vector& args); extern void cd(Vector& args); extern void pwd(Vector& args); + extern void rm(Vector& args); } -- cgit v1.2.3