- 注册时间
- 2004-10-6
- 最后登录
- 1970-1-1
|
发表于 2005-4-27 23:01:00
|
显示全部楼层
支持lavax1.0
- long inputw(long object,char maxlenth,char start,char type)
- {
- //Basic module.
- //object: It desides where to store the input string.
- //maxlenth: It desides how many characters can be input once at the most.
- //start: It decides where to start inputing string on the screen.
- //type: bit 0~1:getword mode; bit 2:1 clear object before input; bit 3:1 ESC=Enter, bit 4:1 Blank string allowed
- //It will return how many characters are input, and -1 means user pressed ESC when bit3 equals 0.
- //Its disadvantage is that you can't input characters more than one screen.
- //Common keyborad is demanded.
- //Operation: Left, right, up, down; PageUp: clear the string; F3: go to the start; F4: go to the end.
- char i,col,row;
- char cc,cr,ch;
- char insmd;
- char inpmd;
- int word[2];
- char hz;
- char bk;
- char fl;
- char lenth;
- int n;
- hz=0;
- insmd=0;
- inpmd=0;
- row=start/20;
- col=start%20;
- if (type & 4)
- {
- memset (object,0,maxlenth);
- }
- inpmd=type & 3;
- lenth=strlen(object);
- n=lenth;
- for (;;)
- {
- lenth=strlen(object);
- if (n>lenth)
- {
- n=lenth;
- }
- fl=n;
- memset (_TEXT+start,0,100-start);
- Locate (row,col);
- printf("%s",object);
- //利用printf自动在屏幕上排版
- bk=0;
- i=row;
- while (i*20+18<start+fl)
- {
- if (*(_TEXT+i*20+19)==0)
- {
- fl++;
- }
- if (*(_TEXT+i*20+19)==32)
- {
- if (*(object+i*20+19-start-fl+n)!=32)
- {
- fl++;
- }
- }
- i++;
- }
- cr=(start+fl)/20;
- cc=(start+fl)%20;
- if ((cc==0)&&(n==lenth))
- {
- word[0]=start+fl-1;
- if (word[0]>start)
- {
- if (*(_TEXT+word[0])==0)
- {
- fl--;
- }
- if (*(_TEXT+word[0])==32)
- {
- if (*(object+strlen(object)-1)!=32)
- {
- fl--;
- }
- }
- }
- cr=(start+fl)/20;
- cc=(start+fl)%20;
- }
- if (*(object+n)&128)
- {
- ch=2;
- } else {
- ch=1;
- }
- if (insmd==1)
- {
- Box(8*cc,16*cr,8*(cc+ch)-1,16*(cr+1)-1,1,2);
- } else {
- Line(8*cc,16*cr+15,8*(cc+ch),16*cr+15,2);
- }
- word[0]=GetWord(inpmd);
- inpmd=3;
- ch=word[0]&255;
- if (ch&96)
- {
- if (ch&128)
- {
- bk=2;
- } else {
- bk=1;
- }
- if ((insmd==0)||(n==lenth))
- {
- i=0;
- } else {
- if (*(object+n)&128)
- {
- i=2;
- } else {
- i=1;
- }
- }
- if (lenth+bk-i>=maxlenth)
- {
- Beep();
- continue;
- }
- if (bk-i)
- {
- memmove (object+n,object+n-bk+i,strlen(object+n)+1+bk-i);
- }
- memcpy (object+n,word,bk);
- if (n==lenth)
- {
- n=strlen(object);
- continue;
- }
- n++;
- if (word[0]&128)
- {
- n++;
- }
- continue;
- } else if (ch==LT_KEY)
- {
- n--;
- if (*(object+n)&128)
- {
- n--;
- }
- if (n<0)
- {
- n=lenth;
- }
- continue;
- } else if (ch==RT_KEY)
- {
- n++;
- if (*(object+n-1)&128)
- {
- n++;
- }
- if (n>lenth)
- {
- n=0;
- }
- continue;
- } else if (ch==UP_KEY)
- //对于上下键要特别注意移行后的中文
- {
- if (n<21)
- {
- n=0;
- continue;
- }
- if (*(object+n-21)&128==0)
- {
- n=n-21;
- continue;
- }
- bk=0;
- for (i=n-1;i>n-21;i--)
- {
- bk=bk^*(object+i);
- }
- //逐一检查之间的字节中最高位为1的字节个数
- //通过奇偶判断
- if (bk&128)
- {
- n=n-21;
- } else {
- n=n-20;
- }
- if (n<0)
- {
- n=0;
- }
- continue;
- } else if (ch==DN_KEY)
- {
- if (n+21>lenth)
- {
- n=lenth;
- continue;
- }
- if (*(object+n+21)&128==0)
- {
- n=n+21;
- continue;
- }
- bk=0;
- for (i=n;i<n+20;i++)
- {
- bk=bk^*(object+i);
- }
- if (bk&128)
- {
- n=n+21;
- } else {
- n=n+20;
- }
- if (n>lenth)
- {
- n=lenth;
- }
- continue;
- } else if (ch==F2_KEY&&lenth)
- {
- bk=0;
- if (n^lenth)
- {
- if (*(object+n)&128)
- {
- i=2;
- } else {
- i=1;
- }
- memmove (object+n,object+n+i,strlen(object+n)+1-i);
- } else {
- n--;
- if (*(object+n)&128)
- {
- n--;
- memset(object+n,0,2);
- } else {
- *(object+n)=0;
- }
- }
- continue;
- } else if (ch==F3_KEY)
- {
- n=0;
- continue;
- } else if (ch==F4_KEY)
- {
- n=lenth;
- continue;
- } else if (ch==ENTER_KEY)
- {
- GtRt:
- lenth=strlen(object);
- memset (object+lenth,0,maxlenth-lenth);
- SetScreen (1);
- if ((lenth==0)&&(type&16==0))
- {
- return -1;
- } else {
- return lenth;
- }
- } else if (ch==ESC_KEY)
- {
- if (type&8)
- {
- goto GtRt;
- } else {
- memset (object,0,maxlenth);
- SetScreen (1);
- return -1;
- }
- } else if (ch==F1_KEY)
- {
- insmd=1-insmd;
- } else if (ch==PU_KEY)
- {
- memset (object,0,maxlenth);
- n=0;
- }
- }
- }
复制代码
|
|