#ifndef INSPECTOR_INSPECTOR_H
#define INSPECTOR_INSPECTOR_H

/*
**	$VER: inspector.h 37.3 (08.11.93)
**
**	inspector.library interface structures and definitions
**
**	Copyright © 1993 Sebastiano Vigna, Fabrizio Lodi and Reinhard Spisser
**	All Rights Reserved
*/

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


#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif

#ifndef EXEC_LIBRARIES_H
#include <exec/libraries.h>
#endif

#ifndef REXX_ERRORS_H
#include <rexx/errors.h>
#endif


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


/* This is the base structure of an Inspector library. It contains information
about the number of InspectorFunction structures and some stuff needed by the
SAS library startup code. */


struct InspectorLibrary {
	struct	Library Library;
	ULONG		SegList;

	struct Library *InspectedLibrary;

	ULONG		ForcingMask;	/* These flags are forced over the local flags */
	ULONG		TransMask;		/* These flags are looked up in the global ones */
	ULONG		Flags;			/* Flag status */

	ULONG		NumEntries;						/* Number of InspectorFunction entries pointed at by the next field */
	struct	FunctionData *Function;		/* The array of InspectorFunction entries of this library */
};


/* This structure holds informations about a specific function of a library. */

struct FunctionData {
	STRPTR	Name;						/* Name of the function (without parenthesis) */
	APTR		OldFunc;					/* When patched, holds the address of the old function */
	APTR		NewFunc;					/*	Function to use when patching */
	ULONG		TransMask;				/* Flags in this mask are transparent (look at an upper level) */
	ULONG		Flags;					/* Flag status */
	LONG		Offset;					/* Offset of this function in the library jump table */
};


/* Flags available for the Flags fields */

enum InspectorFlags {
	FUNCB_Patched,			/* The function is currently patched */
	FUNCB_Disabled,		/* Do not check anything */
	FUNCB_Entry,			/* Print a message at each function entry */
	FUNCB_Result,			/* Print the result (implies FUNCB_Entry) */
	FUNCB_Arguments,		/* Print the arguments (implies FUNCB_Entry) */
	FUNCB_Verbose,			/* implies FUNCB_Entry, FUNCB_Result and FUNCB_Arguments */
	FUNCB_Abort,			/* Do not enter the function if parameters are wrong (simulating function failure) */
	FUNCB_TaskInclude,	/* Check only for certain tasks known to the main library */
	FUNCB_TaskExclude,	/* Do not check certain tasks known to the main library */
	FUNCB_Forbid,			/* Isolate with Forbid()/Permit() the parameter display */
	FUNCB_Parallel,		/* Report on the parallel port */
	FUNCB_NoExpunge,		/* Do not get expunged, even if no patch is present */
	FUNCB_NoCheck,			/* No parameter checking */
	FUNCB_SegTracker,		/* Use SegTracker is present */
	FUNCB_Content,			/* Display first 16 bytes of pointer types */
	FUNCB_NoStackCheck,	/* Do not check for minimum stack requirements. _UNSAFE!_ */
	FUNCB_Pause,			/* Wait for a character being typed during checks */
	FUNCB_COUNT
};


#define FUNCF_Patched		(1UL << FUNCB_Patched)
#define FUNCF_Disabled		(1UL << FUNCB_Disabled)
#define FUNCF_Entry			(1UL << FUNCB_Entry)
#define FUNCF_Result			(1UL << FUNCB_Result)
#define FUNCF_Arguments		(1UL << FUNCB_Arguments)
#define FUNCF_Verbose		(1UL << FUNCB_Verbose)
#define FUNCF_Abort			(1UL << FUNCB_Abort)
#define FUNCF_TaskInclude	(1UL << FUNCB_TaskInclude)
#define FUNCF_TaskExclude	(1UL << FUNCB_TaskExclude)
#define FUNCF_Forbid			(1UL << FUNCB_Forbid)
#define FUNCF_Parallel		(1UL << FUNCB_Parallel)
#define FUNCF_NoExpunge		(1UL << FUNCB_NoExpunge)
#define FUNCF_NoCheck		(1UL << FUNCB_NoCheck)
#define FUNCF_SegTracker	(1UL << FUNCB_SegTracker)
#define FUNCF_Content		(1UL << FUNCB_Content)
#define FUNCF_NoStackCheck	(1UL << FUNCB_NoStackCheck)
#define FUNCF_Pause			(1UL << FUNCB_Pause)


enum OperatorFlags {
	OPB_Set,
	OPB_Clear,
	OPB_Normal,
	OPB_Forcing,
	OPB_Transparent,
	OPB_COUNT
};

#define OPF_Set				(1UL << OPB_Set)
#define OPF_Clear				(1UL << OPB_Clear)
#define OPF_Normal			(1UL << OPB_Normal)
#define OPF_Forcing			(1UL << OPB_Forcing)
#define OPF_Transparent		(1UL << OPB_Transparent)



/* Return codes for InspectorPatch() */

enum InspectorPatchError {
	INSPERROR_CANT_OPEN_LIBRARY = 1,
	INSPERROR_OUT_OF_RANGE,
	INSPERROR_CANT_UNPATCH,
	INSPERROR_BAD_PATTERN,
	INSPERROR_CANT_FIND_FUNCTION,
	INSPERROR_NO_LIBRARY_NAME,
	INSPERROR_OUT_OF_MEMORY,
	INSPERROR_CANT_OPEN_SERIAL
};


/* These are the argument types for a function. */

enum ArgumentTypes {
	AT_NoContent,				/* Argument is a number (do not print contents) */
	AT_CPointer,				/* Argument is a real pointer */
	AT_BCPLPointer,			/* Argument is a shifted BCPL pointer */
	AT_COUNT
};

#endif
