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