2 /* Copyright (C) 2000-2018 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 3 of the License, or
10 (at your option) any later version.
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
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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. */
31 #if defined(__MSDOS__) || defined(__EMX__) \
32 || (defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__))
34 /* Binary I/O nuisances. */
41 # define STDIN_FILENO 0
42 # define STDOUT_FILENO 1
43 # define STDERR_FILENO 2
48 # ifdef HAVE_PROCESS_H
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 # define access(p,m) _access(p,m)
69 # define SET_BINARY(f) do {if (!isatty(f)) setmode(f,O_BINARY);} while(0)
70 # define FOPEN_RB "rb"
71 # define FOPEN_WB "wb"
72 # define FOPEN_RWB "wb+"
75 # define O_BINARY (_O_BINARY)
79 /* The system shell. Groff assumes a Unixy shell, but non-Posix
80 systems don't have standard places where it lives, and might not
81 have it installed to begin with. We want to give them some leeway. */
83 # define getcwd(b,s) _getcwd2(b,s)
85 # define BSHELL (system_shell_name())
86 # define BSHELL_DASH_C (system_shell_dash_c())
87 # define IS_BSHELL(s) (is_system_shell(s))
90 /* The separator for directories in PATH and other environment
93 # define PATH_SEP_CHAR ';'
95 /* Characters that separate directories in a path name. */
96 # define DIR_SEPS "/\\:"
98 /* How to tell if the argument is an absolute file name. */
99 # define IS_ABSOLUTE(f) \
100 ((f)[0] == '/' || (f)[0] == '\\' || (f)[0] && (f)[1] == ':')
102 /* The executable extension. */
103 # define EXE_EXT ".exe"
105 /* Possible executable extensions. */
106 # define PATH_EXT ".com;.exe;.bat;.cmd"
108 /* The system null device. */
109 # define NULL_DEV "NUL"
111 /* The default place to create temporary files. */
114 # define P_tmpdir _P_tmpdir
116 # define P_tmpdir "c:/temp"
124 char * system_shell_name(void);
125 const char * system_shell_dash_c(void);
126 int is_system_shell(const char *);
133 #if defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__)
134 /* Win32 implementations which use the Microsoft runtime library
135 * are prone to hanging when a pipe reader quits with unread data in the pipe.
136 * 'gtroff' avoids this, by invoking 'FLUSH_INPUT_PIPE()', defined as ... */
137 # define FLUSH_INPUT_PIPE(fd) \
138 do if (!isatty(fd)) \
140 char drain[BUFSIZ]; \
141 while (read(fd, drain, sizeof(drain)) > 0) \
145 /* The Microsoft runtime library also has a broken argument passing mechanism,
146 * which may result in improper grouping of arguments passed to a child process
147 * by the 'spawn()' family of functions. In 'groff', only the 'spawnvp()'
148 * function is affected; we work around this defect, by substituting a
149 * wrapper function in place of 'spawnvp()' calls. */
154 int spawnvp_wrapper(int, char *, char **);
158 # ifndef SPAWN_FUNCTION_WRAPPERS
160 # define spawnvp spawnvp_wrapper
162 # define _spawnvp spawnvp
163 # endif /* SPAWN_FUNCTION_WRAPPERS */
166 /* Other implementations do not suffer from Microsoft runtime bugs,
167 * but 'gtroff' requires a dummy definition for FLUSH_INPUT_PIPE() */
168 # define FLUSH_INPUT_PIPE(fd) do {} while(0)
171 /* Defaults, for Posix systems. */
174 # define SET_BINARY(f) do {} while(0)
177 # define FOPEN_RB "r"
180 # define FOPEN_WB "w"
183 # define FOPEN_RWB "w+"
186 # define POPEN_RT "r"
189 # define POPEN_WT "w"
195 # define BSHELL "/bin/sh"
197 #ifndef BSHELL_DASH_C
198 # define BSHELL_DASH_C "-c"
201 # define IS_BSHELL(s) ((s) && strcmp(s,BSHELL) == 0)
204 # define PATH_SEP ":"
205 # define PATH_SEP_CHAR ':'
208 # define DIR_SEPS "/"
211 # define IS_ABSOLUTE(f) ((f)[0] == '/')
220 # define NULL_DEV "/dev/null"
223 # define GS_NAME "gs"
226 # define WAIT(s,p,m) wait(s)
229 # define _WAIT_CHILD 0