1bacd15cpeter/****************************************************************************
201cf73abapt * Copyright 2019,2020 Thomas E. Dickey                                     *
301cf73abapt * Copyright 1998-2015,2017 Free Software Foundation, Inc.                  *
4bacd15cpeter *                                                                          *
5bacd15cpeter * Permission is hereby granted, free of charge, to any person obtaining a  *
6bacd15cpeter * copy of this software and associated documentation files (the            *
7bacd15cpeter * "Software"), to deal in the Software without restriction, including      *
8bacd15cpeter * without limitation the rights to use, copy, modify, merge, publish,      *
9bacd15cpeter * distribute, distribute with modifications, sublicense, and/or sell       *
10bacd15cpeter * copies of the Software, and to permit persons to whom the Software is    *
11bacd15cpeter * furnished to do so, subject to the following conditions:                 *
12bacd15cpeter *                                                                          *
13bacd15cpeter * The above copyright notice and this permission notice shall be included  *
14bacd15cpeter * in all copies or substantial portions of the Software.                   *
15bacd15cpeter *                                                                          *
16bacd15cpeter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17bacd15cpeter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18bacd15cpeter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19bacd15cpeter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20bacd15cpeter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21bacd15cpeter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22bacd15cpeter * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23bacd15cpeter *                                                                          *
24bacd15cpeter * Except as contained in this notice, the name(s) of the above copyright   *
25bacd15cpeter * holders shall not be used in advertising or otherwise to promote the     *
26bacd15cpeter * sale, use or other dealings in this Software without prior written       *
27bacd15cpeter * authorization.                                                           *
28bacd15cpeter ****************************************************************************/
29bacd15cpeter
30bacd15cpeter/****************************************************************************
31de9cbefrafan *  Author: Thomas E. Dickey                    1997-on                     *
32bacd15cpeter ****************************************************************************/
33bacd15cpeter/*
3401cf73abapt * $Id: progs.priv.h,v 1.48 2020/02/02 23:34:34 tom Exp $
35bacd15cpeter *
36bacd15cpeter *	progs.priv.h
37bacd15cpeter *
38bacd15cpeter *	Header file for curses utility programs
39bacd15cpeter */
40bacd15cpeter
41f52ca6ebapt#ifndef PROGS_PRIV_H
42f52ca6ebapt#define PROGS_PRIV_H 1
43f52ca6ebapt
44bacd15cpeter#include <ncurses_cfg.h>
45bacd15cpeter
46a81407apeter#if USE_RCS_IDS
47bacd15cpeter#define MODULE_ID(id) static const char Ident[] = id;
48bacd15cpeter#else
497dbeededelphij#define MODULE_ID(id)		/*nothing */
50bacd15cpeter#endif
51bacd15cpeter
52bacd15cpeter#include <stdlib.h>
53bacd15cpeter#include <ctype.h>
54bacd15cpeter#include <string.h>
55bacd15cpeter#include <sys/types.h>
56bacd15cpeter
57bacd15cpeter#if HAVE_UNISTD_H
58bacd15cpeter#include <unistd.h>
59bacd15cpeter#endif
60bacd15cpeter
61bacd15cpeter#if HAVE_SYS_BSDTYPES_H
62bacd15cpeter#include <sys/bsdtypes.h>	/* needed for ISC */
63bacd15cpeter#endif
64bacd15cpeter
65bacd15cpeter#if HAVE_LIMITS_H
66bacd15cpeter# include <limits.h>
67bacd15cpeter#elif HAVE_SYS_PARAM_H
68bacd15cpeter# include <sys/param.h>
69bacd15cpeter#endif
70bacd15cpeter
71bacd15cpeter#if HAVE_DIRENT_H
72bacd15cpeter# include <dirent.h>
73bacd15cpeter# define NAMLEN(dirent) strlen((dirent)->d_name)
74de9cbefrafan# if defined(_FILE_OFFSET_BITS) && defined(HAVE_STRUCT_DIRENT64)
75de9cbefrafan#  if !defined(_LP64) && (_FILE_OFFSET_BITS == 64)
76de9cbefrafan#   define	DIRENT	struct dirent64
77de9cbefrafan#  else
78de9cbefrafan#   define	DIRENT	struct dirent
79de9cbefrafan#  endif
80de9cbefrafan# else
81de9cbefrafan#  define	DIRENT	struct dirent
82de9cbefrafan# endif
83bacd15cpeter#else
84de9cbefrafan# define DIRENT struct direct
85bacd15cpeter# define NAMLEN(dirent) (dirent)->d_namlen
86bacd15cpeter# if HAVE_SYS_NDIR_H
87bacd15cpeter#  include <sys/ndir.h>
88bacd15cpeter# endif
89bacd15cpeter# if HAVE_SYS_DIR_H
90bacd15cpeter#  include <sys/dir.h>
91bacd15cpeter# endif
92bacd15cpeter# if HAVE_NDIR_H
93bacd15cpeter#  include <ndir.h>
94bacd15cpeter# endif
95bacd15cpeter#endif
96bacd15cpeter
977dbeededelphij#if HAVE_INTTYPES_H
987dbeededelphij# include <inttypes.h>
997dbeededelphij#else
1007dbeededelphij# if HAVE_STDINT_H
1017dbeededelphij#  include <stdint.h>
1027dbeededelphij# endif
1037dbeededelphij#endif
1047dbeededelphij
105d078158rafan#include <assert.h>
106bacd15cpeter#include <errno.h>
107bacd15cpeter
108bacd15cpeter#if DECL_ERRNO
109bacd15cpeterextern int errno;
110bacd15cpeter#endif
111bacd15cpeter
112bacd15cpeter#if HAVE_GETOPT_H
113bacd15cpeter#include <getopt.h>
1147dbeededelphij#elif !defined(HAVE_GETOPT_HEADER)
115bacd15cpeter/* 'getopt()' may be prototyped in <stdlib.h>, but declaring its
116bacd15cpeter * variables doesn't hurt.
117bacd15cpeter */
118bacd15cpeterextern char *optarg;
119bacd15cpeterextern int optind;
120bacd15cpeter#endif /* HAVE_GETOPT_H */
121bacd15cpeter
122f52ca6ebapt#define NCURSES_INTERNALS 1
123f52ca6ebapt#define NCURSES_OPAQUE    0
124f52ca6ebapt
125bacd15cpeter#include <curses.h>
126bacd15cpeter#include <term_entry.h>
1277dbeededelphij#include <nc_termios.h>
128bacd15cpeter#include <tic.h>
129de9cbefrafan#include <nc_tparm.h>
1309f9e55frafan
1317dbeededelphij#include <nc_string.h>
132bacd15cpeter#include <nc_alloc.h>
133f52ca6ebapt
1349f9e55frafan#if HAVE_NC_FREEALL
1359f9e55frafan#undef ExitProgram
1369f9e55frafan#ifdef USE_LIBTINFO
137f52ca6ebapt#define ExitProgram(code) exit_terminfo(code)
1389f9e55frafan#else
1399f9e55frafan#define ExitProgram(code) _nc_free_tic(code)
1409f9e55frafan#endif
1419f9e55frafan#endif
142bacd15cpeter
143f52ca6ebapt#define VtoTrace(opt) (unsigned) ((opt > 0) ? opt : (opt == 0))
144f52ca6ebapt
145f52ca6ebapt/* error-returns for tput */
146f52ca6ebapt#define ErrUsage	2
147f52ca6ebapt#define ErrTermType	3
148f52ca6ebapt#define ErrCapName	4
149f52ca6ebapt#define ErrSystem(n)	(4 + (n))
150f52ca6ebapt
151f52ca6ebapt#if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
152f52ca6ebapt#define IGNORE_RC(func) errno = (int) func
153f52ca6ebapt#else
154f52ca6ebapt#define IGNORE_RC(func) (void) func
155f52ca6ebapt#endif /* gcc workarounds */
156f52ca6ebapt
157bacd15cpeter/* usually in <unistd.h> */
158bacd15cpeter#ifndef STDOUT_FILENO
159bacd15cpeter#define STDOUT_FILENO 1
160bacd15cpeter#endif
161bacd15cpeter
162bacd15cpeter#ifndef STDERR_FILENO
163bacd15cpeter#define STDERR_FILENO 2
164bacd15cpeter#endif
165bacd15cpeter
166bacd15cpeter#ifndef EXIT_SUCCESS
167bacd15cpeter#define EXIT_SUCCESS 0
168bacd15cpeter#endif
169bacd15cpeter
170bacd15cpeter#ifndef EXIT_FAILURE
171bacd15cpeter#define EXIT_FAILURE 1
172bacd15cpeter#endif
173bacd15cpeter
174cc6a5ccpeter#ifndef R_OK
175cc6a5ccpeter#define	R_OK	4		/* Test for readable.  */
176cc6a5ccpeter#endif
177cc6a5ccpeter
178cc6a5ccpeter#ifndef W_OK
179cc6a5ccpeter#define	W_OK	2		/* Test for writable.  */
180cc6a5ccpeter#endif
181cc6a5ccpeter
182cc6a5ccpeter#ifndef X_OK
183cc6a5ccpeter#define	X_OK	1		/* Test for executable.  */
184cc6a5ccpeter#endif
185cc6a5ccpeter
186bacd15cpeter#ifndef F_OK
187bacd15cpeter#define	F_OK	0		/* Test for existence.  */
188bacd15cpeter#endif
189bacd15cpeter
190bacd15cpeter/* usually in <unistd.h> */
191bacd15cpeter#ifndef STDOUT_FILENO
192bacd15cpeter#define STDOUT_FILENO 1
193bacd15cpeter#endif
194bacd15cpeter
195bacd15cpeter#ifndef STDERR_FILENO
196bacd15cpeter#define STDERR_FILENO 2
197bacd15cpeter#endif
198bacd15cpeter
199bacd15cpeter/* may be in limits.h, included from various places */
200bacd15cpeter#ifndef PATH_MAX
201bacd15cpeter# if defined(_POSIX_PATH_MAX)
202bacd15cpeter#  define PATH_MAX _POSIX_PATH_MAX
203bacd15cpeter# elif defined(MAXPATHLEN)
204bacd15cpeter#  define PATH_MAX MAXPATHLEN
205bacd15cpeter# else
2067dbeededelphij#  define PATH_MAX 255		/* the Posix minimum pathsize */
207bacd15cpeter# endif
208bacd15cpeter#endif
209bacd15cpeter
210bacd15cpeter/* We use isascii only to guard against use of 7-bit ctype tables in the
211bacd15cpeter * isprint test in infocmp.
212bacd15cpeter */
213a81407apeter#if !HAVE_ISASCII
214bacd15cpeter# undef isascii
215bacd15cpeter# if ('z'-'a' == 25) && ('z' < 127) && ('Z'-'A' == 25) && ('Z' < 127) && ('9' < 127)
2169a7523dpeter#  define isascii(c) (UChar(c) <= 127)
217bacd15cpeter# else
2187dbeededelphij#  define isascii(c) 1		/* not really ascii anyway */
219bacd15cpeter# endif
220bacd15cpeter#endif
221a81407apeter
2229a7523dpeter#define UChar(c)    ((unsigned char)(c))
223b7ada7fpeter
224a81407apeter#define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
225f52ca6ebapt
226f52ca6ebapt#define NCURSES_EXT_NUMBERS (NCURSES_EXT_COLORS && HAVE_INIT_EXTENDED_COLOR)
227f52ca6ebapt
228f52ca6ebapt#if NCURSES_EXT_NUMBERS
229f52ca6ebapt#else
230f52ca6ebapt#define _nc_free_termtype2(t) _nc_free_termtype(t)
231f52ca6ebapt#define _nc_read_entry2(n,f,t) _nc_read_entry(n,f,t)
232f52ca6ebapt#endif
233f52ca6ebapt
234f52ca6ebapt#endif /* PROGS_PRIV_H */
235