summaryrefslogtreecommitdiff
path: root/Source/Applications
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-24 18:24:46 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-24 18:24:46 +0200
commitb639b99b3e8f4cf77560d8d473b13d992ac8eb10 (patch)
tree63ebeec75f4ab71d73d743afca04a98636dee165 /Source/Applications
parentf62cfdc8ff6297616d68f6b195db7abc82ab457b (diff)
downloadMelon-b639b99b3e8f4cf77560d8d473b13d992ac8eb10.tar.gz
Melon-b639b99b3e8f4cf77560d8d473b13d992ac8eb10.zip
More work on userland syscalls : Files are implemented.
TextFile now is a common (= kernel and userland) library.
Diffstat (limited to 'Source/Applications')
-rw-r--r--Source/Applications/SampleApps/Makefile12
-rw-r--r--Source/Applications/SampleApps/cxxdemo.cpp5
-rw-r--r--Source/Applications/Shell/Help.txt2
-rw-r--r--Source/Applications/Shell/Makefile6
-rw-r--r--Source/Applications/Shell/Shell-fs.ns.cpp35
-rw-r--r--Source/Applications/Shell/Shell.ns.cpp10
-rw-r--r--Source/Applications/Shell/Shell.ns.h2
-rw-r--r--Source/Applications/Shell/main.cpp2
8 files changed, 60 insertions, 14 deletions
diff --git a/Source/Applications/SampleApps/Makefile b/Source/Applications/SampleApps/Makefile
index a632f87..05f79b1 100644
--- a/Source/Applications/SampleApps/Makefile
+++ b/Source/Applications/SampleApps/Makefile
@@ -1,13 +1,13 @@
.PHONY: clean, mrproper
ASM = nasm
-ASMFLAGS = -f elf
+ASMFLAGS = -f bin
CXX = g++
-CXXFLAGS = -nostartfiles -nostdlib -fno-exceptions -fno-rtti -I ../../Library/Common -I ../../Library/Interface -I ../../Library/Userland -D THIS_IS_MELON_USERLAND
+CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I ../../Library/Common -I ../../Library/Interface -I ../../Library/Userland -D THIS_IS_MELON_USERLAND
LD = ld
-LDFLAGS = -T ../../Library/Link.ld
+LDFLAGS = -T ../../Library/Link.ld -L ../../Library
Applications = asmdemo cxxdemo
@@ -20,13 +20,11 @@ rebuild: mrproper all
echo "* Compiling $<..."
$(CXX) $(CXXFLAGS) -c $< -o $@.o
echo "* Linking $@.o..."
- $(LD) $(LDFLAGS) ../../Library/Melon.o $@.o -o $@
+ $(LD) $(LDFLAGS) $@.o -o $@
%: %.asm
echo "* Compiling $<..."
- $(ASM) $(ASMFLAGS) -o $@.o $<
- echo "* Linking $@.o..."
- $(LD) $(LDFLAGS) $@.o -o $@
+ $(ASM) $(ASMFLAGS) -o $@ $<
clean:
echo "* Removing object files..."
diff --git a/Source/Applications/SampleApps/cxxdemo.cpp b/Source/Applications/SampleApps/cxxdemo.cpp
index b9439ce..3d452e7 100644
--- a/Source/Applications/SampleApps/cxxdemo.cpp
+++ b/Source/Applications/SampleApps/cxxdemo.cpp
@@ -1,9 +1,10 @@
#include <Syscall/Syscall.wtf.h>
-#include <WChar.class.h>
+#include <String.class.h>
#include <Binding/VirtualTerminal.class.h>
#include <Binding/Thread.class.h>
+#include <Binding/File.class.h>
-int main() {
+int main(const Vector<String>& args) {
outvt << "Enter some text plz : ";
String s = invt.readLine();
outvt << s;
diff --git a/Source/Applications/Shell/Help.txt b/Source/Applications/Shell/Help.txt
index c1209cf..0b42361 100644
--- a/Source/Applications/Shell/Help.txt
+++ b/Source/Applications/Shell/Help.txt
@@ -4,7 +4,7 @@
- help shows this
- reboot reboots your computer root
- halt shuts down your computer root
- - loadkeys loads a new keymap root
+ - loadkeys loads a keymap root
- free shows free amount of RAM
- uptime shows computer's uptime
- run runs a binary file
diff --git a/Source/Applications/Shell/Makefile b/Source/Applications/Shell/Makefile
index 0eeb620..bf81af6 100644
--- a/Source/Applications/Shell/Makefile
+++ b/Source/Applications/Shell/Makefile
@@ -1,10 +1,10 @@
.PHONY: clean, mrproper
CXX = g++
-CXXFLAGS = -nostartfiles -nostdlib -fno-exceptions -fno-rtti -I ../../Library/Common -I ../../Library/Interface -I ../../Library/Userland -D THIS_IS_MELON_USERLAND
+CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I ../../Library/Common -I ../../Library/Interface -I ../../Library/Userland -D THIS_IS_MELON_USERLAND
LD = ld
-LDFLAGS = -T ../../Library/Link.ld
+LDFLAGS = -T ../../Library/Link.ld -L ../../Library
Objects = main.o \
Shell.ns.o \
@@ -18,7 +18,7 @@ rebuild: mrproper all
$(OutFile): $(Objects)
echo "* Linking $@..."
- $(LD) $(LDFLAGS) ../../Library/Melon.o $^ -o $@
+ $(LD) $(LDFLAGS) $^ -o $@
%.o: %.cpp
echo "* Compiling $<..."
diff --git a/Source/Applications/Shell/Shell-fs.ns.cpp b/Source/Applications/Shell/Shell-fs.ns.cpp
index b7e585a..1d52836 100644
--- a/Source/Applications/Shell/Shell-fs.ns.cpp
+++ b/Source/Applications/Shell/Shell-fs.ns.cpp
@@ -1,4 +1,5 @@
#include "Shell.ns.h"
+#include <TextFile.class.h>
namespace Shell {
@@ -77,4 +78,38 @@ void mkdir(Vector<String>& args) {
}
}
+void cat(Vector<String>& args) {
+ if (args.size() == 1) outvt << "Meow.\n";
+ for (u32int i = 1; i < args.size(); i++) {
+ TextFile f(args[i], FM_READ, cwd);
+ if (f.valid() && f.validOpened()) {
+ while (!f.eof()) {
+ outvt << f.readLine() << "\n";
+ }
+ f.close();
+ } else {
+ outvt << "Error while reading from file " << args[i] << "\n";
+ }
+ }
+}
+
+void 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.ns.cpp b/Source/Applications/Shell/Shell.ns.cpp
index fe8c5f9..7213094 100644
--- a/Source/Applications/Shell/Shell.ns.cpp
+++ b/Source/Applications/Shell/Shell.ns.cpp
@@ -16,6 +16,8 @@ u32int run() {
{"pwd", pwd},
{"rm", rm},
{"mkdir", mkdir},
+ {"cat", cat},
+ {"wf", wf},
{"", 0}
};
@@ -56,6 +58,14 @@ u32int run() {
} 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] == "help") {
+ while (cmd.size() > 1) cmd.pop();
+ cmd.push("/Applications/Shell/Help.txt");
+ cat(cmd);
} else {
u32int i = 0;
bool found = false;
diff --git a/Source/Applications/Shell/Shell.ns.h b/Source/Applications/Shell/Shell.ns.h
index 56fdb46..a22c18d 100644
--- a/Source/Applications/Shell/Shell.ns.h
+++ b/Source/Applications/Shell/Shell.ns.h
@@ -12,4 +12,6 @@ namespace Shell {
extern void pwd(Vector<String>& args);
extern void rm(Vector<String>& args);
extern void mkdir(Vector<String>& args);
+ extern void cat(Vector<String>& args);
+ extern void wf(Vector<String>& args);
}
diff --git a/Source/Applications/Shell/main.cpp b/Source/Applications/Shell/main.cpp
index 70da17b..66c4269 100644
--- a/Source/Applications/Shell/main.cpp
+++ b/Source/Applications/Shell/main.cpp
@@ -1,5 +1,5 @@
#include "Shell.ns.h"
-int main() {
+int main(const Vector<String>& args) {
return Shell::run();
}