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

📄 lib_setup.c

📁 ncurses 库 可能有用酒用 没用就算了 我觉得还可以用
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************** * Copyright (c) 1998-2004,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: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               * *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         * *     and: Thomas E. Dickey 1996-2003                                      * ****************************************************************************//* * Terminal setup routines common to termcap and terminfo: * *		use_env(bool) *		setupterm(char *, int, int *) */#include <curses.priv.h>#include <tic.h>		/* for MAX_NAME_SIZE */#include <term_entry.h>#if SVR4_TERMIO && !defined(_POSIX_SOURCE)#define _POSIX_SOURCE#endif#if HAVE_LOCALE_H#include <locale.h>#endif#include <term.h>		/* lines, columns, cur_term */MODULE_ID("$Id: lib_setup.c,v 1.88 2005/03/12 19:41:45 tom Exp $")/**************************************************************************** * * Terminal size computation * ****************************************************************************/#if HAVE_SIZECHANGE# if !defined(sun) || !TERMIOS#  if HAVE_SYS_IOCTL_H#   include <sys/ioctl.h>#  endif# endif#endif#if NEED_PTEM_H /* On SCO, they neglected to define struct winsize in termios.h -- it's only  * in termio.h and ptem.h (the former conflicts with other definitions).  */# include <sys/stream.h># include <sys/ptem.h>#endif#if HAVE_LANGINFO_CODESET#include <langinfo.h>#endif/* * SCO defines TIOCGSIZE and the corresponding struct.  Other systems (SunOS, * Solaris, IRIX) define TIOCGWINSZ and struct winsize. */#ifdef TIOCGSIZE# define IOCTL_WINSIZE TIOCGSIZE# define STRUCT_WINSIZE struct ttysize# define WINSIZE_ROWS(n) (int)n.ts_lines# define WINSIZE_COLS(n) (int)n.ts_cols#else# ifdef TIOCGWINSZ#  define IOCTL_WINSIZE TIOCGWINSZ#  define STRUCT_WINSIZE struct winsize#  define WINSIZE_ROWS(n) (int)n.ws_row#  define WINSIZE_COLS(n) (int)n.ws_col# endif#endifNCURSES_EXPORT_VAR(char) ttytype[NAMESIZE] = "";NCURSES_EXPORT_VAR(int) LINES = 0;NCURSES_EXPORT_VAR(int) COLS = 0;NCURSES_EXPORT_VAR(int) TABSIZE = 0;static int _use_env = TRUE;NCURSES_EXPORT(void)use_env(bool f){    T((T_CALLED("use_env()")));    _use_env = f;    returnVoid;}static void_nc_get_screensize(int *linep, int *colp)/* Obtain lines/columns values from the environment and/or terminfo entry */{    /* figure out the size of the screen */    T(("screen size: terminfo lines = %d columns = %d", lines, columns));    if (!_use_env) {	*linep = (int) lines;	*colp = (int) columns;    } else {			/* usually want to query LINES and COLUMNS from environment */	int value;	*linep = *colp = 0;	/* first, look for environment variables */	if ((value = _nc_getenv_num("LINES")) > 0) {	    *linep = value;	}	if ((value = _nc_getenv_num("COLUMNS")) > 0) {	    *colp = value;	}	T(("screen size: environment LINES = %d COLUMNS = %d", *linep, *colp));#ifdef __EMX__	if (*linep <= 0 || *colp <= 0) {	    int screendata[2];	    _scrsize(screendata);	    *colp = screendata[0];	    *linep = screendata[1];	    T(("EMX screen size: environment LINES = %d COLUMNS = %d",	       *linep, *colp));	}#endif#if HAVE_SIZECHANGE	/* if that didn't work, maybe we can try asking the OS */	if (*linep <= 0 || *colp <= 0) {	    if (isatty(cur_term->Filedes)) {		STRUCT_WINSIZE size;		errno = 0;		do {		    if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) < 0			&& errno != EINTR)			goto failure;		} while		    (errno == EINTR);		/*		 * Solaris lets users override either dimension with an		 * environment variable.		 */		if (*linep <= 0)		    *linep = WINSIZE_ROWS(size);		if (*colp <= 0)		    *colp = WINSIZE_COLS(size);	    }	    /* FALLTHRU */	  failure:;	}#endif /* HAVE_SIZECHANGE */	/* if we can't get dynamic info about the size, use static */	if (*linep <= 0) {	    *linep = (int) lines;	}	if (*colp <= 0) {	    *colp = (int) columns;	}	/* the ultimate fallback, assume fixed 24x80 size */	if (*linep <= 0) {	    *linep = 24;	}	if (*colp <= 0) {	    *colp = 80;	}	/*	 * Put the derived values back in the screen-size caps, so	 * tigetnum() and tgetnum() will do the right thing.	 */	lines = (short) (*linep);	columns = (short) (*colp);    }    T(("screen size is %dx%d", *linep, *colp));    if (VALID_NUMERIC(init_tabs))	TABSIZE = (int) init_tabs;    else	TABSIZE = 8;    T(("TABSIZE = %d", TABSIZE));}#if USE_SIZECHANGENCURSES_EXPORT(void)_nc_update_screensize(void){    int old_lines = lines;    int new_lines;    int old_cols = columns;    int new_cols;    _nc_get_screensize(&new_lines, &new_cols);    /*     * See is_term_resized() and resizeterm().     * We're doing it this way because those functions belong to the upper     * ncurses library, while this resides in the lower terminfo library.     */    if (SP != 0	&& SP->_resize != 0) {	if ((new_lines != old_lines) || (new_cols != old_cols))	    SP->_resize(new_lines, new_cols);	SP->_sig_winch = FALSE;    }}#endif/**************************************************************************** * * Terminal setup * ****************************************************************************/#define ret_error(code, fmt, arg)	if (errret) {\					    *errret = code;\					    returnCode(ERR);\					} else {\					    fprintf(stderr, fmt, arg);\					    exit(EXIT_FAILURE);\					}#define ret_error0(code, msg)		if (errret) {\					    *errret = code;\					    returnCode(ERR);\					} else {\					    fprintf(stderr, msg);\					    exit(EXIT_FAILURE);\					}#if USE_DATABASE || USE_TERMCAPstatic intgrab_entry(const char *const tn, TERMTYPE *const tp)/* return 1 if entry found, 0 if not found, -1 if database not accessible */{#if USE_DATABASE    char filename[PATH_MAX];#endif    int status;    /*     * $TERM shouldn't contain pathname delimiters.     */    if (strchr(tn, '/'))	return 0;#if USE_DATABASE    if ((status = _nc_read_entry(tn, filename, tp)) != 1) {#if !PURE_TERMINFO	/*	 * Try falling back on the termcap file.	 * Note:  allowing this call links the entire terminfo/termcap	 * compiler into the startup code.  It's preferable to build a

⌨️ 快捷键说明

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