summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Source/Kernel/Core/kmain.wtf.cpp20
-rw-r--r--Source/Kernel/Library/String.class.cpp8
-rw-r--r--Source/Kernel/Library/WChar.class.cpp8
-rw-r--r--Source/Kernel/Library/WChar.class.h18
-rwxr-xr-xSource/Kernel/Melon.kebin149241 -> 153566 bytes
-rw-r--r--Source/Kernel/VFS/File.class.h3
6 files changed, 32 insertions, 25 deletions
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp
index 6dc37ee..89932e3 100644
--- a/Source/Kernel/Core/kmain.wtf.cpp
+++ b/Source/Kernel/Core/kmain.wtf.cpp
@@ -23,6 +23,7 @@
#include <VFS/FileNode.class.h>
#include <VFS/VFS.ns.h>
#include <VFS/DirectoryNode.class.h>
+#include <VFS/File.class.h>
#include <Ressources/logo.cd>
#include <Ressources/keymap-fr.wtf.c>
@@ -81,7 +82,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
IDT::init(); OK(kvt);
PROCESSING(kvt, "Initializing paging...");
- u32int totalRam = ((mbd->mem_upper + 1024) * 1024);
+ u32int totalRam = ((mbd->mem_upper + mbd->mem_lower) * 1024);
PhysMem::initPaging(totalRam); OK(kvt);
INFO(kvt); *kvt << "Total ram : " << (s32int)(totalRam / 1024) << "k (" << (s32int)(totalRam / (1024 * 1024)) << "M).\n";
@@ -177,18 +178,15 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
} else if (tokens[0] == "cat") {
if (tokens.size() == 1) *kvt << "Meow.\n";
for (u32int i = 1; i < tokens.size(); i++) {
- FSNode* n = VFS::find(tokens[i], cwd);
- if (n == NULL) {
- *kvt << "No such file : " << tokens[i] << "\n";
- } else if (n->type() != NT_FILE) {
- *kvt << "Not a file : " << tokens[i] << "\n";
- } else {
- FileNode* f = (FileNode*) n;
- u8int *buff = (u8int*)Mem::kalloc(f->getLength() + 1);
- f->read(0, f->getLength(), buff);
- buff[f->getLength()] = 0;
+ File f(tokens[i], FM_READ, cwd);
+ if (f.valid()) {
+ u8int *buff = (u8int*)Mem::kalloc(f.length() + 1);
+ f.read(f.length(), buff);
+ buff[f.length()] = 0;
*kvt << String((const char*) buff);
Mem::kfree(buff);
+ } else {
+ *kvt << "Error reading from file " << tokens[i] << "\n";
}
}
} else if (tokens[0] == "pwd") {
diff --git a/Source/Kernel/Library/String.class.cpp b/Source/Kernel/Library/String.class.cpp
index 5ee216c..6380b25 100644
--- a/Source/Kernel/Library/String.class.cpp
+++ b/Source/Kernel/Library/String.class.cpp
@@ -55,7 +55,7 @@ String::String() {
}
String::String(const char* string) {
- m_length = WChar::utf8len(string);
+ m_length = WChar::utfLen(string);
if (m_length == 0) {
m_string = 0;
return;
@@ -101,7 +101,7 @@ void String::operator= (const String &other) {
}
void String::operator= (const char* string) {
- m_length = WChar::utf8len(string);
+ m_length = WChar::utfLen(string);
if (m_string != 0) delete [] m_string;
if (m_length == 0) {
m_string = 0;
@@ -125,7 +125,7 @@ bool String::operator== (const String &other) const {
}
bool String::operator== (const char* string) const {
- if (m_length != WChar::utf8len(string)) return false;
+ if (m_length != WChar::utfLen(string)) return false;
int i = 0, l = strlen(string), c = 0;
WChar tmp;
while (i < l) {
@@ -152,7 +152,7 @@ String& String::operator+= (const String &other) {
}
String& String::operator+= (const char* other) {
- WChar* newdata = new WChar[m_length + WChar::utf8len(other) + 1];
+ WChar* newdata = new WChar[m_length + WChar::utfLen(other) + 1];
for (u32int i = 0; i < m_length; i++) {
newdata[i] = m_string[i];
}
diff --git a/Source/Kernel/Library/WChar.class.cpp b/Source/Kernel/Library/WChar.class.cpp
index bb1269d..d7f01de 100644
--- a/Source/Kernel/Library/WChar.class.cpp
+++ b/Source/Kernel/Library/WChar.class.cpp
@@ -19,11 +19,11 @@ WChar::WChar(char c) {
affectAscii(c);
}
-WChar::WChar(const char* c) {
+WChar::WChar(const char* c, u8int encoding) { //TODO : take encoding into account
affectUtf8(c);
}
-u32int WChar::utf8len(const char* c) {
+u32int WChar::utfLen(const char* c, u8int encoding) {
int i = 0, l = CMem::strlen(c), co = 0;
while (i < l) {
if ((c[i] & 0x80) == 0) i += 1;
@@ -42,10 +42,6 @@ void WChar::affectAscii(char c) {
}
u32int WChar::affectUtf8(const char* c) { //Returns the number of bytes for the character
- /*if ((c[0] & 0xB0) == 0x80) { //11000000b == 10000000b, means we are IN a sequence
- value = 0;
- return 1;
- }*/
if ((c[0] & 0x80) == 0) {
value = c[0]; //0x80 = 10000000b
return 1;
diff --git a/Source/Kernel/Library/WChar.class.h b/Source/Kernel/Library/WChar.class.h
index 9ddccd1..fc00577 100644
--- a/Source/Kernel/Library/WChar.class.h
+++ b/Source/Kernel/Library/WChar.class.h
@@ -3,20 +3,32 @@
#include <Core/common.wtf.h>
+enum {
+ UE_UTF8,
+ UE_UTF16,
+ UE_UTF32,
+};
+
+union uchar_repr_t {
+ char c[4];
+ u32int i;
+};
+
struct WChar {
u32int value;
- static WChar CP437[];
+ static WChar CP437[]; //Codepage 437, used for conversion from/to ascii
WChar(); //Creates a null character
WChar(char c); //From ascii character
- WChar(const char* c); //From utf8 string
+ WChar(const char* c, u8int encoding = UE_UTF8); //From utf8 string
- static u32int utf8len(const char* c); //Returns count of utf8 characters in string
+ static u32int utfLen(const char* c, u8int encoding = UE_UTF8); //Returns count of utf8 characters in string
void affectAscii(char c);
u32int affectUtf8(const char* c);
void affectUtf16(const char* c);
void affectUtf32(const char* c);
+
u8int toAscii();
inline WChar operator+ (u32int other) {
diff --git a/Source/Kernel/Melon.ke b/Source/Kernel/Melon.ke
index dbba5db..ca3160e 100755
--- a/Source/Kernel/Melon.ke
+++ b/Source/Kernel/Melon.ke
Binary files differ
diff --git a/Source/Kernel/VFS/File.class.h b/Source/Kernel/VFS/File.class.h
index dace2cf..955db85 100644
--- a/Source/Kernel/VFS/File.class.h
+++ b/Source/Kernel/VFS/File.class.h
@@ -33,7 +33,8 @@ class File {
u32int read(u32int max_length, u8int *data);
bool write(u32int length, u8int *data);
bool seek(u64int count, u8int mode);
- u64int getPosition() { return m_position; }
+ u64int position() { return m_position; }
+ u64int length() { return m_file->getLength(); }
void close(bool unregisterFD = true); //unregisterFD = whether or not we must unregister the file descriptor from process
bool valid() { return m_valid; }