
/*
 * JED.H
 * (c) 1992-3 J.Harper
 */

#ifndef JED_H
#define JED_H

#define	 INTUI_V36_NAMES_ONLY
#include <exec/lists.h>
#include <exec/memory.h>
#include <exec/libraries.h>
#include <clib/asl_protos.h>
#include <clib/diskfont_protos.h>
#include <clib/dos_protos.h>
#include <dos/dostags.h>
#include <clib/exec_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/iffparse_protos.h>
#include <libraries/iffparse.h>
#include <clib/intuition_protos.h>
#include <clib/keymap_protos.h>
#include <clib/rexxsyslib_protos.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include "command.h"

#ifndef NOREGEXP
#include <regexp.h>
#endif

#define	 freestring(s) if(s)FreeVec(s)

/*
 * Line structure -- an array of these is in the TX->tx_Lines
 */
typedef struct LINE
{
    LONG	     ln_Strlen; /* includes '\0' */
    STRPTR	     ln_Line;
} LINE;

/*
 * structure to uniquely identify a character position
 */
typedef struct POS
{
    LONG	     pos_Line;
    WORD	     pos_Col;
} POS;

/*
 * Each bookmark has one of these in the tx_Marks list, the max number of
 * bookmarks is 65536 (±32768)
 */
typedef struct MARK
{
    struct MinNode   mk_Node;
    POS		     mk_Pos;
    WORD	     mk_Index;
} MARK;

/*
 * Prefs structure -- all values local to each window, new windows inherit
 * PREFS from their parent.
 */
typedef struct PREFS
{
    BOOL	     prf_WordWrap;
    BOOL	     prf_AutoIndent;
    BOOL	     prf_NoSnapshotWin;
    WORD	     prf_TabSize;
    WORD	     prf_DiskTab;
    WORD	     prf_SaveTabs;
    WORD	     prf_LeftMargin;
    WORD	     prf_RightMargin;
    UBYTE	     prf_FontName[30];
    LONG	     prf_FontSize;
    UBYTE	     prf_BakDir[100];
    WORD	     prf_MaxBak;
    UBYTE	     prf_ScreenName[100];
} PREFS;

/*
 * each separate file has one of these
 */
typedef struct TX
{
    struct MinNode   tx_Node;
    struct MinList   tx_Views;
    struct MinList   tx_Marks;
    LINE	    *tx_Lines;
    LONG	     tx_NumLines;
    LONG	     tx_Changes;
    STRPTR	     tx_FileName;
    STRPTR	     tx_TitleName;
    BOOL	     tx_ResetPrefs;	/* if TRUE vw_Prefs is reset to default when a new file is edited */
} TX;

/*
 * structure for each window (view)
 */
typedef struct VW
{
    struct MinNode   vw_Node;
    struct Window   *vw_Window;
    struct RastPort *vw_Rp;
    TX		    *vw_Tx;

    POS		     vw_CursorPos;
    POS		     vw_AutoMark;
    POS		     vw_Block[2];
    WORD	     vw_BlockStatus;	/* 0=block marked, 1=start marked, 2=end marked, -1=none marked */
    LONG	     vw_StartLine;
    WORD	     vw_StartCol;

    STRPTR	     vw_LastTitle;
    BOOL	     vw_NonStdTitle;

    BOOL	     vw_Sleeping;
    BOOL	     vw_DisplayLock;
    ULONG	     vw_ClickSecs, vw_ClickMics;

    WORD	     vw_OldDimensions[4];   /* l,t,w,h */
    WORD	     vw_MaxX, vw_MaxY;
    UWORD	     vw_XStartPix, vw_YStartPix;
    UWORD	     vw_XEndPix, vw_YEndPix;
    UWORD	     vw_XWidthPix, vw_YHeightPix;
    UWORD	     vw_XStep;
    struct TextFont *vw_Font;
    UWORD	     vw_FontStart;
    WORD	     vw_FontX, vw_FontY;

    UWORD	     vw_RefreshType;
    POS		     vw_RefreshPos;
    LONG	     vw_LastRefresh;	/* change count at last refresh */
    WORD	     vw_DeferRefresh;

    struct {
	LONG		 line;
	STRPTR		 text;
	LONG		 changes;
    }		     vw_LineUndo;

#ifndef NOREGEXP
    struct {
	regexp		*prog;
	POS		 matchpos;
	LONG		 changes;
    }		     vw_LastRE;
#endif

    PREFS	     vw_Prefs;
} VW;

/*
 * refresh types -- in descending priority.
 */
#define RFF_ALL	     1	    /* all of page is redrawn */
#define RFF_ALLFROM  2	    /* all of page from vw_RefreshPos is redrawn */
#define RFF_CURSLINE 4	    /* line of cursor is redrawn */
#define RFF_LINEFROM 8	    /* all of line from vw_RefreshPos is redrawn */

#define ON  1
#define OFF 0

/*
 * some macros for using MinLists
 */
#define AddMTail(l,n)	AddTail((struct List *)l, (struct Node *)n)
#define InsertM(l,n,ln) Insert((struct List *)l, (struct Node *)n, (struct Node *)ln)
#define RemoveM(n)	Remove((struct Node *)n)
#define NewMList(l)	NewList((struct List *)l)
#define IsMListEmpty(l) IsListEmpty((struct List *)l)
#define IsLastMNode(n)	(!((n)->mln_Succ))

#define Prototype extern

#ifdef DEBUG		/* make static variables viewable for debugging */
#define Local
#else
#define Local	  static
#endif

#endif /* JED_DEF_H */
