diff options
author | Alexis211 <alexis211@gmail.com> | 2009-12-20 16:30:30 +0100 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-12-20 16:30:30 +0100 |
commit | 13d720389a01161a327a30918ad7ac9eec4a3d6c (patch) | |
tree | e1b6ebb12f00e476284684c8deb4a513c4960e2a /Source/Library/Userland | |
parent | 2d3c5a9c47d99c8f4f5561f9eae16497c1cde63a (diff) | |
download | Melon-13d720389a01161a327a30918ad7ac9eec4a3d6c.tar.gz Melon-13d720389a01161a327a30918ad7ac9eec4a3d6c.zip |
[not tested] Introduced StreamApp.class
Diffstat (limited to 'Source/Library/Userland')
-rw-r--r-- | Source/Library/Userland/App/ShellApp.proto.cpp | 2 | ||||
-rw-r--r-- | Source/Library/Userland/App/ShellApp.proto.h | 2 | ||||
-rw-r--r-- | Source/Library/Userland/App/StreamApp.proto.cpp | 39 | ||||
-rw-r--r-- | Source/Library/Userland/App/StreamApp.proto.h | 27 |
4 files changed, 68 insertions, 2 deletions
diff --git a/Source/Library/Userland/App/ShellApp.proto.cpp b/Source/Library/Userland/App/ShellApp.proto.cpp index 9528ca2..840e985 100644 --- a/Source/Library/Userland/App/ShellApp.proto.cpp +++ b/Source/Library/Userland/App/ShellApp.proto.cpp @@ -1,6 +1,6 @@ #include "ShellApp.proto.h" -ShellApp::ShellApp(String name, String desc) +ShellApp::ShellApp(const String &name, const String &desc) : Application(), invt(VirtualTerminal::getIn()), outvt(VirtualTerminal::getOut()) { appName = name, appDesc = desc; if (!invt.valid()) exit(1); diff --git a/Source/Library/Userland/App/ShellApp.proto.h b/Source/Library/Userland/App/ShellApp.proto.h index 2308fd1..bc57cd0 100644 --- a/Source/Library/Userland/App/ShellApp.proto.h +++ b/Source/Library/Userland/App/ShellApp.proto.h @@ -23,7 +23,7 @@ class ShellApp : public Application { Vector<String> args; Vector<flag_t> flags; String appName, appDesc; - ShellApp(String name, String desc); + ShellApp(const String &name, const String &desc); ~ShellApp(); virtual void init(); diff --git a/Source/Library/Userland/App/StreamApp.proto.cpp b/Source/Library/Userland/App/StreamApp.proto.cpp new file mode 100644 index 0000000..97f473e --- /dev/null +++ b/Source/Library/Userland/App/StreamApp.proto.cpp @@ -0,0 +1,39 @@ +#include "StreamApp.proto.h" + +#include <FileStream.class.h> + +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"); +} + +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; + if (sFlag("encoding") == "utf16le") encoding = UE_UTF16_LE; + if (sFlag("encoding") == "utf32be") encoding = UE_UTF32_BE; + if (sFlag("encoding") == "utf32le") encoding = UE_UTF32_LE; + + if (sFlag("output") == "") { + out = &outvt; + } else { + out = new FileOStream(sFlag("output"), FM_TRUNCATE, encoding, FS::cwdNode()); + } + + if (args.size() == 0) { + in = &invt; + } else { + FileIStream *f = new FileIStream(encoding, FS::cwdNode()); + for (u32int i = 0; i < args.size(); i++) { + f->appendFile(args[i]); + } + in = f; + } +} diff --git a/Source/Library/Userland/App/StreamApp.proto.h b/Source/Library/Userland/App/StreamApp.proto.h new file mode 100644 index 0000000..462b1f3 --- /dev/null +++ b/Source/Library/Userland/App/StreamApp.proto.h @@ -0,0 +1,27 @@ +#ifndef DEF_STREAMAPP_PROTO_H +#define DEF_STREAMAPP_PROTO_H + +#include "ShellApp.proto.h" + +#include <IStream.proto.h> +#include <OStream.proto.h> + +/* + * This class implements basic utilities for apps that simply take some input, process it and output something. + * Examples : cat, grep, ... + */ + +class StreamApp : public ShellApp { + protected: + + IStream *in; + OStream *out; + + public: + StreamApp(const String& name, const String& desc); + ~StreamApp(); + + virtual void init(); +}; + +#endif |