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