/* OpenAmiga.org
 *  This file is part of the OpenAmiga "xfdmaster library project"
 *
 * For more information look at:
 *   http://openamiga.org/?function=viewproject&projectid=67
 */

/****************************************************************************
*   XFD library system for cruncher handling
*   Copyright (C) 1994-1998 by Georg Hörmann
*   Copyright (C) 1998 by Dirk Stöcker <soft@dstoecker.de>
*   Copyright (C) 2014 by Fredrik Wikström <fredrik@a500.org>
*
*   This library is free software; you can redistribute it and/or
*   modify it under the terms of the GNU Lesser General Public
*   License as published by the Free Software Foundation; either
*   version 2.1 of the License, or (at your option) any later version.
*
*   This library 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
*   Lesser General Public License for more details.
*
*   You should have received a copy of the GNU Lesser General Public
*   License along with this library; if not, write to the Free Software
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
****************************************************************************/

#include <interfaces/xfdmaster.h>
#include "../xfdmaster_vectors.h"
#include "../xfdmaster_internal.h"

/****** xfdmaster.library/xfdGetErrorText ******************************************
*
*   NAME
*      xfdGetErrorText -- Description
*
*   SYNOPSIS
*      STRPTR xfdGetErrorText(ULONG error);
*
*   FUNCTION
*
*   INPUTS
*       error - 
*
*   RESULT
*       The result ...
*
*   EXAMPLE
*
*   NOTES
*
*   BUGS
*
*   SEE ALSO
*
*****************************************************************************
*
*/

struct ErrorEntry {
	UWORD Error;
	CONST_STRPTR Text;
};
static const struct ErrorEntry ErrorTable[] = {
	{ XFDERR_OK, "no errors" },
	{ XFDERR_NOMEMORY, "out of memory" },
	{ XFDERR_NOSLAVE, "missing slave entry" },
	{ XFDERR_NOTSUPPORTED, "not supported" },
	{ XFDERR_UNKNOWN, "unknown file" },
	{ XFDERR_NOSOURCE, "no source specified" },
	{ XFDERR_WRONGPASSWORD, "wrong password" },
	{ XFDERR_BADHUNK, "bad hunk structure" },
	{ XFDERR_CORRUPTEDDATA, "corrupted data" },
	{ XFDERR_MISSINGRESOURCE, "missing resource" },
	{ XFDERR_WRONGKEY, "wrong 16/32 bit key" },
	{ XFDERR_BETTERCPU, "better cpu required" },
	{ XFDERR_HOOKBREAK, "hook caused break" },
	{ XFDERR_DOSERROR, "dos error" },
	{ XFDERR_NOTARGET, "no user target" },
	{ XFDERR_TARGETTOOSMALL, "user target too small" },
	{ XFDERR_TARGETNOTSUPPORTED, "user target not supported" },
	{ XFDERR_UNDEFINEDHUNK, "undefined hunk type" },
	{ XFDERR_NOHUNKHEADER, "file is not executable" },
	{ XFDERR_BADEXTTYPE, "bad hunk_ext type" },
	{ XFDERR_BUFFERTRUNCATED, "buffer truncated" },
	{ XFDERR_WRONGHUNKAMOUNT, "wrong amount of hunks" },
	{ XFDERR_NOOVERLAYS, "overlays not allowed" },
	{ XFDERR_UNSUPPORTEDHUNK, "unsupported hunk type" },
	{ XFDERR_BADRELMODE, "unknown relocation mode" },
	{ (UWORD)-1, "undefined error" }
};

CONST_STRPTR _xfdMaster_xfdGetErrorText(struct xfdMasterIFace *Self, ULONG error) {
	DEBUGF("xfdGetErrorText(0x%08lx, %lu)\n", Self, error);
	const struct ErrorEntry *entry = ErrorTable;
	while (entry->Error != (UWORD)-1 && entry->Error != error) {
		entry++;
	}
	return entry->Text;
}

