/************
 *
 * Includes:
 *
 ************/

#include <stdio.h>
#include <exec/types.h> 
#include	<intuition/intuitionbase.h>
#include	<intuition/intuition.h>

/***********
 *
 * Defines:
 *
 ***********/

#define MAXWIDTH 80
#define MAXHEIGHT 64
#define BGPEN 0L
#define FGPEN 1L
#define FOLDPEN 2L
#define CTRLPEN 3L
#define EVENLEN(x) (((x)+1)&-2)
#define CONTROLCODE(c) (((c)&127)<32)

#define ZLINESPTR(n) actualEditor->zlinesptr[n]
#define ZLINESNR(n) actualEditor->zlinesnr[n]

#define INFO_XPOS_INC 2
#define INFO_XPOS_LEN 4
#define INFO_YPOS_INC 9
#define INFO_YPOS_LEN 4
#define INFO_NUMOFLINES_INC 16
#define INFO_NUMOFLINES_LEN 4
#define INFO_MINFOLD_INC 22
#define INFO_MINFOLD_LEN 2
#define INFO_MAXFOLD_INC 25
#define INFO_MAXFOLD_LEN 2
#define INFO_FLAGS_INC 29
#define INFO_FLAGS_LEN 5

/*******************
 *
 * Data structures:
 *
 *******************/

struct Zline
{
	struct Zline *succ;
	struct Zline *pred;
	UBYTE flags;
	UBYTE len;
};

#define ZLF_USED 128
#define ZLF_FSE 64
#define ZLF_FOLD 63

struct ZList
{
	struct Zline *head;
	struct Zline *tail;
	struct Zline *tailpred;
};

struct Memorysection
{
	struct Memorysection *succ;
	struct Memorysection *pred;
	UWORD len;
};

struct FList
{
	struct Memorysection *head;
	struct Memorysection *tail;
	struct Memorysection *tailpred;
};

struct Memoryblock
{
	struct Memoryblock *succ;
	struct Memoryblock *pred;
	ULONG length;
	ULONG free;
	struct FList freeliste;
};

struct BList
{
	struct Memoryblock *head;
	struct Memoryblock *tail;
	struct Memoryblock *tailpred;
};

struct Editor
{
	struct Editor *succ;
	struct Editor *pred;
	struct Window *window;
	struct BList block;
	struct ZList zlines;
	UBYTE buffer[MAXWIDTH + 1];
	UBYTE buflastchar;
	UWORD buflen,bufypos;
	UBYTE tabstring[MAXWIDTH];
	UWORD num_lines;
	struct Zline *actual;
	struct Zline *zlinesptr[MAXHEIGHT];
	UWORD zlinesnr[MAXHEIGHT];
	UWORD leftpos;
	UWORD xpos,ypos;
	UWORD wdy;
	UWORD changed		: 1;
	UWORD insert		: 1;
	UWORD tabs			: 1;
	UWORD skipblanks	: 1;
	UWORD autoindent	: 1;
	struct RastPort *rp;
	UWORD xoff,yoff;
	UWORD xscr,yscr;
	UWORD cw,ch;
	UWORD wcw,wch;
	UWORD xrl,xrr,yru,bl;
	UWORD minfold;
	UWORD maxfold;
	UBYTE gc_SIBuffer[256];
	struct StringInfo gc_GadgetSI;
	struct Gadget G_Command;
	UBYTE gi_Text[36];
	struct IntuiText gi_IText;
	struct Gadget G_Info;
	ULONG ip_xpos;
	ULONG ip_ypos;
	ULONG ip_numzlines;
	ULONG ip_minfold;
	ULONG ip_maxfold;
	ULONG ip_flags;
	ULONG ip_topedge;
	UBYTE	filename[80];
	UWORD	rm;
	struct Zline *lineptr;
};

struct EList
{
	struct Editor *head;
	struct Editor *tail;
	struct Editor *tailpred;
};
