/* MINCE.GBL - This is the global variables and constants for
	MINCE, to be included in each source file. */

#include	"stdio.h"
#include	"ctype.h"
#include  "termcap.h"

#define UNIX			1		/* Unix only */
#define TYPE_AHEAD		1		/* type ahead is detectable */
#define SUSER			1		/* single user systems (paging messages) */
#define DIRECT			1
#define GENPW			1

	/* Universal global declarations */
#define TRUE	    (-1)
#define FALSE   0
#define INPUT   0x8000
#define OUTPUT  0x8001
#define UPDATE  0x8002
#define HOME	    0,0
#define FORWARD (-1)
#define BACKWARD	0

	/* MINCE globals */
#define MODEMAX 40
#define STRMAX  40
#define MAXMODES	4
#define BUFFSMAX	7
#define BUFNAMMAX       9


#define FILMAX  15
#define INITTABS	5
#define PREFLINE	10
#define FILLINIT	65
#define INDENTINIT  0
#define MAXPAGES	50
#define MSS		"MSS"
#define SWAPFNAM	"pw.swp"
#define SWAP1FNAM   "a:pw.swp"


	/* BUFFER globals */
#define MAXBUFF 8
#define PSIZE   1024
#define MAXMARK 24
#define SWAPMAX 256
#define MEMORY  0
#define SWAP	    1

#define LOCKED			(-1)
#define SWAP_PSIZE		8
#define FILE_PSIZE		8
#define SWAPBASE		128L

#define NL      '\12'
#define ROWMAX  60
#define COLMAX  132


struct page_desc {
	struct page_desc *nextp, *prevp;	/* list of pages in buffer */
	int afile, apage;		    /* actual location of the page */
	int gstart, plen;		     /* current length of the page */
	} *tpage, *cur_page;

struct buff {
	char bmodf;			     /* buffer modified? */
	struct page_desc *firstp, *lastp;       /* describe the pages */
	int page_cnt;			   /* number of pages currently */
	struct page_desc *pnt_page;     /* the position of the point */
	int pnt_offset;
	} buffers[MAXBUFF], *cur_buff;

 struct mrk {
	struct page_desc *mpage;	/* page in the buffer */
	struct buff *mbuff;	     /* buffer the mark is in */
	int moffset;		    /* offset in the page */
	char modf;		      /* screen mark modified flags */
	} scrnmarks[ROWMAX-1], marks[MAXMARK], *btmark;

struct cbuffer {
	struct buff *bbuff;
	struct mrk *bmark;
	char bname[BUFNAMMAX], fname[FILMAX], bmodes[MAXMODES];
	} buffs[BUFFSMAX];

	char *getmem();
	int arg, argp, lcol, cnt, tmp;
	struct mrk *sstart, *psstart, *send, *altpnt, *altstart;
	int sendp, topp, divide, altbuff;
	int (*functs[3*128])(), (*lfunct)(), fillwidth, indentcol;
	char strarg[STRMAX], mode[MODEMAX], namearg[BUFNAMMAX];
	int stat_col, abort, cmnd, cbuff;

	struct buff *del_buff, *BCreate();
	struct mrk *tmark, *mark, *BCreMrk();

	/* TTY globals */
#define NUL     '\0'
#define BELL    '\7'
#define BS      '\10'
#define TAB     '\11'
#define LF      '\12'
#define CR      '\15'
#define ESC     '\33'
#define DEL     '\177'

struct terminal {
	int nrows;
	int ncols;
	char *bell;
	char *CM;
	char *CE;
	char *CL;
	char termbuf[128];
};
#ifndef GENPW
struct terminal terminal = {
		25,
		80,
		"\007"
};
#else
struct terminal terminal;
#endif

int delaycnt, mhz;

	int prow, pcol, srow, scol, tabincr, tlrow;
	char clrcol[ROWMAX];

	int prefrow;

	/* spare area - patches */
int spare[10];


int cur_char;			   /* location of the point in the page */
int cur_plen;			   /* length of the current page */
char *cur_cptr;		 /* the actual current character */
char *cpstart;			  /* start of the current page */
char *cgstart, *cgend;	  /* position of the gap in the current page */
char cur_modf;			  /* modified on the current page */
int pim_cnt;			 /* number of pages available in memory */
int savecol, swapf;	     /* memory of current col and swap file desc */
char swapmap[SWAPMAX/8];		/* swap file in use flags */


struct pim {
	char *pdata;			    /* address of page in memory */
	struct pim *nextu, *prevu;      /* LRU chain */
	int lfile, lpage;		       /* logical location of page */
	char pim_modf;			  /* modified? */
	struct page_desc *ldesc;	   /* page description for this page */
	} pages[MAXPAGES], *tpim, *firstu, *lastu;



#define ScrnRange() DoScrnRange(FALSE)
#define IncrDsp()       DoIncrDsp(FALSE)

#define BScrnMrk(indx) (&scrnmarks[indx])
#define Buff()  (*cur_cptr)
#define BIsStart() (cur_page==cur_buff->firstp && cur_char==0)
#define BIsEnd() (cur_page==cur_buff->lastp && cur_char>=cur_plen)

long BLocation(), BLength();
struct pim *get_memp();
struct page_desc *new_page();

#define ToLower(tchar) (isupper(tchar)?tolower(tchar):tchar)
#define ToUpper(tchar) (islower(tchar)?toupper(tchar):tchar)


/* END OF MINCE.GBL - Global variable definitions for Mince. */

char def_mode;
int npages;
int help_page;
