TEXT EDITOR 1.0
(C program)

Simple but powerful text editor. Almost all facilities are available.
/* ########################################## # TEXT EDITOR PROGRAM ( for TEF files) # # tested in Turbo C++,version 3.0 # ################15/2/2008################# */ #include<dos.h> #include<dir.h> #include<conio.h> #include<ctype.h> #include<stdio.h> #include<stdlib.h> #include<string.h> #define ROW 21 #define COL 78 #define NOCOLS 999 #define NOLINES 9999 #define MAXFILES 10 #define FRAMEBG BLUE #define FRAMEFG GREEN #define SPACESTOTAB 6 #define CX frm[fI].cX #define CY frm[fI].cY #define SC frm[fI].sC #define SL frm[fI].sL #define SX1 frm[fI].sX1 #define SY1 frm[fI].sY1 #define SX2 frm[fI].sX2 #define SY2 frm[fI].sY2 #define SELECTIONFG BLUE #define SELECTIONBG CYAN #define NOL frm[fI].noOfLines #define MOC frm[fI].maxOfCols #define LINELEN frm[fI].ln[CY].len #define LINEDATA frm[fI].ln[CY].data void Time(); void FExit(); void WPrevious(); void OkDialogBox(char[],char[]); char fR[4][64]; /* findReplace */ int cmdXY[]={6,15,25,35,44,55,65},mx,my,mb; /* mouse x,y and button */ int fI,BG,FG,mouseSelecting, flag,hL; /* highlight, frame Index*/ int NoOfFrame,CMenabl,advice=1,fileNo; /* Clear Menu enabled */ int buffer[20][40][2],bufferX1,bufferX2,bufferY1,bufferY2; struct menuCommands { char cmd[13][16]; int enabl[13], NoOfCmd; }mC[7]= { { { " New ", " Open ", " Save ", " save As ", " Close ", "ÄÄÄÄÄÄÄÄÄÄ", " Exit " }, { 0, 0, 0, 0, 0, -1, 1 }, { 7 } }, { { " cuT ", " Copy ", " Paste ", " cLear " }, { 0, 0, 1 }, { 4 } }, { { " Find ", " Next Ins", " Replace " }, { 0 }, { 3 } }, { { " Upper ", " Lower " }, { 0 }, { 2 } }, { { " Single ", " Double ", " sNgl-Dbl ", " dBl-sngl " }, { 0 }, { 4 } }, { { " next ", " previous ", "ÄÄÄÄÄÄÄÄÄÄ", }, { 0, 0, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 3 } }, { { " Controls ", " About ", " Dedicate " }, { 1, 1, 1 }, { 3 } } }; struct line { char *data; long len; } copyStr; struct frame { struct line *ln; /* all lines */ char fileName[64]; int cX, cY, /* current curser X and Y */ sX1, sX2, sY1, sY2, /* selection parameters */ sL, sC, /* starting line and column on the screen */ SHP, SVP, /* scrolling horizontal and vertical pointer */ noOfLines, maxOfCols, /* max no.of lines and columns */ saved; } frm[MAXFILES]; /******************* Mouse ********************/ void InitMouse() { union REGS r; r.x.ax=0x0, int86(0x33, &r, &r); } void SetMouse(int x, int y) { union REGS r; r.x.ax = 0x4, r.x.cx =x*8, r.x.dx = y*8, int86(0x33, &r, &r); } void ShowMouse() { union REGS r; r.x.ax = 0x1, int86(0x33, &r, &r); } void HideMouse() { union REGS r; r.x.ax =0x2, int86(0x33, &r, &r); } int ReadMouse() { union REGS r; Time(); r.x.ax=0x3, int86(0x33,&r,&r); mx=(int)r.x.cx/8, my=(int)r.x.dx/8, mb=(int)r.x.bx; return mb; } void Color(int fg, int bg) { if(fg!=-1) textcolor(FG=fg); if(bg!=-1) textbackground(BG=bg); } void Put(int x, int y, char str[]) { gotoxy(x,y), HideMouse(), cprintf(str), ShowMouse(); } void Time() { int x,y; static struct time t,tmp={61,61,0,61}; gettime(&t); if(t.ti_sec!=tmp.ti_sec) { x=wherex(), y=wherey(); textcolor(RED), textbackground(GREEN); if(t.ti_sec%2) Put(73,25, ":"); else Put(73,25, " "); if(t.ti_min!=tmp.ti_min) { HideMouse(); gotoxy(74,25),cprintf("%02d",t.ti_min); if(t.ti_hour!=tmp.ti_hour) { gotoxy(71,25); if(t.ti_hour>12) cprintf("%2d",t.ti_hour-12), Put(77,25,"pm"); else cprintf("%2d",(t.ti_hour==0)?12:t.ti_hour), Put(77,25,"am"); } ShowMouse(); } gotoxy(x,y); tmp=t; textcolor(FG), textbackground(BG); } } void HideCurser() { gotoxy(1,1); } int LinLen(int ix) { int i=0; while(frm[fI].ln[ix].data[i]!='\0' && frm[fI].ln[ix].data[i]!='\n') i++; return i; } void PutLine(int ln) { int i; char lnStr[COL+1]; Color(FRAMEFG,FRAMEBG); for(i=SC;i<COL+SC && i<LinLen(ln);i++) lnStr[i-SC]=frm[fI].ln[ln].data[i]; for(;i<COL+SC;i++) lnStr[i-SC]=' '; lnStr[COL]='\0'; gotoxy(2,3+ln-SL); HideMouse(), cprintf("%s",lnStr), ShowMouse(); } void LackOfMemory() { OkDialogBox("ERROR","Memory allocation failed."); stop: FExit(); goto stop; } void InitNewFile() { fI=NoOfFrame++; CX= CY= SX1= SY1= SX2= SY2= SL= SC=0; frm[fI].saved= MOC= NOL=1; frm[fI].ln=(struct line *)malloc(sizeof(struct line)); if(!frm[fI].ln) LackOfMemory(); LINEDATA=(char *)malloc(sizeof(char)); if(!LINEDATA) LackOfMemory(); LINEDATA[0]='\0'; LINELEN=1; } void DrawButton(int x,int y,char str[],int active) { int strLen=strlen(str),i; Color(WHITE,GREEN); HideMouse(); if(active==1) { SetMouse(mx+1,my); Put(x+1,y,str); ShowMouse(); Color(-1,RED); Put(x,y," "); gotoxy(x+1,y+1); for(i=0;i<strLen;i++) cprintf(" "); HideCurser(); while(ReadMouse()); } else { Put(x,y,str); Color(BLACK,RED); Put(x+strLen,y,"Ü"); gotoxy(x+1,y+1); for(i=0;i<strLen;i++) cprintf("ß"); ShowMouse(); HideCurser(); } } void GotoXY() { Color(WHITE,GREEN); gotoxy(4,25); HideMouse(), cprintf("%6d:%-5d",CY+1,CX+1), ShowMouse(); gotoxy(CX-SC+2,CY-SL+3); } void ClearMenu() { int i,j; if(!CMenabl) return; HideMouse(); for(i=bufferY1;i<=bufferY2;i++) for(j=bufferX1;j<=bufferX2;j++) { textattr(buffer[i-bufferY1][j-bufferX1][0]), gotoxy(j,i), cprintf("%c",buffer[i-bufferY1][j-bufferX1][1]); } ShowMouse(); CMenabl=0; HideCurser(); flag|=2; } void DrawCanvas(int x1,int y1,int x2,int y2,char title[]) { int i,j; union REGS r; char *ptr,str[][10]={ {"ÚÄ¿³ÀÙ"}, {"ÉÍ»ºÈ¼"} }; if(CMenabl) ClearMenu(); HideMouse(); for(i=y1;i<=y2+1;i++) { for(j=x1;j<=x2+2;j++) { gotoxy(j,i); r.h.ah=0x8, r.x.bx=0x0, int86(0x10,&r,&r); buffer[i-y1][j-x1][0]=r.h.ah, buffer[i-y1][j-x1][1]=r.h.al; } } bufferX1=x1, bufferX2=x2+2, bufferY1=y1, bufferY2=y2+1; Color(DARKGRAY,BLACK); gotoxy(x1+2,y2+1); for(i=x1;i<=x2;i++) cprintf("%c",buffer[y2+1-y1][i+2-x1][1]); for(i=y1+1;i<=y2;i++) gotoxy(x2+1,i), cprintf("%c%c",buffer[i-y1][x2+1-x1][1], buffer[i-y1][x2+2-x1][1]); Color(WHITE,RED); ptr=(strcmp(title,"")==0) ? str[0] : str[1] ; gotoxy(x1,y1), cprintf("%c",ptr[0]); for(i=x1+1;i<x2;i++) cprintf("%c",ptr[1]); cprintf("%c",ptr[2]); for(j=y1+1;j<y2;j++) { gotoxy(x1,j), cprintf("%c",ptr[3]); for(i=x1+1;i<x2;i++) cprintf(" "); cprintf("%c",ptr[3]); } gotoxy(x1,y2), cprintf("%c",ptr[4]); for(i=x1+1;i<x2;i++) cprintf("%c",ptr[1]); cprintf("%c",ptr[5]); if(strcmp(title,"")!=0) { i=strlen(title); gotoxy((x2+x1-i-1)/2,y1); cprintf(" %s ",title); } ShowMouse(); CMenabl=1; } void PutVScroll() { int i; Color(MAGENTA,BLUE); for(i=4;i<=77;i++) Put(i,24,"±"); Color(WHITE,BLACK), Put(4+frm[fI].SVP,24,"."); } void PutHScroll() { int i; Color(MAGENTA,BLUE); for(i=4;i<=22;i++) Put(80,i,"±"); Color(WHITE,BLACK), Put(80,4+frm[fI].SHP,"."); } int ShiftKeyHit() { union REGS r; r.h.ah=0x2, int86(0x16,&r,&r); if(r.h.al&2) return 1; else return 0; } void SetCurser(int X,int Y) { int tmp, x=CX, y=CY; CY+=Y; if(CY<0) CY=0; else if(CY>=NOL) CY=NOL-1; CX+=X; if(CX<0) CX=0; else if(CX>LinLen(CY)) CX=LinLen(CY); if(SC>CX || CX-SC>=COL) { if(SC==CX+1) SC=CX; else if(SC+COL==CX) SC++ ; else if( !(SC<=CX && SC+COL>=CX)) SC=(CX/COL)*COL; flag|=16; } if(MOC>1 && frm[fI].SVP!=(int)(73.*SC/(MOC-1))) frm[fI].SVP=73.*SC/(MOC-1), flag|=64; if(SL>CY||CY-SL>=ROW) { if(SL==CY+1||SL==CY+2) SL=CY; else if( SL+ROW==CY) SL++; else if( SL+ROW+1==CY) SL+=2; else if(!(SL<=CY&&SL+ROW>=CY)) SL=(CY/ROW)*ROW; flag|=16; } if(NOL>1&&frm[fI].SHP!=(int)18.*SL/(NOL-1)) frm[fI].SHP=18.*SL/(NOL-1), flag|=32; if(ShiftKeyHit() || mouseSelecting) { if(x==SX2&&y==SY2) { if(y==CY&&x>CX||y>CY) flag|=16; else flag|=8; SX2=CX, SY2=CY; } else if(x==SX1&&y==SY1) { if(y==CY&&x<CX||y<CY) flag|=16; else flag|=8; SX1=CX, SY1=CY; } else { flag|=16; SX1=x, SX2=CX, SY1=y, SY2=CY; } if( SY1>SY2 || SY1==SY2&&SX1>SX2 ) { tmp=SX1, SX1=SX2, SX2=tmp; tmp=SY1, SY1=SY2, SY2=tmp; } } flag|=2; } void PutSelection() { int i,j,ln; char lnStr[COL+1]; HideMouse(); Color(SELECTIONFG,-1); for(ln=(SL>SY1)?SL:SY1+1; ln<SY2 && ln<SL+ROW ;ln++) { Color(-1,SELECTIONBG); for(i=SC; i<COL+SC && i<LinLen(ln) ;i++) lnStr[i-SC]=frm[fI].ln[ln].data[i]; lnStr[i-SC]='\0'; gotoxy(2,3+ln-SL), cprintf("%s",lnStr); for(j=i; j<COL+SC ;j++) lnStr[j-i]=' '; lnStr[j-i]='\0'; Color(-1,FRAMEBG), cprintf("%s",lnStr); } Color(-1,SELECTIONBG); if(SL<=SY1&&SY1<SL+ROW) { j=(SX1>SC)?SX1:SC; for(i=j; ((SY1==SY2)?i<SX2:1) && i<LinLen(SY1) && i<SC+COL ;i++) lnStr[i-j]=frm[fI].ln[SY1].data[i]; lnStr[i-j]='\0'; if( SC<=SX1 && SX1<SC+COL ) gotoxy(SX1+2-SC,SY1+3-SL); else gotoxy(2,SY1+3-SL); cprintf("%s",lnStr); } if(SL<=SY2&&SY2<SL+ROW&&SY1!=SY2) { for(i=SC;i<LinLen(SY2)&&i<SC+COL&&i<SX2;i++) lnStr[i-SC]=frm[fI].ln[SY2].data[i]; lnStr[i-SC]='\0'; gotoxy(2,SY2+3-SL), cprintf("%s",lnStr); } ShowMouse(); } void PutData() { int i,j; char lnstr[COL+1]; for(i=SL; i<NOL && i<SL+ROW ;i++) if(i<=SY1||SY2<=i) PutLine(i); for(j=0;j<COL;j++) lnstr[j]=' '; lnstr[j]='\0'; HideMouse(); for(;i<SL+ROW;i++) gotoxy(2,i+3-SL), cprintf("%s",lnstr); ShowMouse(); PutSelection(); } void Scroll() { int i,SOx=CX,SOy=CY; while(1) { if( mx==79 && NOL>1 ) { if( my==2 && SL!=0 ) { SL--; if(frm[fI].SHP!=(int)18.*SL/(NOL-1)) frm[fI].SHP= 18.*SL/(NOL-1); } else if( my==22 && SL!=NOL-1 ) { SL++; if(frm[fI].SHP!=(int)18.*SL/(NOL-1)) frm[fI].SHP= 18.*SL/(NOL-1); } else if( 2<my&&my<22 ) SL= (NOL-1)*(my-3)/18., frm[fI].SHP= (my-3); else break; PutHScroll(), PutData(); } else if( my==23 && MOC>1 ) { if( mx==2 && SC!=0 ) { SC--; if(frm[fI].SVP!=(int)73.*SC/(MOC-1)) frm[fI].SVP= 73.*SC/(MOC-1); } else if( mx==77 && MOC>SC ) { SC++; if(frm[fI].SVP!=(int)73.*SC/(MOC-1)) frm[fI].SVP= 73.*SC/(MOC-1); } else if( 2<mx&&mx<77 ) SC= (mx-3)/73.*(MOC-1), frm[fI].SVP= (mx-3); else break; PutVScroll(), PutData(); } else break; if( SC<=CX && SC+COL>CX && SL<=CY && SL+ROW>CY ) GotoXY(); else HideCurser(); delay(99); while(1) { if(ReadMouse()) { if(mb==1) break; else { CX=SOx,CY=SOy, flag|=32|64; SetCurser(0,0); return; } } if(kbhit()) { CX=SOx,CY=SOy, flag|=32|64; SetCurser(0,0); return; } } } } void DisplayData() { if(flag&16) PutData(); if(flag&32) PutHScroll(); if(flag&64) PutVScroll(); if(flag&4) PutLine(CY); if(flag&8) PutSelection(); GotoXY(); flag=0; } void SetFrame() { int i,len; if(NoOfFrame==0) { Color(BLACK,LIGHTGRAY); gotoxy(1,2); HideMouse(); for(i=0;i<80*23;i++) cputs("°"); Color(GREEN,GREEN); Put(6,25," "); ShowMouse(); HideCurser(); } else { Color(WHITE,BLUE); HideMouse(); for(i=3;i<=23;i++) Put(1,i,"º"); Put(1,2,"ÉÍ[X]"); len=strlen(frm[fI].fileName); for(i=6;i<(40-len/2-1);i++) cprintf("Í"); cprintf(" %s ",frm[fI].fileName); for(i+=len+2;i<=79;i++) cprintf("Í"); cprintf("»"); Put(1,24,"ÈÍ"); Put(79,24,"ͼ"); Color(BLUE,MAGENTA); gotoxy(3,24), cprintf("."); for(i=4;i<=77;i++) cprintf("±"); cprintf("%c",26); gotoxy(80,3), cprintf("."); for(i=4;i<=22;i++) gotoxy(80,i), cprintf("±"); gotoxy(80,23), cprintf("."); ShowMouse(); flag|=64|32|16; SetCurser(0,0); DisplayData(); } CMenabl=0; } void HGetOk(int bY) { char ch; DrawButton(37,bY," Ok ",0); HideCurser(); while(1) { if(kbhit()) { ch=getch(); if(ch==27||ch=='\r'||ch=='o'||ch=='O') return; } if(ReadMouse()==1) { if( my==bY-1 && 35<mx&&mx<44 ) { DrawButton(37,bY," Ok ",1); if( my==bY-1 && 36<mx&&mx<45 ) return; DrawButton(37,bY," Ok ",0); } } } } void OkDialogBox(char title[],char msg[]) { DrawCanvas(39-strlen(msg)/2,10,43+strlen(msg)/2,16,title); Put(41-strlen(msg)/2,12,msg); HGetOk(14); ClearMenu(); } void AddChar(char ch) { int i,j,k,l; if( LINELEN+(CY+1==NOL)>NOCOLS && ch!='\r' ) { OkDialogBox("ERROR","Line,too long,truncted"); if(CX<NOCOLS/2) AddChar('\r'), CY--, CX=LinLen(CY); else AddChar('\r'); AddChar(ch); return; } LINELEN+=1; if(SX1||SX2||SY2||SY1) SX1= SY1= SX2= SY2=0, flag|=16; if(LINELEN>MOC) MOC=LINELEN; LINEDATA=(char *)realloc(LINEDATA,sizeof(char)*LINELEN); if(!LINEDATA) LackOfMemory(); for(i=strlen(LINEDATA);i>=CX;i--) LINEDATA[i+1]=LINEDATA[i]; if(ch=='\r') LINEDATA[i+1]='\n', flag|=16; else LINEDATA[i+1]=ch, flag|=4; CX++; if(ch=='\r') { NOL+=1; if(NOL>=NOLINES) LackOfMemory(); frm[fI].ln=(struct line*)realloc(frm[fI].ln,NOL*sizeof(struct line)); if(!frm[fI].ln) LackOfMemory(); CY++; for(i=NOL-1;i>CY;i--) frm[fI].ln[i]=frm[fI].ln[i-1]; LINEDATA=(char *)malloc(sizeof(char)); if(!LINEDATA) LackOfMemory(); LINEDATA[0]='\0', LINELEN=1; l=k=CX; CX=0; for(;frm[fI].ln[CY-1].data[k]!='\0';k++) AddChar(frm[fI].ln[CY-1].data[k]); CX=0; frm[fI].ln[CY-1].data[l]='\0'; frm[fI].ln[CY-1].len=l+1; frm[fI].ln[CY-1].data=(char *)realloc(frm[fI].ln[CY-1].data,l+1); for(MOC=1,i=0;i<NOL;i++) if(frm[fI].ln[i].len>MOC) MOC=LinLen(i); } frm[fI].saved=0; SetCurser(0,0); } void DelChar() { int i,tmp; if( CY==NOL-1 && LINEDATA[CX]=='\0' ) return; if(LINEDATA[CX]=='\n'&&LINELEN+frm[fI].ln[CY+1].len+(CY==NOL-2)>NOCOLS+3) { OkDialogBox("ERROR","The line is too long"); return; } if(SX1||SX2||SY2||SY1) SX1= SY1= SX2= SY2=0, flag|=16; if(LINEDATA[CX]=='\n') { tmp=CX; for(i=0; i<LinLen(CY+1);i++) AddChar(frm[fI].ln[CY+1].data[i]); free(frm[fI].ln[CY+1].data); for(i=CY+2;i<NOL;i++) frm[fI].ln[i-1]=frm[fI].ln[i]; NOL--; frm[fI].ln=(struct line*)realloc(frm[fI].ln,NOL*sizeof(struct line)); if(!frm[fI].ln) LackOfMemory(); CX=tmp; flag|=16; } else { for(i=CX;i<strlen(LINEDATA);i++) LINEDATA[i]=LINEDATA[i+1]; LINELEN-=1; LINEDATA=(char *)realloc(LINEDATA,LINELEN*sizeof(char)); if(!LINEDATA) LackOfMemory(); flag|=4; } if(LINELEN+1==MOC) { MOC=LINELEN; for(i=0;i<NOL;i++) if(frm[fI].ln[i].len>MOC) { MOC++; break; } } SetCurser(0,0); } void AddBksp() { if(CY==0&&CX==0) return; if(CX==0&&LINELEN+frm[fI].ln[CY-1].len+(CY==NOL-1)>NOCOLS+3) { OkDialogBox("ERROR","The line is too long"); return; } if(CX==0) CY--, CX=LinLen(CY); else CX--; DelChar(); } int get(int ix) /* index */ { int i; char ch; int lcx[]={0,0,0,0}, lsc[]={0,0,0,0}; /* last curser x, y. */ int lcy[]={12,10,12,12}, lmy[]={13,13,13,13}; /* last mouse x, y. */ DrawButton(32,lmy[ix]+1," Ok ",0); DrawButton(42,lmy[ix]+1," Cancel ",0); gotoxy(37+lcx[ix],lcy[ix]); while(1) { if(kbhit()) { ch=getch(); if( ch==0 ) { ch=getch(); switch(ch) { case 83: if(lcx[ix]!=strlen(fR[ix])) for(i=lcx[ix];i<strlen(fR[ix]);i++) fR[ix][i]=fR[ix][i+1]; break; case 77: if(lcx[ix]!=strlen(fR[ix])) lcx[ix]++; break; case 75: if(lcx[ix]!=0) lcx[ix]--; break; case 71: lcx[ix]=0; break; case 79: lcx[ix]=strlen(fR[ix]); break; } } else if(ch==27) return 0; else if(ch=='\t') { if( ix==1 ) ix=2; else if( ix==2 ) ix=1; } else if(ch=='\r') { if(ix!=1&&ix!=2&&fR[ix][0]!=0) return 1; else if( ix==1 || ix==2 ) { if(fR[1][0]!=0) return 1; else ix=1; } } else if( ch==8 && lcx[ix]!=0 ) { for(i=--lcx[ix];i<strlen(fR[ix]);i++) fR[ix][i]=fR[ix][i+1]; } else if(strlen(fR[ix])<59&& ' '<=ch&&ch<='~' ) { for(i=strlen(fR[ix]);i>=lcx[ix];i--) fR[ix][i+1]=fR[ix][i]; fR[ix][lcx[ix]++]=ch; } Color(WHITE,BLUE); gotoxy(37,lcy[ix]); if(lcx[ix]-lsc[ix]>15||lcx[ix]<lsc[ix]) lsc[ix]=(lcx[ix]/15-1)*15+lcx[ix]%15; if(lsc[ix]<0) lsc[ix]=0; HideMouse(); for(i=lsc[ix];fR[ix][i]!='\0'&&i<lsc[ix]+16;i++) cprintf("%c",fR[ix][i]); for(;i<lsc[ix]+16;i++) cprintf(" "); ShowMouse(); gotoxy(37+lcx[ix]-lsc[ix],lcy[ix]); } if(ReadMouse()==1) { if( my==lmy[ix] && 30<mx&&mx<39 ) { DrawButton(32,lmy[ix]+1," Ok ",1); if( my==lmy[ix] && 31<mx&&mx<40 ) { if((ix==0||ix==3)&&fR[ix][0]!=0) return 1; else if(ix==1||ix==2) { if(fR[1][0]!=0) return 1; else ix=1; } } DrawButton(32,lmy[ix]+1," Ok ",0); gotoxy(37+lcx[ix]-lsc[ix],lcy[ix]); } else if(my==lmy[ix]&&mx>40&&mx<49) { DrawButton(42,lmy[ix]+1," Cancel ",1); if(my==lmy[ix]&&mx>41&&mx<50) return 0; DrawButton(42,lmy[ix]+1," Cancel ",0); gotoxy(37+lcx[ix]-lsc[ix],lcy[ix]); } } } } /******************* File *******************/ void FNew() { ClearMenu(); InitNewFile(); sprintf(frm[fI].fileName,"File:%02d",fileNo++); SetFrame(); } void FileName(char *file,char *path) { fnsplit(path,NULL,NULL,file,NULL); file[8]='\0'; } void FOpen(char *file) { char ch; FILE *fp; int i,validFile=1,lines=1,cols=1; if(!strcmp(file,"")) { strcpy(fR[3],""); DrawCanvas(26,10,55,16,"Open"); Color(WHITE,RED); Put(29,12,"File"); Color(-1,BLUE); Put(37,12," "); if(get(3)==0) { ClearMenu(); return; } ClearMenu(); strcat(fR[3],".tef"); } else strcpy(fR[3],file); fp=fopen(fR[3],"r"); if(!fp) { OkDialogBox("ERROR","File Could not be opened"); return; } while(validFile) { ch=fgetc(fp); if(ch==EOF) break; if(ch=='\n') { lines++; if(lines>NOLINES) validFile=0; else cols=1; } else if( ' '<=ch&&ch<='~' || '³'<=ch&&ch<='Ú' ) { if(cols>NOCOLS) validFile=0; else cols++; } else validFile=0; } if(!validFile) { fclose(fp); OkDialogBox("ERROR","Invalid *.tef file"); return; } rewind(fp); InitNewFile(); strcpy(frm[fI].fileName,fR[3]); while(1) { ch=fgetc(fp); frm[fI].saved=1; if(ch==EOF) break; else if(ch=='\n') AddChar('\r'); else AddChar(ch); } fclose(fp); frm[fI].saved=1; SetCurser(-CX,-CY); SetFrame(); } int FSave(int as) { char ch; int i,j; FILE *fp; ClearMenu(); if(as==1) { strcpy(fR[3],""); DrawCanvas(26,10,55,16,"Save As"); Color(WHITE,RED); Put(29,12,"File"); Color(-1,BLUE); Put(37,12," "); if(get(3)==0) { ClearMenu(); return 0; } ClearMenu(); strcat(fR[3],".tef"); fp=fopen(fR[3],"r"); if(fp) { fclose(fp); DrawCanvas(26,10,55,16,"ERROR"); Put(29,12,"Overwrite the file ?"); DrawButton(32,14," Ok ",0); DrawButton(42,14," Cancel ",0); HideCurser(); while(1) { if(kbhit()) { ch=getch(); if(ch==27) { ClearMenu(); return 0; } else if(ch=='\r') break; } if(ReadMouse()==1 && my==13) { if( 30<mx&&mx<39 ) { DrawButton(32,14," Ok ",1); if( my==13 && 31<mx&&mx<40 ) break; DrawButton(32,14," Ok ",0); } else if( 40<mx&&mx<49 ) { DrawButton(42,14," Cancel ",1); if( my==13 && mx>41&&mx<50 ) { ClearMenu(); return 0; } DrawButton(42,14," Cancel ",0); } } } ClearMenu(); } fclose(fp); strcpy(frm[fI].fileName,fR[3]); } fp=fopen(frm[fI].fileName,"w"); if(!fp) { OkDialogBox("ERROR","Saving Failed"); return 0; } for(i=0;i<NOL;i++) for(j=0;j<strlen(frm[fI].ln[i].data);j++) fputc(frm[fI].ln[i].data[j],fp); fclose(fp); frm[fI].saved=1; SetFrame(); return 1; } int FClose() { int i; char tmpfn[MAXFILE],ch; ClearMenu(); if(!frm[fI].saved) { DrawCanvas(24,10,57,16,"Save"); Color(WHITE,RED); FileName(tmpfn,frm[fI].fileName); gotoxy(28,12), cprintf("%s not saved. save ?",tmpfn); DrawButton(27,14," Yes ",0); DrawButton(37,14," No ",0); DrawButton(47,14," Cancel ",0); while(1) { if(kbhit()) { ch=getch(); if( ch=='\r' || ch=='y'||ch=='Y' ) { if(strncmp(frm[fI].fileName,"File:",5)==0) { if(FSave(1)==0) return 0; } else FSave(0); break; } else if(ch=='n'||ch=='N') break; else if( ch==27 || ch=='c'||ch=='C' ) { ClearMenu(); return 0; } } if(ReadMouse()==1&&my==13) { if(25<mx&&mx<34) { DrawButton(27,14," Yes ",1); if( my==13 && 26<mx&&mx<35 ) { if(strncmp(frm[fI].fileName,"File:",5)==0) { if(FSave(1)==0) return 0; } else FSave(0); break; } DrawButton(27,14," Yes ",0); } else if(35<mx&&mx<44) { DrawButton(37,14," No ",1); if( my==13 && 36<mx&&mx<45 ) break; DrawButton(37,14," No ",0); } else if(45<mx&&mx<54) { DrawButton(47,14," Cancel ",1); if( my==13 && 46<mx&&mx<54 ) { ClearMenu(); return 0; } DrawButton(47,14," Cancel ",0); } } } } ClearMenu(); for(i=0;i<NOL;i++) free(frm[fI].ln[i].data); free(frm[fI].ln), NoOfFrame--; for(i=fI;i<NoOfFrame;i++) frm[i]=frm[i+1]; fI--; SetFrame(); return 1; } void FExit() { int i; ClearMenu(); while(NoOfFrame) if(!FClose()) return; free(copyStr.data); exit(0); } /******************** Edit ********************/ void ECopy() { int i,j,k=0; if(SX1==SX2&&SY1==SY2) return; copyStr.len=1; copyStr.data=(char*)realloc(copyStr.data,copyStr.len); if(!copyStr.data) LackOfMemory(); for(i=SY1;i<=SY2;i++) { for(j=0;frm[fI].ln[i].data[j]!='\0';j++) { if(i==SY1&&j==0) j=SX1; if(i==SY2&&j==SX2) break; copyStr.data[k++]=(frm[fI].ln[i].data[j]=='\n')?'\r':frm[fI].ln[i].data[j]; copyStr.data=(char*)realloc(copyStr.data,++copyStr.len); if(!copyStr.data) LackOfMemory(); } } copyStr.data[k]='\0'; } void EClear() { int i,j,l; int sX1=SX1, sY1=SY1, sX2=SX2, sY2=SY2; if( SX1==SX2 && SY1==SY2 ) return; CY=sY1, CX=sX1;; if(sY1==sY2) { for(i=sX1;i<sX2;i++) DelChar(); } else { while(LINEDATA[sX1]!='\n') DelChar(); for(i=sY1+1;i<sY2;i++) { CY++; for(CX=0;LINEDATA[0]!='\n';) DelChar(); } CY++; for(i=0;i<sX2;i++) DelChar(); CY=sY1, CX=LinLen(CY); for(i=sY1;i<sY2;i++) DelChar(); } } void ECut() { ECopy(); EClear(); } void EPaste() { int i; for(i=0;copyStr.data[i]!='\0';i++) AddChar(copyStr.data[i]); } /******************** Search ********************/ int SFindALG(char find[],int sx,int sy) { int i,j,k; for(i=sy;i<NOL;i++) { for(j=0;frm[fI].ln[i].data[j]!='\0';j++) { if(i==sy&&j==0) j=sx; if(tolower(frm[fI].ln[i].data[j])==tolower(find[0])&&(j==0||!isalpha(frm[fI].ln[i].data[j-1]))) { for(k=1;find[k]!='\0';k++) if(tolower(frm[fI].ln[i].data[j+k])!=tolower(find[k])) break; if(find[k]=='\0'&&!isalpha(frm[fI].ln[i].data[j+k])) { SX1=j, SX2=j+k, SY1=SY2=i; return 1; } } } } return 0; } void SFind() { strcpy(fR[0],""); DrawCanvas(26,10,55,16,"Find"); Color(WHITE,RED); Put(29,12,"Word"); Color(-1,BLUE); Put(37,12," "); if(get(0)==0) { ClearMenu(); return; } ClearMenu(); if(SFindALG(fR[0],0,0)) { SetCurser(SX2-CX,SY2-CY); flag|=16; } else OkDialogBox("Not Found","The word not found"); } void SNext() { ClearMenu(); if(!strcmp(fR[0],"")) return; if(SFindALG(fR[0],CX,CY)) { SetCurser(SX2-CX,SY2-CY); flag|=16; } else OkDialogBox("Not Found","The word not found"); } void SReplace() { char *tmp; DrawCanvas(26,8,55,17,"Replace"); strcpy(fR[1],""), strcpy(fR[2],""); Color(WHITE,RED); Put(29,10,"Word :"), Put(29,12,"Replace:"); Color(-1,BLUE); Put(37,10," "), Put(37,12," "); Color(BLACK,RED); Put(29,16," [Tab to change fields.]"); if(get(1)==0) { ClearMenu(); return; } ClearMenu(); tmp=(char*)malloc(sizeof(char)*copyStr.len); strcpy(tmp,copyStr.data), strcpy(copyStr.data,fR[2]); if(SFindALG(fR[1],0,0)) { while(1) { EClear(), EPaste(); if(!SFindALG(fR[1],SX2,SY2)) break; } } else OkDialogBox("Not Found","The word not found"); strcpy(copyStr.data,tmp), free(tmp); } /******************** Case ********************/ void CUpperLower(int upper) { int i,j; for(i=SY1;i<=SY2;i++) { if(i==SY1) j=SX1; else j=0; for(;j<LinLen(i);j++) { if(i==SY2&&j==SX2) break; frm[fI].ln[i].data[j]=(upper)?toupper(frm[fI].ln[i].data[j]):tolower(frm[fI].ln[i].data[j]); } } frm[fI].saved=0; flag|=8; } /******************* Table *******************/ void TSDW(int index) { char ch; int i,j,hL=10; char *title[]={"Single", "Double", "SnglDbl", "DblSngl"}; char *icon[]={"Ú¿ÃÅ´ÀÁÙ³Ä","ÉË»ÌιÈʼºÍ","ÖÒ·Ç׶ÓнºÄ","ÕѸÆصÔϾ³Í"}; DrawCanvas(28,7,52,19,title[index]); DrawButton(31,17," Ok ",0), DrawButton(42,17," Cancel ",0); Color(WHITE,BLUE); HideMouse(); for(i=0;i<=2;i++) { gotoxy(33,10+i*2); for(j=0;j<=14;j++) cprintf(" "); } for(i=0;i<11;i++) gotoxy(33+i%3*5,9+i/3*2), cprintf(" %c ",icon[index][i]); Color(-1,MAGENTA); gotoxy(34+hL%3*5,9+hL/3*2), cprintf(" %c ",icon[index][hL]); ShowMouse(); HideCurser(); while(1) { if(kbhit()) { ch=getch(); if(ch==0) { ch=getch(); Color(-1,BLUE); HideMouse(); gotoxy(34+hL%3*5,9+hL/3*2), cprintf(" %c ",icon[index][hL]); switch(ch) { case 72: if( hL/3!=0 ) hL-=3; break; case 75: if( hL%3!=0 ) hL-=1; break; case 77: if( hL%3!=2 && hL!=10 ) hL+=1; break; case 80: if( hL/3!=3 && hL!=8 ) hL+=3; break; } Color(-1,MAGENTA); gotoxy( 34+hL%3*5, 9+hL/3*2 ), cprintf(" %c ",icon[index][hL]); ShowMouse(); HideCurser(); } else if( ch=='\r' || ch=='o'|| ch=='O' ) { AddChar(icon[index][hL]); goto end; } else if( ch==27 || ch=='c' || ch=='C' ) goto end; } if(ReadMouse()==1) { if( 7<my&&my<15 && 32<mx&&mx<46 ) { if( ( my!=14 || mx<43 ) && (mx-33)%5<3 && (my-8)%2<1 ) { Color(-1,BLUE); gotoxy(34+hL%3*5,9+hL/3*2); HideMouse(); cprintf(" %c ",icon[index][hL]); hL=(my-8)/2*3+(mx-33)/5; Color(-1,GREEN); gotoxy(34+hL%3*5,9+hL/3*2), cprintf(" %c ",icon[index][hL]); ShowMouse(); HideCurser(); while(ReadMouse()); if( 7<my&&my<15 && 32<mx&&mx<46 && (my!=14||mx<43) ) if( (mx-33)%5<3 && (my-8)%2<1 && hL==(my-8)/2*3+(mx-33)/5 ) { AddChar(icon[index][hL]); goto end; } Color(WHITE,MAGENTA), gotoxy( 34+hL%3*5, 9+hL/3*2 ); HideMouse(), cprintf(" %c ",icon[index][hL]), ShowMouse(); HideCurser(); } } else if(my==16) { if(29<mx&&mx<38) { DrawButton(31,17," Ok ",1); if( my==16 && 30<mx&&mx<37 ) { AddChar(icon[index][hL]); goto end; } DrawButton(31,17," Ok ",0); } else if(40<mx&&mx<49) { DrawButton(42,17," Cancel ",1); if( my==16 && 41<mx&&mx<50 ) goto end; DrawButton(42,17," Cancel ",0); } } } } end: ClearMenu(); } /******************* Window *******************/ void WListAll(int frmIndex) { int i; struct frame tmp=frm[frmIndex]; ClearMenu(); for(i=frmIndex;i<NoOfFrame-1;i++) frm[i]=frm[i+1]; for(;i>fI+1;i--) frm[i]=frm[i-1]; frm[i]=tmp; fI=i; SetFrame(); } /******************* Help *******************/ void HAbout() { DrawCanvas(28,8,53,18,"About"); Color(WHITE,RED); Put(34,10," Text Editor"); Put(34,11," vertion 1.0"); Put(34,12," By"); Put(34,13,"Habeeb Perwad,"); Put(34,14," MCA student."); HGetOk(16); } void HControls() { DrawCanvas(25,4,56,21,"Controls"); Color(YELLOW,RED); Put(27, 6,"EDIT KEYS"); Put(27,12,"CURSER KEYS"); Put(27,15,"SELECTION METHODS"); Color(WHITE,-1); Put(29, 7,"Shift+Del [Cut]"); Put(29, 8,"Ctrl+Ins [Copy]"); Put(29, 9,"Shift+Ins [Paste]"); Put(29,10,"Ctrl+Del [Clear]"); Put(29,11,"Bksp,Del,Tab,Enter."); Put(29,13,"Arrow keys,Home,End,PgUp,"); Put(29,14,"PgDn,Ctrl+PgUp,ctrl+PgDn."); Put(29,16,"Shift+curser keys,"); Put(29,17,"Ctrl+mouse click,dragging."); HGetOk(19); } void HDedication() { DrawCanvas(26,9,55,18,"Dedicate To"); Color(WHITE,RED); Put(27,11," RAJKUMAR sir."); Put(27,12," ^^^^^^^^^^^^^"); Put(29,13,"He helps me to understand"); Put(29,14,"the power of C."); HGetOk(16); } void DrawCmd(int pos) { int i; for(i=0;i<mC[pos].NoOfCmd;i++) { if(!mC[pos].enabl[i]) Color(BLACK,RED); else if(i==hL) Color(WHITE,GREEN); else Color(WHITE,RED); Put(cmdXY[pos],3+i,mC[pos].cmd[i]); } HideCurser(); while(ReadMouse()); } void HighlightCmd(int pos) { int i; char ch; ch=getch(); if(hL==-1) return; Color(WHITE,RED), Put(cmdXY[pos],3+hL,mC[pos].cmd[hL]); if(ch==72) { for(i=hL-1;i>=0;i--) if(mC[pos].enabl[i]==1) { hL=i; break; } } else if(ch==80) { for(i=hL+1;i<mC[pos].NoOfCmd;i++) if(mC[pos].enabl[i]==1) { hL=i; break; } } Color(-1,GREEN), Put(cmdXY[pos],3+hL,mC[pos].cmd[hL]); HideCurser(); } /******************** Menu ********************/ void File() { char ch; DrawCanvas(4,2,17,10,""); hL=6; if(NoOfFrame==0) mC[0].enabl[3]= mC[0].enabl[4]=0; else mC[0].enabl[3]=mC[0].enabl[4]=1, hL=3; if( NoOfFrame && strncmp(frm[fI].fileName,"File:",5) && frm[fI].saved==0 ) mC[0].enabl[2]=1, hL=2; else mC[0].enabl[2]=0; if(NoOfFrame==MAXFILES) mC[0].enabl[0]= mC[0].enabl[1]=0; else mC[0].enabl[0]= mC[0].enabl[1]=1, hL=0; DrawCmd(0); while(1) { if(kbhit()) { if((ch=getch())==27) goto end; else if(ch=='\r') { switch(hL) { case 0: FNew(); goto end; case 1: FOpen(""); goto end; case 2: FSave(0); goto end; case 3: FSave(1); goto end; case 4: FClose(); goto end; case 6: FExit(); goto end; } } else if(ch==0) HighlightCmd(0); else { switch(ch) { case 'n': case 'N': if(mC[0].enabl[0]) FNew(); goto end; case 'o': case 'O': if(mC[0].enabl[1]) FOpen(""); goto end; case 's': case 'S': if(mC[0].enabl[2]) FSave(0); goto end; case 'a': case 'A': if(mC[0].enabl[3]) FSave(1); goto end; case 'c': case 'C': if(mC[0].enabl[4]) FClose(); goto end; case 'e': case 'E': if(mC[0].enabl[6]) FExit(); goto end; default : goto end; } } } if(ReadMouse()==1) { if( 2<mx&&mx<17 && 0<my&&my<10 ) while(ReadMouse()); if( 4<mx&&mx<15 ) { switch(my) { case 2 : if(mC[0].enabl[0]) FNew(); goto end; case 3 : if(mC[0].enabl[1]) FOpen(""); goto end; case 4 : if(mC[0].enabl[2]) FSave(0); goto end; case 5 : if(mC[0].enabl[3]) FSave(1); goto end; case 6 : if(mC[0].enabl[4]) FClose(); goto end; case 8 : if(mC[0].enabl[6]) FExit(); goto end; default: goto end; } } else goto end; } if(mb==2) goto end; } end: ClearMenu(); } void Edit() { char ch; DrawCanvas(13,2,26,7,""); hL=-1; if(NoOfFrame==0) mC[1].enabl[2]=0; else mC[1].enabl[2]=1, hL=2; if( NoOfFrame==0 || SX1==SX2&&SY1==SY2 ) mC[1].enabl[0]= mC[1].enabl[1]= mC[1].enabl[3]=0; else mC[1].enabl[0]= mC[1].enabl[1]= mC[1].enabl[3]=1, hL=0; DrawCmd(1); while(1) { if(kbhit()) { if((ch=getch())==27) goto end; else if(ch==0) HighlightCmd(1); else if(ch=='\r') { switch(hL) { case 0 : ECut(); goto end; case 1 : ECopy(); goto end; case 2 : EPaste(); goto end; case 3 : EClear(); goto end; default: goto end; } } else { switch(ch) { case 't': case 'T': if(mC[1].enabl[0]) ECut(); goto end; case 'c': case 'C': if(mC[1].enabl[1]) ECopy(); goto end; case 'p': case 'P': if(mC[1].enabl[2]) EPaste(); goto end; case 'l': case 'L': if(mC[1].enabl[3]) EClear(); goto end; default : goto end; } } } if(ReadMouse()==1) { if( 11<mx&&mx<26 && 0<my&&my<7 ) while(ReadMouse()); if( 13<mx&&mx<24 ) { switch(my) { case 2 : if(mC[1].enabl[0]) ECut(); goto end; case 3 : if(mC[1].enabl[1]) ECopy(); goto end; case 4 : if(mC[1].enabl[2]) EPaste(); goto end; case 5 : if(mC[1].enabl[3]) EClear(); goto end; default: goto end; } } else goto end; } if(mb==2) goto end; } end: ClearMenu(); } void Search() { char ch; DrawCanvas(23,2,36,6,""); if(NoOfFrame>0) mC[2].enabl[0]=mC[2].enabl[2]=1, hL=0; else mC[2].enabl[0]=mC[2].enabl[2]=0, hL=-1; if(NoOfFrame>0 && fR[0][0]!='\0') mC[2].enabl[1]=1; else mC[2].enabl[1]=0; DrawCmd(2); while(1) { if(kbhit()) { if((ch=getch())==27) goto end; else if(ch==0) HighlightCmd(2); else if(ch=='\r') { switch(hL) { case 0 : SFind(); goto end; case 1 : SNext(); goto end; case 2 : SReplace(); goto end; default: goto end; } } else { switch(ch) { case 'f': case 'F': if(mC[2].enabl[0]) SFind(); goto end; case 'n': case 'N': if(mC[2].enabl[1]) SNext(); goto end; case 'r': case 'R': if(mC[2].enabl[2]) SReplace(); goto end; default : goto end; } } } if(ReadMouse()==1) { if( 21<mx&&mx<36 && 0<my&&my<6 ) while(ReadMouse()); if(23<mx&&mx<34) { switch(my) { case 2 : if(mC[2].enabl[0]) SFind(); goto end; case 3 : if(mC[2].enabl[1]) SNext(); goto end; case 4 : if(mC[2].enabl[2]) SReplace(); goto end; default: goto end; } } else goto end; } if(mb==2) goto end; } end: ClearMenu(); } void Case() { char ch; DrawCanvas(33,2,46,5,""); if( NoOfFrame==0 || SX1==SX2&&SY1==SY2 ) mC[3].enabl[0]= mC[3].enabl[1]=0, hL=-1; else mC[3].enabl[0]= mC[3].enabl[1]=1, hL=0; DrawCmd(3); while(1) { if(kbhit()) { if((ch=getch())==27) goto end; else if(ch==0) HighlightCmd(3); else if(ch=='\r') { switch(hL) { case 0 : if(mC[3].enabl[0]) CUpperLower(1); goto end; case 1 : if(mC[3].enabl[1]) CUpperLower(0); goto end; default: goto end; } } else { switch(ch) { case 'u': case 'U': if(mC[3].enabl[0]) CUpperLower(1); goto end; case 'l': case 'L': if(mC[3].enabl[1]) CUpperLower(0); goto end; default : goto end; } } } if(ReadMouse()==1) { if( 31<mx&&mx<46 && 0<my&&my<5 ) while(ReadMouse()); if(33<mx&&mx<44) { switch(my) { case 2 : if(mC[3].enabl[0]) CUpperLower(1); goto end; case 3 : if(mC[3].enabl[1]) CUpperLower(0); goto end; default: goto end; } } else goto end; } else if(mb==2) goto end; } end: ClearMenu(); } void Table() { char ch; DrawCanvas(42,2,55,7,""); if(NoOfFrame>0) mC[4].enabl[0]= mC[4].enabl[1]= mC[4].enabl[2]= mC[4].enabl[3]=1, hL=0; else mC[4].enabl[0]= mC[4].enabl[1]= mC[4].enabl[2]= mC[4].enabl[3]=0, hL=-1; DrawCmd(4); while(1) { if(kbhit()) { if((ch=getch())==27) goto end; else if(ch==0) HighlightCmd(4); else if(ch=='\r') { switch(hL) { case 0 : if(mC[4].enabl[0]) TSDW(0); goto end; case 1 : if(mC[4].enabl[1]) TSDW(1); goto end; case 2 : if(mC[4].enabl[2]) TSDW(2); goto end; case 3 : if(mC[4].enabl[3]) TSDW(3); goto end; default: goto end; } } else { switch(ch) { case 's': case 'S': if(mC[4].enabl[0]) TSDW(0); goto end; case 'd': case 'D': if(mC[4].enabl[1]) TSDW(1); goto end; case 'n': case 'N': if(mC[4].enabl[2]) TSDW(2); goto end; case 'b': case 'B': if(mC[4].enabl[3]) TSDW(3); goto end; default : goto end; } } } if(ReadMouse()==1) { if( 40<mx&&mx<55 && 0<my&&my<7 ) while(ReadMouse()); if(42<mx&&mx<53) { switch(my) { case 2 : if(mC[4].enabl[0]) TSDW(0); goto end; case 3 : if(mC[4].enabl[1]) TSDW(1); goto end; case 4 : if(mC[4].enabl[2]) TSDW(2); goto end; case 5 : if(mC[4].enabl[3]) TSDW(3); goto end; default: goto end; } } else goto end; } if(mb==2) goto end; } end: ClearMenu(); } void Window() { int i; char fn[MAXFILE],ch; DrawCanvas(53,2,66,6+NoOfFrame,""); mC[5].NoOfCmd=3; for(i=0;i<NoOfFrame;i++) { FileName(fn,frm[i].fileName); sprintf(mC[5].cmd[mC[5].NoOfCmd]," %-8s ",fn); mC[5].NoOfCmd++; } if(NoOfFrame==0) mC[5].enabl[0]=mC[5].enabl[1]=0, hL=-1; else if(NoOfFrame==1) mC[5].enabl[0]=mC[5].enabl[1]=0, hL=3; else mC[5].enabl[0]=mC[5].enabl[1]=1, hL=0; DrawCmd(5); while(1) { if(kbhit()) { if((ch=getch())==27) goto end; else if(ch==0) HighlightCmd(5); else if(ch=='\r') { switch(hL) { case 0 : WListAll(0); goto end; case 1 : WListAll(fI-1); goto end; default: if(hL!=-1) WListAll(hL-3); goto end; } } else { switch(ch) { case 'n': case 'N': if(mC[5].enabl[0]) WListAll(0); goto end; case 'p': case 'P': if(mC[5].enabl[1]) WListAll(fI-1); goto end; default : goto end; } } } if(ReadMouse()==1) { if( 51<mx&&mx<66 && 0<my&&my<6+NoOfFrame) while(ReadMouse()); if(53<mx&&mx<64) { switch(my) { case 2 : if(mC[5].enabl[0]) WListAll(0); goto end; case 3 : if(mC[5].enabl[1]) WListAll(fI-1); goto end; default: if(4<my&&my<NoOfFrame+5) WListAll(my-5); goto end; } } else goto end; } if(mb==2) goto end; } end: ClearMenu(); } void Help() { char ch; DrawCanvas(63,2,76,6,""); hL=0; DrawCmd(6); while(1) { if(kbhit()) { if((ch=getch())==27) goto end; else if(ch==0) HighlightCmd(6); else if(ch=='\r') { switch(hL) { case 0: HControls(); goto end; case 1: HAbout(); goto end; case 2: HDedication(); goto end; } } else { switch(ch) { case 'c': case 'C': HControls(); goto end; case 'a': case 'A': HAbout(); goto end; case 'd': case 'D': HDedication(); goto end; default : goto end; } } } if(ReadMouse()==1) { if( 61<mx&&mx<76 && 0<my&&my<6 ) while(ReadMouse()); if(63<mx&&mx<74) { switch(my) { case 2 : HControls(); goto end; case 3 : HAbout(); goto end; case 4 : HDedication(); goto end; default: goto end; } } else goto end; } if(mb==2) goto end; } end: ClearMenu(); } /**********************************************************/ void GetKey() { int i; char ch=getch(); if(ch==0) { ch=getch(); switch(ch) { case 33: File(); return; case 18: Edit(); return; case 31: Search(); return; case 46: Case(); return; case 20: Table(); return; case 17: Window(); return; case 35: Help(); return; default: if(NoOfFrame>0) { switch(ch) { case 82: if(ShiftKeyHit()) EPaste(); // Shift+Ins else SNext(); return; // Ins case 83: if(ShiftKeyHit()) ECut(); // Shift+Del else DelChar(); return; // Del case 71: SetCurser(-CX,0); return; // Home case 72: SetCurser(0,-1); return; // up case 75: SetCurser(-1,0); return; // left case 77: SetCurser(1,0); return; // right case 79: SetCurser(LinLen(CY)-CX,0); return; // End case 80: SetCurser(0,1); return; // down case 73: // PgUp { i=CY-SL; SL-=ROW; flag|=16; if(SL<0) SL=0; SetCurser(0,SL+i-CY); } return; case 81: // PgDn { i=CY-SL; SL+=ROW; flag|=16; if(SL>=NOL) SL-=ROW; SetCurser(0,SL+i-CY); } return; case-110: ECopy(); return; // Shift+I case-109: EClear(); return; // Ctrl+Del case-124: SetCurser(-CX,-CY); return; // Ctrl+PgUp case 118: SetCurser(LinLen(NOL-1)-CX,NOL-1-CY); return; // Ctrl+PgDn } } } } else if(NoOfFrame>0) { switch(ch) { case 8: AddBksp(); return; // Backspace case 9: for(i=0;i<SPACESTOTAB;i++) AddChar(' '); return; //Tab default: if( ' '<=ch&&ch<='~' || ch=='\r' ) AddChar(ch); } } } void PopupMenu() { int sx,sy,i; /* store mx ,my. popupmenu */ char *pm[]= { " Cut ", " Copy ", " Paste ", " Clear " }; if(mx==0||mx==79||my<2||my>22) return; if(mx==1) mx=2; else if(mx>68) mx=68; if(my==2) my=3; else if(my>16) my=16; sx=mx+1, sy=my+1; DrawCanvas(sx,sy,sx+8,sy+5,""); hL=-1; mC[1].enabl[2]=1; if(SX1==SX2&&SY1==SY2) mC[1].enabl[0]= mC[1].enabl[1]= mC[1].enabl[3]=0; else mC[1].enabl[0]= mC[1].enabl[1]= mC[1].enabl[3]=1; for(i=0;i<=3;i++) { if(mC[1].enabl[i]) Color(WHITE,RED); else Color(BLACK,RED); Put(sx+1,sy+1+i,pm[i]); } Color(WHITE,-1); while(ReadMouse()); while(1) { ReadMouse(); if(mb||kbhit()) { if( sx<mx&&mx<sx+8 && sy<=my&&my<=sy+3 && mb==1 ) { switch(my-sy) { case 0: if(mC[1].enabl[0]) ECut(); break; case 1: if(mC[1].enabl[1]) ECopy(); break; case 2: if(mC[1].enabl[2]) EPaste(); break; case 3: if(mC[1].enabl[3]) EClear(); break; } while(ReadMouse()); } ClearMenu(); return; } else { if( hL!=-1 && ( !(my>=sy&&my<=sy+3&&sx<mx&&mx<sx+8) || hL!=my-sy) ) Color(-1,RED), Put(sx+1,sy+1+hL,pm[hL]), hL=-1; if(sy<=my&&my<=sy+3 && sx<mx&&mx<sx+8 && hL!=my-sy && mC[1].enabl[my-sy]) hL=my-sy, Color(-1,GREEN), Put(sx+1,sy+1+hL,pm[hL]); HideCurser(); } } } void MouseSelection() { int oldMX=mx,oldMY=my; if(ShiftKeyHit()) { SetCurser(mx-1+SC-CX,my-2+SL-CY); while(ReadMouse()); return; } SX1= SX2= CX, SY1= SY2= CY; PutData(); SetCurser(mx-1+SC-CX,my-2+SL-CY); GotoXY(); mouseSelecting=1; while(1) { if(ReadMouse()!=1) break; if( mx==0&&CX!=0 || mx==79&&CX<LinLen(CY) || oldMX!=mx || oldMY!=my || my>22&&CY<NOL-1 || my<2&&CY!=0 ) { oldMX=mx, oldMY=my; SetCurser(mx-1+SC-CX,my-2+SL-CY); DisplayData(); delay(99); } } mouseSelecting=0; } void InitProgram() { textmode(C80); InitMouse(); Color(RED,GREEN); clrscr(); Put(9,1,"File Edit Search Case Table Window Help"); Color(GREEN,-1); Put(1,1," "); // for mouse hidding Color(BLACK,-1); Put(24,25,"http://programs.on.googlepages.com"); ShowMouse(); copyStr.len=strlen("<http://programs.on.googlepages.com>")+1; copyStr.data=(char*)malloc(copyStr.len); strcpy(copyStr.data,"<http://programs.on.googlepages.com>"); SetFrame(); } void main( int argc, char *argv[] ) { int i; char ext[MAXEXT]; InitProgram(); HideCurser(); if(argc>1) { fnsplit(argv[1],NULL,NULL,NULL,ext); if(strcmpi(ext,".tef")) OkDialogBox("ERROR","Invalid file extention"); else if( strlen(argv[1])>62 ) OkDialogBox("ERROR","The path is too long"); else FOpen(argv[1]); } while(1) { if(kbhit()) GetKey(); ReadMouse(); if(mb==1) { if(my==0) { if(5<mx&&mx<14) File(); else if(14<mx&&mx<23) { if( advice && NoOfFrame>0 ) OkDialogBox("Advice"," Use popupmenu"), advice=0; else Edit(); } else if(23<mx&&mx<34) Search(); else if(34<mx&&mx<43) Case(); else if(43<mx&&mx<53) Table(); else if(53<mx&&mx<64) Window(); else if(64<mx&&mx<73) Help(); } else if(NoOfFrame>0) { if( my==1 && 1<mx&&mx<5 ) { FClose(); while(ReadMouse()); } else if( mx==79 || my==23 ) Scroll(); else if( 0<my&&my<23 && 0<mx&&mx<79 ) MouseSelection(); } } else if( mb==2 && NoOfFrame>0 ) PopupMenu(); if( flag && NoOfFrame>0 ) DisplayData(); } } /******************************************************* * More programs: http://programs.on.googlepages.com * * Please report suggestions: programs.on@gmail.com * *******************************************2535*lines**/