#ifndef _THINGS_H
#define _THINGS_H
/*
 *      This header defines all the definitions that are used
 *      within the THING system.   The THING system is provided
 *      as a standard feature with most SMS systems, and is
 *      a loadable extra for use with QDOS and close clones.
 *
 *  AMENDMENT HISTORY
 *  ~~~~~~~~~~~~~~~~~
 *  16 Sep 94   DJW   - Added definitions for hotkey system.
 *
 *  14 Dec 95   DJW   - Changed definition of THING_HEADER_EXT to remove
 *                      duplicate definition of thh_next and thh_exld fields.
 *                      (Problem reported by Jonathan Hudson & Lester Wareham)
 *
 *  22 Feb 96   DJW   - Changed parameter definition of hk_do() to remove the
 *                      extra level of indirection that should not be there.
 *                      (Problem reported by Lester Wareham)
 */

#ifndef _SYS_TYPES_H
#include <sys/types.h>
#endif

/*
 *  THING Linkage block
 */
typedef struct _thing_linkage {
    struct _thing_linkage * th_nxtth;   /* Pointer to NeXT THing linkage */
    long    th_usage;
    char *  th_frfre;           /* address of "close" routine for forced free */
    char *  th_frzap;           /* address of "close" routine for forced zap */
    char *  th_thing;           /* pointer to thing itself */
    char *  th_use;
    char *  th_free;
    char *  th_ffree;
    char *  th_remov;
    char    th_nshar;
    char    th_check;
    long    th_verid;
    short   th_name;
    char    th_name_text[1];
    };
typedef struct _thing_linkage THING_LINKAGE; 

/*
 *  Standard THING header
 */
typedef struct {
    char    thh_flag[4];        /* Should always be set to THH_FLAG */
    long    thh_type;
    } THING_HEADER;

#define THH_FLAG     "THG%"     /* standard value of thing header flag */

#define THT_LST      0x01000000 /* Bit set for list of things */
                                /* (in addition to one of values below) */
#define THT_UTIL     0x00000000 /* Utility thing */
#define THT_EXEC     0x00000001 /* executable thing */
#define THT_DATA     0x00000002 /* shared data */
#define THT_EXTN     0x00000003 /* extensions (user mode) */
#define THT_EXTS     0x00000004 /* extensions for system (supervisor mode) */
/*
 *  THING itself header
 */
typedef struct {
    THING_HEADER thh;
    char *  thh_entr;       /* Thing ENTRYy routine */
    char *  thh_exec;       /* Thing EXEC routine */
    } THING_HEADER_SELF;
/*
 *  List of things header
 */
typedef struct {
    THING_HEADER thh;
    long    thh_next;       /* Offset of next thing (or 0) */
    long    thh_exld;       /* extra ID */
    } THING_HEADER_LIST;
/*
 *  EXECutable THING header
 */
typedef struct {
    THING_HEADER thh;
    long    thh_hdrs;
    long    thh_hdrl;
    long    thh_data;
    long    thh_strt;
    } THING_HEADER_EXEC;
/*
 *  Extension THING header
 */
typedef struct {
    THING_HEADER thh;
    long    thh_next;       /* Offset of next thing (or 0) */
    long    thh_exld;       /* extra ID */
    long    thh_pdef;       /* offset of parameter definitions or 0 */
    long    thh_pdes;       /* offset of parameter descriptions or 0 */
    char    thh_code[1];    /* start of code */
    } THING_HEADER_EXT;


/*
 *  Hotkey item header
 */
typedef struct  {
    short   id;
    short   type;
    void    *ptr;
    short   str_len;
} HK_HEAD, *PHK_HEAD;

typedef struct
{
    HK_HEAD hd;
    char name[1];
} HK_ITEM, *PHK_ITEM;


#define HK_ID   0x6869

#define HKI_LLRC    -8
#define HKI_STPR    -6
#define HKI_STBF    -4
#define HKI_STUF    -2
#define HKI_CMD      0
#define HKI_NOP      2
#define HKI_XTHG     4
#define HKI_XFIL     6
#define HKI_PICK     8
#define HKI_WAKE    10
#define HKI_WKXF    12

#define HKI__TRN     0
#define HKI_TRN      1

typedef struct
{
    short   jsrl;
    long    gard;
    short   xo;
    short   yo;
    short   xs;
    short   ys;
    short   brdr;
    short   gmem;
    short   jma6;
    } HKH_GUARD, *PHKH_GUARD;

#define HKH_JSRL        0x4eb9
#define HKH_JMPA6       0x4ed6

/**
 *
 *      Function Prototypes
 *
**/

#ifdef __STDC__
#define _P_(params) params
#else
#define _P_(params) ()
#endif

/*
 *  THING handling 
*/
/*  Name hiding defintions */

/*  Prototypes */
int     sms_fthg    _P_((char *, jobid_t, long *, long, char *, char **));
int     sms_lthg    _P_((THING_LINKAGE *));
int     sms_nthg    _P_((char *, THING_LINKAGE **));
int     sms_nthu    _P_((char *, THING_LINKAGE **, jobid_t *));
int     sms_rthg    _P_((char *));
char *  sms_uthg    _P_((char *, jobid_t, timeout_t, long *, char *, long *, THING_LINKAGE **));
int     sms_zthg    _P_((char *));

/*
 *  HOTKEY System
 */
int     hk_cjob     _P_((void));
int     hk_do       _P_((HK_ITEM *));
int     hk_fitem    _P_((char *key_name, HK_ITEM **, short *, short *)); 
int     hk_gtbuf    _P_((int, char **));
int     hk_kjob     _P_((void));
int     hk_on       _P_((char *));
int     hk_off      _P_((char *));
int     hk_rset     _P_((int, char *));
int     hk_remov    _P_((char *));
int     hk_set      _P_((int, HK_ITEM *, HKH_GUARD *));
int     hk_stbuf    _P_((char *));


#ifdef __LIBRARY__
/*************************************************************************
 *
 *                          C A U T I O N
 *                          ~~~~~~~~~~~~~
 *
 *  The remainder of this header contains definitions that are internal
 *  to the way that the C68 libraries have been implemented on QDOS/SMS.
 *  These definitions should not be used by any user program as they are
 *  subject to change without notice.
 *
 *************************************************************************/


#endif /* __LIBRARY__ */
         

#endif /* _THINGS_H */

