// ddiff/dpatch - manipulate differences between debian packages.
// Copyright 2000 Tom Rothamel <tom-ddiff@onegeek.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  

// Generic file read code. Contains a generic interface to reading and finding
// sub-members of files of various types.

#include <stdio.h>
#include <malloc.h>
#include "genfile.h"

// Implementation of common methods on the various genfile base classes.

FINFO::FINFO() {
	name = NULL;
	tar = NULL;
	hdr = NULL;
}

FINFO::~FINFO() {
	if (name) free(name);
}

GFILE::GFILE() {
	finfo = NULL;
}

GFILE::~GFILE() {
	if (finfo) delete finfo;
}

int GARCHIVE::findfwd(char *name) {
	while (member()) {
		if (!finfo->name) continue;
		if (!strcmp(finfo->name, name)) return 1;
	}

	return 0;
}

int GARCHIVE::find(char *name) {
	if (finfo->name) {
		if (!strcmp(name, finfo->name)) {
			seek(0);
			return 1;
		}
	}

	if (findfwd(name)) return 1;
	reset();
	return findfwd(name);
}
