Add groff 1.19.1, stripped down appropriately.
[dragonfly.git] / contrib / groff-1.19 / src / include / nonposix.h
1 /* Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
2      Written by Eli Zaretskii (eliz@is.elta.co.il)
3
4 This file is part of groff.
5
6 groff is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 groff is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with groff; see the file COPYING.  If not, write to the Free Software
18 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 /* This header file compartmentalize all idiosyncrasies of non-Posix
21    systems, such as MS-DOS, MS-Windows, etc.  It should be loaded after
22    the system headers like stdio.h to protect against warnings and error
23    messages w.r.t. redefining macros. */
24
25 #if defined _MSC_VER
26 # ifndef _WIN32
27 #  define _WIN32
28 # endif
29 #endif
30
31 #if defined(__MSDOS__) || defined(__EMX__) \
32     || (defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__))
33
34 /* Binary I/O nuisances. */
35 # include <fcntl.h>
36 # include <io.h>
37 # ifdef HAVE_UNISTD_H
38 #  include <unistd.h>
39 # endif
40 # ifndef STDIN_FILENO
41 #  define STDIN_FILENO  0
42 #  define STDOUT_FILENO 1
43 #  define STDERR_FILENO 2
44 # endif
45 # ifdef HAVE_DIRECT_H
46 #  include <direct.h>
47 # endif
48 # ifdef HAVE_PROCESS_H
49 #  include <process.h>
50 # endif
51 # if defined(_MSC_VER) || defined(__MINGW32__)
52 #  define POPEN_RT      "rt"
53 #  define POPEN_WT      "wt"
54 #  define popen(c,m)    _popen(c,m)
55 #  define pclose(p)     _pclose(p)
56 #  define pipe(pfd)     _pipe((pfd),0,_O_BINARY|_O_NOINHERIT)
57 #  define mkdir(p,m)    _mkdir(p)
58 #  define setmode(f,m)  _setmode(f,m)
59 #  define WAIT(s,p,m)   _cwait(s,p,m)
60 #  define creat(p,m)    _creat(p,m)
61 #  define read(f,b,s)   _read(f,b,s)
62 #  define write(f,b,s)  _write(f,b,s)
63 #  define dup(f)        _dup(f)
64 #  define dup2(f1,f2)   _dup2(f1,f2)
65 #  define close(f)      _close(f)
66 #  define isatty(f)     _isatty(f)
67 # endif
68 # define SET_BINARY(f)  do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
69 # define FOPEN_RB       "rb"
70 # define FOPEN_WB       "wb"
71 # define FOPEN_RWB      "wb+"
72 # ifndef O_BINARY
73 #  ifdef _O_BINARY
74 #   define O_BINARY     (_O_BINARY)
75 #  endif
76 # endif
77
78 /* The system shell.  Groff assumes a Unixy shell, but non-Posix
79    systems don't have standard places where it lives, and might not
80    have it installed to begin with.  We want to give them some leeway.  */
81 # ifdef __EMX__
82 #  define getcwd(b,s)   _getcwd2(b,s)
83 # else
84 #  define BSHELL        (system_shell_name())
85 #  define BSHELL_DASH_C (system_shell_dash_c())
86 #  define IS_BSHELL(s)  (is_system_shell(s))
87 # endif
88
89 /* The separator for directories in PATH and other environment
90    variables.  */
91 # define PATH_SEP       ";"
92 # define PATH_SEP_CHAR  ';'
93
94 /* Characters that separate directories in a path name.  */
95 # define DIR_SEPS       "/\\:"
96
97 /* How to tell if the argument is an absolute file name.  */
98 # define IS_ABSOLUTE(f) \
99  ((f)[0] == '/' || (f)[0] == '\\' || (f)[0] && (f)[1] == ':')
100
101 /* The executable extension.  */
102 # define EXE_EXT        ".exe"
103
104 /* The system null device.  */
105 # define NULL_DEV       "NUL"
106
107 /* The default place to create temporary files.  */
108 # ifndef P_tmpdir
109 #  ifdef _P_tmpdir
110 #   define P_tmpdir     _P_tmpdir
111 #  else
112 #   define P_tmpdir     "c:/temp"
113 #  endif
114 # endif
115
116 /* Prototypes.  */
117 # ifdef __cplusplus
118   extern "C" {
119 # endif
120     char       * system_shell_name(void);
121     const char * system_shell_dash_c(void);
122     int          is_system_shell(const char *);
123 # ifdef __cplusplus
124   }
125 # endif
126
127 #endif
128
129 #if defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__)
130 /* Win32 implementations which use the Microsoft runtime library
131  * are prone to hanging when a pipe reader quits with unread data in the pipe.
132  * `gtroff' avoids this, by invoking `FLUSH_INPUT_PIPE()', defined as ... */
133 # define FLUSH_INPUT_PIPE(fd)                 \
134  do if (!isatty(fd))                          \
135  {                                            \
136    char drain[BUFSIZ];                        \
137    while (read(fd, drain, sizeof(drain)) > 0) \
138      ;                                        \
139  } while (0)
140
141 /* The Microsoft runtime library also has a broken argument passing mechanism,
142  * which may result in improper grouping of arguments passed to a child process
143  * by the `spawn()' family of functions.  In `groff', only the `spawnvp()'
144  * function is affected; we work around this defect, by substituting a
145  * wrapper function in place of `spawnvp()' calls. */
146
147 # ifdef __cplusplus
148   extern "C" {
149 # endif
150   int spawnvp_wrapper(int, char *, char **);
151 # ifdef __cplusplus
152   }
153 # endif
154 # ifndef SPAWN_FUNCTION_WRAPPERS
155 #  undef  spawnvp
156 #  define spawnvp      spawnvp_wrapper
157 #  undef  _spawnvp
158 #  define _spawnvp     spawnvp
159 # endif /* SPAWN_FUNCTION_WRAPPERS */
160
161 #else
162 /* Other implementations do not suffer from Microsoft runtime bugs,
163  * but `gtroff' requires a dummy definition for FLUSH_INPUT_PIPE() */
164 # define FLUSH_INPUT_PIPE(fd)   do {} while(0)
165 #endif
166
167 /* Defaults, for Posix systems.  */
168
169 #ifndef SET_BINARY
170 # define SET_BINARY(f)  do {} while(0)
171 #endif
172 #ifndef FOPEN_RB
173 # define FOPEN_RB       "r"
174 #endif
175 #ifndef FOPEN_WB
176 # define FOPEN_WB       "w"
177 #endif
178 #ifndef FOPEN_RWB
179 # define FOPEN_RWB      "w+"
180 #endif
181 #ifndef POPEN_RT
182 # define POPEN_RT       "r"
183 #endif
184 #ifndef POPEN_WT
185 # define POPEN_WT       "w"
186 #endif
187 #ifndef O_BINARY
188 # define O_BINARY       0
189 #endif
190 #ifndef BSHELL
191 # define BSHELL         "/bin/sh"
192 #endif
193 #ifndef BSHELL_DASH_C
194 # define BSHELL_DASH_C  "-c"
195 #endif
196 #ifndef IS_BSHELL
197 # define IS_BSHELL(s)   ((s) && strcmp(s,BSHELL) == 0)
198 #endif
199 #ifndef PATH_SEP
200 # define PATH_SEP       ":"
201 # define PATH_SEP_CHAR  ':'
202 #endif
203 #ifndef DIR_SEPS
204 # define DIR_SEPS       "/"
205 #endif
206 #ifndef IS_ABSOLUTE
207 # define IS_ABSOLUTE(f) ((f)[0] == '/')
208 #endif
209 #ifndef EXE_EXT
210 # define EXE_EXT        ""
211 #endif
212 #ifndef NULL_DEV
213 # define NULL_DEV       "/dev/null"
214 #endif
215 #ifndef GS_NAME
216 # define GS_NAME        "gs"
217 #endif
218 #ifndef WAIT
219 # define WAIT(s,p,m)    wait(s)
220 #endif
221 #ifndef _WAIT_CHILD
222 # define _WAIT_CHILD    0
223 #endif