summaryrefslogtreecommitdiff
path: root/Source/Library
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-12-20 19:39:46 +0100
committerAlexis211 <alexis211@gmail.com>2009-12-20 19:39:46 +0100
commit1d301e54da75b90172d129594265f2b629f3125a (patch)
tree1eb918a01ef7677c4328ef1d23a2538647448f0b /Source/Library
parent13d720389a01161a327a30918ad7ac9eec4a3d6c (diff)
downloadMelon-1d301e54da75b90172d129594265f2b629f3125a.tar.gz
Melon-1d301e54da75b90172d129594265f2b629f3125a.zip
rot13, demo app for StreamApp, is working :)
Diffstat (limited to 'Source/Library')
-rw-r--r--Source/Library/Common/FileStream.class.cpp11
-rw-r--r--Source/Library/Common/IStream.proto.cpp5
-rw-r--r--Source/Library/Common/OStream.proto.cpp4
-rw-r--r--Source/Library/Userland/App/ShellApp.proto.cpp5
-rw-r--r--Source/Library/Userland/App/StreamApp.proto.cpp5
-rw-r--r--Source/Library/Userland/Binding/VirtualTerminal.class.h1
6 files changed, 21 insertions, 10 deletions
diff --git a/Source/Library/Common/FileStream.class.cpp b/Source/Library/Common/FileStream.class.cpp
index 322e9aa..317a023 100644
--- a/Source/Library/Common/FileStream.class.cpp
+++ b/Source/Library/Common/FileStream.class.cpp
@@ -6,11 +6,13 @@
FileIStream::FileIStream(const String &filename, u8int encoding, FSNode start) : m_start(start) {
m_file = new File(filename, FM_READ, start);
+ m_filenames = 0;
m_encoding = encoding;
}
FileIStream::FileIStream(u8int encoding, FSNode start) : m_start(start) {
m_file = 0;
+ m_filenames = 0;
m_encoding = encoding;
}
@@ -30,10 +32,11 @@ void FileIStream::appendFile(const String &filename) {
}
String FileIStream::read() {
- if (m_file == 0) return "";
- while (m_file->eof() or !m_file->valid()) {
- m_file->close();
- delete m_file;
+ while (m_file == 0 or m_file->eof() or !m_file->valid()) {
+ if (m_file != 0) {
+ m_file->close();
+ delete m_file;
+ }
m_file = 0;
if (m_filenames == 0) {
return "";
diff --git a/Source/Library/Common/IStream.proto.cpp b/Source/Library/Common/IStream.proto.cpp
index 59c623e..6176eac 100644
--- a/Source/Library/Common/IStream.proto.cpp
+++ b/Source/Library/Common/IStream.proto.cpp
@@ -51,7 +51,10 @@ WChar IStream::getChar() {
String IStream::get(WChar delimiter) {
waitLock();
//calculate length of string to read
- if (m_buffer == 0) populate();
+ if (m_buffer == 0) {
+ unlock();
+ if (!populate()) return "";
+ }
int length = 0, ptr = m_ptr;
for (SimpleList<String> *iter = m_buffer; iter != 0;) {
if (iter->v()[ptr] == delimiter) break;
diff --git a/Source/Library/Common/OStream.proto.cpp b/Source/Library/Common/OStream.proto.cpp
index ba876b3..f0667e7 100644
--- a/Source/Library/Common/OStream.proto.cpp
+++ b/Source/Library/Common/OStream.proto.cpp
@@ -11,6 +11,7 @@ OStream::OStream(const OStream& other) {
}
void OStream::put(const String &s) {
+ if (s.empty()) return;
waitLock();
if (m_buffer == NULL or m_last == NULL) {
m_buffer = m_last = new SimpleList<String>(s);
@@ -55,8 +56,9 @@ OStream& OStream::operator<< (ostream_modifiers_e m) {
flush();
} else if (m == ENDL) {
put("\n");
+ flush();
} else if (m == END) {
- put(String(EOF, 1));
+ put(EOF);
flush();
}
return *this;
diff --git a/Source/Library/Userland/App/ShellApp.proto.cpp b/Source/Library/Userland/App/ShellApp.proto.cpp
index 840e985..123eb73 100644
--- a/Source/Library/Userland/App/ShellApp.proto.cpp
+++ b/Source/Library/Userland/App/ShellApp.proto.cpp
@@ -16,7 +16,8 @@ ShellApp::~ShellApp() {
void ShellApp::init() {
//Parse flags
u32int argc = pr.argc();
- for (u32int i = 0; i < argc; i++) {
+ args.clear();
+ for (u32int i = 1; i < argc; i++) {
String arg = pr.argv(i);
if (arg.empty()) continue;
if (arg == "-") {
@@ -89,7 +90,7 @@ void ShellApp::init() {
//Eventually show help screen
if (bFlag("help")) {
outvt << appName << ": " << appDesc << "\n";
- outvt << "Usage: \t" << appName << " <flags> [-] <arguments>\n\n";
+ outvt << "Usage: \t" << pr.argv(0) << " <flags> [-] <arguments>\n\n";
outvt << "Possible flags :\n";
for (u32int i = 0; i < flags.size(); i++) {
outvt << " --" << flags[i].lName << "\t" << (flags[i].sName != 0 ? "-" : "") << String(flags[i].sName) << "\t";
diff --git a/Source/Library/Userland/App/StreamApp.proto.cpp b/Source/Library/Userland/App/StreamApp.proto.cpp
index 97f473e..b1dc7dd 100644
--- a/Source/Library/Userland/App/StreamApp.proto.cpp
+++ b/Source/Library/Userland/App/StreamApp.proto.cpp
@@ -6,6 +6,7 @@ StreamApp::StreamApp(const String& name, const String& desc)
: ShellApp(name, desc) {
addFlag("o", "output", "Set the output to a file instead of the text output", FT_STR, "");
addFlag("e", "encoding", "Set the encoding for files (input and output)", FT_STR, "utf8");
+ addFlag("a", "append", "When writing to a file, append instead of truncating", FT_BOOL, "");
}
StreamApp::~StreamApp() {
@@ -13,7 +14,7 @@ StreamApp::~StreamApp() {
void StreamApp::init() {
ShellApp::init();
-
+
u8int encoding = UE_UTF8;
if (sFlag("encoding") == "utf8") encoding = UE_UTF8;
if (sFlag("encoding") == "utf16be") encoding = UE_UTF16_BE;
@@ -24,7 +25,7 @@ void StreamApp::init() {
if (sFlag("output") == "") {
out = &outvt;
} else {
- out = new FileOStream(sFlag("output"), FM_TRUNCATE, encoding, FS::cwdNode());
+ out = new FileOStream(sFlag("output"), (bFlag("append") ? FM_APPEND : FM_TRUNCATE), encoding, FS::cwdNode());
}
if (args.size() == 0) {
diff --git a/Source/Library/Userland/Binding/VirtualTerminal.class.h b/Source/Library/Userland/Binding/VirtualTerminal.class.h
index 54bdc53..2a38abd 100644
--- a/Source/Library/Userland/Binding/VirtualTerminal.class.h
+++ b/Source/Library/Userland/Binding/VirtualTerminal.class.h
@@ -39,6 +39,7 @@ class VirtualTerminal : public RessourceCaller, public OStream, public IStream {
String ret = String::unserialize(doCall(VTIF_READLINE, 1));
if (ret[ret.size() - 1] == WChar(EOF)) {
ret = ret.substr(0, ret.size() - 1);
+ if (ret.empty()) return "";
m_eof = true;
}
return ret += "\n";