
 /****************************************************************************
 **									    **
 **		-- TEdi --    (c) 21.4.88 by TAA			    **
 **									    **
 sub3************************************************************************/


 /******  Globals  */

extern struct System System;
extern struct File *Wfile;
extern struct Line *Wline;
extern UBYTE Wpos,Wlen;
extern int Wy,Wx,p2flag,Status;
extern char *Wbuf,*bmp,*CSbuf,*CRbuf;


 /******  SubRoutines  */

CtrlQ()
{
struct File *a,*b;

ModLine();
SaveCheck();
a = &System.Root[0];
b = &System.Root[1];
if (System.AnzFiles == 1)
	{
	KillFile(a);
	Status = 9;
	return(0);
	}
KillFile(&(System.Root[System.Active]));
if (System.Active == 0)
	{
	a->first     = b->first;
	a->last      = b->last;
	a->x         = b->x;
	a->y         = b->y;
	a->Mode      = b->Mode;
	a->SFlag     = b->SFlag;
	a->Actl.Line = b->Actl.Line;
	a->Actl.pos  = b->Actl.pos;
	a->ActLine   = b->ActLine;
	a->AnzLines  = b->AnzLines;
	cpystr(b->Fname,32,a->Fname);
	}
System.AnzFiles = 1;
System.Mode     = 1;
System.Active   = 0;
Wx    = a->x;
Wy    = a->y;
Wline = a->Actl.Line;
Wpos  = a->Actl.pos;
Wlen  = Wline->len;
Wfile = a;
cpystr(Wline->string,Wlen,Wbuf);
BuildFullDisplay();
}


CtrlC()
{
ModLine();
Save();
CtrlQ();
}


CtrlW()
{
ModLine();
if (Wfile->SFlag == 1) { DisplayBeep(0); return(0); }
Save();
InfoPrt(System.Active);
PrtLine(Wpos,Wy,Wbuf,Wlen,1);
}


CtrlL()
{
char FN[32];
int i;

ModLine();
SaveCheck();
FN[0] = 0;
i     = Input(FN,"New File:",32);
if ((i == 0) || (FN[0] == 0)) { PrtLine(Wpos,Wy,Wbuf,Wlen,1); return(0); }
KillFile(Wfile);
InitFile(Wfile,FN);
LoadFile(Wfile);
Wx    = Wfile->x;
Wy    = Wfile->y;
Wline = Wfile->Actl.Line;
Wpos  = Wfile->Actl.pos;
Wlen  = Wline->len;
cpystr(Wline->string,Wlen,Wbuf);
BuildFullDisplay();
}


CtrlS()
{
struct Pos yeah;
int i;

ModLine();
i = Input(CSbuf,"Enter Search String:",30);
if ((i == 0)||(CSbuf[0] == 0)) { PrtLine(Wpos,Wy,Wbuf,Wlen,1); return(0); }
yeah.Line = Wline;
yeah.pos  = Wpos+1;
i = stearch(&yeah,CSbuf);
if (i == 0) { PrtLine(Wpos,Wy,Wbuf,Wlen,1); DisplayBeep(0); return(0); }
Wpos  = yeah.pos;
Wline = yeah.Line;
Wy    = 12;
Wlen  = Wline->len;
cpystr(Wline->string,Wlen,Wbuf);
SPage(Wline,Wy);
}


CtrlR()
{
int i,ln,lo,st=0;
struct Pos yeah;
char a;

ModLine();
i = Input(CSbuf,"Enter String to search:",30);
if (i == 0) { PrtLine(Wpos,Wy,Wbuf,Wlen,1); return(0); }
i = Input(CRbuf,"Enter String to replace:",30);
if (i == 0) { PrtLine(Wpos,Wy,Wbuf,Wlen,1); return(0); }
yeah.Line = Wline;
yeah.pos  = Wpos;
lo        = lenstr(CSbuf);
ln        = lenstr(CRbuf);
while ((stearch(&yeah,CSbuf) == 1)&&(st == 0))
	{
	Wline = yeah.Line;
	Wpos  = yeah.pos;
	Wy    = 12;
	Wlen  = Wline->len;
	cpystr(Wline->string,Wlen,Wbuf);
	SPage(yeah.Line,Wy);
	prtmd(3,0,JAM2);
	prt(26,28,"Replace? Y)es, N)o, Q)uit.",26);
	do
		{
		while ((a = get()) == 0);
		switch(a)
			{
			case 'y': cpystr(Wline->string,Wpos,Wbuf);
				cpystr(CRbuf,ln,Wbuf+Wpos);
				cpystr(Wline->string+Wpos+lo,Wline->len-(Wpos+lo),Wbuf+Wpos+ln);
				Wlen = Wline->len-lo+ln;
				ModLine();
				PrtLine(Wpos,Wy,Wbuf,Wlen,1);
				yeah.pos = Wpos+ln;
				Wfile->SFlag = 0;
				break;
			case 'n': yeah.pos++;
				break;
			case 'q': st = 1;
			}
		}
	while((a != 'n')&&(a != 'y')&&(a != 'q'));
	cursor(0);
	prt(26,28," ",1);
	}
if (st == 0) DisplayBeep();
Wline = yeah.Line;
Wlen  = Wline->len;
Wy    = 12;
Wpos  = yeah.pos;
cpystr(Wline->string,Wlen,Wbuf);
SPage(Wline,Wy);
}


 /******  EndofTextFile  */

