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


 /******  Globals  */

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


 /******  MainRoutiene  */

main(argc,argv)
int argc;
char **argv;
{
char a;

Init();

cursor(0);
prtmd(2,0,JAM2);
prt(27,12,"TEdi V1.0,  coming up...",24);
System.buffer = 0;
System.Fileindex = 2;
switch(argc)
	{
	case 1: InitFile(&(System.Root[0]),"");
		System.Root[0].AnzLines  = 1;
		System.Root[0].first     = AllocMem(sizeof(struct Line),MEMF_PUBLIC);
		System.Root[0].last      = System.Root[0].first;
		System.Root[0].Actl.Line = System.Root[0].first;
		System.Root[0].first->prev = 0;
		System.Root[0].first->next = 0;
		System.Root[0].first->len = 1;
		System.Root[0].first->string = AllocMem(1,MEMF_PUBLIC);
		*(System.Root[0].first->string) = 10;
		System.AnzFiles          = 1;
		System.Mode              = 1;
		System.Active            = 0;
		System.Status            = 1;
		break;

	case 2: prt(27,13,"Loading File, stand by.",23);
		InitFile(&(System.Root[0]),argv[1]);
		LoadFile(&(System.Root[0]));
		System.AnzFiles          = 1;
		System.Mode              = 1;
		System.Active            = 0;
		System.Status            = 1;
		break;

       default: prt(27,13,"Loading Files, stand by.",24);
		InitFile(&(System.Root[0]),argv[1]);
		LoadFile(&(System.Root[0]));
		InitFile(&(System.Root[1]),argv[2]);
		LoadFile(&(System.Root[1]));
		System.AnzFiles          = 2;
		System.Mode              = 0;
		System.Active            = 0;
		System.Status            = 1;
		break;
	}

Wfile = &(System.Root[0]);
Wline = Wfile->first;
Wpos  = 0;
Wlen  = Wline->len;
Wy    = 0;
Wx    = 0;
cpystr(Wline->string,Wlen,Wbuf);
BuildFullDisplay();

do
	{
	Status = 1;
	while((a = get()) == 0);
	if ((int)a == -101)
		{
		switch(CSICheck())
			{
			case 1: AutoScroll(0); Status = 0; break;  /* UP */
			case 2: AutoScroll(1); Status = 0; break;  /* DOWN */
			case 3: Left(); Status = 0;        break;  /* LEFT */
			case 4: Right(); Status = 0;       break;  /* RIGHT */
			case 5: TopofFile(); Status = 0;   break;  /* UP + S */
			case 6: EndofFile(); Status = 0; break;  /* DOWN + S */
			case 7: PageUp(); Status = 0;  break;  /* LEFT + S */
			case 8: PageDown(); Status = 0;   break;  /* RIGHT + S */
			case 9: Help(); Status = 0;        break;  /* HELP */
			}
		}
	if (Status != 0)
		{
		if (((a&127) > 31) && ((a&127) < 127)) Character(a);
		else
			{
			switch(a)
				{
				case   1: CtrlA(); break;        /* BeginLine */
				case   3: CtrlC(); break;        /* Save+Quit */
				case   4: CtrlD(); break;        /* DisplaySize */
				case   5: CtrlE(); break;        /* DelLine */
				case   8: Backspace(); break;    /* BACKSPACE */
				case   9: Character(a); break;   /* TAB */
				case  10: CtrlJ(); break;        /* JUMP */
				case  11: CtrlK(); break;        /* Kill */
				case  12: CtrlL(); break;        /* Load */
				case  13: Return(); break;       /* RETURN */
				case  14: CtrlN(); break;        /* ChangeFName */
				case  15: CtrlO(); break;        /* OpenewWindow */
				case  16: CtrlP(); break;        /* Paste */
				case  17: CtrlQ(); break;        /* QUIT */
				case  18: CtrlR(); break;        /* Replace */
				case  19: CtrlS(); break;        /* Search */
				case  21: CtrlU(); break;        /* Undelete */
				case  23: CtrlW(); break;        /* Save */
				case  24: CtrlX(); break;        /* ChangeWindow */
				case  25: CtrlY(); break;        /* DelEndofLine */
				case  26: CtrlZ(); break;        /* EndofLine */
				case  27: Ctrl27(); break;       /* Mark Begin of Block */
				case  29: Ctrl29(); break;       /* Mark End of Block */
				case 127: Delete(); break;       /* DELETE */
				}
			}
		}
	}
while(Status != 9);

killbuffer();
ReInit();
}


 /******  SubRoutines  */


 /******  EndofTextFile */
