⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comment.cpp

📁 这是unix下的图形库,是文本图形库 非常好
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	case 10:	case 12:		if ( day > 31 ) 			return 1;		else 			break;	case 4:	case 6:	case 9:	case 11:		if ( day > 30 ) 			return 1;		else 			break;	case 2:		if (leapyear) {			if ( day > 28 ) 				return 1;			else 				break;		} else {			if (day > 29 ) 				return 1;			else 				break;		}	case 0:		break;	default:		return 1;	}	return 0;}/* *  判断datastr(格式mm/dd/yyyy)的合理性 */static int	Isdatetype1(char *datestr, int i, int j){	int	Isleapyear(int );	int	year, month, day, leapyear;	datetoint(datestr, &year, &month, &day, 1);	if ( (i == 1) && ( *(datestr + i - 1) == '0') && (j == '0') )		return 1;	if ( (i == 4) && ( *(datestr + i - 1) == '0') && (j == '0') )		return 1;	if ( (i == 6) && (year < 1000) ) 		return 1;	leapyear = Isleapyear(year);	switch ( month ) {	case 1:	case 3:	case 5:	case 7:	case 8:	case 10:	case 12:		if ( day > 31 ) 			return 1;		else 			break;	case 4:	case 6:	case 9:	case 11:		if ( day > 30 ) 			return 1;		else 			break;	case 2:		if (leapyear) {			if ( day > 28 ) 				return 1;			else 				break;		} else {			if (day > 29 ) 				return 1;			else 				break;		}	case 0:		break;	default:		return 1;	}	return 0;}/* *  输入日期型字符串 *  入口: win  --  窗口指针 *        y,x  --  输入位置(相对于win窗口)  *        fmt  --  格式字符串 *         s   --  存储此日期型字符串的字符指针 *  出口: <0   --  操作有误 *        >0   --  返回的控制键ASCII码值 */int	inputdate(WINDOW *win, int y, int x, char *fmt, char *s){	char	initdate[11];	char	initdate_1[11];	int	i, j, lflag, rflag, eflag;	int	y1, x1, fmtflag;	if (fmt[0] == '\0')		strcpy(fmt, "YMD");	if (str_isalpha(fmt))		return - 1;	str_toupper(fmt);	if (!strcmp(fmt, "MDY")) {		strcpy(initdate, "00/00/0000");		fmtflag = 1;	} else {		strcpy(initdate, "0000/00/00");		fmtflag = 0;	}	if ((*(s + 0)) != '\0') {		outstr(win, y, x, 10, s);		strcpy(initdate, s);	} else if (initdate[2] == '/') {		outstr(win, y, x, 10, "  /  /    ");		strcpy(s, "00/00/0000");	} else {		outstr(win, y, x, 10, "    /  /  ");		strcpy(s, "0000/00/00");	}	strcpy(initdate_1, initdate);	wmove(win, y, x);	i = 0;	lflag = 1;	rflag = 0;	eflag = 0;	do {		wrefresh(win);		j = wgetch(win);		getyx(win, y1, x1);		if (x1 >= x + 9)			rflag = 1;		else			rflag = 0;		if (x1 <= x)			lflag = 1;		else			lflag = 0;		if (isdigit(j)) {			*(initdate + i) = j;			if (fmtflag == 0) {				if ( Isdatetype(initdate, i, j) ) {					strcpy(initdate, initdate_1);					beep();					continue;				} else 					strcpy(initdate_1, initdate);			} else {				if ( Isdatetype1(initdate, i, j) ) {					strcpy(initdate, initdate_1);					beep();					continue;				} else 					strcpy(initdate_1, initdate);			}			*(s + i) = (char)j;			mvwaddch(win, y1, x1, (char)j);			if (!rflag) {				i++;				if (initdate[i] == '/') {					i++;					wmove(win, y1, x1 + 2);				}			} else				wmove(win, y1, x1);		} else {			switch (j) {			case 2:			case 3:			case 4:			case 10:			case 14:			case 16:			case 258:			case 259:				eflag = 1;				break;			case 260:			case 8:				if (lflag) {					i = 0;					wmove(win, y, x);				} else {					i--;					if (initdate[i] == '/') {						i--;						wmove(win, y1, x1 - 2);					} else						wmove(win, y1, x1 - 1);				}				break;			case 261:			case 32:				if (rflag) {					i = 9;					wmove(win, y, x + 9);				} else {					i++;					if (initdate[i] == '/') {						i++;						wmove(win, y1, x1 + 2);					} else						wmove(win, y1, x1 + 1);				}			}		}	} while (!eflag);	*(s + strlen(s)) = '\0' ;	return j;}/* *  功能描述: *  在字符串某位置pos向右偏移n位,在此位置截取长度为len的字符子串 *  返回值: *          <0 ---  操作有误 *           1 ---  操作正确 */int	rightstrn(const char *s, int pos, int len, int n, char *t){	int	i, j, flag = 0;	for (i = 0; i <= n; i++)		if (*(s + pos + i) == '\0')			return - 1;	for (i = pos + n, j = 0; i < pos + n + len; i++, j++)		if (*(s + i) == '\0')			return - 2;		else			*(t + j) = *(s + i);	*(t + strlen(t)) == '\0';	return 1;}/*在源字符串s1的某位置截取长度为leng的子字符串复制给目的字符串s2 */void	s1cptos2(char *s1, int pos, int leng, char *s2){	int	i, j, len, leng1;	leng1 = leng;	len = strlen(s1);	if (pos + leng1 > len)		leng1 = len - pos;	for (i = 0, j = pos; i < leng1; i++, j++)		*(s2 + i) = *(s1 + j);	for (j = leng - leng1; j > 0; i++, j--)		*(s2 + i) = ' ';	*(s2 + i) = '\0';}static int	chofstr(char ch){	return 0;}static int	chofdigit(char ch){	return ( (ch >= '0' && ch <= '9') ?  0 : 1 );}static int	chofdouble(char ch){	return ( (ch >= '0' && ch <= '9' || ch == '.' || ch == '-' || ch == 'e' || ch == 'E') ?  0 : 1 );}static int	chofalpha(char ch){	return ( (ch >= 'a' && ch <= 'z'  ||   ch >= 'A' && ch <= 'Z') ?  0 : 1 );}static int	chofalphanum(char ch){	return ( (ch >= 'a' && ch <= 'z'  ||  ch >= 'A' && ch <= 'Z'  ||  ch >= '0' && ch <= '9' ) ?  0 : 1 );}static int	chofchinese(char ch){	return ( (ch < 0) ?  0 : 1 ) ;}static int	chofprint128(char ch){	return ( ( ch > 31 && ch < 127 ) ?  0 : 1 );}static int	chofint(char ch){	return ( (ch >= '0' && ch <= '9' || ch == '-') ?  0 : 1 );}static int	funstatus(int type , char ch){	int	chofstr(char);	int	chofdigit(char);	int	chofdouble(char);	int	chofalpha(char);	int	chofalphanum(char);	int	chofchinese(char);	int	chofprint128(char);	int	chofint(char);	int	(*funpoint[8])(char);	funpoint[0] = chofstr;	funpoint[1] = chofdigit;	funpoint[2] = chofdouble;	funpoint[3] = chofalpha;	funpoint[4] = chofalphanum;	funpoint[5] = chofchinese;	funpoint[6] = chofprint128;	funpoint[7] = chofint;	return ( *funpoint[type])(ch);}/* *  功能描述: 在窗体某一位置输入一定长度的字符串 *  函数入口: win      --  窗体指针 *            y,x      --  窗体坐标 *			  c_x      --  光标停留位置 *            leng     --  在窗体中显示的子字符串长度 *            lengmax  --  字符串的总长度 *            s        --  存放字符串的指针 *            type     --  字符串虚拟类型 *              0      --  可打印字符,值在 32 ~ 255 之间  *              1      --  只能输入 0 ~ 9 十进制数字 *              2      --  只能输入数字,负号和小数点 *              3      --  只能输入大小写字母 *              4      --  只能输入字母和十进制数字 *              5      --  只能输入扩展ASCII码代表的字符,如: 中文和制表 *              6      --  只能输入 32 ~ 126 之间的字符 *              7      --  只能输入数字和负号 *            helpy,helpx -- 帮助主题出现的位置 *            helpstr  --  帮助主题 *  函数出口: 返回控制键值(键CTRL_A不返回,它是输入模式下的插入状态和 * */int	inputstr(WINDOW *win, int y, int x, int c_x,int leng, int lengmax, char *s, int type, int helpy, int helpx, char *helpstr){	/***			void	s1cptos2(char * , int , int , char *);			void 	inschstrover(char ,int ,char *);			void 	covchstr(char ,int ,char *);			void 	bkspchstr(char * ,int );			void 	delchstr(char * ,int );			void 	_showmessage(int ,int ,char * ,int );			***/	int	funstatus(int , char );	char	tmpstr[512];	int	cur_posi, j, modiflag, lflag, rflag, hflag, eflag, endloop;	int	y1, x1, yend, xend;	static int	insflag = 1;	if (leng > lengmax)		return - 100;	for (j = strlen(s); j < lengmax; j++)		*(s + j) = ' ';	*(s + j) = '\0';	cur_posi = c_x-x;	modiflag = 0;	endloop = 0;	yend = y;	xend = x + leng - 1;	s1cptos2(s, 0, leng, tmpstr);	mvwaddstr(win, y, x, tmpstr);	wmove(win, y, c_x);	do {		getyx(win, y1, x1);		if (x1 <= x)			lflag = 1;		else			lflag = 0;		if (x1 >= x + leng - 1)			rflag = 1;		else			rflag = 0;		if (cur_posi == 0)			hflag = 1;		else			hflag = 0;		if (cur_posi >= (lengmax - 1))			eflag = 1;		else			eflag = 0;		j = wgetch(win);		if (j > 31 && j < 256 && j != 127) {			if ( funstatus(type, (char)j) ) {				beep();				continue;			}			if (insflag)				inschstrover( (char)j, cur_posi , s);			else				covchstr( (char)j , cur_posi , s );			modiflag = 1;			if (eflag == 0)				cur_posi++;			if (rflag == 0) {				s1cptos2(s, cur_posi - 1 - x1 + x, leng, tmpstr);				mvwaddstr(win, y, x, tmpstr);				wrefresh(win);				wmove(win, y1, x1 + 1);			} else {				s1cptos2(s, cur_posi - leng + 1, leng, tmpstr);				mvwaddstr(win, y, x, tmpstr);				wrefresh(win);				wmove(win, yend, xend);			}		} else			switch (j) {			case 1:				insflag = !insflag;				break;			case 8:				if (lflag == 1) {					if (hflag == 0) {						bkspchstr(s, cur_posi);						cur_posi--;						if (cur_posi >= leng - 1) {							s1cptos2(s, cur_posi - leng + 1, leng, tmpstr);							mvwaddstr(win, y, x, tmpstr);							wmove(win, yend, xend);						} else {							s1cptos2(s, 0, leng, tmpstr);							mvwaddstr(win, y, x, tmpstr);							wmove(win, y, x + cur_posi);						}					}				} else {					bkspchstr(s, cur_posi);					cur_posi--;					s1cptos2(s, cur_posi - x1 + x + 1, leng, tmpstr);					mvwaddstr(win, y, x, tmpstr);					wmove(win, y1, x1 - 1);				}				modiflag = 1;				break;			case 9:				showmessage(helpy, helpx, helpstr);				touchwin(win);				wrefresh(win);				break;			case 127:				delchstr(s, cur_posi);				s1cptos2(s, cur_posi - x1 + x, leng, tmpstr);				mvwaddstr(win, y, x, tmpstr);				wmove(win, y1, x1);				modiflag = 1;				break;			case 260:				cur_posi--;				if (lflag == 1) {					if (hflag == 1)						endloop = 1;					else {						if (cur_posi >= leng - 1) {							s1cptos2(s, cur_posi - leng + 1, leng, tmpstr);							mvwaddstr(win, y, x, tmpstr);							wmove(win, yend, xend);						} else {							s1cptos2(s, 0, leng, tmpstr);							mvwaddstr(win, y, x, tmpstr);							wmove(win, y, x + cur_posi);						}					}				} else					wmove(win, y1, x1 - 1);				break;			case 261:				cur_posi++;				if (rflag == 1) {					if (eflag == 1)						endloop = 1;					else {						s1cptos2(s, cur_posi - leng + 1, leng, tmpstr);						mvwaddstr(win, y, x, tmpstr);						wmove(win, yend, xend);					}				} else					wmove(win, y1, x1 + 1);				break;			default:				endloop = 1;			}	} while (endloop == 0);	if (modiflag)		j = -j;	return j;}/* *  功能描述: 在窗体某一位置输入一定长度的整型数值(最大+2147483647) *  函数入口: win      --  窗体指针 *            y,x      --  窗体坐标 *			  c_x      --  光标停留位置 *            leng     --  在窗体中显示的子字符串长度 *            lengmax  --  字符串的总长度(int 类型占4个字节) *            p_i      --  存放整数的指针 *            helpy,helpx -- 帮助主题出现的位置 *            helpstr  --  帮助主题 *  函数出口: 返回控制键值(键CTRL_A不返回,它是输入模式下的插入状态和 *            覆盖状态的切换值) *  注    意: 必须包含头文件 stdlib.h */int	inputint(WINDOW *win, int y, int x, int c_x, int leng, int lengmax, int *p_i, int helpy, int helpx, char *helpstr){	/*int	inputstr(WINDOW *, int , int , int , int , char *, int, int, int, char *);*/	int	j;	char	s[20];	sprintf(s, "%d", (*p_i));	j = inputstr(win, y, x, c_x, leng, lengmax, s, 7, helpy, helpx, helpstr);	(*p_i) = atoi(s);	return j;}/* *  功能描述: 在窗体某一位置输入一定长度的长整数值(最大+2147483647) *  函数入口: win      --  窗体指针 *            y,x      --  窗体坐标 *			  c_x      --  光标停留位置 *            leng     --  在窗体中显示的子字符串长度 *            lengmax  --  字符串的总长度(long类型占4个字节) *            p_l      --  存放长整数的指针 *            helpy,helpx -- 帮助主题出现的位置 *            helpstr  --  帮助主题 *  函数出口: 返回控制键值(键CTRL_A不返回,它是输入模式下的插入状态和 *            覆盖状态的切换值) *  注    意: 必须包含头文件 stdlib.h */int	inputlong(WINDOW *win, int y, int x, int c_x, int leng, int lengmax, long *p_l, int helpy, int helpx, char *helpstr){	/*int	inputstr(WINDOW *, int , int , int , int , char *, int, int, int, char *);*/	int	j;	char	s[20];	sprintf(s, "%ld", (*p_l));	j = inputstr(win, y, x, c_x, leng, lengmax, s, 7, helpy, helpx, helpstr);	(*p_l) = atol(s);	return j;}/* *  功能描述: 在窗体某一位置输入一定长度的短整数值(最大+32767) *  函数入口: win      --  窗体指针 *            y,x      --  窗体坐标 *			  c_x      --  光标停留位置 *            leng     --  在窗体中显示的子字符串长度 *            lengmax  --  字符串的总长度(short 类型占2个字节) *            p_s      --  存放短整数的指针 *            helpy,helpx -- 帮助主题出现的位置 *            helpstr  --  帮助主题 *  函数出口: 返回控制键值(键CTRL_A不返回,它是输入模式下的插入状态和 *            覆盖状态的切换值) *  注    意: 必须包含头文件 stdlib.h */int	inputshort(WINDOW *win, int y, int x, int c_x, int leng, int lengmax, short *p_s, int helpy, int helpx, char *helpstr){	/*int	inputstr(WINDOW *, int , int , int , int , char *, int, int, int, char *);*/	int	j;	char	s[20];	sprintf(s, "%d", (*p_s));	j = inputstr(win, y, x, c_x, leng, lengmax, s, 7, helpy, helpx, helpstr);	(*p_s) = atoi(s);	return j;}/* *  功能描述: 在窗体某一位置输入一定长度的双精度浮点数 *  函数入口: win      --  窗体指针 *            y,x      --  窗体坐标 *			  c_x      --  光标停留位置 *            leng     --  在窗体中显示的子字符串长度 *            lengmax  --  字符串的总长度(short 类型占2个字节) *            p_d      --  存放双精度浮点数的指针 *            dfmt     --  此浮点数的格式说明 *            helpy,helpx -- 帮助主题出现的位置 *            helpstr  --  帮助主题 *  函数出口: 返回控制键值(键CTRL_A不返回,它是输入模式下的插入状态和 *            覆盖状态的切换值) *  注    意: 必须包含头文件 stdlib.h */int	inputdouble(WINDOW *win, int y, int x, int c_x, int leng, int lengmax, double *p_d, char *dfmt, int helpy, int helpx, char *helpstr){	/*int	inputstr(WINDOW *, int , int , int , int , char *, int, int, int, char *);*/	int	j;	char	s[40];	sprintf(s, dfmt, (*p_d));	j = inputstr(win, y, x, c_x, leng, lengmax, s, 2, helpy, helpx, helpstr);	(*p_d) = atof(s);	return j;}/* *  把金额转化成大写汉字 */void money_MONEY(double d,char *s){	long	ll,lr;	char	lstr[30];	char	rstr[3];	char	outstr[100];	char	tmpstr[10];	char	doublestr[17];	int		count;	ll=(long)d;	/*	 *  有误差	 *  lr=(long)((d-ll)*100);	 *  sprintf(rstr,"%2ld",lr);	 */	sprintf(lstr,"%ld",ll);	sprintf(doublestr,"%.2lf",d);	count=strlen(doublestr);	rstr[0]=doublestr[count-2];	rstr[1]=doublestr[count-1];	rstr[2]=0;	if(rstr[0]=='0' && rstr[1]=='0') lr=0;	else lr=atol(rstr);	outstr[0]=0;	swapstr(lstr);	for(count=strlen(lstr)-1;count>0;count--)	{		if(lstr[count]=='0'&&lstr[co

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -