Add ncurses 6.4

This commit is contained in:
Justine Tunney 2023-12-10 07:28:01 -08:00
parent 6ee5580adc
commit 0ed7309fdb
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
3071 changed files with 69379 additions and 1 deletions

View file

@ -223,6 +223,7 @@ include dsp/tty/BUILD.mk # │
include dsp/BUILD.mk # │
include third_party/stb/BUILD.mk # │
include third_party/mbedtls/BUILD.mk # │
include third_party/ncurses/BUILD.mk # │
include third_party/libcxx/BUILD.mk # │
include third_party/pcre/BUILD.mk # │
include net/https/BUILD.mk # │

View file

@ -22,6 +22,7 @@ o/$(MODE)/third_party: \
o/$(MODE)/third_party/maxmind \
o/$(MODE)/third_party/mbedtls \
o/$(MODE)/third_party/musl \
o/$(MODE)/third_party/ncurses \
o/$(MODE)/third_party/nsync \
o/$(MODE)/third_party/pcre \
o/$(MODE)/third_party/puff \

132
third_party/ncurses/BUILD.mk vendored Normal file
View file

@ -0,0 +1,132 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
PKGS += THIRD_PARTY_NCURSES
THIRD_PARTY_NCURSES_ARTIFACTS += THIRD_PARTY_NCURSES_A
THIRD_PARTY_NCURSES = $(THIRD_PARTY_NCURSES_A_DEPS) $(THIRD_PARTY_NCURSES_A)
THIRD_PARTY_NCURSES_A = o/$(MODE)/third_party/ncurses/ncurses.a
THIRD_PARTY_NCURSES_A_FILES := $(wildcard third_party/ncurses/*)
THIRD_PARTY_NCURSES_A_HDRS = $(filter %.h,$(THIRD_PARTY_NCURSES_A_FILES))
THIRD_PARTY_NCURSES_A_INCS = $(filter %.inc,$(THIRD_PARTY_NCURSES_A_FILES))
THIRD_PARTY_NCURSES_A_SRCS = $(filter %.c,$(THIRD_PARTY_NCURSES_A_FILES))
THIRD_PARTY_NCURSES_A_TERM := $(wildcard usr/share/terminfo/*/*)
THIRD_PARTY_NCURSES_A_SRCOBJS = $(THIRD_PARTY_NCURSES_A_SRCS:%.c=o/$(MODE)/%.o)
THIRD_PARTY_NCURSES_A_OBJS = \
$(THIRD_PARTY_NCURSES_A_SRCOBJS) \
$(THIRD_PARTY_NCURSES_A_TERM:%=o/$(MODE)/%.zip.o)
THIRD_PARTY_NCURSES_A_CHECKS = \
$(THIRD_PARTY_NCURSES_A).pkg
THIRD_PARTY_NCURSES_A_DIRECTDEPS = \
LIBC_CALLS \
LIBC_FMT \
LIBC_INTRIN \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_PROC \
LIBC_RUNTIME \
LIBC_STDIO \
LIBC_STR \
LIBC_SYSV \
THIRD_PARTY_MUSL
THIRD_PARTY_NCURSES_A_DEPS := \
$(call uniq,$(foreach x,$(THIRD_PARTY_NCURSES_A_DIRECTDEPS),$($(x))))
$(THIRD_PARTY_NCURSES_A): \
third_party/ncurses/ \
$(THIRD_PARTY_NCURSES_A).pkg \
$(THIRD_PARTY_NCURSES_A_OBJS)
$(THIRD_PARTY_NCURSES_A).pkg: \
$(THIRD_PARTY_NCURSES_A_OBJS) \
$(foreach x,$(THIRD_PARTY_NCURSES_A_DIRECTDEPS),$($(x)_A).pkg)
$(THIRD_PARTY_NCURSES_A_SRCOBJS): private \
CFLAGS += \
-fportcosmo \
--param max-inline-insns-single=1200
$(THIRD_PARTY_NCURSES_A_SRCOBJS): private \
CPPFLAGS += \
-DNDEBUG \
--param max-inline-insns-single=1200
o/$(MODE)/third_party/ncurses/define_key.o \
o/$(MODE)/third_party/ncurses/key_defined.o \
o/$(MODE)/third_party/ncurses/keybound.o \
o/$(MODE)/third_party/ncurses/keyok.o \
o/$(MODE)/third_party/ncurses/tries.o \
o/$(MODE)/third_party/ncurses/version.o \
o/$(MODE)/third_party/ncurses/access.o \
o/$(MODE)/third_party/ncurses/add_tries.o \
o/$(MODE)/third_party/ncurses/alloc_ttype.o \
o/$(MODE)/third_party/ncurses/comp_error.o \
o/$(MODE)/third_party/ncurses/comp_hash.o \
o/$(MODE)/third_party/ncurses/db_iterator.o \
o/$(MODE)/third_party/ncurses/doalloc.o \
o/$(MODE)/third_party/ncurses/entries.o \
o/$(MODE)/third_party/ncurses/free_ttype.o \
o/$(MODE)/third_party/ncurses/getenv_num.o \
o/$(MODE)/third_party/ncurses/hashed_db.o \
o/$(MODE)/third_party/ncurses/home_terminfo.o \
o/$(MODE)/third_party/ncurses/init_keytry.o \
o/$(MODE)/third_party/ncurses/lib_acs.o \
o/$(MODE)/third_party/ncurses/lib_baudrate.o \
o/$(MODE)/third_party/ncurses/lib_cur_term.o \
o/$(MODE)/third_party/ncurses/lib_data.o \
o/$(MODE)/third_party/ncurses/lib_has_cap.o \
o/$(MODE)/third_party/ncurses/lib_kernel.o \
o/$(MODE)/third_party/ncurses/lib_longname.o \
o/$(MODE)/third_party/ncurses/lib_napms.o \
o/$(MODE)/third_party/ncurses/lib_options.o \
o/$(MODE)/third_party/ncurses/lib_raw.o \
o/$(MODE)/third_party/ncurses/lib_setup.o \
o/$(MODE)/third_party/ncurses/lib_termcap.o \
o/$(MODE)/third_party/ncurses/lib_termname.o \
o/$(MODE)/third_party/ncurses/lib_tgoto.o \
o/$(MODE)/third_party/ncurses/lib_ti.o \
o/$(MODE)/third_party/ncurses/lib_tparm.o \
o/$(MODE)/third_party/ncurses/lib_tputs.o \
o/$(MODE)/third_party/ncurses/lib_ttyflags.o \
o/$(MODE)/third_party/ncurses/name_match.o \
o/$(MODE)/third_party/ncurses/obsolete.o \
o/$(MODE)/third_party/ncurses/read_entry.o \
o/$(MODE)/third_party/ncurses/read_termcap.o \
o/$(MODE)/third_party/ncurses/strings.o \
o/$(MODE)/third_party/ncurses/trim_sgr0.o \
o/$(MODE)/third_party/ncurses/lib_trace.o \
o/$(MODE)/third_party/ncurses/lib_traceatr.o \
o/$(MODE)/third_party/ncurses/lib_tracebits.o \
o/$(MODE)/third_party/ncurses/lib_tracechr.o \
o/$(MODE)/third_party/ncurses/trace_buf.o \
o/$(MODE)/third_party/ncurses/trace_tries.o \
o/$(MODE)/third_party/ncurses/visbuf.o \
o/$(MODE)/third_party/ncurses/lib_twait.o \
o/$(MODE)/third_party/ncurses/codes.o \
o/$(MODE)/third_party/ncurses/comp_captab.o \
o/$(MODE)/third_party/ncurses/comp_userdefs.o \
o/$(MODE)/third_party/ncurses/fallback.o \
o/$(MODE)/third_party/ncurses/lib_keyname.o \
o/$(MODE)/third_party/ncurses/names.o \
o/$(MODE)/third_party/ncurses/unctrl.o: private \
CPPFLAGS += \
-DUSE_TERMLIB
THIRD_PARTY_NCURSES_BINS = $(THIRD_PARTY_NCURSES_COMS) $(THIRD_PARTY_NCURSES_COMS:%=%.dbg)
THIRD_PARTY_NCURSES_LIBS = $(foreach x,$(THIRD_PARTY_NCURSES_ARTIFACTS),$($(x)))
THIRD_PARTY_NCURSES_SRCS = $(foreach x,$(THIRD_PARTY_NCURSES_ARTIFACTS),$($(x)_SRCS))
THIRD_PARTY_NCURSES_HDRS = $(foreach x,$(THIRD_PARTY_NCURSES_ARTIFACTS),$($(x)_HDRS))
THIRD_PARTY_NCURSES_INCS = $(foreach x,$(THIRD_PARTY_NCURSES_ARTIFACTS),$($(x)_INCS))
THIRD_PARTY_NCURSES_CHECKS = $(foreach x,$(THIRD_PARTY_NCURSES_ARTIFACTS),$($(x)_CHECKS))
THIRD_PARTY_NCURSES_OBJS = $(foreach x,$(THIRD_PARTY_NCURSES_ARTIFACTS),$($(x)_OBJS))
$(THIRD_PARTY_NCURSES_A_SRCOBJS): $(BUILD_FILES) third_party/ncurses/BUILD.mk
.PHONY: o/$(MODE)/third_party/ncurses
o/$(MODE)/third_party/ncurses: \
$(THIRD_PARTY_NCURSES_A) \
$(THIRD_PARTY_NCURSES_BINS) \
$(THIRD_PARTY_NCURSES_CHECKS)

29
third_party/ncurses/LICENSE vendored Normal file
View file

@ -0,0 +1,29 @@
Copyright 2018-2021,2022 Thomas E. Dickey
Copyright 1998-2017,2018 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.
-- vile:txtmode fc=72
-- $Id: COPYING,v 1.11 2022/01/01 11:47:50 tom Exp $

15
third_party/ncurses/README.cosmo vendored Normal file
View file

@ -0,0 +1,15 @@
DESCRIPTION
ncurses is a teletypewriter abstraction library
LICENSE
ncurses license
ORIGIN
https://ftp.gnu.org/gnu/ncurses/ncurses-6.4.tar.gz
LOCAL CHANGES
None.

110
third_party/ncurses/SigAction.h vendored Normal file
View file

@ -0,0 +1,110 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2003,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> *
****************************************************************************/
/*
* $Id: SigAction.h,v 1.10 2020/02/02 23:34:34 tom Exp $
*
* This file exists to handle non-POSIX systems which don't have <unistd.h>,
* and usually no sigaction() nor <termios.h>
*/
#ifndef _SIGACTION_H
#define _SIGACTION_H
#ifndef HAVE_SIGACTION
#define HAVE_SIGACTION 0
#endif
#ifndef HAVE_SIGVEC
#define HAVE_SIGVEC 0
#endif
#if HAVE_SIGACTION
#if !HAVE_TYPE_SIGACTION
typedef struct sigaction sigaction_t;
#endif
#else /* !HAVE_SIGACTION */
#if HAVE_SIGVEC
#undef SIG_BLOCK
#define SIG_BLOCK 00
#undef SIG_UNBLOCK
#define SIG_UNBLOCK 01
#undef SIG_SETMASK
#define SIG_SETMASK 02
/*
* <bsd/signal.h> is in the Linux 1.2.8 + gcc 2.7.0 configuration,
* and is useful for testing this header file.
*/
#if HAVE_BSD_SIGNAL_H
#include <bsd/signal.h>
#endif
typedef struct sigvec sigaction_t;
#define sigset_t _nc_sigset_t
typedef unsigned long sigset_t;
#undef sa_mask
#define sa_mask sv_mask
#undef sa_handler
#define sa_handler sv_handler
#undef sa_flags
#define sa_flags sv_flags
#undef sigaction
#define sigaction _nc_sigaction
#undef sigprocmask
#define sigprocmask _nc_sigprocmask
#undef sigemptyset
#define sigemptyset _nc_sigemptyset
#undef sigsuspend
#define sigsuspend _nc_sigsuspend
#undef sigdelset
#define sigdelset _nc_sigdelset
#undef sigaddset
#define sigaddset _nc_sigaddset
/* tty/lib_tstp.c is the only user */
#include <base/sigaction.c>
#endif /* HAVE_SIGVEC */
#endif /* HAVE_SIGACTION */
#endif /* !defined(_SIGACTION_H) */

260
third_party/ncurses/access.c vendored Normal file
View file

@ -0,0 +1,260 @@
/****************************************************************************
* Copyright 2019-2020,2021 Thomas E. Dickey *
* Copyright 1998-2011,2012 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 *
****************************************************************************/
#include "curses.priv.h"
#include <ctype.h>
#ifndef USE_ROOT_ACCESS
#if HAVE_SETFSUID
#include <sys/fsuid.h>
#else
#include <sys/stat.h>
#endif
#endif
#include "tic.h"
MODULE_ID("$Id: access.c,v 1.31 2021/08/29 10:35:17 tom Exp $")
#define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c))
#ifdef _NC_MSC
# define ACCESS(FN, MODE) access((FN), (MODE)&(R_OK|W_OK))
#else
# define ACCESS access
#endif
NCURSES_EXPORT(char *)
_nc_rootname(char *path)
{
char *result = _nc_basename(path);
#if !MIXEDCASE_FILENAMES || defined(PROG_EXT)
static char *temp;
char *s;
temp = strdup(result);
result = temp;
#if !MIXEDCASE_FILENAMES
for (s = result; *s != '\0'; ++s) {
*s = (char) LOWERCASE(*s);
}
#endif
#if defined(PROG_EXT)
if ((s = strrchr(result, '.')) != 0) {
if (!strcmp(s, PROG_EXT))
*s = '\0';
}
#endif
#endif
return result;
}
/*
* Check if a string appears to be an absolute pathname.
*/
NCURSES_EXPORT(bool)
_nc_is_abs_path(const char *path)
{
#if defined(__EMX__) || defined(__DJGPP__)
#define is_pathname(s) ((((s) != 0) && ((s)[0] == '/')) \
|| (((s)[0] != 0) && ((s)[1] == ':')))
#else
#define is_pathname(s) ((s) != 0 && (s)[0] == '/')
#endif
return is_pathname(path);
}
/*
* Return index of the basename
*/
NCURSES_EXPORT(unsigned)
_nc_pathlast(const char *path)
{
const char *test = strrchr(path, '/');
#ifdef __EMX__
if (test == 0)
test = strrchr(path, '\\');
#endif
if (test == 0)
test = path;
else
test++;
return (unsigned) (test - path);
}
NCURSES_EXPORT(char *)
_nc_basename(char *path)
{
return path + _nc_pathlast(path);
}
NCURSES_EXPORT(int)
_nc_access(const char *path, int mode)
{
int result;
if (path == 0) {
result = -1;
} else if (ACCESS(path, mode) < 0) {
if ((mode & W_OK) != 0
&& errno == ENOENT
&& strlen(path) < PATH_MAX) {
char head[PATH_MAX];
char *leaf;
_nc_STRCPY(head, path, sizeof(head));
leaf = _nc_basename(head);
if (leaf == 0)
leaf = head;
*leaf = '\0';
if (head == leaf)
_nc_STRCPY(head, ".", sizeof(head));
result = ACCESS(head, R_OK | W_OK | X_OK);
} else {
result = -1;
}
} else {
result = 0;
}
return result;
}
NCURSES_EXPORT(bool)
_nc_is_dir_path(const char *path)
{
bool result = FALSE;
struct stat sb;
if (stat(path, &sb) == 0
&& S_ISDIR(sb.st_mode)) {
result = TRUE;
}
return result;
}
NCURSES_EXPORT(bool)
_nc_is_file_path(const char *path)
{
bool result = FALSE;
struct stat sb;
if (stat(path, &sb) == 0
&& S_ISREG(sb.st_mode)) {
result = TRUE;
}
return result;
}
#if HAVE_ISSETUGID
#define is_elevated() issetugid()
#elif HAVE_GETEUID && HAVE_GETEGID
#define is_elevated() \
(getuid() != geteuid() \
|| getgid() != getegid())
#else
#define is_elevated() FALSE
#endif
#if HAVE_SETFSUID
#define lower_privileges() \
int save_err = errno; \
setfsuid(getuid()); \
setfsgid(getgid()); \
errno = save_err
#define resume_elevation() \
save_err = errno; \
setfsuid(geteuid()); \
setfsgid(getegid()); \
errno = save_err
#else
#define lower_privileges() /* nothing */
#define resume_elevation() /* nothing */
#endif
#ifndef USE_ROOT_ENVIRON
/*
* Returns true if we allow application to use environment variables that are
* used for searching lists of directories, etc.
*/
NCURSES_EXPORT(int)
_nc_env_access(void)
{
int result = TRUE;
if (is_elevated()) {
result = FALSE;
} else if ((getuid() == ROOT_UID) || (geteuid() == ROOT_UID)) {
result = FALSE;
}
return result;
}
#endif /* USE_ROOT_ENVIRON */
#ifndef USE_ROOT_ACCESS
/*
* Limit privileges if possible; otherwise disallow access for updating files.
*/
NCURSES_EXPORT(FILE *)
_nc_safe_fopen(const char *path, const char *mode)
{
FILE *result = NULL;
#if HAVE_SETFSUID
lower_privileges();
result = fopen(path, mode);
resume_elevation();
#else
if (!is_elevated() || *mode == 'r') {
result = fopen(path, mode);
}
#endif
return result;
}
NCURSES_EXPORT(int)
_nc_safe_open3(const char *path, int flags, mode_t mode)
{
int result = -1;
#if HAVE_SETFSUID
lower_privileges();
result = open(path, flags, mode);
resume_elevation();
#else
if (!is_elevated() || (flags & O_RDONLY)) {
result = open(path, flags, mode);
}
#endif
return result;
}
#endif /* USE_ROOT_ENVIRON */

123
third_party/ncurses/add_tries.c vendored Normal file
View file

@ -0,0 +1,123 @@
/****************************************************************************
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 1998-2009,2010 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 1998-on *
****************************************************************************/
/*
** add_tries.c
**
** Add keycode/string to tries-tree.
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: add_tries.c,v 1.12 2020/02/02 23:34:34 tom Exp $")
#define SET_TRY(dst,src) if ((dst->ch = *src++) == 128) dst->ch = '\0'
#define CMP_TRY(a,b) ((a)? (a == b) : (b == 128))
NCURSES_EXPORT(int)
_nc_add_to_try(TRIES ** tree, const char *str, unsigned code)
{
TRIES *ptr, *savedptr;
unsigned const char *txt = (unsigned const char *) str;
T((T_CALLED("_nc_add_to_try(%p, %s, %u)"),
(void *) *tree, _nc_visbuf(str), code));
if (txt == 0 || *txt == '\0' || code == 0)
returnCode(ERR);
if ((*tree) != 0) {
ptr = savedptr = (*tree);
for (;;) {
unsigned char cmp = *txt;
while (!CMP_TRY(ptr->ch, cmp)
&& ptr->sibling != 0)
ptr = ptr->sibling;
if (CMP_TRY(ptr->ch, cmp)) {
if (*(++txt) == '\0') {
ptr->value = (unsigned short) code;
returnCode(OK);
}
if (ptr->child != 0)
ptr = ptr->child;
else
break;
} else {
if ((ptr->sibling = typeCalloc(TRIES, 1)) == 0) {
returnCode(ERR);
}
savedptr = ptr = ptr->sibling;
SET_TRY(ptr, txt);
ptr->value = 0;
break;
}
} /* end for (;;) */
} else { /* (*tree) == 0 :: First sequence to be added */
savedptr = ptr = (*tree) = typeCalloc(TRIES, 1);
if (ptr == 0) {
returnCode(ERR);
}
SET_TRY(ptr, txt);
ptr->value = 0;
}
/* at this point, we are adding to the try. ptr->child == 0 */
while (*txt) {
ptr->child = typeCalloc(TRIES, 1);
ptr = ptr->child;
if (ptr == 0) {
while ((ptr = savedptr) != 0) {
savedptr = ptr->child;
free(ptr);
}
*tree = NULL;
returnCode(ERR);
}
SET_TRY(ptr, txt);
ptr->value = 0;
}
ptr->value = (unsigned short) code;
returnCode(OK);
}

405
third_party/ncurses/alloc_entry.c vendored Normal file
View file

@ -0,0 +1,405 @@
/****************************************************************************
* Copyright 2018-2021,2022 Thomas E. Dickey *
* Copyright 1998-2013,2017 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-on *
****************************************************************************/
/*
* alloc_entry.c -- allocation functions for terminfo entries
*
* _nc_copy_entry()
* _nc_init_entry()
* _nc_merge_entry()
* _nc_save_str()
* _nc_wrap_entry()
*
*/
#include "curses.priv.h"
#include "tic.h"
MODULE_ID("$Id: alloc_entry.c,v 1.77 2022/10/15 19:37:33 tom Exp $")
#define ABSENT_OFFSET -1
#define CANCELLED_OFFSET -2
static char *stringbuf; /* buffer for string capabilities */
static size_t next_free; /* next free character in stringbuf */
NCURSES_EXPORT(void)
_nc_init_entry(ENTRY * const tp)
/* initialize a terminal type data block */
{
DEBUG(2, (T_CALLED("_nc_init_entry(tp=%p)"), (void *) tp));
if (tp == NULL) {
#if NO_LEAKS
if (stringbuf != NULL) {
FreeAndNull(stringbuf);
}
return;
#else
_nc_err_abort("_nc_init_entry called without initialization");
#endif
}
if (stringbuf == NULL)
TYPE_CALLOC(char, (size_t) MAX_ENTRY_SIZE, stringbuf);
next_free = 0;
_nc_init_termtype(&(tp->tterm));
DEBUG(2, (T_RETURN("")));
}
NCURSES_EXPORT(ENTRY *)
_nc_copy_entry(ENTRY * oldp)
{
ENTRY *newp;
DEBUG(2, (T_CALLED("_nc_copy_entry(oldp=%p)"), (void *) oldp));
newp = typeCalloc(ENTRY, 1);
if (newp != NULL) {
*newp = *oldp;
_nc_copy_termtype2(&(newp->tterm), &(oldp->tterm));
}
DEBUG(2, (T_RETURN("%p"), (void *) newp));
return (newp);
}
/* save a copy of string in the string buffer */
NCURSES_EXPORT(char *)
_nc_save_str(const char *string)
{
char *result = 0;
size_t old_next_free = next_free;
if (stringbuf != NULL) {
size_t len;
if (!VALID_STRING(string))
string = "";
len = strlen(string) + 1;
if (len == 1 && next_free != 0) {
/*
* Cheat a little by making an empty string point to the end of the
* previous string.
*/
if (next_free < MAX_ENTRY_SIZE) {
result = (stringbuf + next_free - 1);
}
} else if (next_free + len < MAX_ENTRY_SIZE) {
_nc_STRCPY(&stringbuf[next_free], string, MAX_ENTRY_SIZE);
DEBUG(7, ("Saved string %s", _nc_visbuf(string)));
DEBUG(7, ("at location %d", (int) next_free));
next_free += len;
result = (stringbuf + old_next_free);
} else {
_nc_warning("Too much data, some is lost: %s", string);
}
}
return result;
}
NCURSES_EXPORT(void)
_nc_wrap_entry(ENTRY * const ep, bool copy_strings)
/* copy the string parts to allocated storage, preserving pointers to it */
{
int offsets[MAX_ENTRY_SIZE / sizeof(short)];
int useoffsets[MAX_USES];
unsigned i, n;
unsigned nuses;
TERMTYPE2 *tp;
DEBUG(2, (T_CALLED("_nc_wrap_entry(ep=%p, copy_strings=%d)"), (void *)
ep, copy_strings));
if (ep == NULL || stringbuf == NULL)
_nc_err_abort("_nc_wrap_entry called without initialization");
nuses = ep->nuses;
tp = &(ep->tterm);
if (copy_strings) {
next_free = 0; /* clear static storage */
/* copy term_names, Strings, uses */
tp->term_names = _nc_save_str(tp->term_names);
for_each_string(i, tp) {
if (tp->Strings[i] != ABSENT_STRING &&
tp->Strings[i] != CANCELLED_STRING) {
tp->Strings[i] = _nc_save_str(tp->Strings[i]);
}
}
for (i = 0; i < nuses; i++) {
if (ep->uses[i].name == 0) {
ep->uses[i].name = _nc_save_str(ep->uses[i].name);
}
}
free(tp->str_table);
}
assert(tp->term_names >= stringbuf);
n = (unsigned) (tp->term_names - stringbuf);
for_each_string(i, &(ep->tterm)) {
if (i < SIZEOF(offsets)) {
if (tp->Strings[i] == ABSENT_STRING) {
offsets[i] = ABSENT_OFFSET;
} else if (tp->Strings[i] == CANCELLED_STRING) {
offsets[i] = CANCELLED_OFFSET;
} else {
offsets[i] = (int) (tp->Strings[i] - stringbuf);
}
}
}
for (i = 0; i < nuses; i++) {
if (ep->uses[i].name == 0)
useoffsets[i] = ABSENT_OFFSET;
else
useoffsets[i] = (int) (ep->uses[i].name - stringbuf);
}
TYPE_MALLOC(char, next_free, tp->str_table);
(void) memcpy(tp->str_table, stringbuf, next_free);
tp->term_names = tp->str_table + n;
for_each_string(i, &(ep->tterm)) {
if (i < SIZEOF(offsets)) {
if (offsets[i] == ABSENT_OFFSET) {
tp->Strings[i] = ABSENT_STRING;
} else if (offsets[i] == CANCELLED_OFFSET) {
tp->Strings[i] = CANCELLED_STRING;
} else {
tp->Strings[i] = tp->str_table + offsets[i];
}
}
}
#if NCURSES_XNAMES
if (!copy_strings) {
if ((n = (unsigned) NUM_EXT_NAMES(tp)) != 0) {
if (n < SIZEOF(offsets)) {
size_t length = 0;
size_t offset;
for (i = 0; i < n; i++) {
length += strlen(tp->ext_Names[i]) + 1;
offsets[i] = (int) (tp->ext_Names[i] - stringbuf);
}
TYPE_MALLOC(char, length, tp->ext_str_table);
for (i = 0, offset = 0; i < n; i++) {
tp->ext_Names[i] = tp->ext_str_table + offset;
_nc_STRCPY(tp->ext_Names[i],
stringbuf + offsets[i],
length - offset);
offset += strlen(tp->ext_Names[i]) + 1;
}
}
}
}
#endif
for (i = 0; i < nuses; i++) {
if (useoffsets[i] == ABSENT_OFFSET) {
ep->uses[i].name = 0;
} else {
ep->uses[i].name = strdup(tp->str_table + useoffsets[i]);
}
}
DEBUG(2, (T_RETURN("")));
}
NCURSES_EXPORT(void)
_nc_merge_entry(ENTRY * const target, ENTRY * const source)
/* merge capabilities from `from' entry into `to' entry */
{
TERMTYPE2 *to = &(target->tterm);
TERMTYPE2 *from = &(source->tterm);
#if NCURSES_XNAMES
TERMTYPE2 copy;
size_t str_size;
char *str_table;
#endif
unsigned i;
if (source == 0 || from == 0 || target == 0 || to == 0)
return;
#if NCURSES_XNAMES
_nc_copy_termtype2(&copy, from);
from = &copy;
_nc_align_termtype(to, from);
/*
* compute the maximum size of the string-table.
*/
str_size = strlen(to->term_names) + 1;
for_each_string(i, from) {
if (VALID_STRING(from->Strings[i]))
str_size += strlen(from->Strings[i]) + 1;
}
for_each_string(i, to) {
if (VALID_STRING(to->Strings[i]))
str_size += strlen(to->Strings[i]) + 1;
}
/* allocate a string-table large enough for both source/target, and
* copy all of the strings into that table. In the merge, we will
* select from the original source/target lists to construct a new
* target list.
*/
if (str_size != 0) {
char *str_copied;
if ((str_table = malloc(str_size)) == NULL)
_nc_err_abort(MSG_NO_MEMORY);
str_copied = str_table;
strcpy(str_copied, to->term_names);
to->term_names = str_copied;
str_copied += strlen(str_copied) + 1;
for_each_string(i, from) {
if (VALID_STRING(from->Strings[i])) {
strcpy(str_copied, from->Strings[i]);
from->Strings[i] = str_copied;
str_copied += strlen(str_copied) + 1;
}
}
for_each_string(i, to) {
if (VALID_STRING(to->Strings[i])) {
strcpy(str_copied, to->Strings[i]);
to->Strings[i] = str_copied;
str_copied += strlen(str_copied) + 1;
}
}
free(to->str_table);
to->str_table = str_table;
free(from->str_table);
}
/*
* Do the same for the extended-strings (i.e., lists of capabilities).
*/
str_size = 0;
for (i = 0; i < NUM_EXT_NAMES(from); ++i) {
if (VALID_STRING(from->ext_Names[i]))
str_size += strlen(from->ext_Names[i]) + 1;
}
for (i = 0; i < NUM_EXT_NAMES(to); ++i) {
if (VALID_STRING(to->ext_Names[i]))
str_size += strlen(to->ext_Names[i]) + 1;
}
/* allocate a string-table large enough for both source/target, and
* copy all of the strings into that table. In the merge, we will
* select from the original source/target lists to construct a new
* target list.
*/
if (str_size != 0) {
char *str_copied;
if ((str_table = malloc(str_size)) == NULL)
_nc_err_abort(MSG_NO_MEMORY);
str_copied = str_table;
for (i = 0; i < NUM_EXT_NAMES(from); ++i) {
if (VALID_STRING(from->ext_Names[i])) {
strcpy(str_copied, from->ext_Names[i]);
from->ext_Names[i] = str_copied;
str_copied += strlen(str_copied) + 1;
}
}
for (i = 0; i < NUM_EXT_NAMES(to); ++i) {
if (VALID_STRING(to->ext_Names[i])) {
strcpy(str_copied, to->ext_Names[i]);
to->ext_Names[i] = str_copied;
str_copied += strlen(str_copied) + 1;
}
}
free(to->ext_str_table);
to->ext_str_table = str_table;
free(from->ext_str_table);
}
#endif
for_each_boolean(i, from) {
if (to->Booleans[i] != (NCURSES_SBOOL) CANCELLED_BOOLEAN) {
int mergebool = from->Booleans[i];
if (mergebool == CANCELLED_BOOLEAN)
to->Booleans[i] = FALSE;
else if (mergebool == TRUE)
to->Booleans[i] = (NCURSES_SBOOL) mergebool;
}
}
for_each_number(i, from) {
if (to->Numbers[i] != CANCELLED_NUMERIC) {
int mergenum = from->Numbers[i];
if (mergenum == CANCELLED_NUMERIC)
to->Numbers[i] = ABSENT_NUMERIC;
else if (mergenum != ABSENT_NUMERIC)
to->Numbers[i] = (NCURSES_INT2) mergenum;
}
}
/*
* Note: the copies of strings this makes don't have their own
* storage. This is OK right now, but will be a problem if we
* we ever want to deallocate entries.
*/
for_each_string(i, from) {
if (to->Strings[i] != CANCELLED_STRING) {
char *mergestring = from->Strings[i];
if (mergestring == CANCELLED_STRING)
to->Strings[i] = ABSENT_STRING;
else if (mergestring != ABSENT_STRING)
to->Strings[i] = mergestring;
}
}
#if NCURSES_XNAMES
/* cleanup */
free(copy.Booleans);
free(copy.Numbers);
free(copy.Strings);
free(copy.ext_Names);
#endif
}
#if NO_LEAKS
NCURSES_EXPORT(void)
_nc_alloc_entry_leaks(void)
{
if (stringbuf != NULL) {
FreeAndNull(stringbuf);
}
next_free = 0;
}
#endif

702
third_party/ncurses/alloc_ttype.c vendored Normal file
View file

@ -0,0 +1,702 @@
/****************************************************************************
* Copyright 2018-2021,2022 Thomas E. Dickey *
* Copyright 1999-2016,2017 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 <dickey@clark.net> 1999-on *
****************************************************************************/
/*
* align_ttype.c -- functions for TERMTYPE
*
* _nc_align_termtype()
* _nc_copy_termtype()
*
*/
#include "curses.priv.h"
#include "tic.h"
MODULE_ID("$Id: alloc_ttype.c,v 1.46 2022/09/17 21:44:35 tom Exp $")
#if NCURSES_XNAMES
/*
* Merge the a/b lists into dst. Both a/b are sorted (see _nc_extend_names()),
* so we do not have to worry about order dependencies.
*/
static int
merge_names(char **dst, char **a, int na, char **b, int nb)
{
int n = 0;
while (na > 0 && nb > 0) {
int cmp = strcmp(*a, *b);
if (cmp < 0) {
dst[n++] = *a++;
na--;
} else if (cmp > 0) {
dst[n++] = *b++;
nb--;
} else {
dst[n++] = *a;
a++, b++;
na--, nb--;
}
}
while (na-- > 0) {
dst[n++] = *a++;
}
while (nb-- > 0) {
dst[n++] = *b++;
}
DEBUG(4, ("merge_names -> %d", n));
return n;
}
static bool
find_name(char **table, int item, int length, const char *name)
{
int n;
int result = -1;
for (n = item; n < length; ++n) {
if (!strcmp(table[n], name)) {
DEBUG(4, ("found name '%s' @%d", name, n));
result = n;
break;
}
}
if (result < 0) {
DEBUG(4, ("did not find name '%s'", name));
}
return (result >= 0);
}
#define EXTEND_NUM(num, ext) \
DEBUG(4, ("extending " #num " from %d to %d", \
to->num, (unsigned short) (to->num + (ext - to->ext)))); \
to->num = (unsigned short) (to->num + (ext - to->ext))
static void
realign_data(TERMTYPE2 *to, char **ext_Names,
int ext_Booleans,
int ext_Numbers,
int ext_Strings)
{
int n, m, base;
int to_Booleans = to->ext_Booleans;
int to_Numbers = to->ext_Numbers;
int to_Strings = to->ext_Strings;
int to1, to2, from;
DEBUG(4, ("realign_data %d/%d/%d vs %d/%d/%d",
ext_Booleans,
ext_Numbers,
ext_Strings,
to->ext_Booleans,
to->ext_Numbers,
to->ext_Strings));
if (to->ext_Booleans != ext_Booleans) {
to1 = 0;
to2 = to_Booleans + to1;
from = 0;
EXTEND_NUM(num_Booleans, ext_Booleans);
TYPE_REALLOC(NCURSES_SBOOL, to->num_Booleans, to->Booleans);
for (n = to->ext_Booleans - 1,
m = ext_Booleans - 1,
base = to->num_Booleans - (m + 1); m >= 0; m--) {
if (find_name(to->ext_Names, to1, to2, ext_Names[m + from])) {
to->Booleans[base + m] = to->Booleans[base + n--];
} else {
to->Booleans[base + m] = FALSE;
}
}
to->ext_Booleans = UShort(ext_Booleans);
}
if (to->ext_Numbers != ext_Numbers) {
to1 = to_Booleans;
to2 = to_Numbers + to1;
from = ext_Booleans;
EXTEND_NUM(num_Numbers, ext_Numbers);
TYPE_REALLOC(NCURSES_INT2, to->num_Numbers, to->Numbers);
for (n = to->ext_Numbers - 1,
m = ext_Numbers - 1,
base = to->num_Numbers - (m + 1); m >= 0; m--) {
if (find_name(to->ext_Names, to1, to2, ext_Names[m + from])) {
to->Numbers[base + m] = to->Numbers[base + n--];
} else {
to->Numbers[base + m] = ABSENT_NUMERIC;
}
}
to->ext_Numbers = UShort(ext_Numbers);
}
if (to->ext_Strings != ext_Strings) {
to1 = to_Booleans + to_Numbers;
to2 = to_Strings + to1;
from = ext_Booleans + ext_Numbers;
EXTEND_NUM(num_Strings, ext_Strings);
TYPE_REALLOC(char *, to->num_Strings, to->Strings);
for (n = to->ext_Strings - 1,
m = ext_Strings - 1,
base = to->num_Strings - (m + 1); m >= 0; m--) {
if (find_name(to->ext_Names, to1, to2, ext_Names[m + from])) {
to->Strings[base + m] = to->Strings[base + n--];
} else {
to->Strings[base + m] = ABSENT_STRING;
}
}
to->ext_Strings = UShort(ext_Strings);
}
}
/*
* Returns the first index in ext_Names[] for the given token-type
*/
static unsigned
_nc_first_ext_name(TERMTYPE2 *tp, int token_type)
{
unsigned first;
switch (token_type) {
case BOOLEAN:
first = 0;
break;
case NUMBER:
first = tp->ext_Booleans;
break;
case STRING:
first = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
break;
default:
first = 0;
break;
}
return first;
}
/*
* Returns the last index in ext_Names[] for the given token-type
*/
static unsigned
_nc_last_ext_name(TERMTYPE2 *tp, int token_type)
{
unsigned last;
switch (token_type) {
case BOOLEAN:
last = tp->ext_Booleans;
break;
case NUMBER:
last = (unsigned) (tp->ext_Booleans + tp->ext_Numbers);
break;
default:
case STRING:
last = NUM_EXT_NAMES(tp);
break;
}
return last;
}
/*
* Lookup an entry from extended-names, returning -1 if not found
*/
static int
_nc_find_ext_name(TERMTYPE2 *tp, char *name, int token_type)
{
unsigned j;
unsigned first = _nc_first_ext_name(tp, token_type);
unsigned last = _nc_last_ext_name(tp, token_type);
for (j = first; j < last; j++) {
if (!strcmp(name, tp->ext_Names[j])) {
return (int) j;
}
}
return -1;
}
/*
* Translate an index into ext_Names[] into the corresponding index into data
* (e.g., Booleans[]).
*/
static int
_nc_ext_data_index(TERMTYPE2 *tp, int n, int token_type)
{
switch (token_type) {
case BOOLEAN:
n += (tp->num_Booleans - tp->ext_Booleans);
break;
case NUMBER:
n += (tp->num_Numbers - tp->ext_Numbers)
- (tp->ext_Booleans);
break;
default:
case STRING:
n += (tp->num_Strings - tp->ext_Strings)
- (tp->ext_Booleans + tp->ext_Numbers);
}
return n;
}
/*
* Adjust tables to remove (not free) an extended name and its corresponding
* data.
*/
static bool
_nc_del_ext_name(TERMTYPE2 *tp, char *name, int token_type)
{
int first;
if ((first = _nc_find_ext_name(tp, name, token_type)) >= 0) {
int j;
int last = (int) NUM_EXT_NAMES(tp) - 1;
for (j = first; j < last; j++) {
tp->ext_Names[j] = tp->ext_Names[j + 1];
}
first = _nc_ext_data_index(tp, first, token_type);
switch (token_type) {
case BOOLEAN:
last = tp->num_Booleans - 1;
for (j = first; j < last; j++)
tp->Booleans[j] = tp->Booleans[j + 1];
tp->ext_Booleans--;
tp->num_Booleans--;
break;
case NUMBER:
last = tp->num_Numbers - 1;
for (j = first; j < last; j++)
tp->Numbers[j] = tp->Numbers[j + 1];
tp->ext_Numbers--;
tp->num_Numbers--;
break;
case STRING:
last = tp->num_Strings - 1;
for (j = first; j < last; j++)
tp->Strings[j] = tp->Strings[j + 1];
tp->ext_Strings--;
tp->num_Strings--;
break;
}
return TRUE;
}
return FALSE;
}
/*
* Adjust tables to insert an extended name, making room for new data. The
* index into the corresponding data array is returned.
*/
static int
_nc_ins_ext_name(TERMTYPE2 *tp, char *name, int token_type)
{
unsigned first = _nc_first_ext_name(tp, token_type);
unsigned last = _nc_last_ext_name(tp, token_type);
unsigned total = NUM_EXT_NAMES(tp) + 1;
unsigned j, k;
for (j = first; j < last; j++) {
int cmp = strcmp(name, tp->ext_Names[j]);
if (cmp == 0)
/* already present */
return _nc_ext_data_index(tp, (int) j, token_type);
if (cmp < 0) {
break;
}
}
TYPE_REALLOC(char *, total, tp->ext_Names);
for (k = total - 1; k > j; k--)
tp->ext_Names[k] = tp->ext_Names[k - 1];
tp->ext_Names[j] = name;
j = (unsigned) _nc_ext_data_index(tp, (int) j, token_type);
switch (token_type) {
case BOOLEAN:
tp->ext_Booleans++;
tp->num_Booleans++;
TYPE_REALLOC(NCURSES_SBOOL, tp->num_Booleans, tp->Booleans);
for (k = (unsigned) (tp->num_Booleans - 1); k > j; k--)
tp->Booleans[k] = tp->Booleans[k - 1];
break;
case NUMBER:
tp->ext_Numbers++;
tp->num_Numbers++;
TYPE_REALLOC(NCURSES_INT2, tp->num_Numbers, tp->Numbers);
for (k = (unsigned) (tp->num_Numbers - 1); k > j; k--)
tp->Numbers[k] = tp->Numbers[k - 1];
break;
case STRING:
tp->ext_Strings++;
tp->num_Strings++;
TYPE_REALLOC(char *, tp->num_Strings, tp->Strings);
for (k = (unsigned) (tp->num_Strings - 1); k > j; k--)
tp->Strings[k] = tp->Strings[k - 1];
break;
}
return (int) j;
}
/*
* Look for strings that are marked cancelled, which happen to be the same name
* as a boolean or number. We'll get this as a special case when we get a
* cancellation of a name that is inherited from another entry.
*/
static void
adjust_cancels(TERMTYPE2 *to, TERMTYPE2 *from)
{
int first = to->ext_Booleans + to->ext_Numbers;
int last = first + to->ext_Strings;
int j, k;
DEBUG(3, (T_CALLED("adjust_cancels(%s), from(%s)"),
to ? NonNull(to->term_names) : "?",
from ? NonNull(from->term_names) : "?"));
for (j = first; j < last;) {
char *name = to->ext_Names[j];
int j_str = to->num_Strings - first - to->ext_Strings;
if (to->Strings[j + j_str] == CANCELLED_STRING) {
if (_nc_find_ext_name(from, to->ext_Names[j], BOOLEAN) >= 0) {
if (_nc_del_ext_name(to, name, STRING)
|| _nc_del_ext_name(to, name, NUMBER)) {
k = _nc_ins_ext_name(to, name, BOOLEAN);
to->Booleans[k] = FALSE;
} else {
j++;
}
} else if (_nc_find_ext_name(from, to->ext_Names[j], NUMBER) >= 0) {
if (_nc_del_ext_name(to, name, STRING)
|| _nc_del_ext_name(to, name, BOOLEAN)) {
k = _nc_ins_ext_name(to, name, NUMBER);
to->Numbers[k] = CANCELLED_NUMERIC;
} else {
j++;
}
} else if (_nc_find_ext_name(from, to->ext_Names[j], STRING) >= 0) {
if (_nc_del_ext_name(to, name, NUMBER)
|| _nc_del_ext_name(to, name, BOOLEAN)) {
k = _nc_ins_ext_name(to, name, STRING);
to->Strings[k] = CANCELLED_STRING;
} else {
j++;
}
} else {
j++;
}
} else {
j++;
}
}
DEBUG(3, (T_RETURN("")));
}
NCURSES_EXPORT(void)
_nc_align_termtype(TERMTYPE2 *to, TERMTYPE2 *from)
{
int na;
int nb;
char **ext_Names;
na = to ? ((int) NUM_EXT_NAMES(to)) : 0;
nb = from ? ((int) NUM_EXT_NAMES(from)) : 0;
DEBUG(2, (T_CALLED("_nc_align_termtype to(%d:%s), from(%d:%s)"),
na, to ? NonNull(to->term_names) : "?",
nb, from ? NonNull(from->term_names) : "?"));
if (to != NULL && from != NULL && (na != 0 || nb != 0)) {
int ext_Booleans, ext_Numbers, ext_Strings;
bool used_ext_Names = FALSE;
if ((na == nb) /* check if the arrays are equivalent */
&&(to->ext_Booleans == from->ext_Booleans)
&& (to->ext_Numbers == from->ext_Numbers)
&& (to->ext_Strings == from->ext_Strings)) {
int n;
bool same;
for (n = 0, same = TRUE; n < na; n++) {
if (strcmp(to->ext_Names[n], from->ext_Names[n])) {
same = FALSE;
break;
}
}
if (same) {
DEBUG(2, (T_RETURN("")));
return;
}
}
/*
* This is where we pay for having a simple extension representation.
* Allocate a new ext_Names array and merge the two ext_Names arrays
* into it, updating to's counts for booleans, etc. Fortunately we do
* this only for the terminfo compiler (tic) and comparer (infocmp).
*/
TYPE_MALLOC(char *, (size_t)(na + nb), ext_Names);
if (to->ext_Strings && (from->ext_Booleans + from->ext_Numbers))
adjust_cancels(to, from);
if (from->ext_Strings && (to->ext_Booleans + to->ext_Numbers))
adjust_cancels(from, to);
ext_Booleans = merge_names(ext_Names,
to->ext_Names,
to->ext_Booleans,
from->ext_Names,
from->ext_Booleans);
ext_Numbers = merge_names(ext_Names + ext_Booleans,
to->ext_Names
+ to->ext_Booleans,
to->ext_Numbers,
from->ext_Names
+ from->ext_Booleans,
from->ext_Numbers);
ext_Strings = merge_names(ext_Names + ext_Numbers + ext_Booleans,
to->ext_Names
+ to->ext_Booleans
+ to->ext_Numbers,
to->ext_Strings,
from->ext_Names
+ from->ext_Booleans
+ from->ext_Numbers,
from->ext_Strings);
/*
* Now we must reallocate the Booleans, etc., to allow the data to be
* overlaid.
*/
if (na != (ext_Booleans + ext_Numbers + ext_Strings)) {
realign_data(to, ext_Names, ext_Booleans, ext_Numbers, ext_Strings);
FreeIfNeeded(to->ext_Names);
to->ext_Names = ext_Names;
DEBUG(2, ("realigned %d extended names for '%s' (to)",
NUM_EXT_NAMES(to), to->term_names));
used_ext_Names = TRUE;
}
if (nb != (ext_Booleans + ext_Numbers + ext_Strings)) {
nb = (ext_Booleans + ext_Numbers + ext_Strings);
realign_data(from, ext_Names, ext_Booleans, ext_Numbers, ext_Strings);
TYPE_REALLOC(char *, (size_t) nb, from->ext_Names);
memcpy(from->ext_Names, ext_Names, sizeof(char *) * (size_t) nb);
DEBUG(2, ("realigned %d extended names for '%s' (from)",
NUM_EXT_NAMES(from), from->term_names));
}
if (!used_ext_Names)
free(ext_Names);
}
DEBUG(2, (T_RETURN("")));
}
#endif
#define srcINT 1
#define dstINT 2
/*
* TERMTYPE and TERMTYPE2 differ only with regard to the values in Numbers.
* Use 'mode' to decide which to use.
*/
static void
copy_termtype(TERMTYPE2 *dst, const TERMTYPE2 *src, int mode)
{
unsigned i;
int pass;
char *new_table;
#if NCURSES_EXT_NUMBERS
short *oldptr = 0;
int *newptr = 0;
#endif
DEBUG(2, (T_CALLED("copy_termtype(dst=%p, src=%p, mode=%d)"), (void *)
dst, (const void *) src, mode));
*dst = *src; /* ...to copy the sizes and string-tables */
TYPE_MALLOC(NCURSES_SBOOL, NUM_BOOLEANS(dst), dst->Booleans);
TYPE_MALLOC(char *, NUM_STRINGS(dst), dst->Strings);
memcpy(dst->Booleans,
src->Booleans,
NUM_BOOLEANS(dst) * sizeof(dst->Booleans[0]));
memcpy(dst->Strings,
src->Strings,
NUM_STRINGS(dst) * sizeof(dst->Strings[0]));
new_table = NULL;
for (pass = 0; pass < 2; ++pass) {
size_t str_size = 0;
if (src->term_names != NULL) {
if (pass) {
dst->term_names = new_table + str_size;
strcpy(dst->term_names + str_size, src->term_names);
}
str_size += strlen(src->term_names) + 1;
}
for_each_string(i, src) {
if (VALID_STRING(src->Strings[i])) {
if (pass) {
strcpy(new_table + str_size, src->Strings[i]);
dst->Strings[i] = new_table + str_size;
}
str_size += strlen(src->Strings[i]) + 1;
}
}
if (pass) {
dst->str_table = new_table;
} else {
++str_size;
if ((new_table = malloc(str_size)) == NULL)
_nc_err_abort(MSG_NO_MEMORY);
}
}
#if NCURSES_EXT_NUMBERS
if ((mode & dstINT) == 0) {
DEBUG(2, ("...convert int ->short"));
TYPE_MALLOC(short, NUM_NUMBERS(dst), oldptr);
((TERMTYPE *) dst)->Numbers = oldptr;
} else {
DEBUG(2, ("...copy without changing size"));
TYPE_MALLOC(int, NUM_NUMBERS(dst), newptr);
dst->Numbers = newptr;
}
if ((mode == srcINT) && (oldptr != 0)) {
DEBUG(2, ("...copy int ->short"));
for (i = 0; i < NUM_NUMBERS(dst); ++i) {
if (src->Numbers[i] > MAX_OF_TYPE(short)) {
oldptr[i] = MAX_OF_TYPE(short);
} else {
oldptr[i] = (short) src->Numbers[i];
}
}
} else if ((mode == dstINT) && (newptr != 0)) {
DEBUG(2, ("...copy short ->int"));
for (i = 0; i < NUM_NUMBERS(dst); ++i) {
newptr[i] = ((const short *) (src->Numbers))[i];
}
} else {
DEBUG(2, ("...copy %s without change",
(mode & dstINT)
? "int"
: "short"));
memcpy(dst->Numbers,
src->Numbers,
NUM_NUMBERS(dst) * ((mode & dstINT)
? sizeof(int)
: sizeof(short)));
}
#else
(void) mode;
TYPE_MALLOC(short, NUM_NUMBERS(dst), dst->Numbers);
memcpy(dst->Numbers,
src->Numbers,
NUM_NUMBERS(dst) * sizeof(dst->Numbers[0]));
#endif
#if NCURSES_XNAMES
if ((i = NUM_EXT_NAMES(src)) != 0) {
TYPE_MALLOC(char *, i, dst->ext_Names);
memcpy(dst->ext_Names, src->ext_Names, i * sizeof(char *));
new_table = NULL;
for (pass = 0; pass < 2; ++pass) {
size_t str_size = 0;
char *raw_data = src->ext_str_table;
if (raw_data != NULL) {
for (i = 0; i < src->ext_Strings; ++i) {
size_t skip = strlen(raw_data) + 1;
if (skip != 1) {
if (pass) {
strcpy(new_table + str_size, raw_data);
}
str_size += skip;
raw_data += skip;
}
}
}
for (i = 0; i < NUM_EXT_NAMES(dst); ++i) {
if (VALID_STRING(src->ext_Names[i])) {
if (pass) {
strcpy(new_table + str_size, src->ext_Names[i]);
dst->ext_Names[i] = new_table + str_size;
}
str_size += strlen(src->ext_Names[i]) + 1;
}
}
if (pass) {
dst->ext_str_table = new_table;
} else {
++str_size;
if ((new_table = calloc(str_size, 1)) == NULL)
_nc_err_abort(MSG_NO_MEMORY);
}
}
} else {
dst->ext_Names = 0;
}
#endif
DEBUG(2, (T_RETURN("")));
}
/*
* This entrypoint is used by tack 1.07
*/
NCURSES_EXPORT(void)
_nc_copy_termtype(TERMTYPE *dst, const TERMTYPE *src)
{
DEBUG(2, (T_CALLED("_nc_copy_termtype(dst=%p, src=%p)"), (void *) dst,
(const void *) src));
copy_termtype((TERMTYPE2 *) dst, (const TERMTYPE2 *) src, 0);
DEBUG(2, (T_RETURN("")));
}
#if NCURSES_EXT_NUMBERS
NCURSES_EXPORT(void)
_nc_copy_termtype2(TERMTYPE2 *dst, const TERMTYPE2 *src)
{
DEBUG(2, (T_CALLED("_nc_copy_termtype2(dst=%p, src=%p)"), (void *) dst,
(const void *) src));
copy_termtype(dst, src, srcINT | dstINT);
DEBUG(2, (T_RETURN("")));
}
/*
* Use this for exporting the internal TERMTYPE2 to the legacy format used via
* the CUR macro by applications.
*/
NCURSES_EXPORT(void)
_nc_export_termtype2(TERMTYPE *dst, const TERMTYPE2 *src)
{
DEBUG(2, (T_CALLED("_nc_export_termtype2(dst=%p, src=%p)"), (void *)
dst, (const void *) src));
copy_termtype((TERMTYPE2 *) dst, src, srcINT);
DEBUG(2, (T_RETURN("")));
}
#endif /* NCURSES_EXT_NUMBERS */

108
third_party/ncurses/build.priv.h vendored Normal file
View file

@ -0,0 +1,108 @@
/****************************************************************************
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 2010,2012 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 2010 *
****************************************************************************/
/*
* $Id: build.priv.h,v 1.12 2020/02/02 23:34:34 tom Exp $
*
* build.priv.h
*
* This is a reduced version of curses.priv.h, for build-time utilities.
* Because it has fewer dependencies, this simplifies cross-compiling.
*
*/
#ifndef CURSES_PRIV_H
#define CURSES_PRIV_H 1
#include "ncurses_dll.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "ncurses_cfg.h"
#if USE_RCS_IDS
#define MODULE_ID(id) static const char Ident[] = id;
#else
#define MODULE_ID(id) /*nothing */
#endif
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include "curses.h" /* we'll use -Ipath directive to get the right one! */
/* usually in <unistd.h> */
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif
#define FreeAndNull(p) do { free(p); p = 0; } while (0)
#define UChar(c) ((unsigned char)(c))
#define SIZEOF(v) (sizeof(v) / sizeof(v[0]))
#include "nc_alloc.h"
#include "nc_string.h"
/* declare these, to avoid needing term.h */
#if BROKEN_LINKER || USE_REENTRANT
#define NCURSES_ARRAY(name) \
NCURSES_WRAPPED_VAR(NCURSES_CONST char * const *, name)
NCURSES_ARRAY(boolnames);
NCURSES_ARRAY(boolfnames);
NCURSES_ARRAY(numnames);
NCURSES_ARRAY(numfnames);
NCURSES_ARRAY(strnames);
NCURSES_ARRAY(strfnames);
#endif
#if NO_LEAKS
NCURSES_EXPORT(void) _nc_names_leaks(void);
#endif
#ifdef __cplusplus
}
#endif
#endif /* CURSES_PRIV_H */

87
third_party/ncurses/capdefaults.inc vendored Normal file
View file

@ -0,0 +1,87 @@
/****************************************************************************
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2000,2008 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-on *
****************************************************************************/
/* $Id: capdefaults.c,v 1.16 2021/09/04 10:52:55 tom Exp $ */
/*
* Compute obsolete capabilities. The reason this is an include file is
* that the two places where it is needed require the macros to generate
* offsets to different structures. See the file Caps for explanations of
* these conversions.
*
* Note: This code is the functional inverse of the first part of
* postprocess_termcap().
*/
{
char *strp;
short capval;
#define EXTRACT_DELAY(str) \
(short) (strp = strchr(str, '*'), strp ? atoi(strp+1) : 0)
/* current (4.4BSD) capabilities marked obsolete */
if (VALID_STRING(carriage_return)
&& (capval = EXTRACT_DELAY(carriage_return)))
carriage_return_delay = capval;
if (VALID_STRING(newline) && (capval = EXTRACT_DELAY(newline)))
new_line_delay = capval;
/* current (4.4BSD) capabilities not obsolete */
if (!VALID_STRING(termcap_init2) && VALID_STRING(init_3string)) {
termcap_init2 = init_3string;
init_3string = ABSENT_STRING;
}
if (!VALID_STRING(termcap_reset)
&& VALID_STRING(reset_2string)
&& !VALID_STRING(reset_1string)
&& !VALID_STRING(reset_3string)) {
termcap_reset = reset_2string;
reset_2string = ABSENT_STRING;
}
if (magic_cookie_glitch_ul == ABSENT_NUMERIC
&& magic_cookie_glitch != ABSENT_NUMERIC
&& VALID_STRING(enter_underline_mode))
magic_cookie_glitch_ul = magic_cookie_glitch;
/* totally obsolete capabilities */
linefeed_is_newline = (char) (VALID_STRING(newline)
&& (strcmp("\n", newline) == 0));
if (VALID_STRING(cursor_left)
&& (capval = EXTRACT_DELAY(cursor_left)))
backspace_delay = capval;
if (VALID_STRING(tab) && (capval = EXTRACT_DELAY(tab)))
horizontal_tab_delay = capval;
#undef EXTRACT_DELAY
}

1059
third_party/ncurses/captoinfo.c vendored Normal file

File diff suppressed because it is too large Load diff

85
third_party/ncurses/charable.c vendored Normal file
View file

@ -0,0 +1,85 @@
/****************************************************************************
* Copyright 2018,2020 Thomas E. Dickey *
* Copyright 2003-2005,2008 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. *
****************************************************************************/
/*
** Support functions for wide/narrow conversion.
*/
#include "curses.priv.h"
MODULE_ID("$Id: charable.c,v 1.8 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(bool) _nc_is_charable(wchar_t ch)
{
bool result;
#if HAVE_WCTOB
result = (wctob((wint_t) ch) == (int) ch);
#else
result = (_nc_to_char(ch) >= 0);
#endif
return result;
}
NCURSES_EXPORT(int) _nc_to_char(wint_t ch)
{
int result;
#if HAVE_WCTOB
result = wctob(ch);
#elif HAVE_WCTOMB
char temp[MB_LEN_MAX];
result = wctomb(temp, ch);
if (strlen(temp) == 1)
result = UChar(temp[0]);
else
result = -1;
#else
#error expected either wctob/wctomb
#endif
return result;
}
NCURSES_EXPORT(wint_t) _nc_to_widechar(int ch)
{
wint_t result;
#if HAVE_BTOWC
result = btowc(ch);
#elif HAVE_MBTOWC
wchar_t convert;
char temp[2];
temp[0] = ch;
temp[1] = '\0';
if (mbtowc(&convert, temp, 1) >= 0)
result = convert;
else
result = WEOF;
#else
#error expected either btowc/mbtowc
#endif
return result;
}

675
third_party/ncurses/codes.c vendored Normal file
View file

@ -0,0 +1,675 @@
/* This file was generated by MKcodes.awk */
#include "curses.priv.h"
#define IT NCURSES_CONST char * const
#if BROKEN_LINKER || USE_REENTRANT
static const char _nc_code_blob[] =
"bw\0" "am\0" "xb\0" "xs\0" "xn\0" "eo\0" "gn\0" "hc\0" "km\0" "hs\0" "in\0" \
"da\0" "db\0" "mi\0" "ms\0" "os\0" "es\0" "xt\0" "hz\0" "ul\0" "xo\0" "nx\0" \
"5i\0" "HC\0" "NR\0" "NP\0" "ND\0" "cc\0" "ut\0" "hl\0" "YA\0" "YB\0" "YC\0" \
"YD\0" "YE\0" "YF\0" "YG\0" "co\0" "it\0" "li\0" "lm\0" "sg\0" "pb\0" "vt\0" \
"ws\0" "Nl\0" "lh\0" "lw\0" "ma\0" "MW\0" "Co\0" "pa\0" "NC\0" "Ya\0" "Yb\0" \
"Yc\0" "Yd\0" "Ye\0" "Yf\0" "Yg\0" "Yh\0" "Yi\0" "Yj\0" "Yk\0" "Yl\0" "Ym\0" \
"Yn\0" "BT\0" "Yo\0" "Yp\0" "bt\0" "bl\0" "cr\0" "cs\0" "ct\0" "cl\0" "ce\0" \
"cd\0" "ch\0" "CC\0" "cm\0" "do\0" "ho\0" "vi\0" "le\0" "CM\0" "ve\0" "nd\0" \
"ll\0" "up\0" "vs\0" "dc\0" "dl\0" "ds\0" "hd\0" "as\0" "mb\0" "md\0" "ti\0" \
"dm\0" "mh\0" "im\0" "mk\0" "mp\0" "mr\0" "so\0" "us\0" "ec\0" "ae\0" "me\0" \
"te\0" "ed\0" "ei\0" "se\0" "ue\0" "vb\0" "ff\0" "fs\0" "i1\0" "is\0" "i3\0" \
"if\0" "ic\0" "al\0" "ip\0" "kb\0" "ka\0" "kC\0" "kt\0" "kD\0" "kL\0" "kd\0" \
"kM\0" "kE\0" "kS\0" "k0\0" "k1\0" "k;\0" "k2\0" "k3\0" "k4\0" "k5\0" "k6\0" \
"k7\0" "k8\0" "k9\0" "kh\0" "kI\0" "kA\0" "kl\0" "kH\0" "kN\0" "kP\0" "kr\0" \
"kF\0" "kR\0" "kT\0" "ku\0" "ke\0" "ks\0" "l0\0" "l1\0" "la\0" "l2\0" "l3\0" \
"l4\0" "l5\0" "l6\0" "l7\0" "l8\0" "l9\0" "mo\0" "mm\0" "nw\0" "pc\0" "DC\0" \
"DL\0" "DO\0" "IC\0" "SF\0" "AL\0" "LE\0" "RI\0" "SR\0" "UP\0" "pk\0" "pl\0" \
"px\0" "ps\0" "pf\0" "po\0" "rp\0" "r1\0" "r2\0" "r3\0" "rf\0" "rc\0" "cv\0" \
"sc\0" "sf\0" "sr\0" "sa\0" "st\0" "wi\0" "ta\0" "ts\0" "uc\0" "hu\0" "iP\0" \
"K1\0" "K3\0" "K2\0" "K4\0" "K5\0" "pO\0" "rP\0" "ac\0" "pn\0" "kB\0" "SX\0" \
"RX\0" "SA\0" "RA\0" "XN\0" "XF\0" "eA\0" "LO\0" "LF\0" "@1\0" "@2\0" "@3\0" \
"@4\0" "@5\0" "@6\0" "@7\0" "@8\0" "@9\0" "@0\0" "%1\0" "%2\0" "%3\0" "%4\0" \
"%5\0" "%6\0" "%7\0" "%8\0" "%9\0" "%0\0" "&1\0" "&2\0" "&3\0" "&4\0" "&5\0" \
"&6\0" "&7\0" "&8\0" "&9\0" "&0\0" "*1\0" "*2\0" "*3\0" "*4\0" "*5\0" "*6\0" \
"*7\0" "*8\0" "*9\0" "*0\0" "#1\0" "#2\0" "#3\0" "#4\0" "%a\0" "%b\0" "%c\0" \
"%d\0" "%e\0" "%f\0" "%g\0" "%h\0" "%i\0" "%j\0" "!1\0" "!2\0" "!3\0" "RF\0" \
"F1\0" "F2\0" "F3\0" "F4\0" "F5\0" "F6\0" "F7\0" "F8\0" "F9\0" "FA\0" "FB\0" \
"FC\0" "FD\0" "FE\0" "FF\0" "FG\0" "FH\0" "FI\0" "FJ\0" "FK\0" "FL\0" "FM\0" \
"FN\0" "FO\0" "FP\0" "FQ\0" "FR\0" "FS\0" "FT\0" "FU\0" "FV\0" "FW\0" "FX\0" \
"FY\0" "FZ\0" "Fa\0" "Fb\0" "Fc\0" "Fd\0" "Fe\0" "Ff\0" "Fg\0" "Fh\0" "Fi\0" \
"Fj\0" "Fk\0" "Fl\0" "Fm\0" "Fn\0" "Fo\0" "Fp\0" "Fq\0" "Fr\0" "cb\0" "MC\0" \
"ML\0" "MR\0" "Lf\0" "SC\0" "DK\0" "RC\0" "CW\0" "WG\0" "HU\0" "DI\0" "QD\0" \
"TO\0" "PU\0" "fh\0" "PA\0" "WA\0" "u0\0" "u1\0" "u2\0" "u3\0" "u4\0" "u5\0" \
"u6\0" "u7\0" "u8\0" "u9\0" "op\0" "oc\0" "Ic\0" "Ip\0" "sp\0" "Sf\0" "Sb\0" \
"ZA\0" "ZB\0" "ZC\0" "ZD\0" "ZE\0" "ZF\0" "ZG\0" "ZH\0" "ZI\0" "ZJ\0" "ZK\0" \
"ZL\0" "ZM\0" "ZN\0" "ZO\0" "ZP\0" "ZQ\0" "ZR\0" "ZS\0" "ZT\0" "ZU\0" "ZV\0" \
"ZW\0" "ZX\0" "ZY\0" "ZZ\0" "Za\0" "Zb\0" "Zc\0" "Zd\0" "Ze\0" "Zf\0" "Zg\0" \
"Zh\0" "Zi\0" "Zj\0" "Zk\0" "Zl\0" "Zm\0" "Zn\0" "Zo\0" "Zp\0" "Zq\0" "Zr\0" \
"Zs\0" "Zt\0" "Zu\0" "Zv\0" "Zw\0" "Zx\0" "Zy\0" "Km\0" "Mi\0" "RQ\0" "Gm\0" \
"AF\0" "AB\0" "xl\0" "dv\0" "ci\0" "s0\0" "s1\0" "s2\0" "s3\0" "ML\0" "MT\0" \
"Xy\0" "Zz\0" "Yv\0" "Yw\0" "Yx\0" "Yy\0" "Yz\0" "YZ\0" "S1\0" "S2\0" "S3\0" \
"S4\0" "S5\0" "S6\0" "S7\0" "S8\0" "Xh\0" "Xl\0" "Xo\0" "Xr\0" "Xt\0" "Xv\0" \
"sA\0" "YI\0" "i2\0" "rs\0" "ug\0" "bs\0" "ns\0" "nc\0" "dC\0" "dN\0" "nl\0" \
"bc\0" "MT\0" "NL\0" "dB\0" "dT\0" "kn\0" "ko\0" "ma\0" "pt\0" "xr\0" "G2\0" \
"G3\0" "G1\0" "G4\0" "GR\0" "GL\0" "GU\0" "GD\0" "GH\0" "GV\0" "GC\0" "ml\0" \
"mu\0" "bx\0" ;
static const short _nc_offset_boolcodes[] = {
0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42,
45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87,
90, 93, 96, 99, 102, 105, 108, 1401, 1404, 1407, 1422, 1425, 1443, 1446, };
static NCURSES_CONST char ** ptr_boolcodes = 0;
static const short _nc_offset_numcodes[] = {
111, 114, 117, 120, 123, 126,
129, 132, 135, 138, 141, 144, 147, 150, 153, 156, 159, 162,
165, 168, 171, 174, 177, 180, 183, 186, 189, 192, 195, 198,
201, 204, 207, 1398, 1410, 1413, 1428, 1431, 1434, };
static NCURSES_CONST char ** ptr_numcodes = 0;
static const short _nc_offset_strcodes[] = {
210, 213, 216, 219, 222, 225, 228, 231, 234,
237, 240, 243, 246, 249, 252, 255, 258, 261, 264, 267, 270,
273, 276, 279, 282, 285, 288, 291, 294, 297, 300, 303, 306,
309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342,
345, 348, 351, 354, 357, 360, 363, 366, 369, 372, 375, 378,
381, 384, 387, 390, 393, 396, 399, 402, 405, 408, 411, 414,
417, 420, 423, 426, 429, 432, 435, 438, 441, 444, 447, 450,
453, 456, 459, 462, 465, 468, 471, 474, 477, 480, 483, 486,
489, 492, 495, 498, 501, 504, 507, 510, 513, 516, 519, 522,
525, 528, 531, 534, 537, 540, 543, 546, 549, 552, 555, 558,
561, 564, 567, 570, 573, 576, 579, 582, 585, 588, 591, 594,
597, 600, 603, 606, 609, 612, 615, 618, 621, 624, 627, 630,
633, 636, 639, 642, 645, 648, 651, 654, 657, 660, 663, 666,
669, 672, 675, 678, 681, 684, 687, 690, 693, 696, 699, 702,
705, 708, 711, 714, 717, 720, 723, 726, 729, 732, 735, 738,
741, 744, 747, 750, 753, 756, 759, 762, 765, 768, 771, 774,
777, 780, 783, 786, 789, 792, 795, 798, 801, 804, 807, 810,
813, 816, 819, 822, 825, 828, 831, 834, 837, 840, 843, 846,
849, 852, 855, 858, 861, 864, 867, 870, 873, 876, 879, 882,
885, 888, 891, 894, 897, 900, 903, 906, 909, 912, 915, 918,
921, 924, 927, 930, 933, 936, 939, 942, 945, 948, 951, 954,
957, 960, 963, 966, 969, 972, 975, 978, 981, 984, 987, 990,
993, 996, 999, 1002, 1005, 1008, 1011, 1014, 1017, 1020, 1023,
1026, 1029, 1032, 1035, 1038, 1041, 1044, 1047, 1050, 1053, 1056,
1059, 1062, 1065, 1068, 1071, 1074, 1077, 1080, 1083, 1086, 1089,
1092, 1095, 1098, 1101, 1104, 1107, 1110, 1113, 1116, 1119, 1122,
1125, 1128, 1131, 1134, 1137, 1140, 1143, 1146, 1149, 1152, 1155,
1158, 1161, 1164, 1167, 1170, 1173, 1176, 1179, 1182, 1185, 1188,
1191, 1194, 1197, 1200, 1203, 1206, 1209, 1212, 1215, 1218, 1221,
1224, 1227, 1230, 1233, 1236, 1239, 1242, 1245, 1248, 1251, 1254,
1257, 1260, 1263, 1266, 1269, 1272, 1275, 1278, 1281, 1284, 1287,
1290, 1293, 1296, 1299, 1302, 1305, 1308, 1311, 1314, 1317, 1320,
1323, 1326, 1329, 1332, 1335, 1338, 1341, 1344, 1347, 1350, 1353,
1356, 1359, 1362, 1365, 1368, 1371, 1374, 1377, 1380, 1383, 1386,
1389, 1392, 1395, 1416, 1419,
1437, 1440, 1449, 1452,
1455, 1458, 1461, 1464, 1467, 1470, 1473, 1476, 1479, 1482, 1485,
1488, };
static NCURSES_CONST char ** ptr_strcodes = 0;
static IT *
alloc_array(NCURSES_CONST char ***value, const short *offsets, unsigned size)
{
if (*value == 0) {
if ((*value = typeCalloc(NCURSES_CONST char *, size + 1)) != 0) {
unsigned n;
for (n = 0; n < size; ++n) {
(*value)[n] = (NCURSES_CONST char *) _nc_code_blob + offsets[n];
}
}
}
return *value;
}
#define FIX(it) NCURSES_IMPEXP IT * NCURSES_API NCURSES_PUBLIC_VAR(it)(void) { return alloc_array(&ptr_##it, _nc_offset_##it, SIZEOF(_nc_offset_##it)); }
/* remove public definition which conflicts with FIX() */
#undef boolcodes
#undef numcodes
#undef strcodes
/* add local definition */
FIX(boolcodes)
FIX(numcodes)
FIX(strcodes)
/* restore the public definition */
#define FREE_FIX(it) if (ptr_##it) { FreeAndNull(ptr_##it); }
#define boolcodes NCURSES_PUBLIC_VAR(boolcodes())
#define numcodes NCURSES_PUBLIC_VAR(numcodes())
#define strcodes NCURSES_PUBLIC_VAR(strcodes())
#if NO_LEAKS
NCURSES_EXPORT(void)
_nc_codes_leaks(void)
{
FREE_FIX(boolcodes)
FREE_FIX(numcodes)
FREE_FIX(strcodes)
}
#endif
#else
#define DCL(it) NCURSES_EXPORT_VAR(IT) it[]
DCL(boolcodes) = {
"bw",
"am",
"xb",
"xs",
"xn",
"eo",
"gn",
"hc",
"km",
"hs",
"in",
"da",
"db",
"mi",
"ms",
"os",
"es",
"xt",
"hz",
"ul",
"xo",
"nx",
"5i",
"HC",
"NR",
"NP",
"ND",
"cc",
"ut",
"hl",
"YA",
"YB",
"YC",
"YD",
"YE",
"YF",
"YG",
"bs",
"ns",
"nc",
"MT",
"NL",
"pt",
"xr",
(NCURSES_CONST char *)0,
};
DCL(numcodes) = {
"co",
"it",
"li",
"lm",
"sg",
"pb",
"vt",
"ws",
"Nl",
"lh",
"lw",
"ma",
"MW",
"Co",
"pa",
"NC",
"Ya",
"Yb",
"Yc",
"Yd",
"Ye",
"Yf",
"Yg",
"Yh",
"Yi",
"Yj",
"Yk",
"Yl",
"Ym",
"Yn",
"BT",
"Yo",
"Yp",
"ug",
"dC",
"dN",
"dB",
"dT",
"kn",
(NCURSES_CONST char *)0,
};
DCL(strcodes) = {
"bt",
"bl",
"cr",
"cs",
"ct",
"cl",
"ce",
"cd",
"ch",
"CC",
"cm",
"do",
"ho",
"vi",
"le",
"CM",
"ve",
"nd",
"ll",
"up",
"vs",
"dc",
"dl",
"ds",
"hd",
"as",
"mb",
"md",
"ti",
"dm",
"mh",
"im",
"mk",
"mp",
"mr",
"so",
"us",
"ec",
"ae",
"me",
"te",
"ed",
"ei",
"se",
"ue",
"vb",
"ff",
"fs",
"i1",
"is",
"i3",
"if",
"ic",
"al",
"ip",
"kb",
"ka",
"kC",
"kt",
"kD",
"kL",
"kd",
"kM",
"kE",
"kS",
"k0",
"k1",
"k;",
"k2",
"k3",
"k4",
"k5",
"k6",
"k7",
"k8",
"k9",
"kh",
"kI",
"kA",
"kl",
"kH",
"kN",
"kP",
"kr",
"kF",
"kR",
"kT",
"ku",
"ke",
"ks",
"l0",
"l1",
"la",
"l2",
"l3",
"l4",
"l5",
"l6",
"l7",
"l8",
"l9",
"mo",
"mm",
"nw",
"pc",
"DC",
"DL",
"DO",
"IC",
"SF",
"AL",
"LE",
"RI",
"SR",
"UP",
"pk",
"pl",
"px",
"ps",
"pf",
"po",
"rp",
"r1",
"r2",
"r3",
"rf",
"rc",
"cv",
"sc",
"sf",
"sr",
"sa",
"st",
"wi",
"ta",
"ts",
"uc",
"hu",
"iP",
"K1",
"K3",
"K2",
"K4",
"K5",
"pO",
"rP",
"ac",
"pn",
"kB",
"SX",
"RX",
"SA",
"RA",
"XN",
"XF",
"eA",
"LO",
"LF",
"@1",
"@2",
"@3",
"@4",
"@5",
"@6",
"@7",
"@8",
"@9",
"@0",
"%1",
"%2",
"%3",
"%4",
"%5",
"%6",
"%7",
"%8",
"%9",
"%0",
"&1",
"&2",
"&3",
"&4",
"&5",
"&6",
"&7",
"&8",
"&9",
"&0",
"*1",
"*2",
"*3",
"*4",
"*5",
"*6",
"*7",
"*8",
"*9",
"*0",
"#1",
"#2",
"#3",
"#4",
"%a",
"%b",
"%c",
"%d",
"%e",
"%f",
"%g",
"%h",
"%i",
"%j",
"!1",
"!2",
"!3",
"RF",
"F1",
"F2",
"F3",
"F4",
"F5",
"F6",
"F7",
"F8",
"F9",
"FA",
"FB",
"FC",
"FD",
"FE",
"FF",
"FG",
"FH",
"FI",
"FJ",
"FK",
"FL",
"FM",
"FN",
"FO",
"FP",
"FQ",
"FR",
"FS",
"FT",
"FU",
"FV",
"FW",
"FX",
"FY",
"FZ",
"Fa",
"Fb",
"Fc",
"Fd",
"Fe",
"Ff",
"Fg",
"Fh",
"Fi",
"Fj",
"Fk",
"Fl",
"Fm",
"Fn",
"Fo",
"Fp",
"Fq",
"Fr",
"cb",
"MC",
"ML",
"MR",
"Lf",
"SC",
"DK",
"RC",
"CW",
"WG",
"HU",
"DI",
"QD",
"TO",
"PU",
"fh",
"PA",
"WA",
"u0",
"u1",
"u2",
"u3",
"u4",
"u5",
"u6",
"u7",
"u8",
"u9",
"op",
"oc",
"Ic",
"Ip",
"sp",
"Sf",
"Sb",
"ZA",
"ZB",
"ZC",
"ZD",
"ZE",
"ZF",
"ZG",
"ZH",
"ZI",
"ZJ",
"ZK",
"ZL",
"ZM",
"ZN",
"ZO",
"ZP",
"ZQ",
"ZR",
"ZS",
"ZT",
"ZU",
"ZV",
"ZW",
"ZX",
"ZY",
"ZZ",
"Za",
"Zb",
"Zc",
"Zd",
"Ze",
"Zf",
"Zg",
"Zh",
"Zi",
"Zj",
"Zk",
"Zl",
"Zm",
"Zn",
"Zo",
"Zp",
"Zq",
"Zr",
"Zs",
"Zt",
"Zu",
"Zv",
"Zw",
"Zx",
"Zy",
"Km",
"Mi",
"RQ",
"Gm",
"AF",
"AB",
"xl",
"dv",
"ci",
"s0",
"s1",
"s2",
"s3",
"ML",
"MT",
"Xy",
"Zz",
"Yv",
"Yw",
"Yx",
"Yy",
"Yz",
"YZ",
"S1",
"S2",
"S3",
"S4",
"S5",
"S6",
"S7",
"S8",
"Xh",
"Xl",
"Xo",
"Xr",
"Xt",
"Xv",
"sA",
"YI",
"i2",
"rs",
"nl",
"bc",
"ko",
"ma",
"G2",
"G3",
"G1",
"G4",
"GR",
"GL",
"GU",
"GD",
"GH",
"GV",
"GC",
"ml",
"mu",
"bx",
(NCURSES_CONST char *)0,
};
#endif /* BROKEN_LINKER */

3424
third_party/ncurses/comp_captab.c vendored Normal file

File diff suppressed because it is too large Load diff

168
third_party/ncurses/comp_error.c vendored Normal file
View file

@ -0,0 +1,168 @@
/****************************************************************************
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 1998-2012,2016 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-on *
****************************************************************************/
/*
* comp_error.c -- Error message routines
*
*/
#include "curses.priv.h"
#include "tic.h"
MODULE_ID("$Id: comp_error.c,v 1.40 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings = FALSE;
NCURSES_EXPORT_VAR(int) _nc_curr_line = 0; /* current line # in input */
NCURSES_EXPORT_VAR(int) _nc_curr_col = 0; /* current column # in input */
#define SourceName _nc_globals.comp_sourcename
#define TermType _nc_globals.comp_termtype
NCURSES_EXPORT(const char *)
_nc_get_source(void)
{
return SourceName;
}
NCURSES_EXPORT(void)
_nc_set_source(const char *const name)
{
FreeIfNeeded(SourceName);
SourceName = strdup(name);
}
NCURSES_EXPORT(void)
_nc_set_type(const char *const name)
{
#define MY_SIZE (size_t) MAX_NAME_SIZE
if (TermType == 0)
TermType = typeMalloc(char, MY_SIZE + 1);
if (TermType != 0) {
TermType[0] = '\0';
if (name) {
_nc_STRNCAT(TermType, name, MY_SIZE, MY_SIZE);
}
}
}
NCURSES_EXPORT(void)
_nc_get_type(char *name)
{
#if NO_LEAKS
if (name == 0 && TermType != 0) {
FreeAndNull(TermType);
return;
}
#endif
if (name != 0)
_nc_STRCPY(name, TermType != 0 ? TermType : "", MAX_NAME_SIZE);
}
static NCURSES_INLINE void
where_is_problem(void)
{
fprintf(stderr, "\"%s\"", SourceName ? SourceName : "?");
if (_nc_curr_line >= 0)
fprintf(stderr, ", line %d", _nc_curr_line);
if (_nc_curr_col >= 0)
fprintf(stderr, ", col %d", _nc_curr_col);
if (TermType != 0 && TermType[0] != '\0')
fprintf(stderr, ", terminal '%s'", TermType);
fputc(':', stderr);
fputc(' ', stderr);
}
NCURSES_EXPORT(void)
_nc_warning(const char *const fmt, ...)
{
va_list argp;
if (_nc_suppress_warnings)
return;
where_is_problem();
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
fprintf(stderr, "\n");
va_end(argp);
}
NCURSES_EXPORT(void)
_nc_err_abort(const char *const fmt, ...)
{
va_list argp;
where_is_problem();
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
fprintf(stderr, "\n");
va_end(argp);
exit(EXIT_FAILURE);
}
NCURSES_EXPORT(void)
_nc_syserr_abort(const char *const fmt, ...)
{
va_list argp;
where_is_problem();
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
fprintf(stderr, "\n");
va_end(argp);
#if defined(TRACE) || !defined(NDEBUG)
/* If we're debugging, try to show where the problem occurred - this
* will dump core.
*/
#ifndef USE_ROOT_ENVIRON
if (getuid() != ROOT_UID)
#endif
abort();
#endif
/* Dumping core in production code is not a good idea.
*/
exit(EXIT_FAILURE);
}
#if NO_LEAKS
NCURSES_EXPORT(void)
_nc_comp_error_leaks(void)
{
FreeAndNull(SourceName);
FreeAndNull(TermType);
}
#endif

228
third_party/ncurses/comp_expand.c vendored Normal file
View file

@ -0,0 +1,228 @@
/****************************************************************************
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2016,2017 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 1998 *
****************************************************************************/
#include "curses.priv.h"
#include <ctype.h>
#include "tic.h"
MODULE_ID("$Id: comp_expand.c,v 1.34 2021/09/04 10:29:15 tom Exp $")
#if 0
#define DEBUG_THIS(p) DEBUG(9, p)
#else
#define DEBUG_THIS(p) /* nothing */
#endif
static int
trailing_spaces(const char *src)
{
while (*src == ' ')
src++;
return *src == 0;
}
/* this deals with differences over whether 0x7f and 0x80..0x9f are controls */
#define REALPRINT(s) (UChar(*(s)) < 127 && isprint(UChar(*(s))))
#define P_LIMIT(p) (length - (size_t)(p))
NCURSES_EXPORT(char *)
_nc_tic_expand(const char *srcp, bool tic_format, int numbers)
{
static char *buffer;
static size_t length;
int bufp;
const char *str = VALID_STRING(srcp) ? srcp : "\0\0";
size_t need = (2 + strlen(str)) * 4;
int ch;
int octals = 0;
struct {
int ch;
int offset;
} fixups[MAX_TC_FIXUPS];
if (srcp == 0) {
#if NO_LEAKS
if (buffer != 0) {
FreeAndNull(buffer);
length = 0;
}
#endif
return 0;
}
if (buffer == 0 || need > length) {
if ((buffer = typeRealloc(char, length = need, buffer)) == 0)
return 0;
}
DEBUG_THIS(("_nc_tic_expand %s:%s:%s",
tic_format ? "ti" : "tc",
numbers ? "#" : "",
_nc_visbuf(srcp)));
bufp = 0;
while ((ch = UChar(*str)) != 0) {
if (ch == '%' && REALPRINT(str + 1)) {
buffer[bufp++] = *str++;
/*
* Though the character literals are more compact, most
* terminal descriptions use numbers and are not easy
* to read in character-literal form.
*/
switch (numbers) {
case -1:
if (str[0] == S_QUOTE
&& str[1] != '\\'
&& REALPRINT(str + 1)
&& str[2] == S_QUOTE) {
_nc_SPRINTF(buffer + bufp, _nc_SLIMIT(P_LIMIT(bufp))
"{%d}", str[1]);
bufp += (int) strlen(buffer + bufp);
str += 2;
} else {
buffer[bufp++] = *str;
}
break;
/*
* If we have a "%{number}", try to translate it into
* a "%'char'" form, since that will run a little faster
* when we're interpreting it. Also, having one form
* for the constant makes it simpler to compare terminal
* descriptions.
*/
case 1:
if (str[0] == L_BRACE
&& isdigit(UChar(str[1]))) {
char *dst = 0;
long value = strtol(str + 1, &dst, 0);
if (dst != 0
&& *dst == R_BRACE
&& value < 127
&& value != '\\' /* FIXME */
&& isprint((int) value)) {
ch = (int) value;
buffer[bufp++] = S_QUOTE;
if (ch == '\\'
|| ch == S_QUOTE)
buffer[bufp++] = '\\';
buffer[bufp++] = (char) ch;
buffer[bufp++] = S_QUOTE;
str = dst;
} else {
buffer[bufp++] = *str;
}
} else {
buffer[bufp++] = *str;
}
break;
default:
if (*str == ',') /* minitel1 uses this */
buffer[bufp++] = '\\';
buffer[bufp++] = *str;
break;
}
} else if (ch == 128) {
buffer[bufp++] = '\\';
buffer[bufp++] = '0';
} else if (ch == '\033') {
buffer[bufp++] = '\\';
buffer[bufp++] = 'E';
} else if (ch == '\\' && tic_format && (str == srcp || str[-1] != '^')) {
buffer[bufp++] = '\\';
buffer[bufp++] = '\\';
} else if (ch == ' ' && tic_format && (str == srcp ||
trailing_spaces(str))) {
buffer[bufp++] = '\\';
buffer[bufp++] = 's';
} else if ((ch == ',' || ch == '^') && tic_format) {
buffer[bufp++] = '\\';
buffer[bufp++] = (char) ch;
} else if (REALPRINT(str)
&& (ch != ','
&& !(ch == ':' && !tic_format)
&& !(ch == '!' && !tic_format)
&& ch != '^'))
buffer[bufp++] = (char) ch;
else if (ch == '\r') {
buffer[bufp++] = '\\';
buffer[bufp++] = 'r';
} else if (ch == '\n') {
buffer[bufp++] = '\\';
buffer[bufp++] = 'n';
}
#define UnCtl(c) ((c) + '@')
else if (UChar(ch) < 32
&& isdigit(UChar(str[1]))) {
_nc_SPRINTF(&buffer[bufp], _nc_SLIMIT(P_LIMIT(bufp))
"^%c", UnCtl(ch));
bufp += 2;
} else {
_nc_SPRINTF(&buffer[bufp], _nc_SLIMIT(P_LIMIT(bufp))
"\\%03o", ch);
if ((octals < MAX_TC_FIXUPS) &&
((tic_format && (ch == 127)) || ch < 32)) {
fixups[octals].ch = UChar(ch);
fixups[octals].offset = bufp;
++octals;
}
bufp += 4;
}
str++;
}
buffer[bufp] = '\0';
/*
* If most of a short string is ASCII control characters, reformat the
* string to show those in up-arrow format. For longer strings, it is
* more likely that the characters are just binary coding.
*
* If we're formatting termcap, just use the shorter format (up-arrows).
*/
if (octals != 0 && (!tic_format || (bufp - (4 * octals)) < MIN_TC_FIXUPS)) {
while (--octals >= 0) {
char *p = buffer + fixups[octals].offset;
*p++ = '^';
*p++ = (char) ((fixups[octals].ch == 127)
? '?'
: (fixups[octals].ch + (int) '@'));
while ((p[0] = p[2]) != 0) {
++p;
}
}
}
DEBUG_THIS(("... %s", _nc_visbuf(buffer)));
return (buffer);
}

150
third_party/ncurses/comp_hash.c vendored Normal file
View file

@ -0,0 +1,150 @@
/****************************************************************************
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 1998-2008,2009 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-on *
****************************************************************************/
/*
* comp_hash.c --- Routines to deal with the hashtable of capability
* names.
*
*/
#define USE_TERMLIB 1
#include "curses.priv.h"
#include "tic.h"
#include "hashsize.h"
MODULE_ID("$Id: comp_hash.c,v 1.53 2020/02/02 23:34:34 tom Exp $")
/*
* Finds the entry for the given string in the hash table if present.
* Returns a pointer to the entry in the table or 0 if not found.
*/
/* entrypoint used by tack 1.07 */
NCURSES_EXPORT(struct name_table_entry const *)
_nc_find_entry(const char *string,
const HashValue * hash_table)
{
bool termcap = (hash_table != _nc_get_hash_table(FALSE));
const HashData *data = _nc_get_hash_info(termcap);
int hashvalue;
struct name_table_entry const *ptr = 0;
struct name_table_entry const *real_table;
hashvalue = data->hash_of(string);
if (hashvalue >= 0
&& (unsigned) hashvalue < data->table_size
&& data->table_data[hashvalue] >= 0) {
real_table = _nc_get_table(termcap);
ptr = real_table + data->table_data[hashvalue];
while (!data->compare_names(ptr->nte_name, string)) {
if (ptr->nte_link < 0) {
ptr = 0;
break;
}
ptr = real_table + (ptr->nte_link
+ data->table_data[data->table_size]);
}
}
return (ptr);
}
/*
* Finds the entry for the given name with the given type in the given table if
* present (as distinct from _nc_find_entry, which finds the last entry
* regardless of type).
*
* Returns a pointer to the entry in the table or 0 if not found.
*/
NCURSES_EXPORT(struct name_table_entry const *)
_nc_find_type_entry(const char *string,
int type,
bool termcap)
{
struct name_table_entry const *ptr = NULL;
const HashData *data = _nc_get_hash_info(termcap);
int hashvalue = data->hash_of(string);
if (hashvalue >= 0
&& (unsigned) hashvalue < data->table_size
&& data->table_data[hashvalue] >= 0) {
const struct name_table_entry *const table = _nc_get_table(termcap);
ptr = table + data->table_data[hashvalue];
while (ptr->nte_type != type
|| !data->compare_names(ptr->nte_name, string)) {
if (ptr->nte_link < 0) {
ptr = 0;
break;
}
ptr = table + (ptr->nte_link + data->table_data[data->table_size]);
}
}
return ptr;
}
#if NCURSES_XNAMES
NCURSES_EXPORT(struct user_table_entry const *)
_nc_find_user_entry(const char *string)
{
const HashData *data = _nc_get_hash_user();
int hashvalue;
struct user_table_entry const *ptr = 0;
struct user_table_entry const *real_table;
hashvalue = data->hash_of(string);
if (hashvalue >= 0
&& (unsigned) hashvalue < data->table_size
&& data->table_data[hashvalue] >= 0) {
real_table = _nc_get_userdefs_table();
ptr = real_table + data->table_data[hashvalue];
while (!data->compare_names(ptr->ute_name, string)) {
if (ptr->ute_link < 0) {
ptr = 0;
break;
}
ptr = real_table + (ptr->ute_link
+ data->table_data[data->table_size]);
}
}
return (ptr);
}
#endif /* NCURSES_XNAMES */

771
third_party/ncurses/comp_parse.c vendored Normal file
View file

@ -0,0 +1,771 @@
/****************************************************************************
* Copyright 2018-2021,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 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-on *
****************************************************************************/
/*
* comp_parse.c -- parser driver loop and use handling.
*
* Use this code by calling _nc_read_entry_source() on as many source
* files as you like (either terminfo or termcap syntax). If you
* want use-resolution, call _nc_resolve_uses2(). To free the list
* storage, do _nc_free_entries().
*/
#include "curses.priv.h"
#include <ctype.h>
#include "tic.h"
MODULE_ID("$Id: comp_parse.c,v 1.131 2022/10/23 13:15:58 tom Exp $")
static void sanity_check2(TERMTYPE2 *, bool);
NCURSES_IMPEXP void (NCURSES_API *_nc_check_termtype2) (TERMTYPE2 *, bool) = sanity_check2;
static void fixup_acsc(TERMTYPE2 *, int);
static void
enqueue(ENTRY * ep)
/* add an entry to the in-core list */
{
ENTRY *newp;
DEBUG(2, (T_CALLED("enqueue(ep=%p)"), (void *) ep));
newp = _nc_copy_entry(ep);
if (newp == 0)
_nc_err_abort(MSG_NO_MEMORY);
newp->last = _nc_tail;
_nc_tail = newp;
newp->next = 0;
if (newp->last)
newp->last->next = newp;
DEBUG(2, (T_RETURN("")));
}
#define NAMEBUFFER_SIZE (MAX_NAME_SIZE + 2)
static char *
force_bar(char *dst, char *src)
{
if (strchr(src, '|') == 0) {
size_t len = strlen(src);
if (len > MAX_NAME_SIZE)
len = MAX_NAME_SIZE;
_nc_STRNCPY(dst, src, MAX_NAME_SIZE);
_nc_STRCPY(dst + len, "|", NAMEBUFFER_SIZE - len);
src = dst;
}
return src;
}
#define ForceBar(dst, src) ((strchr(src, '|') == 0) ? force_bar(dst, src) : src)
#if NCURSES_USE_TERMCAP && NCURSES_XNAMES
static char *
skip_index(char *name)
{
char *bar = strchr(name, '|');
if (bar != 0 && (bar - name) == 2)
name = bar + 1;
return name;
}
#endif
static bool
check_collisions(char *n1, char *n2, int counter)
{
char *pstart, *qstart, *pend, *qend;
char nc1[NAMEBUFFER_SIZE];
char nc2[NAMEBUFFER_SIZE];
n1 = ForceBar(nc1, n1);
n2 = ForceBar(nc2, n2);
#if NCURSES_USE_TERMCAP && NCURSES_XNAMES
if ((_nc_syntax == SYN_TERMCAP) && _nc_user_definable) {
n1 = skip_index(n1);
n2 = skip_index(n2);
}
#endif
for (pstart = n1; (pend = strchr(pstart, '|')); pstart = pend + 1) {
for (qstart = n2; (qend = strchr(qstart, '|')); qstart = qend + 1) {
if ((pend - pstart == qend - qstart)
&& memcmp(pstart, qstart, (size_t) (pend - pstart)) == 0) {
if (counter > 0)
(void) fprintf(stderr, "Name collision '%.*s' between\n",
(int) (pend - pstart), pstart);
return (TRUE);
}
}
}
return (FALSE);
}
static char *
next_name(char *name)
{
if (*name != '\0')
++name;
return name;
}
static char *
name_ending(char *name)
{
if (*name == '\0') {
name = 0;
} else {
while (*name != '\0' && *name != '|')
++name;
}
return name;
}
/*
* Essentially, find the conflict reported in check_collisions() and remove
* it from the second name, unless that happens to be the last alias.
*/
static bool
remove_collision(char *n1, char *n2)
{
char *p2 = n2;
char *pstart, *qstart, *pend, *qend;
bool removed = FALSE;
#if NCURSES_USE_TERMCAP && NCURSES_XNAMES
if ((_nc_syntax == SYN_TERMCAP) && _nc_user_definable) {
n1 = skip_index(n1);
p2 = n2 = skip_index(n2);
}
#endif
for (pstart = n1; (pend = name_ending(pstart)); pstart = next_name(pend)) {
for (qstart = n2; (qend = name_ending(qstart)); qstart = next_name(qend)) {
if ((pend - pstart == qend - qstart)
&& memcmp(pstart, qstart, (size_t) (pend - pstart)) == 0) {
if (qstart != p2 || *qend == '|') {
if (*qend == '|')
++qend;
while ((*qstart++ = *qend++) != '\0') ;
fprintf(stderr, "...now\t%s\n", p2);
removed = TRUE;
} else {
fprintf(stderr, "Cannot remove alias '%.*s'\n",
(int) (qend - qstart), qstart);
}
break;
}
}
}
return removed;
}
/* do any of the aliases in a pair of terminal names match? */
NCURSES_EXPORT(bool)
_nc_entry_match(char *n1, char *n2)
{
return check_collisions(n1, n2, 0);
}
/****************************************************************************
*
* Entry compiler and resolution logic
*
****************************************************************************/
NCURSES_EXPORT(void)
_nc_read_entry_source(FILE *fp, char *buf,
int literal, bool silent,
bool(*hook) (ENTRY *))
/* slurp all entries in the given file into core */
{
ENTRY thisentry;
bool oldsuppress = _nc_suppress_warnings;
int immediate = 0;
DEBUG(2,
(T_CALLED("_nc_read_entry_source("
"file=%p, buf=%p, literal=%d, silent=%d, hook=%#"
PRIxPTR ")"),
(void *) fp, buf, literal, silent, (intptr_t) hook));
if (silent)
_nc_suppress_warnings = TRUE; /* shut the lexer up, too */
_nc_reset_input(fp, buf);
for (;;) {
memset(&thisentry, 0, sizeof(thisentry));
if (_nc_parse_entry(&thisentry, literal, silent) == ERR)
break;
if (!isalnum(UChar(thisentry.tterm.term_names[0])))
_nc_err_abort("terminal names must start with letter or digit");
/*
* This can be used for immediate compilation of entries with no "use="
* references to disk. That avoids consuming a lot of memory when the
* resolution code could fetch entries off disk.
*/
if (hook != NULLHOOK && (*hook) (&thisentry)) {
immediate++;
} else {
enqueue(&thisentry);
/*
* The enqueued entry is copied with _nc_copy_termtype(), so we can
* free some of the data from thisentry, i.e., the arrays.
*/
FreeIfNeeded(thisentry.tterm.Booleans);
FreeIfNeeded(thisentry.tterm.Numbers);
FreeIfNeeded(thisentry.tterm.Strings);
FreeIfNeeded(thisentry.tterm.str_table);
#if NCURSES_XNAMES
FreeIfNeeded(thisentry.tterm.ext_Names);
FreeIfNeeded(thisentry.tterm.ext_str_table);
#endif
}
}
if (_nc_tail) {
/* set up the head pointer */
for (_nc_head = _nc_tail; _nc_head->last; _nc_head = _nc_head->last)
continue;
DEBUG(2, ("head = %s", _nc_head->tterm.term_names));
DEBUG(2, ("tail = %s", _nc_tail->tterm.term_names));
}
#ifdef TRACE
else if (!immediate)
DEBUG(2, ("no entries parsed"));
#endif
_nc_suppress_warnings = oldsuppress;
DEBUG(2, (T_RETURN("")));
}
#if 0 && NCURSES_XNAMES
static unsigned
find_capname(TERMTYPE2 *p, const char *name)
{
unsigned num_names = NUM_EXT_NAMES(p);
unsigned n;
if (name != 0) {
for (n = 0; n < num_names; ++n) {
if (!strcmp(p->ext_Names[n], name))
break;
}
} else {
n = num_names + 1;
}
return n;
}
static int
extended_captype(TERMTYPE2 *p, unsigned which)
{
int result = UNDEF;
unsigned limit = 0;
limit += p->ext_Booleans;
if (limit != 0 && which < limit) {
result = BOOLEAN;
} else {
limit += p->ext_Numbers;
if (limit != 0 && which < limit) {
result = NUMBER;
} else {
limit += p->ext_Strings;
if (limit != 0 && which < limit) {
result = ((p->Strings[STRCOUNT + which] != CANCELLED_STRING)
? STRING
: CANCEL);
} else if (which >= limit) {
result = CANCEL;
}
}
}
return result;
}
static const char *
name_of_captype(int which)
{
const char *result = "?";
switch (which) {
case BOOLEAN:
result = "boolean";
break;
case NUMBER:
result = "number";
break;
case STRING:
result = "string";
break;
}
return result;
}
#define valid_TERMTYPE2(p) \
((p) != 0 && \
(p)->term_names != 0 && \
(p)->ext_Names != 0)
/*
* Disallow changing the type of an extended capability when doing a "use"
* if one or the other is a string.
*/
static int
invalid_merge(TERMTYPE2 *to, TERMTYPE2 *from)
{
int rc = FALSE;
if (valid_TERMTYPE2(to)
&& valid_TERMTYPE2(from)) {
char *to_name = _nc_first_name(to->term_names);
char *from_name = strdup(_nc_first_name(from->term_names));
unsigned num_names = NUM_EXT_NAMES(from);
unsigned n;
for (n = 0; n < num_names; ++n) {
const char *capname = from->ext_Names[n];
int tt = extended_captype(to, find_capname(to, capname));
int tf = extended_captype(from, n);
if (tt <= STRING
&& tf <= STRING
&& (tt == STRING) != (tf == STRING)) {
if (from_name != 0 && strcmp(to_name, from_name)) {
_nc_warning("merge of %s to %s changes type of %s from %s to %s",
from_name,
to_name,
from->ext_Names[n],
name_of_captype(tf),
name_of_captype(tt));
} else {
_nc_warning("merge of %s changes type of %s from %s to %s",
to_name,
from->ext_Names[n],
name_of_captype(tf),
name_of_captype(tt));
}
rc = TRUE;
}
}
free(from_name);
}
return rc;
}
#define validate_merge(p, q) \
if (invalid_merge(&((p)->tterm), &((q)->tterm))) \
return FALSE
#else
#define validate_merge(p, q) /* nothing */
#endif
NCURSES_EXPORT(int)
_nc_resolve_uses2(bool fullresolve, bool literal)
/* try to resolve all use capabilities */
{
ENTRY *qp, *rp, *lastread = 0;
bool keepgoing;
unsigned i, j;
int unresolved, total_unresolved, multiples;
DEBUG(2, (T_CALLED("_nc_resolve_uses2")));
/*
* Check for multiple occurrences of the same name.
*/
multiples = 0;
for_entry_list(qp) {
int matchcount = 0;
for_entry_list2(rp, qp->next) {
if (qp > rp
&& check_collisions(qp->tterm.term_names,
rp->tterm.term_names,
matchcount + 1)) {
if (!matchcount++) {
(void) fprintf(stderr, "\t%s\n", rp->tterm.term_names);
}
(void) fprintf(stderr, "and\t%s\n", qp->tterm.term_names);
if (!remove_collision(rp->tterm.term_names,
qp->tterm.term_names)) {
++multiples;
}
}
}
}
if (multiples > 0) {
DEBUG(2, (T_RETURN("false")));
return (FALSE);
}
DEBUG(2, ("NO MULTIPLE NAME OCCURRENCES"));
/*
* First resolution stage: compute link pointers corresponding to names.
*/
total_unresolved = 0;
_nc_curr_col = -1;
for_entry_list(qp) {
unresolved = 0;
for (i = 0; i < qp->nuses; i++) {
bool foundit;
char *child = _nc_first_name(qp->tterm.term_names);
char *lookfor = qp->uses[i].name;
long lookline = qp->uses[i].line;
if (lookfor == 0)
continue;
foundit = FALSE;
_nc_set_type(child);
/* first, try to resolve from in-core records */
for_entry_list(rp) {
if (rp != qp
&& _nc_name_match(rp->tterm.term_names, lookfor, "|")) {
DEBUG(2, ("%s: resolving use=%s %p (in core)",
child, lookfor, lookfor));
qp->uses[i].link = rp;
foundit = TRUE;
/* verify that there are no earlier uses */
for (j = 0; j < i; ++j) {
if (qp->uses[j].link != NULL
&& !strcmp(qp->uses[j].link->tterm.term_names,
rp->tterm.term_names)) {
_nc_warning("duplicate use=%s", lookfor);
break;
}
}
}
}
/* if that didn't work, try to merge in a compiled entry */
if (!foundit) {
TERMTYPE2 thisterm;
char filename[PATH_MAX];
memset(&thisterm, 0, sizeof(thisterm));
if (_nc_read_entry2(lookfor, filename, &thisterm) == 1) {
DEBUG(2, ("%s: resolving use=%s (compiled)",
child, lookfor));
TYPE_MALLOC(ENTRY, 1, rp);
rp->tterm = thisterm;
rp->nuses = 0;
rp->next = lastread;
lastread = rp;
qp->uses[i].link = rp;
foundit = TRUE;
/* verify that there are no earlier uses */
for (j = 0; j < i; ++j) {
if (qp->uses[j].link != NULL
&& !strcmp(qp->uses[j].link->tterm.term_names,
rp->tterm.term_names)) {
_nc_warning("duplicate use=%s", lookfor);
break;
}
}
}
}
/* no good, mark this one unresolvable and complain */
if (!foundit) {
unresolved++;
total_unresolved++;
_nc_curr_line = (int) lookline;
_nc_warning("resolution of use=%s failed", lookfor);
qp->uses[i].link = 0;
}
}
}
if (total_unresolved) {
/* free entries read in off disk */
_nc_free_entries(lastread);
DEBUG(2, (T_RETURN("false")));
return (FALSE);
}
DEBUG(2, ("NAME RESOLUTION COMPLETED OK"));
/*
* OK, at this point all (char *) references in `name' members
* have been successfully converted to (ENTRY *) pointers in
* `link' members. Time to do the actual merges.
*/
if (fullresolve) {
do {
ENTRY merged;
keepgoing = FALSE;
for_entry_list(qp) {
if (qp->nuses > 0) {
DEBUG(2, ("%s: attempting merge of %d entries",
_nc_first_name(qp->tterm.term_names),
qp->nuses));
/*
* If any of the use entries we're looking for is
* incomplete, punt. We'll catch this entry on a
* subsequent pass.
*/
for (i = 0; i < qp->nuses; i++) {
if (qp->uses[i].link
&& qp->uses[i].link->nuses) {
DEBUG(2, ("%s: use entry %d unresolved",
_nc_first_name(qp->tterm.term_names), i));
goto incomplete;
}
}
/*
* First, make sure there is no garbage in the
* merge block. As a side effect, copy into
* the merged entry the name field and string
* table pointer.
*/
_nc_copy_termtype2(&(merged.tterm), &(qp->tterm));
/*
* Now merge in each use entry in the proper
* (reverse) order.
*/
for (; qp->nuses; qp->nuses--) {
int n = (int) (qp->nuses - 1);
validate_merge(&merged, qp->uses[n].link);
_nc_merge_entry(&merged, qp->uses[n].link);
free(qp->uses[n].name);
}
/*
* Now merge in the original entry.
*/
validate_merge(&merged, qp);
_nc_merge_entry(&merged, qp);
/*
* Replace the original entry with the merged one.
*/
FreeIfNeeded(qp->tterm.Booleans);
FreeIfNeeded(qp->tterm.Numbers);
FreeIfNeeded(qp->tterm.Strings);
FreeIfNeeded(qp->tterm.str_table);
#if NCURSES_XNAMES
FreeIfNeeded(qp->tterm.ext_Names);
FreeIfNeeded(qp->tterm.ext_str_table);
#endif
qp->tterm = merged.tterm;
_nc_wrap_entry(qp, TRUE);
/*
* We know every entry is resolvable because name resolution
* didn't bomb. So go back for another pass.
*/
/* FALLTHRU */
incomplete:
keepgoing = TRUE;
}
}
} while
(keepgoing);
DEBUG(2, ("MERGES COMPLETED OK"));
}
DEBUG(2, ("RESOLUTION FINISHED"));
if (fullresolve) {
_nc_curr_col = -1;
for_entry_list(qp) {
_nc_curr_line = (int) qp->startline;
_nc_set_type(_nc_first_name(qp->tterm.term_names));
/*
* tic overrides this function pointer to provide more verbose
* checking.
*/
if (_nc_check_termtype2 != sanity_check2) {
SCREEN *save_SP = SP;
SCREEN fake_sp;
TERMINAL fake_tm;
TERMINAL *save_tm = cur_term;
/*
* Setup so that tic can use ordinary terminfo interface to
* obtain capability information.
*/
memset(&fake_sp, 0, sizeof(fake_sp));
memset(&fake_tm, 0, sizeof(fake_tm));
fake_sp._term = &fake_tm;
TerminalType(&fake_tm) = qp->tterm;
_nc_set_screen(&fake_sp);
set_curterm(&fake_tm);
_nc_check_termtype2(&qp->tterm, literal);
/*
* Checking calls tparm, which can allocate memory. Fix leaks.
*/
#define TPS(name) fake_tm.tparm_state.name
FreeAndNull(TPS(out_buff));
FreeAndNull(TPS(fmt_buff));
#undef TPS
_nc_set_screen(save_SP);
set_curterm(save_tm);
} else {
fixup_acsc(&qp->tterm, literal);
}
}
DEBUG(2, ("SANITY CHECK FINISHED"));
}
DEBUG(2, (T_RETURN("true")));
return (TRUE);
}
/*
* This bit of legerdemain turns all the terminfo variable names into
* references to locations in the arrays Booleans, Numbers, and Strings ---
* precisely what's needed.
*/
#undef CUR
#define CUR tp->
static void
fixup_acsc(TERMTYPE2 *tp, int literal)
{
if (!literal) {
if (acs_chars == ABSENT_STRING
&& PRESENT(enter_alt_charset_mode)
&& PRESENT(exit_alt_charset_mode))
acs_chars = strdup(VT_ACSC);
}
}
static void
sanity_check2(TERMTYPE2 *tp, bool literal)
{
if (!PRESENT(exit_attribute_mode)) {
#ifdef __UNUSED__ /* this casts too wide a net */
bool terminal_entry = !strchr(tp->term_names, '+');
if (terminal_entry &&
(PRESENT(set_attributes)
|| PRESENT(enter_standout_mode)
|| PRESENT(enter_underline_mode)
|| PRESENT(enter_blink_mode)
|| PRESENT(enter_bold_mode)
|| PRESENT(enter_dim_mode)
|| PRESENT(enter_secure_mode)
|| PRESENT(enter_protected_mode)
|| PRESENT(enter_reverse_mode)))
_nc_warning("no exit_attribute_mode");
#endif /* __UNUSED__ */
PAIRED(enter_standout_mode, exit_standout_mode);
PAIRED(enter_underline_mode, exit_underline_mode);
#if defined(enter_italics_mode) && defined(exit_italics_mode)
PAIRED(enter_italics_mode, exit_italics_mode);
#endif
}
/* we do this check/fix in postprocess_termcap(), but some packagers
* prefer to bypass it...
*/
if (!literal) {
fixup_acsc(tp, literal);
ANDMISSING(enter_alt_charset_mode, acs_chars);
ANDMISSING(exit_alt_charset_mode, acs_chars);
}
/* listed in structure-member order of first argument */
PAIRED(enter_alt_charset_mode, exit_alt_charset_mode);
ANDMISSING(enter_blink_mode, exit_attribute_mode);
ANDMISSING(enter_bold_mode, exit_attribute_mode);
PAIRED(exit_ca_mode, enter_ca_mode);
PAIRED(enter_delete_mode, exit_delete_mode);
ANDMISSING(enter_dim_mode, exit_attribute_mode);
PAIRED(enter_insert_mode, exit_insert_mode);
ANDMISSING(enter_secure_mode, exit_attribute_mode);
ANDMISSING(enter_protected_mode, exit_attribute_mode);
ANDMISSING(enter_reverse_mode, exit_attribute_mode);
PAIRED(from_status_line, to_status_line);
PAIRED(meta_off, meta_on);
PAIRED(prtr_on, prtr_off);
PAIRED(save_cursor, restore_cursor);
PAIRED(enter_xon_mode, exit_xon_mode);
PAIRED(enter_am_mode, exit_am_mode);
ANDMISSING(label_off, label_on);
#if defined(display_clock) && defined(remove_clock)
PAIRED(display_clock, remove_clock);
#endif
ANDMISSING(set_color_pair, initialize_pair);
}
#if NO_LEAKS
NCURSES_EXPORT(void)
_nc_leaks_tic(void)
{
T((T_CALLED("_nc_leaks_tic()")));
_nc_globals.leak_checking = TRUE;
_nc_alloc_entry_leaks();
_nc_captoinfo_leaks();
_nc_comp_scan_leaks();
#if BROKEN_LINKER || USE_REENTRANT
_nc_names_leaks();
_nc_codes_leaks();
#endif
_nc_tic_expand(0, FALSE, 0);
T((T_RETURN("")));
}
NCURSES_EXPORT(void)
_nc_free_tic(int code)
{
T((T_CALLED("_nc_free_tic(%d)"), code));
_nc_leaks_tic();
exit_terminfo(code);
}
#endif

1060
third_party/ncurses/comp_scan.c vendored Normal file

File diff suppressed because it is too large Load diff

1225
third_party/ncurses/comp_userdefs.c vendored Normal file

File diff suppressed because it is too large Load diff

2114
third_party/ncurses/curses.h vendored Normal file

File diff suppressed because it is too large Load diff

2579
third_party/ncurses/curses.priv.h vendored Normal file

File diff suppressed because it is too large Load diff

457
third_party/ncurses/db_iterator.c vendored Normal file
View file

@ -0,0 +1,457 @@
/****************************************************************************
* Copyright 2018-2020,2022 Thomas E. Dickey *
* Copyright 2006-2016,2017 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 *
****************************************************************************/
/*
* Iterators for terminal databases.
*/
#include "curses.priv.h"
#include <time.h>
#include "tic.h"
#if USE_HASHED_DB
#include "hashed_db.h"
#endif
MODULE_ID("$Id: db_iterator.c,v 1.49 2022/04/23 20:03:15 tom Exp $")
#define HaveTicDirectory _nc_globals.have_tic_directory
#define KeepTicDirectory _nc_globals.keep_tic_directory
#define TicDirectory _nc_globals.tic_directory
#define my_blob _nc_globals.dbd_blob
#define my_list _nc_globals.dbd_list
#define my_size _nc_globals.dbd_size
#define my_time _nc_globals.dbd_time
#define my_vars _nc_globals.dbd_vars
static void
add_to_blob(const char *text, size_t limit)
{
(void) limit;
if (*text != '\0') {
char *last = my_blob + strlen(my_blob);
if (last != my_blob)
*last++ = NCURSES_PATHSEP;
_nc_STRCPY(last, text, limit);
}
}
static bool
check_existence(const char *name, struct stat *sb)
{
bool result = FALSE;
if (quick_prefix(name)) {
result = TRUE;
} else if (stat(name, sb) == 0
&& (S_ISDIR(sb->st_mode)
|| (S_ISREG(sb->st_mode) && sb->st_size))) {
result = TRUE;
}
#if USE_HASHED_DB
else if (strlen(name) < PATH_MAX - sizeof(DBM_SUFFIX)) {
char temp[PATH_MAX];
_nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) "%s%s", name, DBM_SUFFIX);
if (stat(temp, sb) == 0 && S_ISREG(sb->st_mode) && sb->st_size) {
result = TRUE;
}
}
#endif
return result;
}
/*
* Trim newlines (and backslashes preceding those) and tab characters to
* help simplify scripting of the quick-dump feature. Leave spaces and
* other backslashes alone.
*/
static void
trim_formatting(char *source)
{
char *target = source;
char ch;
while ((ch = *source++) != '\0') {
if (ch == '\\' && *source == '\n')
continue;
if (ch == '\n' || ch == '\t')
continue;
*target++ = ch;
}
*target = '\0';
}
/*
* Store the latest value of an environment variable in my_vars[] so we can
* detect if one changes, invalidating the cached search-list.
*/
static bool
update_getenv(const char *name, DBDIRS which)
{
bool result = FALSE;
if (which < dbdLAST) {
char *value;
char *cached_value = my_vars[which].value;
bool same_value;
if ((value = getenv(name)) != 0) {
value = strdup(value);
}
same_value = ((value == 0 && cached_value == 0) ||
(value != 0 &&
cached_value != 0 &&
strcmp(value, cached_value) == 0));
/* Set variable name to enable checks in cache_expired(). */
my_vars[which].name = name;
if (!same_value) {
FreeIfNeeded(my_vars[which].value);
my_vars[which].value = value;
result = TRUE;
} else {
free(value);
}
}
return result;
}
#if NCURSES_USE_DATABASE || NCURSES_USE_TERMCAP
static char *
cache_getenv(const char *name, DBDIRS which)
{
char *result = 0;
(void) update_getenv(name, which);
if (which < dbdLAST) {
result = my_vars[which].value;
}
return result;
}
#endif
/*
* The cache expires if at least a second has passed since the initial lookup,
* or if one of the environment variables changed.
*
* Only a few applications use multiple lookups of terminal entries, seems that
* aside from bulk I/O such as tic and toe, that leaves interactive programs
* which should not be modifying the terminal databases in a way that would
* invalidate the search-list.
*
* The "1-second" is to allow for user-directed changes outside the program.
*/
static bool
cache_expired(void)
{
bool result = FALSE;
time_t now = time((time_t *) 0);
if (now > my_time) {
result = TRUE;
} else {
DBDIRS n;
for (n = (DBDIRS) 0; n < dbdLAST; ++n) {
if (my_vars[n].name != 0
&& update_getenv(my_vars[n].name, n)) {
result = TRUE;
break;
}
}
}
return result;
}
static void
free_cache(void)
{
FreeAndNull(my_blob);
FreeAndNull(my_list);
}
static void
update_tic_dir(const char *update)
{
free((char *) TicDirectory);
TicDirectory = update;
}
/*
* Record the "official" location of the terminfo directory, according to
* the place where we're writing to, or the normal default, if not.
*/
NCURSES_EXPORT(const char *)
_nc_tic_dir(const char *path)
{
T(("_nc_tic_dir %s", NonNull(path)));
if (!KeepTicDirectory) {
if (path != NULL) {
if (path != TicDirectory)
update_tic_dir(strdup(path));
HaveTicDirectory = TRUE;
} else if (HaveTicDirectory == 0) {
if (use_terminfo_vars()) {
const char *envp;
if ((envp = getenv("TERMINFO")) != 0)
return _nc_tic_dir(envp);
}
}
}
return TicDirectory ? TicDirectory : TERMINFO;
}
/*
* Special fix to prevent the terminfo directory from being moved after tic
* has chdir'd to it. If we let it be changed, then if $TERMINFO has a
* relative path, we'll lose track of the actual directory.
*/
NCURSES_EXPORT(void)
_nc_keep_tic_dir(const char *path)
{
_nc_tic_dir(path);
KeepTicDirectory = TRUE;
}
/*
* Cleanup.
*/
NCURSES_EXPORT(void)
_nc_last_db(void)
{
if (my_blob != 0 && cache_expired()) {
free_cache();
}
}
/*
* This is a simple iterator which allows the caller to step through the
* possible locations for a terminfo directory. ncurses uses this to find
* terminfo files to read.
*/
NCURSES_EXPORT(const char *)
_nc_next_db(DBDIRS * state, int *offset)
{
const char *result;
(void) offset;
if ((int) *state < my_size
&& my_list != 0
&& my_list[*state] != 0) {
result = my_list[*state];
(*state)++;
} else {
result = 0;
}
if (result != 0) {
T(("_nc_next_db %d %s", *state, result));
}
return result;
}
NCURSES_EXPORT(void)
_nc_first_db(DBDIRS * state, int *offset)
{
bool cache_has_expired = FALSE;
*state = dbdTIC;
*offset = 0;
T((T_CALLED("_nc_first_db")));
/* build a blob containing all of the strings we will use for a lookup
* table.
*/
if (my_blob == 0 || (cache_has_expired = cache_expired())) {
size_t blobsize = 0;
const char *values[dbdLAST];
struct stat *my_stat;
int j;
if (cache_has_expired)
free_cache();
for (j = 0; j < dbdLAST; ++j)
values[j] = 0;
/*
* This is the first item in the list, and is used only when tic is
* writing to the database, as a performance improvement.
*/
values[dbdTIC] = TicDirectory;
#if NCURSES_USE_DATABASE
#ifdef TERMINFO_DIRS
values[dbdCfgList] = TERMINFO_DIRS;
#endif
#ifdef TERMINFO
values[dbdCfgOnce] = TERMINFO;
#endif
#endif
#if NCURSES_USE_TERMCAP
values[dbdCfgList2] = TERMPATH;
#endif
if (use_terminfo_vars()) {
#if NCURSES_USE_DATABASE
values[dbdEnvOnce] = cache_getenv("TERMINFO", dbdEnvOnce);
values[dbdHome] = _nc_home_terminfo();
(void) cache_getenv("HOME", dbdHome);
values[dbdEnvList] = cache_getenv("TERMINFO_DIRS", dbdEnvList);
#endif
#if NCURSES_USE_TERMCAP
values[dbdEnvOnce2] = cache_getenv("TERMCAP", dbdEnvOnce2);
/* only use $TERMCAP if it is an absolute path */
if (values[dbdEnvOnce2] != 0
&& *values[dbdEnvOnce2] != '/') {
values[dbdEnvOnce2] = 0;
}
values[dbdEnvList2] = cache_getenv("TERMPATH", dbdEnvList2);
#endif /* NCURSES_USE_TERMCAP */
}
for (j = 0; j < dbdLAST; ++j) {
if (values[j] == 0)
values[j] = "";
blobsize += 2 + strlen(values[j]);
}
my_blob = malloc(blobsize);
if (my_blob != 0) {
*my_blob = '\0';
for (j = 0; j < dbdLAST; ++j) {
add_to_blob(values[j], blobsize);
}
/* Now, build an array which will be pointers to the distinct
* strings in the blob.
*/
blobsize = 2;
for (j = 0; my_blob[j] != '\0'; ++j) {
if (my_blob[j] == NCURSES_PATHSEP)
++blobsize;
}
my_list = typeCalloc(char *, blobsize);
my_stat = typeCalloc(struct stat, blobsize);
if (my_list != 0 && my_stat != 0) {
int k = 0;
my_list[k++] = my_blob;
for (j = 0; my_blob[j] != '\0'; ++j) {
if (my_blob[j] == NCURSES_PATHSEP
&& ((&my_blob[j] - my_list[k - 1]) != 3
|| !quick_prefix(my_list[k - 1]))) {
my_blob[j] = '\0';
my_list[k++] = &my_blob[j + 1];
}
}
/*
* Eliminate duplicates from the list.
*/
for (j = 0; my_list[j] != 0; ++j) {
#ifdef TERMINFO
if (*my_list[j] == '\0')
my_list[j] = strdup(TERMINFO);
#endif
trim_formatting(my_list[j]);
for (k = 0; k < j; ++k) {
if (!strcmp(my_list[j], my_list[k])) {
T(("duplicate %s", my_list[j]));
k = j - 1;
while ((my_list[j] = my_list[j + 1]) != 0) {
++j;
}
j = k;
break;
}
}
}
/*
* Eliminate non-existent databases, and those that happen to
* be symlinked to another location.
*/
for (j = 0; my_list[j] != 0; ++j) {
bool found = check_existence(my_list[j], &my_stat[j]);
#if HAVE_LINK
if (found) {
for (k = 0; k < j; ++k) {
if (my_stat[j].st_dev == my_stat[k].st_dev
&& my_stat[j].st_ino == my_stat[k].st_ino) {
found = FALSE;
break;
}
}
}
#endif
if (!found) {
T(("not found %s", my_list[j]));
k = j;
while ((my_list[k] = my_list[k + 1]) != 0) {
++k;
}
--j;
}
}
my_size = j;
my_time = time((time_t *) 0);
} else {
FreeAndNull(my_blob);
}
free(my_stat);
}
}
returnVoid;
}
#if NO_LEAKS
void
_nc_db_iterator_leaks(void)
{
DBDIRS which;
if (my_blob != 0)
FreeAndNull(my_blob);
if (my_list != 0)
FreeAndNull(my_list);
for (which = 0; (int) which < dbdLAST; ++which) {
my_vars[which].name = 0;
FreeIfNeeded(my_vars[which].value);
my_vars[which].value = 0;
}
update_tic_dir(NULL);
}
#endif

86
third_party/ncurses/define_key.c vendored Normal file
View file

@ -0,0 +1,86 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2009,2014 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 1997-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
#include "curses.priv.h"
MODULE_ID("$Id: define_key.c,v 1.22 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
NCURSES_SP_NAME(define_key) (NCURSES_SP_DCLx const char *str, int keycode)
{
int code = ERR;
T((T_CALLED("define_key(%p, %s,%d)"), (void *) SP_PARM, _nc_visbuf(str), keycode));
if (SP_PARM == 0 || !HasTInfoTerminal(SP_PARM)) {
code = ERR;
} else if (keycode > 0) {
unsigned ukey = (unsigned) keycode;
#ifdef USE_TERM_DRIVER
#define CallHasKey(keycode) CallDriver_1(SP_PARM, td_kyExist, keycode)
#else
#define CallHasKey(keycode) NCURSES_SP_NAME(has_key)(NCURSES_SP_ARGx keycode)
#endif
if (str != 0) {
NCURSES_SP_NAME(define_key) (NCURSES_SP_ARGx str, 0);
} else if (CallHasKey(keycode)) {
while (_nc_remove_key(&(SP_PARM->_keytry), ukey))
code = OK;
}
if (str != 0) {
if (NCURSES_SP_NAME(key_defined) (NCURSES_SP_ARGx str) == 0) {
if (_nc_add_to_try(&(SP_PARM->_keytry), str, ukey) == OK) {
code = OK;
} else {
code = ERR;
}
} else {
code = ERR;
}
}
} else {
while (_nc_remove_string(&(SP_PARM->_keytry), str))
code = OK;
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
define_key(const char *str, int keycode)
{
return NCURSES_SP_NAME(define_key) (CURRENT_SCREEN, str, keycode);
}
#endif

62
third_party/ncurses/doalloc.c vendored Normal file
View file

@ -0,0 +1,62 @@
/****************************************************************************
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2002,2012 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 <dickey@clark.net> 1998 *
****************************************************************************/
/*
* Wrapper for malloc/realloc. Standard implementations allow realloc with
* a null pointer, but older libraries may not (e.g., SunOS).
*
* Also if realloc fails, we discard the old memory to avoid leaks.
*/
#include "curses.priv.h"
MODULE_ID("$Id: doalloc.c,v 1.14 2021/04/24 23:43:39 tom Exp $")
void *
_nc_doalloc(void *oldp, size_t amount)
{
void *newp;
if (oldp != NULL) {
if (amount == 0) {
free(oldp);
newp = NULL;
} else if ((newp = realloc(oldp, amount)) == 0) {
free(oldp);
errno = ENOMEM; /* just in case 'free' reset */
}
} else {
newp = malloc(amount);
}
return newp;
}

194
third_party/ncurses/entries.c vendored Normal file
View file

@ -0,0 +1,194 @@
/****************************************************************************
* Copyright 2019-2021,2022 Thomas E. Dickey *
* Copyright 2006-2012,2017 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 *
* and: Juergen Pfeifer *
****************************************************************************/
#include "curses.priv.h"
#include <ctype.h>
#include "tic.h"
MODULE_ID("$Id: entries.c,v 1.34 2022/08/13 16:57:35 tom Exp $")
/****************************************************************************
*
* Entry queue handling
*
****************************************************************************/
/*
* The entry list is a doubly linked list with NULLs terminating the lists:
*
* --------- --------- ---------
* | | | | | | offset
* |-------| |-------| |-------|
* | ----+-->| ----+-->| NULL | next
* |-------| |-------| |-------|
* | NULL |<--+---- |<--+---- | last
* --------- --------- ---------
* ^ ^
* | |
* | |
* _nc_head _nc_tail
*/
NCURSES_EXPORT_VAR(ENTRY *) _nc_head = 0;
NCURSES_EXPORT_VAR(ENTRY *) _nc_tail = 0;
static ENTRY *
_nc_delink_entry(ENTRY * headp, TERMTYPE2 *tterm)
/* delink the allocated storage for the given list entry */
{
ENTRY *ep, *last;
for (last = 0, ep = headp; ep != 0; last = ep, ep = ep->next) {
if (&(ep->tterm) == tterm) {
if (last != 0) {
last->next = ep->next;
}
if (ep->next != 0) {
ep->next->last = last;
}
if (ep == _nc_head) {
_nc_head = ep->next;
}
if (ep == _nc_tail) {
_nc_tail = last;
}
break;
}
}
return ep;
}
NCURSES_EXPORT(void)
_nc_free_entry(ENTRY * headp, TERMTYPE2 *tterm)
/* free the allocated storage consumed by the given list entry */
{
ENTRY *ep;
if ((ep = _nc_delink_entry(headp, tterm)) != 0) {
free(ep);
}
}
NCURSES_EXPORT(void)
_nc_free_entries(ENTRY * headp)
/* free the allocated storage consumed by list entries */
{
(void) headp; /* unused - _nc_head is altered here! */
while (_nc_head != 0) {
_nc_free_termtype2(&(_nc_head->tterm));
}
}
NCURSES_EXPORT(void)
_nc_leaks_tinfo(void)
{
#if NO_LEAKS
char *s;
#endif
T((T_CALLED("_nc_leaks_tinfo()")));
#if NO_LEAKS
_nc_globals.leak_checking = TRUE;
_nc_free_tparm(cur_term);
_nc_tgetent_leaks();
#ifdef USE_PTHREADS
/*
* Discard any prescreen data which is not used for the current screen.
*/
_nc_lock_global(screen);
{
PRESCREEN_LIST *p;
pthread_t id = GetThreadID();
for (p = _nc_prescreen.allocated; p != 0; p = p->next) {
if (p->id == id && p->sp != CURRENT_SCREEN) {
FreeAndNull(p->sp);
}
}
}
_nc_unlock_global(screen);
#endif
if (TerminalOf(CURRENT_SCREEN) != 0) {
del_curterm(TerminalOf(CURRENT_SCREEN));
}
_nc_forget_prescr();
_nc_comp_captab_leaks();
_nc_comp_userdefs_leaks();
_nc_free_entries(_nc_head);
_nc_get_type(0);
_nc_first_name(0);
_nc_db_iterator_leaks();
_nc_keyname_leaks();
#if BROKEN_LINKER || USE_REENTRANT
_nc_names_leaks();
_nc_codes_leaks();
FreeIfNeeded(_nc_prescreen.real_acs_map);
#endif
_nc_comp_error_leaks();
if ((s = _nc_home_terminfo()) != 0)
free(s);
#ifdef TRACE
T((T_RETURN("")));
curses_trace(0);
_nc_trace_buf(-1, (size_t) 0);
#endif
#endif /* NO_LEAKS */
returnVoid;
}
#if NO_LEAKS
NCURSES_EXPORT(void)
_nc_free_tinfo(int code)
{
T((T_CALLED("_nc_free_tinfo(%d)"), code));
_nc_leaks_tinfo();
exit(code);
}
#endif
NCURSES_EXPORT(void)
exit_terminfo(int code)
{
T((T_CALLED("exit_terminfo(%d)"), code));
#if NO_LEAKS
_nc_leaks_tinfo();
#endif
exit(code);
}

55
third_party/ncurses/eti.h vendored Normal file
View file

@ -0,0 +1,55 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2002,2003 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: Juergen Pfeifer, 1995,1997 *
****************************************************************************/
/* $Id: eti.h,v 1.9 2020/02/02 23:34:34 tom Exp $ */
#ifndef NCURSES_ETI_H_incl
#define NCURSES_ETI_H_incl 1
#define E_OK (0)
#define E_SYSTEM_ERROR (-1)
#define E_BAD_ARGUMENT (-2)
#define E_POSTED (-3)
#define E_CONNECTED (-4)
#define E_BAD_STATE (-5)
#define E_NO_ROOM (-6)
#define E_NOT_POSTED (-7)
#define E_UNKNOWN_COMMAND (-8)
#define E_NO_MATCH (-9)
#define E_NOT_SELECTABLE (-10)
#define E_NOT_CONNECTED (-11)
#define E_REQUEST_DENIED (-12)
#define E_INVALID_FIELD (-13)
#define E_CURRENT (-14)
#endif

61
third_party/ncurses/expanded.c vendored Normal file
View file

@ -0,0 +1,61 @@
/* generated by MKexpanded.sh */
#define NEED_NCURSES_CH_T 1
#include "curses.priv.h"
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
#if NCURSES_EXPANDED
void
_nc_toggle_attr_on (attr_t *S, attr_t at)
{
{ if (((int)((((unsigned long)(at) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))) >> 8))) > 0) { (*S) = ((*S) & ALL_BUT_COLOR) | (attr_t) (at); } else { (*S) |= (attr_t) (at); } ;};
}
void
_nc_toggle_attr_off (attr_t *S, attr_t at)
{
{ if (((int)((((unsigned long)(at) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))) >> 8))) > 0) { (*S) &= ~(at|((chtype)((((1U) << 8) - 1U)) << ((0) + 8))); } else { (*S) &= ~(at); } ;};
}
int
_nc_DelCharCost_sp (SCREEN *sp, int count)
{
return (((cur_term)->type2. Strings[105] != 0) ? sp->_dch_cost : (((cur_term)->type2. Strings[21] != 0) ? (sp->_dch1_cost * count) : 1000000));
}
int
_nc_InsCharCost_sp (SCREEN *sp, int count)
{
return (((cur_term)->type2. Strings[108] != 0) ? sp->_ich_cost : (((cur_term)->type2. Strings[31] && (cur_term)->type2. Strings[42]) ? sp->_smir_cost + sp->_rmir_cost + (sp->_ip_cost * count) : (((cur_term)->type2. Strings[52] != 0) ? ((sp->_ich1_cost + sp->_ip_cost) * count) : 1000000)));
}
void
_nc_UpdateAttrs_sp (SCREEN *sp, const cchar_t * c)
{
if (!((((*((sp)->_current_attr))).attr) == (((*(c))).attr) && ((((*((sp)->_current_attr))).ext_color) ? (((*((sp)->_current_attr))).ext_color) : ((int)((((unsigned long)((((*((sp)->_current_attr))).attr)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))) >> 8)))) == ((((*(c))).ext_color) ? (((*(c))).ext_color) : ((int)((((unsigned long)((((*(c))).attr)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))) >> 8)))))) { do { int vid_pair = ((((*(c))).ext_color) ? (((*(c))).ext_color) : ((int)((((unsigned long)((((*(c))).attr)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))) >> 8)))); vid_puts_sp( sp, (((*(c))).attr), (short) ((((*(c))).ext_color) ? (((*(c))).ext_color) : ((int)((((unsigned long)((((*(c))).attr)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))) >> 8)))), &vid_pair, _nc_outch_sp); } while (0); };
}
#if NCURSES_SP_FUNCS
int
_nc_DelCharCost (int count)
{
return _nc_DelCharCost_sp (SP, count);
}
int
_nc_InsCharCost (int count)
{
return _nc_InsCharCost_sp(SP, count);
}
void
_nc_UpdateAttrs (const cchar_t * c)
{
_nc_UpdateAttrs_sp(SP,c);
}
#endif
#else /* ! NCURSES_EXPANDED */
NCURSES_EXPORT(void) _nc_expanded (void) { }
#endif /* NCURSES_EXPANDED */

34
third_party/ncurses/fallback.c vendored Normal file
View file

@ -0,0 +1,34 @@
/* This file was generated by ./tinfo/MKfallback.sh */
/*
* DO NOT EDIT THIS FILE BY HAND!
*/
#include "curses.priv.h"
NCURSES_EXPORT(const TERMTYPE2 *)
_nc_fallback2 (const char *name GCC_UNUSED)
{
/* the fallback list is empty */
return((const TERMTYPE2 *)0);
}
#if NCURSES_EXT_NUMBERS
#undef _nc_fallback
/*
* This entrypoint is used by tack 1.07
*/
NCURSES_EXPORT(const TERMTYPE *)
_nc_fallback (const char *name)
{
const TERMTYPE2 *tp = _nc_fallback2(name);
const TERMTYPE *result = 0;
if (tp != 0) {
static TERMTYPE temp;
_nc_export_termtype2(&temp, tp);
result = &temp;
}
return result;
}
#endif

86
third_party/ncurses/fifo_defs.h vendored Normal file
View file

@ -0,0 +1,86 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2012,2016 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> *
****************************************************************************/
/*
* Common macros for lib_getch.c, lib_ungetch.c
*
* $Id: fifo_defs.h,v 1.9 2020/02/02 23:34:34 tom Exp $
*/
#ifndef FIFO_DEFS_H
#define FIFO_DEFS_H 1
#define head sp->_fifohead
#define tail sp->_fifotail
/* peek points to next uninterpreted character */
#define peek sp->_fifopeek
#define h_inc() { \
(head >= FIFO_SIZE-1) \
? head = 0 \
: head++; \
if (head == tail) \
head = -1, tail = 0; \
}
#define h_dec() { \
(head <= 0) \
? head = FIFO_SIZE-1 \
: head--; \
if (head == tail) \
tail = -1; \
}
#define t_inc() { \
(tail >= FIFO_SIZE-1) \
? tail = 0 \
: tail++; \
if (tail == head) \
tail = -1; \
}
#define t_dec() { \
(tail <= 0) \
? tail = FIFO_SIZE-1 \
: tail--; \
if (head == tail) \
fifo_clear(sp); \
}
#define p_inc() { \
(peek >= FIFO_SIZE-1) \
? peek = 0 \
: peek++; \
}
#define cooked_key_in_fifo() ((head >= 0) && (peek != head))
#define raw_key_in_fifo() ((head >= 0) && (peek != tail))
#endif /* FIFO_DEFS_H */

460
third_party/ncurses/form.h vendored Normal file
View file

@ -0,0 +1,460 @@
/****************************************************************************
* Copyright 2018-2019-2020,2021 Thomas E. Dickey *
* Copyright 1998-2016,2017 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: Juergen Pfeifer, 1995,1997 *
****************************************************************************/
/* $Id: form.h,v 0.32 2021/06/17 21:26:02 tom Exp $ */
#ifndef FORM_H
#define FORM_H
/* *INDENT-OFF*/
#include "curses.h"
#include <eti.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(BUILDING_FORM)
# define FORM_IMPEXP NCURSES_EXPORT_GENERAL_EXPORT
#else
# define FORM_IMPEXP NCURSES_EXPORT_GENERAL_IMPORT
#endif
#define FORM_WRAPPED_VAR(type,name) extern FORM_IMPEXP type NCURSES_PUBLIC_VAR(name)(void)
#define FORM_EXPORT(type) FORM_IMPEXP type NCURSES_API
#define FORM_EXPORT_VAR(type) FORM_IMPEXP type
#ifndef FORM_PRIV_H
typedef void *FIELD_CELL;
#endif
#ifndef NCURSES_FIELD_INTERNALS
#define NCURSES_FIELD_INTERNALS /* nothing */
#endif
typedef int Form_Options;
typedef int Field_Options;
/**********
* _PAGE *
**********/
typedef struct pagenode
#if !NCURSES_OPAQUE_FORM
{
short pmin; /* index of first field on page */
short pmax; /* index of last field on page */
short smin; /* index of top leftmost field on page */
short smax; /* index of bottom rightmost field on page */
}
#endif /* !NCURSES_OPAQUE_FORM */
_PAGE;
/**********
* FIELD *
**********/
typedef struct fieldnode
#if 1 /* not yet: !NCURSES_OPAQUE_FORM */
{
unsigned short status; /* flags */
short rows; /* size in rows */
short cols; /* size in cols */
short frow; /* first row */
short fcol; /* first col */
int drows; /* dynamic rows */
int dcols; /* dynamic cols */
int maxgrow; /* maximum field growth */
int nrow; /* off-screen rows */
short nbuf; /* additional buffers */
short just; /* justification */
short page; /* page on form */
short index; /* into form -> field */
int pad; /* pad character */
chtype fore; /* foreground attribute */
chtype back; /* background attribute */
Field_Options opts; /* options */
struct fieldnode * snext; /* sorted order pointer */
struct fieldnode * sprev; /* sorted order pointer */
struct fieldnode * link; /* linked field chain */
struct formnode * form; /* containing form */
struct typenode * type; /* field type */
void * arg; /* argument for type */
FIELD_CELL * buf; /* field buffers */
void * usrptr; /* user pointer */
/*
* The wide-character configuration requires extra information. Because
* there are existing applications that manipulate the members of FIELD
* directly, we cannot make the struct opaque, except by changing the ABI.
* Offsets of members up to this point are the same in the narrow- and
* wide-character configuration. But note that the type of buf depends on
* the configuration, and is made opaque for that reason.
*/
NCURSES_FIELD_INTERNALS
}
#endif /* NCURSES_OPAQUE_FORM */
FIELD;
/*********
* FORM *
*********/
typedef struct formnode
#if 1 /* not yet: !NCURSES_OPAQUE_FORM */
{
unsigned short status; /* flags */
short rows; /* size in rows */
short cols; /* size in cols */
int currow; /* current row in field window */
int curcol; /* current col in field window */
int toprow; /* in scrollable field window */
int begincol; /* in horiz. scrollable field */
short maxfield; /* number of fields */
short maxpage; /* number of pages */
short curpage; /* index into page */
Form_Options opts; /* options */
WINDOW * win; /* window */
WINDOW * sub; /* subwindow */
WINDOW * w; /* window for current field */
FIELD ** field; /* field [maxfield] */
FIELD * current; /* current field */
_PAGE * page; /* page [maxpage] */
void * usrptr; /* user pointer */
void (*forminit)(struct formnode *);
void (*formterm)(struct formnode *);
void (*fieldinit)(struct formnode *);
void (*fieldterm)(struct formnode *);
}
#endif /* !NCURSES_OPAQUE_FORM */
FORM;
/**************
* FIELDTYPE *
**************/
typedef struct typenode
#if !NCURSES_OPAQUE_FORM
{
unsigned short status; /* flags */
long ref; /* reference count */
struct typenode * left; /* ptr to operand for | */
struct typenode * right; /* ptr to operand for | */
void* (*makearg)(va_list *); /* make fieldtype arg */
void* (*copyarg)(const void *); /* copy fieldtype arg */
void (*freearg)(void *); /* free fieldtype arg */
#if NCURSES_INTEROP_FUNCS
union {
bool (*ofcheck)(FIELD *,const void *); /* field validation */
bool (*gfcheck)(FORM*,FIELD *,const void*); /* generic field validation */
} fieldcheck;
union {
bool (*occheck)(int,const void *); /* character validation */
bool (*gccheck)(int,FORM*,
FIELD*,const void*); /* generic char validation */
} charcheck;
union {
bool (*onext)(FIELD *,const void *); /* enumerate next value */
bool (*gnext)(FORM*,FIELD*,const void*); /* generic enumerate next */
} enum_next;
union {
bool (*oprev)(FIELD *,const void *); /* enumerate prev value */
bool (*gprev)(FORM*,FIELD*,const void*); /* generic enumerate prev */
} enum_prev;
void* (*genericarg)(void*); /* Alternate Arg method */
#else
bool (*fcheck)(FIELD *,const void *); /* field validation */
bool (*ccheck)(int,const void *); /* character validation */
bool (*next)(FIELD *,const void *); /* enumerate next value */
bool (*prev)(FIELD *,const void *); /* enumerate prev value */
#endif
}
#endif /* !NCURSES_OPAQUE_FORM */
FIELDTYPE;
typedef void (*Form_Hook)(FORM *);
/***************************
* miscellaneous #defines *
***************************/
/* field justification */
#define NO_JUSTIFICATION (0)
#define JUSTIFY_LEFT (1)
#define JUSTIFY_CENTER (2)
#define JUSTIFY_RIGHT (3)
/* field options */
#define O_VISIBLE (0x0001U)
#define O_ACTIVE (0x0002U)
#define O_PUBLIC (0x0004U)
#define O_EDIT (0x0008U)
#define O_WRAP (0x0010U)
#define O_BLANK (0x0020U)
#define O_AUTOSKIP (0x0040U)
#define O_NULLOK (0x0080U)
#define O_PASSOK (0x0100U)
#define O_STATIC (0x0200U)
#define O_DYNAMIC_JUSTIFY (0x0400U) /* ncurses extension */
#define O_NO_LEFT_STRIP (0x0800U) /* ncurses extension */
#define O_EDGE_INSERT_STAY (0x1000U) /* ncurses extension */
#define O_INPUT_LIMIT (0x2000U) /* ncurses extension */
/* form options */
#define O_NL_OVERLOAD (0x0001U)
#define O_BS_OVERLOAD (0x0002U)
/* form driver commands */
#define REQ_NEXT_PAGE (KEY_MAX + 1) /* move to next page */
#define REQ_PREV_PAGE (KEY_MAX + 2) /* move to previous page */
#define REQ_FIRST_PAGE (KEY_MAX + 3) /* move to first page */
#define REQ_LAST_PAGE (KEY_MAX + 4) /* move to last page */
#define REQ_NEXT_FIELD (KEY_MAX + 5) /* move to next field */
#define REQ_PREV_FIELD (KEY_MAX + 6) /* move to previous field */
#define REQ_FIRST_FIELD (KEY_MAX + 7) /* move to first field */
#define REQ_LAST_FIELD (KEY_MAX + 8) /* move to last field */
#define REQ_SNEXT_FIELD (KEY_MAX + 9) /* move to sorted next field */
#define REQ_SPREV_FIELD (KEY_MAX + 10) /* move to sorted prev field */
#define REQ_SFIRST_FIELD (KEY_MAX + 11) /* move to sorted first field */
#define REQ_SLAST_FIELD (KEY_MAX + 12) /* move to sorted last field */
#define REQ_LEFT_FIELD (KEY_MAX + 13) /* move to left to field */
#define REQ_RIGHT_FIELD (KEY_MAX + 14) /* move to right to field */
#define REQ_UP_FIELD (KEY_MAX + 15) /* move to up to field */
#define REQ_DOWN_FIELD (KEY_MAX + 16) /* move to down to field */
#define REQ_NEXT_CHAR (KEY_MAX + 17) /* move to next char in field */
#define REQ_PREV_CHAR (KEY_MAX + 18) /* move to prev char in field */
#define REQ_NEXT_LINE (KEY_MAX + 19) /* move to next line in field */
#define REQ_PREV_LINE (KEY_MAX + 20) /* move to prev line in field */
#define REQ_NEXT_WORD (KEY_MAX + 21) /* move to next word in field */
#define REQ_PREV_WORD (KEY_MAX + 22) /* move to prev word in field */
#define REQ_BEG_FIELD (KEY_MAX + 23) /* move to first char in field */
#define REQ_END_FIELD (KEY_MAX + 24) /* move after last char in fld */
#define REQ_BEG_LINE (KEY_MAX + 25) /* move to beginning of line */
#define REQ_END_LINE (KEY_MAX + 26) /* move after last char in line */
#define REQ_LEFT_CHAR (KEY_MAX + 27) /* move left in field */
#define REQ_RIGHT_CHAR (KEY_MAX + 28) /* move right in field */
#define REQ_UP_CHAR (KEY_MAX + 29) /* move up in field */
#define REQ_DOWN_CHAR (KEY_MAX + 30) /* move down in field */
#define REQ_NEW_LINE (KEY_MAX + 31) /* insert/overlay new line */
#define REQ_INS_CHAR (KEY_MAX + 32) /* insert blank char at cursor */
#define REQ_INS_LINE (KEY_MAX + 33) /* insert blank line at cursor */
#define REQ_DEL_CHAR (KEY_MAX + 34) /* delete char at cursor */
#define REQ_DEL_PREV (KEY_MAX + 35) /* delete char before cursor */
#define REQ_DEL_LINE (KEY_MAX + 36) /* delete line at cursor */
#define REQ_DEL_WORD (KEY_MAX + 37) /* delete word at cursor */
#define REQ_CLR_EOL (KEY_MAX + 38) /* clear to end of line */
#define REQ_CLR_EOF (KEY_MAX + 39) /* clear to end of field */
#define REQ_CLR_FIELD (KEY_MAX + 40) /* clear entire field */
#define REQ_OVL_MODE (KEY_MAX + 41) /* begin overlay mode */
#define REQ_INS_MODE (KEY_MAX + 42) /* begin insert mode */
#define REQ_SCR_FLINE (KEY_MAX + 43) /* scroll field forward a line */
#define REQ_SCR_BLINE (KEY_MAX + 44) /* scroll field backward a line */
#define REQ_SCR_FPAGE (KEY_MAX + 45) /* scroll field forward a page */
#define REQ_SCR_BPAGE (KEY_MAX + 46) /* scroll field backward a page */
#define REQ_SCR_FHPAGE (KEY_MAX + 47) /* scroll field forward half page */
#define REQ_SCR_BHPAGE (KEY_MAX + 48) /* scroll field backward half page */
#define REQ_SCR_FCHAR (KEY_MAX + 49) /* horizontal scroll char */
#define REQ_SCR_BCHAR (KEY_MAX + 50) /* horizontal scroll char */
#define REQ_SCR_HFLINE (KEY_MAX + 51) /* horizontal scroll line */
#define REQ_SCR_HBLINE (KEY_MAX + 52) /* horizontal scroll line */
#define REQ_SCR_HFHALF (KEY_MAX + 53) /* horizontal scroll half line */
#define REQ_SCR_HBHALF (KEY_MAX + 54) /* horizontal scroll half line */
#define REQ_VALIDATION (KEY_MAX + 55) /* validate field */
#define REQ_NEXT_CHOICE (KEY_MAX + 56) /* display next field choice */
#define REQ_PREV_CHOICE (KEY_MAX + 57) /* display prev field choice */
#define MIN_FORM_COMMAND (KEY_MAX + 1) /* used by form_driver */
#define MAX_FORM_COMMAND (KEY_MAX + 57) /* used by form_driver */
#if defined(MAX_COMMAND)
# if (MAX_FORM_COMMAND > MAX_COMMAND)
# error Something is wrong -- MAX_FORM_COMMAND is greater than MAX_COMMAND
# elif (MAX_COMMAND != (KEY_MAX + 128))
# error Something is wrong -- MAX_COMMAND is already inconsistently defined.
# endif
#else
# define MAX_COMMAND (KEY_MAX + 128)
#endif
/*************************
* standard field types *
*************************/
extern FORM_EXPORT_VAR(FIELDTYPE *) TYPE_ALPHA;
extern FORM_EXPORT_VAR(FIELDTYPE *) TYPE_ALNUM;
extern FORM_EXPORT_VAR(FIELDTYPE *) TYPE_ENUM;
extern FORM_EXPORT_VAR(FIELDTYPE *) TYPE_INTEGER;
extern FORM_EXPORT_VAR(FIELDTYPE *) TYPE_NUMERIC;
extern FORM_EXPORT_VAR(FIELDTYPE *) TYPE_REGEXP;
/************************************
* built-in additional field types *
* They are not defined in SVr4 *
************************************/
extern FORM_EXPORT_VAR(FIELDTYPE *) TYPE_IPV4; /* Internet IP Version 4 address */
/***********************
* FIELDTYPE routines *
***********************/
extern FORM_EXPORT(FIELDTYPE *) new_fieldtype (
bool (* const field_check)(FIELD *,const void *),
bool (* const char_check)(int,const void *));
extern FORM_EXPORT(FIELDTYPE *) link_fieldtype(
FIELDTYPE *, FIELDTYPE *);
extern FORM_EXPORT(int) free_fieldtype (FIELDTYPE *);
extern FORM_EXPORT(int) set_fieldtype_arg (FIELDTYPE *,
void * (* const make_arg)(va_list *),
void * (* const copy_arg)(const void *),
void (* const free_arg)(void *));
extern FORM_EXPORT(int) set_fieldtype_choice (FIELDTYPE *,
bool (* const next_choice)(FIELD *,const void *),
bool (* const prev_choice)(FIELD *,const void *));
/*******************
* FIELD routines *
*******************/
extern FORM_EXPORT(FIELD *) new_field (int,int,int,int,int,int);
extern FORM_EXPORT(FIELD *) dup_field (FIELD *,int,int);
extern FORM_EXPORT(FIELD *) link_field (FIELD *,int,int);
extern FORM_EXPORT(int) free_field (FIELD *);
extern FORM_EXPORT(int) field_info (const FIELD *,int *,int *,int *,int *,int *,int *);
extern FORM_EXPORT(int) dynamic_field_info (const FIELD *,int *,int *,int *);
extern FORM_EXPORT(int) set_max_field ( FIELD *,int);
extern FORM_EXPORT(int) move_field (FIELD *,int,int);
extern FORM_EXPORT(int) set_field_type (FIELD *,FIELDTYPE *,...);
extern FORM_EXPORT(int) set_new_page (FIELD *,bool);
extern FORM_EXPORT(int) set_field_just (FIELD *,int);
extern FORM_EXPORT(int) field_just (const FIELD *);
extern FORM_EXPORT(int) set_field_fore (FIELD *,chtype);
extern FORM_EXPORT(int) set_field_back (FIELD *,chtype);
extern FORM_EXPORT(int) set_field_pad (FIELD *,int);
extern FORM_EXPORT(int) field_pad (const FIELD *);
extern FORM_EXPORT(int) set_field_buffer (FIELD *,int,const char *);
extern FORM_EXPORT(int) set_field_status (FIELD *,bool);
extern FORM_EXPORT(int) set_field_userptr (FIELD *, void *);
extern FORM_EXPORT(int) set_field_opts (FIELD *,Field_Options);
extern FORM_EXPORT(int) field_opts_on (FIELD *,Field_Options);
extern FORM_EXPORT(int) field_opts_off (FIELD *,Field_Options);
extern FORM_EXPORT(chtype) field_fore (const FIELD *);
extern FORM_EXPORT(chtype) field_back (const FIELD *);
extern FORM_EXPORT(bool) new_page (const FIELD *);
extern FORM_EXPORT(bool) field_status (const FIELD *);
extern FORM_EXPORT(void *) field_arg (const FIELD *);
extern FORM_EXPORT(void *) field_userptr (const FIELD *);
extern FORM_EXPORT(FIELDTYPE *) field_type (const FIELD *);
extern FORM_EXPORT(char *) field_buffer (const FIELD *,int);
extern FORM_EXPORT(Field_Options) field_opts (const FIELD *);
/******************
* FORM routines *
******************/
extern FORM_EXPORT(FORM *) new_form (FIELD **);
extern FORM_EXPORT(FIELD **) form_fields (const FORM *);
extern FORM_EXPORT(FIELD *) current_field (const FORM *);
extern FORM_EXPORT(WINDOW *) form_win (const FORM *);
extern FORM_EXPORT(WINDOW *) form_sub (const FORM *);
extern FORM_EXPORT(Form_Hook) form_init (const FORM *);
extern FORM_EXPORT(Form_Hook) form_term (const FORM *);
extern FORM_EXPORT(Form_Hook) field_init (const FORM *);
extern FORM_EXPORT(Form_Hook) field_term (const FORM *);
extern FORM_EXPORT(int) free_form (FORM *);
extern FORM_EXPORT(int) set_form_fields (FORM *,FIELD **);
extern FORM_EXPORT(int) field_count (const FORM *);
extern FORM_EXPORT(int) set_form_win (FORM *,WINDOW *);
extern FORM_EXPORT(int) set_form_sub (FORM *,WINDOW *);
extern FORM_EXPORT(int) set_current_field (FORM *,FIELD *);
extern FORM_EXPORT(int) unfocus_current_field (FORM *);
extern FORM_EXPORT(int) field_index (const FIELD *);
extern FORM_EXPORT(int) set_form_page (FORM *,int);
extern FORM_EXPORT(int) form_page (const FORM *);
extern FORM_EXPORT(int) scale_form (const FORM *,int *,int *);
extern FORM_EXPORT(int) set_form_init (FORM *,Form_Hook);
extern FORM_EXPORT(int) set_form_term (FORM *,Form_Hook);
extern FORM_EXPORT(int) set_field_init (FORM *,Form_Hook);
extern FORM_EXPORT(int) set_field_term (FORM *,Form_Hook);
extern FORM_EXPORT(int) post_form (FORM *);
extern FORM_EXPORT(int) unpost_form (FORM *);
extern FORM_EXPORT(int) pos_form_cursor (FORM *);
extern FORM_EXPORT(int) form_driver (FORM *,int);
# if NCURSES_WIDECHAR
extern FORM_EXPORT(int) form_driver_w (FORM *,int,wchar_t);
# endif
extern FORM_EXPORT(int) set_form_userptr (FORM *,void *);
extern FORM_EXPORT(int) set_form_opts (FORM *,Form_Options);
extern FORM_EXPORT(int) form_opts_on (FORM *,Form_Options);
extern FORM_EXPORT(int) form_opts_off (FORM *,Form_Options);
extern FORM_EXPORT(int) form_request_by_name (const char *);
extern FORM_EXPORT(const char *) form_request_name (int);
extern FORM_EXPORT(void *) form_userptr (const FORM *);
extern FORM_EXPORT(Form_Options) form_opts (const FORM *);
extern FORM_EXPORT(bool) data_ahead (const FORM *);
extern FORM_EXPORT(bool) data_behind (const FORM *);
#if NCURSES_SP_FUNCS
extern FORM_EXPORT(FORM *) NCURSES_SP_NAME(new_form) (SCREEN*, FIELD **);
#endif
#ifdef __cplusplus
}
#endif
/* *INDENT-ON*/
#endif /* FORM_H */

108
third_party/ncurses/free_ttype.c vendored Normal file
View file

@ -0,0 +1,108 @@
/****************************************************************************
* Copyright 2020,2022 Thomas E. Dickey *
* Copyright 1999-2011,2017 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 1999-on *
****************************************************************************/
/*
* free_ttype.c -- allocation functions for TERMTYPE
*
* _nc_free_termtype()
* use_extended_names()
*
*/
#include "curses.priv.h"
#include "tic.h"
MODULE_ID("$Id: free_ttype.c,v 1.21 2022/05/28 18:02:33 tom Exp $")
static void
really_free_termtype(TERMTYPE2 *ptr, bool freeStrings)
{
T(("really_free_termtype(%s) %d", ptr->term_names, freeStrings));
if (freeStrings) {
FreeIfNeeded(ptr->str_table);
}
FreeIfNeeded(ptr->Booleans);
FreeIfNeeded(ptr->Numbers);
FreeIfNeeded(ptr->Strings);
#if NCURSES_XNAMES
if (freeStrings) {
FreeIfNeeded(ptr->ext_str_table);
}
FreeIfNeeded(ptr->ext_Names);
#endif
memset(ptr, 0, sizeof(TERMTYPE));
_nc_free_entry(_nc_head, ptr);
}
/*
* This entrypoint was used by tack 1.07; deprecated with ncurses 6.2
*/
NCURSES_EXPORT(void)
_nc_free_termtype(TERMTYPE *ptr)
{
really_free_termtype((TERMTYPE2 *) ptr, !NCURSES_EXT_NUMBERS);
}
/*
* These similar entrypoints are not used outside of ncurses.
*/
NCURSES_EXPORT(void)
_nc_free_termtype1(TERMTYPE *ptr)
{
really_free_termtype((TERMTYPE2 *) ptr, TRUE);
}
#if NCURSES_EXT_NUMBERS
NCURSES_EXPORT(void)
_nc_free_termtype2(TERMTYPE2 *ptr)
{
really_free_termtype(ptr, TRUE);
}
#endif
#if NCURSES_XNAMES
NCURSES_EXPORT_VAR(bool) _nc_user_definable = TRUE;
NCURSES_EXPORT(int)
use_extended_names(bool flag)
{
int oldflag = _nc_user_definable;
START_TRACE();
T((T_CALLED("use_extended_names(%d)"), flag));
_nc_user_definable = flag;
returnBool(oldflag);
}
#endif

76
third_party/ncurses/getenv_num.c vendored Normal file
View file

@ -0,0 +1,76 @@
/****************************************************************************
* Copyright 2018,2020 Thomas E. Dickey *
* Copyright 1998-2012,2013 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 <dickey@clark.net> 1998 *
****************************************************************************/
/*
* getenv_num.c -- obtain a number from the environment
*/
#include "curses.priv.h"
MODULE_ID("$Id: getenv_num.c,v 1.8 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
_nc_getenv_num(const char *name)
{
char *dst = 0;
char *src = getenv(name);
long value;
if ((src == 0)
|| (value = strtol(src, &dst, 0)) < 0
|| (dst == src)
|| (*dst != '\0')
|| (int) value < value)
value = -1;
return (int) value;
}
NCURSES_EXPORT(void)
_nc_setenv_num(const char *name, int value)
{
if (name != 0 && value >= 0) {
char buffer[128];
#if HAVE_SETENV
_nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "%d", value);
setenv(name, buffer, 1);
#elif HAVE_PUTENV
char *s;
_nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer)) "%s=%d", name, value);
if ((s = strdup(buffer)) != 0)
putenv(s);
#else
#error expected setenv/putenv functions
#endif
}
}

373
third_party/ncurses/hardscroll.c vendored Normal file
View file

@ -0,0 +1,373 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2015,2016 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-on *
* and: Alexander V Lukyanov 1997-1998 *
****************************************************************************/
/******************************************************************************
NAME
hardscroll.c -- hardware-scrolling optimization for ncurses
SYNOPSIS
void _nc_scroll_optimize(void)
DESCRIPTION
OVERVIEW
This algorithm for computes optimum hardware scrolling to transform an
old screen (curscr) into a new screen (newscr) via vertical line moves.
Because the screen has a `grain' (there are insert/delete/scroll line
operations but no insert/delete/scroll column operations), it is efficient
break the update algorithm into two pieces: a first stage that does only line
moves, optimizing the end product of user-invoked insertions, deletions, and
scrolls; and a second phase (corresponding to the present doupdate code in
ncurses) that does only line transformations.
The common case we want hardware scrolling for is to handle line insertions
and deletions in screen-oriented text-editors. This two-stage approach will
accomplish that at a low computation and code-size cost.
LINE-MOVE COMPUTATION
Now, to a discussion of the line-move computation.
For expository purposes, consider the screen lines to be represented by
integers 0..23 (with the understanding that the value of 23 may vary).
Let a new line introduced by insertion, scrolling, or at the bottom of
the screen following a line delete be given the index -1.
Assume that the real screen starts with lines 0..23. Now, we have
the following possible line-oriented operations on the screen:
Insertion: inserts a line at a given screen row, forcing all lines below
to scroll forward. The last screen line is lost. For example, an insertion
at line 5 would produce: 0..4 -1 5..23.
Deletion: deletes a line at a given screen row, forcing all lines below
to scroll forward. The last screen line is made new. For example, a deletion
at line 7 would produce: 0..6 8..23 -1.
Scroll up: move a range of lines up 1. The bottom line of the range
becomes new. For example, scrolling up the region from 9 to 14 will
produce 0..8 10..14 -1 15..23.
Scroll down: move a range of lines down 1. The top line of the range
becomes new. For example, scrolling down the region from 12 to 16 will produce
0..11 -1 12..15 17..23.
Now, an obvious property of all these operations is that they preserve the
order of old lines, though not their position in the sequence.
The key trick of this algorithm is that the original line indices described
above are actually maintained as _line[].oldindex fields in the window
structure, and stick to each line through scroll and insert/delete operations.
Thus, it is possible at update time to look at the oldnum fields and compute
an optimal set of il/dl/scroll operations that will take the real screen
lines to the virtual screen lines. Once these vertical moves have been done,
we can hand off to the second stage of the update algorithm, which does line
transformations.
Note that the move computation does not need to have the full generality
of a diff algorithm (which it superficially resembles) because lines cannot
be moved out of order.
THE ALGORITHM
The scrolling is done in two passes. The first pass is from top to bottom
scroling hunks UP. The second one is from bottom to top scrolling hunks DOWN.
Obviously enough, no lines to be scrolled will be destroyed. (lav)
HOW TO TEST THIS:
Use the following production:
hardscroll: hardscroll.c
$(CC) -g -DSCROLLDEBUG hardscroll.c -o hardscroll
Then just type scramble vectors and watch. The following test loads are
a representative sample of cases:
----------------------------- CUT HERE ------------------------------------
# No lines moved
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#
# A scroll up
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 -1
#
# A scroll down
-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#
# An insertion (after line 12)
0 1 2 3 4 5 6 7 8 9 10 11 12 -1 13 14 15 16 17 18 19 20 21 22
#
# A simple deletion (line 10)
0 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 20 21 22 23 -1
#
# A more complex case
-1 -1 -1 -1 -1 3 4 5 6 7 -1 -1 8 9 10 11 12 13 14 15 16 17 -1 -1
----------------------------- CUT HERE ------------------------------------
AUTHOR
Eric S. Raymond <esr@snark.thyrsus.com>, November 1994
New algorithm by Alexander V. Lukyanov <lav@yars.free.net>, Aug 1997
*****************************************************************************/
#include "curses.priv.h"
MODULE_ID("$Id: hardscroll.c,v 1.54 2020/02/02 23:34:34 tom Exp $")
#if defined(SCROLLDEBUG) || defined(HASHDEBUG)
# undef screen_lines
# define screen_lines(sp) MAXLINES
NCURSES_EXPORT_VAR (int)
oldnums[MAXLINES];
# define OLDNUM(sp,n) oldnums[n]
# define _tracef printf
# undef TR
# define TR(n, a) if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); }
extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
#else /* no debug */
/* OLDNUM(n) indicates which line will be shifted to the position n.
if OLDNUM(n) == _NEWINDEX, then the line n in new, not shifted from
somewhere. */
NCURSES_EXPORT_VAR (int *)
_nc_oldnums = 0; /* obsolete: keep for ABI compat */
# if USE_HASHMAP
# define oldnums(sp) (sp)->_oldnum_list
# define OLDNUM(sp,n) oldnums(sp)[n]
# else /* !USE_HASHMAP */
# define OLDNUM(sp,n) NewScreen(sp)->_line[n].oldindex
# endif /* !USE_HASHMAP */
#define OLDNUM_SIZE(sp) (sp)->_oldnum_size
#endif /* defined(SCROLLDEBUG) || defined(HASHDEBUG) */
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_scroll_optimize) (NCURSES_SP_DCL0)
/* scroll optimization to transform curscr to newscr */
{
int i;
int start, end, shift;
TR(TRACE_ICALLS, (T_CALLED("_nc_scroll_optimize(%p)"), (void *) SP_PARM));
#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG)
#if USE_HASHMAP
/* get enough storage */
assert(OLDNUM_SIZE(SP_PARM) >= 0);
assert(screen_lines(SP_PARM) > 0);
if ((oldnums(SP_PARM) == 0)
|| (OLDNUM_SIZE(SP_PARM) < screen_lines(SP_PARM))) {
int need_lines = ((OLDNUM_SIZE(SP_PARM) < screen_lines(SP_PARM))
? screen_lines(SP_PARM)
: OLDNUM_SIZE(SP_PARM));
int *new_oldnums = typeRealloc(int,
(size_t) need_lines,
oldnums(SP_PARM));
if (!new_oldnums)
return;
oldnums(SP_PARM) = new_oldnums;
OLDNUM_SIZE(SP_PARM) = need_lines;
}
/* calculate the indices */
NCURSES_SP_NAME(_nc_hash_map) (NCURSES_SP_ARG);
#endif
#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */
#ifdef TRACE
if (USE_TRACEF(TRACE_UPDATE | TRACE_MOVE)) {
NCURSES_SP_NAME(_nc_linedump) (NCURSES_SP_ARG);
_nc_unlock_global(tracef);
}
#endif /* TRACE */
/* pass 1 - from top to bottom scrolling up */
for (i = 0; i < screen_lines(SP_PARM);) {
while (i < screen_lines(SP_PARM)
&& (OLDNUM(SP_PARM, i) == _NEWINDEX || OLDNUM(SP_PARM, i) <= i))
i++;
if (i >= screen_lines(SP_PARM))
break;
shift = OLDNUM(SP_PARM, i) - i; /* shift > 0 */
start = i;
i++;
while (i < screen_lines(SP_PARM)
&& OLDNUM(SP_PARM, i) != _NEWINDEX
&& OLDNUM(SP_PARM, i) - i == shift)
i++;
end = i - 1 + shift;
TR(TRACE_UPDATE | TRACE_MOVE, ("scroll [%d, %d] by %d", start, end, shift));
#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG)
if (NCURSES_SP_NAME(_nc_scrolln) (NCURSES_SP_ARGx
shift,
start,
end,
screen_lines(SP_PARM) - 1) == ERR) {
TR(TRACE_UPDATE | TRACE_MOVE, ("unable to scroll"));
continue;
}
#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */
}
/* pass 2 - from bottom to top scrolling down */
for (i = screen_lines(SP_PARM) - 1; i >= 0;) {
while (i >= 0
&& (OLDNUM(SP_PARM, i) == _NEWINDEX
|| OLDNUM(SP_PARM, i) >= i)) {
i--;
}
if (i < 0)
break;
shift = OLDNUM(SP_PARM, i) - i; /* shift < 0 */
end = i;
i--;
while (i >= 0
&& OLDNUM(SP_PARM, i) != _NEWINDEX
&& OLDNUM(SP_PARM, i) - i == shift) {
i--;
}
start = i + 1 - (-shift);
TR(TRACE_UPDATE | TRACE_MOVE, ("scroll [%d, %d] by %d", start, end, shift));
#if !defined(SCROLLDEBUG) && !defined(HASHDEBUG)
if (NCURSES_SP_NAME(_nc_scrolln) (NCURSES_SP_ARGx
shift,
start,
end,
screen_lines(SP_PARM) - 1) == ERR) {
TR(TRACE_UPDATE | TRACE_MOVE, ("unable to scroll"));
continue;
}
#endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */
}
TR(TRACE_ICALLS, (T_RETURN("")));
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_scroll_optimize(void)
{
NCURSES_SP_NAME(_nc_scroll_optimize) (CURRENT_SCREEN);
}
#endif
#if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_linedump) (NCURSES_SP_DCL0)
/* dump the state of the real and virtual oldnum fields */
{
char *buf = 0;
size_t want = ((size_t) screen_lines(SP_PARM) + 1) * 4;
(void) SP_PARM;
if ((buf = typeMalloc(char, want)) != 0) {
int n;
*buf = '\0';
for (n = 0; n < screen_lines(SP_PARM); n++)
_nc_SPRINTF(buf + strlen(buf),
_nc_SLIMIT(want - strlen(buf))
" %02d", OLDNUM(SP_PARM, n));
TR(TRACE_UPDATE | TRACE_MOVE, ("virt %s", buf));
free(buf);
}
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_linedump(void)
{
NCURSES_SP_NAME(_nc_linedump) (CURRENT_SCREEN);
}
#endif
#endif /* defined(TRACE) || defined(SCROLLDEBUG) */
#ifdef SCROLLDEBUG
int
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
{
char line[BUFSIZ], *st;
#ifdef TRACE
_nc_tracing = TRACE_MOVE;
#endif
for (;;) {
int n;
for (n = 0; n < screen_lines(sp); n++)
oldnums[n] = _NEWINDEX;
/* grab the test vector */
if (fgets(line, sizeof(line), stdin) == (char *) NULL)
exit(EXIT_SUCCESS);
/* parse it */
n = 0;
if (line[0] == '#') {
(void) fputs(line, stderr);
continue;
}
st = strtok(line, " ");
do {
oldnums[n++] = atoi(st);
} while
((st = strtok((char *) NULL, " ")) != 0);
/* display it */
(void) fputs("Initial input:\n", stderr);
_nc_linedump();
_nc_scroll_optimize();
}
}
#endif /* SCROLLDEBUG */
/* hardscroll.c ends here */

342
third_party/ncurses/hashed_db.c vendored Normal file
View file

@ -0,0 +1,342 @@
/****************************************************************************
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 2006-2011,2013 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 2006-on *
****************************************************************************/
#include "curses.priv.h"
#include "tic.h"
#include "hashed_db.h"
#if USE_HASHED_DB
MODULE_ID("$Id: hashed_db.c,v 1.19 2020/02/02 23:34:34 tom Exp $")
#if HASHED_DB_API >= 2
static DBC *cursor;
#endif
typedef struct _myconn {
struct _myconn *next;
DB *db;
char *path;
bool modify;
} MYCONN;
static MYCONN *connections;
static void
cleanup(void)
{
while (connections != 0) {
_nc_db_close(connections->db);
}
}
static DB *
find_connection(const char *path, bool modify)
{
DB *result = 0;
MYCONN *p;
for (p = connections; p != 0; p = p->next) {
if (!strcmp(p->path, path) && p->modify == modify) {
result = p->db;
break;
}
}
return result;
}
static void
drop_connection(DB * db)
{
MYCONN *p, *q;
for (p = connections, q = 0; p != 0; q = p, p = p->next) {
if (p->db == db) {
if (q != 0)
q->next = p->next;
else
connections = p->next;
free(p->path);
free(p);
break;
}
}
}
static void
make_connection(DB * db, const char *path, bool modify)
{
MYCONN *p = typeCalloc(MYCONN, 1);
if (p != 0) {
p->db = db;
p->path = strdup(path);
p->modify = modify;
if (p->path != 0) {
p->next = connections;
connections = p;
} else {
free(p);
}
}
}
/*
* Open the database.
*/
NCURSES_EXPORT(DB *)
_nc_db_open(const char *path, bool modify)
{
DB *result = 0;
int code;
if (connections == 0)
atexit(cleanup);
if ((result = find_connection(path, modify)) == 0) {
#if HASHED_DB_API >= 4
db_create(&result, NULL, 0);
if ((code = result->open(result,
NULL,
path,
NULL,
DB_HASH,
modify ? DB_CREATE : DB_RDONLY,
0644)) != 0) {
result = 0;
}
#elif HASHED_DB_API >= 3
db_create(&result, NULL, 0);
if ((code = result->open(result,
path,
NULL,
DB_HASH,
modify ? DB_CREATE : DB_RDONLY,
0644)) != 0) {
result = 0;
}
#elif HASHED_DB_API >= 2
if ((code = db_open(path,
DB_HASH,
modify ? DB_CREATE : DB_RDONLY,
0644,
(DB_ENV *) 0,
(DB_INFO *) 0,
&result)) != 0) {
result = 0;
}
#else
if ((result = dbopen(path,
modify ? (O_CREAT | O_RDWR) : O_RDONLY,
0644,
DB_HASH,
NULL)) == 0) {
code = errno;
}
#endif
if (result != 0) {
make_connection(result, path, modify);
T(("opened %s", path));
} else {
T(("cannot open %s: %s", path, strerror(code)));
}
}
return result;
}
/*
* Close the database. Do not attempt to use the 'db' handle after this call.
*/
NCURSES_EXPORT(int)
_nc_db_close(DB * db)
{
int result;
drop_connection(db);
#if HASHED_DB_API >= 2
result = db->close(db, 0);
#else
result = db->close(db);
#endif
return result;
}
/*
* Write a record to the database.
*
* Returns 0 on success.
*
* FIXME: the FreeBSD cap_mkdb program assumes the database could have
* duplicates. There appears to be no good reason for that (review/fix).
*/
NCURSES_EXPORT(int)
_nc_db_put(DB * db, DBT * key, DBT * data)
{
int result;
#if HASHED_DB_API >= 2
/* remove any pre-existing value, since we do not want duplicates */
(void) db->del(db, NULL, key, 0);
result = db->put(db, NULL, key, data, DB_NOOVERWRITE);
#else
result = db->put(db, key, data, R_NOOVERWRITE);
#endif
return result;
}
/*
* Read a record from the database.
*
* Returns 0 on success.
*/
NCURSES_EXPORT(int)
_nc_db_get(DB * db, DBT * key, DBT * data)
{
int result;
memset(data, 0, sizeof(*data));
#if HASHED_DB_API >= 2
result = db->get(db, NULL, key, data, 0);
#else
result = db->get(db, key, data, 0);
#endif
return result;
}
/*
* Read the first record from the database, ignoring order.
*
* Returns 0 on success.
*/
NCURSES_EXPORT(int)
_nc_db_first(DB * db, DBT * key, DBT * data)
{
int result;
memset(key, 0, sizeof(*key));
memset(data, 0, sizeof(*data));
#if HASHED_DB_API >= 2
if ((result = db->cursor(db, NULL, &cursor, 0)) == 0) {
result = cursor->c_get(cursor, key, data, DB_FIRST);
}
#else
result = db->seq(db, key, data, 0);
#endif
return result;
}
/*
* Read the next record from the database, ignoring order.
*
* Returns 0 on success.
*/
NCURSES_EXPORT(int)
_nc_db_next(DB * db, DBT * key, DBT * data)
{
int result;
#if HASHED_DB_API >= 2
(void) db;
if (cursor != 0) {
result = cursor->c_get(cursor, key, data, DB_NEXT);
} else {
result = -1;
}
#else
result = db->seq(db, key, data, R_NEXT);
#endif
return result;
}
/*
* Check if a record is a terminfo index record. Index records are those that
* contain only an alias pointing to a list of aliases.
*/
NCURSES_EXPORT(bool)
_nc_db_have_index(DBT * key, DBT * data, char **buffer, int *size)
{
bool result = FALSE;
int used = (int) data->size - 1;
char *have = (char *) data->data;
(void) key;
if (*have++ == 2) {
result = TRUE;
}
/*
* Update params in any case for consistency with _nc_db_have_data().
*/
*buffer = have;
*size = used;
return result;
}
/*
* Check if a record is the terminfo data record. Ignore index records, e.g.,
* those that contain only an alias pointing to a list of aliases.
*/
NCURSES_EXPORT(bool)
_nc_db_have_data(DBT * key, DBT * data, char **buffer, int *size)
{
bool result = FALSE;
int used = (int) data->size - 1;
char *have = (char *) data->data;
if (*have++ == 0) {
if (data->size > key->size
&& IS_TIC_MAGIC(have)) {
result = TRUE;
}
}
/*
* Update params in any case to make it simple to follow a index record
* to the data record.
*/
*buffer = have;
*size = used;
return result;
}
#else
extern
NCURSES_EXPORT(void)
_nc_hashed_db(void);
NCURSES_EXPORT(void)
_nc_hashed_db(void)
{
}
#endif /* USE_HASHED_DB */

72
third_party/ncurses/hashed_db.h vendored Normal file
View file

@ -0,0 +1,72 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 2006-2014,2017 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 2006 *
****************************************************************************/
/*
* $Id: hashed_db.h,v 1.9 2020/02/02 23:34:34 tom Exp $
*/
#ifndef HASHED_DB_H
#define HASHED_DB_H 1
#include "ncurses_cfg.h"
#include "curses.h"
#if USE_HASHED_DB
#define DB_DBM_HSEARCH 0 /* quiet gcc -Wundef with db6 */
#include <db.h>
#ifndef DBM_SUFFIX
#define DBM_SUFFIX ".db"
#endif
#ifdef DB_VERSION_MAJOR
#define HASHED_DB_API DB_VERSION_MAJOR
#else
#define HASHED_DB_API 1 /* e.g., db 1.8.5 */
#endif
extern NCURSES_EXPORT(DB *) _nc_db_open(const char * /* path */, bool /* modify */);
extern NCURSES_EXPORT(bool) _nc_db_have_data(DBT * /* key */, DBT * /* data */, char ** /* buffer */, int * /* size */);
extern NCURSES_EXPORT(bool) _nc_db_have_index(DBT * /* key */, DBT * /* data */, char ** /* buffer */, int * /* size */);
extern NCURSES_EXPORT(int) _nc_db_close(DB * /* db */);
extern NCURSES_EXPORT(int) _nc_db_first(DB * /* db */, DBT * /* key */, DBT * /* data */);
extern NCURSES_EXPORT(int) _nc_db_next(DB * /* db */, DBT * /* key */, DBT * /* data */);
extern NCURSES_EXPORT(int) _nc_db_get(DB * /* db */, DBT * /* key */, DBT * /* data */);
extern NCURSES_EXPORT(int) _nc_db_put(DB * /* db */, DBT * /* key */, DBT * /* data */);
#endif
#endif /* HASHED_DB_H */

592
third_party/ncurses/hashmap.c vendored Normal file
View file

@ -0,0 +1,592 @@
/****************************************************************************
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 1998-2015,2016 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> *
****************************************************************************/
/******************************************************************************
NAME
hashmap.c -- fill in scramble vector based on text hashes
SYNOPSIS
void _nc_hash_map(void)
DESCRIPTION:
This code attempts to recognize pairs of old and new lines in the physical
and virtual screens. When a line pair is recognized, the old line index is
placed in the oldindex member of the virtual screen line, to be used by the
vertical-motion optimizer portion of the update logic (see hardscroll.c).
Line pairs are recognized by applying a modified Heckel's algorithm,
sped up by hashing. If a line hash is unique in both screens, those
lines must be a pair. Then if the lines just before or after the pair
are the same or similar, they are a pair too.
We don't worry about false pairs produced by hash collisions, on the
assumption that such cases are rare and will only make the latter stages
of update less efficient, not introduce errors.
HOW TO TEST THIS:
Use the following production:
hashmap: hashmap.c
$(CC) -g -DHASHDEBUG hashmap.c hardscroll.c ../objects/lib_trace.o -o hashmap
AUTHOR
Eric S. Raymond <esr@snark.thyrsus.com>, May 1996
Bug fixes and improvements by Alexander V. Lukyanov <lav@yars.free.net>, 1997
*****************************************************************************/
#include "curses.priv.h"
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
MODULE_ID("$Id: hashmap.c,v 1.69 2020/05/31 17:50:48 tom Exp $")
#ifdef HASHDEBUG
# define _tracef printf
# undef TR
# ifdef TRACE
# define TR(n, a) if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); }
# else
# define TR(n, a) { _tracef a ; putchar('\n'); }
# endif
# undef screen_lines
# define screen_lines(sp) MAXLINES
# define TEXTWIDTH(sp) 1
static int oldnums[MAXLINES], reallines[MAXLINES];
static NCURSES_CH_T oldtext[MAXLINES][TEXTWIDTH(sp)];
static NCURSES_CH_T newtext[MAXLINES][TEXTWIDTH(sp)];
# define OLDNUM(sp,n) oldnums[n]
# define OLDTEXT(sp,n) oldtext[n]
# define NEWTEXT(sp,m) newtext[m]
# define PENDING(sp,n) 1
#else /* !HASHDEBUG */
# define OLDNUM(sp,n) (sp)->_oldnum_list[n]
# define OLDTEXT(sp,n) CurScreen(sp)->_line[n].text
# define NEWTEXT(sp,m) NewScreen(sp)->_line[m].text
# define TEXTWIDTH(sp) (CurScreen(sp)->_maxx + 1)
# define PENDING(sp,n) (NewScreen(sp)->_line[n].firstchar != _NOCHANGE)
#endif /* !HASHDEBUG */
#define oldhash(sp) ((sp)->oldhash)
#define newhash(sp) ((sp)->newhash)
#define hashtab(sp) ((sp)->hashtab)
#define lines_alloc(sp) ((sp)->hashtab_len)
#if USE_WIDEC_SUPPORT
#define HASH_VAL(ch) (ch.chars[0])
#else
#define HASH_VAL(ch) (ch)
#endif
static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
static NCURSES_INLINE unsigned long
hash(SCREEN *sp, NCURSES_CH_T *text)
{
int i;
NCURSES_CH_T ch;
unsigned long result = 0;
(void) sp;
for (i = TEXTWIDTH(sp); i > 0; i--) {
ch = *text++;
result += (result << 5) + (unsigned long) HASH_VAL(ch);
}
return result;
}
/* approximate update cost */
static int
update_cost(SCREEN *sp, NCURSES_CH_T *from, NCURSES_CH_T *to)
{
int cost = 0;
int i;
(void) sp;
for (i = TEXTWIDTH(sp); i > 0; i--, from++, to++)
if (!(CharEq(*from, *to)))
cost++;
return cost;
}
static int
update_cost_from_blank(SCREEN *sp, NCURSES_CH_T *to)
{
int cost = 0;
int i;
NCURSES_CH_T blank = blankchar;
(void) sp;
if (back_color_erase)
SetPair(blank, GetPair(stdscr->_nc_bkgd));
for (i = TEXTWIDTH(sp); i > 0; i--, to++)
if (!(CharEq(blank, *to)))
cost++;
return cost;
}
/*
* Returns true when moving line 'from' to line 'to' seems to be cost
* effective. 'blank' indicates whether the line 'to' would become blank.
*/
static NCURSES_INLINE bool
cost_effective(SCREEN *sp, const int from, const int to, const int blank)
{
int new_from;
if (from == to)
return FALSE;
new_from = OLDNUM(sp, from);
if (new_from == _NEWINDEX)
new_from = from;
/*
* On the left side of >= is the cost before moving;
* on the right side -- cost after moving.
*/
return (((blank ? update_cost_from_blank(sp, NEWTEXT(sp, to))
: update_cost(sp, OLDTEXT(sp, to), NEWTEXT(sp, to)))
+ update_cost(sp, OLDTEXT(sp, new_from), NEWTEXT(sp, from)))
>= ((new_from == from ? update_cost_from_blank(sp, NEWTEXT(sp, from))
: update_cost(sp, OLDTEXT(sp, new_from), NEWTEXT(sp, from)))
+ update_cost(sp, OLDTEXT(sp, from), NEWTEXT(sp, to))))
? TRUE : FALSE;
}
static void
grow_hunks(SCREEN *sp)
{
int back_limit; /* limits for cells to fill */
int back_ref_limit; /* limit for references */
int i;
int next_hunk;
/*
* This is tricky part. We have unique pairs to use as anchors.
* Use these to deduce the presence of spans of identical lines.
*/
back_limit = 0;
back_ref_limit = 0;
i = 0;
while (i < screen_lines(sp) && OLDNUM(sp, i) == _NEWINDEX)
i++;
for (; i < screen_lines(sp); i = next_hunk) {
int forward_limit;
int forward_ref_limit;
int end;
int start = i;
int shift = OLDNUM(sp, i) - i;
/* get forward limit */
i = start + 1;
while (i < screen_lines(sp)
&& OLDNUM(sp, i) != _NEWINDEX
&& OLDNUM(sp, i) - i == shift)
i++;
end = i;
while (i < screen_lines(sp) && OLDNUM(sp, i) == _NEWINDEX)
i++;
next_hunk = i;
forward_limit = i;
if (i >= screen_lines(sp) || OLDNUM(sp, i) >= i)
forward_ref_limit = i;
else
forward_ref_limit = OLDNUM(sp, i);
i = start - 1;
/* grow back */
if (shift < 0)
back_limit = back_ref_limit + (-shift);
while (i >= back_limit) {
if (newhash(sp)[i] == oldhash(sp)[i + shift]
|| cost_effective(sp, i + shift, i, shift < 0)) {
OLDNUM(sp, i) = i + shift;
TR(TRACE_UPDATE | TRACE_MOVE,
("connected new line %d to old line %d (backward continuation)",
i, i + shift));
} else {
TR(TRACE_UPDATE | TRACE_MOVE,
("not connecting new line %d to old line %d (backward continuation)",
i, i + shift));
break;
}
i--;
}
i = end;
/* grow forward */
if (shift > 0)
forward_limit = forward_ref_limit - shift;
while (i < forward_limit) {
if (newhash(sp)[i] == oldhash(sp)[i + shift]
|| cost_effective(sp, i + shift, i, shift > 0)) {
OLDNUM(sp, i) = i + shift;
TR(TRACE_UPDATE | TRACE_MOVE,
("connected new line %d to old line %d (forward continuation)",
i, i + shift));
} else {
TR(TRACE_UPDATE | TRACE_MOVE,
("not connecting new line %d to old line %d (forward continuation)",
i, i + shift));
break;
}
i++;
}
back_ref_limit = back_limit = i;
if (shift > 0)
back_ref_limit += shift;
}
}
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_hash_map) (NCURSES_SP_DCL0)
{
HASHMAP *hsp;
register int i;
if (screen_lines(SP_PARM) > lines_alloc(SP_PARM)) {
if (hashtab(SP_PARM))
free(hashtab(SP_PARM));
hashtab(SP_PARM) = typeMalloc(HASHMAP,
((size_t) screen_lines(SP_PARM) + 1) * 2);
if (!hashtab(SP_PARM)) {
if (oldhash(SP_PARM)) {
FreeAndNull(oldhash(SP_PARM));
}
lines_alloc(SP_PARM) = 0;
return;
}
lines_alloc(SP_PARM) = screen_lines(SP_PARM);
}
if (oldhash(SP_PARM) && newhash(SP_PARM)) {
/* re-hash only changed lines */
for (i = 0; i < screen_lines(SP_PARM); i++) {
if (PENDING(SP_PARM, i))
newhash(SP_PARM)[i] = hash(SP_PARM, NEWTEXT(SP_PARM, i));
}
} else {
/* re-hash all */
if (oldhash(SP_PARM) == 0)
oldhash(SP_PARM) = typeCalloc(unsigned long,
(size_t) screen_lines(SP_PARM));
if (newhash(SP_PARM) == 0)
newhash(SP_PARM) = typeCalloc(unsigned long,
(size_t) screen_lines(SP_PARM));
if (!oldhash(SP_PARM) || !newhash(SP_PARM))
return; /* malloc failure */
for (i = 0; i < screen_lines(SP_PARM); i++) {
newhash(SP_PARM)[i] = hash(SP_PARM, NEWTEXT(SP_PARM, i));
oldhash(SP_PARM)[i] = hash(SP_PARM, OLDTEXT(SP_PARM, i));
}
}
#ifdef HASH_VERIFY
for (i = 0; i < screen_lines(SP_PARM); i++) {
if (newhash(SP_PARM)[i] != hash(SP_PARM, NEWTEXT(SP_PARM, i)))
fprintf(stderr, "error in newhash[%d]\n", i);
if (oldhash(SP_PARM)[i] != hash(SP_PARM, OLDTEXT(SP_PARM, i)))
fprintf(stderr, "error in oldhash[%d]\n", i);
}
#endif
/*
* Set up and count line-hash values.
*/
memset(hashtab(SP_PARM), '\0',
sizeof(*(hashtab(SP_PARM)))
* ((size_t) screen_lines(SP_PARM) + 1) * 2);
for (i = 0; i < screen_lines(SP_PARM); i++) {
unsigned long hashval = oldhash(SP_PARM)[i];
for (hsp = hashtab(SP_PARM); hsp->hashval; hsp++)
if (hsp->hashval == hashval)
break;
hsp->hashval = hashval; /* in case this is a new entry */
hsp->oldcount++;
hsp->oldindex = i;
}
for (i = 0; i < screen_lines(SP_PARM); i++) {
unsigned long hashval = newhash(SP_PARM)[i];
for (hsp = hashtab(SP_PARM); hsp->hashval; hsp++)
if (hsp->hashval == hashval)
break;
hsp->hashval = hashval; /* in case this is a new entry */
hsp->newcount++;
hsp->newindex = i;
OLDNUM(SP_PARM, i) = _NEWINDEX; /* initialize old indices array */
}
/*
* Mark line pairs corresponding to unique hash pairs.
*
* We don't mark lines with offset 0, because it can make fail
* extending hunks by cost_effective. Otherwise, it does not
* have any side effects.
*/
for (hsp = hashtab(SP_PARM); hsp->hashval; hsp++)
if (hsp->oldcount == 1 && hsp->newcount == 1
&& hsp->oldindex != hsp->newindex) {
TR(TRACE_UPDATE | TRACE_MOVE,
("new line %d is hash-identical to old line %d (unique)",
hsp->newindex, hsp->oldindex));
OLDNUM(SP_PARM, hsp->newindex) = hsp->oldindex;
}
grow_hunks(SP_PARM);
/*
* Eliminate bad or impossible shifts -- this includes removing
* those hunks which could not grow because of conflicts, as well
* those which are to be moved too far, they are likely to destroy
* more than carry.
*/
for (i = 0; i < screen_lines(SP_PARM);) {
int start, shift, size;
while (i < screen_lines(SP_PARM) && OLDNUM(SP_PARM, i) == _NEWINDEX)
i++;
if (i >= screen_lines(SP_PARM))
break;
start = i;
shift = OLDNUM(SP_PARM, i) - i;
i++;
while (i < screen_lines(SP_PARM)
&& OLDNUM(SP_PARM, i) != _NEWINDEX
&& OLDNUM(SP_PARM, i) - i == shift)
i++;
size = i - start;
if (size < 3 || size + min(size / 8, 2) < abs(shift)) {
while (start < i) {
OLDNUM(SP_PARM, start) = _NEWINDEX;
start++;
}
}
}
/* After clearing invalid hunks, try grow the rest. */
grow_hunks(SP_PARM);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_hash_map(void)
{
NCURSES_SP_NAME(_nc_hash_map) (CURRENT_SCREEN);
}
#endif
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_make_oldhash) (NCURSES_SP_DCLx int i)
{
if (oldhash(SP_PARM))
oldhash(SP_PARM)[i] = hash(SP_PARM, OLDTEXT(SP_PARM, i));
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_make_oldhash(int i)
{
NCURSES_SP_NAME(_nc_make_oldhash) (CURRENT_SCREEN, i);
}
#endif
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_scroll_oldhash) (NCURSES_SP_DCLx int n, int top, int bot)
{
size_t size;
int i;
if (!oldhash(SP_PARM))
return;
size = sizeof(*(oldhash(SP_PARM))) * (size_t) (bot - top + 1 - abs(n));
if (n > 0) {
memmove(oldhash(SP_PARM) + top, oldhash(SP_PARM) + top + n, size);
for (i = bot; i > bot - n; i--)
oldhash(SP_PARM)[i] = hash(SP_PARM, OLDTEXT(SP_PARM, i));
} else {
memmove(oldhash(SP_PARM) + top - n, oldhash(SP_PARM) + top, size);
for (i = top; i < top - n; i++)
oldhash(SP_PARM)[i] = hash(SP_PARM, OLDTEXT(SP_PARM, i));
}
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_scroll_oldhash(int n, int top, int bot)
{
NCURSES_SP_NAME(_nc_scroll_oldhash) (CURRENT_SCREEN, n, top, bot);
}
#endif
#ifdef HASHDEBUG
static void
usage(void)
{
static const char *table[] =
{
"hashmap test-driver",
"",
"# comment",
"l get initial line number vector",
"n use following letters as text of new lines",
"o use following letters as text of old lines",
"d dump state of test arrays",
"h apply hash mapper and see scroll optimization",
"? this message"
};
size_t n;
for (n = 0; n < sizeof(table) / sizeof(table[0]); n++)
fprintf(stderr, "%s\n", table[n]);
}
int
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
{
char line[BUFSIZ], *st;
int n;
if (setupterm(NULL, fileno(stdout), (int *) 0) == ERR)
return EXIT_FAILURE;
(void) _nc_alloc_screen();
for (n = 0; n < screen_lines(sp); n++) {
reallines[n] = n;
oldnums[n] = _NEWINDEX;
CharOf(oldtext[n][0]) = CharOf(newtext[n][0]) = '.';
}
if (NC_ISATTY(fileno(stdin)))
usage();
#ifdef TRACE
_nc_tracing = TRACE_MOVE;
#endif
for (;;) {
/* grab a test command */
if (fgets(line, sizeof(line), stdin) == (char *) NULL)
break;
switch (line[0]) {
case '#': /* comment */
(void) fputs(line, stderr);
break;
case 'l': /* get initial line number vector */
for (n = 0; n < screen_lines(sp); n++) {
reallines[n] = n;
oldnums[n] = _NEWINDEX;
}
n = 0;
st = strtok(line, " ");
do {
oldnums[n++] = atoi(st);
} while
((st = strtok((char *) NULL, " ")) != 0);
break;
case 'n': /* use following letters as text of new lines */
for (n = 0; n < screen_lines(sp); n++)
CharOf(newtext[n][0]) = '.';
for (n = 0; n < screen_lines(sp); n++)
if (line[n + 1] == '\n')
break;
else
CharOf(newtext[n][0]) = line[n + 1];
break;
case 'o': /* use following letters as text of old lines */
for (n = 0; n < screen_lines(sp); n++)
CharOf(oldtext[n][0]) = '.';
for (n = 0; n < screen_lines(sp); n++)
if (line[n + 1] == '\n')
break;
else
CharOf(oldtext[n][0]) = line[n + 1];
break;
case 'd': /* dump state of test arrays */
#ifdef TRACE
_nc_linedump();
#endif
(void) fputs("Old lines: [", stdout);
for (n = 0; n < screen_lines(sp); n++)
putchar(CharOf(oldtext[n][0]));
putchar(']');
putchar('\n');
(void) fputs("New lines: [", stdout);
for (n = 0; n < screen_lines(sp); n++)
putchar(CharOf(newtext[n][0]));
putchar(']');
putchar('\n');
break;
case 'h': /* apply hash mapper and see scroll optimization */
_nc_hash_map();
(void) fputs("Result:\n", stderr);
#ifdef TRACE
_nc_linedump();
#endif
_nc_scroll_optimize();
(void) fputs("Done.\n", stderr);
break;
default:
case '?':
usage();
break;
}
}
exit_curses(EXIT_SUCCESS);
}
#endif /* HASHDEBUG */
/* hashmap.c ends here */

6
third_party/ncurses/hashsize.h vendored Normal file
View file

@ -0,0 +1,6 @@
/*
* hashsize.h -- hash and token table constants
*/
#define CAPTABSIZE 497
#define HASHTABSIZE (497 * 2)

67
third_party/ncurses/home_terminfo.c vendored Normal file
View file

@ -0,0 +1,67 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2012,2016 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 *
****************************************************************************/
/*
* home_terminfo.c -- return the $HOME/.terminfo string, expanded
*/
#include "curses.priv.h"
#include "tic.h"
MODULE_ID("$Id: home_terminfo.c,v 1.17 2020/02/02 23:34:34 tom Exp $")
/* ncurses extension...fall back on user's private directory */
#define MyBuffer _nc_globals.home_terminfo
NCURSES_EXPORT(char *)
_nc_home_terminfo(void)
{
char *result = 0;
#if USE_HOME_TERMINFO
if (use_terminfo_vars()) {
if (MyBuffer == 0) {
char *home;
if ((home = getenv("HOME")) != 0) {
size_t want = (strlen(home) + sizeof(PRIVATE_INFO));
TYPE_MALLOC(char, want, MyBuffer);
_nc_SPRINTF(MyBuffer, _nc_SLIMIT(want) PRIVATE_INFO, home);
}
}
result = MyBuffer;
}
#endif
return result;
}

112
third_party/ncurses/init_keytry.c vendored Normal file
View file

@ -0,0 +1,112 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1999-2010,2016 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. *
****************************************************************************/
#include "curses.priv.h"
#include "tic.h" /* struct tinfo_fkeys */
MODULE_ID("$Id: init_keytry.c,v 1.19 2020/02/02 23:34:34 tom Exp $")
/*
** _nc_init_keytry()
**
** Construct the try for the current terminal's keypad keys.
**
*/
/*
* Internal entrypoints use SCREEN* parameter to obtain capabilities rather
* than cur_term.
*/
#undef CUR
#define CUR SP_TERMTYPE
#if BROKEN_LINKER
#undef _nc_tinfo_fkeys
#endif
/* LINT_PREPRO
#if 0*/
#include "init_keytry.h"
/* LINT_PREPRO
#endif*/
#if BROKEN_LINKER
const struct tinfo_fkeys *
_nc_tinfo_fkeysf(void)
{
return _nc_tinfo_fkeys;
}
#endif
NCURSES_EXPORT(void)
_nc_init_keytry(SCREEN *sp)
{
/* The sp->_keytry value is initialized in newterm(), where the sp
* structure is created, because we can not tell where keypad() or
* mouse_activate() (which will call keyok()) are first called.
*/
if (sp != 0) {
unsigned n;
for (n = 0; _nc_tinfo_fkeys[n].code; n++) {
if (_nc_tinfo_fkeys[n].offset < STRCOUNT) {
(void) _nc_add_to_try(&(sp->_keytry),
CUR Strings[_nc_tinfo_fkeys[n].offset],
_nc_tinfo_fkeys[n].code);
}
}
#if NCURSES_XNAMES
/*
* Add any of the extended strings to the tries if their name begins
* with 'k', i.e., they follow the convention of other terminfo key
* names.
*/
{
TERMTYPE *tp = &(sp->_term->type);
for (n = STRCOUNT; n < NUM_STRINGS(tp); ++n) {
const char *name = ExtStrname(tp, (int) n, strnames);
char *value = tp->Strings[n];
if (name != 0
&& *name == 'k'
&& value != 0
&& NCURSES_SP_NAME(key_defined) (NCURSES_SP_ARGx
value) == 0) {
(void) _nc_add_to_try(&(sp->_keytry),
value,
n - STRCOUNT + KEY_MAX);
}
}
}
#endif
#ifdef TRACE
_nc_trace_tries(sp->_keytry);
#endif
}
}

164
third_party/ncurses/init_keytry.h vendored Normal file
View file

@ -0,0 +1,164 @@
#ifndef _INIT_KEYTRY_H
#define _INIT_KEYTRY_H 1
/* This file was generated by MAKE_KEYS */
#include "tic.h"
#if BROKEN_LINKER
static
#endif
const struct tinfo_fkeys _nc_tinfo_fkeys[] = {
{ 139, KEY_A1 }, /* key_a1 */
{ 140, KEY_A3 }, /* key_a3 */
{ 141, KEY_B2 }, /* key_b2 */
{ 55, KEY_BACKSPACE }, /* key_backspace */
{ 158, KEY_BEG }, /* key_beg */
{ 148, KEY_BTAB }, /* key_btab */
{ 142, KEY_C1 }, /* key_c1 */
{ 143, KEY_C3 }, /* key_c3 */
{ 159, KEY_CANCEL }, /* key_cancel */
{ 56, KEY_CATAB }, /* key_catab */
{ 57, KEY_CLEAR }, /* key_clear */
{ 160, KEY_CLOSE }, /* key_close */
{ 161, KEY_COMMAND }, /* key_command */
{ 162, KEY_COPY }, /* key_copy */
{ 163, KEY_CREATE }, /* key_create */
{ 58, KEY_CTAB }, /* key_ctab */
{ 59, KEY_DC }, /* key_dc */
{ 60, KEY_DL }, /* key_dl */
{ 61, KEY_DOWN }, /* key_down */
{ 62, KEY_EIC }, /* key_eic */
{ 164, KEY_END }, /* key_end */
{ 165, KEY_ENTER }, /* key_enter */
{ 63, KEY_EOL }, /* key_eol */
{ 64, KEY_EOS }, /* key_eos */
{ 166, KEY_EXIT }, /* key_exit */
{ 65, KEY_F(0) }, /* key_f0 */
{ 66, KEY_F(1) }, /* key_f1 */
{ 67, KEY_F(10) }, /* key_f10 */
{ 216, KEY_F(11) }, /* key_f11 */
{ 217, KEY_F(12) }, /* key_f12 */
{ 218, KEY_F(13) }, /* key_f13 */
{ 219, KEY_F(14) }, /* key_f14 */
{ 220, KEY_F(15) }, /* key_f15 */
{ 221, KEY_F(16) }, /* key_f16 */
{ 222, KEY_F(17) }, /* key_f17 */
{ 223, KEY_F(18) }, /* key_f18 */
{ 224, KEY_F(19) }, /* key_f19 */
{ 68, KEY_F(2) }, /* key_f2 */
{ 225, KEY_F(20) }, /* key_f20 */
{ 226, KEY_F(21) }, /* key_f21 */
{ 227, KEY_F(22) }, /* key_f22 */
{ 228, KEY_F(23) }, /* key_f23 */
{ 229, KEY_F(24) }, /* key_f24 */
{ 230, KEY_F(25) }, /* key_f25 */
{ 231, KEY_F(26) }, /* key_f26 */
{ 232, KEY_F(27) }, /* key_f27 */
{ 233, KEY_F(28) }, /* key_f28 */
{ 234, KEY_F(29) }, /* key_f29 */
{ 69, KEY_F(3) }, /* key_f3 */
{ 235, KEY_F(30) }, /* key_f30 */
{ 236, KEY_F(31) }, /* key_f31 */
{ 237, KEY_F(32) }, /* key_f32 */
{ 238, KEY_F(33) }, /* key_f33 */
{ 239, KEY_F(34) }, /* key_f34 */
{ 240, KEY_F(35) }, /* key_f35 */
{ 241, KEY_F(36) }, /* key_f36 */
{ 242, KEY_F(37) }, /* key_f37 */
{ 243, KEY_F(38) }, /* key_f38 */
{ 244, KEY_F(39) }, /* key_f39 */
{ 70, KEY_F(4) }, /* key_f4 */
{ 245, KEY_F(40) }, /* key_f40 */
{ 246, KEY_F(41) }, /* key_f41 */
{ 247, KEY_F(42) }, /* key_f42 */
{ 248, KEY_F(43) }, /* key_f43 */
{ 249, KEY_F(44) }, /* key_f44 */
{ 250, KEY_F(45) }, /* key_f45 */
{ 251, KEY_F(46) }, /* key_f46 */
{ 252, KEY_F(47) }, /* key_f47 */
{ 253, KEY_F(48) }, /* key_f48 */
{ 254, KEY_F(49) }, /* key_f49 */
{ 71, KEY_F(5) }, /* key_f5 */
{ 255, KEY_F(50) }, /* key_f50 */
{ 256, KEY_F(51) }, /* key_f51 */
{ 257, KEY_F(52) }, /* key_f52 */
{ 258, KEY_F(53) }, /* key_f53 */
{ 259, KEY_F(54) }, /* key_f54 */
{ 260, KEY_F(55) }, /* key_f55 */
{ 261, KEY_F(56) }, /* key_f56 */
{ 262, KEY_F(57) }, /* key_f57 */
{ 263, KEY_F(58) }, /* key_f58 */
{ 264, KEY_F(59) }, /* key_f59 */
{ 72, KEY_F(6) }, /* key_f6 */
{ 265, KEY_F(60) }, /* key_f60 */
{ 266, KEY_F(61) }, /* key_f61 */
{ 267, KEY_F(62) }, /* key_f62 */
{ 268, KEY_F(63) }, /* key_f63 */
{ 73, KEY_F(7) }, /* key_f7 */
{ 74, KEY_F(8) }, /* key_f8 */
{ 75, KEY_F(9) }, /* key_f9 */
{ 167, KEY_FIND }, /* key_find */
{ 168, KEY_HELP }, /* key_help */
{ 76, KEY_HOME }, /* key_home */
{ 77, KEY_IC }, /* key_ic */
{ 78, KEY_IL }, /* key_il */
{ 79, KEY_LEFT }, /* key_left */
{ 80, KEY_LL }, /* key_ll */
{ 169, KEY_MARK }, /* key_mark */
{ 170, KEY_MESSAGE }, /* key_message */
{ 355, KEY_MOUSE }, /* key_mouse */
{ 171, KEY_MOVE }, /* key_move */
{ 172, KEY_NEXT }, /* key_next */
{ 81, KEY_NPAGE }, /* key_npage */
{ 173, KEY_OPEN }, /* key_open */
{ 174, KEY_OPTIONS }, /* key_options */
{ 82, KEY_PPAGE }, /* key_ppage */
{ 175, KEY_PREVIOUS }, /* key_previous */
{ 176, KEY_PRINT }, /* key_print */
{ 177, KEY_REDO }, /* key_redo */
{ 178, KEY_REFERENCE }, /* key_reference */
{ 179, KEY_REFRESH }, /* key_refresh */
{ 180, KEY_REPLACE }, /* key_replace */
{ 181, KEY_RESTART }, /* key_restart */
{ 182, KEY_RESUME }, /* key_resume */
{ 83, KEY_RIGHT }, /* key_right */
{ 183, KEY_SAVE }, /* key_save */
{ 186, KEY_SBEG }, /* key_sbeg */
{ 187, KEY_SCANCEL }, /* key_scancel */
{ 188, KEY_SCOMMAND }, /* key_scommand */
{ 189, KEY_SCOPY }, /* key_scopy */
{ 190, KEY_SCREATE }, /* key_screate */
{ 191, KEY_SDC }, /* key_sdc */
{ 192, KEY_SDL }, /* key_sdl */
{ 193, KEY_SELECT }, /* key_select */
{ 194, KEY_SEND }, /* key_send */
{ 195, KEY_SEOL }, /* key_seol */
{ 196, KEY_SEXIT }, /* key_sexit */
{ 84, KEY_SF }, /* key_sf */
{ 197, KEY_SFIND }, /* key_sfind */
{ 198, KEY_SHELP }, /* key_shelp */
{ 199, KEY_SHOME }, /* key_shome */
{ 200, KEY_SIC }, /* key_sic */
{ 201, KEY_SLEFT }, /* key_sleft */
{ 202, KEY_SMESSAGE }, /* key_smessage */
{ 203, KEY_SMOVE }, /* key_smove */
{ 204, KEY_SNEXT }, /* key_snext */
{ 205, KEY_SOPTIONS }, /* key_soptions */
{ 206, KEY_SPREVIOUS }, /* key_sprevious */
{ 207, KEY_SPRINT }, /* key_sprint */
{ 85, KEY_SR }, /* key_sr */
{ 208, KEY_SREDO }, /* key_sredo */
{ 209, KEY_SREPLACE }, /* key_sreplace */
{ 210, KEY_SRIGHT }, /* key_sright */
{ 211, KEY_SRSUME }, /* key_srsume */
{ 212, KEY_SSAVE }, /* key_ssave */
{ 213, KEY_SSUSPEND }, /* key_ssuspend */
{ 86, KEY_STAB }, /* key_stab */
{ 214, KEY_SUNDO }, /* key_sundo */
{ 184, KEY_SUSPEND }, /* key_suspend */
{ 185, KEY_UNDO }, /* key_undo */
{ 87, KEY_UP }, /* key_up */
{ 0, 0} };
#endif /* _INIT_KEYTRY_H */

87
third_party/ncurses/key_defined.c vendored Normal file
View file

@ -0,0 +1,87 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 2003-2006,2009 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, 2003 *
****************************************************************************/
#include "curses.priv.h"
MODULE_ID("$Id: key_defined.c,v 1.10 2020/02/02 23:34:34 tom Exp $")
static int
find_definition(TRIES * tree, const char *str)
{
TRIES *ptr;
int result = OK;
if (str != 0 && *str != '\0') {
for (ptr = tree; ptr != 0; ptr = ptr->sibling) {
if (UChar(*str) == UChar(ptr->ch)) {
if (str[1] == '\0' && ptr->child != 0) {
result = ERR;
} else if ((result = find_definition(ptr->child, str + 1))
== OK) {
result = ptr->value;
} else if (str[1] == '\0') {
result = ERR;
}
}
if (result != OK)
break;
}
}
return (result);
}
/*
* Returns the keycode associated with the given string. If none is found,
* return OK. If the string is only a prefix to other strings, return ERR.
* Otherwise, return the keycode's value (neither OK/ERR).
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(key_defined) (NCURSES_SP_DCLx const char *str)
{
int code = ERR;
T((T_CALLED("key_defined(%p, %s)"), (void *) SP_PARM, _nc_visbuf(str)));
if (SP_PARM != 0 && str != 0) {
code = find_definition(SP_PARM->_keytry, str);
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
key_defined(const char *str)
{
return NCURSES_SP_NAME(key_defined) (CURRENT_SCREEN, str);
}
#endif

64
third_party/ncurses/keybound.c vendored Normal file
View file

@ -0,0 +1,64 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1999-2009,2011 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 1999-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
#include "curses.priv.h"
MODULE_ID("$Id: keybound.c,v 1.12 2020/02/02 23:34:34 tom Exp $")
/*
* Returns the count'th string definition which is associated with the
* given keycode. The result is malloc'd, must be freed by the caller.
*/
NCURSES_EXPORT(char *)
NCURSES_SP_NAME(keybound) (NCURSES_SP_DCLx int code, int count)
{
char *result = 0;
T((T_CALLED("keybound(%p, %d,%d)"), (void *) SP_PARM, code, count));
if (SP_PARM != 0 && code >= 0) {
result = _nc_expand_try(SP_PARM->_keytry,
(unsigned) code,
&count,
(size_t) 0);
}
returnPtr(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(char *)
keybound(int code, int count)
{
return NCURSES_SP_NAME(keybound) (CURRENT_SCREEN, code, count);
}
#endif

103
third_party/ncurses/keyok.c vendored Normal file
View file

@ -0,0 +1,103 @@
/****************************************************************************
* Copyright 2019-2020,2021 Thomas E. Dickey *
* Copyright 1998-2012,2014 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 1997-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
#include "curses.priv.h"
MODULE_ID("$Id: keyok.c,v 1.17 2021/06/17 21:26:02 tom Exp $")
/*
* Enable (or disable) ncurses' interpretation of a keycode by adding (or
* removing) the corresponding 'tries' entry.
*
* Do this by storing a second tree of tries, which records the disabled keys.
* The simplest way to copy is to make a function that returns the string (with
* nulls set to 0200), then use that to reinsert the string into the
* corresponding tree.
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(keyok) (NCURSES_SP_DCLx int c, bool flag)
{
int code = ERR;
if (HasTerminal(SP_PARM)) {
T((T_CALLED("keyok(%p, %d,%d)"), (void *) SP_PARM, c, flag));
#ifdef USE_TERM_DRIVER
code = CallDriver_2(sp, td_kyOk, c, flag);
#else
if (c >= 0) {
int count = 0;
char *s;
unsigned ch = (unsigned) c;
if (flag) {
while ((s = _nc_expand_try(SP_PARM->_key_ok,
ch, &count, (size_t) 0)) != 0) {
if (_nc_remove_key(&(SP_PARM->_key_ok), ch)) {
code = _nc_add_to_try(&(SP_PARM->_keytry), s, ch);
free(s);
count = 0;
if (code != OK)
break;
} else {
free(s);
}
}
} else {
while ((s = _nc_expand_try(SP_PARM->_keytry,
ch, &count, (size_t) 0)) != 0) {
if (_nc_remove_key(&(SP_PARM->_keytry), ch)) {
code = _nc_add_to_try(&(SP_PARM->_key_ok), s, ch);
free(s);
count = 0;
if (code != OK)
break;
} else {
free(s);
}
}
}
}
#endif
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
keyok(int c, bool flag)
{
return NCURSES_SP_NAME(keyok) (CURRENT_SCREEN, c, flag);
}
#endif

58
third_party/ncurses/legacy_coding.c vendored Normal file
View file

@ -0,0 +1,58 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 2005,2009 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 2005 *
* Juergen Pfeifer 2009 *
****************************************************************************/
#include "curses.priv.h"
MODULE_ID("$Id: legacy_coding.c,v 1.6 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
NCURSES_SP_NAME(use_legacy_coding) (NCURSES_SP_DCLx int level)
{
int result = ERR;
T((T_CALLED("use_legacy_coding(%p,%d)"), (void *) SP_PARM, level));
if (level >= 0 && level <= 2 && SP_PARM != 0) {
result = SP_PARM->_legacy_coding;
SP_PARM->_legacy_coding = level;
}
returnCode(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
use_legacy_coding(int level)
{
return NCURSES_SP_NAME(use_legacy_coding) (CURRENT_SCREEN, level);
}
#endif

326
third_party/ncurses/lib_acs.c vendored Normal file
View file

@ -0,0 +1,326 @@
/****************************************************************************
* Copyright 2018-2019,2020 Thomas E. Dickey *
* Copyright 1998-2014,2017 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-on *
* and: Juergen Pfeifer 2008 *
****************************************************************************/
#include "curses.priv.h"
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
MODULE_ID("$Id: lib_acs.c,v 1.50 2020/02/02 23:34:34 tom Exp $")
#if BROKEN_LINKER || USE_REENTRANT
#define MyBuffer _nc_prescreen.real_acs_map
NCURSES_EXPORT(chtype *)
NCURSES_PUBLIC_VAR(acs_map) (void)
{
if (MyBuffer == 0)
MyBuffer = typeCalloc(chtype, ACS_LEN);
return MyBuffer;
}
#undef MyBuffer
#else
NCURSES_EXPORT_VAR (chtype) acs_map[ACS_LEN] =
{
0
};
#endif
#ifdef USE_TERM_DRIVER
NCURSES_EXPORT(chtype)
NCURSES_SP_NAME(_nc_acs_char) (NCURSES_SP_DCLx int c)
{
chtype *map;
if (c < 0 || c >= ACS_LEN)
return (chtype) 0;
map = (SP_PARM != 0) ? SP_PARM->_acs_map :
#if BROKEN_LINKER || USE_REENTRANT
_nc_prescreen.real_acs_map
#else
acs_map
#endif
;
return map[c];
}
#endif /* USE_TERM_DRIVER */
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_init_acs) (NCURSES_SP_DCL0)
{
chtype *fake_map = acs_map;
chtype *real_map = SP_PARM != 0 ? SP_PARM->_acs_map : fake_map;
int j;
T(("initializing ACS map"));
/*
* If we're using this from curses (rather than terminfo), we are storing
* the mapping information in the SCREEN struct so we can decide how to
* render it.
*/
if (real_map != fake_map) {
for (j = 1; j < ACS_LEN; ++j) {
real_map[j] = 0;
fake_map[j] = A_ALTCHARSET | (chtype) j;
if (SP_PARM)
SP_PARM->_screen_acs_map[j] = FALSE;
}
} else {
for (j = 1; j < ACS_LEN; ++j) {
real_map[j] = 0;
}
}
/*
* Initializations for a UNIX-like multi-terminal environment. Use
* ASCII chars and count on the terminfo description to do better.
*/
real_map['l'] = '+'; /* should be upper left corner */
real_map['m'] = '+'; /* should be lower left corner */
real_map['k'] = '+'; /* should be upper right corner */
real_map['j'] = '+'; /* should be lower right corner */
real_map['u'] = '+'; /* should be tee pointing left */
real_map['t'] = '+'; /* should be tee pointing right */
real_map['v'] = '+'; /* should be tee pointing up */
real_map['w'] = '+'; /* should be tee pointing down */
real_map['q'] = '-'; /* should be horizontal line */
real_map['x'] = '|'; /* should be vertical line */
real_map['n'] = '+'; /* should be large plus or crossover */
real_map['o'] = '~'; /* should be scan line 1 */
real_map['s'] = '_'; /* should be scan line 9 */
real_map['`'] = '+'; /* should be diamond */
real_map['a'] = ':'; /* should be checker board (stipple) */
real_map['f'] = '\''; /* should be degree symbol */
real_map['g'] = '#'; /* should be plus/minus */
real_map['~'] = 'o'; /* should be bullet */
real_map[','] = '<'; /* should be arrow pointing left */
real_map['+'] = '>'; /* should be arrow pointing right */
real_map['.'] = 'v'; /* should be arrow pointing down */
real_map['-'] = '^'; /* should be arrow pointing up */
real_map['h'] = '#'; /* should be board of squares */
real_map['i'] = '#'; /* should be lantern symbol */
real_map['0'] = '#'; /* should be solid square block */
/* these defaults were invented for ncurses */
real_map['p'] = '-'; /* should be scan line 3 */
real_map['r'] = '-'; /* should be scan line 7 */
real_map['y'] = '<'; /* should be less-than-or-equal-to */
real_map['z'] = '>'; /* should be greater-than-or-equal-to */
real_map['{'] = '*'; /* should be greek pi */
real_map['|'] = '!'; /* should be not-equal */
real_map['}'] = 'f'; /* should be pound-sterling symbol */
/* thick-line-drawing */
real_map['L'] = '+'; /* upper left corner */
real_map['M'] = '+'; /* lower left corner */
real_map['K'] = '+'; /* upper right corner */
real_map['J'] = '+'; /* lower right corner */
real_map['T'] = '+'; /* tee pointing left */
real_map['U'] = '+'; /* tee pointing right */
real_map['V'] = '+'; /* tee pointing up */
real_map['W'] = '+'; /* tee pointing down */
real_map['Q'] = '-'; /* horizontal line */
real_map['X'] = '|'; /* vertical line */
real_map['N'] = '+'; /* large plus or crossover */
/* double-line-drawing */
real_map['C'] = '+'; /* upper left corner */
real_map['D'] = '+'; /* lower left corner */
real_map['B'] = '+'; /* upper right corner */
real_map['A'] = '+'; /* lower right corner */
real_map['G'] = '+'; /* tee pointing left */
real_map['F'] = '+'; /* tee pointing right */
real_map['H'] = '+'; /* tee pointing up */
real_map['I'] = '+'; /* tee pointing down */
real_map['R'] = '-'; /* horizontal line */
real_map['Y'] = '|'; /* vertical line */
real_map['E'] = '+'; /* large plus or crossover */
#ifdef USE_TERM_DRIVER
CallDriver_2(SP_PARM, td_initacs, real_map, fake_map);
#else
if (ena_acs != NULL) {
NCURSES_PUTP2("ena_acs", ena_acs);
}
#if NCURSES_EXT_FUNCS && defined(enter_pc_charset_mode) && defined(exit_pc_charset_mode)
/*
* Linux console "supports" the "PC ROM" character set by the coincidence
* that smpch/rmpch and smacs/rmacs have the same values. ncurses has
* no codepage support (see SCO Merge for an example). Outside of the
* values defined in acsc, there are no definitions for the "PC ROM"
* character set (assumed by some applications to be codepage 437), but we
* allow those applications to use those codepoints.
*
* test/blue.c uses this feature.
*/
#define PCH_KLUDGE(a,b) (a != 0 && b != 0 && !strcmp(a,b))
if (PCH_KLUDGE(enter_pc_charset_mode, enter_alt_charset_mode) &&
PCH_KLUDGE(exit_pc_charset_mode, exit_alt_charset_mode)) {
size_t i;
for (i = 1; i < ACS_LEN; ++i) {
if (real_map[i] == 0) {
real_map[i] = (chtype) i;
if (real_map != fake_map) {
if (SP != 0)
SP->_screen_acs_map[i] = TRUE;
}
}
}
}
#endif
if (acs_chars != NULL) {
size_t i = 0;
size_t length = strlen(acs_chars);
while (i + 1 < length) {
if (acs_chars[i] != 0 && UChar(acs_chars[i]) < ACS_LEN) {
real_map[UChar(acs_chars[i])] = UChar(acs_chars[i + 1]) | A_ALTCHARSET;
T(("#%d real_map[%s] = %s",
(int) i,
_tracechar(UChar(acs_chars[i])),
_tracechtype(real_map[UChar(acs_chars[i])])));
if (SP != 0) {
SP->_screen_acs_map[UChar(acs_chars[i])] = TRUE;
}
}
i += 2;
}
}
#ifdef TRACE
/* Show the equivalent mapping, noting if it does not match the
* given attribute, whether by re-ordering or duplication.
*/
if (USE_TRACEF(TRACE_CALLS)) {
size_t n, m;
char show[ACS_LEN * 2 + 1];
for (n = 1, m = 0; n < ACS_LEN; n++) {
if (real_map[n] != 0) {
show[m++] = (char) n;
show[m++] = (char) ChCharOf(real_map[n]);
}
}
show[m] = 0;
if (acs_chars == NULL || strcmp(acs_chars, show))
_tracef("%s acs_chars %s",
(acs_chars == NULL) ? "NULL" : "READ",
_nc_visbuf(acs_chars));
_tracef("%s acs_chars %s",
(acs_chars == NULL)
? "NULL"
: (strcmp(acs_chars, show)
? "DIFF"
: "SAME"),
_nc_visbuf(show));
_nc_unlock_global(tracef);
}
#endif /* TRACE */
#endif
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_init_acs(void)
{
NCURSES_SP_NAME(_nc_init_acs) (CURRENT_SCREEN);
}
#endif
#if !NCURSES_WCWIDTH_GRAPHICS
NCURSES_EXPORT(int)
_nc_wacs_width(unsigned ch)
{
int result;
switch (ch) {
case 0x00a3: /* FALLTHRU - ncurses pound-sterling symbol */
case 0x00b0: /* FALLTHRU - VT100 degree symbol */
case 0x00b1: /* FALLTHRU - VT100 plus/minus */
case 0x00b7: /* FALLTHRU - VT100 bullet */
case 0x03c0: /* FALLTHRU - ncurses greek pi */
case 0x2190: /* FALLTHRU - Teletype arrow pointing left */
case 0x2191: /* FALLTHRU - Teletype arrow pointing up */
case 0x2192: /* FALLTHRU - Teletype arrow pointing right */
case 0x2193: /* FALLTHRU - Teletype arrow pointing down */
case 0x2260: /* FALLTHRU - ncurses not-equal */
case 0x2264: /* FALLTHRU - ncurses less-than-or-equal-to */
case 0x2265: /* FALLTHRU - ncurses greater-than-or-equal-to */
case 0x23ba: /* FALLTHRU - VT100 scan line 1 */
case 0x23bb: /* FALLTHRU - ncurses scan line 3 */
case 0x23bc: /* FALLTHRU - ncurses scan line 7 */
case 0x23bd: /* FALLTHRU - VT100 scan line 9 */
case 0x2500: /* FALLTHRU - VT100 horizontal line */
case 0x2501: /* FALLTHRU - thick horizontal line */
case 0x2502: /* FALLTHRU - VT100 vertical line */
case 0x2503: /* FALLTHRU - thick vertical line */
case 0x250c: /* FALLTHRU - VT100 upper left corner */
case 0x250f: /* FALLTHRU - thick upper left corner */
case 0x2510: /* FALLTHRU - VT100 upper right corner */
case 0x2513: /* FALLTHRU - thick upper right corner */
case 0x2514: /* FALLTHRU - VT100 lower left corner */
case 0x2517: /* FALLTHRU - thick lower left corner */
case 0x2518: /* FALLTHRU - VT100 lower right corner */
case 0x251b: /* FALLTHRU - thick lower right corner */
case 0x251c: /* FALLTHRU - VT100 tee pointing left */
case 0x2523: /* FALLTHRU - thick tee pointing left */
case 0x2524: /* FALLTHRU - VT100 tee pointing right */
case 0x252b: /* FALLTHRU - thick tee pointing right */
case 0x252c: /* FALLTHRU - VT100 tee pointing down */
case 0x2533: /* FALLTHRU - thick tee pointing down */
case 0x2534: /* FALLTHRU - VT100 tee pointing up */
case 0x253b: /* FALLTHRU - thick tee pointing up */
case 0x253c: /* FALLTHRU - VT100 large plus or crossover */
case 0x254b: /* FALLTHRU - thick large plus or crossover */
case 0x2550: /* FALLTHRU - double horizontal line */
case 0x2551: /* FALLTHRU - double vertical line */
case 0x2554: /* FALLTHRU - double upper left corner */
case 0x2557: /* FALLTHRU - double upper right corner */
case 0x255a: /* FALLTHRU - double lower left corner */
case 0x255d: /* FALLTHRU - double lower right corner */
case 0x2560: /* FALLTHRU - double tee pointing right */
case 0x2563: /* FALLTHRU - double tee pointing left */
case 0x2566: /* FALLTHRU - double tee pointing down */
case 0x2569: /* FALLTHRU - double tee pointing up */
case 0x256c: /* FALLTHRU - double large plus or crossover */
case 0x2592: /* FALLTHRU - VT100 checker board (stipple) */
case 0x25ae: /* FALLTHRU - Teletype solid square block */
case 0x25c6: /* FALLTHRU - VT100 diamond */
case 0x2603: /* FALLTHRU - Teletype lantern symbol */
result = 1;
break;
default:
result = wcwidth(ch);
break;
}
return result;
}
#endif /* !NCURSES_WCWIDTH_GRAPHICS */

444
third_party/ncurses/lib_add_wch.c vendored Normal file
View file

@ -0,0 +1,444 @@
/****************************************************************************
* Copyright 2019-2020,2021 Thomas E. Dickey *
* Copyright 2004-2011,2016 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. *
****************************************************************************/
/*
** lib_add_wch.c
**
** The routine wadd_wch().
**
*/
#include "curses.priv.h"
#if HAVE_WCTYPE_H
#include <wctype.h>
#endif
MODULE_ID("$Id: lib_add_wch.c,v 1.17 2021/06/17 21:26:02 tom Exp $")
/* clone/adapt lib_addch.c */
static const cchar_t blankchar = NewChar(BLANK_TEXT);
/*
* Ugly microtweaking alert. Everything from here to end of module is
* likely to be speed-critical -- profiling data sure says it is!
* Most of the important screen-painting functions are shells around
* wadd_wch(). So we make every effort to reduce function-call overhead
* by inlining stuff, even at the cost of making wrapped copies for
* export. Also we supply some internal versions that don't call the
* window sync hook, for use by string-put functions.
*/
/* Return bit mask for clearing color pair number if given ch has color */
#define COLOR_MASK(ch) (~(attr_t)(((ch) & A_COLOR) ? A_COLOR : 0))
static NCURSES_INLINE cchar_t
render_char(WINDOW *win, cchar_t ch)
/* compute a rendition of the given char correct for the current context */
{
attr_t a = WINDOW_ATTRS(win);
int pair = GetPair(ch);
if (ISBLANK(ch)
&& AttrOf(ch) == A_NORMAL
&& pair == 0) {
/* color/pair in attrs has precedence over bkgrnd */
ch = win->_nc_bkgd;
SetAttr(ch, a | AttrOf(win->_nc_bkgd));
if ((pair = GET_WINDOW_PAIR(win)) == 0)
pair = GetPair(win->_nc_bkgd);
SetPair(ch, pair);
} else {
/* color in attrs has precedence over bkgrnd */
a |= AttrOf(win->_nc_bkgd) & COLOR_MASK(a);
/* color in ch has precedence */
if (pair == 0) {
if ((pair = GET_WINDOW_PAIR(win)) == 0)
pair = GetPair(win->_nc_bkgd);
}
AddAttr(ch, (a & COLOR_MASK(AttrOf(ch))));
SetPair(ch, pair);
}
TR(TRACE_VIRTPUT,
("render_char bkg %s (%d), attrs %s (%d) -> ch %s (%d)",
_tracech_t2(1, CHREF(win->_nc_bkgd)),
GetPair(win->_nc_bkgd),
_traceattr(WINDOW_ATTRS(win)),
GET_WINDOW_PAIR(win),
_tracech_t2(3, CHREF(ch)),
GetPair(ch)));
return (ch);
}
/* check if position is legal; if not, return error */
#ifndef NDEBUG /* treat this like an assertion */
#define CHECK_POSITION(win, x, y) \
if (y > win->_maxy \
|| x > win->_maxx \
|| y < 0 \
|| x < 0) { \
TR(TRACE_VIRTPUT, ("Alert! Win=%p _curx = %d, _cury = %d " \
"(_maxx = %d, _maxy = %d)", win, x, y, \
win->_maxx, win->_maxy)); \
return(ERR); \
}
#else
#define CHECK_POSITION(win, x, y) /* nothing */
#endif
static bool
newline_forces_scroll(WINDOW *win, NCURSES_SIZE_T *ypos)
{
bool result = FALSE;
if (*ypos >= win->_regtop && *ypos == win->_regbottom) {
*ypos = win->_regbottom;
result = TRUE;
} else {
*ypos = (NCURSES_SIZE_T) (*ypos + 1);
}
return result;
}
/*
* The _WRAPPED flag is useful only for telling an application that we've just
* wrapped the cursor. We don't do anything with this flag except set it when
* wrapping, and clear it whenever we move the cursor. If we try to wrap at
* the lower-right corner of a window, we cannot move the cursor (since that
* wouldn't be legal). So we return an error (which is what SVr4 does).
* Unlike SVr4, we can successfully add a character to the lower-right corner
* (Solaris 2.6 does this also, however).
*/
static int
wrap_to_next_line(WINDOW *win)
{
win->_flags |= _WRAPPED;
if (newline_forces_scroll(win, &(win->_cury))) {
win->_curx = win->_maxx;
if (!win->_scroll)
return (ERR);
scroll(win);
}
win->_curx = 0;
return (OK);
}
static int wadd_wch_literal(WINDOW *, cchar_t);
/*
* Fill the given number of cells with blanks using the current background
* rendition. This saves/restores the current x-position.
*/
static void
fill_cells(WINDOW *win, int count)
{
cchar_t blank = blankchar;
int save_x = win->_curx;
int save_y = win->_cury;
while (count-- > 0) {
if (wadd_wch_literal(win, blank) == ERR)
break;
}
win->_curx = (NCURSES_SIZE_T) save_x;
win->_cury = (NCURSES_SIZE_T) save_y;
}
static int
wadd_wch_literal(WINDOW *win, cchar_t ch)
{
int x;
int y;
struct ldat *line;
x = win->_curx;
y = win->_cury;
CHECK_POSITION(win, x, y);
ch = render_char(win, ch);
line = win->_line + y;
CHANGED_CELL(line, x);
/*
* Non-spacing characters are added to the current cell.
*
* Spacing characters that are wider than one column require some display
* adjustments.
*/
{
int len = _nc_wacs_width(CharOf(ch));
int i;
int j;
wchar_t *chars;
if (len == 0) { /* non-spacing */
if ((x > 0 && y >= 0)
|| (win->_maxx >= 0 && win->_cury >= 1)) {
if (x > 0 && y >= 0)
chars = (win->_line[y].text[x - 1].chars);
else
chars = (win->_line[y - 1].text[win->_maxx].chars);
for (i = 0; i < CCHARW_MAX; ++i) {
if (chars[i] == 0) {
TR(TRACE_VIRTPUT,
("added non-spacing %d: %x",
x, (int) CharOf(ch)));
chars[i] = CharOf(ch);
break;
}
}
}
goto testwrapping;
} else if (len > 1) { /* multi-column characters */
/*
* Check if the character will fit on the current line. If it does
* not fit, fill in the remainder of the line with blanks. and
* move to the next line.
*/
if (len > win->_maxx + 1) {
TR(TRACE_VIRTPUT, ("character will not fit"));
return ERR;
} else if (x + len > win->_maxx + 1) {
int count = win->_maxx + 1 - x;
TR(TRACE_VIRTPUT, ("fill %d remaining cells", count));
fill_cells(win, count);
if (wrap_to_next_line(win) == ERR)
return ERR;
x = win->_curx;
y = win->_cury;
line = win->_line + y;
}
/*
* Check for cells which are orphaned by adding this character, set
* those to blanks.
*
* FIXME: this actually could fill j-i cells, more complicated to
* setup though.
*/
for (i = 0; i < len; ++i) {
if (isWidecBase(win->_line[y].text[x + i])) {
break;
} else if (isWidecExt(win->_line[y].text[x + i])) {
for (j = i; x + j <= win->_maxx; ++j) {
if (!isWidecExt(win->_line[y].text[x + j])) {
TR(TRACE_VIRTPUT, ("fill %d orphan cells", j));
fill_cells(win, j);
break;
}
}
break;
}
}
/*
* Finally, add the cells for this character.
*/
for (i = 0; i < len; ++i) {
cchar_t value = ch;
SetWidecExt(value, i);
TR(TRACE_VIRTPUT, ("multicolumn %d:%d (%d,%d)",
i + 1, len,
win->_begy + y, win->_begx + x));
line->text[x] = value;
CHANGED_CELL(line, x);
++x;
}
goto testwrapping;
}
}
/*
* Single-column characters.
*/
line->text[x++] = ch;
/*
* This label is used only for wide-characters.
*/
testwrapping:
TR(TRACE_VIRTPUT, ("cell (%ld, %ld..%d) = %s",
(long) win->_cury, (long) win->_curx, x - 1,
_tracech_t(CHREF(ch))));
if (x > win->_maxx) {
return wrap_to_next_line(win);
}
win->_curx = (NCURSES_SIZE_T) x;
return OK;
}
static NCURSES_INLINE int
wadd_wch_nosync(WINDOW *win, cchar_t ch)
/* the workhorse function -- add a character to the given window */
{
NCURSES_SIZE_T x, y;
wchar_t *s;
int tabsize = 8;
#if USE_REENTRANT
SCREEN *sp = _nc_screen_of(win);
#endif
/*
* If we are using the alternate character set, forget about locale.
* Otherwise, if the locale claims the code is printable, treat it that
* way.
*/
if ((AttrOf(ch) & A_ALTCHARSET)
|| iswprint((wint_t) CharOf(ch)))
return wadd_wch_literal(win, ch);
/*
* Handle carriage control and other codes that are not printable, or are
* known to expand to more than one character according to unctrl().
*/
x = win->_curx;
y = win->_cury;
switch (CharOf(ch)) {
case '\t':
#if USE_REENTRANT
tabsize = *ptrTabsize(sp);
#else
tabsize = TABSIZE;
#endif
x = (NCURSES_SIZE_T) (x + (tabsize - (x % tabsize)));
/*
* Space-fill the tab on the bottom line so that we'll get the
* "correct" cursor position.
*/
if ((!win->_scroll && (y == win->_regbottom))
|| (x <= win->_maxx)) {
cchar_t blank = blankchar;
AddAttr(blank, AttrOf(ch));
while (win->_curx < x) {
if (wadd_wch_literal(win, blank) == ERR)
return (ERR);
}
break;
} else {
wclrtoeol(win);
win->_flags |= _WRAPPED;
if (newline_forces_scroll(win, &y)) {
x = win->_maxx;
if (win->_scroll) {
scroll(win);
x = 0;
}
} else {
x = 0;
}
}
break;
case '\n':
wclrtoeol(win);
if (newline_forces_scroll(win, &y)) {
if (win->_scroll)
scroll(win);
else
return (ERR);
}
/* FALLTHRU */
case '\r':
x = 0;
win->_flags &= ~_WRAPPED;
break;
case '\b':
if (x == 0)
return (OK);
x--;
win->_flags &= ~_WRAPPED;
break;
default:
if ((s = wunctrl(&ch)) != 0) {
while (*s) {
cchar_t sch;
SetChar(sch, *s++, AttrOf(ch));
if_EXT_COLORS(SetPair(sch, GetPair(ch)));
if (wadd_wch_literal(win, sch) == ERR)
return ERR;
}
return OK;
}
return ERR;
}
win->_curx = x;
win->_cury = y;
return OK;
}
/*
* The versions below call _nc_synchook(). We wanted to avoid this in the
* version exported for string puts; they'll call _nc_synchook once at end
* of run.
*/
/* These are actual entry points */
NCURSES_EXPORT(int)
wadd_wch(WINDOW *win, const cchar_t *wch)
{
int code = ERR;
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wadd_wch(%p, %s)"),
(void *) win,
_tracecchar_t(wch)));
if (win && (wadd_wch_nosync(win, *wch) != ERR)) {
_nc_synchook(win);
code = OK;
}
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
return (code);
}
NCURSES_EXPORT(int)
wecho_wchar(WINDOW *win, const cchar_t *wch)
{
int code = ERR;
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"),
(void *) win,
_tracecchar_t(wch)));
if (win && (wadd_wch_nosync(win, *wch) != ERR)) {
bool save_immed = win->_immed;
win->_immed = TRUE;
_nc_synchook(win);
win->_immed = save_immed;
code = OK;
}
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
return (code);
}

602
third_party/ncurses/lib_addch.c vendored Normal file
View file

@ -0,0 +1,602 @@
/****************************************************************************
* Copyright 2019-2021,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 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. *
****************************************************************************/
/*
** lib_addch.c
**
** The routine waddch().
**
*/
#include "curses.priv.h"
#include <ctype.h>
MODULE_ID("$Id: lib_addch.c,v 1.141 2022/06/12 15:16:41 tom Exp $")
static const NCURSES_CH_T blankchar = NewChar(BLANK_TEXT);
/*
* Ugly microtweaking alert. Everything from here to end of module is
* likely to be speed-critical -- profiling data sure says it is!
* Most of the important screen-painting functions are shells around
* waddch(). So we make every effort to reduce function-call overhead
* by inlining stuff, even at the cost of making wrapped copies for
* export. Also we supply some internal versions that don't call the
* window sync hook, for use by string-put functions.
*/
/* Return bit mask for clearing color pair number if given ch has color */
#define COLOR_MASK(ch) (~(attr_t)(((ch) & A_COLOR) ? A_COLOR : 0))
static NCURSES_INLINE NCURSES_CH_T
render_char(WINDOW *win, NCURSES_CH_T ch)
/* compute a rendition of the given char correct for the current context */
{
attr_t a = WINDOW_ATTRS(win);
int pair = GetPair(ch);
if (ISBLANK(ch)
&& AttrOf(ch) == A_NORMAL
&& pair == 0) {
/* color/pair in attrs has precedence over bkgrnd */
ch = win->_nc_bkgd;
SetAttr(ch, a | AttrOf(win->_nc_bkgd));
if ((pair = GET_WINDOW_PAIR(win)) == 0)
pair = GetPair(win->_nc_bkgd);
SetPair(ch, pair);
} else {
/* color in attrs has precedence over bkgrnd */
a |= AttrOf(win->_nc_bkgd) & COLOR_MASK(a);
/* color in ch has precedence */
if (pair == 0) {
if ((pair = GET_WINDOW_PAIR(win)) == 0)
pair = GetPair(win->_nc_bkgd);
}
AddAttr(ch, (a & COLOR_MASK(AttrOf(ch))));
SetPair(ch, pair);
}
TR(TRACE_VIRTPUT,
("render_char bkg %s (%d), attrs %s (%d) -> ch %s (%d)",
_tracech_t2(1, CHREF(win->_nc_bkgd)),
GetPair(win->_nc_bkgd),
_traceattr(WINDOW_ATTRS(win)),
GET_WINDOW_PAIR(win),
_tracech_t2(3, CHREF(ch)),
GetPair(ch)));
return (ch);
}
NCURSES_EXPORT(NCURSES_CH_T)
_nc_render(WINDOW *win, NCURSES_CH_T ch)
/* make render_char() visible while still allowing us to inline it below */
{
return render_char(win, ch);
}
/* check if position is legal; if not, return error */
#ifndef NDEBUG /* treat this like an assertion */
#define CHECK_POSITION(win, x, y) \
if (y > win->_maxy \
|| x > win->_maxx \
|| y < 0 \
|| x < 0) { \
TR(TRACE_VIRTPUT, ("Alert! Win=%p _curx = %d, _cury = %d " \
"(_maxx = %d, _maxy = %d)", win, x, y, \
win->_maxx, win->_maxy)); \
return(ERR); \
}
#else
#define CHECK_POSITION(win, x, y) /* nothing */
#endif
static bool
newline_forces_scroll(WINDOW *win, NCURSES_SIZE_T *ypos)
{
bool result = FALSE;
if (*ypos >= win->_regtop && *ypos <= win->_regbottom) {
if (*ypos == win->_regbottom) {
*ypos = win->_regbottom;
result = TRUE;
} else if (*ypos < win->_maxy) {
*ypos = (NCURSES_SIZE_T) (*ypos + 1);
}
} else if (*ypos < win->_maxy) {
*ypos = (NCURSES_SIZE_T) (*ypos + 1);
}
return result;
}
/*
* The _WRAPPED flag is useful only for telling an application that we've just
* wrapped the cursor. We don't do anything with this flag except set it when
* wrapping, and clear it whenever we move the cursor. If we try to wrap at
* the lower-right corner of a window, we cannot move the cursor (since that
* wouldn't be legal). So we return an error (which is what SVr4 does).
* Unlike SVr4, we can successfully add a character to the lower-right corner
* (Solaris 2.6 does this also, however).
*/
static int
wrap_to_next_line(WINDOW *win)
{
win->_flags |= _WRAPPED;
if (newline_forces_scroll(win, &(win->_cury))) {
win->_curx = win->_maxx;
if (!win->_scroll)
return (ERR);
scroll(win);
}
win->_curx = 0;
return (OK);
}
#if USE_WIDEC_SUPPORT
static int waddch_literal(WINDOW *, NCURSES_CH_T);
/*
* Fill the given number of cells with blanks using the current background
* rendition. This saves/restores the current x-position.
*/
static void
fill_cells(WINDOW *win, int count)
{
NCURSES_CH_T blank = blankchar;
int save_x = win->_curx;
int save_y = win->_cury;
while (count-- > 0) {
if (waddch_literal(win, blank) == ERR)
break;
}
win->_curx = (NCURSES_SIZE_T) save_x;
win->_cury = (NCURSES_SIZE_T) save_y;
}
#endif
/*
* Build up the bytes for a multibyte character, returning the length when
* complete (a positive number), -1 for error and -2 for incomplete.
*/
#if USE_WIDEC_SUPPORT
NCURSES_EXPORT(int)
_nc_build_wch(WINDOW *win, ARG_CH_T ch)
{
char *buffer = WINDOW_EXT(win, addch_work);
int len;
int x = win->_curx;
int y = win->_cury;
mbstate_t state;
wchar_t result;
if ((WINDOW_EXT(win, addch_used) != 0) &&
(WINDOW_EXT(win, addch_x) != x ||
WINDOW_EXT(win, addch_y) != y)) {
/* discard the incomplete multibyte character */
WINDOW_EXT(win, addch_used) = 0;
TR(TRACE_VIRTPUT,
("Alert discarded multibyte on move (%d,%d) -> (%d,%d)",
WINDOW_EXT(win, addch_y), WINDOW_EXT(win, addch_x),
y, x));
}
WINDOW_EXT(win, addch_x) = x;
WINDOW_EXT(win, addch_y) = y;
/*
* If the background character is a wide-character, that may interfere with
* processing multibyte characters in this function.
*/
if (!is8bits(CharOf(CHDEREF(ch)))) {
if (WINDOW_EXT(win, addch_used) != 0) {
/* discard the incomplete multibyte character */
WINDOW_EXT(win, addch_used) = 0;
TR(TRACE_VIRTPUT,
("Alert discarded incomplete multibyte"));
}
return 1;
}
init_mb(state);
buffer[WINDOW_EXT(win, addch_used)] = (char) CharOf(CHDEREF(ch));
WINDOW_EXT(win, addch_used) += 1;
buffer[WINDOW_EXT(win, addch_used)] = '\0';
if ((len = (int) mbrtowc(&result,
buffer,
(size_t) WINDOW_EXT(win, addch_used),
&state)) > 0) {
attr_t attrs = AttrOf(CHDEREF(ch));
if_EXT_COLORS(int pair = GetPair(CHDEREF(ch)));
SetChar(CHDEREF(ch), result, attrs);
if_EXT_COLORS(SetPair(CHDEREF(ch), pair));
WINDOW_EXT(win, addch_used) = 0;
} else if (len == -1) {
/*
* An error occurred. We could either discard everything,
* or assume that the error was in the previous input.
* Try the latter.
*/
TR(TRACE_VIRTPUT, ("Alert! mbrtowc returns error"));
/* handle this with unctrl() */
WINDOW_EXT(win, addch_used) = 0;
}
return len;
}
#endif /* USE_WIDEC_SUPPORT */
static
#if !USE_WIDEC_SUPPORT /* cannot be inline if it is recursive */
NCURSES_INLINE
#endif
int
waddch_literal(WINDOW *win, NCURSES_CH_T ch)
{
int x;
int y;
struct ldat *line;
x = win->_curx;
y = win->_cury;
CHECK_POSITION(win, x, y);
ch = render_char(win, ch);
line = win->_line + y;
CHANGED_CELL(line, x);
/*
* Build up multibyte characters until we have a wide-character.
*/
#if NCURSES_SP_FUNCS
#define DeriveSP() SCREEN *sp = _nc_screen_of(win);
#else
#define DeriveSP() /*nothing */
#endif
if_WIDEC({
DeriveSP();
if (WINDOW_EXT(win, addch_used) != 0 || !Charable(ch)) {
int len = _nc_build_wch(win, CHREF(ch));
if (len >= -1) {
attr_t attr = AttrOf(ch);
/* handle EILSEQ (i.e., when len >= -1) */
if (len == -1 && is8bits(CharOf(ch))) {
const char *s = NCURSES_SP_NAME(unctrl)
(NCURSES_SP_ARGx (chtype) CharOf(ch));
if (s[1] != '\0') {
int rc = OK;
while (*s != '\0') {
rc = waddch(win, UChar(*s) | attr);
if (rc != OK)
break;
++s;
}
return rc;
}
}
if (len == -1)
return waddch(win, ' ' | attr);
} else {
return OK;
}
}
});
/*
* Non-spacing characters are added to the current cell.
*
* Spacing characters that are wider than one column require some display
* adjustments.
*/
if_WIDEC({
int len = _nc_wacs_width(CharOf(ch));
int i;
int j;
if (len == 0) { /* non-spacing */
if ((x > 0 && y >= 0)
|| (win->_maxx >= 0 && win->_cury >= 1)) {
NCURSES_CH_T *dst;
wchar_t *chars;
if (x > 0 && y >= 0) {
for (j = x - 1; j >= 0; --j) {
if (!isWidecExt(win->_line[y].text[j])) {
win->_curx = (NCURSES_SIZE_T) j;
break;
}
}
dst = &(win->_line[y].text[j]);
} else {
dst = &(win->_line[y - 1].text[win->_maxx]);
}
chars = dst->chars;
for (i = 0; i < CCHARW_MAX; ++i) {
if (chars[i] == 0) {
TR(TRACE_VIRTPUT,
("adding non-spacing %s (level %d)",
_tracech_t(CHREF(ch)), i));
chars[i] = CharOf(ch);
break;
}
}
}
goto testwrapping;
} else if (len > 1) { /* multi-column characters */
/*
* Check if the character will fit on the current line. If it does
* not fit, fill in the remainder of the line with blanks. and
* move to the next line.
*/
if (len > win->_maxx + 1) {
TR(TRACE_VIRTPUT, ("character will not fit"));
return ERR;
} else if (x + len > win->_maxx + 1) {
int count = win->_maxx + 1 - x;
TR(TRACE_VIRTPUT, ("fill %d remaining cells", count));
fill_cells(win, count);
if (wrap_to_next_line(win) == ERR)
return ERR;
x = win->_curx;
y = win->_cury;
CHECK_POSITION(win, x, y);
line = win->_line + y;
}
/*
* Check for cells which are orphaned by adding this character, set
* those to blanks.
*
* FIXME: this actually could fill j-i cells, more complicated to
* setup though.
*/
for (i = 0; i < len; ++i) {
if (isWidecBase(win->_line[y].text[x + i])) {
break;
} else if (isWidecExt(win->_line[y].text[x + i])) {
for (j = i; x + j <= win->_maxx; ++j) {
if (!isWidecExt(win->_line[y].text[x + j])) {
TR(TRACE_VIRTPUT, ("fill %d orphan cells", j));
fill_cells(win, j);
break;
}
}
break;
}
}
/*
* Finally, add the cells for this character.
*/
for (i = 0; i < len; ++i) {
NCURSES_CH_T value = ch;
SetWidecExt(value, i);
TR(TRACE_VIRTPUT, ("multicolumn %d:%d (%d,%d)",
i + 1, len,
win->_begy + y, win->_begx + x));
line->text[x] = value;
CHANGED_CELL(line, x);
++x;
}
goto testwrapping;
}
});
/*
* Single-column characters.
*/
line->text[x++] = ch;
/*
* This label is used only for wide-characters.
*/
if_WIDEC(
testwrapping:
);
TR(TRACE_VIRTPUT, ("cell (%d, %d..%d) = %s",
win->_cury, win->_curx, x - 1,
_tracech_t(CHREF(line->text[win->_curx]))));
if (x > win->_maxx) {
return wrap_to_next_line(win);
}
win->_curx = (NCURSES_SIZE_T) x;
return OK;
}
static NCURSES_INLINE int
waddch_nosync(WINDOW *win, const NCURSES_CH_T ch)
/* the workhorse function -- add a character to the given window */
{
NCURSES_SIZE_T x, y;
chtype t = (chtype) CharOf(ch);
#if USE_WIDEC_SUPPORT || NCURSES_SP_FUNCS || USE_REENTRANT
SCREEN *sp = _nc_screen_of(win);
#endif
const char *s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx t);
int tabsize = 8;
/*
* If we are using the alternate character set, forget about locale.
* Otherwise, if unctrl() returns a single-character or the locale
* claims the code is printable (and not also a control character),
* treat it that way.
*/
if ((AttrOf(ch) & A_ALTCHARSET)
|| (
#if USE_WIDEC_SUPPORT
(sp != 0 && sp->_legacy_coding) &&
#endif
s[1] == 0
)
|| (
(isprint((int) t) && !iscntrl((int) t))
#if USE_WIDEC_SUPPORT
|| ((sp == 0 || !sp->_legacy_coding) &&
(WINDOW_EXT(win, addch_used)
|| !_nc_is_charable(CharOf(ch))))
#endif
)) {
return waddch_literal(win, ch);
}
/*
* Handle carriage control and other codes that are not printable, or are
* known to expand to more than one character according to unctrl().
*/
x = win->_curx;
y = win->_cury;
CHECK_POSITION(win, x, y);
switch (t) {
case '\t':
#if USE_REENTRANT
tabsize = *ptrTabsize(sp);
#else
tabsize = TABSIZE;
#endif
x = (NCURSES_SIZE_T) (x + (tabsize - (x % tabsize)));
/*
* Space-fill the tab on the bottom line so that we'll get the
* "correct" cursor position.
*/
if ((!win->_scroll && (y == win->_regbottom))
|| (x <= win->_maxx)) {
NCURSES_CH_T blank = blankchar;
AddAttr(blank, AttrOf(ch));
while (win->_curx < x) {
if (waddch_literal(win, blank) == ERR)
return (ERR);
}
break;
} else {
wclrtoeol(win);
win->_flags |= _WRAPPED;
if (newline_forces_scroll(win, &y)) {
x = win->_maxx;
if (win->_scroll) {
scroll(win);
x = 0;
}
} else {
x = 0;
}
}
break;
case '\n':
wclrtoeol(win);
if (newline_forces_scroll(win, &y)) {
if (win->_scroll)
scroll(win);
else
return (ERR);
}
/* FALLTHRU */
case '\r':
x = 0;
win->_flags &= ~_WRAPPED;
break;
case '\b':
if (x == 0)
return (OK);
x--;
win->_flags &= ~_WRAPPED;
break;
default:
while (*s) {
NCURSES_CH_T sch;
SetChar(sch, UChar(*s++), AttrOf(ch));
if_EXT_COLORS(SetPair(sch, GetPair(ch)));
if (waddch_literal(win, sch) == ERR)
return ERR;
}
return (OK);
}
win->_curx = x;
win->_cury = y;
return (OK);
}
NCURSES_EXPORT(int)
_nc_waddch_nosync(WINDOW *win, const NCURSES_CH_T c)
/* export copy of waddch_nosync() so the string-put functions can use it */
{
return (waddch_nosync(win, c));
}
/*
* The versions below call _nc_synchook(). We wanted to avoid this in the
* version exported for string puts; they'll call _nc_synchook once at end
* of run.
*/
/* These are actual entry points */
NCURSES_EXPORT(int)
waddch(WINDOW *win, const chtype ch)
{
int code = ERR;
NCURSES_CH_T wch;
SetChar2(wch, ch);
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("waddch(%p, %s)"), (void *) win,
_tracechtype(ch)));
if (win && (waddch_nosync(win, wch) != ERR)) {
_nc_synchook(win);
code = OK;
}
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
return (code);
}
NCURSES_EXPORT(int)
wechochar(WINDOW *win, const chtype ch)
{
int code = ERR;
NCURSES_CH_T wch;
SetChar2(wch, ch);
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wechochar(%p, %s)"),
(void *) win,
_tracechtype(ch)));
if (win && (waddch_nosync(win, wch) != ERR)) {
bool save_immed = win->_immed;
win->_immed = TRUE;
_nc_synchook(win);
win->_immed = save_immed;
code = OK;
}
TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
return (code);
}

255
third_party/ncurses/lib_addstr.c vendored Normal file
View file

@ -0,0 +1,255 @@
/****************************************************************************
* Copyright 2019-2020,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 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> *
* *
* Rewritten 2001-2004 to support wide-characters by *
* Sven Verdoolaege *
* Thomas Dickey *
****************************************************************************/
/*
** lib_addstr.c
*
** The routines waddnstr(), waddchnstr().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_addstr.c,v 1.58 2022/06/11 20:12:04 tom Exp $")
NCURSES_EXPORT(int)
waddnstr(WINDOW *win, const char *astr, int n)
{
const char *str = astr;
int code = ERR;
T((T_CALLED("waddnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(astr, n), n));
if (win && (str != 0)) {
TR(TRACE_VIRTPUT | TRACE_ATTRS,
("... current %s", _traceattr(WINDOW_ATTRS(win))));
code = OK;
TR(TRACE_VIRTPUT, ("str is not null, length = %d",
((n > 0) ? n : (int) strlen(str))));
if (n < 0)
n = INT_MAX;
while ((*str != '\0') && (n-- > 0)) {
NCURSES_CH_T ch;
TR(TRACE_VIRTPUT, ("*str = %#o", UChar(*str)));
SetChar(ch, UChar(*str++), A_NORMAL);
if (_nc_waddch_nosync(win, ch) == ERR) {
code = ERR;
break;
}
}
_nc_synchook(win);
}
TR(TRACE_VIRTPUT, ("waddnstr returns %d", code));
returnCode(code);
}
NCURSES_EXPORT(int)
waddchnstr(WINDOW *win, const chtype *astr, int n)
{
NCURSES_SIZE_T y, x;
int code = OK;
int i;
struct ldat *line;
T((T_CALLED("waddchnstr(%p,%p,%d)"), (void *) win, (const void *) astr, n));
if (!win || !astr)
returnCode(ERR);
y = win->_cury;
x = win->_curx;
if (n < 0) {
const chtype *str;
n = 0;
for (str = (const chtype *) astr; *str != 0; str++)
n++;
}
if (n > win->_maxx - x + 1)
n = win->_maxx - x + 1;
if (n == 0)
returnCode(code);
line = &(win->_line[y]);
for (i = 0; i < n && ChCharOf(astr[i]) != '\0'; ++i) {
SetChar2(line->text[i + x], astr[i]);
}
CHANGED_RANGE(line, x, (NCURSES_SIZE_T) (x + n - 1));
_nc_synchook(win);
returnCode(code);
}
#if USE_WIDEC_SUPPORT
NCURSES_EXPORT(int)
_nc_wchstrlen(const cchar_t *s)
{
int result = 0;
if (s != 0) {
while (CharOf(s[result]) != L'\0') {
result++;
}
}
return result;
}
NCURSES_EXPORT(int)
wadd_wchnstr(WINDOW *win, const cchar_t *astr, int n)
{
static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
NCURSES_SIZE_T y;
NCURSES_SIZE_T x;
int code = OK;
struct ldat *line;
int i, j, start, len, end;
T((T_CALLED("wadd_wchnstr(%p,%s,%d)"),
(void *) win,
_nc_viscbuf(astr, n),
n));
if (!win)
returnCode(ERR);
y = win->_cury;
x = win->_curx;
if (n < 0) {
n = _nc_wchstrlen(astr);
}
if (n > win->_maxx - x + 1)
n = win->_maxx - x + 1;
if (n == 0)
returnCode(code);
line = &(win->_line[y]);
start = x;
end = x + n - 1;
/*
* Reset orphaned cells of multi-column characters that extend up to the
* new string's location to blanks.
*/
if (x > 0 && isWidecExt(line->text[x])) {
for (i = 0; i <= x; ++i) {
if (!isWidecExt(line->text[x - i])) {
/* must be isWidecBase() */
start -= i;
while (i > 0) {
line->text[x - i--] = _nc_render(win, blank);
}
break;
}
}
}
/*
* Copy the new string to the window.
*/
for (i = 0; i < n && CharOf(astr[i]) != L'\0' && x <= win->_maxx; ++i) {
if (isWidecExt(astr[i]))
continue;
len = _nc_wacs_width(CharOf(astr[i]));
if (x + len - 1 <= win->_maxx) {
line->text[x] = _nc_render(win, astr[i]);
if (len > 1) {
for (j = 0; j < len; ++j) {
if (j != 0) {
line->text[x + j] = line->text[x];
}
SetWidecExt(line->text[x + j], j);
}
} else {
len = 1;
}
x = (NCURSES_SIZE_T) (x + len);
end += len - 1;
} else {
break;
}
}
/*
* Set orphaned cells of multi-column characters which lie after the new
* string to blanks.
*/
while (x <= win->_maxx && isWidecExt(line->text[x])) {
line->text[x] = _nc_render(win, blank);
++end;
++x;
}
CHANGED_RANGE(line, start, end);
_nc_synchook(win);
returnCode(code);
}
NCURSES_EXPORT(int)
waddnwstr(WINDOW *win, const wchar_t *str, int n)
{
int code = ERR;
T((T_CALLED("waddnwstr(%p,%s,%d)"), (void *) win, _nc_viswbufn(str, n), n));
if (win && (str != 0)) {
TR(TRACE_VIRTPUT | TRACE_ATTRS,
("... current %s", _traceattr(WINDOW_ATTRS(win))));
code = OK;
TR(TRACE_VIRTPUT, ("str is not null, length = %d",
((n > 0) ? n : (int) wcslen(str))));
if (n < 0)
n = INT_MAX;
while ((*str != L('\0')) && (n-- > 0)) {
NCURSES_CH_T ch;
TR(TRACE_VIRTPUT, ("*str[0] = %#lx", (unsigned long) *str));
SetChar(ch, *str++, A_NORMAL);
if (wadd_wch(win, &ch) == ERR) {
code = ERR;
break;
}
}
_nc_synchook(win);
}
TR(TRACE_VIRTPUT, ("waddnwstr returns %d", code));
returnCode(code);
}
#endif

317
third_party/ncurses/lib_baudrate.c vendored Normal file
View file

@ -0,0 +1,317 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2016,2017 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-on *
****************************************************************************/
/*
* lib_baudrate.c
*
*/
#include "curses.priv.h"
#include "termcap.h" /* ospeed */
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#include <sys/param.h>
#endif
/*
* These systems use similar header files, which define B1200 as 1200, etc.,
* but can be overridden by defining USE_OLD_TTY so B1200 is 9, which makes all
* of the indices up to B115200 fit nicely in a 'short', allowing us to retain
* ospeed's type for compatibility.
*/
#if NCURSES_OSPEED_COMPAT && \
((defined(__FreeBSD__) && (__FreeBSD_version < 700000)) || \
defined(__NetBSD__) || \
((defined(__OpenBSD__) && OpenBSD < 201510)) || \
defined(__APPLE__))
#undef B0
#undef B50
#undef B75
#undef B110
#undef B134
#undef B150
#undef B200
#undef B300
#undef B600
#undef B1200
#undef B1800
#undef B2400
#undef B4800
#undef B9600
#undef B19200
#undef EXTA
#undef B38400
#undef EXTB
#undef B57600
#undef B115200
#undef B230400
#undef B460800
#undef B921600
#define USE_OLD_TTY
#include <sys/ttydev.h>
#else
#undef USE_OLD_TTY
#endif /* USE_OLD_TTY */
MODULE_ID("$Id: lib_baudrate.c,v 1.45 2020/09/05 21:15:32 tom Exp $")
/*
* int
* baudrate()
*
* Returns the current terminal's baud rate.
*
*/
struct speed {
int given_speed; /* values for 'ospeed' */
int actual_speed; /* the actual speed */
};
#if !defined(EXP_WIN32_DRIVER)
#define DATA(number) { B##number, number }
static struct speed speeds[] =
{
DATA(0),
DATA(50),
DATA(75),
DATA(110),
DATA(134),
DATA(150),
DATA(200),
DATA(300),
DATA(600),
DATA(1200),
DATA(1800),
DATA(2400),
DATA(4800),
DATA(9600),
#ifdef B19200
DATA(19200),
#elif defined(EXTA)
{EXTA, 19200},
#endif
#ifdef B28800
DATA(28800),
#endif
#ifdef B38400
DATA(38400),
#elif defined(EXTB)
{EXTB, 38400},
#endif
#ifdef B57600
DATA(57600),
#endif
/* ifdef to prevent overflow when OLD_TTY is not available */
#if !(NCURSES_OSPEED_COMPAT && defined(__FreeBSD__) && (__FreeBSD_version > 700000))
#ifdef B76800
DATA(76800),
#endif
#ifdef B115200
DATA(115200),
#endif
#ifdef B153600
DATA(153600),
#endif
#ifdef B230400
DATA(230400),
#endif
#ifdef B307200
DATA(307200),
#endif
#ifdef B460800
DATA(460800),
#endif
#ifdef B500000
DATA(500000),
#endif
#ifdef B576000
DATA(576000),
#endif
#ifdef B921600
DATA(921600),
#endif
#ifdef B1000000
DATA(1000000),
#endif
#ifdef B1152000
DATA(1152000),
#endif
#ifdef B1500000
DATA(1500000),
#endif
#ifdef B2000000
DATA(2000000),
#endif
#ifdef B2500000
DATA(2500000),
#endif
#ifdef B3000000
DATA(3000000),
#endif
#ifdef B3500000
DATA(3500000),
#endif
#ifdef B4000000
DATA(4000000),
#endif
#endif
};
#endif /* !EXP_WIN32_DRIVER */
NCURSES_EXPORT(int)
_nc_baudrate(int OSpeed)
{
#if defined(EXP_WIN32_DRIVER)
/* On Windows this is a noop */
(void) OSpeed;
return (OK);
#else
#if !USE_REENTRANT
static int last_OSpeed;
static int last_baudrate;
#endif
int result = ERR;
if (OSpeed < 0)
OSpeed = (NCURSES_OSPEED) OSpeed;
if (OSpeed < 0)
OSpeed = (unsigned short) OSpeed;
#if !USE_REENTRANT
if (OSpeed == last_OSpeed) {
result = last_baudrate;
}
#endif
if (result == ERR) {
if (OSpeed >= 0) {
unsigned i;
for (i = 0; i < SIZEOF(speeds); i++) {
if (speeds[i].given_speed > OSpeed) {
break;
}
if (speeds[i].given_speed == OSpeed) {
result = speeds[i].actual_speed;
break;
}
}
}
#if !USE_REENTRANT
if (OSpeed != last_OSpeed) {
last_OSpeed = OSpeed;
last_baudrate = result;
}
#endif
}
return (result);
#endif /* !EXP_WIN32_DRIVER */
}
NCURSES_EXPORT(int)
_nc_ospeed(int BaudRate)
{
int result = 1;
#if defined(EXP_WIN32_DRIVER)
(void) BaudRate;
#else
if (BaudRate >= 0) {
unsigned i;
for (i = 0; i < SIZEOF(speeds); i++) {
if (speeds[i].actual_speed == BaudRate) {
result = speeds[i].given_speed;
break;
}
}
}
#endif
return (result);
}
NCURSES_EXPORT(int)
NCURSES_SP_NAME(baudrate) (NCURSES_SP_DCL0)
{
int result;
T((T_CALLED("baudrate(%p)"), (void *) SP_PARM));
#if defined(EXP_WIN32_DRIVER)
result = OK;
#else
/*
* In debugging, allow the environment symbol to override when we're
* redirecting to a file, so we can construct repeatable test-cases
* that take into account costs that depend on baudrate.
*/
#ifdef TRACE
if (IsValidTIScreen(SP_PARM)
&& !NC_ISATTY(fileno((SP_PARM && SP_PARM->_ofp) ? SP_PARM->_ofp : stdout))
&& getenv("BAUDRATE") != 0) {
int ret;
if ((ret = _nc_getenv_num("BAUDRATE")) <= 0)
ret = 9600;
ospeed = (NCURSES_OSPEED) _nc_ospeed(ret);
returnCode(ret);
}
#endif
if (IsValidTIScreen(SP_PARM)) {
#ifdef USE_OLD_TTY
result = (int) cfgetospeed(&(TerminalOf(SP_PARM)->Nttyb));
ospeed = (NCURSES_OSPEED) _nc_ospeed(result);
#else /* !USE_OLD_TTY */
#ifdef TERMIOS
ospeed = (NCURSES_OSPEED) cfgetospeed(&(TerminalOf(SP_PARM)->Nttyb));
#else
ospeed = (NCURSES_OSPEED) TerminalOf(SP_PARM)->Nttyb.sg_ospeed;
#endif
result = _nc_baudrate(ospeed);
#endif
TerminalOf(SP_PARM)->_baudrate = result;
} else {
result = ERR;
}
#endif /* !EXP_WIN32_DRIVER */
returnCode(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
baudrate(void)
{
return NCURSES_SP_NAME(baudrate) (CURRENT_SCREEN);
}
#endif

91
third_party/ncurses/lib_beep.c vendored Normal file
View file

@ -0,0 +1,91 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2013,2014 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-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
* beep.c
*
* The routine beep().
*
*/
#include "curses.priv.h"
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
MODULE_ID("$Id: lib_beep.c,v 1.18 2020/02/02 23:34:34 tom Exp $")
/*
* beep()
*
* Sound the current terminal's audible bell if it has one. If not,
* flash the screen if possible.
*
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(beep) (NCURSES_SP_DCL0)
{
int res = ERR;
T((T_CALLED("beep(%p)"), (void *) SP_PARM));
#ifdef USE_TERM_DRIVER
if (SP_PARM != 0)
res = CallDriver_1(SP_PARM, td_doBeepOrFlash, TRUE);
#else
/* FIXME: should make sure that we are not in altchar mode */
if (cur_term == 0) {
res = ERR;
} else if (bell) {
res = NCURSES_PUTP2_FLUSH("bell", bell);
} else if (flash_screen) {
res = NCURSES_PUTP2_FLUSH("flash_screen", flash_screen);
_nc_flush();
}
#endif
returnCode(res);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
beep(void)
{
return NCURSES_SP_NAME(beep) (CURRENT_SCREEN);
}
#endif

273
third_party/ncurses/lib_bkgd.c vendored Normal file
View file

@ -0,0 +1,273 @@
/****************************************************************************
* Copyright 2018-2020,2021 Thomas E. Dickey *
* Copyright 1998-2014,2016 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: Juergen Pfeifer 1997 *
* and: Sven Verdoolaege 2000 *
* and: Thomas E. Dickey 1996-on *
****************************************************************************/
#include "curses.priv.h"
MODULE_ID("$Id: lib_bkgd.c,v 1.63 2021/05/08 14:58:12 tom Exp $")
static const NCURSES_CH_T blank = NewChar(BLANK_TEXT);
/*
* Set the window's background information.
*/
#if USE_WIDEC_SUPPORT
NCURSES_EXPORT(void)
#else
static NCURSES_INLINE void
#endif
wbkgrndset(WINDOW *win, const ARG_CH_T ch)
{
T((T_CALLED("wbkgrndset(%p,%s)"), (void *) win, _tracech_t(ch)));
if (win) {
attr_t off = AttrOf(win->_nc_bkgd);
attr_t on = AttrOf(CHDEREF(ch));
toggle_attr_off(WINDOW_ATTRS(win), off);
toggle_attr_on(WINDOW_ATTRS(win), on);
#if NCURSES_EXT_COLORS
{
int pair;
if (GetPair(win->_nc_bkgd) != 0)
SET_WINDOW_PAIR(win, 0);
if ((pair = GetPair(CHDEREF(ch))) != 0)
SET_WINDOW_PAIR(win, pair);
}
#endif
if (CharOf(CHDEREF(ch)) == L('\0')) {
SetChar(win->_nc_bkgd, BLANK_TEXT, AttrOf(CHDEREF(ch)));
if_EXT_COLORS(SetPair(win->_nc_bkgd, GetPair(CHDEREF(ch))));
} else {
win->_nc_bkgd = CHDEREF(ch);
}
#if USE_WIDEC_SUPPORT
/*
* If we're compiled for wide-character support, _bkgrnd is the
* preferred location for the background information since it stores
* more than _bkgd. Update _bkgd each time we modify _bkgrnd, so the
* macro getbkgd() will work.
*/
{
cchar_t wch;
int tmp;
memset(&wch, 0, sizeof(wch));
(void) wgetbkgrnd(win, &wch);
tmp = _nc_to_char((wint_t) CharOf(wch));
win->_bkgd = (((tmp == EOF) ? ' ' : (chtype) tmp)
| (AttrOf(wch) & ALL_BUT_COLOR)
| (chtype) ColorPair(GET_WINDOW_PAIR(win)));
}
#endif
}
returnVoid;
}
NCURSES_EXPORT(void)
wbkgdset(WINDOW *win, chtype ch)
{
NCURSES_CH_T wch;
T((T_CALLED("wbkgdset(%p,%s)"), (void *) win, _tracechtype(ch)));
SetChar2(wch, ch);
wbkgrndset(win, CHREF(wch));
returnVoid;
}
/*
* Set the window's background information and apply it to each cell.
*/
static NCURSES_INLINE int
_nc_background(WINDOW *win, const ARG_CH_T ch, bool narrow)
{
#undef SP_PARM
#define SP_PARM SP /* to use Charable() */
int code = ERR;
#if USE_WIDEC_SUPPORT
T((T_CALLED("%s(%p,%s)"),
narrow ? "wbkgd" : "wbkgrnd",
(void *) win,
_tracecchar_t(ch)));
#define TraceChar(c) _tracecchar_t2(1, &(c))
#else
T((T_CALLED("%s(%p,%s)"),
"wbkgd",
(void *) win,
_tracech_t(ch)));
(void) narrow;
#define TraceChar(c) _tracechar(CharOf(c))
#endif
if (SP == 0) {
;
} else if (win) {
NCURSES_CH_T new_bkgd = CHDEREF(ch);
NCURSES_CH_T old_bkgd;
int y;
NCURSES_CH_T old_char;
attr_t old_attr;
int old_pair;
NCURSES_CH_T new_char;
attr_t new_attr;
int new_pair;
/* SVr4 trims color info if non-color terminal */
if (!SP->_pair_limit) {
RemAttr(new_bkgd, A_COLOR);
SetPair(new_bkgd, 0);
}
/* avoid setting background-character to a null */
if (CharOf(new_bkgd) == 0) {
NCURSES_CH_T tmp_bkgd = blank;
SetAttr(tmp_bkgd, AttrOf(new_bkgd));
SetPair(tmp_bkgd, GetPair(new_bkgd));
new_bkgd = tmp_bkgd;
}
memset(&old_bkgd, 0, sizeof(old_bkgd));
(void) wgetbkgrnd(win, &old_bkgd);
if (!memcmp(&old_bkgd, &new_bkgd, sizeof(new_bkgd))) {
T(("...unchanged"));
returnCode(OK);
}
old_char = old_bkgd;
RemAttr(old_char, ~A_CHARTEXT);
old_attr = AttrOf(old_bkgd);
old_pair = GetPair(old_bkgd);
if (!(old_attr & A_COLOR)) {
old_pair = 0;
}
T(("... old background char %s, attr %s, pair %d",
TraceChar(old_char), _traceattr(old_attr), old_pair));
new_char = new_bkgd;
RemAttr(new_char, ~A_CHARTEXT);
new_attr = AttrOf(new_bkgd);
new_pair = GetPair(new_bkgd);
/* SVr4 limits background character to printable 7-bits */
if (
#if USE_WIDEC_SUPPORT
narrow &&
#endif
!Charable(new_bkgd)) {
new_char = old_char;
}
if (!(new_attr & A_COLOR)) {
new_pair = 0;
}
T(("... new background char %s, attr %s, pair %d",
TraceChar(new_char), _traceattr(new_attr), new_pair));
(void) wbkgrndset(win, CHREF(new_bkgd));
/* SVr4 updates color pair if old/new match, otherwise just attrs */
if ((new_pair != 0) && (new_pair == old_pair)) {
WINDOW_ATTRS(win) = new_attr;
SET_WINDOW_PAIR(win, new_pair);
} else {
WINDOW_ATTRS(win) = new_attr;
}
for (y = 0; y <= win->_maxy; y++) {
int x;
for (x = 0; x <= win->_maxx; x++) {
NCURSES_CH_T *cp = &(win->_line[y].text[x]);
int tmp_pair = GetPair(*cp);
attr_t tmp_attr = AttrOf(*cp);
if (CharEq(*cp, old_bkgd)) {
#if USE_WIDEC_SUPPORT
if (!narrow) {
if (Charable(new_bkgd)) {
SetChar2(*cp, CharOf(new_char));
} else {
SetChar(*cp, L' ', AttrOf(new_char));
}
memcpy(cp->chars,
new_char.chars,
CCHARW_MAX * sizeof(cp->chars[0]));
} else
#endif
SetChar2(*cp, CharOf(new_char));
}
if (tmp_pair != 0) {
if (tmp_pair == old_pair) {
SetAttr(*cp, (tmp_attr & ~old_attr) | new_attr);
SetPair(*cp, new_pair);
} else {
SetAttr(*cp,
(tmp_attr & (~old_attr | A_COLOR))
| (new_attr & ALL_BUT_COLOR));
}
} else {
SetAttr(*cp, (tmp_attr & ~old_attr) | new_attr);
SetPair(*cp, new_pair);
}
}
}
touchwin(win);
_nc_synchook(win);
code = OK;
}
returnCode(code);
}
#if USE_WIDEC_SUPPORT
NCURSES_EXPORT(int)
wbkgrnd(WINDOW *win, const ARG_CH_T ch)
{
return _nc_background(win, ch, FALSE);
}
#endif
NCURSES_EXPORT(int)
wbkgd(WINDOW *win, chtype ch)
{
NCURSES_CH_T wch;
SetChar2(wch, ch);
return _nc_background(win, CHREF(wch), TRUE);
}

140
third_party/ncurses/lib_box.c vendored Normal file
View file

@ -0,0 +1,140 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2010,2017 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-on *
* and: Sven Verdoolaege 2001 *
****************************************************************************/
/*
** lib_box.c
**
** The routine wborder().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_box.c,v 1.26 2020/02/02 23:34:34 tom Exp $")
#if USE_WIDEC_SUPPORT
static NCURSES_INLINE chtype
_my_render(WINDOW *win, chtype ch)
{
NCURSES_CH_T wch;
SetChar2(wch, ch);
wch = _nc_render(win, wch);
return ((attr_t) CharOf(wch)) | AttrOf(wch);
}
#define RENDER_WITH_DEFAULT(ch,def) w ## ch = _my_render(win, (ch == 0) ? def : ch)
#else
#define RENDER_WITH_DEFAULT(ch,def) w ## ch = _nc_render(win, (ch == 0) ? def : ch)
#endif
NCURSES_EXPORT(int)
wborder(WINDOW *win,
chtype ls, chtype rs,
chtype ts, chtype bs,
chtype tl, chtype tr,
chtype bl, chtype br)
{
NCURSES_SIZE_T i;
NCURSES_SIZE_T endx, endy;
chtype wls, wrs, wts, wbs, wtl, wtr, wbl, wbr;
T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
(void *) win,
_tracechtype2(1, ls),
_tracechtype2(2, rs),
_tracechtype2(3, ts),
_tracechtype2(4, bs),
_tracechtype2(5, tl),
_tracechtype2(6, tr),
_tracechtype2(7, bl),
_tracechtype2(8, br)));
if (!win)
returnCode(ERR);
RENDER_WITH_DEFAULT(ls, ACS_VLINE);
RENDER_WITH_DEFAULT(rs, ACS_VLINE);
RENDER_WITH_DEFAULT(ts, ACS_HLINE);
RENDER_WITH_DEFAULT(bs, ACS_HLINE);
RENDER_WITH_DEFAULT(tl, ACS_ULCORNER);
RENDER_WITH_DEFAULT(tr, ACS_URCORNER);
RENDER_WITH_DEFAULT(bl, ACS_LLCORNER);
RENDER_WITH_DEFAULT(br, ACS_LRCORNER);
T(("using %s, %s, %s, %s, %s, %s, %s, %s",
_tracechtype2(1, wls),
_tracechtype2(2, wrs),
_tracechtype2(3, wts),
_tracechtype2(4, wbs),
_tracechtype2(5, wtl),
_tracechtype2(6, wtr),
_tracechtype2(7, wbl),
_tracechtype2(8, wbr)));
endx = win->_maxx;
endy = win->_maxy;
for (i = 0; i <= endx; i++) {
SetChar2(win->_line[0].text[i], wts);
SetChar2(win->_line[endy].text[i], wbs);
}
win->_line[endy].firstchar = win->_line[0].firstchar = 0;
win->_line[endy].lastchar = win->_line[0].lastchar = endx;
for (i = 0; i <= endy; i++) {
#if USE_WIDEC_SUPPORT
if (endx > 0 && isWidecExt(win->_line[i].text[endx])) {
SetChar2(win->_line[i].text[endx - 1], ' ');
}
#endif
SetChar2(win->_line[i].text[0], wls);
SetChar2(win->_line[i].text[endx], wrs);
win->_line[i].firstchar = 0;
win->_line[i].lastchar = endx;
#if USE_WIDEC_SUPPORT
if (isWidecExt(win->_line[i].text[1])) {
SetChar2(win->_line[i].text[1], ' ');
}
#endif
}
SetChar2(win->_line[0].text[0], wtl);
SetChar2(win->_line[0].text[endx], wtr);
SetChar2(win->_line[endy].text[0], wbl);
SetChar2(win->_line[endy].text[endx], wbr);
_nc_synchook(win);
returnCode(OK);
}

114
third_party/ncurses/lib_box_set.c vendored Normal file
View file

@ -0,0 +1,114 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 2002-2009,2011 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. *
****************************************************************************/
/****************************************************************************
* Authors: Sven Verdoolaege and Thomas Dickey 2001,2002 *
****************************************************************************/
/*
** lib_box_set.c
**
** The routine wborder_set().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_box_set.c,v 1.7 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
wborder_set(WINDOW *win,
const ARG_CH_T ls, const ARG_CH_T rs,
const ARG_CH_T ts, const ARG_CH_T bs,
const ARG_CH_T tl, const ARG_CH_T tr,
const ARG_CH_T bl, const ARG_CH_T br)
{
NCURSES_SIZE_T i;
NCURSES_SIZE_T endx, endy;
NCURSES_CH_T wls, wrs, wts, wbs, wtl, wtr, wbl, wbr;
T((T_CALLED("wborder_set(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
(void *) win,
_tracech_t2(1, ls),
_tracech_t2(2, rs),
_tracech_t2(3, ts),
_tracech_t2(4, bs),
_tracech_t2(5, tl),
_tracech_t2(6, tr),
_tracech_t2(7, bl),
_tracech_t2(8, br)));
if (!win)
returnCode(ERR);
#define RENDER_WITH_DEFAULT(ch,def) w ##ch = _nc_render(win, (ch == 0) ? *(const ARG_CH_T)def : *ch)
RENDER_WITH_DEFAULT(ls, WACS_VLINE);
RENDER_WITH_DEFAULT(rs, WACS_VLINE);
RENDER_WITH_DEFAULT(ts, WACS_HLINE);
RENDER_WITH_DEFAULT(bs, WACS_HLINE);
RENDER_WITH_DEFAULT(tl, WACS_ULCORNER);
RENDER_WITH_DEFAULT(tr, WACS_URCORNER);
RENDER_WITH_DEFAULT(bl, WACS_LLCORNER);
RENDER_WITH_DEFAULT(br, WACS_LRCORNER);
T(("using %s, %s, %s, %s, %s, %s, %s, %s",
_tracech_t2(1, CHREF(wls)),
_tracech_t2(2, CHREF(wrs)),
_tracech_t2(3, CHREF(wts)),
_tracech_t2(4, CHREF(wbs)),
_tracech_t2(5, CHREF(wtl)),
_tracech_t2(6, CHREF(wtr)),
_tracech_t2(7, CHREF(wbl)),
_tracech_t2(8, CHREF(wbr))));
endx = win->_maxx;
endy = win->_maxy;
for (i = 0; i <= endx; i++) {
win->_line[0].text[i] = wts;
win->_line[endy].text[i] = wbs;
}
win->_line[endy].firstchar = win->_line[0].firstchar = 0;
win->_line[endy].lastchar = win->_line[0].lastchar = endx;
for (i = 0; i <= endy; i++) {
win->_line[i].text[0] = wls;
win->_line[i].text[endx] = wrs;
win->_line[i].firstchar = 0;
win->_line[i].lastchar = endx;
}
win->_line[0].text[0] = wtl;
win->_line[0].text[endx] = wtr;
win->_line[endy].text[0] = wbl;
win->_line[endy].text[endx] = wbr;
_nc_synchook(win);
returnCode(OK);
}

158
third_party/ncurses/lib_cchar.c vendored Normal file
View file

@ -0,0 +1,158 @@
/****************************************************************************
* Copyright 2019-2021,2022 Thomas E. Dickey *
* Copyright 2001-2016,2017 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. *
****************************************************************************/
/*
** lib_cchar.c
**
** The routines setcchar() and getcchar().
**
*/
#include "curses.priv.h"
#include <wchar.h>
MODULE_ID("$Id: lib_cchar.c,v 1.38 2022/07/27 08:03:16 tom Exp $")
/*
* The SuSv2 description leaves some room for interpretation. We'll assume wch
* points to a string which is L'\0' terminated, contains at least one
* character with strictly positive width, which must be the first, and
* contains no characters of negative width.
*/
NCURSES_EXPORT(int)
setcchar(cchar_t *wcval,
const wchar_t *wch,
const attr_t attrs,
NCURSES_PAIRS_T pair_arg,
const void *opts)
{
int code = OK;
int color_pair = pair_arg;
unsigned len;
TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,attrs=%lu,pair=%d,%p)"),
(void *) wcval, _nc_viswbuf(wch),
(unsigned long) attrs, color_pair, opts));
set_extended_pair(opts, color_pair);
if (wch == NULL
|| ((len = (unsigned) wcslen(wch)) > 1 && _nc_wacs_width(wch[0]) < 0)
|| color_pair < 0) {
code = ERR;
} else {
unsigned i;
if (len > CCHARW_MAX)
len = CCHARW_MAX;
/*
* If we have a following spacing-character, stop at that point. We
* are only interested in adding non-spacing characters.
*/
for (i = 1; i < len; ++i) {
if (_nc_wacs_width(wch[i]) != 0) {
len = i;
break;
}
}
memset(wcval, 0, sizeof(*wcval));
if (len != 0) {
SetAttr(*wcval, attrs);
SetPair(CHDEREF(wcval), color_pair);
memcpy(&wcval->chars, wch, len * sizeof(wchar_t));
TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len,
_tracecchar_t(wcval)));
}
}
TR(TRACE_CCALLS, (T_RETURN("%d"), code));
return (code);
}
NCURSES_EXPORT(int)
getcchar(const cchar_t *wcval,
wchar_t *wch,
attr_t *attrs,
NCURSES_PAIRS_T *pair_arg,
void *opts)
{
int code = ERR;
TR(TRACE_CCALLS, (T_CALLED("getcchar(%p,%p,%p,%p,%p)"),
(const void *) wcval,
(void *) wch,
(void *) attrs,
(void *) pair_arg,
opts));
#if !NCURSES_EXT_COLORS
if (opts != NULL) {
; /* empty */
} else
#endif
if (wcval != NULL) {
wchar_t *wp;
int len;
#if HAVE_WMEMCHR
len = ((wp = wmemchr(wcval->chars, L'\0', (size_t) CCHARW_MAX))
? (int) (wp - wcval->chars)
: CCHARW_MAX);
#else
len = wcsnlen(wcval->chars, CCHARW_MAX);
#endif
if (wch == NULL) {
/*
* If the value is a null, set the length to 1.
* If the value is not a null, return the length plus 1 for null.
*/
code = (len < CCHARW_MAX) ? (len + 1) : CCHARW_MAX;
} else if (attrs == 0 || pair_arg == 0) {
code = ERR;
} else if (len >= 0) {
int color_pair;
TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len,
_tracecchar_t(wcval)));
*attrs = AttrOf(*wcval) & A_ATTRIBUTES;
color_pair = GetPair(*wcval);
get_extended_pair(opts, color_pair);
*pair_arg = limit_PAIRS(color_pair);
wmemcpy(wch, wcval->chars, (size_t) len);
wch[len] = L'\0';
if (*pair_arg >= 0)
code = OK;
}
}
TR(TRACE_CCALLS, (T_RETURN("%d"), code));
return (code);
}

80
third_party/ncurses/lib_chgat.c vendored Normal file
View file

@ -0,0 +1,80 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2016,2017 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: Sven Verdoolaege 2001 *
* and: Thomas E. Dickey 2005 *
****************************************************************************/
/*
** lib_chgat.c
**
** The routine wchgat().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_chgat.c,v 1.13 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
wchgat(WINDOW *win,
int n,
attr_t attr,
NCURSES_PAIRS_T pair_arg,
const void *opts GCC_UNUSED)
{
int code = ERR;
int color_pair = pair_arg;
T((T_CALLED("wchgat(%p,%d,%s,%d)"),
(void *) win,
n,
_traceattr(attr),
color_pair));
set_extended_pair(opts, color_pair);
if (win) {
struct ldat *line = &(win->_line[win->_cury]);
int i;
toggle_attr_on(attr, ColorPair(color_pair));
for (i = win->_curx; i <= win->_maxx && (n == -1 || (n-- > 0)); i++) {
SetAttr(line->text[i], attr);
SetPair(line->text[i], color_pair);
CHANGED_CELL(line, i);
}
code = OK;
}
returnCode(code);
}

57
third_party/ncurses/lib_clear.c vendored Normal file
View file

@ -0,0 +1,57 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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> *
****************************************************************************/
/*
** lib_clear.c
**
** The routine wclear().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_clear.c,v 1.9 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
wclear(WINDOW *win)
{
int code = ERR;
T((T_CALLED("wclear(%p)"), (void *) win));
if ((code = werase(win)) != ERR)
win->_clear = TRUE;
returnCode(code);
}

56
third_party/ncurses/lib_clearok.c vendored Normal file
View file

@ -0,0 +1,56 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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> *
****************************************************************************/
/*
** lib_clearok.c
**
** The routine clearok.
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_clearok.c,v 1.6 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
clearok(WINDOW *win, bool flag)
{
T((T_CALLED("clearok(%p,%d)"), (void *) win, flag));
if (win) {
win->_clear = flag;
returnCode(OK);
} else
returnCode(ERR);
}

77
third_party/ncurses/lib_clrbot.c vendored Normal file
View file

@ -0,0 +1,77 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2006,2009 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> *
****************************************************************************/
/*
** lib_clrbot.c
**
** The routine wclrtobot().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_clrbot.c,v 1.22 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
wclrtobot(WINDOW *win)
{
int code = ERR;
T((T_CALLED("wclrtobot(%p)"), (void *) win));
if (win) {
NCURSES_SIZE_T y;
NCURSES_SIZE_T startx = win->_curx;
NCURSES_CH_T blank = win->_nc_bkgd;
T(("clearing from y = %ld to y = %ld with maxx = %ld",
(long) win->_cury, (long) win->_maxy, (long) win->_maxx));
for (y = win->_cury; y <= win->_maxy; y++) {
struct ldat *line = &(win->_line[y]);
NCURSES_CH_T *ptr = &(line->text[startx]);
NCURSES_CH_T *end = &(line->text[win->_maxx]);
CHANGED_TO_EOL(line, startx, win->_maxx);
while (ptr <= end)
*ptr++ = blank;
startx = 0;
}
_nc_synchook(win);
code = OK;
}
returnCode(code);
}

92
third_party/ncurses/lib_clreol.c vendored Normal file
View file

@ -0,0 +1,92 @@
/****************************************************************************
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2001,2009 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> *
****************************************************************************/
/*
** lib_clreol.c
**
** The routine wclrtoeol().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_clreol.c,v 1.24 2021/10/23 19:06:01 tom Exp $")
NCURSES_EXPORT(int)
wclrtoeol(WINDOW *win)
{
int code = ERR;
T((T_CALLED("wclrtoeol(%p)"), (void *) win));
if (win) {
NCURSES_CH_T blank;
NCURSES_CH_T *ptr, *end;
struct ldat *line;
NCURSES_SIZE_T y = win->_cury;
NCURSES_SIZE_T x = win->_curx;
/*
* If we have just wrapped the cursor, the clear applies to the
* new line, unless we are at the lower right corner.
*/
if (IS_WRAPPED(win) != 0
&& y < win->_maxy) {
win->_flags &= ~_WRAPPED;
}
/*
* There's no point in clearing if we're not on a legal
* position, either.
*/
if (IS_WRAPPED(win)
|| y > win->_maxy
|| x > win->_maxx)
returnCode(ERR);
blank = win->_nc_bkgd;
line = &win->_line[y];
CHANGED_TO_EOL(line, x, win->_maxx);
ptr = &(line->text[x]);
end = &(line->text[win->_maxx]);
while (ptr <= end)
*ptr++ = blank;
_nc_synchook(win);
code = OK;
}
returnCode(code);
}

1166
third_party/ncurses/lib_color.c vendored Normal file

File diff suppressed because it is too large Load diff

65
third_party/ncurses/lib_colorset.c vendored Normal file
View file

@ -0,0 +1,65 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2014,2017 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: Juergen Pfeifer, 1998 *
* and: Thomas E. Dickey, 2005-on *
****************************************************************************/
/*
** lib_colorset.c
**
** The routine wcolor_set().
**
*/
#include "curses.priv.h"
#include <ctype.h>
MODULE_ID("$Id: lib_colorset.c,v 1.16 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
wcolor_set(WINDOW *win, NCURSES_PAIRS_T pair_arg, void *opts)
{
int code = ERR;
int color_pair = pair_arg;
T((T_CALLED("wcolor_set(%p,%d)"), (void *) win, color_pair));
set_extended_pair(opts, color_pair);
if (win
&& (SP != 0)
&& (color_pair >= 0)
&& (color_pair < SP->_pair_limit)) {
TR(TRACE_ATTRS, ("... current %ld", (long) GET_WINDOW_PAIR(win)));
SET_WINDOW_PAIR(win, color_pair);
if_EXT_COLORS(win->_color = color_pair);
code = OK;
}
returnCode(code);
}

200
third_party/ncurses/lib_cur_term.c vendored Normal file
View file

@ -0,0 +1,200 @@
/****************************************************************************
,* Copyright 2020-2021,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 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 <dickey@clark.net> 1997 *
****************************************************************************/
/*
* Module that "owns" the 'cur_term' variable:
*
* TERMINAL *set_curterm(TERMINAL *)
* int del_curterm(TERMINAL *)
*/
#include "curses.priv.h"
#include "termcap.h" /* ospeed */
#include "tic.h" /* VALID_STRING */
MODULE_ID("$Id: lib_cur_term.c,v 1.49 2022/05/28 17:56:55 tom Exp $")
#undef CUR
#define CUR TerminalType(termp).
#if USE_REENTRANT
NCURSES_EXPORT(TERMINAL *)
NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_DCL0)
{
return ((0 != TerminalOf(SP_PARM)) ? TerminalOf(SP_PARM) : CurTerm);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(TERMINAL *)
_nc_get_cur_term(void)
{
return NCURSES_SP_NAME(_nc_get_cur_term) (CURRENT_SCREEN);
}
#endif
NCURSES_EXPORT(TERMINAL *)
NCURSES_PUBLIC_VAR(cur_term) (void)
{
#if NCURSES_SP_FUNCS
return NCURSES_SP_NAME(_nc_get_cur_term) (CURRENT_SCREEN);
#else
return NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_ARG);
#endif
}
#else
NCURSES_EXPORT_VAR(TERMINAL *) cur_term = 0;
#endif
NCURSES_EXPORT(TERMINAL *)
NCURSES_SP_NAME(set_curterm) (NCURSES_SP_DCLx TERMINAL *termp)
{
TERMINAL *oldterm;
T((T_CALLED("set_curterm(%p)"), (void *) termp));
_nc_lock_global(curses);
oldterm = cur_term;
if (SP_PARM)
SP_PARM->_term = termp;
#if USE_REENTRANT
CurTerm = termp;
#else
cur_term = termp;
#endif
if (termp != 0) {
#ifdef USE_TERM_DRIVER
TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) termp;
ospeed = (NCURSES_OSPEED) _nc_ospeed(termp->_baudrate);
if (TCB->drv &&
TCB->drv->isTerminfo &&
TerminalType(termp).Strings) {
PC = (char) (VALID_STRING(pad_char) ? pad_char[0] : 0);
}
TCB->csp = SP_PARM;
#else
ospeed = (NCURSES_OSPEED) _nc_ospeed(termp->_baudrate);
if (TerminalType(termp).Strings) {
PC = (char) (VALID_STRING(pad_char) ? pad_char[0] : 0);
}
#endif
#if !USE_REENTRANT
save_ttytype(termp);
#endif
}
_nc_unlock_global(curses);
T((T_RETURN("%p"), (void *) oldterm));
return (oldterm);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(TERMINAL *)
set_curterm(TERMINAL *termp)
{
return NCURSES_SP_NAME(set_curterm) (CURRENT_SCREEN, termp);
}
#endif
NCURSES_EXPORT(int)
NCURSES_SP_NAME(del_curterm) (NCURSES_SP_DCLx TERMINAL *termp)
{
int rc = ERR;
T((T_CALLED("del_curterm(%p, %p)"), (void *) SP_PARM, (void *) termp));
if (termp != 0) {
#ifdef USE_TERM_DRIVER
TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) termp;
#endif
TERMINAL *cur = (
#if USE_REENTRANT
NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_ARG)
#else
cur_term
#endif
);
#if NCURSES_EXT_NUMBERS
#if NCURSES_EXT_COLORS
_nc_free_termtype1(&termp->type);
#else
_nc_free_termtype2(&termp->type);
#endif
#endif
_nc_free_termtype2(&TerminalType(termp));
if (termp == cur)
NCURSES_SP_NAME(set_curterm) (NCURSES_SP_ARGx 0);
FreeIfNeeded(termp->_termname);
#if USE_HOME_TERMINFO
if (_nc_globals.home_terminfo != 0) {
FreeAndNull(_nc_globals.home_terminfo);
}
#endif
#ifdef USE_TERM_DRIVER
if (TCB->drv)
TCB->drv->td_release(TCB);
#endif
#if NO_LEAKS
/* discard memory used in tgetent's cache for this terminal */
_nc_tgetent_leak(termp);
#endif
if (--_nc_globals.terminal_count == 0) {
_nc_free_tparm(termp);
}
free(termp->tparm_state.fmt_buff);
free(termp->tparm_state.out_buff);
free(termp);
rc = OK;
}
returnCode(rc);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
del_curterm(TERMINAL *termp)
{
int rc;
_nc_lock_global(curses);
rc = NCURSES_SP_NAME(del_curterm) (CURRENT_SCREEN, termp);
_nc_unlock_global(curses);
return (rc);
}
#endif

406
third_party/ncurses/lib_data.c vendored Normal file
View file

@ -0,0 +1,406 @@
/****************************************************************************
* Copyright 2018-2021,2022 Thomas E. Dickey *
* Copyright 1998-2016,2017 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-on *
* and: Juergen Pfeifer *
****************************************************************************/
/*
** lib_data.c
**
** Common data that may/may not be allocated, but is referenced globally
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_data.c,v 1.87 2022/07/09 22:03:21 tom Exp $")
/*
* OS/2's native linker complains if we don't initialize public data when
* constructing a dll (reported by J.J.G.Ripoll).
*/
#if USE_REENTRANT
NCURSES_EXPORT(WINDOW *)
NCURSES_PUBLIC_VAR(stdscr) (void)
{
return CURRENT_SCREEN ? StdScreen(CURRENT_SCREEN) : 0;
}
NCURSES_EXPORT(WINDOW *)
NCURSES_PUBLIC_VAR(curscr) (void)
{
return CURRENT_SCREEN ? CurScreen(CURRENT_SCREEN) : 0;
}
NCURSES_EXPORT(WINDOW *)
NCURSES_PUBLIC_VAR(newscr) (void)
{
return CURRENT_SCREEN ? NewScreen(CURRENT_SCREEN) : 0;
}
#else
NCURSES_EXPORT_VAR(WINDOW *) stdscr = 0;
NCURSES_EXPORT_VAR(WINDOW *) curscr = 0;
NCURSES_EXPORT_VAR(WINDOW *) newscr = 0;
#endif
NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain = 0;
/*
* The variable 'SP' will be defined as a function on systems that cannot link
* data-only modules, since it is used in a lot of places within ncurses and we
* cannot guarantee that any application will use any particular function. We
* put the WINDOW variables in this module, because it appears that any
* application that uses them will also use 'SP'.
*
* This module intentionally does not reference other ncurses modules, to avoid
* module coupling that increases the size of the executable.
*/
#if BROKEN_LINKER
static SCREEN *my_screen;
NCURSES_EXPORT(SCREEN *)
_nc_screen(void)
{
return my_screen;
}
NCURSES_EXPORT(int)
_nc_alloc_screen(void)
{
my_screen = _nc_alloc_screen_sp();
T(("_nc_alloc_screen_sp %p", my_screen));
return (my_screen != 0);
}
NCURSES_EXPORT(void)
_nc_set_screen(SCREEN *sp)
{
my_screen = sp;
}
#else
NCURSES_EXPORT_VAR(SCREEN *) SP = NULL; /* Some linkers require initialized data... */
#endif
/* *INDENT-OFF* */
#define CHARS_0s { '\0' }
#define TGETENT_0 { 0L, FALSE, NULL, NULL, NULL }
#define TGETENT_0s { TGETENT_0, TGETENT_0, TGETENT_0, TGETENT_0 }
NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = {
0, /* have_sigtstp */
0, /* have_sigwinch */
0, /* cleanup_nested */
FALSE, /* init_signals */
FALSE, /* init_screen */
NULL, /* comp_sourcename */
NULL, /* comp_termtype */
FALSE, /* have_tic_directory */
FALSE, /* keep_tic_directory */
0, /* tic_directory */
NULL, /* dbi_list */
0, /* dbi_size */
NULL, /* first_name */
NULL, /* keyname_table */
0, /* init_keyname */
0, /* slk_format */
2048, /* getstr_limit */
NULL, /* safeprint_buf */
0, /* safeprint_used */
TGETENT_0s, /* tgetent_cache */
0, /* tgetent_index */
0, /* tgetent_sequence */
0, /* terminal_count */
0, /* dbd_blob */
0, /* dbd_list */
0, /* dbd_size */
0, /* dbd_time */
{ { 0, 0 } }, /* dbd_vars */
#if HAVE_TSEARCH
NULL, /* cached_tparm */
0, /* count_tparm */
#endif /* HAVE_TSEARCH */
#ifdef USE_TERM_DRIVER
0, /* term_driver */
#endif
#ifndef USE_SP_WINDOWLIST
0, /* _nc_windowlist */
#endif
#if USE_HOME_TERMINFO
NULL, /* home_terminfo */
#endif
#if !USE_SAFE_SPRINTF
0, /* safeprint_cols */
0, /* safeprint_rows */
#endif
#ifdef USE_PTHREADS
PTHREAD_MUTEX_INITIALIZER, /* mutex_curses */
PTHREAD_MUTEX_INITIALIZER, /* mutex_prescreen */
PTHREAD_MUTEX_INITIALIZER, /* mutex_screen */
PTHREAD_MUTEX_INITIALIZER, /* mutex_update */
PTHREAD_MUTEX_INITIALIZER, /* mutex_tst_tracef */
PTHREAD_MUTEX_INITIALIZER, /* mutex_tracef */
0, /* nested_tracef */
0, /* use_pthreads */
#if USE_PTHREADS_EINTR
0, /* read_thread */
#endif
#endif
#if USE_WIDEC_SUPPORT
CHARS_0s, /* key_name */
#endif
#ifdef TRACE
FALSE, /* trace_opened */
CHARS_0s, /* trace_fname */
0, /* trace_level */
NULL, /* trace_fp */
-1, /* trace_fd */
NULL, /* tracearg_buf */
0, /* tracearg_used */
NULL, /* tracebuf_ptr */
0, /* tracebuf_used */
CHARS_0s, /* tracechr_buf */
NULL, /* tracedmp_buf */
0, /* tracedmp_used */
NULL, /* tracetry_buf */
0, /* tracetry_used */
{ CHARS_0s, CHARS_0s }, /* traceatr_color_buf */
0, /* traceatr_color_sel */
-1, /* traceatr_color_last */
#if !defined(USE_PTHREADS) && USE_REENTRANT
0, /* nested_tracef */
#endif
#endif /* TRACE */
#if NO_LEAKS
FALSE, /* leak_checking */
#endif
};
#define STACK_FRAME_0 { { 0 }, 0 }
#define STACK_FRAME_0s { STACK_FRAME_0 }
#define NUM_VARS_0s { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
#define RIPOFF_0 { 0,0,0 }
#define RIPOFF_0s { RIPOFF_0 }
NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen = {
NULL, /* allocated */
TRUE, /* use_env */
FALSE, /* filter_mode */
A_NORMAL, /* previous_attr */
{ /* tparm_state */
NULL, /* tparam_base */
STACK_FRAME_0s, /* stack */
0, /* stack_ptr */
NULL, /* out_buff */
0, /* out_size */
0, /* out_used */
NULL, /* fmt_buff */
0, /* fmt_size */
NUM_VARS_0s, /* static_vars */
#ifdef TRACE
NULL, /* tname */
#endif
},
NULL, /* saved_tty */
FALSE, /* use_tioctl */
0, /* _outch */
#ifndef USE_SP_RIPOFF
RIPOFF_0s, /* ripoff */
NULL, /* rsp */
#endif
#if NCURSES_NO_PADDING
FALSE, /* flag to set if padding disabled */
#endif
#if BROKEN_LINKER || USE_REENTRANT
NULL, /* real_acs_map */
0, /* LINES */
0, /* COLS */
8, /* TABSIZE */
1000, /* ESCDELAY */
0, /* cur_term */
#endif
#ifdef TRACE
#if BROKEN_LINKER || USE_REENTRANT
0L, /* _outchars */
NULL, /* _tputs_trace */
#endif
#endif
};
/* *INDENT-ON* */
/*
* wgetch() and other functions with a WINDOW* parameter may use a SCREEN*
* internally, and it is useful to allow those to be invoked without switching
* SCREEN's, e.g., for multi-threaded applications.
*/
NCURSES_EXPORT(SCREEN *)
_nc_screen_of(WINDOW *win)
{
SCREEN *sp = 0;
if (win != 0) {
sp = WINDOW_EXT(win, screen);
}
return (sp);
}
/******************************************************************************/
#ifdef USE_PTHREADS
static void
init_global_mutexes(void)
{
static bool initialized = FALSE;
if (!initialized) {
initialized = TRUE;
_nc_mutex_init(&_nc_globals.mutex_curses);
_nc_mutex_init(&_nc_globals.mutex_prescreen);
_nc_mutex_init(&_nc_globals.mutex_screen);
_nc_mutex_init(&_nc_globals.mutex_update);
_nc_mutex_init(&_nc_globals.mutex_tst_tracef);
_nc_mutex_init(&_nc_globals.mutex_tracef);
}
}
NCURSES_EXPORT(void)
_nc_init_pthreads(void)
{
if (_nc_use_pthreads)
return;
# if USE_WEAK_SYMBOLS
if ((pthread_mutex_init) == 0)
return;
if ((pthread_mutex_lock) == 0)
return;
if ((pthread_mutex_unlock) == 0)
return;
if ((pthread_mutex_trylock) == 0)
return;
if ((pthread_mutexattr_settype) == 0)
return;
# endif
_nc_use_pthreads = 1;
init_global_mutexes();
}
/*
* Use recursive mutexes if we have them - they're part of Unix98.
* For the cases where we do not, _nc_mutex_trylock() is used to avoid a
* deadlock, at the expense of memory leaks and unexpected failures that
* may not be handled by typical clients.
*
* FIXME - need configure check for PTHREAD_MUTEX_RECURSIVE, define it to
* PTHREAD_MUTEX_NORMAL if not supported.
*/
NCURSES_EXPORT(void)
_nc_mutex_init(pthread_mutex_t * obj)
{
pthread_mutexattr_t recattr;
if (_nc_use_pthreads) {
pthread_mutexattr_init(&recattr);
pthread_mutexattr_settype(&recattr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(obj, &recattr);
}
}
NCURSES_EXPORT(int)
_nc_mutex_lock(pthread_mutex_t * obj)
{
int rc = 0;
if (_nc_use_pthreads != 0)
rc = pthread_mutex_lock(obj);
return rc;
}
NCURSES_EXPORT(int)
_nc_mutex_trylock(pthread_mutex_t * obj)
{
int rc = 0;
if (_nc_use_pthreads != 0)
rc = pthread_mutex_trylock(obj);
return rc;
}
NCURSES_EXPORT(int)
_nc_mutex_unlock(pthread_mutex_t * obj)
{
int rc = 0;
if (_nc_use_pthreads != 0)
rc = pthread_mutex_unlock(obj);
return rc;
}
#endif /* USE_PTHREADS */
#if defined(USE_PTHREADS) || USE_PTHREADS_EINTR
#if USE_WEAK_SYMBOLS
/*
* NB: sigprocmask(2) is global but pthread_sigmask(3p)
* only for the calling thread.
*/
NCURSES_EXPORT(int)
_nc_sigprocmask(int how, const sigset_t * newmask, sigset_t * oldmask)
{
if ((pthread_sigmask))
return pthread_sigmask(how, newmask, oldmask);
else
return (sigprocmask) (how, newmask, oldmask);
}
#endif
#endif /* USE_PTHREADS */

70
third_party/ncurses/lib_delch.c vendored Normal file
View file

@ -0,0 +1,70 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2001,2009 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> *
****************************************************************************/
/*
** lib_delch.c
**
** The routine wdelch().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_delch.c,v 1.14 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
wdelch(WINDOW *win)
{
int code = ERR;
T((T_CALLED("wdelch(%p)"), (void *) win));
if (win) {
NCURSES_CH_T blank = win->_nc_bkgd;
struct ldat *line = &(win->_line[win->_cury]);
NCURSES_CH_T *end = &(line->text[win->_maxx]);
NCURSES_CH_T *temp2 = &(line->text[win->_curx + 1]);
NCURSES_CH_T *temp1 = temp2 - 1;
CHANGED_TO_EOL(line, win->_curx, win->_maxx);
while (temp1 < end)
*temp1++ = *temp2++;
*temp1 = blank;
_nc_synchook(win);
code = OK;
}
returnCode(code);
}

102
third_party/ncurses/lib_delwin.c vendored Normal file
View file

@ -0,0 +1,102 @@
/****************************************************************************
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2008,2009 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-on *
* and: Juergen Pfeifer 2008 *
****************************************************************************/
/*
** lib_delwin.c
**
** The routine delwin().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_delwin.c,v 1.24 2021/12/11 23:56:25 tom Exp $")
static bool
cannot_delete(WINDOW *win)
{
bool result = TRUE;
if (IS_PAD(win)) {
result = FALSE;
} else {
WINDOWLIST *p;
#ifdef USE_SP_WINDOWLIST
SCREEN *sp = _nc_screen_of(win);
#endif
for (each_window(SP_PARM, p)) {
if (&(p->win) == win) {
result = FALSE;
} else if (IS_SUBWIN(&(p->win))
&& p->win._parent == win) {
result = TRUE;
break;
}
}
}
return result;
}
NCURSES_EXPORT(int)
delwin(WINDOW *win)
{
int result = ERR;
T((T_CALLED("delwin(%p)"), (void *) win));
if (_nc_try_global(curses) == 0) {
if (win == 0
|| cannot_delete(win)) {
result = ERR;
} else if (IS_PAD(win)) {
win->_parent = NULL;
result = _nc_freewin(win);
} else {
#if NCURSES_SP_FUNCS
SCREEN *sp = _nc_screen_of(win);
#endif
if (IS_SUBWIN(win)) {
touchwin(win->_parent);
} else if (CurScreen(SP_PARM) != 0) {
touchwin(CurScreen(SP_PARM));
}
result = _nc_freewin(win);
}
_nc_unlock_global(curses);
}
returnCode(result);
}

104
third_party/ncurses/lib_dft_fgbg.c vendored Normal file
View file

@ -0,0 +1,104 @@
/****************************************************************************
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2014,2017 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 1998-on *
* Juergen Pfeifer 2009 *
****************************************************************************/
#include "curses.priv.h"
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
MODULE_ID("$Id: lib_dft_fgbg.c,v 1.31 2021/04/03 22:27:18 tom Exp $")
/*
* Modify the behavior of color-pair 0 so that the library doesn't assume that
* it is white on black. This is an extension to XSI curses.
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(use_default_colors) (NCURSES_SP_DCL0)
{
T((T_CALLED("use_default_colors(%p)"), (void *) SP_PARM));
returnCode(NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_ARGx -1, -1));
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
use_default_colors(void)
{
return NCURSES_SP_NAME(use_default_colors) (CURRENT_SCREEN);
}
#endif
/*
* Modify the behavior of color-pair 0 so that the library assumes that it
* is something specific, possibly not white on black.
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_DCLx int fg, int bg)
{
int code = ERR;
T((T_CALLED("assume_default_colors(%p,%d,%d)"), (void *) SP_PARM, fg, bg));
if (SP_PARM != 0) {
#ifdef USE_TERM_DRIVER
code = CallDriver_2(SP_PARM, td_defaultcolors, fg, bg);
#else
if ((orig_pair || orig_colors) && !initialize_pair) {
SP_PARM->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
SP_PARM->_has_sgr_39_49 = (tigetflag("AX") == TRUE);
SP_PARM->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : fg;
SP_PARM->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : bg;
if (SP_PARM->_color_pairs != 0) {
bool save = SP_PARM->_default_color;
SP_PARM->_assumed_color = TRUE;
SP_PARM->_default_color = TRUE;
NCURSES_SP_NAME(init_pair) (NCURSES_SP_ARGx 0,
(short)fg,
(short)bg);
SP_PARM->_default_color = save;
}
code = OK;
}
#endif
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
assume_default_colors(int fg, int bg)
{
return NCURSES_SP_NAME(assume_default_colors) (CURRENT_SCREEN, fg, bg);
}
#endif

84
third_party/ncurses/lib_echo.c vendored Normal file
View file

@ -0,0 +1,84 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
* echo.c
*
* Routines:
* echo()
* noecho()
*
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_echo.c,v 1.9 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
NCURSES_SP_NAME(echo) (NCURSES_SP_DCL0)
{
T((T_CALLED("echo(%p)"), (void *) SP_PARM));
if (0 == SP_PARM)
returnCode(ERR);
SP_PARM->_echo = TRUE;
returnCode(OK);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
echo(void)
{
return NCURSES_SP_NAME(echo) (CURRENT_SCREEN);
}
#endif
NCURSES_EXPORT(int)
NCURSES_SP_NAME(noecho) (NCURSES_SP_DCL0)
{
T((T_CALLED("noecho(%p)"), (void *) SP_PARM));
if (0 == SP_PARM)
returnCode(ERR);
SP_PARM->_echo = FALSE;
returnCode(OK);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
noecho(void)
{
return NCURSES_SP_NAME(noecho) (CURRENT_SCREEN);
}
#endif

80
third_party/ncurses/lib_endwin.c vendored Normal file
View file

@ -0,0 +1,80 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2014,2017 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-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
** lib_endwin.c
**
** The routine endwin().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_endwin.c,v 1.25 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
NCURSES_SP_NAME(endwin) (NCURSES_SP_DCL0)
{
int code = ERR;
T((T_CALLED("endwin(%p)"), (void *) SP_PARM));
if (SP_PARM) {
#ifdef USE_TERM_DRIVER
TERMINAL_CONTROL_BLOCK *TCB = TCBOf(SP_PARM);
SP_PARM->_endwin = ewSuspend;
if (TCB && TCB->drv && TCB->drv->td_scexit)
TCB->drv->td_scexit(SP_PARM);
#else
SP_PARM->_endwin = ewSuspend;
SP_PARM->_mouse_wrap(SP_PARM);
_nc_screen_wrap();
_nc_mvcur_wrap(); /* wrap up cursor addressing */
#endif
code = NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_ARG);
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
endwin(void)
{
return NCURSES_SP_NAME(endwin) (CURRENT_SCREEN);
}
#endif

97
third_party/ncurses/lib_erase.c vendored Normal file
View file

@ -0,0 +1,97 @@
/****************************************************************************
* Copyright 2020,2022 Thomas E. Dickey *
* Copyright 1998-2009,2016 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-on *
****************************************************************************/
/*
** lib_erase.c
**
** The routine werase().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_erase.c,v 1.20 2022/09/03 21:40:27 tom Exp $")
NCURSES_EXPORT(int)
werase(WINDOW *win)
{
int code = ERR;
NCURSES_CH_T *start;
T((T_CALLED("werase(%p)"), (void *) win));
if (win) {
NCURSES_CH_T blank;
NCURSES_CH_T *sp;
int y;
blank = win->_nc_bkgd;
for (y = 0; y <= win->_maxy; y++) {
NCURSES_CH_T *end;
start = win->_line[y].text;
end = &start[win->_maxx];
/*
* If this is a derived window, we have to handle the case where
* a multicolumn character extends into the window that we are
* erasing.
*/
if_WIDEC({
if (isWidecExt(start[0])) {
int x = (win->_parent != 0) ? (win->_begx) : 0;
while (x-- > 0) {
if (isWidecBase(start[-1])) {
--start;
break;
}
--start;
}
}
});
for (sp = start; sp <= end; sp++)
*sp = blank;
win->_line[y].firstchar = 0;
win->_line[y].lastchar = win->_maxx;
}
win->_curx = win->_cury = 0;
win->_flags &= ~_WRAPPED;
_nc_synchook(win);
code = OK;
}
returnCode(code);
}

96
third_party/ncurses/lib_erasewchar.c vendored Normal file
View file

@ -0,0 +1,96 @@
/****************************************************************************
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 2002-2010,2014 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 2002 *
****************************************************************************/
#include "curses.priv.h"
MODULE_ID("$Id: lib_erasewchar.c,v 1.5 2021/05/22 23:51:14 tom Exp $")
/*
* erasewchar()
*
* Return erase character as given in cur_term->Ottyb.
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(erasewchar) (NCURSES_SP_DCLx wchar_t *wch);
NCURSES_EXPORT(int)
NCURSES_SP_NAME(erasewchar) (NCURSES_SP_DCLx wchar_t *wch)
{
int value;
int result = ERR;
T((T_CALLED("erasewchar()")));
if ((value = NCURSES_SP_NAME(erasechar) (NCURSES_SP_ARG)) != ERR) {
*wch = (wchar_t) value;
result = OK;
}
returnCode(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
erasewchar(wchar_t *wch)
{
return NCURSES_SP_NAME(erasewchar) (CURRENT_SCREEN, wch);
}
#endif
/*
* killwchar()
*
* Return kill character as given in cur_term->Ottyb.
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(killwchar) (NCURSES_SP_DCLx wchar_t *wch);
NCURSES_EXPORT(int)
NCURSES_SP_NAME(killwchar) (NCURSES_SP_DCLx wchar_t *wch)
{
int value;
int result = ERR;
T((T_CALLED("killwchar()")));
if ((value = NCURSES_SP_NAME(killchar) (NCURSES_SP_ARG)) != ERR) {
*wch = (wchar_t) value;
result = OK;
}
returnCode(result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
killwchar(wchar_t *wch)
{
return NCURSES_SP_NAME(killwchar) (CURRENT_SCREEN, wch);
}
#endif

88
third_party/ncurses/lib_flash.c vendored Normal file
View file

@ -0,0 +1,88 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2013,2014 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-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
* flash.c
*
* The routine flash().
*
*/
#include "curses.priv.h"
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
MODULE_ID("$Id: lib_flash.c,v 1.15 2020/02/02 23:34:34 tom Exp $")
/*
* flash()
*
* Flash the current terminal's screen if possible. If not,
* sound the audible bell if one exists.
*
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(flash) (NCURSES_SP_DCL0)
{
int res = ERR;
T((T_CALLED("flash(%p)"), (void *) SP_PARM));
#ifdef USE_TERM_DRIVER
if (SP_PARM != 0)
res = CallDriver_1(SP_PARM, td_doBeepOrFlash, FALSE);
#else
if (HasTerminal(SP_PARM)) {
/* FIXME: should make sure that we are not in altchar mode */
if (flash_screen) {
res = NCURSES_PUTP2_FLUSH("flash_screen", flash_screen);
} else if (bell) {
res = NCURSES_PUTP2_FLUSH("bell", bell);
}
}
#endif
returnCode(res);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
flash(void)
{
return NCURSES_SP_NAME(flash) (CURRENT_SCREEN);
}
#endif

201
third_party/ncurses/lib_freeall.c vendored Normal file
View file

@ -0,0 +1,201 @@
/****************************************************************************
* Copyright 2018-2020,2021 Thomas E. Dickey *
* Copyright 1998-2016,2017 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 1996-on *
****************************************************************************/
#include "curses.priv.h"
#include "tic.h"
#if HAVE_NC_FREEALL
#if HAVE_LIBDBMALLOC
extern int malloc_errfd; /* FIXME */
#endif
MODULE_ID("$Id: lib_freeall.c,v 1.76 2021/11/06 21:52:49 tom Exp $")
/*
* Free all ncurses data. This is used for testing only (there's no practical
* use for it as an extension).
*/
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_DCL0)
{
static va_list empty_va;
T((T_CALLED("_nc_freeall()")));
#if NO_LEAKS
_nc_globals.leak_checking = TRUE;
if (SP_PARM != 0) {
if (SP_PARM->_oldnum_list != 0) {
FreeAndNull(SP_PARM->_oldnum_list);
}
if (SP_PARM->_panelHook.destroy != 0) {
SP_PARM->_panelHook.destroy(SP_PARM->_panelHook.stdscr_pseudo_panel);
}
#if NCURSES_EXT_COLORS
_nc_new_pair_leaks(SP_PARM);
#endif
}
#endif
if (SP_PARM != 0) {
_nc_lock_global(curses);
while (WindowList(SP_PARM) != 0) {
WINDOWLIST *p, *q;
bool deleted = FALSE;
/* Delete only windows that're not a parent */
for (each_window(SP_PARM, p)) {
WINDOW *p_win = &(p->win);
bool found = FALSE;
if (IS_PAD(p_win))
continue;
#ifndef USE_SP_WINDOWLIST
if (p->screen != SP_PARM)
continue;
#endif
for (each_window(SP_PARM, q)) {
WINDOW *q_win = &(q->win);
#ifndef USE_SP_WINDOWLIST
if (q->screen != SP_PARM)
continue;
#endif
if ((p != q)
&& IS_SUBWIN(q_win)
&& (p_win == q_win->_parent)) {
found = TRUE;
break;
}
}
if (!found) {
if (delwin(p_win) != ERR)
deleted = TRUE;
break;
}
}
/*
* Don't continue to loop if the list is trashed.
*/
if (!deleted)
break;
}
delscreen(SP_PARM);
_nc_unlock_global(curses);
}
(void) _nc_printf_string(0, empty_va);
#ifdef TRACE
(void) _nc_trace_buf(-1, (size_t) 0);
#endif
#if USE_WIDEC_SUPPORT
FreeIfNeeded(_nc_wacs);
#endif
_nc_leaks_tinfo();
#if HAVE_LIBDBMALLOC
malloc_dump(malloc_errfd);
#elif HAVE_LIBDMALLOC
#elif HAVE_LIBMPATROL
__mp_summary();
#elif HAVE_PURIFY
purify_all_inuse();
#endif
returnVoid;
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_freeall(void)
{
NCURSES_SP_NAME(_nc_freeall) (CURRENT_SCREEN);
}
#endif
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code)
{
T((T_CALLED("_nc_free_and_exit(%d)"), code));
NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
NCURSES_SP_NAME(_nc_freeall) (NCURSES_SP_ARG);
#ifdef TRACE
curses_trace(0); /* close trace file, freeing its setbuf */
{
static va_list fake;
free(_nc_varargs("?", fake));
}
#endif
exit(code);
}
#else /* !HAVE_NC_FREEALL */
NCURSES_EXPORT(void)
_nc_freeall(void)
{
}
NCURSES_EXPORT(void)
NCURSES_SP_NAME(_nc_free_and_exit) (NCURSES_SP_DCLx int code)
{
if (SP_PARM) {
delscreen(SP_PARM);
}
exit(code);
}
#endif /* HAVE_NC_FREEALL */
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(void)
_nc_free_and_exit(int code)
{
NCURSES_SP_NAME(_nc_free_and_exit) (CURRENT_SCREEN, code);
}
#endif
NCURSES_EXPORT(void)
exit_curses(int code)
{
#if NO_LEAKS
#if NCURSES_SP_FUNCS
NCURSES_SP_NAME(_nc_free_and_exit) (CURRENT_SCREEN, code);
#else
_nc_free_and_exit(code); /* deprecated... */
#endif
#endif
exit(code);
}

1170
third_party/ncurses/lib_gen.c vendored Normal file

File diff suppressed because it is too large Load diff

121
third_party/ncurses/lib_get_wch.c vendored Normal file
View file

@ -0,0 +1,121 @@
/****************************************************************************
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 2002-2011,2016 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 2002-on *
****************************************************************************/
/*
** lib_get_wch.c
**
** The routine get_wch().
**
*/
#include "curses.priv.h"
#include <ctype.h>
MODULE_ID("$Id: lib_get_wch.c,v 1.26 2021/04/17 16:12:54 tom Exp $")
NCURSES_EXPORT(int)
wget_wch(WINDOW *win, wint_t *result)
{
SCREEN *sp;
int code;
int value = 0;
#ifndef state_unused
mbstate_t state;
#endif
T((T_CALLED("wget_wch(%p)"), (void *) win));
/*
* We can get a stream of single-byte characters and KEY_xxx codes from
* _nc_wgetch(), while we want to return a wide character or KEY_xxx code.
*/
_nc_lock_global(curses);
sp = _nc_screen_of(win);
if (sp != 0) {
size_t count = 0;
for (;;) {
char buffer[(MB_LEN_MAX * 9) + 1]; /* allow some redundant shifts */
T(("reading %d of %d", (int) count + 1, (int) sizeof(buffer)));
code = _nc_wgetch(win, &value, TRUE EVENTLIST_2nd((_nc_eventlist
*) 0));
if (code == ERR) {
break;
} else if (code == KEY_CODE_YES) {
/*
* If we were processing an incomplete multibyte character,
* return an error since we have a KEY_xxx code which
* interrupts it. For some cases, we could improve this by
* writing a new version of lib_getch.c(!), but it is not clear
* whether the improvement would be worth the effort.
*/
if (count != 0) {
safe_ungetch(SP_PARM, value);
code = ERR;
}
break;
} else if (count + 1 >= sizeof(buffer)) {
safe_ungetch(SP_PARM, value);
code = ERR;
break;
} else {
int status;
buffer[count++] = (char) UChar(value);
reset_mbytes(state);
status = count_mbytes(buffer, count, state);
if (status >= 0) {
wchar_t wch;
reset_mbytes(state);
if (check_mbytes(wch, buffer, count, state) != status) {
code = ERR; /* the two calls should match */
safe_ungetch(SP_PARM, value);
}
value = wch;
break;
}
}
}
} else {
code = ERR;
}
if (result != 0)
*result = (wint_t) value;
_nc_unlock_global(curses);
T(("result %#o", value));
returnCode(code);
}

233
third_party/ncurses/lib_get_wstr.c vendored Normal file
View file

@ -0,0 +1,233 @@
/****************************************************************************
* Copyright 2018-2020,2021 Thomas E. Dickey *
* Copyright 2002-2009,2011 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 *
****************************************************************************/
/*
** lib_get_wstr.c
**
** The routine wgetn_wstr().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_get_wstr.c,v 1.20 2021/10/23 19:02:59 tom Exp $")
static int
wadd_wint(WINDOW *win, wint_t *src)
{
cchar_t tmp;
wchar_t wch[2];
wch[0] = (wchar_t) (*src);
wch[1] = 0;
setcchar(&tmp, wch, A_NORMAL, (short) 0, NULL);
return wadd_wch(win, &tmp);
}
/*
* This wipes out the last character, no matter whether it was a tab, control
* or other character, and handles reverse wraparound.
*/
static wint_t *
WipeOut(WINDOW *win, int y, int x, wint_t *first, wint_t *last, int echoed)
{
if (last > first) {
*--last = '\0';
if (echoed) {
int y1 = win->_cury;
int x1 = win->_curx;
int n;
wmove(win, y, x);
for (n = 0; first[n] != 0; ++n) {
wadd_wint(win, first + n);
}
getyx(win, y, x);
while (win->_cury < y1
|| (win->_cury == y1 && win->_curx < x1))
waddch(win, (chtype) ' ');
wmove(win, y, x);
}
}
return last;
}
NCURSES_EXPORT(int)
wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
{
SCREEN *sp = _nc_screen_of(win);
TTY buf;
bool oldnl, oldecho, oldraw, oldcbreak;
wchar_t erasec = 0;
wchar_t killc = 0;
wint_t *oldstr = str;
wint_t *tmpstr = str;
wint_t ch;
int y, x, code;
T((T_CALLED("wgetn_wstr(%p,%p, %d)"), (void *) win, (void *) str, maxlen));
if (!win)
returnCode(ERR);
maxlen = _nc_getstr_limit(maxlen);
_nc_get_tty_mode(&buf);
oldnl = sp->_nl;
oldecho = sp->_echo;
oldraw = sp->_raw;
oldcbreak = sp->_cbreak;
NCURSES_SP_NAME(nl) (NCURSES_SP_ARG);
NCURSES_SP_NAME(noecho) (NCURSES_SP_ARG);
NCURSES_SP_NAME(raw) (NCURSES_SP_ARG);
NCURSES_SP_NAME(erasewchar) (NCURSES_SP_ARGx &erasec);
NCURSES_SP_NAME(killwchar) (NCURSES_SP_ARGx &killc);
getyx(win, y, x);
if (is_wintouched(win) || (win->_flags & _HASMOVED))
wrefresh(win);
while ((code = wget_wch(win, &ch)) != ERR) {
/*
* Map special characters into key-codes.
*/
if (ch == '\r')
ch = '\n';
if (ch == '\n') {
code = KEY_CODE_YES;
ch = KEY_ENTER;
}
if (ch != 0 && ch < KEY_MIN) {
if (ch == (wint_t) erasec) {
ch = KEY_BACKSPACE;
code = KEY_CODE_YES;
}
if (ch == (wint_t) killc) {
ch = KEY_EOL;
code = KEY_CODE_YES;
}
}
if (code == KEY_CODE_YES) {
/*
* Some terminals (the Wyse-50 is the most common) generate a \n
* from the down-arrow key. With this logic, it is the user's
* choice whether to set kcud=\n for wget_wch(); terminating
* *getn_wstr() with \n should work either way.
*/
if (ch == KEY_DOWN || ch == KEY_ENTER) {
if (oldecho == TRUE
&& win->_cury == win->_maxy
&& win->_scroll)
wechochar(win, (chtype) '\n');
break;
}
if (ch == KEY_LEFT || ch == KEY_BACKSPACE) {
if (tmpstr > oldstr) {
tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
}
} else if (ch == KEY_EOL) {
while (tmpstr > oldstr) {
tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
}
} else {
beep();
}
} else if (tmpstr - oldstr >= maxlen) {
beep();
} else {
*tmpstr++ = ch;
*tmpstr = 0;
if (oldecho == TRUE) {
int oldy = win->_cury;
if (wadd_wint(win, tmpstr - 1) == ERR) {
/*
* We can't really use the lower-right corner for input,
* since it'll mess up bookkeeping for erases.
*/
win->_flags &= ~_WRAPPED;
waddch(win, (chtype) ' ');
tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
continue;
} else if (IS_WRAPPED(win)) {
/*
* If the last waddch forced a wrap & scroll, adjust our
* reference point for erasures.
*/
if (win->_scroll
&& oldy == win->_maxy
&& win->_cury == win->_maxy) {
if (--y <= 0) {
y = 0;
}
}
win->_flags &= ~_WRAPPED;
}
wrefresh(win);
}
}
}
win->_curx = 0;
win->_flags &= ~_WRAPPED;
if (win->_cury < win->_maxy)
win->_cury++;
wrefresh(win);
/* Restore with a single I/O call, to fix minor asymmetry between
* raw/noraw, etc.
*/
sp->_nl = oldnl;
sp->_echo = oldecho;
sp->_raw = oldraw;
sp->_cbreak = oldcbreak;
(void) _nc_set_tty_mode(&buf);
*tmpstr = 0;
if (code == ERR) {
if (tmpstr == oldstr) {
*tmpstr++ = WEOF;
*tmpstr = 0;
}
returnCode(ERR);
}
T(("wgetn_wstr returns %s", _nc_viswibuf(oldstr)));
returnCode(OK);
}

802
third_party/ncurses/lib_getch.c vendored Normal file
View file

@ -0,0 +1,802 @@
/****************************************************************************
* Copyright 2018-2021,2022 Thomas E. Dickey *
* Copyright 1998-2015,2016 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-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
** lib_getch.c
**
** The routine getch().
**
*/
#define NEED_KEY_EVENT
#include "curses.priv.h"
MODULE_ID("$Id: lib_getch.c,v 1.145 2022/12/24 22:38:38 tom Exp $")
#include "fifo_defs.h"
#if USE_REENTRANT
#define GetEscdelay(sp) *_nc_ptr_Escdelay(sp)
NCURSES_EXPORT(int)
NCURSES_PUBLIC_VAR(ESCDELAY) (void)
{
return *(_nc_ptr_Escdelay(CURRENT_SCREEN));
}
NCURSES_EXPORT(int *)
_nc_ptr_Escdelay(SCREEN *sp)
{
return ptrEscdelay(sp);
}
#else
#define GetEscdelay(sp) ESCDELAY
NCURSES_EXPORT_VAR(int) ESCDELAY = 1000;
#endif
#if NCURSES_EXT_FUNCS
NCURSES_EXPORT(int)
NCURSES_SP_NAME(set_escdelay) (NCURSES_SP_DCLx int value)
{
int code = OK;
if (value < 0) {
code = ERR;
} else {
#if USE_REENTRANT
if (SP_PARM) {
SET_ESCDELAY(value);
} else {
code = ERR;
}
#else
(void) SP_PARM;
ESCDELAY = value;
#endif
}
return code;
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
set_escdelay(int value)
{
int code;
if (value < 0) {
code = ERR;
} else {
#if USE_REENTRANT
code = NCURSES_SP_NAME(set_escdelay) (CURRENT_SCREEN, value);
#else
ESCDELAY = value;
code = OK;
#endif
}
return code;
}
#endif
#endif /* NCURSES_EXT_FUNCS */
#if NCURSES_EXT_FUNCS
NCURSES_EXPORT(int)
NCURSES_SP_NAME(get_escdelay) (NCURSES_SP_DCL0)
{
#if !USE_REENTRANT
(void) SP_PARM;
#endif
return GetEscdelay(SP_PARM);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
get_escdelay(void)
{
return NCURSES_SP_NAME(get_escdelay) (CURRENT_SCREEN);
}
#endif
#endif /* NCURSES_EXT_FUNCS */
static int
_nc_use_meta(WINDOW *win)
{
SCREEN *sp = _nc_screen_of(win);
return (sp ? sp->_use_meta : 0);
}
#ifdef USE_TERM_DRIVER
# if defined(_NC_WINDOWS) && !defined(EXP_WIN32_DRIVER)
static HANDLE
_nc_get_handle(int fd)
{
intptr_t value = _get_osfhandle(fd);
return (HANDLE) value;
}
# endif
#endif
/*
* Check for mouse activity, returning nonzero if we find any.
*/
static int
check_mouse_activity(SCREEN *sp, int delay EVENTLIST_2nd(_nc_eventlist * evl))
{
int rc;
#ifdef USE_TERM_DRIVER
TERMINAL_CONTROL_BLOCK *TCB = TCBOf(sp);
rc = TCBOf(sp)->drv->td_testmouse(TCBOf(sp), delay EVENTLIST_2nd(evl));
# if defined(EXP_WIN32_DRIVER)
/* if we emulate terminfo on console, we have to use the console routine */
if (IsTermInfoOnConsole(sp)) {
rc = _nc_console_testmouse(sp,
_nc_console_handle(sp->_ifd),
delay EVENTLIST_2nd(evl));
} else
# elif defined(_NC_WINDOWS)
/* if we emulate terminfo on console, we have to use the console routine */
if (IsTermInfoOnConsole(sp)) {
HANDLE fd = _nc_get_handle(sp->_ifd);
rc = _nc_mingw_testmouse(sp, fd, delay EVENTLIST_2nd(evl));
} else
# endif
rc = TCB->drv->td_testmouse(TCB, delay EVENTLIST_2nd(evl));
#else /* !USE_TERM_DRIVER */
# if USE_SYSMOUSE
if ((sp->_mouse_type == M_SYSMOUSE)
&& (sp->_sysmouse_head < sp->_sysmouse_tail)) {
rc = TW_MOUSE;
} else
# endif
{
# if defined(EXP_WIN32_DRIVER)
rc = _nc_console_testmouse(sp,
_nc_console_handle(sp->_ifd),
delay
EVENTLIST_2nd(evl));
# else
rc = _nc_timed_wait(sp,
TWAIT_MASK,
delay,
(int *) 0
EVENTLIST_2nd(evl));
# endif
# if USE_SYSMOUSE
if ((sp->_mouse_type == M_SYSMOUSE)
&& (sp->_sysmouse_head < sp->_sysmouse_tail)
&& (rc == 0)
&& (errno == EINTR)) {
rc |= TW_MOUSE;
}
# endif
}
#endif /* USE_TERM_DRIVER */
return rc;
}
static NCURSES_INLINE int
fifo_peek(SCREEN *sp)
{
int ch = (peek >= 0) ? sp->_fifo[peek] : ERR;
TR(TRACE_IEVENT, ("peeking at %d", peek));
p_inc();
return ch;
}
static NCURSES_INLINE int
fifo_pull(SCREEN *sp)
{
int ch = (head >= 0) ? sp->_fifo[head] : ERR;
TR(TRACE_IEVENT, ("pulling %s from %d", _nc_tracechar(sp, ch), head));
if (peek == head) {
h_inc();
peek = head;
} else {
h_inc();
}
#ifdef TRACE
if (USE_TRACEF(TRACE_IEVENT)) {
_nc_fifo_dump(sp);
_nc_unlock_global(tracef);
}
#endif
return ch;
}
static NCURSES_INLINE int
fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
{
int n;
int ch = 0;
int mask = 0;
(void) mask;
if (tail < 0)
return ERR;
#ifdef NCURSES_WGETCH_EVENTS
if (evl
#if USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE
|| (sp->_mouse_fd >= 0)
#endif
) {
mask = check_mouse_activity(sp, -1 EVENTLIST_2nd(evl));
} else
mask = 0;
if (mask & TW_EVENT) {
T(("fifo_push: ungetch KEY_EVENT"));
safe_ungetch(sp, KEY_EVENT);
return KEY_EVENT;
}
#elif USE_GPM_SUPPORT || USE_EMX_MOUSE || USE_SYSMOUSE
if (sp->_mouse_fd >= 0) {
mask = check_mouse_activity(sp, -1 EVENTLIST_2nd(evl));
}
#endif
#if USE_GPM_SUPPORT || USE_EMX_MOUSE
if ((sp->_mouse_fd >= 0) && (mask & TW_MOUSE)) {
sp->_mouse_event(sp);
ch = KEY_MOUSE;
n = 1;
} else
#endif
#if USE_SYSMOUSE
if ((sp->_mouse_type == M_SYSMOUSE)
&& (sp->_sysmouse_head < sp->_sysmouse_tail)) {
sp->_mouse_event(sp);
ch = KEY_MOUSE;
n = 1;
} else if ((sp->_mouse_type == M_SYSMOUSE)
&& (mask <= 0) && errno == EINTR) {
sp->_mouse_event(sp);
ch = KEY_MOUSE;
n = 1;
} else
#endif
#ifdef USE_TERM_DRIVER
if ((sp->_mouse_type == M_TERM_DRIVER)
&& (sp->_drv_mouse_head < sp->_drv_mouse_tail)) {
sp->_mouse_event(sp);
ch = KEY_MOUSE;
n = 1;
} else
#endif
#if USE_KLIBC_KBD
if (NC_ISATTY(sp->_ifd) && sp->_cbreak) {
ch = _read_kbd(0, 1, !sp->_raw);
n = (ch == -1) ? -1 : 1;
sp->_extended_key = (ch == 0);
} else
#endif
{ /* Can block... */
#if defined(USE_TERM_DRIVER)
int buf;
# if defined(EXP_WIN32_DRIVER)
if (NC_ISATTY(sp->_ifd) && IsTermInfoOnConsole(sp) && sp->_cbreak) {
_nc_set_read_thread(TRUE);
n = _nc_console_read(sp,
_nc_console_handle(sp->_ifd),
&buf);
_nc_set_read_thread(FALSE);
} else
# elif defined(_NC_WINDOWS)
if (NC_ISATTY(sp->_ifd) && IsTermInfoOnConsole(sp) && sp->_cbreak)
n = _nc_mingw_console_read(sp,
_nc_get_handle(sp->_ifd),
&buf);
else
# endif /* EXP_WIN32_DRIVER */
n = CallDriver_1(sp, td_read, &buf);
ch = buf;
#else /* !USE_TERM_DRIVER */
#if defined(EXP_WIN32_DRIVER)
int buf;
#endif
unsigned char c2 = 0;
_nc_set_read_thread(TRUE);
#if defined(EXP_WIN32_DRIVER)
n = _nc_console_read(sp,
_nc_console_handle(sp->_ifd),
&buf);
c2 = buf;
#else
n = (int) read(sp->_ifd, &c2, (size_t) 1);
#endif
_nc_set_read_thread(FALSE);
ch = c2;
#endif /* USE_TERM_DRIVER */
}
if ((n == -1) || (n == 0)) {
TR(TRACE_IEVENT, ("read(%d,&ch,1)=%d, errno=%d", sp->_ifd, n, errno));
ch = ERR;
}
TR(TRACE_IEVENT, ("read %d characters", n));
sp->_fifo[tail] = ch;
sp->_fifohold = 0;
if (head == -1)
head = peek = tail;
t_inc();
TR(TRACE_IEVENT, ("pushed %s at %d", _nc_tracechar(sp, ch), tail));
#ifdef TRACE
if (USE_TRACEF(TRACE_IEVENT)) {
_nc_fifo_dump(sp);
_nc_unlock_global(tracef);
}
#endif
return ch;
}
static NCURSES_INLINE void
fifo_clear(SCREEN *sp)
{
memset(sp->_fifo, 0, sizeof(sp->_fifo));
head = -1;
tail = peek = 0;
}
static int kgetch(SCREEN *, bool EVENTLIST_2nd(_nc_eventlist *));
static void
recur_wrefresh(WINDOW *win)
{
#ifdef USE_PTHREADS
SCREEN *sp = _nc_screen_of(win);
bool same_sp;
if (_nc_use_pthreads) {
_nc_lock_global(curses);
same_sp = (sp == CURRENT_SCREEN);
_nc_unlock_global(curses);
} else {
same_sp = (sp == CURRENT_SCREEN);
}
if (_nc_use_pthreads && !same_sp) {
SCREEN *save_SP;
/* temporarily switch to the window's screen to check/refresh */
_nc_lock_global(curses);
save_SP = CURRENT_SCREEN;
_nc_set_screen(sp);
recur_wrefresh(win);
_nc_set_screen(save_SP);
_nc_unlock_global(curses);
} else
#endif
if ((is_wintouched(win) || (win->_flags & _HASMOVED))
&& !IS_PAD(win)) {
wrefresh(win);
}
}
static int
recur_wgetnstr(WINDOW *win, char *buf)
{
SCREEN *sp = _nc_screen_of(win);
int rc;
if (sp != 0) {
#ifdef USE_PTHREADS
if (_nc_use_pthreads && sp != CURRENT_SCREEN) {
SCREEN *save_SP;
/* temporarily switch to the window's screen to get cooked input */
_nc_lock_global(curses);
save_SP = CURRENT_SCREEN;
_nc_set_screen(sp);
rc = recur_wgetnstr(win, buf);
_nc_set_screen(save_SP);
_nc_unlock_global(curses);
} else
#endif
{
sp->_called_wgetch = TRUE;
rc = wgetnstr(win, buf, MAXCOLUMNS);
sp->_called_wgetch = FALSE;
}
} else {
rc = ERR;
}
return rc;
}
NCURSES_EXPORT(int)
_nc_wgetch(WINDOW *win,
int *result,
int use_meta
EVENTLIST_2nd(_nc_eventlist * evl))
{
SCREEN *sp;
int ch;
int rc = 0;
#ifdef NCURSES_WGETCH_EVENTS
int event_delay = -1;
#endif
T((T_CALLED("_nc_wgetch(%p)"), (void *) win));
*result = 0;
sp = _nc_screen_of(win);
if (win == 0 || sp == 0) {
returnCode(ERR);
}
if (cooked_key_in_fifo()) {
recur_wrefresh(win);
*result = fifo_pull(sp);
returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK);
}
#ifdef NCURSES_WGETCH_EVENTS
if (evl && (evl->count == 0))
evl = NULL;
event_delay = _nc_eventlist_timeout(evl);
#endif
/*
* Handle cooked mode. Grab a string from the screen,
* stuff its contents in the FIFO queue, and pop off
* the first character to return it.
*/
if (head == -1 &&
!sp->_notty &&
!sp->_raw &&
!sp->_cbreak &&
!sp->_called_wgetch) {
char buf[MAXCOLUMNS], *bufp;
TR(TRACE_IEVENT, ("filling queue in cooked mode"));
/* ungetch in reverse order */
#ifdef NCURSES_WGETCH_EVENTS
rc = recur_wgetnstr(win, buf);
if (rc != KEY_EVENT && rc != ERR)
safe_ungetch(sp, '\n');
#else
if (recur_wgetnstr(win, buf) != ERR)
safe_ungetch(sp, '\n');
#endif
for (bufp = buf + strlen(buf); bufp > buf; bufp--)
safe_ungetch(sp, bufp[-1]);
#ifdef NCURSES_WGETCH_EVENTS
/* Return it first */
if (rc == KEY_EVENT) {
*result = rc;
} else
#endif
*result = fifo_pull(sp);
returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK);
}
if (win->_use_keypad != sp->_keypad_on)
_nc_keypad(sp, win->_use_keypad);
recur_wrefresh(win);
if (win->_notimeout || (win->_delay >= 0) || (sp->_cbreak > 1)) {
if (head == -1) { /* fifo is empty */
int delay;
TR(TRACE_IEVENT, ("timed delay in wgetch()"));
if (sp->_cbreak > 1)
delay = (sp->_cbreak - 1) * 100;
else
delay = win->_delay;
#ifdef NCURSES_WGETCH_EVENTS
if (event_delay >= 0 && delay > event_delay)
delay = event_delay;
#endif
TR(TRACE_IEVENT, ("delay is %d milliseconds", delay));
rc = check_mouse_activity(sp, delay EVENTLIST_2nd(evl));
#ifdef NCURSES_WGETCH_EVENTS
if (rc & TW_EVENT) {
*result = KEY_EVENT;
returnCode(KEY_CODE_YES);
}
#endif
if (!rc) {
goto check_sigwinch;
}
}
/* else go on to read data available */
}
if (win->_use_keypad) {
/*
* This is tricky. We only want to get special-key
* events one at a time. But we want to accumulate
* mouse events until either (a) the mouse logic tells
* us it has picked up a complete gesture, or (b)
* there's a detectable time lapse after one.
*
* Note: if the mouse code starts failing to compose
* press/release events into clicks, you should probably
* increase the wait with mouseinterval().
*/
int runcount = 0;
do {
ch = kgetch(sp, win->_notimeout EVENTLIST_2nd(evl));
if (ch == KEY_MOUSE) {
++runcount;
if (sp->_mouse_inline(sp))
break;
}
if (sp->_maxclick < 0)
break;
} while
(ch == KEY_MOUSE
&& (((rc = check_mouse_activity(sp, sp->_maxclick
EVENTLIST_2nd(evl))) != 0
&& !(rc & TW_EVENT))
|| !sp->_mouse_parse(sp, runcount)));
#ifdef NCURSES_WGETCH_EVENTS
if ((rc & TW_EVENT) && !(ch == KEY_EVENT)) {
safe_ungetch(sp, ch);
ch = KEY_EVENT;
}
#endif
if (runcount > 0 && ch != KEY_MOUSE) {
#ifdef NCURSES_WGETCH_EVENTS
/* mouse event sequence ended by an event, report event */
if (ch == KEY_EVENT) {
safe_ungetch(sp, KEY_MOUSE); /* FIXME This interrupts a gesture... */
} else
#endif
{
/* mouse event sequence ended by keystroke, store keystroke */
safe_ungetch(sp, ch);
ch = KEY_MOUSE;
}
}
} else {
if (head == -1)
fifo_push(sp EVENTLIST_2nd(evl));
ch = fifo_pull(sp);
}
if (ch == ERR) {
check_sigwinch:
#if USE_SIZECHANGE
if (_nc_handle_sigwinch(sp)) {
_nc_update_screensize(sp);
/* resizeterm can push KEY_RESIZE */
if (cooked_key_in_fifo()) {
*result = fifo_pull(sp);
/*
* Get the ERR from queue -- it is from WINCH,
* so we should take it out, the "error" is handled.
*/
if (fifo_peek(sp) == -1)
fifo_pull(sp);
returnCode(*result >= KEY_MIN ? KEY_CODE_YES : OK);
}
}
#endif
returnCode(ERR);
}
/*
* If echo() is in effect, display the printable version of the
* key on the screen. Carriage return and backspace are treated
* specially by Solaris curses:
*
* If carriage return is defined as a function key in the
* terminfo, e.g., kent, then Solaris may return either ^J (or ^M
* if nonl() is set) or KEY_ENTER depending on the echo() mode.
* We echo before translating carriage return based on nonl(),
* since the visual result simply moves the cursor to column 0.
*
* Backspace is a different matter. Solaris curses does not
* translate it to KEY_BACKSPACE if kbs=^H. This does not depend
* on the stty modes, but appears to be a hardcoded special case.
* This is a difference from ncurses, which uses the terminfo entry.
* However, we provide the same visual result as Solaris, moving the
* cursor to the left.
*/
if (sp->_echo && !IS_PAD(win)) {
chtype backup = (chtype) ((ch == KEY_BACKSPACE) ? '\b' : ch);
if (backup < KEY_MIN)
wechochar(win, backup);
}
/*
* Simulate ICRNL mode
*/
if ((ch == '\r') && sp->_nl)
ch = '\n';
/* Strip 8th-bit if so desired. We do this only for characters that
* are in the range 128-255, to provide compatibility with terminals
* that display only 7-bit characters. Note that 'ch' may be a
* function key at this point, so we mustn't strip _those_.
*/
if (!use_meta)
if ((ch < KEY_MIN) && (ch & 0x80))
ch &= 0x7f;
T(("wgetch returning : %s", _nc_tracechar(sp, ch)));
*result = ch;
returnCode(ch >= KEY_MIN ? KEY_CODE_YES : OK);
}
#ifdef NCURSES_WGETCH_EVENTS
NCURSES_EXPORT(int)
wgetch_events(WINDOW *win, _nc_eventlist * evl)
{
int code;
int value;
T((T_CALLED("wgetch_events(%p,%p)"), (void *) win, (void *) evl));
code = _nc_wgetch(win,
&value,
_nc_use_meta(win)
EVENTLIST_2nd(evl));
if (code != ERR)
code = value;
returnCode(code);
}
#endif
NCURSES_EXPORT(int)
wgetch(WINDOW *win)
{
int code;
int value;
T((T_CALLED("wgetch(%p)"), (void *) win));
code = _nc_wgetch(win,
&value,
_nc_use_meta(win)
EVENTLIST_2nd((_nc_eventlist *) 0));
if (code != ERR)
code = value;
returnCode(code);
}
/*
** int
** kgetch()
**
** Get an input character, but take care of keypad sequences, returning
** an appropriate code when one matches the input. After each character
** is received, set an alarm call based on ESCDELAY. If no more of the
** sequence is received by the time the alarm goes off, pass through
** the sequence gotten so far.
**
** This function must be called when there are no cooked keys in queue.
** (that is head==-1 || peek==head)
**
*/
static int
kgetch(SCREEN *sp, bool forever EVENTLIST_2nd(_nc_eventlist * evl))
{
TRIES *ptr;
int ch = 0;
int timeleft = forever ? 9999999 : GetEscdelay(sp);
TR(TRACE_IEVENT, ("kgetch() called"));
ptr = sp->_keytry;
for (;;) {
if (cooked_key_in_fifo() && sp->_fifo[head] >= KEY_MIN) {
break;
} else if (!raw_key_in_fifo()) {
ch = fifo_push(sp EVENTLIST_2nd(evl));
if (ch == ERR) {
peek = head; /* the keys stay uninterpreted */
return ERR;
}
#ifdef NCURSES_WGETCH_EVENTS
else if (ch == KEY_EVENT) {
peek = head; /* the keys stay uninterpreted */
return fifo_pull(sp); /* Remove KEY_EVENT from the queue */
}
#endif
}
ch = fifo_peek(sp);
if (ch >= KEY_MIN) {
/* If not first in queue, somebody put this key there on purpose in
* emergency. Consider it higher priority than the unfinished
* keysequence we are parsing.
*/
peek = head;
/* assume the key is the last in fifo */
t_dec(); /* remove the key */
return ch;
}
TR(TRACE_IEVENT, ("ch: %s", _nc_tracechar(sp, (unsigned char) ch)));
while ((ptr != NULL) && (ptr->ch != (unsigned char) ch))
ptr = ptr->sibling;
if (ptr == NULL) {
TR(TRACE_IEVENT, ("ptr is null"));
break;
}
TR(TRACE_IEVENT, ("ptr=%p, ch=%d, value=%d",
(void *) ptr, ptr->ch, ptr->value));
if (ptr->value != 0) { /* sequence terminated */
TR(TRACE_IEVENT, ("end of sequence"));
if (peek == tail) {
fifo_clear(sp);
} else {
head = peek;
}
return (ptr->value);
}
ptr = ptr->child;
if (!raw_key_in_fifo()) {
int rc;
TR(TRACE_IEVENT, ("waiting for rest of sequence"));
rc = check_mouse_activity(sp, timeleft EVENTLIST_2nd(evl));
#ifdef NCURSES_WGETCH_EVENTS
if (rc & TW_EVENT) {
TR(TRACE_IEVENT, ("interrupted by a user event"));
/* FIXME Should have preserved remainder timeleft for reuse... */
peek = head; /* Restart interpreting later */
return KEY_EVENT;
}
#endif
if (!rc) {
TR(TRACE_IEVENT, ("ran out of time"));
break;
}
}
}
ch = fifo_pull(sp);
peek = head;
return ch;
}

227
third_party/ncurses/lib_getstr.c vendored Normal file
View file

@ -0,0 +1,227 @@
/****************************************************************************
* Copyright 2018-2020,2021 Thomas E. Dickey *
* Copyright 1998-2011,2017 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> *
****************************************************************************/
/*
** lib_getstr.c
**
** The routine wgetstr().
**
*/
#define NEED_KEY_EVENT
#include "curses.priv.h"
MODULE_ID("$Id: lib_getstr.c,v 1.38 2021/10/23 19:02:39 tom Exp $")
/*
* This wipes out the last character, no matter whether it was a tab, control
* or other character, and handles reverse wraparound.
*/
static char *
WipeOut(WINDOW *win, int y, int x, char *first, char *last, int echoed)
{
if (last > first) {
*--last = '\0';
if (echoed) {
int y1 = win->_cury;
int x1 = win->_curx;
wmove(win, y, x);
waddstr(win, first);
getyx(win, y, x);
while (win->_cury < y1
|| (win->_cury == y1 && win->_curx < x1))
waddch(win, (chtype) ' ');
wmove(win, y, x);
}
}
return last;
}
NCURSES_EXPORT(int)
wgetnstr_events(WINDOW *win,
char *str,
int maxlen,
EVENTLIST_1st(_nc_eventlist * evl))
{
SCREEN *sp = _nc_screen_of(win);
TTY buf;
bool oldnl, oldecho, oldraw, oldcbreak;
char erasec;
char killc;
char *oldstr;
int ch;
int y, x;
T((T_CALLED("wgetnstr(%p,%p,%d)"), (void *) win, (void *) str, maxlen));
if (!win || !str)
returnCode(ERR);
maxlen = _nc_getstr_limit(maxlen);
NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_ARGx &buf);
oldnl = sp->_nl;
oldecho = sp->_echo;
oldraw = sp->_raw;
oldcbreak = sp->_cbreak;
NCURSES_SP_NAME(nl) (NCURSES_SP_ARG);
NCURSES_SP_NAME(noecho) (NCURSES_SP_ARG);
NCURSES_SP_NAME(raw) (NCURSES_SP_ARG);
erasec = NCURSES_SP_NAME(erasechar) (NCURSES_SP_ARG);
killc = NCURSES_SP_NAME(killchar) (NCURSES_SP_ARG);
oldstr = str;
getyx(win, y, x);
if (is_wintouched(win) || (win->_flags & _HASMOVED))
wrefresh(win);
while ((ch = wgetch_events(win, evl)) != ERR) {
/*
* Some terminals (the Wyse-50 is the most common) generate
* a \n from the down-arrow key. With this logic, it is the
* user's choice whether to set kcud=\n for wgetch();
* terminating *getstr() with \n should work either way.
*/
if (ch == '\n'
|| ch == '\r'
|| ch == KEY_DOWN
|| ch == KEY_ENTER) {
if (oldecho == TRUE
&& win->_cury == win->_maxy
&& win->_scroll)
wechochar(win, (chtype) '\n');
break;
}
#ifdef KEY_EVENT
if (ch == KEY_EVENT)
break;
#endif
#ifdef KEY_RESIZE
if (ch == KEY_RESIZE)
break;
#endif
if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
if (str > oldstr) {
str = WipeOut(win, y, x, oldstr, str, oldecho);
}
} else if (ch == killc) {
while (str > oldstr) {
str = WipeOut(win, y, x, oldstr, str, oldecho);
}
} else if (ch >= KEY_MIN
|| (str - oldstr >= maxlen)) {
NCURSES_SP_NAME(beep) (NCURSES_SP_ARG);
} else {
*str++ = (char) ch;
if (oldecho == TRUE) {
int oldy = win->_cury;
if (waddch(win, (chtype) ch) == ERR) {
/*
* We can't really use the lower-right
* corner for input, since it'll mess
* up bookkeeping for erases.
*/
win->_flags &= ~_WRAPPED;
waddch(win, (chtype) ' ');
str = WipeOut(win, y, x, oldstr, str, oldecho);
continue;
} else if (IS_WRAPPED(win)) {
/*
* If the last waddch forced a wrap &
* scroll, adjust our reference point
* for erasures.
*/
if (win->_scroll
&& oldy == win->_maxy
&& win->_cury == win->_maxy) {
if (--y <= 0) {
y = 0;
}
}
win->_flags &= ~_WRAPPED;
}
wrefresh(win);
}
}
}
win->_curx = 0;
win->_flags &= ~_WRAPPED;
if (win->_cury < win->_maxy)
win->_cury++;
wrefresh(win);
/* Restore with a single I/O call, to fix minor asymmetry between
* raw/noraw, etc.
*/
sp->_nl = oldnl;
sp->_echo = oldecho;
sp->_raw = oldraw;
sp->_cbreak = oldcbreak;
NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
*str = '\0';
if (ch == ERR)
returnCode(ch);
T(("wgetnstr returns %s", _nc_visbuf(oldstr)));
#ifdef KEY_EVENT
if (ch == KEY_EVENT)
returnCode(ch);
#endif
#ifdef KEY_RESIZE
if (ch == KEY_RESIZE)
returnCode(ch);
#endif
returnCode(OK);
}
#ifdef NCURSES_WGETCH_EVENTS
NCURSES_EXPORT(int)
wgetnstr(WINDOW *win, char *str, int maxlen)
{
returnCode(wgetnstr_events(win,
str,
maxlen,
EVENTLIST_1st((_nc_eventlist *) 0)));
}
#endif

95
third_party/ncurses/lib_has_cap.c vendored Normal file
View file

@ -0,0 +1,95 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2009,2013 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 *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
** lib_has_cap.c
**
** The routines to query terminal capabilities
**
*/
#include "curses.priv.h"
#ifndef CUR
#define CUR SP_TERMTYPE
#endif
MODULE_ID("$Id: lib_has_cap.c,v 1.11 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(bool)
NCURSES_SP_NAME(has_ic) (NCURSES_SP_DCL0)
{
bool code = FALSE;
T((T_CALLED("has_ic(%p)"), (void *) SP_PARM));
if (HasTInfoTerminal(SP_PARM)) {
code = ((insert_character || parm_ich
|| (enter_insert_mode && exit_insert_mode))
&& (delete_character || parm_dch)) ? TRUE : FALSE;
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(bool)
has_ic(void)
{
return NCURSES_SP_NAME(has_ic) (CURRENT_SCREEN);
}
#endif
NCURSES_EXPORT(bool)
NCURSES_SP_NAME(has_il) (NCURSES_SP_DCL0)
{
bool code = FALSE;
T((T_CALLED("has_il(%p)"), (void *) SP_PARM));
if (HasTInfoTerminal(SP_PARM)) {
code = ((insert_line || parm_insert_line)
&& (delete_line || parm_delete_line)) ? TRUE : FALSE;
}
returnCode(code);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(bool)
has_il(void)
{
return NCURSES_SP_NAME(has_il) (CURRENT_SCREEN);
}
#endif

89
third_party/ncurses/lib_hline.c vendored Normal file
View file

@ -0,0 +1,89 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2016,2017 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-on *
* and: Sven Verdoolaege 2001 *
****************************************************************************/
/*
** lib_hline.c
**
** The routine whline().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_hline.c,v 1.16 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
whline(WINDOW *win, chtype ch, int n)
{
int code = ERR;
T((T_CALLED("whline(%p,%s,%d)"), (void *) win, _tracechtype(ch), n));
if (win) {
struct ldat *line = &(win->_line[win->_cury]);
NCURSES_CH_T wch;
int start = win->_curx;
int end = start + n - 1;
if (end > win->_maxx)
end = win->_maxx;
CHANGED_RANGE(line, start, end);
if (ch == 0)
SetChar2(wch, ACS_HLINE);
else
SetChar2(wch, ch);
wch = _nc_render(win, wch);
#if USE_WIDEC_SUPPORT
if (start > 0 && isWidecExt(line->text[start])) {
SetChar2(line->text[start - 1], ' ');
}
if (end < win->_maxx && isWidecExt(line->text[end + 1])) {
SetChar2(line->text[end + 1], ' ');
}
#endif
while (end >= start) {
line->text[end] = wch;
end--;
}
_nc_synchook(win);
code = OK;
}
returnCode(code);
}

78
third_party/ncurses/lib_hline_set.c vendored Normal file
View file

@ -0,0 +1,78 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 2002-2010,2016 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 Dickey 2002 *
****************************************************************************/
/*
** lib_hline_set.c
**
** The routine whline_set().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_hline_set.c,v 1.6 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
whline_set(WINDOW *win, const cchar_t *ch, int n)
{
int code = ERR;
T((T_CALLED("whline_set(%p,%s,%d)"), (void *) win, _tracecchar_t(ch), n));
if (win) {
struct ldat *line = &(win->_line[win->_cury]);
NCURSES_CH_T wch;
int start = win->_curx;
int end = start + n - 1;
if (end > win->_maxx)
end = win->_maxx;
CHANGED_RANGE(line, start, end);
if (ch == 0)
wch = *WACS_HLINE;
else
wch = *ch;
wch = _nc_render(win, wch);
while (end >= start) {
line->text[end] = wch;
end--;
}
_nc_synchook(win);
code = OK;
}
returnCode(code);
}

55
third_party/ncurses/lib_immedok.c vendored Normal file
View file

@ -0,0 +1,55 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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> *
****************************************************************************/
/*
** lib_immedok.c
**
** The routine immedok.
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_immedok.c,v 1.6 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(void)
immedok(WINDOW *win, bool flag)
{
T((T_CALLED("immedok(%p,%d)"), (void *) win, flag));
if (win)
win->_immed = flag;
returnVoid;
}

65
third_party/ncurses/lib_in_wch.c vendored Normal file
View file

@ -0,0 +1,65 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 2002-2009,2016 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 Dickey *
****************************************************************************/
/*
** lib_in_wch.c
**
** The routine win_wch().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_in_wch.c,v 1.7 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
win_wch(WINDOW *win, cchar_t *wcval)
{
int code = OK;
TR(TRACE_CCALLS, (T_CALLED("win_wch(%p,%p)"), (void *) win, (void *) wcval));
if (win != 0
&& wcval != 0) {
int row, col;
getyx(win, row, col);
*wcval = win->_line[row].text[col];
TR(TRACE_CCALLS, ("data %s", _tracecchar_t(wcval)));
} else {
code = ERR;
}
TR(TRACE_CCALLS, (T_RETURN("%d"), code));
return (code);
}

77
third_party/ncurses/lib_in_wchnstr.c vendored Normal file
View file

@ -0,0 +1,77 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 2002-2007,2009 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 Dickey *
****************************************************************************/
/*
** lib_in_wchnstr.c
**
** The routine win_wchnstr().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_in_wchnstr.c,v 1.9 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
win_wchnstr(WINDOW *win, cchar_t *wchstr, int n)
{
int code = OK;
T((T_CALLED("win_wchnstr(%p,%p,%d)"), (void *) win, (void *) wchstr, n));
if (win != 0
&& wchstr != 0) {
NCURSES_CH_T *src;
int row, col;
int j, k, limit;
getyx(win, row, col);
limit = getmaxx(win) - col;
src = &(win->_line[row].text[col]);
if (n < 0) {
n = limit;
} else if (n > limit) {
n = limit;
}
for (j = k = 0; j < n; ++j) {
if (j == 0 || !WidecExt(src[j]) || isWidecBase(src[j])) {
wchstr[k++] = src[j];
}
}
memset(&(wchstr[k]), 0, sizeof(*wchstr));
T(("result = %s", _nc_viscbuf(wchstr, n)));
} else {
code = ERR;
}
returnCode(code);
}

69
third_party/ncurses/lib_inchstr.c vendored Normal file
View file

@ -0,0 +1,69 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2010,2017 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-on *
****************************************************************************/
/*
** lib_inchstr.c
**
** The routine winchnstr().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_inchstr.c,v 1.17 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
winchnstr(WINDOW *win, chtype *str, int n)
{
int i = 0;
T((T_CALLED("winchnstr(%p,%p,%d)"), (void *) win, (void *) str, n));
if (!win || !str) {
i = ERR;
} else {
int row = win->_cury;
int col = win->_curx;
NCURSES_CH_T *text = win->_line[row].text;
for (; (n < 0 || (i < n)) && (col + i <= win->_maxx); i++) {
str[i] = (((chtype) CharOf(text[col + i]) & A_CHARTEXT) |
AttrOf(text[col + i]));
}
str[i] = (chtype) 0;
}
returnCode(i);
}

110
third_party/ncurses/lib_initscr.c vendored Normal file
View file

@ -0,0 +1,110 @@
/****************************************************************************
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 1998-2016,2017 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-on *
****************************************************************************/
/*
** lib_initscr.c
**
** The routines initscr(), and termname().
**
*/
#include "curses.priv.h"
#if HAVE_SYS_TERMIO_H
#include <sys/termio.h> /* needed for ISC */
#endif
MODULE_ID("$Id: lib_initscr.c,v 1.48 2020/09/07 14:26:48 tom Exp $")
NCURSES_EXPORT(WINDOW *)
initscr(void)
{
WINDOW *result;
START_TRACE();
T((T_CALLED("initscr()")));
_nc_init_pthreads();
_nc_lock_global(curses);
/* Portable applications must not call initscr() more than once */
if (!_nc_globals.init_screen) {
const char *env;
char *name;
_nc_globals.init_screen = TRUE;
env = getenv("TERM");
(void) VALID_TERM_ENV(env, "unknown");
if ((name = strdup(env)) == NULL) {
fprintf(stderr, "Error opening allocating $TERM.\n");
ExitProgram(EXIT_FAILURE);
}
#ifdef __CYGWIN__
/*
* 2002/9/21
* Work around a bug in Cygwin. Full-screen subprocesses run from
* bash, in turn spawned from another full-screen process, will dump
* core when attempting to write to stdout. Opening /dev/tty
* explicitly seems to fix the problem.
*/
if (NC_ISATTY(fileno(stdout))) {
FILE *fp = fopen("/dev/tty", "w");
if (fp != 0 && NC_ISATTY(fileno(fp))) {
fclose(stdout);
dup2(fileno(fp), STDOUT_FILENO);
stdout = fdopen(STDOUT_FILENO, "w");
}
}
#endif
if (newterm(name, stdout, stdin) == 0) {
fprintf(stderr, "Error opening terminal: %s.\n", name);
ExitProgram(EXIT_FAILURE);
}
/* def_shell_mode - done in newterm/_nc_setupscreen */
#if NCURSES_SP_FUNCS
NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
#else
def_prog_mode();
#endif
free(name);
}
result = stdscr;
_nc_unlock_global(curses);
returnWin(result);
}

150
third_party/ncurses/lib_ins_wch.c vendored Normal file
View file

@ -0,0 +1,150 @@
/****************************************************************************
* Copyright 2019,2020 Thomas E. Dickey *
* Copyright 2002-2016,2017 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 Dickey 2002 *
****************************************************************************/
/*
** lib_ins_wch.c
**
** The routine wins_wch().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_ins_wch.c,v 1.25 2020/12/05 20:04:59 tom Exp $")
/*
* Insert the given character, updating the current location to simplify
* inserting a string.
*/
NCURSES_EXPORT(int)
_nc_insert_wch(WINDOW *win, const cchar_t *wch)
{
int cells = _nc_wacs_width(CharOf(CHDEREF(wch)));
int code = OK;
if (cells < 0) {
code = winsch(win, (chtype) CharOf(CHDEREF(wch)));
} else {
if (cells == 0)
cells = 1;
if (win->_curx <= win->_maxx) {
int cell;
struct ldat *line = &(win->_line[win->_cury]);
NCURSES_CH_T *end = &(line->text[win->_curx]);
NCURSES_CH_T *temp1 = &(line->text[win->_maxx]);
NCURSES_CH_T *temp2 = temp1 - cells;
CHANGED_TO_EOL(line, win->_curx, win->_maxx);
while (temp1 > end)
*temp1-- = *temp2--;
*temp1 = _nc_render(win, *wch);
for (cell = 1; cell < cells; ++cell) {
SetWidecExt(temp1[cell], cell);
}
win->_curx = (NCURSES_SIZE_T) (win->_curx + cells);
}
}
return code;
}
NCURSES_EXPORT(int)
wins_wch(WINDOW *win, const cchar_t *wch)
{
int code = ERR;
T((T_CALLED("wins_wch(%p, %s)"), (void *) win, _tracecchar_t(wch)));
if (win != 0) {
NCURSES_SIZE_T oy = win->_cury;
NCURSES_SIZE_T ox = win->_curx;
code = _nc_insert_wch(win, wch);
win->_curx = ox;
win->_cury = oy;
_nc_synchook(win);
}
returnCode(code);
}
NCURSES_EXPORT(int)
wins_nwstr(WINDOW *win, const wchar_t *wstr, int n)
{
int code = ERR;
T((T_CALLED("wins_nwstr(%p,%s,%d)"),
(void *) win, _nc_viswbufn(wstr, n), n));
if (win != 0
&& wstr != 0) {
if (n < 1)
n = INT_MAX;
code = OK;
if (n > 0) {
const wchar_t *cp;
SCREEN *sp = _nc_screen_of(win);
NCURSES_SIZE_T oy = win->_cury;
NCURSES_SIZE_T ox = win->_curx;
for (cp = wstr; (*cp != L'\0') && ((cp - wstr) < n); cp++) {
int len = _nc_wacs_width(*cp);
if ((len >= 0 && len != 1) || !is7bits(*cp)) {
cchar_t tmp_cchar;
wchar_t tmp_wchar = *cp;
memset(&tmp_cchar, 0, sizeof(tmp_cchar));
(void) setcchar(&tmp_cchar,
&tmp_wchar,
WA_NORMAL,
(short) 0,
(void *) 0);
code = _nc_insert_wch(win, &tmp_cchar);
} else {
/* tabs, other ASCII stuff */
code = _nc_insert_ch(sp, win, (chtype) (*cp));
}
if (code != OK)
break;
}
win->_curx = ox;
win->_cury = oy;
_nc_synchook(win);
}
}
returnCode(code);
}

165
third_party/ncurses/lib_insch.c vendored Normal file
View file

@ -0,0 +1,165 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2013,2016 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: Sven Verdoolaege *
* and: Thomas E. Dickey *
****************************************************************************/
/*
** lib_insch.c
**
** The routine winsch().
**
*/
#include "curses.priv.h"
#include <ctype.h>
MODULE_ID("$Id: lib_insch.c,v 1.37 2020/02/02 23:34:34 tom Exp $")
/*
* Insert the given character, updating the current location to simplify
* inserting a string.
*/
NCURSES_EXPORT(int)
_nc_insert_ch(SCREEN *sp, WINDOW *win, chtype ch)
{
int code = OK;
int ch8 = (int) ChCharOf(ch);
NCURSES_CH_T wch;
int count;
int tabsize = (
#if USE_REENTRANT
sp->_TABSIZE
#else
TABSIZE
#endif
);
switch (ch) {
case '\t':
for (count = (tabsize - (win->_curx % tabsize)); count > 0; count--) {
if ((code = _nc_insert_ch(sp, win, ' ')) != OK)
break;
}
break;
case '\n':
case '\r':
case '\b':
SetChar2(wch, ch);
_nc_waddch_nosync(win, wch);
break;
default:
if (
#if USE_WIDEC_SUPPORT
WINDOW_EXT(win, addch_used) == 0 &&
#endif
(isprint(ch8) ||
(ChAttrOf(ch) & A_ALTCHARSET) ||
(sp != 0 && sp->_legacy_coding && !iscntrl(ch8)))) {
if (win->_curx <= win->_maxx) {
struct ldat *line = &(win->_line[win->_cury]);
NCURSES_CH_T *end = &(line->text[win->_curx]);
NCURSES_CH_T *temp1 = &(line->text[win->_maxx]);
NCURSES_CH_T *temp2 = temp1 - 1;
SetChar2(wch, ch);
CHANGED_TO_EOL(line, win->_curx, win->_maxx);
while (temp1 > end)
*temp1-- = *temp2--;
*temp1 = _nc_render(win, wch);
win->_curx++;
}
} else if (iscntrl(ch8)) {
NCURSES_CONST char *s;
s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx (chtype) ch8);
while (*s != '\0') {
code = _nc_insert_ch(sp, win, ChAttrOf(ch) | UChar(*s));
if (code != OK)
break;
++s;
}
}
#if USE_WIDEC_SUPPORT
else {
/*
* Handle multibyte characters here
*/
SetChar2(wch, ch);
wch = _nc_render(win, wch);
count = _nc_build_wch(win, &wch);
if (count > 0) {
code = _nc_insert_wch(win, &wch);
} else if (count == -1) {
NCURSES_CONST char *s;
/* handle EILSEQ */
s = NCURSES_SP_NAME(unctrl) (NCURSES_SP_ARGx (chtype) ch8);
if (strlen(s) > 1) {
while (*s != '\0') {
code = _nc_insert_ch(sp, win,
ChAttrOf(ch) | UChar(*s));
if (code != OK)
break;
++s;
}
} else {
code = ERR;
}
}
}
#endif
break;
}
return code;
}
NCURSES_EXPORT(int)
winsch(WINDOW *win, chtype c)
{
int code = ERR;
T((T_CALLED("winsch(%p, %s)"), (void *) win, _tracechtype(c)));
if (win != 0) {
NCURSES_SIZE_T oy = win->_cury;
NCURSES_SIZE_T ox = win->_curx;
code = _nc_insert_ch(_nc_screen_of(win), win, c);
win->_curx = ox;
win->_cury = oy;
_nc_synchook(win);
}
returnCode(code);
}

64
third_party/ncurses/lib_insdel.c vendored Normal file
View file

@ -0,0 +1,64 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2003,2009 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> *
****************************************************************************/
/*
** lib_insdel.c
**
** The routine winsdelln(win, n).
** positive n insert n lines above current line
** negative n delete n lines starting from current line
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_insdel.c,v 1.14 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
winsdelln(WINDOW *win, int n)
{
int code = ERR;
T((T_CALLED("winsdelln(%p,%d)"), (void *) win, n));
if (win) {
if (n != 0) {
_nc_scroll_window(win, -n, win->_cury, win->_maxy,
win->_nc_bkgd);
_nc_synchook(win);
}
code = OK;
}
returnCode(code);
}

96
third_party/ncurses/lib_insnstr.c vendored Normal file
View file

@ -0,0 +1,96 @@
/****************************************************************************
* Copyright 2018-2020,2022 Thomas E. Dickey *
* Copyright 2004-2009,2016 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 *
****************************************************************************/
/*
** lib_insnstr.c
**
** The routine winsnstr().
**
*/
#include "curses.priv.h"
#include <ctype.h>
MODULE_ID("$Id: lib_insnstr.c,v 1.8 2022/05/21 17:35:15 tom Exp $")
NCURSES_EXPORT(int)
winsnstr(WINDOW *win, const char *s, int n)
{
int code = ERR;
const unsigned char *str = (const unsigned char *) s;
T((T_CALLED("winsnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(s, n), n));
if (win != 0 && str != 0) {
SCREEN *sp = _nc_screen_of(win);
#if USE_WIDEC_SUPPORT
/*
* If the output contains "wide" (multibyte) characters, we will not
* really know the width of a character until we get the last byte
* of the character. Since the preceding byte(s) may use more columns
* on the screen than the final character, it is best to route the
* call to the wins_nwstr() function.
*/
if (sp->_screen_unicode) {
size_t nn = (n > 0) ? (size_t) n : strlen(s);
wchar_t *buffer = typeMalloc(wchar_t, nn + 1);
if (buffer != 0) {
mbstate_t state;
size_t n3;
init_mb(state);
n3 = mbstowcs(buffer, s, nn);
if (n3 != (size_t) (-1)) {
buffer[n3] = '\0';
code = wins_nwstr(win, buffer, (int) n3);
}
free(buffer);
}
}
if (code == ERR)
#endif
{
NCURSES_SIZE_T oy = win->_cury;
NCURSES_SIZE_T ox = win->_curx;
const unsigned char *cp;
for (cp = str; (n <= 0 || (cp - str) < n) && *cp; cp++) {
_nc_insert_ch(sp, win, (chtype) UChar(*cp));
}
win->_curx = ox;
win->_cury = oy;
_nc_synchook(win);
code = OK;
}
}
returnCode(code);
}

122
third_party/ncurses/lib_instr.c vendored Normal file
View file

@ -0,0 +1,122 @@
/****************************************************************************
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2016,2017 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-on *
****************************************************************************/
/*
** lib_instr.c
**
** The routine winnstr().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_instr.c,v 1.25 2021/04/03 22:24:18 tom Exp $")
NCURSES_EXPORT(int)
winnstr(WINDOW *win, char *str, int n)
{
int i = 0;
T((T_CALLED("winnstr(%p,%p,%d)"), (void *) win, str, n));
if (!win || !str) {
i = ERR;
} else {
int row = win->_cury;
int col = win->_curx;
NCURSES_CH_T *text = win->_line[row].text;
if (n < 0)
n = win->_maxx - col + 1;
for (; i < n;) {
#if USE_WIDEC_SUPPORT
cchar_t *cell = &(text[col]);
attr_t attrs;
NCURSES_PAIRS_T pair;
char *tmp;
if (!isWidecExt(*cell)) {
wchar_t *wch;
int n2;
n2 = getcchar(cell, 0, 0, 0, 0);
if (n2 > 0
&& (wch = typeCalloc(wchar_t, (unsigned) n2 + 1)) != 0) {
bool done = FALSE;
if (getcchar(cell, wch, &attrs, &pair, 0) == OK) {
mbstate_t state;
size_t n3;
init_mb(state);
n3 = wcstombs(0, wch, (size_t) 0);
if (!isEILSEQ(n3) && (n3 != 0)) {
size_t need = n3 + 10 + (size_t) i;
int have = (int) n3 + i;
/* check for loop-done as well as overflow */
if (have > n || (int) need <= 0) {
done = TRUE;
} else if ((tmp = typeCalloc(char, need)) == 0) {
done = TRUE;
} else {
size_t i3;
init_mb(state);
wcstombs(tmp, wch, n3);
for (i3 = 0; i3 < n3; ++i3)
str[i++] = tmp[i3];
free(tmp);
}
}
}
free(wch);
if (done)
break;
}
}
#else
str[i++] = (char) CharOf(text[col]);
#endif
if (++col > win->_maxx) {
break;
}
}
str[i] = '\0'; /* SVr4 does not seem to count the null */
}
T(("winnstr returns %s", _nc_visbuf(str)));
returnCode(i);
}

114
third_party/ncurses/lib_inwstr.c vendored Normal file
View file

@ -0,0 +1,114 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 2002-2016,2017 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 Dickey *
****************************************************************************/
/*
** lib_inwstr.c
**
** The routines winnwstr() and winwstr().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_inwstr.c,v 1.9 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
winnwstr(WINDOW *win, wchar_t *wstr, int n)
{
int count = 0;
cchar_t *text;
T((T_CALLED("winnwstr(%p,%p,%d)"), (void *) win, (void *) wstr, n));
if (wstr != 0) {
if (win) {
int row, col;
int last = 0;
bool done = FALSE;
getyx(win, row, col);
text = win->_line[row].text;
while (count < n && !done && count != ERR) {
if (!isWidecExt(text[col])) {
int inx;
wchar_t wch;
for (inx = 0; (inx < CCHARW_MAX)
&& ((wch = text[col].chars[inx]) != 0);
++inx) {
if (count + 1 > n) {
done = TRUE;
if (last == 0) {
count = ERR; /* error if we store nothing */
} else {
count = last; /* only store complete chars */
}
break;
}
wstr[count++] = wch;
}
}
last = count;
if (++col > win->_maxx) {
break;
}
}
}
if (count > 0) {
wstr[count] = '\0';
T(("winnwstr returns %s", _nc_viswbuf(wstr)));
}
}
returnCode(count);
}
/*
* X/Open says winwstr() returns OK if not ERR. If that is not a blunder, it
* must have a null termination on the string (see above). Unlike winnstr(),
* it does not define what happens for a negative count with winnwstr().
*/
NCURSES_EXPORT(int)
winwstr(WINDOW *win, wchar_t *wstr)
{
int result = OK;
T((T_CALLED("winwstr(%p,%p)"), (void *) win, (void *) wstr));
if (win == 0) {
result = ERR;
} else if (winnwstr(win, wstr,
CCHARW_MAX * (win->_maxx - win->_curx + 1)) == ERR) {
result = ERR;
}
returnCode(result);
}

62
third_party/ncurses/lib_isendwin.c vendored Normal file
View file

@ -0,0 +1,62 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2009,2017 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-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
** lib_endwin.c
**
** The routine endwin().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_isendwin.c,v 1.9 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(bool)
NCURSES_SP_NAME(isendwin) (NCURSES_SP_DCL0)
{
if (SP_PARM == NULL)
return FALSE;
return (SP_PARM->_endwin == ewSuspend);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(bool)
isendwin(void)
{
return NCURSES_SP_NAME(isendwin) (CURRENT_SCREEN);
}
#endif

195
third_party/ncurses/lib_kernel.c vendored Normal file
View file

@ -0,0 +1,195 @@
/****************************************************************************
* Copyright 2020,2022 Thomas E. Dickey *
* Copyright 1998-2009,2010 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 2002 *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
* lib_kernel.c
*
* Misc. low-level routines:
* erasechar()
* killchar()
* flushinp()
*
* The baudrate() and delay_output() functions could logically live here,
* but are in other modules to reduce the static-link size of programs
* that use only these facilities.
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_kernel.c,v 1.35 2022/07/28 20:14:51 tom Exp $")
#ifdef TERMIOS
static int
_nc_vdisable(void)
{
int value = -1;
#if defined(_POSIX_VDISABLE) && HAVE_UNISTD_H
value = _POSIX_VDISABLE;
#endif
#if defined(_PC_VDISABLE) && HAVE_FPATHCONF
if (value == -1) {
value = (int) fpathconf(0, _PC_VDISABLE);
if (value == -1) {
value = 0377;
}
}
#elif defined(VDISABLE)
if (value == -1)
value = VDISABLE;
#endif
return value;
}
#endif /* TERMIOS */
/*
* erasechar()
*
* Return erase character as given in cur_term->Ottyb.
*
*/
NCURSES_EXPORT(char)
NCURSES_SP_NAME(erasechar) (NCURSES_SP_DCL0)
{
int result = ERR;
TERMINAL *termp = TerminalOf(SP_PARM);
T((T_CALLED("erasechar(%p)"), (void *) SP_PARM));
if (termp != 0) {
#ifdef TERMIOS
result = termp->Ottyb.c_cc[VERASE];
if (result == _nc_vdisable())
result = ERR;
#elif defined(EXP_WIN32_DRIVER)
result = ERR;
#else
result = termp->Ottyb.sg_erase;
#endif
}
returnChar((char) result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(char)
erasechar(void)
{
return NCURSES_SP_NAME(erasechar) (CURRENT_SCREEN);
}
#endif
/*
* killchar()
*
* Return kill character as given in cur_term->Ottyb.
*
*/
NCURSES_EXPORT(char)
NCURSES_SP_NAME(killchar) (NCURSES_SP_DCL0)
{
int result = ERR;
TERMINAL *termp = TerminalOf(SP_PARM);
T((T_CALLED("killchar(%p)"), (void *) SP_PARM));
if (termp != 0) {
#ifdef TERMIOS
result = termp->Ottyb.c_cc[VKILL];
if (result == _nc_vdisable())
result = ERR;
#elif defined(EXP_WIN32_DRIVER)
result = ERR;
#else
result = termp->Ottyb.sg_kill;
#endif
}
returnChar((char) result);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(char)
killchar(void)
{
return NCURSES_SP_NAME(killchar) (CURRENT_SCREEN);
}
#endif
/*
* flushinp()
*
* Flush any input on cur_term->Filedes
*
*/
NCURSES_EXPORT(int)
NCURSES_SP_NAME(flushinp) (NCURSES_SP_DCL0)
{
TERMINAL *termp = TerminalOf(SP_PARM);
T((T_CALLED("flushinp(%p)"), (void *) SP_PARM));
if (termp != 0) {
#ifdef TERMIOS
tcflush(termp->Filedes, TCIFLUSH);
#else
errno = 0;
do {
#if defined(EXP_WIN32_DRIVER)
_nc_console_flush(_nc_console_fd2handle(termp->Filedes));
#else
ioctl(termp->Filedes, TIOCFLUSH, 0);
#endif
} while
(errno == EINTR);
#endif
if (SP_PARM) {
SP_PARM->_fifohead = -1;
SP_PARM->_fifotail = 0;
SP_PARM->_fifopeek = 0;
}
returnCode(OK);
}
returnCode(ERR);
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(int)
flushinp(void)
{
return NCURSES_SP_NAME(flushinp) (CURRENT_SCREEN);
}
#endif

62
third_party/ncurses/lib_key_name.c vendored Normal file
View file

@ -0,0 +1,62 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 2007-2008,2017 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. *
****************************************************************************/
/*
** lib_key_name.c
**
** The routine key_name().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_key_name.c,v 1.5 2020/02/02 23:34:34 tom Exp $")
#define MyData _nc_globals.key_name
NCURSES_EXPORT(NCURSES_CONST char *)
key_name(wchar_t c)
{
cchar_t my_cchar;
wchar_t *my_wchars;
size_t len;
memset(&my_cchar, 0, sizeof(my_cchar));
my_cchar.chars[0] = c;
my_cchar.chars[1] = L'\0';
my_wchars = wunctrl(&my_cchar);
len = wcstombs(MyData, my_wchars, sizeof(MyData) - 1);
if (isEILSEQ(len) || (len == 0)) {
return 0;
}
MyData[len] = '\0';
return MyData;
}

421
third_party/ncurses/lib_keyname.c vendored Normal file
View file

@ -0,0 +1,421 @@
/* generated by MKkeyname.awk */
#include "curses.priv.h"
#include "tic.h"
struct kn { short offset; int code; };
static const struct kn _nc_key_names[] = {
{ 0, KEY_A1 },
{ 7, KEY_A3 },
{ 14, KEY_B2 },
{ 21, KEY_BACKSPACE },
{ 35, KEY_BEG },
{ 43, KEY_BREAK },
{ 53, KEY_BTAB },
{ 62, KEY_C1 },
{ 69, KEY_C3 },
{ 76, KEY_CANCEL },
{ 87, KEY_CATAB },
{ 97, KEY_CLEAR },
{ 107, KEY_CLOSE },
{ 117, KEY_COMMAND },
{ 129, KEY_COPY },
{ 138, KEY_CREATE },
{ 149, KEY_CTAB },
{ 158, KEY_DC },
{ 165, KEY_DL },
{ 172, KEY_DOWN },
{ 181, KEY_EIC },
{ 189, KEY_END },
{ 197, KEY_ENTER },
{ 207, KEY_EOL },
{ 215, KEY_EOS },
{ 223, KEY_EXIT },
{ 232, KEY_F(0) },
{ 241, KEY_F(1) },
{ 250, KEY_F(10) },
{ 260, KEY_F(11) },
{ 270, KEY_F(12) },
{ 280, KEY_F(13) },
{ 290, KEY_F(14) },
{ 300, KEY_F(15) },
{ 310, KEY_F(16) },
{ 320, KEY_F(17) },
{ 330, KEY_F(18) },
{ 340, KEY_F(19) },
{ 350, KEY_F(2) },
{ 359, KEY_F(20) },
{ 369, KEY_F(21) },
{ 379, KEY_F(22) },
{ 389, KEY_F(23) },
{ 399, KEY_F(24) },
{ 409, KEY_F(25) },
{ 419, KEY_F(26) },
{ 429, KEY_F(27) },
{ 439, KEY_F(28) },
{ 449, KEY_F(29) },
{ 459, KEY_F(3) },
{ 468, KEY_F(30) },
{ 478, KEY_F(31) },
{ 488, KEY_F(32) },
{ 498, KEY_F(33) },
{ 508, KEY_F(34) },
{ 518, KEY_F(35) },
{ 528, KEY_F(36) },
{ 538, KEY_F(37) },
{ 548, KEY_F(38) },
{ 558, KEY_F(39) },
{ 568, KEY_F(4) },
{ 577, KEY_F(40) },
{ 587, KEY_F(41) },
{ 597, KEY_F(42) },
{ 607, KEY_F(43) },
{ 617, KEY_F(44) },
{ 627, KEY_F(45) },
{ 637, KEY_F(46) },
{ 647, KEY_F(47) },
{ 657, KEY_F(48) },
{ 667, KEY_F(49) },
{ 677, KEY_F(5) },
{ 686, KEY_F(50) },
{ 696, KEY_F(51) },
{ 706, KEY_F(52) },
{ 716, KEY_F(53) },
{ 726, KEY_F(54) },
{ 736, KEY_F(55) },
{ 746, KEY_F(56) },
{ 756, KEY_F(57) },
{ 766, KEY_F(58) },
{ 776, KEY_F(59) },
{ 786, KEY_F(6) },
{ 795, KEY_F(60) },
{ 805, KEY_F(61) },
{ 815, KEY_F(62) },
{ 825, KEY_F(63) },
{ 835, KEY_F(7) },
{ 844, KEY_F(8) },
{ 853, KEY_F(9) },
{ 862, KEY_FIND },
{ 871, KEY_HELP },
{ 880, KEY_HOME },
{ 889, KEY_IC },
{ 896, KEY_IL },
{ 903, KEY_LEFT },
{ 912, KEY_LL },
{ 919, KEY_MARK },
{ 928, KEY_MESSAGE },
{ 940, KEY_MOUSE },
{ 950, KEY_MOVE },
{ 959, KEY_NEXT },
{ 968, KEY_NPAGE },
{ 978, KEY_OPEN },
{ 987, KEY_OPTIONS },
{ 999, KEY_PPAGE },
{ 1009, KEY_PREVIOUS },
{ 1022, KEY_PRINT },
{ 1032, KEY_REDO },
{ 1041, KEY_REFERENCE },
{ 1055, KEY_REFRESH },
{ 1067, KEY_REPLACE },
{ 1079, KEY_RESET },
{ 1089, KEY_RESIZE },
{ 1100, KEY_RESTART },
{ 1112, KEY_RESUME },
{ 1123, KEY_RIGHT },
{ 1133, KEY_SAVE },
{ 1142, KEY_SBEG },
{ 1151, KEY_SCANCEL },
{ 1163, KEY_SCOMMAND },
{ 1176, KEY_SCOPY },
{ 1186, KEY_SCREATE },
{ 1198, KEY_SDC },
{ 1206, KEY_SDL },
{ 1214, KEY_SELECT },
{ 1225, KEY_SEND },
{ 1234, KEY_SEOL },
{ 1243, KEY_SEXIT },
{ 1253, KEY_SF },
{ 1260, KEY_SFIND },
{ 1270, KEY_SHELP },
{ 1280, KEY_SHOME },
{ 1290, KEY_SIC },
{ 1298, KEY_SLEFT },
{ 1308, KEY_SMESSAGE },
{ 1321, KEY_SMOVE },
{ 1331, KEY_SNEXT },
{ 1341, KEY_SOPTIONS },
{ 1354, KEY_SPREVIOUS },
{ 1368, KEY_SPRINT },
{ 1379, KEY_SR },
{ 1386, KEY_SREDO },
{ 1396, KEY_SREPLACE },
{ 1409, KEY_SRESET },
{ 1420, KEY_SRIGHT },
{ 1431, KEY_SRSUME },
{ 1442, KEY_SSAVE },
{ 1452, KEY_SSUSPEND },
{ 1465, KEY_STAB },
{ 1474, KEY_SUNDO },
{ 1484, KEY_SUSPEND },
{ 1496, KEY_UNDO },
{ 1505, KEY_UP },
{ -1, 0 }};
static const char key_names[] =
"KEY_A1\0"
"KEY_A3\0"
"KEY_B2\0"
"KEY_BACKSPACE\0"
"KEY_BEG\0"
"KEY_BREAK\0"
"KEY_BTAB\0"
"KEY_C1\0"
"KEY_C3\0"
"KEY_CANCEL\0"
"KEY_CATAB\0"
"KEY_CLEAR\0"
"KEY_CLOSE\0"
"KEY_COMMAND\0"
"KEY_COPY\0"
"KEY_CREATE\0"
"KEY_CTAB\0"
"KEY_DC\0"
"KEY_DL\0"
"KEY_DOWN\0"
"KEY_EIC\0"
"KEY_END\0"
"KEY_ENTER\0"
"KEY_EOL\0"
"KEY_EOS\0"
"KEY_EXIT\0"
"KEY_F(0)\0"
"KEY_F(1)\0"
"KEY_F(10)\0"
"KEY_F(11)\0"
"KEY_F(12)\0"
"KEY_F(13)\0"
"KEY_F(14)\0"
"KEY_F(15)\0"
"KEY_F(16)\0"
"KEY_F(17)\0"
"KEY_F(18)\0"
"KEY_F(19)\0"
"KEY_F(2)\0"
"KEY_F(20)\0"
"KEY_F(21)\0"
"KEY_F(22)\0"
"KEY_F(23)\0"
"KEY_F(24)\0"
"KEY_F(25)\0"
"KEY_F(26)\0"
"KEY_F(27)\0"
"KEY_F(28)\0"
"KEY_F(29)\0"
"KEY_F(3)\0"
"KEY_F(30)\0"
"KEY_F(31)\0"
"KEY_F(32)\0"
"KEY_F(33)\0"
"KEY_F(34)\0"
"KEY_F(35)\0"
"KEY_F(36)\0"
"KEY_F(37)\0"
"KEY_F(38)\0"
"KEY_F(39)\0"
"KEY_F(4)\0"
"KEY_F(40)\0"
"KEY_F(41)\0"
"KEY_F(42)\0"
"KEY_F(43)\0"
"KEY_F(44)\0"
"KEY_F(45)\0"
"KEY_F(46)\0"
"KEY_F(47)\0"
"KEY_F(48)\0"
"KEY_F(49)\0"
"KEY_F(5)\0"
"KEY_F(50)\0"
"KEY_F(51)\0"
"KEY_F(52)\0"
"KEY_F(53)\0"
"KEY_F(54)\0"
"KEY_F(55)\0"
"KEY_F(56)\0"
"KEY_F(57)\0"
"KEY_F(58)\0"
"KEY_F(59)\0"
"KEY_F(6)\0"
"KEY_F(60)\0"
"KEY_F(61)\0"
"KEY_F(62)\0"
"KEY_F(63)\0"
"KEY_F(7)\0"
"KEY_F(8)\0"
"KEY_F(9)\0"
"KEY_FIND\0"
"KEY_HELP\0"
"KEY_HOME\0"
"KEY_IC\0"
"KEY_IL\0"
"KEY_LEFT\0"
"KEY_LL\0"
"KEY_MARK\0"
"KEY_MESSAGE\0"
"KEY_MOUSE\0"
"KEY_MOVE\0"
"KEY_NEXT\0"
"KEY_NPAGE\0"
"KEY_OPEN\0"
"KEY_OPTIONS\0"
"KEY_PPAGE\0"
"KEY_PREVIOUS\0"
"KEY_PRINT\0"
"KEY_REDO\0"
"KEY_REFERENCE\0"
"KEY_REFRESH\0"
"KEY_REPLACE\0"
"KEY_RESET\0"
"KEY_RESIZE\0"
"KEY_RESTART\0"
"KEY_RESUME\0"
"KEY_RIGHT\0"
"KEY_SAVE\0"
"KEY_SBEG\0"
"KEY_SCANCEL\0"
"KEY_SCOMMAND\0"
"KEY_SCOPY\0"
"KEY_SCREATE\0"
"KEY_SDC\0"
"KEY_SDL\0"
"KEY_SELECT\0"
"KEY_SEND\0"
"KEY_SEOL\0"
"KEY_SEXIT\0"
"KEY_SF\0"
"KEY_SFIND\0"
"KEY_SHELP\0"
"KEY_SHOME\0"
"KEY_SIC\0"
"KEY_SLEFT\0"
"KEY_SMESSAGE\0"
"KEY_SMOVE\0"
"KEY_SNEXT\0"
"KEY_SOPTIONS\0"
"KEY_SPREVIOUS\0"
"KEY_SPRINT\0"
"KEY_SR\0"
"KEY_SREDO\0"
"KEY_SREPLACE\0"
"KEY_SRESET\0"
"KEY_SRIGHT\0"
"KEY_SRSUME\0"
"KEY_SSAVE\0"
"KEY_SSUSPEND\0"
"KEY_STAB\0"
"KEY_SUNDO\0"
"KEY_SUSPEND\0"
"KEY_UNDO\0"
"KEY_UP\0";
#define SIZEOF_TABLE 256
#define MyTable _nc_globals.keyname_table
#define MyInit _nc_globals.init_keyname
NCURSES_EXPORT(NCURSES_CONST char *)
safe_keyname (SCREEN *sp, int c)
{
char name[20];
NCURSES_CONST char *result = 0;
if (c == -1) {
result = "-1";
} else {
int i;
for (i = 0; _nc_key_names[i].offset != -1; i++) {
if (_nc_key_names[i].code == c) {
result = (NCURSES_CONST char *)key_names + _nc_key_names[i].offset;
break;
}
}
if (result == 0 && (c >= 0 && c < SIZEOF_TABLE)) {
if (MyTable == 0)
MyTable = typeCalloc(char *, SIZEOF_TABLE);
if (MyTable != 0) {
int m_prefix = (sp == 0 || sp->_use_meta);
/* if sense of meta() changed, discard cached data */
if (MyInit != (m_prefix + 1)) {
MyInit = m_prefix + 1;
for (i = 0; i < SIZEOF_TABLE; ++i) {
if (MyTable[i]) {
FreeAndNull(MyTable[i]);
}
}
}
/* create and cache result as needed */
if (MyTable[c] == 0) {
int cc = c;
char *p = name;
#define P_LIMIT (sizeof(name) - (size_t) (p - name))
if (cc >= 128 && m_prefix) {
_nc_STRCPY(p, "M-", P_LIMIT);
p += 2;
cc -= 128;
}
if (cc < 32)
_nc_SPRINTF(p, _nc_SLIMIT(P_LIMIT) "^%c", cc + '@');
else if (cc == 127)
_nc_STRCPY(p, "^?", P_LIMIT);
else
_nc_SPRINTF(p, _nc_SLIMIT(P_LIMIT) "%c", cc);
MyTable[c] = strdup(name);
}
result = MyTable[c];
}
#if NCURSES_EXT_FUNCS && NCURSES_XNAMES
} else if (result == 0 && HasTerminal(sp)) {
int j, k;
char * bound;
TERMTYPE2 *tp = &TerminalType(TerminalOf(sp));
unsigned save_trace = _nc_tracing;
_nc_tracing = 0; /* prevent recursion via keybound() */
for (j = 0; (bound = NCURSES_SP_NAME(keybound)(NCURSES_SP_ARGx c, j)) != 0; ++j) {
for(k = STRCOUNT; k < (int) NUM_STRINGS(tp); k++) {
if (tp->Strings[k] != 0 && !strcmp(bound, tp->Strings[k])) {
result = ExtStrname(tp, k, strnames);
break;
}
}
free(bound);
if (result != 0)
break;
}
_nc_tracing = save_trace;
#endif
}
}
return result;
}
NCURSES_EXPORT(NCURSES_CONST char *)
keyname (int c)
{
return safe_keyname (CURRENT_SCREEN, c);
}
#if NO_LEAKS
void _nc_keyname_leaks(void)
{
if (MyTable != 0) {
int j;
for (j = 0; j < SIZEOF_TABLE; ++j) {
FreeIfNeeded(MyTable[j]);
}
FreeAndNull(MyTable);
}
}
#endif /* NO_LEAKS */

56
third_party/ncurses/lib_leaveok.c vendored Normal file
View file

@ -0,0 +1,56 @@
/****************************************************************************
* Copyright 2020 Thomas E. Dickey *
* Copyright 1998-2000,2009 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> *
****************************************************************************/
/*
** lib_leaveok.c
**
** The routine leaveok.
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_leaveok.c,v 1.7 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(int)
leaveok(WINDOW *win, bool flag)
{
T((T_CALLED("leaveok(%p,%d)"), (void *) win, flag));
if (win) {
win->_leaveok = flag;
returnCode(OK);
} else
returnCode(ERR);
}

104
third_party/ncurses/lib_longname.c vendored Normal file
View file

@ -0,0 +1,104 @@
/****************************************************************************
* Copyright 2020,2021 Thomas E. Dickey *
* Copyright 1998-2010,2015 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-on *
* and: Juergen Pfeifer 2009 *
****************************************************************************/
/*
** lib_longname.c
**
** The routine longname().
**
*/
#include "curses.priv.h"
MODULE_ID("$Id: lib_longname.c,v 1.15 2021/04/03 22:36:21 tom Exp $")
#if USE_REENTRANT
NCURSES_EXPORT(char *)
NCURSES_SP_NAME(longname) (NCURSES_SP_DCL0)
{
static char empty[] =
{'\0'};
T((T_CALLED("longname(%p)"), (void *) SP_PARM));
if (SP_PARM) {
char *ptr;
for (ptr = SP_PARM->_ttytype + strlen(SP_PARM->_ttytype);
ptr > SP_PARM->_ttytype;
ptr--)
if (*ptr == '|')
returnPtr(ptr + 1);
returnPtr(SP_PARM->_ttytype);
}
return empty;
}
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(char *)
longname(void)
{
return NCURSES_SP_NAME(longname) (CURRENT_SCREEN);
}
#endif
#else
/* a dummy entrypoint is simpler than generating a conditional in curses.h */
#if NCURSES_SP_FUNCS
NCURSES_EXPORT(char *)
NCURSES_SP_NAME(longname) (NCURSES_SP_DCL0)
{
(void) SP_PARM;
return longname();
}
#endif
NCURSES_EXPORT(char *)
longname(void)
{
char *ptr;
T((T_CALLED("longname()")));
for (ptr = ttytype + strlen(ttytype);
ptr > ttytype;
ptr--)
if (*ptr == '|')
returnPtr(ptr + 1);
returnPtr(ttytype);
}
#endif

Some files were not shown because too many files have changed in this diff Show more