1 /* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005
2 Free Software Foundation, Inc.
3 Written by Eli Zaretskii (eliz@is.elta.co.il)
5 This file is part of groff.
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file COPYING. If not, write to the Free Software
19 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
21 /* This header file compartmentalize all idiosyncrasies of non-Posix
22 systems, such as MS-DOS, MS-Windows, etc. It should be loaded after
23 the system headers like stdio.h to protect against warnings and error
24 messages w.r.t. redefining macros. */
32 #if defined(__MSDOS__) || defined(__EMX__) \
33 || (defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__))
35 /* Binary I/O nuisances. */
42 # define STDIN_FILENO 0
43 # define STDOUT_FILENO 1
44 # define STDERR_FILENO 2
49 # ifdef HAVE_PROCESS_H
52 # if defined(_MSC_VER) || defined(__MINGW32__)
53 # define POPEN_RT "rt"
54 # define POPEN_WT "wt"
55 # define popen(c,m) _popen(c,m)
56 # define pclose(p) _pclose(p)
57 # define pipe(pfd) _pipe((pfd),0,_O_BINARY|_O_NOINHERIT)
58 # define mkdir(p,m) _mkdir(p)
59 # define setmode(f,m) _setmode(f,m)
60 # define WAIT(s,p,m) _cwait(s,p,m)
61 # define creat(p,m) _creat(p,m)
62 # define read(f,b,s) _read(f,b,s)
63 # define write(f,b,s) _write(f,b,s)
64 # define dup(f) _dup(f)
65 # define dup2(f1,f2) _dup2(f1,f2)
66 # define close(f) _close(f)
67 # define isatty(f) _isatty(f)
68 # define access(p,m) _access(p,m)
70 # define SET_BINARY(f) do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
71 # define FOPEN_RB "rb"
72 # define FOPEN_WB "wb"
73 # define FOPEN_RWB "wb+"
76 # define O_BINARY (_O_BINARY)
80 /* The system shell. Groff assumes a Unixy shell, but non-Posix
81 systems don't have standard places where it lives, and might not
82 have it installed to begin with. We want to give them some leeway. */
84 # define getcwd(b,s) _getcwd2(b,s)
86 # define BSHELL (system_shell_name())
87 # define BSHELL_DASH_C (system_shell_dash_c())
88 # define IS_BSHELL(s) (is_system_shell(s))
91 /* The separator for directories in PATH and other environment
94 # define PATH_SEP_CHAR ';'
96 /* Characters that separate directories in a path name. */
97 # define DIR_SEPS "/\\:"
99 /* How to tell if the argument is an absolute file name. */
100 # define IS_ABSOLUTE(f) \
101 ((f)[0] == '/' || (f)[0] == '\\' || (f)[0] && (f)[1] == ':')
103 /* The executable extension. */
104 # define EXE_EXT ".exe"
106 /* Possible executable extensions. */
107 # define PATH_EXT ".com;.exe;.bat;.cmd"
109 /* The system null device. */
110 # define NULL_DEV "NUL"
112 /* The default place to create temporary files. */
115 # define P_tmpdir _P_tmpdir
117 # define P_tmpdir "c:/temp"
125 char * system_shell_name(void);
126 const char * system_shell_dash_c(void);
127 int is_system_shell(const char *);
134 #if defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__)
135 /* Win32 implementations which use the Microsoft runtime library
136 * are prone to hanging when a pipe reader quits with unread data in the pipe.
137 * `gtroff' avoids this, by invoking `FLUSH_INPUT_PIPE()', defined as ... */
138 # define FLUSH_INPUT_PIPE(fd) \
139 do if (!isatty(fd)) \
141 char drain[BUFSIZ]; \
142 while (read(fd, drain, sizeof(drain)) > 0) \
146 /* The Microsoft runtime library also has a broken argument passing mechanism,
147 * which may result in improper grouping of arguments passed to a child process
148 * by the `spawn()' family of functions. In `groff', only the `spawnvp()'
149 * function is affected; we work around this defect, by substituting a
150 * wrapper function in place of `spawnvp()' calls. */
155 int spawnvp_wrapper(int, char *, char **);
159 # ifndef SPAWN_FUNCTION_WRAPPERS
161 # define spawnvp spawnvp_wrapper
163 # define _spawnvp spawnvp
164 # endif /* SPAWN_FUNCTION_WRAPPERS */
167 /* Other implementations do not suffer from Microsoft runtime bugs,
168 * but `gtroff' requires a dummy definition for FLUSH_INPUT_PIPE() */
169 # define FLUSH_INPUT_PIPE(fd) do {} while(0)
172 /* Defaults, for Posix systems. */
175 # define SET_BINARY(f) do {} while(0)
178 # define FOPEN_RB "r"
181 # define FOPEN_WB "w"
184 # define FOPEN_RWB "w+"
187 # define POPEN_RT "r"
190 # define POPEN_WT "w"
196 # define BSHELL "/bin/sh"
198 #ifndef BSHELL_DASH_C
199 # define BSHELL_DASH_C "-c"
202 # define IS_BSHELL(s) ((s) && strcmp(s,BSHELL) == 0)
205 # define PATH_SEP ":"
206 # define PATH_SEP_CHAR ':'
209 # define DIR_SEPS "/"
212 # define IS_ABSOLUTE(f) ((f)[0] == '/')
221 # define NULL_DEV "/dev/null"
224 # define GS_NAME "gs"
227 # define WAIT(s,p,m) wait(s)
230 # define _WAIT_CHILD 0