#ifndef	LIBRARIES_ERRORMSG_H
#define	LIBRARIES_ERRORMSG_H
/*
**	$Filename: libraries/errormsg.h $
**	$Revision: 4.01 $
**
**	errormsg.library definitions
**
**	(C) Copyright 1994 Frédéric Delacroix
**	All Rights Reserved
*/

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

#ifndef	EXEC_LISTS_H
#include <exec/lists.h>
#endif

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

#ifndef	EXEC_SEMAPHORES_H
#include <exec/semaphores.h>
#endif

#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem.h>
#endif

struct ErrorMsgBase {
   struct Library LibNode;
   ULONG emb_SegList;	/* pointer to seglist (PRIVATE) */

/* These remain valid as long as errormsg.library is open, they are readable
   by your application... */
   APTR emb_DOSBase;	/* pointer to DOSBase */
   APTR emb_IntuitionBase;	/* pointer to IntuitionBase */
   APTR emb_LocaleBase;	/* pointer to LocaleBase */
   APTR emb_UtilityBase;	/* pointer to UtilityBase */
   APTR emb_RexxSysLibBase;	/* pointer to RexxSysLibBase (or NULL if it */
   				/* couldn't be opened), new for V2.0 */
   APTR emb_ExecBase;	/* pointer to ExecBase , new for V3.02 */

/* This is private (subject to changes): */
   APTR emb_Locale;
   APTR emb_Catalog;
   struct SignalSemaphore emb_FaultSemaphore;
   struct MinList emb_FaultCache;
   UBYTE FaultBuffer[100];
};

/************************************************************************
* System ID values							*
*************************************************************************
These IDs are to be passed as the "System" argument: */

#define ERMSYS_INVALID	-1L	/* internal use */
#define ERMSYS_DOS	0L	/* messages from dos.library */
#define ERMSYS_EXEC	1L	/* messages from exec.library */
#define ERMSYS_GRAPHICS	2L	/* messages from graphics.library */
#define ERMSYS_INTUITION	3L	/* messages from intuition.library */
#define ERMSYS_IFFPARSE	4L	/* messages from iffparse.library */

#define ERMSYS_AUDIO	5L	/* messages from audio.device */
#define ERMSYS_GAMEPORT	6L	/* messages from gameport.device */
#define ERMSYS_NARRATOR	7L	/* messages from narrator.device */
#define ERMSYS_PARALLEL	8L	/* messages from parallel.device */
#define ERMSYS_PRINTER	9L	/* messages from printer.device */
#define ERMSYS_SCSIDISK	10L	/* messages from scsidisk.device */
#define ERMSYS_SERIAL	11L	/* messages from serial.device */
#define ERMSYS_TRACKDISK	12L	/* messages from trackdisk.device */
#define ERMSYS_CLIPBOARD	13L	/* etc... */
#define ERMSYS_CONSOLE	14L
#define ERMSYS_INPUT	15L
#define ERMSYS_KEYBOARD	16L
#define ERMSYS_TIMER	17L

#define	ERMSYS_AMIGAGUIDE	18L
#define	ERMSYS_ARP	19L
#define	ERMSYS_COMMODITIES	20L
#define	ERMSYS_ERRORMSG	21L	/* yes, we can diagnostic our own errors */
#define	ERMSYS_EXPANSION	22L
#define	ERMSYS_GADTOOLS	23L
#define	ERMSYS_POWERPACKER	24L
#define	ERMSYS_TRANSLATOR	25L
#define	ERMSYS_DATATYPES	26L
#define	ERMSYS_DISKFONT	27L

/* new for V3: */
#define ERMSYS_MUI	28L

/* new for V3.04: */
#define ERMSYS_XFD	29L

/* new for V4.00: */
#define ERMSYS_GADTOOLSBOX	30L

/* new for V4.01: */
#define ERMSYS_GUIFRONT	31L
#define ERMSYS_XPK	32L

#define	ERMSYS_LAST	ERMSYS_XPK	/* (for now!) */

/************************************************************************
* Subsystem ID values							*
*************************************************************************
These values were chosen so that they look significant: they are equal
to _LVO offsets for libraries, and CMD_ for devices... It's probably
just as good to implement them as that in your program... A warning
however: some _LVO are not recognized (for example, ERMSUB_MatchFirst
is the same value as ERMSUB_IoErr), some are recognized as a special
case (like ERMSYS_MUI/ERMSUB_MUIAutoError).

Another note: they may be ignored for some systems... */
#define ERMSUB_Generic	0L	/* This is for systems that do not support
	specific subsystem values. Providing this will protect you from
	future changes... */

/* Values for ERMSYS_DOS: */
/* Special note: passing 0 as the error code when using ERMSYS_DOS/
ERMSUB_IoErr will tell errormsg.library to get the error from IoErr()
itself. */

#define ERMSUB_IoErr	-132L	/* internally implemented as a cached */
#define ERMSUB_MatchFirst	ERMSUB_IoErr	/* call to Fault() */
#define ERMSUB_MatchNext	ERMSUB_IoErr	/* (value is _LVOIoErr) */
#define ERMSUB_Fault	ERMSUB_IoErr

#define	MIN_DOS_ERROR	100	/* Only these codes are supported, */
#define	MAX_DOS_ERROR	310	/* to prevent "Error code..." to be stored
				   in memory hundreds of times... */

/* Values for ERMSYS_EXEC:
for this value, you may pass the memory requirements (MEMF_...) as the
error code for a more precise message, or 0 for a standard out of mem.
ex: GetErrorMsg(ERMSYS_EXEC,ERMSUB_NoMemory,MEMF_CHIP!MEMF_CLEAR) will
return "Not enough CHIP memory" */
#define ERMSUB_NoMemory	-198L	/* (equals _LVOAllocMem) */

/* This value is new for V3.02. With ERMSYS_EXEC/ERMSUB_NoLibrary, you can
alert the user when a library has failed to open. The Code parameter is
a bit special then: it is a flag mask. By setting bits in this mask, you
tell errormsg.library you wish to have a message with arguments (the library
name and version) in it. See below for supported value, and for
DisplayErrorMsgA() additionnal tag handling.
This value can of course also be used for opening devices and resources.
(You should not provide a version number for resources) */
#define ERMSUB_NoLibrary	-552	/* (equals _LVOOpenLibrary) */


/* Values for ERMSYS_GRAPHICS:
note: these two are only usable as of V39 of the OS (Release 3.0) */
#define ERMSUB_MakeVPort	-216L	/* (equals _LVOMakeVPort) */
#define ERMSUB_MrgCop	-210L	/* (_LVOMrgCop) */

/* Values for ERMSYS_INTUITION:
note: returned through the SA_ErrorCode TagItem */
#define ERMSUB_OpenScreen	-198L	/* (_LVOOpenScreen) */
#define ERMSUB_OpenScreenTagList	ERMSUB_OpenScreen

/* Values for ERMSYS_COMMODITIES: */
#define	ERMSUB_CxBroker	-36L	/* (_LVOCxBroker) */
#define	ERMSUB_CxObjError	-66L	/* (_LVOCxObjError) */

/* New for V3: this subsystem ID is valid only for ERMSYS_MUI, providing it
to GetErrorMsgA() and providing a pointer to the base of muimaster.library
instead of a code in D0 will tell errormsg.library to call MUI_Error
automagically. This base must be valid ! errormsg.library currently checks
if the ln_Name field points to the good name, but don't count on it as it
can (and will if the library base is incorrect) cause (luckily harmless)
Enforcer hits.
If you provide the error code yourself, use ERMSUB_Generic instead.*/

#define	ERMSUB_MUIAutoError	-66L	/* (_LVOMUI_Error) */

/* New for V4.00, values defined for ERMSYS_GADTOOLSBOX: */

/* Use this one for errors returned by GTX_LoadGUIA() */
#define ERMSUB_LoadGUI	-264L	/* (_LVOGTX_LoadGUIA) */

/* This one is used to identify errors returned by the function
SetupScreen() in the generated source: */
#define ERMSUB_SetupScreen	1L

/* And this one for errors issued by the functions OpenxxxWindow(): */
#define ERMSUB_OpenAWindow	2L


/* Values for ERMSYS_GUIFRONT, new for V4.01: */

/* This is for error codes returned by GF_CreateGUIA() via the
GUI_ExtendedError tag. */
#define ERMSUB_CreateGUIA	EQU	-60L	/* (_LVOGF_CreateGUIA) */


/* No values are defined for the other systems yet, just provide
ERMSUB_Generic as the subsystem code. Note: narrator.device does not
use the standard error codes that are defined in exec/errors.h */

/***************************************************************************
* Errors that may be returned by errormsg.library itself (returned through *
* the EMT_Error tag):                                                      *
***************************************************************************/
#define	ERMERR_Unsupported_System	1L
#define	ERMERR_Unsupported_SubSystem	2L
#define	ERMERR_Unknown_Code	3L
#define	ERMERR_NoMemory	4L


/***************************************************************************
* Some flags                                                               *
***************************************************************************/
/* Tell GetErrorMsgA() (and thus DisplayErrorMsgA() too) to return a message
with a place (%s) for the library name when ERMSYS_EXEC/ERMSUB_NoLibrary
is used (the code argument is then a mask made of these flags). */
#define	EXECB_NOLIB_USENAME	0L
#define	EXECF_NOLIB_USENAME	1<<EXECB_NOLIB_USENAME

/* Tell errormsg.library to return a message with a place (%ld) for the
library version number when ERMSYS_EXEC/ERMSUB_NoLibrary is used. Secify
only together with EXECF_NOLIB_USENAME (in the code argument too). */
#define	EXECB_NOLIB_USEVERSION	1L
#define	EXECF_NOLIB_USEVERSION	1<<EXECB_NOLIB_USEVERSION

/* Like it says ! */
#define	EXECB_NOLIB_PRIVATE1	31L
#define	EXECF_NOLIB_PRIVATE1	1<<EXECB_NOLIB_PRIVATE1


/***************************************************************************
* Tag values                                                               *
***************************************************************************/
#define EMT_Dummy	TAG_USER

/* Tag values for GetErrorMsgA(): */

#define EMT_Error	EMT_Dummy+1
#define EMT_Length	EMT_Dummy+2
#define EMT_ForceCopy	EMT_Dummy+4

/* Tag values for DisplayMsgA(): */

#define EMT_Window	EMT_Dummy+20
#define EMT_Title	EMT_Dummy+21
#define EMT_GadFmt	EMT_Dummy+22
#define EMT_IDCMPPtr	EMT_Dummy+23

/* new for V3.01: DisplayMessageA() (so DisplayErrorMsgA() too) can use
MUI_RequestA() instead of EasyRequestArgs(). See autodocs for details. */
#define	EMT_MUIBase	EMT_Dummy+24
#define	EMT_MUIAppObject	EMT_Dummy+25
#define	EMT_MUIWinObject	EMT_Dummy+26

/* new tags for DisplayErrorMsgA() in V3.02.
these tag are only checked for ERMSYS_EXEC/ERMSUB_NoLibrary sys/subsystem
pair, and only when using DisplayErrorMsgA(). If you use GetErrorMsgA()
and then DisplayMessageA(), you must provide these arguments by hand. The
tags are quite self-explanatory, they are described in the DisplayErrorMsgA()
autodoc. */
#define	EMT_LibName	EMT_Dummy+40
#define	EMT_LibVersion	EMT_Dummy+41

/**************************************************************************/
#define ErrorMsgName	"errormsg.library"	/* beware ! lower-case ! */

#endif	/* LIBRARIES_ERRORMSG_H */
