diff options
-rw-r--r-- | include/Input.h | 6 | ||||
-rw-r--r-- | lib/Input.cc | 30 |
2 files changed, 24 insertions, 12 deletions
diff --git a/include/Input.h b/include/Input.h index 0b074b2..181bf21 100644 --- a/include/Input.h +++ b/include/Input.h @@ -54,12 +54,14 @@ extern Stdin_t Stdin; class Archive : public Base { public: - Archive(const String &, int = 0) throw (GeneralException); + Archive(const String &, int = 0); + Archive(Handle *, int = 0); virtual ~Archive(); protected: static bool inarchive(const String &); static int open(const String &, Input::openresults_t *) throw (GeneralException); private: + void create() throw (GeneralException); bool inarchivein(const String &); int openin(const String &, Input::openresults_t *) throw (GeneralException); class FileTree : public Base { @@ -80,7 +82,7 @@ class Archive : public Base { FileTree * next, * prev, * father, * child; } filetree; String name; - Input archive; + Handle * archive; int type; Archive * next, * prev; static Archive * header; diff --git a/lib/Input.cc b/lib/Input.cc index c77120c..25862e3 100644 --- a/lib/Input.cc +++ b/lib/Input.cc @@ -193,8 +193,17 @@ Stdin_t Stdin; Archive * Archive::header = 0; -Archive::Archive(const String & fname, int atype) throw (GeneralException) : - name(fname), archive(fname), type(atype) { +Archive::Archive(const String & fname, int atype) : + name(fname), archive(new Input(fname)), type(atype) { + create(); +} + +Archive::Archive(Handle * hand, int atype) : + name(hand->GetName()), archive(hand), type(atype) { + create(); +} + +void Archive::create() { char buffer[1024]; int len; size_t size; @@ -203,18 +212,18 @@ Archive::Archive(const String & fname, int atype) throw (GeneralException) : switch(type) { case ARCHIVE_BUILTIN: - archive.read(buffer, 4); + archive->read(buffer, 4); if (*((Uint32 *)buffer) != BUILTIN_SIG) throw GeneralException(_("Archive: not in built-in format.")); while (p) { - archive.read(buffer, 1); + archive->read(buffer, 1); len = *buffer; if (len) { - archive.read(buffer, len); + archive->read(buffer, len); buffer[len] = 0; ifname = buffer; - size = archive.readU32(); - archive.read(buffer, 1); + size = archive->readU32(); + archive->read(buffer, 1); #ifdef DEBUG printm(M_BARE, _("Adding file `") + ifname + _("' to node `") + p->name + "'\n"); #endif @@ -225,7 +234,7 @@ Archive::Archive(const String & fname, int atype) throw (GeneralException) : p = p->Father(); } } - filetree.compute_ptrs(archive.tell()); + filetree.compute_ptrs(archive->tell()); break; default: throw GeneralException(_("Archive: unsupported archive format.")); @@ -236,7 +245,6 @@ Archive::Archive(const String & fname, int atype) throw (GeneralException) : header = this; if (next) next->prev = this; - } Archive::~Archive() { @@ -246,6 +254,8 @@ Archive::~Archive() { next->prev = prev; if (header == this) header = next; + + delete archive; } bool Archive::inarchive(const String & fname) { @@ -345,7 +355,7 @@ int Archive::openin(const String & fname, Input::openresults_t * results) throw results->ptr = p->ptr; results->size = p->size; results->type = p->type; - return archive.Dup(); + return archive->Dup(); } Archive::FileTree::FileTree(const String & fname, size_t fsize, int ftype, Archive::FileTree * fFather) : |