/*-- Rev Header - do NOT edit!
 *
 *  Filename : editfile.h
 *  Purpose  : Eine Klasse, die das Bearbeiten von Files erleichtert
 *
 *  Program  : -
 *  Author   : Gerhard Müller
 *  Copyright: (c) by Gerhard Müller
 *  Creation : Tue Sep  7 02:26:39 1993
 *
 *  compile  :
 *
 *  Compile version  : 0.1
 *  Ext. Version     : 0.1
 *
 *  REVISION HISTORY
 *
 *  Date                     Comment
 *  ------------------------ -------------------------------------------------
 *  Fri Sep 17 00:45:42 1993 Took from CED_Help, seems to work quite well
 *
 *-- REV_END --
 */

#ifndef ADD_EDITFILE_H
#define ADD_EDITFILE_H

	/*
	 * C-Includes, C-Definitionen
	 *
	 */

#define class _class
#define template _template

extern "C" {
#include <exec/types.h>
#include <exec/execbase.h>
#include <exec/memory.h>
#include <clib/alib_protos.h>
#include <clib/alib_stdio_protos.h>
#include <utility/tagitem.h>
#include <inline/stubs.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#ifdef __OPTIMIZE__
#include <inline/exec.h>
#include <inline/dos.h>
#else
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#endif
}

#undef template
#undef class


	/*
	 * C++-Includes, C++-Definitionen
	 *
	 */

#include "add.h"		// we call GetFileSize()
#include "OwnError.h"

class editfile {

private:
	ULONG	size;	// Länge des Files
	char	*mem;	// Zeiger auf Speicher im RAM
	BOOL	goodflag; // Öffnen erfolgreich ? Ja=TRUE

	void _intern_editfile(BPTR fh);

public:

	char	**index;	// Zeiger auf Array von Char-Pointern (0-terminitert)

/*

       ---> |----|
            |    | --> "String 1"
            |----|
            |    | --> "String 2"
            |----|
               .
               .
               .
            |----|
            |    | --> "String n"
            |----|
            |    | --> 0
            |----|

*/

	ULONG	strings;	// Anzahl Strings in Tabelle

	inline editfile(BPTR fh);
	inline editfile(char *filename);

	~editfile()
	{
		if(index) FreeVec(index);
		if(mem) FreeVec(mem);
	}

	inline BOOL editfile::good();
	inline BOOL editfile::bad();

};


inline editfile::editfile(char *filename)
{
	BPTR	fh;				// filehandle

	err.Clear();			// clear out all previous errors

	index=0;				// clear all private variables
	mem=0;

	if(fh=Open((unsigned char *)filename,MODE_OLDFILE))
	{
		_intern_editfile((BPTR) fh);

		Close(fh);
	}
	else
	{
		// kein File

		err.DosError(IoErr());
	}
}

inline editfile::editfile(BPTR fh)
{
	err.Clear();			// clear out all previous errors
	_intern_editfile((BPTR) fh);
}



inline BOOL editfile::good()
{
	return goodflag;
}

inline BOOL editfile::bad()
{
	return !goodflag;
}

#endif
