xref: /freebsd/contrib/ncurses/progs/progs.priv.h (revision 02e9120893770924227138ba49df1edb3896112a)
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.52 2020/09/05 19:35:06 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_LIMITS_H
62 # include <limits.h>
63 #elif HAVE_SYS_PARAM_H
64 # include <sys/param.h>
65 #endif
66 
67 #if HAVE_DIRENT_H
68 # include <dirent.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
73 #  else
74 #   define	DIRENT	struct dirent
75 #  endif
76 # else
77 #  define	DIRENT	struct dirent
78 # endif
79 #else
80 # define DIRENT struct direct
81 # define NAMLEN(dirent) (dirent)->d_namlen
82 # if HAVE_SYS_NDIR_H
83 #  include <sys/ndir.h>
84 # endif
85 # if HAVE_SYS_DIR_H
86 #  include <sys/dir.h>
87 # endif
88 # if HAVE_NDIR_H
89 #  include <ndir.h>
90 # endif
91 #endif
92 
93 #if HAVE_INTTYPES_H
94 # include <inttypes.h>
95 #else
96 # if HAVE_STDINT_H
97 #  include <stdint.h>
98 # endif
99 #endif
100 
101 #include <assert.h>
102 #include <errno.h>
103 
104 #if DECL_ERRNO
105 extern int errno;
106 #endif
107 
108 #if HAVE_GETOPT_H
109 #include <getopt.h>
110 #elif !defined(HAVE_GETOPT_HEADER)
111 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its
112  * variables doesn't hurt.
113  */
114 extern char *optarg;
115 extern int optind;
116 #endif /* HAVE_GETOPT_H */
117 
118 #undef _NC_WINDOWS
119 #if (defined(_WIN32) || defined(_WIN64))
120 #define _NC_WINDOWS 1
121 #endif
122 
123 #define NCURSES_INTERNALS 1
124 #define NCURSES_OPAQUE    0
125 
126 #include <curses.h>
127 
128 #if !(defined(NCURSES_WGETCH_EVENTS) && defined(NEED_KEY_EVENT))
129 #undef KEY_EVENT		/* reduce compiler-warnings with Visual C++ */
130 #endif
131 
132 #include <term_entry.h>
133 #include <nc_termios.h>
134 #include <tic.h>
135 #include <nc_tparm.h>
136 
137 #include <nc_string.h>
138 #include <nc_alloc.h>
139 
140 #if HAVE_NC_FREEALL
141 #undef ExitProgram
142 #ifdef USE_LIBTINFO
143 #define ExitProgram(code) exit_terminfo(code)
144 #else
145 #define ExitProgram(code) _nc_free_tic(code)
146 #endif
147 #endif
148 
149 #define VtoTrace(opt) (unsigned) ((opt > 0) ? opt : (opt == 0))
150 
151 /* error-returns for tput */
152 #define ErrUsage	2
153 #define ErrTermType	3
154 #define ErrCapName	4
155 #define ErrSystem(n)	(4 + (n))
156 
157 #if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
158 #define IGNORE_RC(func) errno = (int) func
159 #else
160 #define IGNORE_RC(func) (void) func
161 #endif /* gcc workarounds */
162 
163 /* usually in <unistd.h> */
164 #ifndef STDIN_FILENO
165 #define STDIN_FILENO 0
166 #endif
167 
168 #ifndef STDOUT_FILENO
169 #define STDOUT_FILENO 1
170 #endif
171 
172 #ifndef STDERR_FILENO
173 #define STDERR_FILENO 2
174 #endif
175 
176 #ifndef EXIT_SUCCESS
177 #define EXIT_SUCCESS 0
178 #endif
179 
180 #ifndef EXIT_FAILURE
181 #define EXIT_FAILURE 1
182 #endif
183 
184 #ifndef R_OK
185 #define	R_OK	4		/* Test for readable.  */
186 #endif
187 
188 #ifndef W_OK
189 #define	W_OK	2		/* Test for writable.  */
190 #endif
191 
192 #ifndef X_OK
193 #define	X_OK	1		/* Test for executable.  */
194 #endif
195 
196 #ifndef F_OK
197 #define	F_OK	0		/* Test for existence.  */
198 #endif
199 
200 /* usually in <unistd.h> */
201 #ifndef STDOUT_FILENO
202 #define STDOUT_FILENO 1
203 #endif
204 
205 #ifndef STDERR_FILENO
206 #define STDERR_FILENO 2
207 #endif
208 
209 /* may be in limits.h, included from various places */
210 #ifndef PATH_MAX
211 # if defined(_POSIX_PATH_MAX)
212 #  define PATH_MAX _POSIX_PATH_MAX
213 # elif defined(MAXPATHLEN)
214 #  define PATH_MAX MAXPATHLEN
215 # else
216 #  define PATH_MAX 255		/* the Posix minimum pathsize */
217 # endif
218 #endif
219 
220 /* We use isascii only to guard against use of 7-bit ctype tables in the
221  * isprint test in infocmp.
222  */
223 #if !HAVE_ISASCII
224 # undef isascii
225 # if ('z'-'a' == 25) && ('z' < 127) && ('Z'-'A' == 25) && ('Z' < 127) && ('9' < 127)
226 #  define isascii(c) (UChar(c) <= 127)
227 # else
228 #  define isascii(c) 1		/* not really ascii anyway */
229 # endif
230 #endif
231 
232 #define UChar(c)    ((unsigned char)(c))
233 
234 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
235 
236 #define NCURSES_EXT_NUMBERS (NCURSES_EXT_COLORS && HAVE_INIT_EXTENDED_COLOR)
237 
238 #if NCURSES_EXT_NUMBERS
239 #else
240 #define _nc_free_termtype2(t) _nc_free_termtype(t)
241 #define _nc_read_entry2(n,f,t) _nc_read_entry(n,f,t)
242 #endif
243 
244 #endif /* PROGS_PRIV_H */
245