#include <intuition/intuitionbase.h>
#ifdef AZTEC_C
#include <functions.h>
struct IORequest *CreateExtIO(); /* This is a kludge that is necessary    */
                                 /* since this definition is missing from */
                                 /* manx's <functions.h> include file.    */
#endif AZTEC_C
#include <libraries/arpbase.h>
#include <devices/input.h>
#include <devices/keymap.h>
#include <devices/console.h>
#include <devices/clipboard.h>
#include <exec/memory.h>
#include <exec/interrupts.h>
#include <graphics/gfxmacros.h>

#define Create(_Obj)     AllocMem((LONG)sizeof(struct _Obj), MEMF_PUBLIC|MEMF_CLEAR)
#define Kill(_Obj)       FreeMem(_Obj, (LONG)sizeof(*_Obj))
#define Delete(_Obj)     if (_Obj) FreeMem(_Obj, (LONG)sizeof(*_Obj))

#define SNAPRSRC "Snap.resource"

struct SnapRsrc {
    struct Node node;
    struct Task *Task;
    WORD Priority;
    WORD gfxqual;
    WORD textqual;
    WORD insertkey;
    WORD cwkey;
    char Prepend[17];
    char Append[17];
    WORD flags;
    LONG chardelay;
    LONG linedelay;
    UWORD CrawlPtrn;
    WORD StartUnit;
    WORD FrameMask;
    WORD GadOffset;
    WORD CacheSize;
    WORD BadChar;
};

#define XEROX           1
#define EARLYPATCH      2
#define TRUEUNDERSCORE  4
#define JOINLONG        8

struct Snap {
    ULONG Size;
    char Chars[1];
};

struct GfxSnap {
    struct Gadget DiskGad;
    struct Gadget VProp;
    struct Gadget HProp;
    struct PropInfo VInfo;
    struct PropInfo HInfo;
    struct Image VImage;
    struct Image HImage;
    LONG x, y;
    LONG width, height;
    LONG depth;
    LONG viewmode;
    char rgb[32][3];
    SHORT pagew;
    SHORT pageh;
    struct Window *window;
    struct BitMap BM;
};

struct CacheWindow {
    struct MinNode Node;
    struct Window *Window;
    SHORT xoff;
    SHORT yoff;
    SHORT fw;
    SHORT fh;
};

#define SAVEGAD 1
#define DISKGAD 2
#define NAMEGAD 3
#define VPROP   4
#define HPROP   5

#define CLIP_FIRST 0
#define CLIP_CONT  1
#define CLIP_LAST  2

#define TitleFont(win) ((struct TextFont *)(win->IFont ? win->IFont : win->RPort->Font))

#define Swap2L(_x,_y) { REGISTER LONG _t = _x; _x = _y; _y = _t; }

#define noaction 0
#define snapgfx  1  /* window */
#define snaptext 2  /* text */
#define insert   4  /* inserting */

#define waiting   0
#define selregion 1
#define waitext   2
#define selgfx    3
#define waitgfx   4

#define UNIT_FRAME 1 /* rect of chars */
#define UNIT_CHAR  2 /* characters with line wrap */
#define UNIT_WORD  3 /* words with line wrap */
#define UNIT_LINE  4 /* lines */

#ifdef LATTICE
#include <string.h>     /* Prototyping of string functions */
#include <stdlib.h>     /* Prototyping of standard lib functions */
#endif

/* C_Args & ARGs borrowed from the Arp include file */

ULONG ReadClip ARGs( (struct IOClipReq *, STRPTR, ULONG, WORD) );
VOID WriteClip ARGs( (struct IOClipReq *, STRPTR, ULONG, WORD) );
VOID SaveClip ARGs( (UBYTE *, ULONG) );
struct Snap *FetchClip ARGs( (VOID) );
VOID MultiDraw ARGs( (struct RastPort *, LONG, Point *) );
VOID crawl_frame ARGs( (LONG) );
VOID erase_frame ARGs( (VOID) );
VOID draw_frame ARGs( (LONG) );
ULONG InvertKeyMap ARGs( (ULONG, struct InputEvent *, struct KeyMap *) );
UWORD LowKeyInvert ARGs( (register UBYTE, struct KeyMap *, UWORD *, UWORD *, ULONG *) );
VOID IndexKey ARGs( (ULONG, struct KeyMap *, ULONG *) );
WORD checkNormal ARGs( (LONG, UBYTE, UWORD, UWORD *) );
WORD checkVanilla ARGs( (UBYTE *, UBYTE, UWORD *) );
WORD checkDead ARGs( (UBYTE **, UBYTE, UWORD *, ULONG *) );
WORD deadQual ARGs( (WORD, UWORD *) );
struct Screen *WhichScreen ARGs( (VOID) );
struct Window *WhichWindow ARGs( (struct Screen *) );
VOID FreePlanes ARGs( (struct BitMap *, LONG, LONG) );
WORD AllocPlanes ARGs( (struct BitMap *, LONG, LONG) );
VOID CacheWindow ARGs( (struct Window *, LONG, LONG, SHORT, SHORT) );
struct CacheWindow *GetCachedWindow ARGs( (struct Screen *, struct Window *) );
VOID CloseStuff ARGs( (VOID) );
WORD OpenStuff ARGs( (VOID) );
VOID SafePatch ARGs( (VOID) );
VOID SafeRestore ARGs( (VOID) );
WORD bump ARGs( (WORD, UBYTE *, WORD) );
ULONG WriteBody ARGs( (struct BitMap *) );
WORD SaveGS ARGs( (struct GfxSnap *) );
WORD isdigit ARGs( (char) );
LONG dectoint ARGs( (char *) );
LONG hextoint ARGs( (char *) );
VOID InsertAscii ARGs( (ULONG) );
VOID GadText ARGs( (struct Gadget *, char *, LONG) );
VOID SwapColorMap ARGs( (struct GfxSnap *) );
VOID CheckWindowMsgs ARGs( (VOID) );
VOID SetSnapFont ARGs( (struct TextFont *) );
WORD IsSpace ARGs( (LONG, LONG) );
VOID update_frame ARGs( (VOID) );
VOID FindWord ARGs( (VOID) );
VOID ChangeUnit ARGs( (VOID) );
VOID ExtendSelection ARGs( (VOID) );
WORD SnapChars ARGs( (VOID) );
WORD HandleChars ARGs( (VOID) );
VOID FixHeights ARGs( (VOID) );
struct GfxSnap *SnapGfx ARGs( (struct RastPort *) );
VOID ExtendGfx ARGs( (VOID) );
VOID gfx_frame ARGs( (VOID) );
WORD HandleGfx ARGs( (VOID) );
struct Window *opensharedwindow ARGs( (struct NewWindow *) );
VOID closesharedwindow ARGs( (struct Window *) );
VOID SetUpBorder ARGs( (struct Border *, struct Gadget *) );
VOID AdjustSize ARGs( (struct GfxSnap *) );
VOID SyncGS ARGs( (struct GfxSnap *) );
SHORT OpenCW ARGs( (VOID) );
UBYTE C_Args interpret ARGs( (UWORD *) );
VOID CopyFont ARGs( (VOID) );
VOID myhandler();
