diff options
Diffstat (limited to 'ncurses/base/lib_set_term.c')
| -rw-r--r-- | ncurses/base/lib_set_term.c | 128 |
1 files changed, 65 insertions, 63 deletions
diff --git a/ncurses/base/lib_set_term.c b/ncurses/base/lib_set_term.c index 78de859208b6..b6f9e57f5568 100644 --- a/ncurses/base/lib_set_term.c +++ b/ncurses/base/lib_set_term.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2021,2022 Thomas E. Dickey * + * Copyright 2018-2024,2025 Thomas E. Dickey * * Copyright 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -57,9 +57,9 @@ #undef CUR #define CUR SP_TERMTYPE -MODULE_ID("$Id: lib_set_term.c,v 1.184 2022/12/10 21:34:12 tom Exp $") +MODULE_ID("$Id: lib_set_term.c,v 1.199 2025/12/27 12:28:45 tom Exp $") -#ifdef USE_TERM_DRIVER +#if USE_TERM_DRIVER #define MaxColors InfoOf(sp).maxcolors #define NumLabels InfoOf(sp).numlabels #else @@ -81,7 +81,7 @@ set_term(SCREEN *screenp) _nc_set_screen(screenp); newSP = screenp; - if (newSP != 0) { + if (newSP != NULL) { TINFO_SET_CURTERM(newSP, newSP->_term); #if !USE_REENTRANT curscr = CurScreen(newSP); @@ -91,11 +91,11 @@ set_term(SCREEN *screenp) COLOR_PAIRS = newSP->_pair_count; #endif } else { - TINFO_SET_CURTERM(oldSP, 0); + TINFO_SET_CURTERM(oldSP, NULL); #if !USE_REENTRANT - curscr = 0; - newscr = 0; - stdscr = 0; + curscr = NULL; + newscr = NULL; + stdscr = NULL; COLORS = 0; COLOR_PAIRS = 0; #endif @@ -110,7 +110,7 @@ set_term(SCREEN *screenp) static void _nc_free_keytry(TRIES * kt) { - if (kt != 0) { + if (kt != NULL) { _nc_free_keytry(kt->child); _nc_free_keytry(kt->sibling); free(kt); @@ -120,7 +120,7 @@ _nc_free_keytry(TRIES * kt) static bool delink_screen(SCREEN *sp) { - SCREEN *last = 0; + SCREEN *last = NULL; SCREEN *temp; bool result = FALSE; @@ -160,7 +160,7 @@ delscreen(SCREEN *sp) rop++) { if (rop->win) { (void) delwin(rop->win); - rop->win = 0; + rop->win = NULL; } } } @@ -174,9 +174,9 @@ delscreen(SCREEN *sp) } } - if (sp->_slk != 0) { + if (sp->_slk != NULL) { - if (sp->_slk->ent != 0) { + if (sp->_slk->ent != NULL) { int i; for (i = 0; i < sp->_slk->labcnt; ++i) { @@ -186,14 +186,14 @@ delscreen(SCREEN *sp) free(sp->_slk->ent); } free(sp->_slk); - sp->_slk = 0; + sp->_slk = NULL; } _nc_free_keytry(sp->_keytry); - sp->_keytry = 0; + sp->_keytry = NULL; _nc_free_keytry(sp->_key_ok); - sp->_key_ok = 0; + sp->_key_ok = NULL; FreeIfNeeded(sp->_current_attr); @@ -217,9 +217,9 @@ delscreen(SCREEN *sp) } #if USE_GPM_SUPPORT #ifdef HAVE_LIBDL - if (sp->_dlopen_gpm != 0) { + if (sp->_dlopen_gpm != NULL) { dlclose(sp->_dlopen_gpm); - sp->_dlopen_gpm = 0; + sp->_dlopen_gpm = NULL; } #endif #endif /* USE_GPM_SUPPORT */ @@ -232,17 +232,17 @@ delscreen(SCREEN *sp) */ if (is_current) { #if !USE_REENTRANT - curscr = 0; - newscr = 0; - stdscr = 0; + curscr = NULL; + newscr = NULL; + stdscr = NULL; COLORS = 0; COLOR_PAIRS = 0; #endif - _nc_set_screen(0); + _nc_set_screen(NULL); #if USE_WIDEC_SUPPORT - if (SP == 0) { + if (SP == NULL) { FreeIfNeeded(_nc_wacs); - _nc_wacs = 0; + _nc_wacs = NULL; } #endif } else { @@ -303,7 +303,7 @@ extract_fgbg(const char *src, int *result) } #endif -#define ReturnScreenError() do { _nc_set_screen(0); \ +#define ReturnScreenError() do { _nc_set_screen(NULL); \ returnCode(ERR); } while (0) /* OS-independent screen initializations */ @@ -315,26 +315,29 @@ NCURSES_SP_NAME(_nc_setupscreen) ( int slines, int scolumns, FILE *output, - int filtered, + bool filtered, int slk_format) { -#ifndef USE_TERM_DRIVER +#if !USE_TERM_DRIVER static const TTY null_TTY; /* all zeros iff uninitialized */ #endif char *env; int bottom_stolen = 0; SCREEN *sp; -#ifndef USE_TERM_DRIVER +#if !USE_TERM_DRIVER bool support_cookies = USE_XMC_SUPPORT; #endif T((T_CALLED("_nc_setupscreen(%d, %d, %p, %d, %d)"), slines, scolumns, (void *) output, filtered, slk_format)); - assert(CURRENT_SCREEN == 0); /* has been reset in newterm() ! */ + /* CURRENT_SCREEN is reset in newterm() */ + if (CURRENT_SCREEN) + returnCode(ERR); #if NCURSES_SP_FUNCS - assert(spp != 0); + if (spp == NULL) + returnCode(ERR); sp = *spp; if (!sp) { @@ -357,13 +360,13 @@ NCURSES_SP_NAME(_nc_setupscreen) ( sp->_next_screen = _nc_screen_chain; _nc_screen_chain = sp; - if ((sp->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0) { + if ((sp->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == NULL) { ReturnScreenError(); } #else if (!_nc_alloc_screen() - || ((SP->_acs_map = typeCalloc(chtype, ACS_LEN)) == 0) - || ((SP->_screen_acs_map = typeCalloc(bool, ACS_LEN)) == 0)) { + || ((SP->_acs_map = typeCalloc(chtype, ACS_LEN)) == NULL) + || ((SP->_screen_acs_map = typeCalloc(bool, ACS_LEN)) == NULL)) { returnCode(ERR); } @@ -373,7 +376,7 @@ NCURSES_SP_NAME(_nc_setupscreen) ( sp->_next_screen = _nc_screen_chain; _nc_screen_chain = sp; - if ((sp->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0) { + if ((sp->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == NULL) { returnCode(ERR); } #endif @@ -383,12 +386,16 @@ NCURSES_SP_NAME(_nc_setupscreen) ( */ _nc_set_screen(sp); sp->_term = cur_term; -#ifdef USE_TERM_DRIVER +#if USE_TERM_DRIVER TCBOf(sp)->csp = sp; _nc_get_screensize(sp, sp->_term, &slines, &scolumns); #else _nc_get_screensize(sp, &slines, &scolumns); #endif + if (scolumns < 0) + scolumns = 0; + if (slines < 0) + slines = 0; SET_LINES(slines); SET_COLS(scolumns); @@ -401,7 +408,7 @@ NCURSES_SP_NAME(_nc_setupscreen) ( if (filtered) { slines = 1; SET_LINES(slines); -#ifdef USE_TERM_DRIVER +#if USE_TERM_DRIVER CallDriver(sp, td_setfilter); #else /* *INDENT-EQLS* */ @@ -420,12 +427,7 @@ NCURSES_SP_NAME(_nc_setupscreen) ( #endif T(("filter screensize %dx%d", slines, scolumns)); } -#ifdef __DJGPP__ - T(("setting output mode to binary")); - fflush(output); - setmode(output, O_BINARY); -#endif -#if defined(EXP_WIN32_DRIVER) +#if USE_NAMED_PIPES T(("setting output mode to binary")); fflush(output); _setmode(fileno(output), _O_BINARY); @@ -437,12 +439,12 @@ NCURSES_SP_NAME(_nc_setupscreen) ( fflush(output); sp->_ofd = output ? fileno(output) : -1; sp->_ofp = output; -#if defined(EXP_WIN32_DRIVER) +#if USE_NAMED_PIPES if (output) _setmode(fileno(output), _O_BINARY); #endif sp->out_limit = (size_t) ((2 + slines) * (6 + scolumns)); - if ((sp->out_buffer = malloc(sp->out_limit)) == 0) + if ((sp->out_buffer = malloc(sp->out_limit)) == NULL) sp->out_limit = 0; sp->out_inuse = 0; @@ -455,7 +457,7 @@ NCURSES_SP_NAME(_nc_setupscreen) ( /* * Set our assumption of the terminal's default foreground and background - * colors. The curs_color man-page states that we can assume that the + * colors. The curs_color man page states that we can assume that the * background is black. The origin of this assumption appears to be * terminals that displayed colored text, but no colored backgrounds, e.g., * the first colored terminals around 1980. More recent ones with better @@ -484,7 +486,7 @@ NCURSES_SP_NAME(_nc_setupscreen) ( * Allow those assumed/default color assumptions to be overridden at * runtime: */ - if ((env = getenv("NCURSES_ASSUMED_COLORS")) != 0) { + if ((env = getenv("NCURSES_ASSUMED_COLORS")) != NULL) { int fg, bg; char sep1, sep2; int count = sscanf(env, "%d%c%d%c", &fg, &sep1, &bg, &sep2); @@ -551,7 +553,7 @@ NCURSES_SP_NAME(_nc_setupscreen) ( if (NCURSES_SP_NAME(has_colors) (NCURSES_SP_ARG)) { sp->_ok_attributes |= A_COLOR; } -#ifdef USE_TERM_DRIVER +#if USE_TERM_DRIVER _nc_cookie_init(sp); #else #if USE_XMC_SUPPORT @@ -560,7 +562,7 @@ NCURSES_SP_NAME(_nc_setupscreen) ( * in the environment, reset the support-flag. */ if (magic_cookie_glitch >= 0) { - if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) { + if (getenv("NCURSES_NO_MAGIC_COOKIE") != NULL) { support_cookies = FALSE; } } @@ -638,10 +640,10 @@ NCURSES_SP_NAME(_nc_setupscreen) ( NCURSES_SP_NAME(_nc_init_acs) (NCURSES_SP_ARG); #if USE_WIDEC_SUPPORT sp->_screen_unicode = _nc_unicode_locale(); - if (_nc_wacs == 0) { + if (_nc_wacs == NULL) { _nc_init_wacs(); } - if (_nc_wacs == 0) { + if (_nc_wacs == NULL) { ReturnScreenError(); } @@ -649,7 +651,7 @@ NCURSES_SP_NAME(_nc_setupscreen) ( && _nc_locale_breaks_acs(sp->_term)); #endif env = _nc_get_locale(); - sp->_legacy_coding = ((env == 0) + sp->_legacy_coding = ((env == NULL) || !strcmp(env, "C") || !strcmp(env, "POSIX")); T(("legacy-coding %d", sp->_legacy_coding)); @@ -657,19 +659,19 @@ NCURSES_SP_NAME(_nc_setupscreen) ( sp->_nc_sp_idcok = TRUE; sp->_nc_sp_idlok = FALSE; - sp->oldhash = 0; - sp->newhash = 0; + sp->oldhash = NULL; + sp->newhash = NULL; T(("creating newscr")); NewScreen(sp) = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx slines, scolumns, 0, 0); - if (NewScreen(sp) == 0) { + if (NewScreen(sp) == NULL) { ReturnScreenError(); } T(("creating curscr")); CurScreen(sp) = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx slines, scolumns, 0, 0); - if (CurScreen(sp) == 0) { + if (CurScreen(sp) == NULL) { ReturnScreenError(); } #if !USE_REENTRANT @@ -688,8 +690,8 @@ NCURSES_SP_NAME(_nc_setupscreen) ( * Get the current tty-modes. setupterm() may already have done this, * unless we use the term-driver. */ -#ifndef USE_TERM_DRIVER - if (cur_term != 0 && +#if !USE_TERM_DRIVER + if (cur_term != NULL && !memcmp(&cur_term->Ottyb, &null_TTY, sizeof(TTY))) #endif { @@ -755,7 +757,7 @@ NCURSES_SP_NAME(_nc_setupscreen) ( assert((sp->_lines_avail + sp->_topstolen + bottom_stolen) == slines); if ((StdScreen(sp) = NCURSES_SP_NAME(newwin) (NCURSES_SP_ARGx sp->_lines_avail, - scolumns, 0, 0)) == 0) { + scolumns, 0, 0)) == NULL) { ReturnScreenError(); } SET_LINES(sp->_lines_avail); @@ -771,10 +773,10 @@ NCURSES_EXPORT(int) _nc_setupscreen(int slines GCC_UNUSED, int scolumns GCC_UNUSED, FILE *output, - int filtered, + bool filtered, int slk_format) { - SCREEN *sp = 0; + SCREEN *sp = NULL; int rc = NCURSES_SP_NAME(_nc_setupscreen) (&sp, slines, scolumns, @@ -782,7 +784,7 @@ _nc_setupscreen(int slines GCC_UNUSED, filtered, slk_format); if (rc != OK) - _nc_set_screen(0); + _nc_set_screen(NULL); return rc; } #endif @@ -805,13 +807,13 @@ NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_DCLx TR_FUNC_ARG(0, init))); #if NCURSES_SP_FUNCS - if (SP_PARM != 0 && SP_PARM->_prescreen) + if (SP_PARM != NULL && SP_PARM->_prescreen) #endif { if (line == 0) { code = OK; } else { - if (safe_ripoff_sp == 0) { + if (safe_ripoff_sp == NULL) { safe_ripoff_sp = safe_ripoff_stack; } if (safe_ripoff_sp < safe_ripoff_stack + N_RIPS) { |
