文本编辑器源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/* A Screen Editer Subsystem */

#define TURBOC

#include

#include

#include

#include

#include

#define BUF_SIZE 32000

#define LINE_LEN 79-2

#define MAX_LINES 24-1

#define KILL_BUF_SIZE 4*LINE_LEN

/***********************************************************/

char buf[BUF_SIZE];

char *curloc,*endloc;

int scrnx,scrny;

char killbuf[KILL_BUF_SIZE];

char *helpline="F1:save F2:load F3:find F4:replace ^K:kill line ^Y:Yank ^Z:qiut"; /*************************************************************/ void edit(char *fname),help(void);

void gotoxy(int x,int y),clrline(int y);

void edit_clr_col(int x,int y),clrscr(void);

void printline(char *p),delete_char(void);

void search(void),kill_line(void);

void scrolldn(int x,int y);

void scrollup(int topx,int topy,int endx,int endy);

void upline(void);

void downline(void),left(void),right(void);

void display_scrn(int x,int y,char *p);

void pagedown(void),pageup(void),replace(void);

void home(void),gotoend(void),yank(void);

int load(char *fname),save(char *fname);

void edit_gets(char *str);

void draw_border(int,int,int,int,int);

/***************************************************/

main(int argc,char *argv[])

{

union REGS r;

char fname[80];

if(argc<2)

{

draw_border(0,0,78,24,0x1f);

draw_border(20,12,60,14,0x2f);

gotoxy(20,11);

printf("\7FILE NAME:");

gotoxy(21,13);

gets(fname);

edit(fname);

}

if(argc==2)

{

strupr(argv[1]);

if(strstr(argv[1],".EXE")||strstr(argv[1],".COM")||\

strstr(argv[1],".OBJ")||strstr(argv[1],".LIB"))

{

printf("\7Can't edit file :%s",argv[1]);

exit(1);

}

else edit(argv[1]);

}

r.h.ah=6;

r.h.al=0;

r.h.ch=0;

r.h.cl=0;

r.h.dh=24;

r.h.dl=79;

r.h.bh=7;

int86(0x10,&r,&r);

gotoxy(1,1);

}

/******************************************************************/ void edit(char *fname)

{

union k

{

char ch[2];

unsigned i;

}key;

char name[80];

/* try to load the file */

if(!load(fname))curloc=endloc=buf;

strcpy(name,fname);

/* set initial values to X,Y coordinate vars */

scrnx=scrny=0;

display_scrn(0,0,curloc);

help();

gotoxy(1,1);

/* editer main loop . */

do{

#ifdef TURBOC

key.i=bioskey(0);

#endif

if(!key.ch[0])

{

switch(key.ch[1])

{

case 59: /*F1 :save file */

save(name);

break;

case 60: /*F2: load file */

clrline(MAX_LINES);

gotoxy(1,MAX_LINES);

printf("Enter filename :");

edit_gets(name);

strupr(name);

if(strstr(name,".EXE")||strstr(name,".COM")||\

strstr(name,".OBJ")||strstr(name,".LIB"))

{

gotoxy(1,MAX_LINES);

printf("\7Can't edit file: %s",name);

getch();

help();

break;

}

if( * name) load(name);

help();

display_scrn(0,0,curloc);

scrnx=scrny=0;

break;

case 61:

search();

break;

case 62:

replace();

break;

case 71:

home();

相关文档
最新文档