xref: /openbsd/usr.bin/tic/progs.priv.h (revision 898184e3)
1 /* $OpenBSD: progs.priv.h,v 1.9 2010/01/12 23:22:14 nicm Exp $ */
2 
3 /****************************************************************************
4  * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30 
31 /****************************************************************************
32  *  Author: Thomas E. Dickey                    1997-on                     *
33  ****************************************************************************/
34 /*
35  * $Id: progs.priv.h,v 1.9 2010/01/12 23:22:14 nicm Exp $
36  *
37  *	progs.priv.h
38  *
39  *	Header file for curses utility programs
40  */
41 
42 #include <ncurses_cfg.h>
43 
44 #if USE_RCS_IDS
45 #define MODULE_ID(id) static const char Ident[] = id;
46 #else
47 #define MODULE_ID(id) /*nothing*/
48 #endif
49 
50 #include <stdlib.h>
51 #include <ctype.h>
52 #include <string.h>
53 #include <sys/types.h>
54 
55 #if HAVE_UNISTD_H
56 #include <unistd.h>
57 #endif
58 
59 #if HAVE_SYS_BSDTYPES_H
60 #include <sys/bsdtypes.h>	/* needed for ISC */
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 #include <assert.h>
96 #include <errno.h>
97 
98 #if DECL_ERRNO
99 extern int errno;
100 #endif
101 
102 #if HAVE_GETOPT_H
103 #include <getopt.h>
104 #else
105 /* 'getopt()' may be prototyped in <stdlib.h>, but declaring its
106  * variables doesn't hurt.
107  */
108 extern char *optarg;
109 extern int optind;
110 #endif /* HAVE_GETOPT_H */
111 
112 #include <curses.h>
113 #include <term_entry.h>
114 #include <tic.h>
115 #include <nc_tparm.h>
116 
117 #include <nc_alloc.h>
118 #if HAVE_NC_FREEALL
119 #undef ExitProgram
120 #ifdef USE_LIBTINFO
121 #define ExitProgram(code) _nc_free_tinfo(code)
122 #else
123 #define ExitProgram(code) _nc_free_tic(code)
124 #endif
125 #endif
126 
127 /* usually in <unistd.h> */
128 #ifndef STDOUT_FILENO
129 #define STDOUT_FILENO 1
130 #endif
131 
132 #ifndef STDERR_FILENO
133 #define STDERR_FILENO 2
134 #endif
135 
136 #ifndef EXIT_SUCCESS
137 #define EXIT_SUCCESS 0
138 #endif
139 
140 #ifndef EXIT_FAILURE
141 #define EXIT_FAILURE 1
142 #endif
143 
144 #ifndef R_OK
145 #define	R_OK	4		/* Test for readable.  */
146 #endif
147 
148 #ifndef W_OK
149 #define	W_OK	2		/* Test for writable.  */
150 #endif
151 
152 #ifndef X_OK
153 #define	X_OK	1		/* Test for executable.  */
154 #endif
155 
156 #ifndef F_OK
157 #define	F_OK	0		/* Test for existence.  */
158 #endif
159 
160 /* usually in <unistd.h> */
161 #ifndef STDOUT_FILENO
162 #define STDOUT_FILENO 1
163 #endif
164 
165 #ifndef STDERR_FILENO
166 #define STDERR_FILENO 2
167 #endif
168 
169 /* may be in limits.h, included from various places */
170 #ifndef PATH_MAX
171 # if defined(_POSIX_PATH_MAX)
172 #  define PATH_MAX _POSIX_PATH_MAX
173 # elif defined(MAXPATHLEN)
174 #  define PATH_MAX MAXPATHLEN
175 # else
176 #  define PATH_MAX 255	/* the Posix minimum pathsize */
177 # endif
178 #endif
179 
180 /* We use isascii only to guard against use of 7-bit ctype tables in the
181  * isprint test in infocmp.
182  */
183 #if !HAVE_ISASCII
184 # undef isascii
185 # if ('z'-'a' == 25) && ('z' < 127) && ('Z'-'A' == 25) && ('Z' < 127) && ('9' < 127)
186 #  define isascii(c) (UChar(c) <= 127)
187 # else
188 #  define isascii(c) 1	/* not really ascii anyway */
189 # endif
190 #endif
191 
192 #define UChar(c)    ((unsigned char)(c))
193 
194 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
195