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

📄 demo_termcap.c

📁 ncurses 库 可能有用酒用 没用就算了 我觉得还可以用
💻 C
字号:
/**************************************************************************** * Copyright (c) 2005 Free Software Foundation, Inc.                        * *                                                                          * * Permission is hereby granted, free of charge, to any person obtaining a  * * copy of this software and associated documentation files (the            * * "Software"), to deal in the Software without restriction, including      * * without limitation the rights to use, copy, modify, merge, publish,      * * distribute, distribute with modifications, sublicense, and/or sell       * * copies of the Software, and to permit persons to whom the Software is    * * furnished to do so, subject to the following conditions:                 * *                                                                          * * The above copyright notice and this permission notice shall be included  * * in all copies or substantial portions of the Software.                   * *                                                                          * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  * * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               * * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   * * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   * * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    * * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    * * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               * *                                                                          * * Except as contained in this notice, the name(s) of the above copyright   * * holders shall not be used in advertising or otherwise to promote the     * * sale, use or other dealings in this Software without prior written       * * authorization.                                                           * ****************************************************************************//* * Author: Thomas E. Dickey * * $Id: demo_termcap.c,v 1.2 2005/04/30 14:57:54 tom Exp $ * * A simple demo of the termcap interface. */#include <test.priv.h>#define isCapName(c) (isgraph(c) && strchr("^#=:\\", c) == 0)static voiddumpit(char *cap){    /*     * One of the limitations of the termcap interface is that the library     * cannot determine the size of the buffer passed via tgetstr(), nor the     * amount of space remaining.  This demo simply reuses the whole buffer     * for each call; a normal termcap application would try to use the buffer     * to hold all of the strings extracted from the terminal entry.     */    char area[1024], *ap = area;    char *str;    int num;    if ((str = tgetstr(cap, &ap)) != 0) {	/*	 * Note that the strings returned are mostly terminfo format, since	 * ncurses does not convert except for a handful of special cases.	 */	printf("str %s = ", cap);	while (*str != 0) {	    int ch = UChar(*str++);	    switch (ch) {	    case '\177':		fputs("^?", stdout);		break;	    case '\033':		fputs("\\E", stdout);		break;	    case '\b':		fputs("\\b", stdout);		break;	    case '\f':		fputs("\\f", stdout);		break;	    case '\n':		fputs("\\n", stdout);		break;	    case '\r':		fputs("\\r", stdout);		break;	    case ' ':		fputs("\\s", stdout);		break;	    case '\t':		fputs("\\t", stdout);		break;	    case '^':		fputs("\\^", stdout);		break;	    case ':':		fputs("\\072", stdout);		break;	    case '\\':		fputs("\\\\", stdout);		break;	    default:		if (isgraph(ch))		    fputc(ch, stdout);		else if (ch < 32)		    printf("^%c", ch + '@');		else		    printf("\\%03o", ch);		break;	    }	}	printf("\n");    } else if ((num = tgetnum(cap)) >= 0) {	printf("num %s = %d\n", cap, num);    } else if ((num = tgetflag(cap)) != 0) {	printf("flg %s\n", cap);    }    fflush(stdout);}static voiddemo_termcap(char *name){    char buffer[1024];    printf("Terminal type %s\n", name);    if (tgetent(buffer, name)) {	char cap[3];	int c1, c2;	cap[2] = 0;	for (c1 = 0; c1 < 256; ++c1) {	    cap[0] = c1;	    if (isCapName(c1)) {		for (c2 = 0; c2 < 256; ++c2) {		    cap[1] = c2;		    if (isCapName(c2)) {			dumpit(cap);		    }		}	    }	}    }}intmain(int argc, char *argv[]){    int n;    char *name;    if (argc > 1) {	for (n = 1; n < argc; ++n) {	    demo_termcap(argv[n]);	}    } else if ((name = getenv("TERM")) != 0) {	demo_termcap(name);    } else {	demo_termcap("dumb");    }    ExitProgram(EXIT_SUCCESS);}

⌨️ 快捷键说明

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