- 注册时间
- 2005-9-12
- 最后登录
- 1970-1-1
|
发表于 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--;
}
} |
|