Merge branch 'vendor/FILE'
[dragonfly.git] / contrib / texinfo / system.h
1 /* system.h: system-dependent declarations; include this first.
2    $Id: system.h,v 1.10 2008/07/26 17:13:26 karl Exp $
3
4    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5    2006, 2007, 2008 Free Software Foundation, Inc.
6
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 #ifndef TEXINFO_SYSTEM_H
21 #define TEXINFO_SYSTEM_H
22
23 #define _GNU_SOURCE
24
25 #include <config.h>
26
27 #ifdef MIKTEX
28 #include <gnu-miktex.h>
29 #define S_ISDIR(x) ((x)&_S_IFDIR) 
30 #else
31 /* MiKTeX defines substring() in a separate DLL, where it has its
32    own __declspec declaration.  We don't want to try to duplicate 
33    this Microsoft-ism here.  */
34 extern char *substring (const char *, const char *);
35 #endif
36
37 /* Assume ANSI C89 headers are available.  */
38 #include <locale.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <ctype.h>
43
44 /* Use POSIX headers.  If they are not available, we use the substitute
45    provided by gnulib.  */
46 #include <getopt.h>
47 #include <unistd.h>
48
49 /* For gettext (NLS).  */
50 #define const
51 #include "gettext.h"
52 #undef const
53
54 #define _(String) gettext (String)
55 #define N_(String) (String)
56
57 /* Additional gnulib includes.  */
58 #include "mbchar.h"
59 #include "mbswidth.h"
60 #include "xalloc.h"
61 #include "xsetenv.h"
62 #if HAVE_MBRTOWC
63 #include "mbiter.h"
64 #endif
65
66 #include <errno.h>
67 #ifndef errno
68 extern int errno;
69 #endif
70 #ifdef VMS
71 #include <perror.h>
72 #endif
73
74 #ifndef HAVE_DECL_STRERROR
75 extern char *strerror ();
76 #endif
77
78 #ifdef HAVE_LIMITS_H
79 #include <limits.h>
80 #endif
81 #ifndef PATH_MAX
82 #ifndef _POSIX_PATH_MAX
83 # define _POSIX_PATH_MAX 255
84 #endif
85 #define PATH_MAX _POSIX_PATH_MAX
86 #endif
87
88 #ifndef HAVE_DECL_STRCOLL
89 extern int strcoll ();
90 #endif
91
92 #include <sys/stat.h>
93 #if STAT_MACROS_BROKEN
94 # undef S_ISDIR
95 #endif
96 #if !defined(S_ISDIR) && defined(S_IFDIR)
97 # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
98 #endif
99
100 #ifdef HAVE_SYS_FILE_H
101 #include <sys/file.h>
102 #endif /* HAVE_SYS_FILE_H */
103
104 #ifndef O_RDONLY
105 /* Since <fcntl.h> is POSIX, prefer that to <sys/fcntl.h>.
106    This also avoids some useless warnings on (at least) Linux.  */
107 #ifdef HAVE_FCNTL_H
108 #include <fcntl.h>
109 #else /* not HAVE_FCNTL_H */
110 #ifdef HAVE_SYS_FCNTL_H
111 #include <sys/fcntl.h>
112 #endif /* not HAVE_SYS_FCNTL_H */
113 #endif /* not HAVE_FCNTL_H */
114 #endif /* not O_RDONLY */
115
116 /* MS-DOS and similar non-Posix systems have some peculiarities:
117     - they distinguish between binary and text files;
118     - they use both `/' and `\\' as directory separator in file names;
119     - they can have a drive letter X: prepended to a file name;
120     - they have a separate root directory on each drive;
121     - their filesystems are case-insensitive;
122     - directories in environment variables (like INFOPATH) are separated
123         by `;' rather than `:';
124     - text files can have their lines ended either with \n or with \r\n pairs;
125    These are all parameterized here except the last, which is
126    handled by the source code as appropriate (mostly, in info/).  */
127 #ifndef O_BINARY
128 # ifdef _O_BINARY
129 #  define O_BINARY _O_BINARY
130 # else
131 #  define O_BINARY 0
132 # endif
133 #endif /* O_BINARY */
134
135 /* We'd like to take advantage of _doprnt if it's around, a la error.c,
136    but then we'd have no VA_SPRINTF.  */
137 #if HAVE_VPRINTF
138 # if __STDC__
139 #  include <stdarg.h>
140 #  define VA_START(args, lastarg) va_start(args, lastarg)
141 # else
142 #  include <varargs.h>
143 #  define VA_START(args, lastarg) va_start(args)
144 # endif
145 # define VA_FPRINTF(file, fmt, ap) vfprintf (file, fmt, ap)
146 # define VA_SPRINTF(str, fmt, ap) vsprintf (str, fmt, ap)
147 #else /* not HAVE_VPRINTF */
148 # define VA_START(args, lastarg)
149 # define va_alist a1, a2, a3, a4, a5, a6, a7, a8
150 # define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
151 # define va_end(args)
152 #endif
153
154 #if O_BINARY
155 # ifdef HAVE_IO_H
156 #  include <io.h>
157 # endif
158 # ifdef __MSDOS__
159 #  include <limits.h>
160 #  ifdef __DJGPP__
161 #   define HAVE_LONG_FILENAMES(dir)  (pathconf (dir, _PC_NAME_MAX) > 12)
162 #   define NULL_DEVICE  "/dev/null"
163 #   define DEFAULT_INFOPATH "c:/djgpp/info;/usr/local/info;/usr/info;."
164     /* DJGPP supports /dev/null, which is okay for Unix aficionados,
165        shell scripts and Makefiles, but interactive DOS die-hards
166        would probably want to have NUL as well.  */
167 #   define ALSO_NULL_DEVICE  "NUL"
168 #  else  /* O_BINARY && !__DJGPP__ */
169 #   define HAVE_LONG_FILENAMES(dir)  (0)
170 #   define NULL_DEVICE  "NUL"
171 #  endif /* O_BINARY && !__DJGPP__ */
172 #  define SET_SCREEN_SIZE_HELPER terminal_prep_terminal()
173 #  define DEFAULT_INFO_PRINT_COMMAND ">PRN"
174 # else   /* O_BINARY && !__MSDOS__ */
175 #  define setmode(f,m)  _setmode(f,m)
176 #  define HAVE_LONG_FILENAMES(dir)   (1)
177 #  define NULL_DEVICE   "NUL"
178 # endif  /* O_BINARY && !__MSDOS__ */
179 # ifdef __CYGWIN__
180 #  define DEFAULT_TMPDIR        "/tmp/"
181 #  define PATH_SEP      ":"
182 #  define STRIP_DOT_EXE 0
183 #  undef NULL_DEVICE
184 #  define NULL_DEVICE "/dev/null"
185 #  define PIPE_USE_FORK 1
186 # else  /* O_BINARY && !__CYGWIN__ */
187 #  define DEFAULT_TMPDIR        "c:/"
188 #  define PATH_SEP      ";"
189 #  define STRIP_DOT_EXE 1
190 # endif /* O_BINARY && !__CYGWIN__ */
191   /* Back to any O_BINARY system.  */
192 # define FILENAME_CMP   mbscasecmp
193 # define FILENAME_CMPN  mbsncasecmp
194 # define FOPEN_RBIN     "rb"
195 # define FOPEN_WBIN     "wb"
196 # define HAVE_DRIVE(n)  ((n)[0] && (n)[1] == ':')
197 # define IS_SLASH(c)    ((c) == '/' || (c) == '\\')
198 # define IS_ABSOLUTE(n) (IS_SLASH((n)[0]) || HAVE_DRIVE(n))
199 # define PIPE_USE_FORK  0
200 # define SET_BINARY(f)  do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
201
202 #else  /* not O_BINARY, i.e., Unix */
203 # define SET_BINARY(f)  (void)0
204 # define FOPEN_RBIN     "r"
205 # define FOPEN_WBIN     "w"
206 # define IS_SLASH(c)    ((c) == '/')
207 # define HAVE_DRIVE(n)  (0)
208 # define IS_ABSOLUTE(n) ((n)[0] == '/')
209 # define FILENAME_CMP   strcmp
210 # define FILENAME_CMPN  strncmp
211 # define HAVE_LONG_FILENAMES(dir)   (1)
212 # define PATH_SEP       ":"
213 # define STRIP_DOT_EXE  0
214 # ifdef VMS
215 #  define DEFAULT_TMPDIR "sys$scratch:"
216 # else
217 #  define DEFAULT_TMPDIR "/tmp/"
218 # endif
219 # define NULL_DEVICE    "/dev/null"
220 # define PIPE_USE_FORK  1
221 #endif /* not O_BINARY */
222
223 /* Everything but DJGPP.  */
224 #ifndef ALSO_NULL_DEVICE
225 # define ALSO_NULL_DEVICE  ""
226 #endif
227
228 #ifdef HAVE_PWD_H
229 #include <pwd.h>
230 #endif
231 /* Some systems don't declare this function in pwd.h. */
232 struct passwd *getpwnam (const char *name);
233
234 /* Our library routines not included in any system library.  */
235 extern void *xmalloc (size_t), *xrealloc (void *, size_t);
236 extern char *xstrdup (const char *);
237 extern void xexit (int);
238
239 /* For convenience.  */
240 #define STREQ(s1,s2) (strcmp (s1, s2) == 0)
241 #define STRCASEEQ(s1,s2) (strcasecmp (s1, s2) == 0)
242 #define STRNCASEEQ(s1,s2,n) (strncasecmp (s1, s2, n) == 0)
243
244 /* We don't need anything fancy.  If we did need something fancy, gnulib
245    has it.  */
246 #ifdef MIN
247 #undef MIN
248 #endif
249 #define MIN(a,b) ((a) < (b) ? (a) : (b))
250 #ifdef MAX
251 #undef MAX
252 #endif
253 #define MAX(a,b) ((a) > (b) ? (a) : (b))
254
255 #ifdef DMALLOC_DEBUG
256 #define DMALLOC_FUNC_CHECK
257 #include "dmalloc.h"
258 #endif
259
260 #endif /* TEXINFO_SYSTEM_H */