易码技术论坛

 找回密码
 加入易码
搜索
查看: 304330|回复: 12

[求助]谁有文本编辑器的源码?借我参考一下~!

[复制链接]
发表于 2006-7-6 09:27:00 | 显示全部楼层
以下是引用xintu1987在2006-7-2 22:00:00的发言:[BR]我原先有做过一个,你好像也是吧?

做的时候因为时间和技术的问题所以暂时没做工了~

我在编写时遇到几个问题:
1:换行后删除字符的问题,几行可以实现,但太多了就选成显求与写入的不一样~

2:~~~



还有几个问题,但现在想不起来了~

我编写的第一个可以正常写入下面的程序:

void main()
{

printf("中国人");

getchar();

}

可以输入和显示~

但程序太大时就有BUGB~!
你把你遇到的问题也说出来看看~


楼上说有BUG,什么?是不是内存用过量了?
发表于 2006-7-6 16:22:00 | 显示全部楼层
看样子市
发表于 2006-7-6 17:55:00 | 显示全部楼层
已经发在 星迷天地 里了
发表于 2006-6-30 12:11:00 | 显示全部楼层
看来等不到了,自己找吧
 楼主| 发表于 2006-7-1 14:53:00 | 显示全部楼层
等了3个月了~~~
发表于 2006-7-1 15:42:00 | 显示全部楼层
看看吧,可能对你有帮助,这是一段字符输入函数,很简单,希望能祈祷抛砖引玉的作用,

PS 原创不是我





define FONT_SMA 0
#define FONT_LAR 1
#define EDIT_INS 0
#define EDIT_OVR 1
#define KEY_LEFT 23
#define KEY_RIGHT 22
#define KEY_UP 20
#define KEY_DOWN 21
#define KEY_ENTER 13
#define KEY_SHIFT 18
#define KEY_CAPS 26
#define KEY_ESC 27
#define KEY_HELP 25
#define KEY_SPC 32
#define KEY_F1 28
#define KEY_F2 29
#define KEY_F3 30
#define KEY_F4 31
//文字缓存
char textBuf[100];
//保存地址,长度,显示坐标,字体
char Input(long textAdd,char length,char textX,char textY,char font){
char strPt;//字串指针、长度
char curX,curY,curL;//光标坐标、长度
int word;//获得的单个字符的ASCII或GB码
char editMode;
strPt=0;
word=0;
editMode=EDIT_INS;
if(font==FONT_SMA){//判断字体
curL=6;
curY=textY+11;
}
else{
curL=8;
curY=textY+15;
}
while(1){
Refresh();
TextOut(textX,textY,textAdd,0x40+0x80*font);//显示当前字串
curX=textX+strPt*curL;
if(editMode==EDIT_INS){//绘制光标
if(*(textAdd+strPt)>=0xa1){Line(curX,curY,curX+curL*2-1,curY,2);}
else{Line(curX,curY,curX+curL-1,curY,2);}
}else{
if(*(textAdd+strPt)>=0xa1){Box(curX,curY-curL*2,curX+curL*2-1,curY,1,2);}else
{Box(curX,curY-curL*2,curX+curL-1,curY,1,2);}
}
word=GetWord(3);
if(word==KEY_ENTER||word==KEY_ESC){break;}
if(word==KEY_F1){//切换插入、覆盖
if(editMode==EDIT_INS){editMode=EDIT_OVR;}
else{editMode=EDIT_INS;}
continue;
}
if(word==KEY_LEFT){//左移光标
if(strPt>0){
if(*(textAdd+strPt-1)>=0xa1){strPt=strPt-2;}
else{strPt--;}
}
continue;
}
if(word==KEY_RIGHT){//右移光标
if(strPt<strlen(textAdd)){
if(*(textAdd+strPt)>=0xa1){strPt=strPt+2;}
else{strPt++;}
}
continue;
}
if(word==KEY_F2){//删除字符
if(*(textAdd+strPt)==NULL){
if(strPt>0){
if(*(textAdd+strPt-1)>=0xa1){strPt=strPt-2;}
else{strPt--;}
}
}
if(*(textAdd+strPt)>=0xa1){strcpy(textBuf,textAdd+strPt+2);}
else if(*(textAdd+strPt)!=0){strcpy(textBuf,textAdd+strPt+1);}
strcpy(textAdd+strPt,textBuf);
continue;
}
//加入字符
if(!isgraph(word&0xff) && (word>>8==0)){continue;}//合法字符
if(editMode==EDIT_INS||*(textAdd+strPt)==NULL){//插入模式,或是光标在最后为新加的字符腾出空间
if(word>>8!=0&&strlen(textAdd)>=length-1){continue;}//判断长度是否超过规定长度
if(word>>8==0&&strlen(textAdd)>=length){continue;}
strcpy(textBuf,textAdd+strPt);
if(word>>8!=0){strcpy(textAdd+strPt+2,textBuf);}
else{strcpy(textAdd+strPt+1,textBuf);}
}
if(word>>8!=0){//汉字
if(*(textAdd+strPt)<0xA1&&editMode==EDIT_OVR){//覆盖英文或数字
if(strlen(textAdd)>=length)continue;
strcpy(textBuf,textAdd+strPt);
strcpy(textAdd+strPt+1,textBuf);
}
*(textAdd+strPt)=word&0xff;
*(textAdd+strPt+1)=word>>8;
strPt=strPt+2;
}else{//英文或数字
if(strlen(textAdd)>=length&&*(textAdd+strPt)==NULL)continue;
if(*(textAdd+strPt)>=0xA1&&editMode==EDIT_OVR){//覆盖汉字
strcpy(textBuf,textAdd+strPt+1);
strcpy(textAdd+strPt,textBuf);
}
*(textAdd+strPt)=word&0xff;
strPt++;
}
}
if(word==KEY_ESC)return 0;
return!0;
}

void main(){
char text[20];
memset(text,0,20);
Input(text,18,10,10,1);
}




 楼主| 发表于 2006-7-2 13:42:00 | 显示全部楼层
谢谢了
发表于 2006-7-2 22:00:00 | 显示全部楼层
我原先有做过一个,你好像也是吧?

做的时候因为时间和技术的问题所以暂时没做工了~

我在编写时遇到几个问题:
1:换行后删除字符的问题,几行可以实现,但太多了就选成显求与写入的不一样~

2:~~~



还有几个问题,但现在想不起来了~

我编写的第一个可以正常写入下面的程序:

void main()
{

printf("中国人");

getchar();

}

可以输入和显示~

但程序太大时就有BUGB~!
你把你遇到的问题也说出来看看~
 楼主| 发表于 2006-3-18 13:58:11 | 显示全部楼层 |阅读模式
如题~
发表于 2008-1-5 17:12:06 | 显示全部楼层

源码

这是我通过把E路客的那个缩小了后再理解~
然后修改的~原理很简单~!
因在网吧,没时间上传优化好的~

下面的存在一些BUG:


下次再发已更新的~


#define TSL 16384 //文本长度最大
#define DTIME 32 //频控制的最短时间
#define NOWDMAX 48//路径字符串的最大长度
#define C_ONPC 0  //“是否在PC上运行”选项的序号

char numkey[11]="0bnmghjtyu";   //键盘键值表
char punkey[18]="qwerasdfzxcviopkl";
char punto[18]="+-*/;' =()[],<>{}";   //键值表中按键对应的符号
char punkeyb[15]="bnmghjtyu.    ";
char puntob[15]=" %:|~?!&#_`^$@";
char txt_h[26]={0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x18,0x0,0x0,0x1a,0x0,0x0,0x0,0x0,0x0,0x18,0x0,0x0,0x1a,0x0,0x0,0x0,0x0,0xd,0xa};  //TXT文件的文件头(TC800没有)
char cian,ciul;   //英数和大小写输入法状态的标记
char clips=0;  //剪贴板的标记,0为用内存,1为用文件
char cfg[2]=" ";  //配置选项表,'.'为真,' '为假
char nowd[48],str[60],sstr[25],clip[1025],ts[TSL+1],ab[30],ac[30];
long qq,clipl=0;  
//str:字符串传递、临时存放处;sstr:搜索的字串;nowd:路径字串传递;clip:剪贴板;ts:放文本的主空间;clipl:剪贴板长度




long input(long xx){
char k,td[26];
long tnp,nowo,i,ens;
int ciam,a,b;
memset(td,0,26);
nowo=td;
ciam=1;
ClearScreen();
while(1){
AAA:
if(ciam==0)TextOut(1,68,"A",2);
else TextOut(1,68,"a",2);
TextOut(1,1,xx,1);
TextOut(1,13,td,1);
a=(nowo-td)*6+1;
ens=td+strlen(td);
Block(a,13,a+1,26,1);
Refresh();
ClearScreen();
k=getchar();
if(k==26){ciam=ciam==0;goto AAA;}

if(k==29){
if(nowo<=td)continue;
memmove(nowo-1,nowo,ens-nowo);
nowo--;*(ens-1)=0;ens--;
continue;
}
if(k==27)return 0;
if(k==13)return td;
if(k==23)nowo--;
if(k==22)nowo++;

if(ciam){//小写
if(isprint(k)){
if(26-strlen(td)<1)goto AAA; //插入字符
memmove(nowo+1,nowo,ens-nowo);
ens++;*nowo=k;nowo++;
  }
}
else if(isprint(k)){
if(26-strlen(td)<1)goto AAA;
memmove(nowo+1,nowo,ens-nowo);
ens++;*nowo=toupper(k);nowo++;
}

if(nowo<td)nowo=td;

}//while结束


}









long openfile(int a)
{
char filea[60];
char lj[60];
char qc[60];


int i,n,tmp;
tmp=n=0;i=1;

memmove(lj,qc,60);
ChDir("/");strcat(lj,"/");
for(;;){
  if(!FileList(filea)||!strcmp(filea,".."))
   { tmp--;i=i-n-1;
     memmove(lj+i,qc,n);
    if(tmp<0){memmove(lj,qc,60);
              break;}
    ChDir("..");continue;
   }

if(ChDir(filea)){
  n=strlen(filea);
  strcat(lj,filea);i=i+n;
  strcat(lj,"/");i++;
  tmp++;continue;
                   }
else tmp--;strcat(lj,filea);
     n=strlen(filea);i=i+n;
     if(a==0)return lj;
     if(a==1)return filea;
      }

}



/////////////////
//用带阴影的框显示t指向的字串
char dia(int t){
char w,k;w=strlen(t)*3;TextOut(80-w,34,t,65);k=getchar();return(k);
}

///////////////////////////////
//显示菜单,返回所选的项号
char menu(int title,int a,int b,int c){
char k,n;k=0;n=1;
Box(14,9,146,71,1,0);Box(15,10,145,70,0,1);
TextOut(18,13,title,65);
TextOut(19,28,"A",65);TextOut(32,28,a,65);
TextOut(19,41,"B",65);TextOut(32,41,b,65);
TextOut(19,54,"C",65);TextOut(32,54,c,65);
Line(17,26,143,26,1);Line(29,27,29,68,1);
Circle(136,18,4,1,1);
Box(134,18,138,19,1,0);
while(k!=13){
Box(18,15+n*13,26,27+n*13,1,2);
k=getchar();
Box(18,15+n*13,26,27+n*13,1,2);
if(k==21&&n<3)n++;
else if(k==20&&n>1)n--;
else if(k==27)return(0);
else if(k=='a')return(1);
else if(k=='b')return(2);
else if(k=='c')return(3);
}
return(n);
}


///////////
//判断nowp所指向的字节是否是中文的右半字节,*nowp要>=160,end是终点
long ismid(long nowp,long end){
long i;
for(i=nowp;*i>=160&&i>=end;i--);
return(!((nowp-i)%2));
}


/////////////////
//自己写的输入法
char inputc(){
char k;char show[30];
long i;
AAA:if(cian==0)TextOut(1,1,"E",66);else TextOut(1,1,"n",66);
if(ciul==0)TextOut(1,14,"A",66);else TextOut(1,14,"a",66);
k=getchar();
if(k==26){
  cian=cian==0;
  goto AAA;
}
if(k==18){
  ciul=ciul==0;
  goto AAA;
}
if(cian){
  for(i=0;i<10;i++)if(k==numkey)return(i+48);
  for(i=0;i<17;i++)if(k==punkey)return(punto);
}else{
  if(k=='0'){
    Box(5,13,155,79,1,0);Box(6,14,154,78,0,1);
    TextOut(7,40," + - * / !   & # , < >",65);
    strcpy(show," ; '   = |   ~ ? { }");show[5]=34;TextOut(7,54,show,65);
    strcpy(show," ( ) [ ]     % :");show[9]=92;TextOut(7,66,show,65);
    TextOut(7,28,"字母键:↓空格:` 小数点:_",65);
    TextOut(7,16,"请选择符号: F1-F3: ^ $ @",65);k=getchar();for(i=0;i<17;i++)if(k==punkey)return(punto);for(i=0;i<14;i++)if(k==punkeyb)return(puntob);return(0);
    }
  if(ciul){if(isprint(k))return(k);}
  else return(toupper(k));
}
if(k=='.')return('.');
if(k==' ')return(' ');
return(k);
}

/////////////////
//向地址b的前面搜索换行符,实际作用是返回b指向的字节所在文本行的第一字符的地址
long backsearch(long b){
long i,tmp;
tmp=strchr(ts,13);
if(tmp>b||!tmp)return(ts);
for(i=b;*i!=13;i--);
return(i+2);
}


///////////////////////////
//以下为最主要的函数,运行前要先将文本载入ts。
long codeedit(char m){
char new,nomove,f,k,lkey;//new:屏幕指针移动标记,0不移动,1令屏幕指针hh[0]指向光标所在行的行首,2:hh[0]下移一行,这么做比较省时;nomove:0为屏幕无相对滚动,1为有滚动;f:文件句柄;k:存键值;lkey:标记是否连续响应按键
char show[30];//显示缓冲
long lasttime,tmp,end,sx,lasth,nowp,start,i,x,y,a,b;//lasttime:频控制用;tmp,a,b:临时变量,生存期短时用;end,nowp,start:指针变量(指针变量也可为int型),分别指向文本尾,光标处和复制起点(值-1时为无设定);sx:屏幕右滚偏移量;lasth:最后一行相对屏幕所在行,值9时为不在屏幕里
long aa,bb,o,l,ii,ll,hh[7],hl[7];//hh:指针,指向屏幕上每行的行首地址;hl:每行长度
nowp=hh[0]=ts;new=0;nomove=0;lkey=0;y=0;sx=0;nowp=ts;start=-1;lasttime=Getms();show[25]=0;l=-1;
while(1){
end=ts+strlen(ts);
y=0;lasth=9;
//移动屏幕指针
if(nowp<hh[0]){
  hh[0]=backsearch(nowp-1);
}else if(new==2){
hh[0]=hh[1];
}
//变量y为光标所在行相对屏幕的行号,以下为y,hh,hl赋值
for(i=0;i<6;i++){
  if(nowp>=hh)y=i;
  tmp=strchr(hh,13);
  if(tmp){hh[i+1]=tmp+2;hl=hh[i+1]-hh-2;}
  else {lasth=i;hl=strlen(hh);break;}
  }
if(nowp-hh[y]-sx>24)sx=nowp-hh[y]-24;
if(nowp-hh[y]<sx)sx=nowp-hh[y];
//显示

ClearScreen();
for(i=0;i<6;i++){

if(lasth==y);
else {
memcpy(show,hh+sx,25);
if(sx>hl)show[0]=0;
tmp=strchr(show,13);
if(tmp){*tmp=27;*(tmp+1)=0;}
}
TextOut(8,i*13+2,show,1);
}
if(l!=-1)TextOut(1,27,".",2);
if(sx>0)TextOut(1,68,"<",2);
x=(nowp-hh[y]-sx)*6+8;
Block(x,y*13+2,x+1,y*13+13,2);
Rectangle(7,1,159,80,1);
Refresh();
new=0;

k=inputc();
Delay(55);

if(k==20){
a=nowp-hh[y];
b=backsearch(hh[y]-3);
tmp=strchr(b,13);
if(a>tmp-b)nowp=tmp;
else nowp=b+nowp-hh[y];

}

else if(k==21){
if(y==5)new=2;
a=nowp-hh[y];
tmp=strchr(hh[y+1],13);
if(!tmp)continue;
if(a>tmp-hh[y+1])nowp=hh[y+1]+tmp-hh[y+1];
else nowp=hh[y+1]+a;
}

else if(k==22){
if(*nowp>160)nowp=nowp+2;else nowp++;if(*nowp==10){nowp++;if(y==5)new=2;}
}

else if(k==23){
if(*nowp>160)nowp=nowp-2;else nowp--;if(*nowp==10)nowp--;
}

else if(k==19){if(sx==0)continue;sx--;}
else if(k==14){sx++;}
else if(k==27){
f=fopen("/文本文件/xintu.txt","w");
if(!f){fclose(f);continue;}
fwrite(ts,1,end-ts,f);
fclose(f);exit(0);
}
else if(k==13){
if(y==5)new=2;
memmove(nowp+2,nowp,end-nowp);
*nowp=13;*(nowp+1)=10;
end=end+2;nowp=nowp+2;
}
else if(k==29){
if(*(nowp-1)==10||*(nowp-1)>160){
memmove(nowp-2,nowp,end-nowp);
*end=0;*(end-1)=0;end=end-2;nowp=nowp-2;
}
else {memmove(nowp-1,nowp,end-nowp);
  *end=0;end--;nowp--;
}
}
发表于 2008-1-5 17:12:41 | 显示全部楼层
else if(k==30){
Box(10,5,135,65,1,0);//反显
Box(10,5,135,78,0,1);//外边框
Box(12,77,137,79,1,1);//下投影
Box(136,7,137,79,1,1);//右投影
Line(12,21,133,21,1);//直线
TextOut(46,7,"功能选择",65);
TextOut(24,23,"F:查找 F3:续查",65);
TextOut(12,37,".:设起点 z:清空内存",65);
TextOut(12,50,"C:复制 V:粘贴 D:删除",65);
TextOut(12,63,"X:剪切 H:替换 L:保留",65);
b=getchar();
if(b=='f'){ClearScreen();ii=input("请输入查找的字符串");
  strcpy(sstr,ii);tmp=strstr(nowp,sstr);
   if(tmp){nowp=tmp+1;hh[0]=backsearch(tmp);
   }
   else {nowp=nowp;
   TextOut(46,20,"未找到!",2);Refresh();Delay(333);
   }
}
if(b==30){tmp=strstr(nowp,sstr);if(tmp){nowp=tmp+1;   hh[0]=backsearch(tmp);
    }
   else {
    nowp=nowp;
TextOut(46,20,"未找到!",2);Refresh();Delay(333);
    }
}//f结束
if(b=='.'){l=nowp;}//.结束
if(b=='d'){if(l==-1){TextOut(46,20,"未设计起点!",2);Refresh();getchar();continue;}
if(nowp<l){TextOut(46,20,"不能在起点前!",2);Refresh();getchar();l=-1;continue;}
aa=nowp-l;
memmove(l,nowp,end-nowp);
memset(end-aa,0,aa);
nowp=nowp-aa;l=-1;
}//d结束
if(b=='c'){if(l==-1){TextOut(46,20,"未设计起点!",2);Refresh();getchar();continue;}
if(abs(nowp-l)<1024){
TextOut(46,20,"复制中...!",2);Refresh();Delay(333);f=fopen("/xintu.mem","wb");
if(!f){TextOut(46,20,"电力或空间不足!",2);Refresh();getchar();continue;}
  aa=abs(nowp-l);if(nowp>l)bb=l;else bb=nowp;
  fwrite(bb,1,aa,f);bb=1;fclose(f);
}
}//c结束
if(b=='v'){
    if(bb){
     TextOut(46,20,"粘贴中..!",2);Refresh();Delay(333);f=fopen("/xintu.mem","rb");
     memmove(nowp+aa,nowp,end-nowp);
     fread(nowp,1,l,f);
     l=-1;fclose(f);
   }
}//v结束
if(b=='x'){
if(l==-1){TextOut(46,20,"未设计起点!",2);Refresh();getchar();continue;}
if(abs(nowp-l)<1024){
TextOut(46,20,"复制中...!",2);Refresh();Delay(333);f=fopen("/xintu.mem","wb");
if(!f){TextOut(46,20,"电力或空间不足!",2);Refresh();getchar();continue;}
  aa=abs(nowp-l);if(nowp>l)bb=l;else bb=nowp;
  fwrite(bb,1,aa,f);bb=1;fclose(f);
}
if(nowp<l){TextOut(46,20,"不能在起点前!",2);Refresh();getchar();l=-1;continue;}
aa=nowp-l;
memmove(l,nowp,end-nowp);
memset(end-aa,0,aa);
nowp=nowp-aa;l=-1;
}//X结束
if(b=='h'){
ClearScreen();ii=input("请输入要查找的字符串");
         if(!ii){TextOut(46,20,"无输入!",2);Refresh();Delay(333);continue;}
  strcpy(sstr,ii);tmp=strstr(nowp,sstr);
   if(tmp){nowp=tmp+1;hh[0]=backsearch(tmp);
   }//输入查
   else {nowp=nowp;TextOut(46,20,"未找到!",2);Refresh();Delay(333);continue;}
   
   strcat(ab,ii);aa=strlen(ab);
   ii=input("请输入要替换的字符串");if(!ii){TextOut(46,20,"无输入!",2);Refresh();Delay(333);continue;}
   strcat(ac,ii);bb=strlen(ac);
   if(aa<bb){
   memmove(nowp+bb,nowp,end-nowp);
   memmove(nowp,ac,bb);end=end+bb-aa;
   }
   else {
   memmove(nowp,ac,bb);
   memmove(nowp,nowp+bb,end-nowp);
   }
  
   }//H结束



if(b=='z'){DeleteFile("/xintu.mem");l=-1;aa=bb=0;}




  }//30结束


else if(isprint(k)){//插入字符
memmove(nowp+1,nowp,end-nowp);
*nowp=k;nowp++;end++;
}
if(nowp<ts)nowp=ts;
if(nowp>end)nowp=end;
}//while结束
}
///////////////////
void main(){
char f,w;
long fsize,l;
memset(ts,0,TSL+1);
cian=0;ciul=1;
punto[6]=34;puntob[0]=92;punkeyb[11]=28;punkeyb[12]=29;punkeyb[13]=30;memset(sstr,0,19);l=1;
while(1){
ClearScreen();
TextOut(30,5,"文本编译器",1);
TextOut(33,20,"1.打开文本",1);
TextOut(35,33,"2.新建文本",1);
TextOut(37,46,"3.退出",1);
Block(30,l*13+6,100,l*13+18,2);
Refresh();
w=getchar();
if(w==20&&l>1)l--;
if(w==21&&l<3)l++;
if(w==13)break;
}//while结束

if(l==1){
qq=openfile(0);
strcat(nowd,qq);
f=fopen(nowd,"r");if(!f){dia("打开失败!");}
fsize=fseek(f,0,2);
if(cfg[C_ONPC]==' ')fsize=fsize-24;
if(fsize>TSL){dia("文件大小超过上限");fclose(f);return;}
if(cfg[C_ONPC]==' ')fseek(f,24,0);else rewind(f);
fread(ts,1,fsize,f);
fclose(f);codeedit(1);
}
if(l==2){
f=fopen("/LavaData/xin.dat","wb");if(!f){dia("打开失败!");}
rewind(f);
fread(ts,1,1,f);
fclose(f);codeedit(1);

}
if(l==3)exit(0);
}//程序结束
发表于 2008-1-5 17:15:00 | 显示全部楼层

原理很简单的哦!

真的很多软件的原理都很简单
但是少了算法~也就是思路~
发表于 2008-1-19 15:50:00 | 显示全部楼层
建议加上[code][/code]
您需要登录后才可以回帖 登录 | 加入易码

本版积分规则

Archiver|手机版|小黑屋|EMAX Studio

GMT+8, 2024-4-20 21:19 , Processed in 0.010720 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表