diff options
author | Alexis211 <alexis211@gmail.com> | 2009-10-24 18:24:46 +0200 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-10-24 18:24:46 +0200 |
commit | b639b99b3e8f4cf77560d8d473b13d992ac8eb10 (patch) | |
tree | 63ebeec75f4ab71d73d743afca04a98636dee165 /Source/Library/Common | |
parent | f62cfdc8ff6297616d68f6b195db7abc82ab457b (diff) | |
download | Melon-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/Library/Common')
-rw-r--r-- | Source/Library/Common/TextFile.class.cpp | 30 | ||||
-rw-r--r-- | Source/Library/Common/TextFile.class.h | 31 |
2 files changed, 61 insertions, 0 deletions
diff --git a/Source/Library/Common/TextFile.class.cpp b/Source/Library/Common/TextFile.class.cpp new file mode 100644 index 0000000..040e2d7 --- /dev/null +++ b/Source/Library/Common/TextFile.class.cpp @@ -0,0 +1,30 @@ +#include "TextFile.class.h" + +bool TextFile::write(String str, bool addnl) { + ByteArray a(str, m_encoding); + if (addnl) a += (u8int)'\n'; + return File::write(a); +} + +String TextFile::readLine(char separator) { + const u32int bufflen = 512; + String ret; + ByteArray temp; + while (1) { + temp.resize(bufflen); + u32int r = read(temp); + u32int l = r; + for (u32int i = 0; i < r; i++) { + if (temp[i] == separator) { + l = i; + temp.resize(i); + break; + } + } + ret += temp.toString(m_encoding); + if (l != r or r != bufflen) { + if (l != r) seek((r - l) - 1, SM_BACKWARD); + return ret; + } + } +} diff --git a/Source/Library/Common/TextFile.class.h b/Source/Library/Common/TextFile.class.h new file mode 100644 index 0000000..3749b6a --- /dev/null +++ b/Source/Library/Common/TextFile.class.h @@ -0,0 +1,31 @@ +#ifndef DEF_TEXTFILE_CLASS_H +#define DEF_TEXTFILE_CLASS_H + +#ifdef THIS_IS_MELON_KERNEL +#include <VFS/File.class.h> +#else +#include <Binding/File.class.h> +#endif + +class TextFile : public File { + private: + u8int m_encoding; + + public: +#ifdef THIS_IS_MELON_KERNEL + TextFile(u8int encoding = UE_UTF8) : File() { m_encoding = encoding; } + TextFile(String filename, u8int mode = FM_READ, FSNode* start = 0, u8int encoding = UE_UTF8) + : File(filename, mode, start) { m_encoding = encoding; } +#else + TextFile(u32int id, u8int encoding = UE_UTF8) : File(id) { m_encoding = encoding; } + TextFile(String filename, u8int mode = FM_READ, FSNode start = FSNode(0), u8int encoding = UE_UTF8) + : File(filename, mode, start) { m_encoding = encoding; } +#endif + ~TextFile() {} + + void setEncoding(u8int encoding = UE_UTF8) { m_encoding = encoding; } + bool write(String str, bool addnl = false); // Addnl = wether or not to add \n at end + String readLine(char separator = '\n'); +}; + +#endif |