]> ncurses.scripts.mit.edu Git - ncurses.git/blob - progs/progs.priv.h
ncurses 6.2 - patch 20200229
[ncurses.git] / progs / progs.priv.h
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.49 2020/02/29 20:57:36 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
109 extern 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  */
118 extern char *optarg;
119 extern 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 STDIN_FILENO
159 #define STDIN_FILENO 0
160 #endif
161
162 #ifndef STDOUT_FILENO
163 #define STDOUT_FILENO 1
164 #endif
165
166 #ifndef STDERR_FILENO
167 #define STDERR_FILENO 2
168 #endif
169
170 #ifndef EXIT_SUCCESS
171 #define EXIT_SUCCESS 0
172 #endif
173
174 #ifndef EXIT_FAILURE
175 #define EXIT_FAILURE 1
176 #endif
177
178 #ifndef R_OK
179 #define R_OK    4               /* Test for readable.  */
180 #endif
181
182 #ifndef W_OK
183 #define W_OK    2               /* Test for writable.  */
184 #endif
185
186 #ifndef X_OK
187 #define X_OK    1               /* Test for executable.  */
188 #endif
189
190 #ifndef F_OK
191 #define F_OK    0               /* Test for existence.  */
192 #endif
193
194 /* usually in <unistd.h> */
195 #ifndef STDOUT_FILENO
196 #define STDOUT_FILENO 1
197 #endif
198
199 #ifndef STDERR_FILENO
200 #define STDERR_FILENO 2
201 #endif
202
203 /* may be in limits.h, included from various places */
204 #ifndef PATH_MAX
205 # if defined(_POSIX_PATH_MAX)
206 #  define PATH_MAX _POSIX_PATH_MAX
207 # elif defined(MAXPATHLEN)
208 #  define PATH_MAX MAXPATHLEN
209 # else
210 #  define PATH_MAX 255          /* the Posix minimum pathsize */
211 # endif
212 #endif
213
214 /* We use isascii only to guard against use of 7-bit ctype tables in the
215  * isprint test in infocmp.
216  */
217 #if !HAVE_ISASCII
218 # undef isascii
219 # if ('z'-'a' == 25) && ('z' < 127) && ('Z'-'A' == 25) && ('Z' < 127) && ('9' < 127)
220 #  define isascii(c) (UChar(c) <= 127)
221 # else
222 #  define isascii(c) 1          /* not really ascii anyway */
223 # endif
224 #endif
225
226 #define UChar(c)    ((unsigned char)(c))
227
228 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
229
230 #define NCURSES_EXT_NUMBERS (NCURSES_EXT_COLORS && HAVE_INIT_EXTENDED_COLOR)
231
232 #if NCURSES_EXT_NUMBERS
233 #else
234 #define _nc_free_termtype2(t) _nc_free_termtype(t)
235 #define _nc_read_entry2(n,f,t) _nc_read_entry(n,f,t)
236 #endif
237
238 #endif /* PROGS_PRIV_H */