3 /* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005
4 Free Software Foundation, Inc.
5 Written by Eli Zaretskii (eliz@is.elta.co.il)
7 This file is part of groff.
9 groff is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 groff is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License along
20 with groff; see the file COPYING. If not, write to the Free Software
21 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
23 /* This header file compartmentalize all idiosyncrasies of non-Posix
24 systems, such as MS-DOS, MS-Windows, etc. It should be loaded after
25 the system headers like stdio.h to protect against warnings and error
26 messages w.r.t. redefining macros. */
34 #if defined(__MSDOS__) || defined(__EMX__) \
35 || (defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__))
37 /* Binary I/O nuisances. */
44 # define STDIN_FILENO 0
45 # define STDOUT_FILENO 1
46 # define STDERR_FILENO 2
51 # ifdef HAVE_PROCESS_H
54 # if defined(_MSC_VER) || defined(__MINGW32__)
55 # define POPEN_RT "rt"
56 # define POPEN_WT "wt"
57 # define popen(c,m) _popen(c,m)
58 # define pclose(p) _pclose(p)
59 # define pipe(pfd) _pipe((pfd),0,_O_BINARY|_O_NOINHERIT)
60 # define mkdir(p,m) _mkdir(p)
61 # define setmode(f,m) _setmode(f,m)
62 # define WAIT(s,p,m) _cwait(s,p,m)
63 # define creat(p,m) _creat(p,m)
64 # define read(f,b,s) _read(f,b,s)
65 # define write(f,b,s) _write(f,b,s)
66 # define dup(f) _dup(f)
67 # define dup2(f1,f2) _dup2(f1,f2)
68 # define close(f) _close(f)
69 # define isatty(f) _isatty(f)
70 # define access(p,m) _access(p,m)
72 # define SET_BINARY(f) do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
73 # define FOPEN_RB "rb"
74 # define FOPEN_WB "wb"
75 # define FOPEN_RWB "wb+"
78 # define O_BINARY (_O_BINARY)
82 /* The system shell. Groff assumes a Unixy shell, but non-Posix
83 systems don't have standard places where it lives, and might not
84 have it installed to begin with. We want to give them some leeway. */
86 # define getcwd(b,s) _getcwd2(b,s)
88 # define BSHELL (system_shell_name())
89 # define BSHELL_DASH_C (system_shell_dash_c())
90 # define IS_BSHELL(s) (is_system_shell(s))
93 /* The separator for directories in PATH and other environment
96 # define PATH_SEP_CHAR ';'
98 /* Characters that separate directories in a path name. */
99 # define DIR_SEPS "/\\:"
101 /* How to tell if the argument is an absolute file name. */
102 # define IS_ABSOLUTE(f) \
103 ((f)[0] == '/' || (f)[0] == '\\' || (f)[0] && (f)[1] == ':')
105 /* The executable extension. */
106 # define EXE_EXT ".exe"
108 /* Possible executable extensions. */
109 # define PATH_EXT ".com;.exe;.bat;.cmd"
111 /* The system null device. */
112 # define NULL_DEV "NUL"
114 /* The default place to create temporary files. */
117 # define P_tmpdir _P_tmpdir
119 # define P_tmpdir "c:/temp"
127 char * system_shell_name(void);
128 const char * system_shell_dash_c(void);
129 int is_system_shell(const char *);
136 #if defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__)
137 /* Win32 implementations which use the Microsoft runtime library
138 * are prone to hanging when a pipe reader quits with unread data in the pipe.
139 * `gtroff' avoids this, by invoking `FLUSH_INPUT_PIPE()', defined as ... */
140 # define FLUSH_INPUT_PIPE(fd) \
141 do if (!isatty(fd)) \
143 char drain[BUFSIZ]; \
144 while (read(fd, drain, sizeof(drain)) > 0) \
148 /* The Microsoft runtime library also has a broken argument passing mechanism,
149 * which may result in improper grouping of arguments passed to a child process
150 * by the `spawn()' family of functions. In `groff', only the `spawnvp()'
151 * function is affected; we work around this defect, by substituting a
152 * wrapper function in place of `spawnvp()' calls. */
157 int spawnvp_wrapper(int, char *, char **);
161 # ifndef SPAWN_FUNCTION_WRAPPERS
163 # define spawnvp spawnvp_wrapper
165 # define _spawnvp spawnvp
166 # endif /* SPAWN_FUNCTION_WRAPPERS */
169 /* Other implementations do not suffer from Microsoft runtime bugs,
170 * but `gtroff' requires a dummy definition for FLUSH_INPUT_PIPE() */
171 # define FLUSH_INPUT_PIPE(fd) do {} while(0)
174 /* Defaults, for Posix systems. */
177 # define SET_BINARY(f) do {} while(0)
180 # define FOPEN_RB "r"
183 # define FOPEN_WB "w"
186 # define FOPEN_RWB "w+"
189 # define POPEN_RT "r"
192 # define POPEN_WT "w"
198 # define BSHELL "/bin/sh"
200 #ifndef BSHELL_DASH_C
201 # define BSHELL_DASH_C "-c"
204 # define IS_BSHELL(s) ((s) && strcmp(s,BSHELL) == 0)
207 # define PATH_SEP ":"
208 # define PATH_SEP_CHAR ':'
211 # define DIR_SEPS "/"
214 # define IS_ABSOLUTE(f) ((f)[0] == '/')
223 # define NULL_DEV "/dev/null"
226 # define GS_NAME "gs"
229 # define WAIT(s,p,m) wait(s)
232 # define _WAIT_CHILD 0