test13_1.txt

来自「嵌入式c源码」· 文本 代码 · 共 52 行

TXT
52
字号
#include <stdlib.h>
#include <stdio.h>
#include <term.h>
#include <curses.h>
#define NUMCAPS 3

int main(void)
{
	int j;
	int retval=0;
	char *buf;
	char *boolcaps[NUMCAPS]={"am", "bce", "km"};
	char *numcaps[NUMCAPS]={"cols", "lines", "colors"};
	char *strcaps[NUMCAPS]={"cup", "flash", "hpa"};
	/*初始化terminfo数据结构 */
		
	if(setupterm(NULL,fileno(stdin),NULL)!=OK){
		perror("setupterm( )");
		exit(EXIT_FAILURE);
	}

	for(j=0;j<NUMCAPS;++j){
		retval=tigetflag(boolcaps[j]);
		if(retval==FALSE)
			printf("'%s' unsupported\n",boolcaps[j]);
		else
			printf("'%s' supported\n",boolcaps[j]);
	}
	/*测试终端对am、bce和km三种布尔型能力 */
	fputc('\n',stdout);

	for(j=0;j<NUMCAPS;++j){
		retval=tigetnum(numcaps[j]);
		if(retval==ERR)
			printf("'%s' unsupported\n",numcaps[j]);
		else
			printf("'%s' is %d\n",numcaps[j],retval);
	}
	fputc('\n',stdout);
	/*查询数值型能力 */

	for(j=0;j<NUMCAPS;++j){
		buf=tigetstr(strcaps[j]);
		if(buf=NULL)
			printf("'%s' unsupported\n",strcaps[j]);
		else
			printf("'%s' is %s\n",strcaps[j],buf[0]);
	}
	/*查询字符型能力*/
}

⌨️ 快捷键说明

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