+'\" t
.\"***************************************************************************
-.\" Copyright 2018-2020,2021 Thomas E. Dickey *
+.\" Copyright 2018-2022,2023 Thomas E. Dickey *
.\" Copyright 1998-2016,2017 Free Software Foundation, Inc. *
.\" *
.\" Permission is hereby granted, free of charge, to any person obtaining a *
.\" authorization. *
.\"***************************************************************************
.\"
-.\" $Id: curs_terminfo.3x,v 1.79 2021/12/25 21:34:58 tom Exp $
-.TH curs_terminfo 3X ""
+.\" $Id: curs_terminfo.3x,v 1.111 2023/09/30 21:38:11 tom Exp $
+.TH curs_terminfo 3X 2023-09-30 "ncurses 6.4" "Library calls"
.ie \n(.g .ds `` \(lq
.el .ds `` ``
.ie \n(.g .ds '' \(rq
.el .IP \(bu 2
..
.ds n 5
-.na
-.hy 0
.SH NAME
-\fBdel_curterm\fP,
-\fBmvcur\fP,
-\fBputp\fP,
-\fBrestartterm\fP,
-\fBset_curterm\fP,
-\fBsetupterm\fP,
-\fBtigetflag\fP,
-\fBtigetnum\fP,
-\fBtigetstr\fP,
-\fBtiparm\fP,
-\fBtparm\fP,
-\fBtputs\fP,
-\fBvid_attr\fP,
-\fBvid_puts\fP,
-\fBvidattr\fP,
-\fBvidputs\fP \- \fBcurses\fP interfaces to terminfo database
-.ad
-.hy
+\fB\%del_curterm\fP,
+\fB\%mvcur\fP,
+\fB\%putp\fP,
+\fB\%restartterm\fP,
+\fB\%set_curterm\fP,
+\fB\%setupterm\fP,
+\fB\%tigetflag\fP,
+\fB\%tigetnum\fP,
+\fB\%tigetstr\fP,
+\fB\%tiparm\fP,
+\fB\%tiparm_s\fP,
+\fB\%tiscan_s\fP,
+\fB\%tparm\fP,
+\fB\%tputs\fP,
+\fB\%vid_attr\fP,
+\fB\%vid_puts\fP,
+\fB\%vidattr\fP,
+\fB\%vidputs\fP \-
+\fIcurses\fR interfaces to \fIterminfo\fR database
.SH SYNOPSIS
.nf
\fB#include <curses.h>\fP
\fB#include <term.h>\fP
-.sp
+.PP
\fBTERMINAL *cur_term;\fP
-.sp
+.PP
\fBconst char * const boolnames[];\fP
\fBconst char * const boolcodes[];\fP
\fBconst char * const boolfnames[];\fP
\fBconst char * const strnames[];\fP
\fBconst char * const strcodes[];\fP
\fBconst char * const strfnames[];\fP
-.sp
-\fBint setupterm(const char *\fP\fIterm\fP\fB, int \fP\fIfiledes\fP\fB, int *\fP\fIerrret\fP\fB);\fP
-.br
-\fBTERMINAL *set_curterm(TERMINAL *\fP\fInterm\fP\fB);\fP
-.br
-\fBint del_curterm(TERMINAL *\fP\fIoterm\fP\fB);\fP
-.br
-\fBint restartterm(const char *\fP\fIterm\fP\fB, int \fP\fIfiledes\fP\fB, int *\fP\fIerrret\fP\fB);\fP
-.sp
-\fBchar *tparm(const char *\fP\fIstr\fP\fB, ...);\fP
-.br
-\fBint tputs(const char *\fP\fIstr\fP\fB, int \fP\fIaffcnt\fP\fB, int (*\fP\fIputc\fP\fB)(int));\fP
-.br
-\fBint putp(const char *\fP\fIstr\fP\fB);\fP
-.sp
-\fBint vidputs(chtype \fP\fIattrs\fP\fB, int (*\fP\fIputc\fP\fB)(int));\fP
-.br
-\fBint vidattr(chtype \fP\fIattrs\fP\fB);\fP
-.br
-\fBint vid_puts(attr_t \fP\fIattrs\fP\fB, short \fP\fIpair\fP\fB, void *\fP\fIopts\fP\fB, int (*\fP\fIputc\fP\fB)(int));\fP
-.br
-\fBint vid_attr(attr_t \fP\fIattrs\fP\fB, short \fP\fIpair\fP\fB, void *\fP\fIopts\fP\fB);\fP
-.sp
-\fBint mvcur(int \fP\fIoldrow\fP\fB, int \fP\fIoldcol\fP\fB, int \fP\fInewrow\fP, int \fP\fInewcol\fP\fB);\fP
-.sp
-\fBint tigetflag(const char *\fP\fIcapname\fP\fB);\fP
-.br
-\fBint tigetnum(const char *\fP\fIcapname\fP\fB);\fP
-.br
-\fBchar *tigetstr(const char *\fP\fIcapname\fP\fB);\fP
-.sp
-\fBchar *tiparm(const char *\fP\fIstr\fP\fB, ...);\fP
-.br
+.PP
+\fBint setupterm(const char *\fIterm\fB, int \fIfiledes\fB, int *\fIerrret\fB);\fR
+\fBTERMINAL *set_curterm(TERMINAL *\fInterm\fB);\fR
+\fBint del_curterm(TERMINAL *\fIoterm\fB);\fR
+\fBint restartterm(const char *\fIterm\fB, int \fIfiledes\fB, int *\fIerrret\fB);\fR
+.PP
+\fBchar *tparm(const char *\fIstr\fB, ...);\fR
+ \fIor\fP
+\fBchar *tparm(const char *\fIstr\fB, long \fIp1 ... \fBlong \fIp9\fB);\fR
+.PP
+\fBint tputs(const char *\fIstr\fB, int \fIaffcnt\fB, int (*\fIputc\fB)(int));\fR
+\fBint putp(const char *\fIstr\fB);\fR
+.PP
+\fBint vidputs(chtype \fIattrs\fB, int (*\fIputc\fB)(int));\fR
+\fBint vidattr(chtype \fIattrs\fB);\fR
+\fBint vid_puts(attr_t \fIattrs\fB, short \fIpair\fB, void *\fIopts\fB, int (*\fIputc\fB)(int));\fR
+\fBint vid_attr(attr_t \fIattrs\fB, short \fIpair\fB, void *\fIopts\fB);\fR
+.PP
+\fBint mvcur(int \fIoldrow\fB, int \fIoldcol\fB, int \fInewrow\fR, int \fInewcol\fB);\fR
+.PP
+\fBint tigetflag(const char *\fIcapname\fB);\fR
+\fBint tigetnum(const char *\fIcapname\fB);\fR
+\fBchar *tigetstr(const char *\fIcapname\fB);\fR
+.PP
+\fBchar *tiparm(const char *\fIstr\fB, ...);\fR
+.PP
+\fI/* extensions */\fP
+\fBchar *tiparm_s(int \fIexpected\fB, int \fImask\fB, const char *\fIstr\fB, ...);\fR
+\fBint tiscan_s(int *\fIexpected\fB, int *\fImask\fB, const char *\fIstr\fB);\fR
.fi
.SH DESCRIPTION
These low-level routines must be called by programs that have to deal
-directly with the \fBterminfo\fP database to handle certain terminal
+directly with the \fIterminfo\fP database to handle certain terminal
capabilities, such as programming function keys.
For all other
-functionality, \fBcurses\fP routines are more suitable and their use is
+functionality, \fIcurses\fP routines are more suitable and their use is
recommended.
.PP
None of these functions use (or are aware of) multibyte character strings
capability string values have no associated encoding;
they are strings of 8-bit characters.
.SS Initialization
-.PP
Initially, \fBsetupterm\fP should be called.
The high-level curses functions \fBinitscr\fP and
\fBnewterm\fP call \fBsetupterm\fP to initialize the
If \fIterm\fP is null, the environment variable \fBTERM\fP is used.
.TP 5
\fIfiledes\fP
-is the file descriptor used for all output.
+is the file descriptor used for getting and setting terminal I/O modes.
+.IP
+Higher-level applications use \fBnewterm\fP(3X) for initializing the terminal,
+passing an output \fIstream\fP rather than a \fIdescriptor\fP.
+In curses, the two are the same because \fBnewterm\fP calls \fBsetupterm\fP,
+passing the file descriptor derived from its output stream parameter.
.TP 5
\fIerrret\fP
points to an optional location where an error status can be returned to
.RS
.TP 5
.B 1
-means that the terminal is hardcopy, cannot be used for curses applications.
+means that the terminal is hardcopy, cannot be used for \fIcurses\fP applications.
.IP
-\fBsetupterm\fP determines if the entry is a hardcopy type by
+\fB\%setupterm\fP determines if the entry is a hardcopy type by
checking the \fBhc\fP (\fBhardcopy\fP) capability.
.TP 5
.B 0
means that the terminal could not be found,
or that it is a generic type,
-having too little information for curses applications to run.
+having too little information for \fIcurses\fP applications to run.
.IP
-\fBsetupterm\fP determines if the entry is a generic type by
-checking the \fBgn\fP (\fBgeneric\fP) capability.
+\fB\%setupterm\fP determines if the entry is a generic type by
+checking the \fBgn\fP \%(\fBgeneric_type\fP) capability.
.TP 5
.B \-1
-means that the \fBterminfo\fP database could not be found.
+means that the \fIterminfo\fP database could not be found.
.RE
.IP
If \fIerrret\fP is
-null, \fBsetupterm\fP prints an error message upon finding an error
+null, \fB\%setupterm\fP prints an error message upon finding an error
and exits.
Thus, the simplest call is:
-.sp
- \fBsetupterm((char *)0, 1, (int *)0);\fP,
-.sp
+.IP
+\fBsetupterm((char *)0, 1, (int *)0);\fP,
+.PP
which uses all the defaults and sends the output to \fBstdout\fP.
.RE
.\" ***************************************************************************
.SS The Terminal State
-.PP
The \fBsetupterm\fP routine stores its information about the terminal
in a \fBTERMINAL\fP structure pointed to by the global variable \fBcur_term\fP.
If it detects an error,
calls \fBsetupterm\fP, and then restores the bits.
.\" ***************************************************************************
.SS Formatting Output
-.PP
The \fBtparm\fP routine instantiates the string \fIstr\fP with
parameters \fIpi\fP. A pointer is returned to the result of \fIstr\fP
with the parameters applied.
\fBtiparm\fP is a newer form of \fBtparm\fP which uses \fI<stdarg.h>\fP
rather than a fixed-parameter list.
Its numeric parameters are integers (int) rather than longs.
+.PP
+Both \fBtparm\fP and \fBtiparm\fP assume that the application passes
+parameters consistent with the terminal description.
+Two extensions are provided as alternatives to deal with untrusted data:
+.bP
+\fBtiparm_s\fP is an extension which is a safer formatting function
+than \fBtparm\fR or \fBtiparm\fR,
+because it allows the developer to tell the curses
+library how many parameters to expect in the parameter list,
+and which may be string parameters.
+.IP
+The \fImask\fP parameter has one bit set for each of the parameters
+(up to 9) which will be passed as char* rather than numbers.
+.bP
+The extension \fBtiscan_s\fP allows the application
+to inspect a formatting capability to see what the curses library would assume.
.\" ***************************************************************************
.SS Output Functions
-.PP
The \fBtputs\fP routine applies padding information
(i.e., by interpreting marker embedded in the terminfo capability
such as \*(``$<5>\*('' as 5 milliseconds)
\fIputc\fP is a \fBputchar\fP-like routine to which
the characters are passed, one at a time.
.PP
-The \fBputp\fP routine calls \fBtputs(\fP\fIstr\fP\fB, 1, putchar)\fP.
+The \fBputp\fR routine calls \fBtputs(\fIstr\fB, 1, putchar)\fR.
The output of \fBputp\fP always goes to \fBstdout\fP, rather than
the \fIfiledes\fP specified in \fBsetupterm\fP.
.PP
.PP
The \fBmvcur\fP routine provides low-level cursor motion.
It takes effect immediately (rather than at the next refresh).
+Unlike the other low-level output functions,
+which either write to the standard output or pass an output function parameter,
+\fBmvcur\fP uses an output file descriptor derived from
+the output stream parameter of \fBnewterm\fP(3X).
.PP
While \fBputp\fP and \fBmvcur\fP are low-level functions which
do not use the high-level curses state,
-they are declared in \fB<curses.h>\fP because SystemV did this
+they are declared in \fB\%<curses.h>\fP because System\ V did this
(see \fIHISTORY\fP).
.\" ***************************************************************************
.SS Terminal Capability Functions
-.PP
The \fBtigetflag\fP, \fBtigetnum\fP and \fBtigetstr\fP routines return
the value of the capability corresponding to the \fBterminfo\fP
\fIcapname\fP passed to them, such as \fBxenl\fP.
if it is canceled or absent from the terminal description.
.\" ***************************************************************************
.SS Terminal Capability Names
-.PP
These null-terminated arrays contain
.bP
-the short terminfo names (\*(``codes\*(''),
+the short \fIterminfo\fP names (\*(``codes\*(''),
.bP
-the \fBtermcap\fP names (\*(``names\*(''), and
+the \fItermcap\fP names (\*(``names\*(''), and
.bP
-the long terminfo names (\*(``fnames\*('')
+the long \fIterminfo\fP names (\*(``fnames\*('')
+.PP
+for each of the predefined \fIterminfo\fP variables:
.PP
-for each of the predefined \fBterminfo\fP variables:
-.sp
.RS
+.nf
\fBconst char *boolnames[]\fP, \fB*boolcodes[]\fP, \fB*boolfnames[]\fP
-.br
\fBconst char *numnames[]\fP, \fB*numcodes[]\fP, \fB*numfnames[]\fP
-.br
\fBconst char *strnames[]\fP, \fB*strcodes[]\fP, \fB*strfnames[]\fP
+.fi
.RE
+.\" ***************************************************************************
+.SS Releasing Memory
+Each successful call to \fBsetupterm\fP allocates memory to hold the terminal
+description.
+As a side-effect, it sets \fBcur_term\fP to point to this memory.
+If an application calls
+.IP
+\fBdel_curterm(cur_term);\fP
+.PP
+the memory will be freed.
+.PP
+The formatting functions \fBtparm\fP and \fBtiparm\fP extend the storage
+allocated by \fBsetupterm\fP:
+.bP
+the \*(``static\*('' terminfo variables [a-z].
+Before ncurses 6.3, those were shared by all screens.
+With ncurses 6.3, those are allocated per screen.
+See \fBterminfo\fP(\*n) for details.
+.bP
+to improve performance, ncurses 6.3 caches the result of analyzing terminfo
+strings for their parameter types.
+That is stored as a binary tree referenced from the \fBTERMINAL\fP structure.
+.PP
+The higher-level \fBinitscr\fP and \fBnewterm\fP functions use \fBsetupterm\fP.
+Normally they do not free this memory, but it is possible to do that using
+the \fBdelscreen\fP(3X) function.
+.\" ***************************************************************************
.SH RETURN VALUE
Routines that return an integer return \fBERR\fP upon failure and \fBOK\fP
(SVr4 only specifies \*(``an integer value other than \fBERR\fP\*('')
create the initial windows (stdscr, curscr, newscr).
Other error conditions are documented above.
.TP 5
+\fBtparm\fP
+returns a null if the capability would require unexpected parameters,
+e.g., too many, too few, or incorrect types
+(strings where integers are expected, or vice versa).
+.TP 5
\fBtputs\fP
returns an error if the string parameter is null.
It does not detect I/O errors:
but except for \fBsetterm\fP, are likewise macros.
The one function, \fBsetterm\fP, is mentioned in the manual page.
The manual page notes that the \fBsetterm\fP routine
-was replaced by \fBsetupterm\fP, stating that the call:
-.sp
- \fBsetupterm(\fP\fIterm\fP\fB, 1, (int *)0)\fP
-.sp
-provides the same functionality as \fBsetterm(\fP\fIterm\fP\fB)\fP,
+was replaced by \fB\%setupterm\fP, stating that the call
+.IP
+\fBsetupterm(\fIterm\fB, 1, (int *)0)\fR
+.PP
+provides the same functionality as \fBsetterm(\fIterm\fB)\fR,
and is not recommended for new programs.
This implementation provides each of those symbols
as macros for BSD compatibility,
.\" ***************************************************************************
.SH HISTORY
-.PP
SVr2 introduced the terminfo feature.
-Its programming manual mentioned these low-level functions:
+Its programming manual mentioned the following low-level functions.
+.PP
.TS
-l l
-_ _
-l l.
-\fBFunction\fP \fBDescription\fP
+lB lB
+lB lx.
+Function Description
+_
fixterm restore tty to \*(``in curses\*('' state
gettmode establish current tty modes
mvcur low level cursor motion
.TE
.PP
The programming manual also mentioned
-functions provided for termcap compatibility
-(commenting that they \*(``may go away at a later date\*(''):
+functions provided for \fItermcap\fP compatibility
+(commenting that they \*(``may go away at a later date\*('').
+.PP
.TS
-l l
-_ _
-l l.
-\fBFunction\fP \fBDescription\fP
-tgetent look up termcap entry for given \fIname\fP
+lB lB
+lB lx.
+Function Description
+_
+tgetent look up \fItermcap\fP entry for given \fIname\fP
tgetflag get boolean entry for given \fIid\fP
tgetnum get numeric entry for given \fIid\fP
tgetstr get string entry for given \fIid\fP
.PP
SVr3 extended terminfo by adding functions to retrieve capability values
(like the termcap interface),
-and reusing tgoto and tputs:
+and reusing \fBtgoto\fP and \fBtputs\fP:
+.PP
.TS
-l l
-_ _
-l l.
-\fBFunction\fP \fBDescription\fP
+lB lB
+lB lx.
+Function Description
+_
tigetflag get boolean entry for given \fIid\fP
tigetnum get numeric entry for given \fIid\fP
tigetstr get string entry for given \fIid\fP
.TE
.PP
-SVr3 also replaced several of the SVr2 terminfo functions
-which had no counterpart in the termcap interface,
-documenting them as obsolete:
+SVr3 also replaced several of the SVr2 \fIterminfo\fP functions
+which had no counterpart in the \fItermcap\fP interface,
+documenting them as obsolete.
+.PP
.TS
-l l
-_ _
-l l.
-\fBFunction\fP \fBReplaced by\fP
+lB lB
+l lx.
+Function Replaced by
+_
crmode cbreak
fixterm reset_prog_mode
-gettmode N/A
+gettmode \fIn/a\fP
nocrmode nocbreak
resetterm reset_shell_mode
saveterm def_prog_mode
.PP
SVr4 added the \fBvid_attr\fP and \fBvid_puts\fP functions.
.PP
-There are other low-level functions declared in the curses header files
+There are other low-level functions declared in the \fIcurses\fP header files
on Unix systems,
but none were documented.
The functions marked \*(``obsolete\*('' remained in use
by the Unix \fBvi\fP(1) editor.
.SH PORTABILITY
+.SS Extensions
+The functions marked as extensions were designed for \fBncurses\fP(3X),
+and are not found in SVr4 curses, 4.4BSD curses,
+or any other previous version of curses.
.SS Legacy functions
-.PP
X/Open notes that \fBvidattr\fP and \fBvidputs\fP may be macros.
.PP
The function \fBsetterm\fP is not described by X/Open and must
be considered non-portable.
All other functions are as described by X/Open.
.SS Legacy data
-.PP
\fBsetupterm\fP copies the terminal name to the array \fBttytype\fP.
This is not part of X/Open Curses, but is assumed by some applications.
.PP
Extended terminal capability names, e.g., as defined by \fB@TIC@\ \-x\fP,
are not stored in the arrays described here.
.SS Output buffering
-.PP
Older versions of \fBncurses\fP assumed that the file descriptor passed to
\fBsetupterm\fP from \fBinitscr\fP or \fBnewterm\fP uses buffered I/O,
and would write to the corresponding stream.
alternate versions of these functions
using the more reliable buffering scheme.
.SS Function prototypes
-.PP
The X/Open Curses prototypes are based on the SVr4 curses header declarations,
which were defined at the same time the C language was first standardized in
the late 1980s.
.IP
As an extension, this implementation can be configured to change the
function prototypes to use the \fBconst\fP keyword.
-The ncurses ABI 6 enables this feature by default.
+The \fIncurses\fP ABI 6 enables this feature by default.
.bP
X/Open Curses prototypes \fBtparm\fP with a fixed number of parameters,
rather than a variable argument list.
.IP
In response to review comments by Thomas E. Dickey,
X/Open Curses Issue 7 proposed the \fBtiparm\fP function in mid-2009.
-.SS Special TERM treatment
+.IP
+While \fBtiparm\fP is always provided in ncurses,
+the older form is only available as a build-time configuration option.
+If not specially configured, \fBtparm\fP is the same as \fBtiparm\fP.
.PP
+Both forms of \fBtparm\fP have drawbacks:
+.bP
+Most of the calls to \fBtparm\fP use only one or two parameters.
+Passing nine on each call is awkward.
+.IP
+Using \fBlong\fP for the numeric parameter type is a workaround
+to make the parameter use the same amount of stack as a pointer.
+That approach dates back to the mid-1980s, before C was standardized.
+Since then, there is a standard
+(and pointers are not required to fit in a long).
+.bP
+Providing the right number of parameters for a variadic function
+such as \fBtiparm\fP can be a problem, in particular for string parameters.
+However, only a few terminfo capabilities use string parameters
+(e.g., the ones used for programmable function keys).
+.IP
+The ncurses library checks usage of these capabilities,
+and returns an error if the capability mishandles string parameters.
+But it cannot check if a calling program provides strings in the right
+places for the \fBtparm\fP calls.
+.IP
+The \fB@TPUT@\fR(1) program checks its use of these capabilities with a table,
+so that it calls \fBtparm\fP correctly.
+.SS Special TERM treatment
If configured to use the terminal-driver,
e.g., for the MinGW port,
.bP
\fBsetupterm\fP interprets a missing/empty TERM variable as the
special value \*(``unknown\*(''.
+.IP
+SVr4 curses uses the
+special value \*(``dumb\*(''.
+.IP
+The difference between the two is that
+the former uses the \fBgn\fP (\fBgeneric_type\fR) terminfo capability,
+while the latter does not.
+A generic terminal is unsuitable for full-screen applications.
.bP
\fBsetupterm\fP allows explicit use of the
the windows console driver by checking if $TERM is set to
\*(``#win32con\*('' or an abbreviation of that string.
.SS Other portability issues
-.PP
In System V Release 4, \fBset_curterm\fP has an \fBint\fP return type and
returns \fBOK\fP or \fBERR\fP. We have chosen to implement the X/Open Curses
semantics.
This implementation allows the caller to use \-1's for the old ordinates.
In that case, the old location is unknown.
.SH SEE ALSO
-\fBcurses\fP(3X),
-\fBcurs_initscr\fP(3X),
-\fBcurs_kernel\fP(3X),
-\fBcurs_termcap\fP(3X),
-\fBcurs_variables\fP(3X),
-\fBterm_variables\fP(3X),
-\fBputc\fP(3),
-\fBterminfo\fP(\*n)
+\fB\%curses\fP(3X),
+\fB\%curs_initscr\fP(3X),
+\fB\%curs_kernel\fP(3X),
+\fB\%curs_memleaks\fP(3X),
+\fB\%curs_termcap\fP(3X),
+\fB\%curs_variables\fP(3X),
+\fB\%term_variables\fP(3X),
+\fB\%putc\fP(3),
+\fB\%terminfo\fP(\*n)