#include #include #include #include #define CLR textbackground(BLACK);textcolor(WHITE) #define INV_CLR textbackground(WHITE);textcolor(BLACK) int copyflag=0,cutflag=0,pasteflag=0; void set_string(char str[50]) { int i; for(i=0;i<50;i++) str[i]='\0'; } void show_main_screen() { int i; printf("OPEN SAVE NEW COPY CUT PASTE\n"); printf("%c",201); for(i=0;i<77;i++) printf("%c",205); printf("%c\n",187); for(i=0;i<21;i++) printf("%c\n",186); printf("%c",200); for(i=0;i<77;i++) printf("%c",205); printf("%c",188); for(i=3;i<24;i++) { gotoxy(79,i); cprintf("%c",186); } gotoxy(4,4); cprintf(" "); } void main() { char ch,ch1,fname[20],str[50],str1[50]; FILE *fp; int ax,ay,x,y,i,j,left=0,right=0,revflag=0,x1,y1; int start=1,end=0,k=0,flag=0,s1flag=0,s2flag=0,startx,starty,endx,endy; CLR; i=0; j=0; clrscr(); show_main_screen(); while(1) { ch=getch(); if(ch!=0) { if(ch==27) // for escape { gotoxy(5,23); cprintf("\n\nOut Of Editor window"); break; } else if(ch==8) //for back space { if(wherex()<=5) gotoxy(5+1,wherey()); printf("\b"); printf(" "); printf("\b"); } else if(ch==13) //for enter { gotoxy(5,wherey()+1); } else if(ch==75) printf("\b"); else if(ch==3) // Copy ctrl+c { l1: str[i]='\0'; // in case F4 is pressed if(copyflag==1) goto l2; // back to F4 case } else if(ch==22) // Paste ctrl+v { l5: start=1; //in case F6 is Pressed startx=wherex(); starty=wherey(); gotoxy(startx,starty); if(revflag==0) { revflag=1; strrev(str); } else { if(left==1) cprintf("%s",str); else cprintf("%s",str1); } if(pasteflag==1) //go back to F6 case goto l6; } else if(ch==24) // Cut ctrl+x { //in case F5 is pressed l3: str[i]='\0'; str1[k]='\0'; gotoxy(ax,ay); textbackground(0); textcolor(0); cprintf("%s",str1); CLR; if(cutflag==1) //go back to F5 case goto l4; } else { x1=wherex(); y1=wherey(); gotoxy(70,24); cprintf("%d : %d",x1-5,y1); gotoxy(x1,y1); if(wherex()>=77) gotoxy(4,wherey()+1); printf("%c",ch); } } else { char c,ch1,c1,sv; int x1,y1; int ii,jj; FILE *fp1; char savestring[1000],savename[20]; int char_count=0; int a,b; c=getch(); switch(c) { case 59: gotoxy(5,23); cprintf("\n\nEnter A Filename To Be Opened -: "); gets(fname); fp=fopen(fname,"r"); if(fp==NULL) { gotoxy(5,23); cprintf("\n\nFile Not Found...Try Again"); getch(); exit(0); } else fclose(fp); fp=fopen(fname,"r"); //gotoxy(4,4); clrscr(); show_main_screen(); a=b=4; while(!feof(fp)) { c1=fgetc(fp); if(char_count>=68) { gotoxy(4,wherey()+1); char_count=0; cprintf(" %c",c1); } else { cprintf("%c",c1); char_count++; } } break; case 60: set_string(savestring); ii=0; jj=0; gotoxy(5,4); a=wherex(); b=wherey(); while(1) { if(a>=68) { a=5; gotoxy(5,b++); } gettext(a,b,a,b,&sv); savestring[ii]=sv; ii++; if(wherey()>=21) break; gotoxy(a++,b); } gotoxy(5,23); cprintf("\n\nEnter A File Name -: "); gets(savename); fp1=fopen(savename,"wb+"); if(fp1==NULL) { printf("\nUnable To Create File..Try Again.."); getch(); exit(0); } else fclose(fp1); fp1=fopen(savename,"w+"); fprintf(fp1,"%s",savestring); fclose(fp1); gotoxy(5,23); cprintf("\nFile Saved..."); break; case 61: clrscr(); show_main_screen(); break; case 62: copyflag=1; goto l1; l2: copyflag=0; break; case 63: cutflag=1; goto l3; l4: cutflag=0; break; case 64: pasteflag=1; goto l5; l6: pasteflag=0; break; case 115: left=1; //set_string(str); revflag=0; start=0; x1=wherex(); y1=wherey(); x1=x1-1; INV_CLR; gettext(x1,y1,x1,y1,&ch1); gotoxy(x1,y1); cprintf("%c",ch1); gotoxy(x1,y1); CLR; str[i]=ch1; i++; break; case 116: right=1; if(flag==0) { flag=1; ax=wherex(); ay=wherey(); } revflag=0; x1=wherex(); y1=wherey(); startx=x1; starty=y1; //x1=x1+1; INV_CLR; gettext(x1,y1,x1,y1,&ch1); gotoxy(x1,y1); cprintf("%c",ch1); str1[k]=ch1; k++; gotoxy(x,y); CLR; break; case 75: if(wherex()<=5) gotoxy(5,wherey()); else gotoxy(wherex()-1,wherey()); break; case 77: if(wherex()>=77) gotoxy(77,wherey()); else gotoxy(wherex()+1,wherey()); break; } } } getch(); }