diff options
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 |