#include #include #include #include #include #include #include #define TRUE 1 #define FALSE 0 /* Listed below are the hex values of keys of keyboard */ #define UP 0x4800 /* moves cursor one line up */ #define DOWN 0x5000 /* moves cursor one line down */ #define LEFT 0x4b00 /* moves cursor one character left*/ #define RIGHT 0x4d00 /* moves cursor one character right*/ #define TAB 0xf09 /* moves cursor 8 characters right*/ #define END 0x4f00 /* moves cursor to the end of line*/ #define HOME 0x4700 /* moves cursor to the top of line*/ #define PAGEUP 0x4900/* moves cursor to the top of screen(page)*/ #define PAGEDN 0x5100/* moves cursor to the bottom of screen(page)*/ /* HotKeys for Menu System */ #define ALT_F 0x2100 /*calls the File system*/ #define ALT_E 0x1200 /*calls the Edit system*/ #define ALT_T 0x1400 /*calls the Tool system*/ #define ALT_X 0x2d00 /*calls the eXit system (i.e. exits from editor */ #define ALT_H 0x2300 /*calls the Help system*/ /*HotKeys for Control System*/ #define CTRL_D 0x2004 /*deletes the whole screen*/ #define CTRL_R 0x1312 /*restore the currently deleted by pressing CtrlD"*/ #define CTRL_E 0x1205 /*deletes to the end of line*/ #define CTRL_I 0x1709 /*insert a blank line on cursor position*/ #define CTRL_X 0x2d18 /*cuts line or character */ #define CTRL_P 0x1910 /*paste from the cursor position*/ #define CTRL_C 0x2e03 /*copy line or character */ #define CTRL_L 0x260c /*deletes the line of cursor position*/ #define CTRL_S 0x1f13 /*deletes the whole screen */ #define CTRL_N 0x316e #define CTRL_V 0x2f16 #define F10 0x4400 /*calls the menusystem*/ #define ESC 0x11b /*Escapes from current part*/ #define BKSP 0xe08 /*Deletes one character left*/ #define DEL 0x5300 /*deletes the character on cursor*/ #define ENTER 0x1c0d /*place cursor to new line*/ //variables used for cursor status int CurCol,CurRow,CurWord,RowMax,ColMax[20]; int Key;//variable for value of key pressed char Chars;//variable for character value of key pressed char CutBuf[60]; char far *ins = ( char far * ) 0x417 ;//varable for insert key //variables used for counter in various loops(eg for,while etc.) int i,j,k; //variable for Buffer value char Buffer[5][2400]; //function prototypes int FileSystem(int, int); void EditSystem(int, int ),HelpSystem(),ToolSystem(), Cut(),Copy(),Paste(),Delete(), New(),Save(),Load(), Print() , Del(); void Ins(char c); /////////////////////////////////////////////////////////////////////// // FUNCTION : Default() // // PURPOSE : sets all the variables default // /////////////////////////////////////////////////////////////////////// void Default() { CurCol=CurRow=CurWord=RowMax=1; for(i=0;i<20;i++) ColMax[i] = 1; }//end of Default() /////////////////////////////////////////////////////////////////////// // FUNCTION : DrawBox() // // PURPOSE : Draw the outline box of the editor screen // /////////////////////////////////////////////////////////////////////// void DrawBox() { int i; textattr(BROWN); gotoxy(3,3); cprintf("ษอออออออออออออออออออ NONAME.TXT อออออออออออออออออออออออออออออหอออออออออออออออป"); for(i=4;i<24;i++) { gotoxy(3,i); cprintf("บ"); gotoxy(64,i); cprintf("บ"); gotoxy(80,i); cprintf("บ"); } gotoxy(3,24); cprintf("ศออออออออออออออออออออออออออออออออออออออออออออออออออออออออออออสอออออออออออออออผ"); gotoxy(64,5); cprintf("ฬอออออออออออออออน"); gotoxy(64,11); cprintf("ฬอออออออออออออออน"); gotoxy(64,19); cprintf("ฬอออออออออออออออน"); gotoxy(64,22); cprintf("ฬอออออออออออออออน"); textattr(CYAN); gotoxy(25,1); cprintf(" ----- THE ----- "); gotoxy(25,2); cprintf(" **** LINE EDITOR **** "); // gotoxy(3,25); // cprintf("Copyright : BINSAN KHADKA { for help contact : }"); }//end of DrawBox /////////////////////////////////////////////////////////////////////// // FUNCTION : DrawBox1() // // PURPOSE : Draw the outline box of the help screen // /////////////////////////////////////////////////////////////////////// void DrawBox1() { int i=18,j=9,k,l; textattr(BLACK); textbackground(GREEN); gotoxy(i,j); cprintf("ษออออออออออออออออออออออออออออออป"); gotoxy(i,j+10); cprintf("ศออออออออออออออออออออออออออออออผ"); gotoxy(i+12,j); cprintf(" HELP "); for (k=1;k<10;k++) { gotoxy(i,j+k); cprintf("บ"); gotoxy(i+31,j+k); cprintf("บ"); } }//of DrawBox1() /////////////////////////////////////////////////////////////////////// // FUNCTION : DrawBox2() // // PURPOSE : Draw the outline box of the dialog box // /////////////////////////////////////////////////////////////////////// void DrawBox2() { int i=18,j=9,k,l; textattr(BLACK); textbackground(GREEN); gotoxy(i,j); cprintf("ษอออออออออออออออออออออออออออออออออออป"); gotoxy(i,j+5); cprintf("ศอออออออออออออออออออออออออออออออออออผ"); for (k=1;k<5;k++) { gotoxy(i,j+k); cprintf("บ"); gotoxy(i+36,j+k); cprintf("บ"); } }//of DrawBox1() /////////////////////////////////////////////////////////////////////// // FUNCTION : MenuOption() // // PURPOSE : Displays the options of main menu on the screen // /////////////////////////////////////////////////////////////////////// void MenuOption() { textattr(RED); gotoxy(66,4); cprintf(" MAIN MENU "); textbackground(BLACK); textattr(GREEN); gotoxy(66,6); cprintf(" 1.File "); gotoxy(66,7); cprintf(" 2.Edit "); gotoxy(66,8); cprintf(" 3.Tool "); gotoxy(66,9); cprintf(" 4.Help "); gotoxy(66,10); cprintf(" 5.Exit "); gotoxy(66,12); cprintf(" QUICK HELP "); gotoxy(66,13); cprintf(" F10 -> Menu "); gotoxy(66,14); cprintf("Alt+F -> File "); gotoxy(66,15); cprintf("Alt+E -> Edit "); gotoxy(66,16); cprintf("Alt+T -> Tool "); gotoxy(66,17); cprintf("Alt+H -> Help "); gotoxy(66,18); cprintf("Alt+X -> Exit "); }//of MenuOption /////////////////////////////////////////////////////////////////////// // FUNCTION : FileOption() // // PURPOSE : Displays the options of file menu on the screen // /////////////////////////////////////////////////////////////////////// void FileOption() { textattr(RED); gotoxy(66,4); cprintf(" FILE MENU "); textbackground(BLACK); textattr(GREEN); gotoxy(66,6); cprintf(" 1.New "); gotoxy(66,7); cprintf(" 2.Save "); gotoxy(66,8); cprintf(" 3.Load "); gotoxy(66,9); cprintf(" 4.Print "); gotoxy(66,10); cprintf(" 5.Return "); gotoxy(66,12); cprintf("Quick Help "); gotoxy(66,13); cprintf(" N -> New "); gotoxy(66,14); cprintf(" S -> Save "); gotoxy(66,15); cprintf(" L -> Load "); gotoxy(66,16); cprintf(" P -> Print "); gotoxy(66,17); cprintf("ESC -> Return "); gotoxy(66,18); cprintf(" "); }//of FileOption /////////////////////////////////////////////////////////////////////// // FUNCTION : EditOption() // // PURPOSE : Displays the options of edit menu on the screen // /////////////////////////////////////////////////////////////////////// void EditOption() { textattr(RED); gotoxy(66,4); cprintf(" EDIT MENU "); textbackground(BLACK); textattr(GREEN); gotoxy(66,6); cprintf(" 1.Cut "); gotoxy(66,7); cprintf(" 2.Copy "); gotoxy(66,8); cprintf(" 3.Paste "); gotoxy(66,9); cprintf(" 4.Delete "); gotoxy(66,10); cprintf(" 5.Return "); gotoxy(66,12); cprintf("Quick Help "); gotoxy(66,13); cprintf(" C -> Cut "); gotoxy(66,14); cprintf(" O -> Copy "); gotoxy(66,15); cprintf(" P -> Paste "); gotoxy(66,16); cprintf(" D -> Delete "); gotoxy(66,17); cprintf("ESC -> Return "); gotoxy(66,18); cprintf(" "); }//of EditOption /////////////////////////////////////////////////////////////////////// // FUNCTION : Highlight(int i, int j) // // PURPOSE : Highlights jth option of ith menu // /////////////////////////////////////////////////////////////////////// void Highlight(int i,int j) { _setcursortype(_NOCURSOR); switch(i) { case 1: //MenuSystem MenuOption(); switch(j) { case 1: gotoxy(66,6); textbackground(WHITE); textcolor(MAGENTA); cprintf(" 1.File "); break; case 2: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,7); cprintf(" 2.Edit "); break; case 3: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,8); cprintf(" 3.Tool "); break; case 4: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,9); cprintf(" 4.Help "); break; case 5: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,10); cprintf(" 5.Exit "); break; }//of switch(j) break;//break of case 1 case 2://FileSystem FileOption(); switch(j) { case 1: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,6); cprintf(" 1.New "); break; case 2: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,7); cprintf(" 2.Save "); break; case 3: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,8); cprintf(" 3.Load "); break; case 4: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,9); cprintf(" 4.Print "); break; case 5: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,10); cprintf(" 5.Return "); }//of switch(j) break; case 3://EditSystem EditOption(); switch(j) { case 1: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,6); cprintf(" 1.Cut "); break; case 2: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,7); cprintf(" 2.Copy "); break; case 3: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,8); cprintf(" 3.Paste "); break; case 4: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,9); cprintf(" 4.Delete "); break; case 5: textbackground(WHITE); textcolor(MAGENTA); gotoxy(66,10); cprintf(" 5.Return "); }//of switch(j) break;//of case 3 default: break; }//of switch(i) }//of Highlight() /////////////////////////////////////////////////////////////////////// // FUNCTION : MenuSystem() // // PURPOSE : performs the function of main menu // /////////////////////////////////////////////////////////////////////// void MenuSystem(int Choice, int Key) { int Choice1 = 1; window(1,1,80,25); while(1) { switch(Choice) { case 1: Highlight(1,Choice); //Highlight File if (Key == ENTER) { Key = 0; Key = FileSystem(Choice1,Key); if (Key == -1) return; } break; case 2: Highlight(1,Choice);//Highlight Edit if (Key == ENTER) { Key = 0; EditSystem(Choice1,Key); } break; case 3: Highlight(1,Choice); //Highlight Tool if (Key == ENTER) { Key=0; ToolSystem(); } break; case 4: Highlight(1,Choice); //Highlight Help if (Key == ENTER) HelpSystem(); break; case 5: Highlight(1,Choice);//Highlight Exit if (Key == ENTER) exit(1); default: break; }//of switch(choice) Key = bioskey(0); if (Key == ESC) { MenuOption(); break; } else if (Key == DOWN) if (Choice < 5) Choice++; else Choice =1; if (Key == UP) if (Choice > 1) Choice--; else Choice =5; }//of while(1) return; }//of MenuSystem() /////////////////////////////////////////////////////////////////////// // FUNCTION : New() // // PURPOSE : performs the function for new editor screen // /////////////////////////////////////////////////////////////////////// void New() { char Ch; gettext(4,4,63,23,Buffer[4]); DrawBox2(); window(19,10,53,13); clrscr(); textbackground(GREEN); textcolor(WHITE); for (i=0;i<2400;i++) if (Buffer[2][i] != Buffer[4][i]) { cprintf("File Not Saved, save (Y/N) ?"); gotoxy(2,2); scanf(" %c",&Ch); if ((Ch == 'Y') || (Ch == 'y')) { Save(); break; } else break; } for (i=0; i<2400;i++) Buffer[0][i] = ' '; Default(); window(1,1,80,25); gotoxy(24,3); textattr (BROWN); cprintf("NONAME.TXT ออออออออออ"); window (4,4,63,23); clrscr(); _setcursortype(_NOCURSOR); window(1,1,80,25); Highlight(1,1); }//of New() /////////////////////////////////////////////////////////////////////// // FUNCTION : Save() // // PURPOSE : performs the function to save // /////////////////////////////////////////////////////////////////////// void Save() { char filename[13]; FILE *fopenptr; gettext(4,4,63,23,Buffer[2]); top: DrawBox2(); window(19,10,53,13); clrscr(); gotoxy (5,1); textbackground(GREEN); textcolor(WHITE); cprintf("Enter File Name :"); _setcursortype(_NORMALCURSOR); gotoxy(2,2); scanf(" %s",filename); if (strlen(filename) >= 13) { printf("\a"); goto top; } fopenptr = fopen(filename,"w"); for (i=0;i<2399;i++) fprintf(fopenptr,"%c",Buffer[2][i]); fclose(fopenptr); gotoxy(3,3); cprintf("File Saved "); delay(900); window(1,1,80,25); for (i=0;i1) Choice1--; }//of while(1) return (1); }//of FileSystem /////////////////////////////////////////////////////////////////////// // FUNCTION : Cut() // // PURPOSE : performs the function to cut // /////////////////////////////////////////////////////////////////////// void Cut() { int Ch; window(1,1,80,25); gettext(4,4,63,23,Buffer[2]); DrawBox2(); window(19,10,53,13); clrscr(); gotoxy(1,1); textbackground(GREEN); textcolor(WHITE); cprintf("Number of Characters to cut"); gotoxy(2,2); cprintf(" from cursor position : "); _setcursortype(_NORMALCURSOR); scanf(" %d",&Ch); for (k=0,j=0;k 1) Choice1--; }//of while(1) }//of EditSystem() /////////////////////////////////////////////////////////////////////// // FUNCTION : ToolSystem() // // PURPOSE : performs the function of Tool menu // /////////////////////////////////////////////////////////////////////// void ToolSystem() { gettext(4,4,63,23,Buffer[3]); DrawBox2(); window(19,10,53,13); clrscr(); gotoxy(5,2); textbackground(GREEN); textcolor(WHITE); cprintf("Yet to be Implemented"); gotoxy(7,3); cprintf("Press any key to exit..."); getch(); window(4,4,63,23); puttext(4,4,63,23,Buffer[3]); window(1,1,80,25); }//of ToolSystem() /////////////////////////////////////////////////////////////////////// // FUNCTION : HelpSystem() // // PURPOSE : performs the function of Help menu // /////////////////////////////////////////////////////////////////////// void HelpSystem() { char *index[]= { " ; OK: ESC ; ->: NEXT", "BACK: <- ; OK: ESC ; ->: NEXT", "BACK: <- ; OK: ESC ; " }; char *help1[] ={ " Cursor Movement Commands : ", "------------------------------", " Move Character Left - LEFT ", " Move Character Right - RIGHT ", " Move Line Up - UP ", " Move Line Down - DOWN ", " Move to top of Line - HOME ", " Move to end of Line - END " }; char *help2[]={ " Special Keys : ", "------------------------------", " Open File Menu - Alt+F ", " Open Edit Menu - Alt+E ", " Display Help Menu - Alt+H ", " Exits from Editor - Alt+X ", " Delete whole Screen - Ctrl+D ", " Restore deleted Screen-Ctrl+R" }; char *help3[]={ " Special keys(Cont...) : ", "------------------------------", " Save the file -Alt+F,S", " Load existing file -Alt+F,L", " Load new file to edit-Alt+F,N", " Print current file -Alt+f,P", " ", " ", }; char *help4[]={ " Special keys(Cont...) : ", "------------------------------", " Cut selected text - Ctrl+X ", " Copy selected text - Ctlr+C ", " Paste the text - Ctrl+P ", " ", " ", " ", }; char *help5[]={ " Special keys(Cont...) : ", "------------------------------", " Highlight MenuBar - F10 ", " Delete Current line - Clrt+L ", " Insert A Blank Line - Ctrl+I ", " ", " ", " ", }; int tag = 1; gettext(4,4,63,23,Buffer[1]); DrawBox1(); window(19,10,48,18); clrscr(); textattr(BLACK); textbackground(GREEN); _setcursortype(_SOLIDCURSOR); for (i=0;i<8;i++) { gotoxy(1,1+i); cprintf("%s",help1[i]); } gotoxy(1,9); textcolor(WHITE); textbackground(BLACK); cprintf("%s",index[0]); tag = 1; while(1) { Key = bioskey(0); if (Key == ESC) { window(1,1,80,24); puttext(4,4,63,23,Buffer[1]); _setcursortype(_NOCURSOR); return; } switch(Key) { case RIGHT: switch (tag) { case 1: for (i=0;i<8;i++) { textcolor(BLACK); textbackground(GREEN); gotoxy(1,1+i); cprintf("%s",help2[i]); } gotoxy(1,9); textcolor(WHITE); textbackground(BLACK); cprintf("%s",index[1]); tag ++; break; case 2: for (i=0;i<8;i++) { textcolor(BLACK); textbackground(GREEN); gotoxy(1,1+i); cprintf("%s",help3[i]); } gotoxy(1,9); textcolor(WHITE); textbackground(BLACK); cprintf("%s",index[1]); tag ++; break; case 3: for (i=0;i<8;i++) { textcolor(BLACK); textbackground(GREEN); gotoxy(1,1+i); cprintf("%s",help4[i]); } gotoxy(1,9); textcolor(WHITE); textbackground(BLACK); cprintf("%s",index[1]); tag ++; break; case 4: for (i=0;i<8;i++) { textcolor(BLACK); textbackground(GREEN); gotoxy(1,1+i); cprintf("%s",help5[i]); } gotoxy(1,9); textcolor(WHITE); textbackground(BLACK); cprintf("%s",index[2]); tag ++; break; default: printf("\a"); }//of switch (tag) break; case LEFT: switch (tag) { case 2: for (i=0;i<8;i++) { textcolor(BLACK); textbackground(GREEN); gotoxy(1,1+i); cprintf("%s",help1[i]); } gotoxy(1,9); textcolor(WHITE); textbackground(BLACK); cprintf("%s",index[0]); tag --; break; case 3: for (i=0;i<8;i++) { textcolor(BLACK); textbackground(GREEN); gotoxy(1,1+i); cprintf("%s",help2[i]); } gotoxy(1,9); textcolor(WHITE); textbackground(BLACK); cprintf("%s",index[1]); tag --; break; case 4: for (i=0;i<8;i++) { textcolor(BLACK); textbackground(GREEN); gotoxy(1,1+i); cprintf("%s",help3[i]); } gotoxy(1,9); textcolor(WHITE); textbackground(BLACK); cprintf("%s",index[1]); tag --; break; case 5: for (i=0;i<8;i++) { textcolor(BLACK); textbackground(GREEN); gotoxy(1,1+i); cprintf("%s",help4[i]); } gotoxy(1,9); textcolor(WHITE); textbackground(BLACK); cprintf("%s",index[1]); tag --; break; default: printf("\a"); }//of switch (tag) break; }//of switch(Key) }//of while(1) }//of HelpSystem() /////////////////////////////////////////////////////////////////////// // FUNCTION : Ins() // // PURPOSE : Inserts the character in current cursor position // /////////////////////////////////////////////////////////////////////// void Ins(char c) { int xyz; int BufferCol; BufferCol = ((((CurRow-1)*60) + (CurCol-1)) * 2); xyz=(60*CurRow*2)-1; for (i=xyz;i>BufferCol;i--) Buffer[0][i]=Buffer[0][i-2]; Buffer[0][BufferCol] = c; Buffer[0][BufferCol+1] = 15; //attribute if (CurCol < 60) { CurCol++; ColMax[CurRow-1]++; } else { CurRow++; CurCol=1; ColMax[CurRow-1]++; } puttext(4,4,63,23,Buffer[0]); }//of Ins() /////////////////////////////////////////////////////////////////////// // FUNCTION : Del() // // PURPOSE : Deletes the character in current cursor position // /////////////////////////////////////////////////////////////////////// void Del() { int BufferCol,zyx; BufferCol = ((((CurRow-1)*60) + (CurCol-1)) * 2); zyx=((60*(CurRow)*2)-1); for (i=BufferCol;i= 20) && ( CurCol >= 60)) //if cursor is at end of editor screen printf("\a"); // beep else { gotoxy(CurCol,CurRow); textattr(15); //attribute is White on Black putch(Key); } if (CurCol < 60) { CurCol++; //increase the cursor position ColMax[CurRow-1]++; } else //if cursor is at end of line { if (CurRow < 20) { CurRow++; //position cursor at new line RowMax++; CurCol = 1; //position cursor at initial position ColMax[CurRow-1]++; } } } gettext(4,4,63,24,Buffer[0]); } else switch(Key) { case DEL: Del(); break; case BKSP: if (CurCol>1) { --CurCol; Del(); } break; case UP: if (CurRow > 1) CurRow--; break; case RIGHT: if (CurCol < 60) CurCol++; break; case LEFT: if (CurCol > 1) CurCol--; break; case DOWN: if (CurRow < 20) if (CurRow < RowMax) CurRow++; break; case TAB: if (CurCol < 60) CurCol +=4; break; case ENTER: if (CurRow < 20) { CurRow++; if (RowMax < 20) RowMax++; CurCol=1; } else printf("\a"); break; case END: if (ColMax[CurRow-1] < 60) CurCol = ColMax[CurRow-1]; else CurCol = ColMax[CurRow-1]; break; case HOME: CurCol = 1; break; case PAGEDN: CurRow = RowMax; break; case PAGEUP: CurRow = 1; break; case F10: MenuSystem(1,0); break; case ALT_F: MenuSystem(1,ENTER); //choice is file(first choice) break; case ALT_E: MenuSystem(2,ENTER); //choice is Edit(second choice) break; case ALT_T: MenuSystem(3,ENTER); //choice is Tool(third choice) break; case ALT_H: MenuSystem(4,ENTER); //choice is Help(fourth choice) break; case ALT_X: MenuSystem(5,ENTER); //choice is Exit(fifth choice) clrscr(); break; case CTRL_D: gettext(4,4,63,23,Buffer[4]); Delete(); break; case CTRL_S: gettext(4,4,63,23,Buffer[4]); textbackground(BLACK); Save(); break; case CTRL_E: gettext(4,4,63,23,Buffer[4]); textbackground(BLACK); clreol(); break; case CTRL_I: gettext(4,4,63,23,Buffer[4]); insline(); break; case CTRL_R: window(4,4,63,23); puttext(4,4,63,23,Buffer[4]); break; case CTRL_X: gettext(4,4,63,23,Buffer[4]); Cut(); break; case CTRL_C: gettext(4,4,63,23,Buffer[4]); Copy(); break; case CTRL_P: gettext(4,4,63,23,Buffer[4]); Paste(); break; case CTRL_N: New(); break; case CTRL_L: window(1,1,80,25); Load(); break; case CTRL_V: window(1,1,80,25); Print(); break; case ESC: exit(0); }//of switch(Key) if (Key == ESC) break; }//of while(TRUE) }//end of function main()