1 /* Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
2 Written by Eli Zaretskii (eliz@is.elta.co.il)
4 This file is part of groff.
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
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
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. */
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)
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+"
74 # define O_BINARY (_O_BINARY)
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. */
82 # define getcwd(b,s) _getcwd2(b,s)
84 # define BSHELL (system_shell_name())
85 # define BSHELL_DASH_C (system_shell_dash_c())
86 # define IS_BSHELL(s) (is_system_shell(s))
89 /* The separator for directories in PATH and other environment
92 # define PATH_SEP_CHAR ';'
94 /* Characters that separate directories in a path name. */
95 # define DIR_SEPS "/\\:"
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] == ':')
101 /* The executable extension. */
102 # define EXE_EXT ".exe"
104 /* The system null device. */
105 # define NULL_DEV "NUL"
107 /* The default place to create temporary files. */
110 # define P_tmpdir _P_tmpdir
112 # define P_tmpdir "c:/temp"
120 char * system_shell_name(void);
121 const char * system_shell_dash_c(void);
122 int is_system_shell(const char *);
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)) \
136 char drain[BUFSIZ]; \
137 while (read(fd, drain, sizeof(drain)) > 0) \
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. */
150 int spawnvp_wrapper(int, char *, char **);
154 # ifndef SPAWN_FUNCTION_WRAPPERS
156 # define spawnvp spawnvp_wrapper
158 # define _spawnvp spawnvp
159 # endif /* SPAWN_FUNCTION_WRAPPERS */
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)
167 /* Defaults, for Posix systems. */
170 # define SET_BINARY(f) do {} while(0)
173 # define FOPEN_RB "r"
176 # define FOPEN_WB "w"
179 # define FOPEN_RWB "w+"
182 # define POPEN_RT "r"
185 # define POPEN_WT "w"
191 # define BSHELL "/bin/sh"
193 #ifndef BSHELL_DASH_C
194 # define BSHELL_DASH_C "-c"
197 # define IS_BSHELL(s) ((s) && strcmp(s,BSHELL) == 0)
200 # define PATH_SEP ":"
201 # define PATH_SEP_CHAR ':'
204 # define DIR_SEPS "/"
207 # define IS_ABSOLUTE(f) ((f)[0] == '/')
213 # define NULL_DEV "/dev/null"
216 # define GS_NAME "gs"
219 # define WAIT(s,p,m) wait(s)
222 # define _WAIT_CHILD 0