/****************************************************************************
*
*	KeyMacro.h ------------	KeyMacro main include file.
*
*	Author ----------------	Olaf Barthel, MXM
*				Brabeckstrasse 35
*				D-3000 Hannover 71
*
*	KeyMacro  ©  Copyright  1990  by  MXM;  Executable  program,
*	documentation  and  source  code are shareware.  If you like
*	this  program  a  small donation will entitle you to receive
*	updates and new programs from MXM.
*
****************************************************************************/

#ifndef KEYMACRO_H
#define KEYMACRO_H 1

#define __NO_PRAGMAS 1

	/* Standard include files. */

#include <intuition/intuitionbase.h>
#include <libraries/dosextens.h>
#include <workbench/workbench.h>
#include <devices/inputevent.h>
#include <libraries/arpbase.h>
#include <workbench/startup.h>
#include <graphics/gfxbase.h>
#include <exec/interrupts.h>
#include <devices/console.h>
#include <devices/conunit.h>
#include <devices/keymap.h>
#include <devices/timer.h>
#include <exec/execbase.h>
#include <devices/input.h>
#include <exec/memory.h>

#include <clib/intuition_protos.h>
#include <clib/graphics_protos.h>
#include <clib/console_protos.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>

	/* Name of global MsgPort and program revision. */

#define PORTNAME	"KeyMacro"
#define REVISION	8

	/* Signal flag names. */

#define SIG_CLOSE	SIGBREAKF_CTRL_C
#define SIG_PORT	(1 << SigBit)
#define SIG_SHAKE	SIGBREAKF_CTRL_F

	/* MacroKey tag IDs */

#define MK_UNUSED	0
#define MK_WORD		1
#define MK_COMMAND	2

	/* MacroMessage tad IDs */

#define MM_INPUT	0
#define MM_UPDATE	1
#define MM_EXECUTE	2

	/* Maximum number of key macros. Change this if you prefer
	 * more of less.
	 */

#define MAXMACROS	30

	/* KeyMacro InputEvent subclass. */

#define KM_SUBCLASS	97

	/* Values for non-ASCII key codes. */

#define KC_CURSORUP	140
#define KC_CURSORDOWN	141
#define KC_CURSORRIGHT	142
#define KC_CURSORLEFT	143

#define KC_FKEY1	129
#define KC_FKEY2	130
#define KC_FKEY3	131
#define KC_FKEY4	132
#define KC_FKEY5	133
#define KC_FKEY6	134
#define KC_FKEY7	135
#define KC_FKEY8	136
#define KC_FKEY9	137
#define KC_FKEY10	138

#define KC_HELP		139

	/* ToUpper macro, will also handle international characters. */

#define ToUpper(c)	(((c >= 224 && c <= 254) || (c >= 'a' && c <= 'z')) ? c - 32 : c)

	/* Allocate public memory. */

#define AllocPub(Size)	AllocRem(Size,MEMF_PUBLIC | MEMF_CLEAR)

	/* A keyboard alias, includes a name string and a value
	 * to be used as an equivalent.
	 */

struct KeyAlias
{
	char	*ka_Name;
	UWORD	 ka_Key;
};

	/* A MacroKey structure. */

struct MacroKey
{
	UBYTE	 mk_Type;		/* Type of macro key. */

	UBYTE	 mk_CommandKey;		/* Key to call this macro. */
	UWORD	 mk_CommandQualifier;	/* Qualifier needed to hold while pressing the key. */

	UBYTE	*mk_String;		/* String to be entered/Name of command to be executed. */
	UBYTE	*mk_Window;		/* Name of window to look for. */
};

	/* A MacroMessage structure. */

struct MacroMessage
{
	struct Message	 mm_Message;	/* Standard Exec message. */

	UBYTE		 mm_Type;	/* Message type. */

	struct MacroKey	*mm_MacroKey;	/* A list of macro keys. */

	LONG		 mm_NumMacros;	/* Number of macros to follow. */
	struct MacroKey	*mm_MacroList;	/* A list of macros to add to the list. */

	UBYTE		*mm_FileName;	/* A file to execute. */
	UBYTE		*mm_WindowName;	/* A window title to look for. */
};

	/* A MSeg structure, basically an extended MsgPort. */

struct MSeg
{
	struct MsgPort	 Port;		/* Standard Exec MsgPort. */

	BPTR		 Segment;	/* Pointer to handler segment. */
	LONG		 SegSize;	/* Length of MSeg structure. */

	UBYTE		 Revision;	/* Handler revision. */

	struct Task	*Father;	/* Calling task. */
	struct Task	*Child;		/* Waiting task. */

	ULONG		 RingBack;	/* Global wait signal. */

	LONG		 NumMacros;	/* Number of macros in list. */
	struct MacroKey	*MacroList;	/* A list of macro keys. */

	struct KeyMap	*DefaultKeyMap;	/* Default keymap used for key translation. */
	LONG		 Delay;		/* Key event delay in micro seconds. */
};

#endif	/* KEYMACRO_H */
