1/*	$NetBSD$	*/
2
3/* Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005
4   Free Software Foundation, Inc.
5     Written by Eli Zaretskii (eliz@is.elta.co.il)
6
7This file is part of groff.
8
9groff is free software; you can redistribute it and/or modify it under
10the terms of the GNU General Public License as published by the Free
11Software Foundation; either version 2, or (at your option) any later
12version.
13
14groff is distributed in the hope that it will be useful, but WITHOUT ANY
15WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17for more details.
18
19You should have received a copy of the GNU General Public License along
20with groff; see the file COPYING.  If not, write to the Free Software
21Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
22
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. */
27
28#if defined _MSC_VER
29# ifndef _WIN32
30#  define _WIN32
31# endif
32#endif
33
34#if defined(__MSDOS__) || defined(__EMX__) \
35    || (defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__))
36
37/* Binary I/O nuisances. */
38# include <fcntl.h>
39# include <io.h>
40# ifdef HAVE_UNISTD_H
41#  include <unistd.h>
42# endif
43# ifndef STDIN_FILENO
44#  define STDIN_FILENO	0
45#  define STDOUT_FILENO	1
46#  define STDERR_FILENO	2
47# endif
48# ifdef HAVE_DIRECT_H
49#  include <direct.h>
50# endif
51# ifdef HAVE_PROCESS_H
52#  include <process.h>
53# endif
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)
71# endif
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+"
76# ifndef O_BINARY
77#  ifdef _O_BINARY
78#   define O_BINARY	(_O_BINARY)
79#  endif
80# endif
81
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.  */
85# ifdef __EMX__
86#  define getcwd(b,s)	_getcwd2(b,s)
87# else
88#  define BSHELL	(system_shell_name())
89#  define BSHELL_DASH_C	(system_shell_dash_c())
90#  define IS_BSHELL(s)	(is_system_shell(s))
91# endif
92
93/* The separator for directories in PATH and other environment
94   variables.  */
95# define PATH_SEP	";"
96# define PATH_SEP_CHAR	';'
97
98/* Characters that separate directories in a path name.  */
99# define DIR_SEPS	"/\\:"
100
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] == ':')
104
105/* The executable extension.  */
106# define EXE_EXT	".exe"
107
108/* Possible executable extensions.  */
109# define PATH_EXT	".com;.exe;.bat;.cmd"
110
111/* The system null device.  */
112# define NULL_DEV	"NUL"
113
114/* The default place to create temporary files.  */
115# ifndef P_tmpdir
116#  ifdef _P_tmpdir
117#   define P_tmpdir	_P_tmpdir
118#  else
119#   define P_tmpdir	"c:/temp"
120#  endif
121# endif
122
123/* Prototypes.  */
124# ifdef __cplusplus
125  extern "C" {
126# endif
127    char       * system_shell_name(void);
128    const char * system_shell_dash_c(void);
129    int		 is_system_shell(const char *);
130# ifdef __cplusplus
131  }
132# endif
133
134#endif
135
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))			      \
142 {					      \
143   char drain[BUFSIZ];			      \
144   while (read(fd, drain, sizeof(drain)) > 0) \
145     ;					      \
146 } while (0)
147
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. */
153
154# ifdef __cplusplus
155  extern "C" {
156# endif
157  int spawnvp_wrapper(int, char *, char **);
158# ifdef __cplusplus
159  }
160# endif
161# ifndef SPAWN_FUNCTION_WRAPPERS
162#  undef  spawnvp
163#  define spawnvp      spawnvp_wrapper
164#  undef  _spawnvp
165#  define _spawnvp     spawnvp
166# endif /* SPAWN_FUNCTION_WRAPPERS */
167
168#else
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)
172#endif
173
174/* Defaults, for Posix systems.  */
175
176#ifndef SET_BINARY
177# define SET_BINARY(f)	do {} while(0)
178#endif
179#ifndef FOPEN_RB
180# define FOPEN_RB	"r"
181#endif
182#ifndef FOPEN_WB
183# define FOPEN_WB	"w"
184#endif
185#ifndef FOPEN_RWB
186# define FOPEN_RWB	"w+"
187#endif
188#ifndef POPEN_RT
189# define POPEN_RT	"r"
190#endif
191#ifndef POPEN_WT
192# define POPEN_WT	"w"
193#endif
194#ifndef O_BINARY
195# define O_BINARY	0
196#endif
197#ifndef BSHELL
198# define BSHELL		"/bin/sh"
199#endif
200#ifndef BSHELL_DASH_C
201# define BSHELL_DASH_C	"-c"
202#endif
203#ifndef IS_BSHELL
204# define IS_BSHELL(s)	((s) && strcmp(s,BSHELL) == 0)
205#endif
206#ifndef PATH_SEP
207# define PATH_SEP	":"
208# define PATH_SEP_CHAR	':'
209#endif
210#ifndef DIR_SEPS
211# define DIR_SEPS	"/"
212#endif
213#ifndef IS_ABSOLUTE
214# define IS_ABSOLUTE(f)	((f)[0] == '/')
215#endif
216#ifndef EXE_EXT
217# define EXE_EXT	""
218#endif
219#ifndef PATH_EXT
220# define PATH_EXT	""
221#endif
222#ifndef NULL_DEV
223# define NULL_DEV	"/dev/null"
224#endif
225#ifndef GS_NAME
226# define GS_NAME	"gs"
227#endif
228#ifndef WAIT
229# define WAIT(s,p,m)	wait(s)
230#endif
231#ifndef _WAIT_CHILD
232# define _WAIT_CHILD	0
233#endif
234