xref: /dflybsd-src/contrib/ncurses/progs/progs.priv.h (revision 0cadad7e49c6219b0de0675ef6a6f44683d177d4)
15f4613f2SJohn Marino /****************************************************************************
2*32bb5217SDaniel Fojt  * Copyright 2019,2020 Thomas E. Dickey                                     *
3*32bb5217SDaniel Fojt  * Copyright 1998-2015,2017 Free Software Foundation, Inc.                  *
45f4613f2SJohn Marino  *                                                                          *
55f4613f2SJohn Marino  * Permission is hereby granted, free of charge, to any person obtaining a  *
65f4613f2SJohn Marino  * copy of this software and associated documentation files (the            *
75f4613f2SJohn Marino  * "Software"), to deal in the Software without restriction, including      *
85f4613f2SJohn Marino  * without limitation the rights to use, copy, modify, merge, publish,      *
95f4613f2SJohn Marino  * distribute, distribute with modifications, sublicense, and/or sell       *
105f4613f2SJohn Marino  * copies of the Software, and to permit persons to whom the Software is    *
115f4613f2SJohn Marino  * furnished to do so, subject to the following conditions:                 *
125f4613f2SJohn Marino  *                                                                          *
135f4613f2SJohn Marino  * The above copyright notice and this permission notice shall be included  *
145f4613f2SJohn Marino  * in all copies or substantial portions of the Software.                   *
155f4613f2SJohn Marino  *                                                                          *
165f4613f2SJohn Marino  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
175f4613f2SJohn Marino  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
185f4613f2SJohn Marino  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
195f4613f2SJohn Marino  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
205f4613f2SJohn Marino  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
215f4613f2SJohn Marino  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
225f4613f2SJohn Marino  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
235f4613f2SJohn Marino  *                                                                          *
245f4613f2SJohn Marino  * Except as contained in this notice, the name(s) of the above copyright   *
255f4613f2SJohn Marino  * holders shall not be used in advertising or otherwise to promote the     *
265f4613f2SJohn Marino  * sale, use or other dealings in this Software without prior written       *
275f4613f2SJohn Marino  * authorization.                                                           *
285f4613f2SJohn Marino  ****************************************************************************/
295f4613f2SJohn Marino 
305f4613f2SJohn Marino /****************************************************************************
315f4613f2SJohn Marino  *  Author: Thomas E. Dickey                    1997-on                     *
325f4613f2SJohn Marino  ****************************************************************************/
335f4613f2SJohn Marino /*
34*32bb5217SDaniel Fojt  * $Id: progs.priv.h,v 1.48 2020/02/02 23:34:34 tom Exp $
355f4613f2SJohn Marino  *
365f4613f2SJohn Marino  *	progs.priv.h
375f4613f2SJohn Marino  *
385f4613f2SJohn Marino  *	Header file for curses utility programs
395f4613f2SJohn Marino  */
405f4613f2SJohn Marino 
413468e90cSJohn Marino #ifndef PROGS_PRIV_H
423468e90cSJohn Marino #define PROGS_PRIV_H 1
433468e90cSJohn Marino 
445f4613f2SJohn Marino #include <ncurses_cfg.h>
455f4613f2SJohn Marino 
465f4613f2SJohn Marino #if USE_RCS_IDS
475f4613f2SJohn Marino #define MODULE_ID(id) static const char Ident[] = id;
485f4613f2SJohn Marino #else
495f4613f2SJohn Marino #define MODULE_ID(id)		/*nothing */
505f4613f2SJohn Marino #endif
515f4613f2SJohn Marino 
525f4613f2SJohn Marino #include <stdlib.h>
535f4613f2SJohn Marino #include <ctype.h>
545f4613f2SJohn Marino #include <string.h>
555f4613f2SJohn Marino #include <sys/types.h>
565f4613f2SJohn Marino 
575f4613f2SJohn Marino #if HAVE_UNISTD_H
585f4613f2SJohn Marino #include <unistd.h>
595f4613f2SJohn Marino #endif
605f4613f2SJohn Marino 
615f4613f2SJohn Marino #if HAVE_SYS_BSDTYPES_H
625f4613f2SJohn Marino #include <sys/bsdtypes.h>	/* needed for ISC */
635f4613f2SJohn Marino #endif
645f4613f2SJohn Marino 
655f4613f2SJohn Marino #if HAVE_LIMITS_H
665f4613f2SJohn Marino # include <limits.h>
675f4613f2SJohn Marino #elif HAVE_SYS_PARAM_H
685f4613f2SJohn Marino # include <sys/param.h>
695f4613f2SJohn Marino #endif
705f4613f2SJohn Marino 
715f4613f2SJohn Marino #if HAVE_DIRENT_H
725f4613f2SJohn Marino # include <dirent.h>
735f4613f2SJohn Marino # define NAMLEN(dirent) strlen((dirent)->d_name)
745f4613f2SJohn Marino # if defined(_FILE_OFFSET_BITS) && defined(HAVE_STRUCT_DIRENT64)
755f4613f2SJohn Marino #  if !defined(_LP64) && (_FILE_OFFSET_BITS == 64)
765f4613f2SJohn Marino #   define	DIRENT	struct dirent64
775f4613f2SJohn Marino #  else
785f4613f2SJohn Marino #   define	DIRENT	struct dirent
795f4613f2SJohn Marino #  endif
805f4613f2SJohn Marino # else
815f4613f2SJohn Marino #  define	DIRENT	struct dirent
825f4613f2SJohn Marino # endif
835f4613f2SJohn Marino #else
845f4613f2SJohn Marino # define DIRENT struct direct
855f4613f2SJohn Marino # define NAMLEN(dirent) (dirent)->d_namlen
865f4613f2SJohn Marino # if HAVE_SYS_NDIR_H
875f4613f2SJohn Marino #  include <sys/ndir.h>
885f4613f2SJohn Marino # endif
895f4613f2SJohn Marino # if HAVE_SYS_DIR_H
905f4613f2SJohn Marino #  include <sys/dir.h>
915f4613f2SJohn Marino # endif
925f4613f2SJohn Marino # if HAVE_NDIR_H
935f4613f2SJohn Marino #  include <ndir.h>
945f4613f2SJohn Marino # endif
955f4613f2SJohn Marino #endif
965f4613f2SJohn Marino 
973468e90cSJohn Marino #if HAVE_INTTYPES_H
983468e90cSJohn Marino # include <inttypes.h>
993468e90cSJohn Marino #else
1003468e90cSJohn Marino # if HAVE_STDINT_H
1013468e90cSJohn Marino #  include <stdint.h>
1023468e90cSJohn Marino # endif
1033468e90cSJohn Marino #endif
1043468e90cSJohn Marino 
1055f4613f2SJohn Marino #include <assert.h>
1065f4613f2SJohn Marino #include <errno.h>
1075f4613f2SJohn Marino 
1085f4613f2SJohn Marino #if DECL_ERRNO
1095f4613f2SJohn Marino extern int errno;
1105f4613f2SJohn Marino #endif
1115f4613f2SJohn Marino 
1125f4613f2SJohn Marino #if HAVE_GETOPT_H
1135f4613f2SJohn Marino #include <getopt.h>
1143468e90cSJohn Marino #elif !defined(HAVE_GETOPT_HEADER)
1155f4613f2SJohn Marino /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its
1165f4613f2SJohn Marino  * variables doesn't hurt.
1175f4613f2SJohn Marino  */
1185f4613f2SJohn Marino extern char *optarg;
1195f4613f2SJohn Marino extern int optind;
1205f4613f2SJohn Marino #endif /* HAVE_GETOPT_H */
1215f4613f2SJohn Marino 
122*32bb5217SDaniel Fojt #define NCURSES_INTERNALS 1
123*32bb5217SDaniel Fojt #define NCURSES_OPAQUE    0
124*32bb5217SDaniel Fojt 
1255f4613f2SJohn Marino #include <curses.h>
1265f4613f2SJohn Marino #include <term_entry.h>
1273468e90cSJohn Marino #include <nc_termios.h>
1285f4613f2SJohn Marino #include <tic.h>
1295f4613f2SJohn Marino #include <nc_tparm.h>
1305f4613f2SJohn Marino 
1313468e90cSJohn Marino #include <nc_string.h>
1325f4613f2SJohn Marino #include <nc_alloc.h>
133*32bb5217SDaniel Fojt 
1345f4613f2SJohn Marino #if HAVE_NC_FREEALL
1355f4613f2SJohn Marino #undef ExitProgram
1365f4613f2SJohn Marino #ifdef USE_LIBTINFO
137*32bb5217SDaniel Fojt #define ExitProgram(code) exit_terminfo(code)
1385f4613f2SJohn Marino #else
1395f4613f2SJohn Marino #define ExitProgram(code) _nc_free_tic(code)
1405f4613f2SJohn Marino #endif
1415f4613f2SJohn Marino #endif
1425f4613f2SJohn Marino 
143*32bb5217SDaniel Fojt #define VtoTrace(opt) (unsigned) ((opt > 0) ? opt : (opt == 0))
144*32bb5217SDaniel Fojt 
145*32bb5217SDaniel Fojt /* error-returns for tput */
146*32bb5217SDaniel Fojt #define ErrUsage	2
147*32bb5217SDaniel Fojt #define ErrTermType	3
148*32bb5217SDaniel Fojt #define ErrCapName	4
149*32bb5217SDaniel Fojt #define ErrSystem(n)	(4 + (n))
150*32bb5217SDaniel Fojt 
1513468e90cSJohn Marino #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
1523468e90cSJohn Marino #define IGNORE_RC(func) errno = (int) func
1533468e90cSJohn Marino #else
1543468e90cSJohn Marino #define IGNORE_RC(func) (void) func
1553468e90cSJohn Marino #endif /* gcc workarounds */
1563468e90cSJohn Marino 
1575f4613f2SJohn Marino /* usually in <unistd.h> */
1585f4613f2SJohn Marino #ifndef STDOUT_FILENO
1595f4613f2SJohn Marino #define STDOUT_FILENO 1
1605f4613f2SJohn Marino #endif
1615f4613f2SJohn Marino 
1625f4613f2SJohn Marino #ifndef STDERR_FILENO
1635f4613f2SJohn Marino #define STDERR_FILENO 2
1645f4613f2SJohn Marino #endif
1655f4613f2SJohn Marino 
1665f4613f2SJohn Marino #ifndef EXIT_SUCCESS
1675f4613f2SJohn Marino #define EXIT_SUCCESS 0
1685f4613f2SJohn Marino #endif
1695f4613f2SJohn Marino 
1705f4613f2SJohn Marino #ifndef EXIT_FAILURE
1715f4613f2SJohn Marino #define EXIT_FAILURE 1
1725f4613f2SJohn Marino #endif
1735f4613f2SJohn Marino 
1745f4613f2SJohn Marino #ifndef R_OK
1755f4613f2SJohn Marino #define	R_OK	4		/* Test for readable.  */
1765f4613f2SJohn Marino #endif
1775f4613f2SJohn Marino 
1785f4613f2SJohn Marino #ifndef W_OK
1795f4613f2SJohn Marino #define	W_OK	2		/* Test for writable.  */
1805f4613f2SJohn Marino #endif
1815f4613f2SJohn Marino 
1825f4613f2SJohn Marino #ifndef X_OK
1835f4613f2SJohn Marino #define	X_OK	1		/* Test for executable.  */
1845f4613f2SJohn Marino #endif
1855f4613f2SJohn Marino 
1865f4613f2SJohn Marino #ifndef F_OK
1875f4613f2SJohn Marino #define	F_OK	0		/* Test for existence.  */
1885f4613f2SJohn Marino #endif
1895f4613f2SJohn Marino 
1905f4613f2SJohn Marino /* usually in <unistd.h> */
1915f4613f2SJohn Marino #ifndef STDOUT_FILENO
1925f4613f2SJohn Marino #define STDOUT_FILENO 1
1935f4613f2SJohn Marino #endif
1945f4613f2SJohn Marino 
1955f4613f2SJohn Marino #ifndef STDERR_FILENO
1965f4613f2SJohn Marino #define STDERR_FILENO 2
1975f4613f2SJohn Marino #endif
1985f4613f2SJohn Marino 
1995f4613f2SJohn Marino /* may be in limits.h, included from various places */
2005f4613f2SJohn Marino #ifndef PATH_MAX
2015f4613f2SJohn Marino # if defined(_POSIX_PATH_MAX)
2025f4613f2SJohn Marino #  define PATH_MAX _POSIX_PATH_MAX
2035f4613f2SJohn Marino # elif defined(MAXPATHLEN)
2045f4613f2SJohn Marino #  define PATH_MAX MAXPATHLEN
2055f4613f2SJohn Marino # else
2065f4613f2SJohn Marino #  define PATH_MAX 255		/* the Posix minimum pathsize */
2075f4613f2SJohn Marino # endif
2085f4613f2SJohn Marino #endif
2095f4613f2SJohn Marino 
2105f4613f2SJohn Marino /* We use isascii only to guard against use of 7-bit ctype tables in the
2115f4613f2SJohn Marino  * isprint test in infocmp.
2125f4613f2SJohn Marino  */
2135f4613f2SJohn Marino #if !HAVE_ISASCII
2145f4613f2SJohn Marino # undef isascii
2155f4613f2SJohn Marino # if ('z'-'a' == 25) && ('z' < 127) && ('Z'-'A' == 25) && ('Z' < 127) && ('9' < 127)
2165f4613f2SJohn Marino #  define isascii(c) (UChar(c) <= 127)
2175f4613f2SJohn Marino # else
2185f4613f2SJohn Marino #  define isascii(c) 1		/* not really ascii anyway */
2195f4613f2SJohn Marino # endif
2205f4613f2SJohn Marino #endif
2215f4613f2SJohn Marino 
2225f4613f2SJohn Marino #define UChar(c)    ((unsigned char)(c))
2235f4613f2SJohn Marino 
2245f4613f2SJohn Marino #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
2253468e90cSJohn Marino 
226*32bb5217SDaniel Fojt #define NCURSES_EXT_NUMBERS (NCURSES_EXT_COLORS && HAVE_INIT_EXTENDED_COLOR)
227*32bb5217SDaniel Fojt 
228*32bb5217SDaniel Fojt #if NCURSES_EXT_NUMBERS
229*32bb5217SDaniel Fojt #else
230*32bb5217SDaniel Fojt #define _nc_free_termtype2(t) _nc_free_termtype(t)
231*32bb5217SDaniel Fojt #define _nc_read_entry2(n,f,t) _nc_read_entry(n,f,t)
232*32bb5217SDaniel Fojt #endif
233*32bb5217SDaniel Fojt 
2343468e90cSJohn Marino #endif /* PROGS_PRIV_H */
235