📄 curlib.c
字号:
if( debug_yx(y,x,"mvget_char()") == FALSE ) return(FALSE); } move(y,x); refresh(); while (!(ch=get_key())); mvaddch(y,x,ch); refresh(); return ch;}/*----------------------------------------------------------------------------* * FUNCTION: 从(y,x)处得到一个字符并显示. * Argument: * int y - 开始行. * int x - 开始列. * Return : * 输入字符. * 说 明: 光标键除外. *----------------------------------------------------------------------------*/mvgetd(int y,int x){ unsigned char ch; if( need_check_flag == 1 ) { if( debug_yx(y,x,"mvgetd()") == FALSE ) return(FALSE); } move(y,x); refresh(); for(;;) { while (!(ch=get_key())); if( ch == KeyEsc) { if (get_key() ==0 ) break; get_key(); beep(); } else { mvaddch(y,x,ch); refresh(); break; } } return ch;}/*----------------------------------------------------------------------------* * FUNCTION: 从(y,x)处得到一个在字符表中的字符并显示. * Argument: * int y - 开始行. * int x - 开始列. * char *ctable - 字符表. * Return : * 输入字符. * 说 明: 光标键除外. *----------------------------------------------------------------------------*/mvgete(int y,int x,char *ctable){ unsigned char ch; if( need_check_flag == 1 ) { if( debug_yx(y,x,"mvgete()") == FALSE ) return(FALSE); } move(y,x); refresh(); for(;;) { while (!(ch=get_key())); if( ch == KeyEsc) { if (get_key() ==0 ) break; get_key(); beep(); } else { if(is_in(ctable,ch) >=0) { mvaddch(y,x,ch); refresh(); break; } else { beep(); } } } return ch;}/*----------------------------------------------------------------------------* * FUNCTION: 从键盘读一整数 * 变量定义: * int y : 屏幕位置的横坐标; * int x : 屏幕位置的纵坐标; * char *intbuf: 读取的整数存放地址; * int len : 读取的整数的长度; * 返回值: * 0: 被向左箭头移出最左端或移动向上箭头; * 1: 被向右箭头移出最右端或移动向下箭头,或 * 输满所要求长度的字串或按了回车; * -1: 按了 ESC 键; *----------------------------------------------------------------------------*/get_int(int y,int x,int *intbuf,int len){ int atoi(),sign; char strbuf[DATA_LENGTH]; if( need_check_flag == 1 ) { if((debug_yx(y,x,"get_int()") == FALSE) || (debug_rowcol(0,len,"get_int()") == FALSE) || (debug_yx(y,x+len-1,"get_int()") == FALSE) ) return(FALSE); } if(len >= 256) return(-1); *strbuf='\0'; if(abs(*intbuf) > 0) sprintf(strbuf,"%.0f",(double)*intbuf); for(;;) { sign=getline(y,x,strbuf,len,5,"-0123456789"); if(check_intlen(strbuf) <= 9) break; } *intbuf=atoi(strbuf); sprintf(strbuf,"%.0f",(double)*intbuf); mvaddstr(y,x,space(len)); mvaddstr(y,x,strbuf); refresh(); return(sign);}/*----------------------------------------------------------------------------* * FUNCTION: 从键盘读一长整数 * 变量定义: * x : 屏幕位置的横坐标; * y : 屏幕位置的纵坐标; * char * : 读取的长整数存放地址; * len : 读取的长整数的长度; * 返回值: * 0: 被向左箭头移出最左端或移动向上箭头; * 1: 被向右箭头移出最右端或移动向下箭头,或 * 输满所要求长度的字串或按了回车; * -1: 按了 ESC 键; *----------------------------------------------------------------------------*/get_long(int x,int y,long *longbuf,int len){ double atof(); char strbuf[256]; int sign; if(need_check_flag ==1) { if((debug_yx(y,x,"get_long()") ==FALSE) || (debug_rowcol(0,len,"get_long()") ==FALSE) || (debug_yx(y,x+len-1,"get_long()") ==FALSE) ) return(FALSE); } if(len >= 256) return(-1); *strbuf='\0'; if(abs(*longbuf) > (long)0) sprintf(strbuf,"%.0f",(double)*longbuf); for(;;) { sign=getline(x,y,strbuf,len,5,"-0123456789"); if(check_intlen(strbuf) <=9) break; } *longbuf=(long)atof(strbuf); sprintf(strbuf,"%.0f",(double)*longbuf); mvaddstr(x,y,space(len)); mvaddstr(x,y,strbuf); refresh(); return(sign);}/*------------------------------------------------------------------ * FUNCTION: 从键盘读一浮点数 * 变量定义: * x : 屏幕位置的横坐标; * y : 屏幕位置的纵坐标; * char * : 读取的浮点数存放地址; * len : 读取的长度; * dec : 小数点后位数; * * 返回值: * 0: 被向左箭头移出最左端或移动向上箭头; * 1: 被向右箭头移出最右端或移动向下箭头,或 * 输满所要求长度的字串或按了回车; * -1: 按了 ESC 键; *-----------------------------------------------------------------*/get_double(int sy,int sx,double *doublebuf,int len,int dec){ double atof(); char strbuf[DATA_LENGTH]; int sign; if(need_check_flag ==1) { if((debug_yx(sy,sx,"get_double()") ==FALSE) || (debug_rowcol(0,len,"get_double()") ==FALSE) || (debug_yx(sy,sx+len-1,"get_double()") ==FALSE) ) return(FALSE); } if(len >= 256 || len <= dec) return(-1); *strbuf='\0'; if(*doublebuf > 0 || *doublebuf < 0) { switch(dec) { case 0: sprintf(strbuf,"%.0f",(double)(*doublebuf)); break; case 1: sprintf(strbuf,"%.1f",(double)(*doublebuf)); break; case 2: sprintf(strbuf,"%.2f",(double)(*doublebuf)); break; case 3: sprintf(strbuf,"%.3f",(double)(*doublebuf)); break; case 4: sprintf(strbuf,"%.4f",(double)(*doublebuf)); break; case 5: sprintf(strbuf,"%.5f",(double)(*doublebuf)); break; case 6: sprintf(strbuf,"%.6f",(double)(*doublebuf)); break; case 7: sprintf(strbuf,"%.7f",(double)(*doublebuf)); break; case 8: sprintf(strbuf,"%.8f",(double)(*doublebuf)); break; case 9: default: sprintf(strbuf,"%.9f",(double)(*doublebuf)); break; } } strbuf[len]='\0'; for(;;) { sign=getline(sy,sx,strbuf,len,5,"-.0123456789"); if(check_intlen(strbuf) <= 13) break; } *doublebuf=(double)atof(strbuf); switch(dec) { case 0: sprintf(strbuf,"%.0f",(double)*doublebuf); break; case 1: sprintf(strbuf,"%.1f",(double)*doublebuf); break; case 2: sprintf(strbuf,"%.2f",(double)*doublebuf); break; case 3: sprintf(strbuf,"%.3f",(double)*doublebuf); break; case 4: sprintf(strbuf,"%.4f",(double)*doublebuf); break; case 5: sprintf(strbuf,"%.5f",(double)*doublebuf); break; case 6: sprintf(strbuf,"%.6f",(double)*doublebuf); break; case 7: sprintf(strbuf,"%.7f",(double)*doublebuf); break; case 8: sprintf(strbuf,"%.8f",(double)*doublebuf); break; case 9: default: sprintf(strbuf,"%.9f",(double)*doublebuf); break; } strbuf[len]='\0'; mvaddstr(sy,sx,space(len)); mvaddstr(sy,sx,strbuf); refresh(); return(sign);}/*----------------------------------------------------------------------------* * FUNCTION: 从键盘读一串 * 变量定义: * x : 屏幕位置的横坐标; * y : 屏幕位置的纵坐标; * strbuf : 读取的字串存放地址; * col : 读取的字串的长度; * fid : 读取的字串的特性; * = 0 :<字符限定表>为空串时 ,不显示, 接受任意字符; * <字符限定表>为非空串时,显示<字符限定表>的首字符,接受任意字符; * = 1 : 显示, 接受数字字符; * = 2 : 显示, 接受字母字符; * = 3 : 显示, 接受数字加字母字符; * = 4 : 显示, 接受任何字符; * = 5 : 显示, 仅接受指定<字符表>上的字符; * = 6 : 显示, 不接受任意字符; * * = 11: 和=1同, 但要求读满所需长度才能返回; * = 12: 和=2同, 但要求读满所需长度才能返回; * = 13: 和=3同, 但要求读满所需长度才能返回; * = 14: 和=4同, 但要求读满所需长度才能返回; * = 15: 和=5同, 但要求读满所需长度才能返回; * * =-11: 和=11同, 但要求读满所需长度才能返回; * <字符限定表>为空串时 ,不显示; * <字符限定表>为非空串时,显示'*'; * =-12: 和=12同, 但要求读满所需长度才能返回; * <字符限定表>为空串时 ,不显示; * <字符限定表>为非空串时,显示'*'; * =-13: 和=13同, 但要求读满所需长度才能返回; * <字符限定表>为空串时 ,不显示; * <字符限定表>为非空串时,显示'*'; * =-14: 和=14同, 但要求读满所需长度才能返回; * <字符限定表>为空串时 ,不显示; * <字符限定表>为非空串时,显示'*'; * =-15: 和=15同, 但要求读满所需长度才能返回; * <字符限定表>为空串时 ,不显示; * <字符限定表>为非空串时,显示'*'; * ctable : 无条件接受字串的<字符限定表>; * * 返回值: * 0: 被向左箭头移出最左端或移动向上箭头; * 1: 被向右箭头移出最右端或移动向下箭头,或 * 输满所要求长度的字串或按了回车; * -1: 按了 ESC 键; *----------------------------------------------------------------------------*/getline(int sy,int sx,char *strbuf,int col,int fid,char *ctable){ int return_code,sign; if(need_check_flag ==1) { if((debug_yx(sy,sx,"getline()") ==FALSE) || (debug_rowcol(0,col,"getline()") ==FALSE) || (debug_yx(sy,sx+col-1,"getline()") ==FALSE) ) return(FALSE); } return_code=getlinen(sy,sx,strbuf,col,fid,ctable,0); switch(return_code) { case -1:/* ESC */ sign=-1; break; case 0:/* ← */ case 1:/* ↑ */ sign=0; break; case 2:/* → */ case 3:/* ↓ */ case 4:/* KeyEnter */ case 5:/* 输满 */ sign=1; break; default: break; } return sign;}/*----------------------------------------------------------------------------* * FUNCTION: 从键盘读一串 * * 变量定义与上getlinen相同,但返回值不同: * * 返回值: * KeyEsc : 按了 ESC 键; * KeyLeft : 被向左箭头移出最左端; * KeyUp : 移动向上箭头; * KeyRight: 被向右箭头移出最右端; * KeyDown : 移动向下箭头; * KeyEnter: 按了回车,输满所要求长度的字串; *----------------------------------------------------------------------------*/getlineg(int sy,int sx,char *strbuf,int col,int fid,char *ctable){ int return_code,sign; if(need_check_flag ==1) { if((debug_yx(sy,sx,"getlineg()") ==FALSE) || (debug_rowcol(0,col,"getlineg()") ==FALSE) || (debug_yx(sy,sx+col-1,"getlineg()") ==FALSE) ) return(FALSE); } switch(getlinen(sy,sx,strbuf,col,fid,ctable,0)) { case -1:/* ESC */ return KeyEsc; case 0:/* ← */ return KeyLeft; case 1:/* ↑ */ return KeyUp; case 2:/* → */ return KeyRight; case 3:/* ↓ */ return KeyDown; case 4:/* KeyEnter */ case 5:/* 输满 */ return KeyEnter; }}/*----------------------------------------------------------------------------* * FUNCTION: 从键盘读一串 * * 变量定义与上getlinen相同,但返回值不同: * * 返回值: * 0: 被向左箭头移出最左端或移动向上箭头; * 1: 被向右箭头移出最右端或移动向下箭头,或 * 输满所要求长度的字串或按了回车; * -1: 按了 ESC 键; * *----------------------------------------------------------------------------*/getlinem(int sy,int sx,char *strbuf,int col,int fid,char *ctable,int start_pos){ int return_code,sign; if(need_check_flag ==1) { if((debug_yx(sy,sx,"getlinem()") ==FALSE) || (debug_rowcol(0,col,"getlinem()") ==FALSE) || (debug_yx(sy,sx+col-1,"getlinem()") ==FALSE) ) return(FALSE); } return_code=getlinen(sy,sx,strbuf,col,fid,ctable,start_pos); switch(return_code) { case -1:/* ESC */ sign=-1; break; case 0:/* ← */ case 1:/* ↑ */ sign=0; break; case 2:/* → */ case 3:/* ↓ */ case 4:/* KeyEnter */ case 5:/* 输满 */ sign=1; break; default: break; } return sign;}/*----------------------------------------------------------------------------* * FUNCTION: 从键盘读从某位开始的串 * * 变量定义: * x : 屏幕位置的横坐标; * y : 屏幕位置的纵坐标; * strbuf : 读取的字串存放地址; * col : 读取的字串的长度; * fid : 读取的字串的特性; * = 0 :<字符限定表>为空串时 ,不显示, 接受任意字符; * <字符限定表>为非空串时,显示'*',接受任意字符; * = 1 : 显示, 接受数字字符; * = 2 : 显示, 接受字母字符; * = 3 : 显示, 接受数字加字母字符; * = 4 : 显示, 接受任何字符; * = 5 : 显示, 仅接受指定<字符表>上的字符; * = 6 : 显示, 不接受任意字符; * * = 11: 和=1同, 但要求读满所需长度才能返回; * = 12: 和=2同, 但要求读满所需长度才能返回; * = 13: 和=3同, 但要求读满所需长度才能返回; * = 14: 和=4同, 但要求读满所需长度才能返回; * = 15: 和=5同, 但要求读满所需长度才能返回; * * =-11: 和=11同, 但要求读满所需长度才能返回; * <字符限定表>为空串时 ,不显示; * <字符限定表>为非空串时,显示'*'; * =-12: 和=12同, 但要求读满所需长度才能返回; * <字符限定表>为空串时 ,不显示; * <字符限定表>为非空串时,显示'*'; * =-13: 和=13同, 但要求读满所需长度才能返回; * <字符限定表>为空串时 ,不显示; * <字符限定表>为非空串时,显示'*'; * =-14: 和=14同, 但要求读满所需长度才能返回; * <字符限定表>为空串时 ,不显示; * <字符限定表>为非空串时,显示'*'; * =-15: 和=15同, 但要求读满所需长度才能返回; * <字符限定表>为空串时 ,不显示; * <字符限定表>为非空串时,显示'*'; * ctable : 无条件接受字串的<字符限定表>; * start_pos: 起始位置; * * 返回值: * -1: 按了 ESC 键, 或有错; * 0: 被向左箭头移出最左端; * 1: 移动向上箭头; * 2: 被向右箭头移出最右端; * 3: 移动向下箭头; * 4: 按了回车; * 5: 输满所要求长度的字串; *----------------------------------------------------------------------------*/getlinen(int sy,int sx,char *strbuf,int col,int fid,char *ctable,int start_pos){ char *strbuf_ptr,*tmp_ptr,*buf; int i,y,x,endx,len,sign,need_quit,pass_check; unsigned char ch,ch2,ch3,cstar; if(need_check_flag ==1) { if((debug_yx(sy,sx,"getlinen()") ==FALSE) || (debug_rowcol(0,col,"getlinen()") ==FALSE) || (debug_yx(sy,sx+col-1,"getlinen()") ==FALSE) ) return(FALSE); } if( col < 0 ) /* 超界 */ { return(-1); } cstar='*'; buf=(char *)malloc(col+5); *buf='\0';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -