From beb4c7aa02cfe80cdfc6793406823c5f32cb0b74 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 2 Apr 2022 19:04:29 +0200 Subject: Reformatted Reader and updated header includes --- FoundationEx/Reader.cpp | 56 +++++++++++++++++++++++++++++-------------------- FoundationEx/Reader.h | 23 +++++++++++--------- 2 files changed, 46 insertions(+), 33 deletions(-) (limited to 'FoundationEx') diff --git a/FoundationEx/Reader.cpp b/FoundationEx/Reader.cpp index 682627d..b39e9bc 100644 --- a/FoundationEx/Reader.cpp +++ b/FoundationEx/Reader.cpp @@ -3,21 +3,22 @@ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors Copyright (c) 1997-2006, Destroyer Studios LLC. - AUTHOR: John DiCamillo + AUTHOR: John DiCamillo - OVERVIEW - ======== - Implementation of the Reader class + OVERVIEW + ======== + Implementation of the Reader class */ #include "Reader.h" -#include + +#include +#include #include -#include + #include "Utils.h" -// +-------------------------------------------------------------------+ Text ConsoleReader::more() @@ -31,25 +32,29 @@ ConsoleReader::more() return Text(p); } + void ConsoleReader::printPrimaryPrompt() { - printf("- "); + std::printf("- "); } + void ConsoleReader::fillInputBuffer() { - fgets(buffer, 980, stdin); + std::fgets(buffer, 980, stdin); p = buffer; - while (isspace(*p)) p++; + while (std::isspace(*p)) p++; } -// +-------------------------------------------------------------------+ -FileReader::FileReader(const char* fname) - : filename(fname), done(0) -{ } +FileReader::FileReader(const char* fname) : + filename(fname), + done(0) +{ +} + Text FileReader::more() @@ -76,15 +81,22 @@ FileReader::more() return result; } -// +-------------------------------------------------------------------+ -BlockReader::BlockReader(const char* block) - : data((char*) block), done(0), length(0) -{ } +BlockReader::BlockReader(const char* block) : + data((char*) block), + done(0), + length(0) +{ +} + + +BlockReader::BlockReader(const char* block, int len) : + data((char*) block), + done(0), + length(len) +{ +} -BlockReader::BlockReader(const char* block, int len) - : data((char*) block), done(0), length(len) -{ } Text BlockReader::more() @@ -105,5 +117,3 @@ BlockReader::more() done = 1; return Text(); } - - diff --git a/FoundationEx/Reader.h b/FoundationEx/Reader.h index e1154d1..ed6aebc 100644 --- a/FoundationEx/Reader.h +++ b/FoundationEx/Reader.h @@ -3,20 +3,19 @@ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors Copyright (c) 1997-2006, Destroyer Studios LLC. - AUTHOR: John DiCamillo + AUTHOR: John DiCamillo - OVERVIEW - ======== - Declaration of the Reader class + OVERVIEW + ======== + Declaration of the Reader class */ -#ifndef READER_H -#define READER_H +#ifndef Reader_h +#define Reader_h #include "Text.h" -// +-------------------------------------------------------------------+ class Reader { @@ -27,10 +26,11 @@ public: virtual Text more() = 0; }; + class ConsoleReader : public Reader { public: - virtual Text more(); + virtual Text more() override; void printPrimaryPrompt(); void fillInputBuffer(); @@ -40,17 +40,19 @@ private: char* p; }; + class FileReader : public Reader { public: FileReader(const char* fname); - virtual Text more(); + virtual Text more() override; private: Text filename; int done; }; + class BlockReader : public Reader { public: @@ -64,4 +66,5 @@ private: int length; }; -#endif + +#endif // Reader_h -- cgit v1.1