1 /****************************************************************************
2 * Copyright 2019-2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2015,2017 Free Software Foundation, Inc. *
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: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
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. *
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 *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Thomas E. Dickey 1997-on *
32 ****************************************************************************/
34 * $Id: progs.priv.h,v 1.58 2022/09/17 18:58:05 tom Exp $
38 * Header file for curses utility programs
42 #define PROGS_PRIV_H 1
44 #include <ncurses_cfg.h>
47 #define MODULE_ID(id) static const char Ident[] = id;
49 #define MODULE_ID(id) /*nothing */
55 #include <sys/types.h>
63 #elif HAVE_SYS_PARAM_H
64 # include <sys/param.h>
69 # define NAMLEN(dirent) strlen((dirent)->d_name)
70 # if defined(_FILE_OFFSET_BITS) && defined(HAVE_STRUCT_DIRENT64)
71 # if !defined(_LP64) && (_FILE_OFFSET_BITS == 64)
72 # define DIRENT struct dirent64
74 # define DIRENT struct dirent
77 # define DIRENT struct dirent
80 # define DIRENT struct direct
81 # define NAMLEN(dirent) (dirent)->d_namlen
83 # include <sys/ndir.h>
94 # include <inttypes.h>
110 #elif !defined(HAVE_GETOPT_HEADER)
111 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its
112 * variables doesn't hurt.
116 #endif /* HAVE_GETOPT_H */
119 #if (defined(_WIN32) || defined(_WIN64))
120 #define _NC_WINDOWS 1
123 #define NCURSES_INTERNALS 1
124 #define NCURSES_OPAQUE 0
128 #if !(defined(NCURSES_WGETCH_EVENTS) && defined(NEED_KEY_EVENT))
129 #undef KEY_EVENT /* reduce compiler-warnings with Visual C++ */
132 #include <term_entry.h>
133 #include <nc_termios.h>
135 #include <nc_tparm.h>
137 #include <nc_string.h>
138 #include <nc_alloc.h>
139 #include <nc_access.h>
144 #define ExitProgram(code) exit_terminfo(code)
146 #define ExitProgram(code) _nc_free_tic(code)
150 /* error-returns for tput */
152 #define ErrTermType 3
154 #define ErrSystem(n) (4 + (n))
156 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
157 #define IGNORE_RC(func) errno = (int) func
159 #define IGNORE_RC(func) (void) func
160 #endif /* gcc workarounds */
162 /* usually in <unistd.h> */
164 #define STDIN_FILENO 0
167 #ifndef STDOUT_FILENO
168 #define STDOUT_FILENO 1
171 #ifndef STDERR_FILENO
172 #define STDERR_FILENO 2
176 #define EXIT_SUCCESS 0
180 #define EXIT_FAILURE 1
184 #define R_OK 4 /* Test for readable. */
188 #define W_OK 2 /* Test for writable. */
192 #define X_OK 1 /* Test for executable. */
196 #define F_OK 0 /* Test for existence. */
199 /* usually in <unistd.h> */
200 #ifndef STDOUT_FILENO
201 #define STDOUT_FILENO 1
204 #ifndef STDERR_FILENO
205 #define STDERR_FILENO 2
208 /* may be in limits.h, included from various places */
210 # if defined(_POSIX_PATH_MAX)
211 # define PATH_MAX _POSIX_PATH_MAX
212 # elif defined(MAXPATHLEN)
213 # define PATH_MAX MAXPATHLEN
215 # define PATH_MAX 255 /* the Posix minimum pathsize */
219 /* We use isascii only to guard against use of 7-bit ctype tables in the
220 * isprint test in infocmp.
224 # if ('z'-'a' == 25) && ('z' < 127) && ('Z'-'A' == 25) && ('Z' < 127) && ('9' < 127)
225 # define isascii(c) (UChar(c) <= 127)
227 # define isascii(c) 1 /* not really ascii anyway */
231 #define UChar(c) ((unsigned char)(c))
233 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
235 #define VtoTrace(opt) (unsigned) ((opt > 0) ? opt : (opt == 0))
238 * If configured for tracing, the debug- and trace-output are merged together
239 * in the trace file for "upper" levels of the verbose option.
242 #define use_verbosity(level) do { \
243 set_trace_level(level); \
244 if (_nc_tracing > DEBUG_LEVEL(2)) \
245 _nc_tracing |= TRACE_MAXIMUM; \
246 else if (_nc_tracing == DEBUG_LEVEL(2)) \
247 _nc_tracing |= TRACE_ORDINARY; \
249 curses_trace(_nc_tracing); \
252 #define use_verbosity(level) do { set_trace_level(level); } while (0)
255 #define NCURSES_EXT_NUMBERS (NCURSES_EXT_COLORS && HAVE_INIT_EXTENDED_COLOR)
257 #if NCURSES_EXT_NUMBERS
259 #define _nc_free_termtype2(t) _nc_free_termtype(t)
260 #define _nc_read_entry2(n,f,t) _nc_read_entry(n,f,t)
263 #endif /* PROGS_PRIV_H */