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

/****************************************************************************
*   FileDescript Linker
*
*   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 "../xfdmaster_internal.h"
#include <string.h>

static const TEXT DizStartTxt[] = "@BEGIN_FILE_ID.DIZ";
static const TEXT DizEndTxt[] = "@END_FILE_ID.DIZ";

BOOL LB_AnalyseDizPPC(struct xfdMasterIFace *Self, APTR hunk,
	struct xfdLinkerInfo *linkerinfo)
{
	CONST_STRPTR start = linkerinfo->xfdli_Buffer;
	ULONG length = linkerinfo->xfdli_BufLen;
	CONST_STRPTR end = start + length - 16;

	if (strcmp(start, DizStartTxt) == 0) {
		linkerinfo->xfdli_Amount1 = 1;
		// original asm checks end[16] here but this must be a bug IMO
		if (end[15] == '\n') {
			end--;
		}
		if (strcmp(end, DizEndTxt) != 0) {
			return TRUE;
		}
	} else if (strcmp(end, DizEndTxt) == 0) {
		linkerinfo->xfdli_Amount1 = 2;
		return TRUE;
	}
	return FALSE;
}

BOOL LB_UnlinkDizPPC(struct xfdMasterIFace *Self,
	struct xfdLinkerInfo *linkerinfo)
{
	/*if (linkerinfo->xfdli_Amount1 == 1) {
	} else {
	}*/
	linkerinfo->xfdli_Error = XFDERR_NOTSUPPORTED;
	return FALSE;
}

