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