/*********************************************************************\
**                               ________________________________    **
**    A n t h o n y             |________    __    __    ________|   **
**                                       |  |o_|  |o_|  |            **
**            T h y s s e n            __|   __    __   |__          **
**                                  __|   __|  |  |  |__   |__       **
**   `` Dragon Computing ! ''    __|   __|     |  |     |__   |__    **
**                              |_____|        |__|        |_____|   **
**                                                                   **
\*********************************************************************/
/* Reprogrammed by  Anthony Thyssen Feburary 1991 --
**   Original Program "MyMenu" from `Fred Fish Disk 225' by
** Darin Johnson, 1989.  Thanks for the original program it is
** the best I had seen, but has a number of mistakes.
**   Thanks to Sylvain Rougier & Pierre Carrette for their version
** of Run.o which was also reprogrammed.
**   Edited with Dme and Compiled with Lattice C v5.0 and my own
** "ArpC" startup code for Arp Programs.
*/

#define  DO_ARP_COPIES         /* replace Dos calls with Arp Calls */
#include <Libraries/ArpBase.h>
#include <Proto/Arp.h>
#include <Proto/Exec.h>
#include <Proto/Intuition.h>
#include <Proto/Graphics.h>
#include <Exec/Memory.h>
#include <String.h>

#define VERSION         "AMenu v2.0"
#define COPYRIGHT \
 "AMenu v2.0 -- WorkBench menu support\n by Anthony Thyssen (Dragon Computing)"

#define AMENU_CONFIG    "S:AMenu.Config"
#define AMENU_CONFIG2   "AMenu.Config"
#define AMENU_HANDLER   "L:AMenu-Handler"
#define AMENU_HANDLER2  "AMenu-Handler"
#define AMENU_PORT      "AMenu-Port"
#define AMENU_WBPORT    "AMenu-WBPort"


  /* AMenu Defaults */
#define DEF_STACK        4096         /* Defaults used by program */
#define DEF_CONSOLE     "CON:100/11/200/20/AMenu Command"
#define DEF_DIRECTORY   "SYS:"        /* the assigned Sys: not boot device */


  /* Debugging Macros */
#ifdef DBUG     /* Debuging macros -- only compile DB( stmt ) on DBUG */
#  define DB(stmt)   stmt
#  define DBConsole  "CON:250/155/300/100/Debug Console"  /* PAL screen only */
   extern BPTR   DBWindow;   /* file handle to above window */
#else
#  define DB(stmt)
#endif


extern struct ArpBase       *ArpBase;
extern struct IntuitionBase *IntuitionBase;
extern struct GfxBase       *GfxBase;


  /* information about what to run on menu entry selection */
struct ExtMenuItem {
  struct MenuItem     MenuItem;     /* MenuItem it extend */
  struct ExtMenuItem *NextEItem;    /* Search and Freeing List Link */
  char               *Cmd;          /* Command to execute */
  char               *Args;         /* Arguments for Non-WorkBench */
  char               *Console;      /* Window to use  `'   `' */
  char               *Directory;    /* Directory      `'   `' */
  ULONG               Stack;        /* Stack          `'   `' */
  BYTE                Pri;          /* Prioity        `'   `' */
  char                Mode;         /* How to execute the item R,C,W */
};


  /* Error codes returned by Handler in M->ErrorCode */
typedef enum {
 ERR_OK, ERR_LIB, ERR_MPORT, ERR_DIR, ERR_MON, ERR_REPLYPORT, ERR_WBOPEN
} HandlerError;


  /* shared data structure attached to a Named Port */
struct MPort {
  struct MsgPort      Port;                   /* Port data is attacted to */
  struct ExtMenuItem *EItemList;              /* List for search and Free */
  struct Menu        *AMenu;                  /* Pointer to My New Menus */
  struct Window      *WBWindow;               /* BackGround Window of WB */
  BPTR                Segment;                /* struct Segment ptr */
  char               *Console;                /* Default Console */
  char               *Directory;              /* Default Directory */
  struct Task        *Handler, *Parent;       /* Other Task */
  USHORT              HandlerSig, ParentSig;  /* signals to flag with */
  HandlerError        ErrorCode;              /* Returned error code */
};

extern struct MPort *M;       /* Pointer to the Named Port */


