文本编辑器源代码

上传人:公**** 文档编号:561824908 上传时间:2022-09-04 格式:DOCX 页数:17 大小:25.70KB
返回 下载 相关 举报
文本编辑器源代码_第1页
第1页 / 共17页
文本编辑器源代码_第2页
第2页 / 共17页
文本编辑器源代码_第3页
第3页 / 共17页
文本编辑器源代码_第4页
第4页 / 共17页
文本编辑器源代码_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《文本编辑器源代码》由会员分享,可在线阅读,更多相关《文本编辑器源代码(17页珍藏版)》请在金锄头文库上搜索。

1、/* AScreen 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/ / / Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx

2、Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx /char bufBUF_SIZE;char *curloc,*endloc;int scrnx,scrny;char killbufKILL_BUF_SIZE;char *helpline=Fl:save F2:load F3:find F4:replace AK:kill line AY:Yank AZ:qiut;void edit(char *fname),help(void);void gotoxy(int x,int y),clrline(int

3、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)

4、;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 fname80;if(argc2)draw_border(0,0,78,24,0x1f);draw_border(20,12,6

5、0,14,0x2f);gotoxy(20,11);printf(7FILE NAME:);gotoxy(21,13);gets(fname);edit(fname);if(argc=2)strupr(argv1);if(strstr(argv1,.EXE)|strstr(argv1,.COM)| strstr(argv1,.OBJ)|strstr(argv1,.LIB)printf(7Cant edit file :%s,argv1);exit(1);else edit(argv1);r.h.ah=6;r.h.al=0;r.h.ch=0;r.h.cl=0;r.h.dh=24;r.h.dl=79

6、;r.h.bh=7;int86(0x10,&r,&r);gotoxy(1,1);void edit(char *fname)union kchar ch2;unsigned i;key; char name80;/* 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

7、 main loop . */do#ifdef TURBOC key.i=bioskey(0);#endifif(!key.ch0)switch(key.ch1)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,.

8、OBJ)|strstr(name,.LIB) gotoxy(1,MAX_LINES); printf(7Cant 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();break;case 79:gotoend();break;case 75: /*left*/left();break;cas

9、e 77:right();break;case 72:upline();break;case 80:downline();break;case 73:pageup();break;case 81:pagedown();break;case 83: /*Del*/if(curlocendloc) delete_char();break;if(curlocbuf)scrnx=scrny=0; curloc=buf;gotoxy(scrnx+1,scrny+1); /*postion cursor */ elseswitch(key.ch0)case r:/*see if buffer is ful

10、l */ if(endloc=buf+BUF_SIZE-2) break;/* move contents of file below current location down one byte to make room for the RETURN.*/ memmove(curloc+1,curloc,endloc-curloc+1); *curloc=key.ch0; /*put RETURN in file */curloc+;/*clear rest of line */ edit_clr_col(scrnx,scrny);scrnx=0;scrny+;/*move text on

11、screen down */ if(scrny=MAX_LINES-1) /*at bottom of page */ scrny=MAX_LINES-2; scrollup(1,1,LINE_LEN,scrny+1);else scrolldn(scrnx+1,scrny+1); gotoxy(scrnx+1,scrny+1); printline(curloc); endloc+;/* advance the end of file pointer */break;case b:if(curloc=buf) break;left();delete_char();break;case 11:

12、kill_line();break;case 25:yank();break;case 26:clrline(MAX_LINES); gotoxy(1,MAX_LINES);printf(If saved file,pressYexit7); if(tolower(getch()=y) goto end; help();break;default:/* enter keystroke into file */*see if buf is full */ if(endloc=buf+BUF_SIZE-2) break;/*cant type past end of line */ if(scrn

13、x=LINE_LEN) break;memmove(curloc+1,curloc,endloc-curloc+1); *curloc=key.ch0;putch(*curloc);scrnx+;gotoxy(scrnx+1,scrny+1); printline(curloc+1); curloc+;endloc+;gotoxy(scrnx+1,scrny+1);while(1);end: printf(n);/ Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx

14、Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx Tx TxDisplay a line pointed to by p.*1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号