⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editor.c

📁 文本编辑器
💻 C
📖 第 1 页 / 共 2 页
字号:
/* S.I.E. of BUPT jingle8848@sohu.com 2005.9.15 Passed in TC2.0 */
#include "conio.h"
#include "stdio.h"
#include "bios.h"
#include"stdlib.h"

#define F1 0x3b00                           /*define some special key*/                    
#define F2 0x3c00
#define F3 0x3d00
#define F4 0x3e00
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define SPACE 0x3920
#define ESC 0x011b
#define ENTER 0x1c0d
#define BACKSPACE 0xe08

struct chain *p;
struct chain *s;
struct chain *h=NULL;

static char MenuName1[10]="File";             /*define menu*/
static char MenuName2[12]="Edit";
static char MenuName3[14]="Search";
static char MenuName4[10]="Help";
static char OptionMenu1[4][10]={"New     ",
                                "Open    ",
                                "Save    ",
                                "Exit    "
                               };
static char OptionMenu2[1][10]={"Edit    "
                               };
static char OptionMenu3[1][10]={"Search  "
                               };
static char OptionMenu4[2][10]={"Command ",
                                "About   "
                               };
int *key;
int CurX=2,CurY=4;
int line,col,*keystate;


int getkey(int *key)                        /*get key from keyboard*/
{
  line=wherex()-1;
  col=wherey()-3;
  gotoxy(46,25);
  textbackground(7);
  textcolor(BLACK);
  cprintf("%2d",line);
  gotoxy(53,25);
  textbackground(7);
  textcolor(BLACK);
  cprintf("%2d",col);                    /*show line and col*/
  gotoxy(56,25);
  textbackground(11);
  textcolor(WHITE);
  *keystate=bioskey(2);
  switch(*keystate)                      /*show NumLock,Insert,CapsLock and ScrollLock state*/
	{ 
	  case 0x00:   cprintf("                        ");break;
	  case 0x20:   cprintf(" NUM                    ");break;
      case 0x40:   cprintf("      CAPS              ");break;
	  case 0x80:   cprintf("            INS         ");break;
      case 0x10:   cprintf("                 SCROLL ");break;
	  case 0x30:   cprintf(" NUM             SCROLL ");break;
	  case 0x50:   cprintf("      CAPS       SCROLL ");break;
	  case 0x60:   cprintf(" NUM  CAPS              ");break;
	  case 0x70:   cprintf(" NUM  CAPS       SCROLL ");break;
	  case 0x90:   cprintf("            INS  SCROLL ");break;
	  case 0xa0:   cprintf(" NUM        INS         ");break;
	  case 0xb0:   cprintf(" NUM        INS  SCROLL ");break;
	  case 0xc0:   cprintf("      CAPS  INS         ");break;
	  case 0xd0:   cprintf("      CAPS  INS  SCROLL ");break;
	  case 0xe0:   cprintf(" NUM  CAPS  INS         ");break;
	  case 0xf0:   cprintf(" NUM  CAPS  INS  SCROLL ");break;
     }


gotoxy(CurX,CurY);
*key=bioskey(0);    
}


struct chain
{       char data;
        struct chain *next;
        struct chain *prior;
};


FILE *in;
FILE* OpenNewFile (char filename[])      /*open new file*/
									/* being analyzed*/
{/*OpenNewFile*/
    
	
	/*true as long as file not opened */
	FILE* inFile;
	
    middlebox();
          textcolor(WHITE);
	cprintf ("File Name:");
	scanf ("%s", filename);
	inFile = fopen (filename, "r") ;

	/*check for opening ok; if not, print an error message*/
	/* and re-promt*/
	if (!inFile)
	{
		gotoxy(30,5);
		cprintf(" Can't open the file.");
		getch();
	}
return (inFile);		/* return file pointer as result */
}

middlebox()                            /*paint a middlebox for some menu*/
     {
	 int xx,yy;  
   for(xx=30;xx<=50;xx++)
      {gotoxy(xx,4); 
              cprintf("%c",196);
       gotoxy(xx,6);
              cprintf("%c",196);              
             }
   for(yy=5;yy<=5;yy++)
             {gotoxy(29,yy);
              cprintf("%c",179);
       gotoxy(51,yy);
              cprintf("%c",179);
             }
          gotoxy(51,6);
          cprintf("%c",217); 
          gotoxy(29,4);
          cprintf("%c",218);
          gotoxy(29,6);
          cprintf("%c",192);
          gotoxy(51,4);
          cprintf("%c",191);
		  gotoxy(30,5);
}

bigbox()                           /*paint a bigger box than middle box for Help menu*/
     {
	 int xx,yy;
	
   for(xx=20;xx<=60;xx++)
      {gotoxy(xx,4); 
              cprintf("%c",196);
       gotoxy(xx,12);
              cprintf("%c",196);              
             }
   for(yy=5;yy<=11;yy++)
             {gotoxy(19,yy);
              cprintf("%c",179);
       gotoxy(61,yy);
              cprintf("%c",179);
             }
          gotoxy(61,12);
          cprintf("%c",217); 
          gotoxy(19,4);
          cprintf("%c",218);
          gotoxy(19,12);
          cprintf("%c",192);
          gotoxy(61,4);
          cprintf("%c",191);
		  gotoxy(20,5);
}

FILE *out;
FILE* save(char filename[])    /* save file */
{        middlebox();
         textcolor(WHITE);
	cprintf ("Save As:");
	scanf("%s", filename);
		return(out);
}

DisplayMenu(int PosMenu,int PosOption) /*display four menus*/
{
 int VarX,VarY,Var;
 switch(PosMenu)
 {
  case 1:{                       /*menu File*/
          gotoxy(7,1);
          textcolor(WHITE);
          textbackground(BLACK);    
          cprintf("%s",MenuName1);
          textcolor(BLACK);textbackground(7);
    for(VarX=7;VarX<=14;VarX++)
            { gotoxy(VarX,2); 
              cprintf("%c",196);
              gotoxy(VarX,7);
              cprintf("%c",196);              
             }
    for(VarY=3;VarY<=6;VarY++)
             {gotoxy(6,VarY);
              cprintf("%c",179);
              gotoxy(15,VarY);
              cprintf("%c",179);
             }
          gotoxy(15,7);
          cprintf("%c",217); 
          gotoxy(6,2);
          cprintf("%c",218);
          gotoxy(6,7);
          cprintf("%c",192);
          gotoxy(15,2);
          cprintf("%c",191);
          /* display 4 item in menu File */
          for(Var=0;Var<4;Var++)
          {gotoxy(6+1,2+Var+1);
           cprintf("%s",&OptionMenu1[Var][0]);
          }
          gotoxy(6+1,2+PosOption);
          textbackground(BLACK);
          textcolor(WHITE);
          cprintf("%s",&OptionMenu1[PosOption-1][0]);
          gotoxy(CurX,CurY);
          break;
         }
  case 2:{                           /*menu Edit*/
          gotoxy(27,1);
          textcolor(WHITE);
          textbackground(BLACK);    
          cprintf("%s",MenuName2);
          textcolor(BLACK);textbackground(7);
   for(VarX=27;VarX<=34;VarX++)
      {gotoxy(VarX,2); 
              cprintf("%c",196);
       gotoxy(VarX,4);
              cprintf("%c",196);             
             }
   for(VarY=3;VarY<=3;VarY++)
             {gotoxy(26,VarY);
              cprintf("%c",179);
              gotoxy(35,VarY);
              cprintf("%c",179);
             }
          gotoxy(35,4);
          cprintf("%c",217);
          gotoxy(26,2);
          cprintf("%c",218);
          gotoxy(26,4);
          cprintf("%c",192);
          gotoxy(35,2);
          cprintf("%c",191);
          for(Var=0;Var<1;Var++)
          {gotoxy(27,Var+3);
           cprintf("%s",&OptionMenu2[Var][0]);
          }
          gotoxy(26+1,2+PosOption);
          textbackground(BLACK);
          textcolor(WHITE);
          cprintf("%s",&OptionMenu2[PosOption-1][0]);
          gotoxy(CurX,CurY);
          break;
         }
  case 3:{                            /*menu Search*/
          gotoxy(47,1);
          textcolor(WHITE);
          textbackground(BLACK);    
          cprintf("%s",MenuName3);
          textcolor(BLACK);textbackground(7);
   for(VarX=47;VarX<=54;VarX++)
             {gotoxy(VarX,2); 
              cprintf("%c",196);
              gotoxy(VarX,4);
              cprintf("%c",196);              
             }
   for(VarY=3;VarY<=3;VarY++)
             {gotoxy(46,VarY);
              cprintf("%c",179);
              gotoxy(55,VarY);
              cprintf("%c",179);
             }
          gotoxy(55,4);
          cprintf("%c",217); 
          gotoxy(46,2);
          cprintf("%c",218);
          gotoxy(46,4);
          cprintf("%c",192);
          gotoxy(55,2);
          cprintf("%c",191);
          for(Var=0;Var<1;Var++)
          {gotoxy(47,Var+3);
           cprintf("%s",&OptionMenu3[Var][0]);
          }
          gotoxy(46+1,2+PosOption);
          textbackground(BLACK);
          textcolor(WHITE);
          cprintf("%s",&OptionMenu3[PosOption-1][0]);
          gotoxy(CurX,CurY);
          break;
         }
  case 4:{                        /*menu Help*/
          gotoxy(67,1);
          textcolor(WHITE);
          textbackground(BLACK);    
          cprintf("%s",MenuName4);
          textcolor(BLACK);textbackground(7);
   for(VarX=67;VarX<=74;VarX++)
             {gotoxy(VarX,2); 
              cprintf("%c",196);
              gotoxy(VarX,5);
              cprintf("%c",196);              
             }
   for(VarY=3;VarY<=4;VarY++)
             {gotoxy(66,VarY);
              cprintf("%c",179);
       gotoxy(75,VarY);
              cprintf("%c",179);
              }
          gotoxy(75,5);
          cprintf("%c",217);
          gotoxy(66,2);
          cprintf("%c",218);
          gotoxy(66,5);
          cprintf("%c",192);
          gotoxy(75,2);
          cprintf("%c",191);
          for(Var=0;Var<2;Var++)
          {gotoxy(67,2+Var+1);
           cprintf("%s",&OptionMenu4[Var][0]);
          }
          gotoxy(67,2+PosOption);
          textbackground(BLACK);
          textcolor(WHITE);
          cprintf("%s",&OptionMenu4[PosOption-1][0]);
          gotoxy(CurX,CurY);
          break;
         }
  default:break;
 }/*end of switch(PosMenu)*/
}




main()
{      
 char filename[25]={"UNTITLED"};
 int VarX,VarY,PosMenu,PosOption;

 char textSave[4096];

 clrscr();
 textbackground(BLUE);
 for(VarY=1;VarY<=25;VarY++) /*set background color*/
 {
  for(VarX=1;VarX<=80;VarX++)
   {
    gotoxy(VarX,VarY);
    cprintf("%c",0);
   }
 }

 textcolor(7);       
 for(VarX=1;VarX<=80;VarX++) 
 {
  gotoxy(VarX,1);
  cprintf("%c",219);
  gotoxy(VarX,25);
  if(VarX!=80)                   
     cprintf("%c",219);	
 }
 
 gotoxy(2,25);             /*window bottom tips*/
 textcolor(RED);
 textbackground(7);
 cprintf("F1");            
 textcolor(BLACK);
 cprintf("-File");
 textcolor(RED);
 cprintf("  F2");
 textcolor(BLACK);
 cprintf("-Edit");
 textcolor(RED);
 cprintf("  F3");
 textcolor(BLACK);
 cprintf("-Search");
 textcolor(RED);
 cprintf("  F4");
 textcolor(BLACK);
 cprintf("-Help");
 textcolor(BLUE);
 cprintf(" %c",219);
 textcolor(BLACK);
 cprintf(" line    col");
 textbackground(BLUE);

 textcolor(15);              /*paint white border*/
 for(VarX=2;VarX<=79;VarX++) 
 {
  gotoxy(VarX,2);         
  cprintf("%c",205);
 }
 cprintf("%c",184);    
 gotoxy(1,2);
 cprintf("%c",213);    
 for(VarY=3;VarY<=23;VarY++)
 {
  gotoxy(1,VarY);         
  cprintf("%c",179);
  gotoxy(80,VarY);        
  cprintf("%c",179);
 }
 cprintf("%c",192);    
 for(VarX=2;VarX<=79;VarX++)   
    cprintf("%c",196);
 gotoxy(80,24);
 cprintf("%c",217);    
 /*paint menu content*/
 textcolor(BLACK);
 textbackground(7);
 gotoxy(7,1);
 cprintf("%s",MenuName1);
 gotoxy(27,1);
 cprintf("%s",MenuName2);
 gotoxy(47,1);
 cprintf("%s",MenuName3);
 gotoxy(67,1);
 cprintf("%s",MenuName4);
 textcolor(RED);            
 gotoxy(7,1);cprintf("F");
 gotoxy(27,1);cprintf("E");
 gotoxy(47,1);cprintf("S");
 gotoxy(67,1);cprintf("H");

 
 gotoxy(2,4);
 p=h;
 while(1)
{Start:
     gotoxy(35,2);
     textcolor(WHITE);
	 printf("          ");
     gotoxy(36,2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -