From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from re-prd-fep-047.btinternet.com (mailomta10-re.btinternet.com [213.120.69.103]) by sourceware.org (Postfix) with ESMTPS id 7829D385841C for ; Sun, 23 Apr 2023 14:43:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7829D385841C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dronecode.org.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dronecode.org.uk Received: from re-prd-rgout-004.btmx-prd.synchronoss.net ([10.2.54.7]) by re-prd-fep-047.btinternet.com with ESMTP id <20230423144357.UYAC20465.re-prd-fep-047.btinternet.com@re-prd-rgout-004.btmx-prd.synchronoss.net>; Sun, 23 Apr 2023 15:43:57 +0100 Authentication-Results: btinternet.com; none X-SNCR-Rigid: 63FE9A2B061F5636 X-Originating-IP: [86.140.112.72] X-OWM-Source-IP: 86.140.112.72 (GB) X-OWM-Env-Sender: jonturney@btinternet.com X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvhedrfedtkedgkedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhonhcuvfhurhhnvgihuceojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqnecuggftrfgrthhtvghrnhepleeitdejhfdtveekheeugeffgeevfedtjeejveefhfeiffefkedtvdetheehieejnecukfhppeekiedrudegtddrudduvddrjedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplhhotggrlhhhohhsthdrlhhotggrlhguohhmrghinhdpihhnvghtpeekiedrudegtddrudduvddrjedvpdhmrghilhhfrhhomhepjhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukhdpnhgspghrtghpthhtohepvddprhgtphhtthhopegthihgfihinhdqrghpphhssegthihgfihinhdrtghomhdprhgtphhtthhopehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkpdhrvghvkffrpehhohhsthekiedqudegtddqudduvddqjedvrdhrrghnghgvkeeiqddugedtrdgsthgtvghnthhrrghlphhluhhsrdgtohhmpdgruhhthhgpuhhsvghrpehjohhnthhurhhnvgihsegsthhinhhtvghrnhgvthdrtghomhdpghgvohfk rfepifeupdfovfetjfhoshhtpehrvgdqphhrugdqrhhgohhuthdqtddtge X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from localhost.localdomain (86.140.112.72) by re-prd-rgout-004.btmx-prd.synchronoss.net (5.8.814) (authenticated as jonturney@btinternet.com) id 63FE9A2B061F5636; Sun, 23 Apr 2023 15:43:57 +0100 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 1/2] Add underlying() method to io_stream class Date: Sun, 23 Apr 2023 15:43:29 +0100 Message-Id: <20230423144330.3107-2-jon.turney@dronecode.org.uk> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230423144330.3107-1-jon.turney@dronecode.org.uk> References: <20230423144330.3107-1-jon.turney@dronecode.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,TXREP,T_FILL_THIS_FORM_SHORT,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Add underlying() method to io_stream class. This saves having to pass around both original and decompressed stream, just so you can call tell() on the original stream. For a non-compressed stream, it simply returns that io_stream object. In the case of a compressed stream, this returns the io_stream object for the underlying file stream. Move the original and owns_original members up to compress class from it's subclasses to facilitate that. Also clean up some cruft in io_stream.h --- compress.h | 13 +++++++++++++ compress_bz.cc | 2 -- compress_bz.h | 2 -- compress_gz.h | 2 -- compress_xz.cc | 2 -- compress_xz.h | 2 -- compress_zstd.cc | 2 -- compress_zstd.h | 2 -- io_stream.h | 31 ++++++------------------------- 9 files changed, 19 insertions(+), 39 deletions(-) diff --git a/compress.h b/compress.h index 1692fa6..5e84408 100644 --- a/compress.h +++ b/compress.h @@ -21,6 +21,11 @@ class compress:public io_stream { public: + compress () : + original(NULL), + owns_original(true) + { }; + /* Get a decompressed stream from a normal stream. If this function returns non-null * a valid compress header was found. The io_stream pointer passed to decompress * should be discarded. The old io_stream will be automatically closed when the @@ -48,6 +53,14 @@ public: virtual const char *next_file_name () = 0; /* if you are still needing these hints... give up now! */ virtual ~compress () = 0; + + virtual io_stream *underlying () + { + return original; + } +protected: + io_stream *original; + bool owns_original; }; #endif /* SETUP_COMPRESS_H */ diff --git a/compress_bz.cc b/compress_bz.cc index d801de1..f8a1199 100644 --- a/compress_bz.cc +++ b/compress_bz.cc @@ -26,7 +26,6 @@ compress_bz::compress_bz (io_stream * parent) : peeklen (0), position (0) { /* read only via this constructor */ - original = 0; lasterr = 0; if (!parent || parent->error ()) { @@ -34,7 +33,6 @@ compress_bz::compress_bz (io_stream * parent) : peeklen (0), position (0) return; } original = parent; - owns_original = true; init_state(); } diff --git a/compress_bz.h b/compress_bz.h index 9ab59d7..6ccccfc 100644 --- a/compress_bz.h +++ b/compress_bz.h @@ -56,8 +56,6 @@ public: /* if you are still needing these hints... give up now! */ virtual ~ compress_bz (); private: - io_stream *original; - bool owns_original; char peekbuf[512]; size_t peeklen; int lasterr; diff --git a/compress_gz.h b/compress_gz.h index c7ae14b..05b4b7b 100644 --- a/compress_gz.h +++ b/compress_gz.h @@ -67,8 +67,6 @@ private: void putLong (unsigned long); void destroy (); int do_flush (int); - io_stream *original; - bool owns_original; const char *openmode; /* from zlib */ z_stream stream; diff --git a/compress_xz.cc b/compress_xz.cc index b91c8a4..5c34a54 100644 --- a/compress_xz.cc +++ b/compress_xz.cc @@ -45,8 +45,6 @@ le64dec(const void *pp) */ compress_xz::compress_xz (io_stream * parent) : - original(NULL), - owns_original(true), peeklen(0), lasterr(0), compression_type (COMPRESSION_UNKNOWN) diff --git a/compress_xz.h b/compress_xz.h index 9be7822..48e620d 100644 --- a/compress_xz.h +++ b/compress_xz.h @@ -44,8 +44,6 @@ public: private: compress_xz () {}; - io_stream *original; - bool owns_original; char peekbuf[512]; size_t peeklen; int lasterr; diff --git a/compress_zstd.cc b/compress_zstd.cc index 8d6e51f..ba0e491 100644 --- a/compress_zstd.cc +++ b/compress_zstd.cc @@ -24,8 +24,6 @@ */ compress_zstd::compress_zstd (io_stream * parent) : - original(NULL), - owns_original(true), lasterr(0) { /* read only */ diff --git a/compress_zstd.h b/compress_zstd.h index b9b541e..c30d1a8 100644 --- a/compress_zstd.h +++ b/compress_zstd.h @@ -39,8 +39,6 @@ public: private: compress_zstd () {}; - io_stream *original; - bool owns_original; int lasterr; void create (); void destroy (); diff --git a/io_stream.h b/io_stream.h index f19e134..68915b1 100644 --- a/io_stream.h +++ b/io_stream.h @@ -47,15 +47,6 @@ typedef enum } path_type_t; -typedef enum -{ - IO_STREAM_INVALID, - IO_STREAM_STREAM, - IO_STREAM_COMPRESS, - IO_STREAM_ARCHIVE -} -io_stream_type_t; - typedef enum { IO_STREAM_SYMLINK, @@ -143,27 +134,17 @@ public: virtual int error () = 0; /* hmm, yet another for the guessing books */ virtual char *gets (char *, size_t len); - /* what sort of stream is this? - * known types are: - * IO_STREAM_INVALID - not a valid stream. - * IO_STREAM_STREAM - just another stream. - * IO_STREAM_COMPRESS - a compressed or compressing stream. - * IO_STREAM_ARCHIVE - an archive of some sort, with > 0 files. - * this is a crutch for real runtime type evaluation. - */ - /* Find out the next stream name - - * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar - * for foobar that is an archive, next_file_name is the next - * extractable filename. - */ -// virtual const char* next_file_name() = NULL; - /* if you are still needing these hints... give up now! */ + virtual ~io_stream () = 0; io_stream& operator << (io_stream&); virtual void operator << (std::string) {} virtual void operator << (const char *) {} - + + virtual io_stream *underlying () + { + return this; + } protected: void operator= (const io_stream &); io_stream() {}; -- 2.39.0