#include <dos.h>
#include <stdio.h>
#include <graphics.h>

/*#include "boywin.h"*/

#define DEFAULT			-1
#define SZ 			1000
#define QB			100
#define Q1			(QB/2)
#define Q2			(QB*3/5)
#define Q3			(QB*2/5)
#define HC			256
#define KK			16000
#define BP			(edit_buf->TWidth/2)
#define HH			(edit_buf->THeight)
#define ZS			(edit_buf->TWidth)
#define H1			(HH-1)
#define H3			(HH-2)
#define CursorColor		BLACK
#define TabSize			8
#define RowSpace		5
#define ColSpace		0  // at this stage, it should be '0' only.
#define FontHeight		16
#define FontWidth		8
#define GRAPHX(x)		RowSpace+(x)*(FontHeight+RowSpace)
#define GRAPHY(y)		ColSpace+(y)*(FontWidth+ColSpace)-vsr((y),edit_buf)*ColSpace
#define TEXTY_M(y)              ((y)-edit_buf->GTop-RowSpace)/(FontHeight+RowSpace)
#define TEXTX_M(x)		((x)-edit_buf->GLeft-ColSpace)/(FontWidth+ColSpace)
#define	EditAreaNumberMax	10

struct EditType{
	int EditAreaHandle;
	int RedrawFlag;
	int Enable;
	int Active;
	int GLeft;
	int GTop;
	int GRight;
	int GBottom;
	int GWidth;
	int GHeight;
	int TWidth;
	int THeight;
	int TextFont;
	int TextColor;
	int BackColor;
	int BlockTextColor;
	int BlockBackColor;
	int InsertStatus;
	char *EditFileName;
	FILE *EditFile;
	int TCurX;
	int TCurY;
	int TOldX;
	int TOldY;
	int index;
	long xx;
	int yy;
	int ss_max;
	int ss_x;
	int m;
	int fp_end;
	int old;
	int blck;
	long ksx;
	int ksy;
	long kwx;
	int kwy;
	long txx;
	long tyy;
	int chg;
	int first;
	int oa;
	int ob;
	long wra[SZ];
	long wrb[SZ];
	long ttl_x;
	long fp_rd;
	long ser;
	long Oser;
	long vw;
	long vv;
	unsigned char *ss[QB];
	char * bfile;
	char * file1;
	char * file2;
	char * ddd;
	char * dd;
	char * hsz;
	char * fnd;
	FILE *fp1;
	FILE *fp2;
	FILE *fp3;
	};
typedef struct EditType EDIT;

////////////////////////////////////////////////////////
//#define LK->mfile	edit_buf.EditFileName             //
//#define LK->fp		edit_buf.EditFile         //
//#define LK->ins		edit_buf.InsertStatus     //
////////////////////////////////////////////////////////


extern int errno;

static char da[]={0x0a,0};

int  CREATE_BOY_EDIT(EDIT *EditArea);
int  BOY_EDIT_TEST(EDIT *EditArea,TEST *Test);
void REDRAW_EDIT(EDIT *edit_buf);

void Warning(char *message);
int far Get_text(TEST *key);

void DisplayEditAreaEnviament(EDIT *edit_buf);
void SaveEnviament(void);
void RestoreEnviament(void);

void bk(EDIT *edit_buf);
void xh(EDIT *edit_buf);
int  read_from(int a,int b,FILE *f,EDIT *edit_buf);
void write_to(int a,int b,FILE *f,EDIT *edit_buf);
void write_prompt(char a,EDIT *edit_buf);
void write_ques(char a,EDIT *edit_buf);
extern int string_lingth(EDIT *edit_buf);
void write_string(int tx,int ty,char *string,EDIT *edit_buf);
void write_string_block(int tx,int ty,char *string,EDIT *edit_buf);
void TextString(int tx,int ty,char *string,int textcolor,int backcolor,int flag,EDIT *edit_buf);
void write_string3(int tx,int ty,char *string,EDIT *edit_buf);
void write_string_block3(int tx,int ty,char *string,EDIT *edit_buf);
void write_char(int tx,int ty,char ch,EDIT *edit_buf);
void DrawCursorXY(int tx,int ty,EDIT *edit_buf);
void ClearCursorXY(int tx,int ty,EDIT *edit_buf);
void ClearCursor(EDIT *edit_buf);
void DrawCursor(EDIT *edit_buf);
void goto_xy(int tx,int ty,EDIT *edit_buf);
void write_space(int tx,int ty,int length,int color,EDIT *edit_buf);
void KEYb_Enter(EDIT *edit_buf);
void KEYb_BkSpace(EDIT *edit_buf);
void KEYb_Del(EDIT *edit_buf);
int  KEYb_delc(EDIT *edit_buf);
int  vs(int a,EDIT *edit_buf);
int  vsr(int a,EDIT *edit_buf);
void orien(EDIT *edit_buf);
void orien2(EDIT *edit_buf);
void KEYb_Ctrl_N(EDIT *edit_buf);
void KEYb_Ctrl_E(int a,EDIT *edit_buf);
void KEYb_Ctrl_Y(int a,EDIT *edit_buf);
void KEYb_Ctrl_T(int a,EDIT *edit_buf);
void KEYb_Ctrl_F(int a,EDIT *edit_buf);
void KEYb_Ctrl_D(EDIT *edit_buf);
void dks(EDIT *edit_buf);
void KEYb_Ctrl_K(EDIT *edit_buf);
void KEYb_Ctrl_V(EDIT *edit_buf);
void write_block(long v,EDIT *edit_buf);
void del_block(EDIT *edit_buf);
int  read_block(EDIT *edit_buf);
int  hb(EDIT *edit_buf);
int  over(int g,EDIT *edit_buf);
void KEYb_Ctrl_W(EDIT *edit_buf);
void KEYb_Ctrl_R(EDIT *edit_buf);
//void KEYb_Esc(EDIT *edit_buf);
void Chr(TEST *Test,EDIT *edit_buf);
void intercept(int ky,EDIT *edit_buf);
void KEYb_PgUp(EDIT *edit_buf);
void KEYb_PgDn(EDIT *edit_buf);
void KEYb_Right(EDIT *edit_buf);
void KEYb_Left(EDIT *edit_buf);
void KEYb_Up(EDIT *edit_buf);
void KEYb_Down(EDIT *edit_buf);
void KEYb_Ins(EDIT *edit_buf);
void KEYb_Home(EDIT *edit_buf);
void KEYb_End(EDIT *edit_buf);
void comp_disp(EDIT *edit_buf);
void comp_disp_m(int a,int b,EDIT *edit_buf);
void comput(EDIT *edit_buf);
void mvto(long a,EDIT *edit_buf);
void KEYb_F1(int a,EDIT *edit_buf);
void KEYb_Shift_F1(EDIT *edit_buf);
void KEYb_F2(long i,EDIT *edit_buf);
void KEYb_F5(EDIT *edit_buf);
void KEYb_Shift_F5(EDIT *edit_buf);
int  Edit_find(char *a,EDIT *edit_buf);
void KEYb_F6(EDIT *edit_buf);
void KEYb_F7(EDIT *edit_buf);
void KEYb_Shift_F7(EDIT *edit_buf);
void KEYb_F8(EDIT *edit_buf);
void KEYb_F7_m(EDIT *edit_buf);
void KEYb_Shift_F7_m(EDIT *edit_buf);
void KEYb_F8_m(EDIT *edit_buf);
void KEYb_F9(EDIT *edit_buf);
void KEYb_Shift_F9(EDIT *edit_buf);
void upto(long a,EDIT *edit_buf);
void dnto(long a,EDIT *edit_buf);
void wfp1(EDIT *edit_buf);
void movbk(int s,int a,EDIT *edit_buf);
void mov(int s,int a,EDIT *edit_buf);
void tj(EDIT *edit_buf);
void ste(EDIT *edit_buf);
void wfp2(EDIT *edit_buf);
void roll_scr_up(int a,int b,EDIT *edit_buf);
void roll_scr_down(int a,int b,EDIT *edit_buf);
void disp(int a,int i,EDIT *edit_buf);
void disp3(int a,int i,EDIT *edit_buf);
void disp_t(EDIT *edit_buf);
void disp_m(int a,int b,EDIT *edit_buf);
int  key_digit(int e,EDIT *edit_buf);
int  key_string(int j,int e,unsigned char a[],int d,EDIT *edit_buf);
int  key_yn(int e);
void double_line(EDIT *edit_buf);
void KEYb_Tab(EDIT *edit_buf);
void GOTO(long x,int y,EDIT *edit_buf);
void EditAreaCloseAll(EDIT *edit_buf);
//int EditChange(EDIT *edit_buf);
