/*
    (C) 1995-96 AROS - The Amiga Replacement OS
    $Id: entryhandler.c,v 1.1 1997/02/03 16:44:22 digulla Exp $

    Desc:
    Lang: english
*/
#include "iffparse_intern.h"

/*****************************************************************************

    NAME */
#include <proto/iffparse.h>

	AROS_LH6(LONG, EntryHandler,

/*  SYNOPSIS */
	AROS_LHA(struct IFFHandle *, iff, A0),
	AROS_LHA(LONG              , type, D0),
	AROS_LHA(LONG              , id, D1),
	AROS_LHA(LONG              , position, D2),
	AROS_LHA(struct Hook      *, handler, A1),
	AROS_LHA(APTR              , object, A2),

/*  LOCATION */
	struct Library *, IFFParseBase, 17, IFFParse)

/*  FUNCTION
	Installs an entry handler for a specific chunk type
	that wil be called whenever a chunk of that type is pushed on the contextstack
	via ParseIFF().


    INPUTS
	iff	    - pointer to an iffhandle struct.
	type	  - type code for the chunk to handle. (ex: "ILBM").
	id	  -  ID code for the chunk to handle. (ex: "CMAP")
	position  -  position of localcontextitem. See StoreLocalItem for
		    more info.
	handler    -  an initialised Hook structure for the handler function.
	object	  -  pointer to some kind of object that will be passed to
		    your handler function.

    RESULT
	error - 0 If successfull, IFFERR_#? elsewise.

    NOTES

    EXAMPLE

    BUGS

    SEE ALSO
	ExitHandler(), StoreLocalItem(), StoreItemInContext()



    INTERNALS

    HISTORY
  27-11-96    digulla automatically created from
	  iffparse_lib.fd and clib/iffparse_protos.h

*****************************************************************************/
{
    AROS_LIBFUNC_INIT
    AROS_LIBBASE_EXT_DECL(struct Library *,IFFParseBase)

    struct LocalContextItem *lci;
    struct HandlerInfo *hi;

    if
    (
	!(lci = AllocLocalItem
	    (
		type,
		id,
		IFFLCI_ENTRYHANDLER,
		sizeof (struct HandlerInfo)
	    )
	)
    )
	return (IFFERR_NOMEM);

    /* Get pointer to the user data */
    hi = LocalItemData(lci);

    hi->hi_Hook  = handler;

    hi->hi_Object  = object;

    return
    (
	StoreLocalItem
	(
	    iff,
	    lci,
	    position
	)
    );

    AROS_LIBFUNC_EXIT
} /* EntryHandler */
