Grep: Add DragonFly README files
[dragonfly.git] / gnu / usr.bin / grep / system.h
1 /* Portability cruft.  Include after config.h and sys/types.h.
2    Copyright (C) 1996, 1998, 1999 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17    02111-1307, USA.  */
18
19 #undef PARAMS
20 #if defined (__STDC__) && __STDC__
21 # ifndef _PTR_T
22 # define _PTR_T
23   typedef void * ptr_t;
24 # endif
25 # define PARAMS(x) x
26 #else
27 # ifndef _PTR_T
28 # define _PTR_T
29   typedef char * ptr_t;
30 # endif
31 # define PARAMS(x) ()
32 #endif
33
34 #ifdef HAVE_UNISTD_H
35 # include <fcntl.h>
36 # include <unistd.h>
37 #else
38 # define O_RDONLY 0
39 # define SEEK_SET 0
40 # define SEEK_CUR 1
41 int open(), read(), close();
42 #endif
43
44 #include <errno.h>
45 #ifndef errno
46 extern int errno;
47 #endif
48
49 #ifndef HAVE_STRERROR
50 extern int sys_nerr;
51 extern char *sys_errlist[];
52 # define strerror(E) (0 <= (E) && (E) < sys_nerr ? _(sys_errlist[E]) : _("Unknown system error"))
53 #endif
54
55 /* Some operating systems treat text and binary files differently.  */
56 #if O_BINARY
57 # include <io.h>
58 # ifdef HAVE_SETMODE
59 #  define SET_BINARY(fd)  setmode (fd, O_BINARY)
60 # else
61 #  define SET_BINARY(fd)  _setmode (fd, O_BINARY)
62 # endif
63 #else
64 # ifndef O_BINARY
65 #  define O_BINARY 0
66 #  define SET_BINARY(fd)   (void)0
67 # endif
68 #endif
69
70 #ifdef HAVE_DOS_FILE_NAMES
71 # define IS_SLASH(c) ((c) == '/' || (c) == '\\')
72 # define FILESYSTEM_PREFIX_LEN(f) ((f)[0] && (f)[1] == ':' ? 2 : 0)
73 #endif
74
75 #ifndef IS_SLASH
76 # define IS_SLASH(c) ((c) == '/')
77 #endif
78
79 #ifndef FILESYSTEM_PREFIX_LEN
80 # define FILESYSTEM_PREFIX_LEN(f) 0
81 #endif
82
83 /* This assumes _WIN32, like DJGPP, has D_OK.  Does it?  In what header?  */
84 #ifdef D_OK
85 # ifdef EISDIR
86 #  define is_EISDIR(e, f) \
87      ((e) == EISDIR \
88       || ((e) == EACCES && access (f, D_OK) == 0 && ((e) = EISDIR, 1)))
89 # else
90 #  define is_EISDIR(e, f) ((e) == EACCES && access (f, D_OK) == 0)
91 # endif
92 #endif
93
94 #ifndef is_EISDIR
95 # ifdef EISDIR
96 #  define is_EISDIR(e, f) ((e) == EISDIR)
97 # else
98 #  define is_EISDIR(e, f) 0
99 # endif
100 #endif
101
102 #if STAT_MACROS_BROKEN
103 # undef S_ISDIR
104 # undef S_ISREG
105 #endif
106 #if !defined(S_ISDIR) && defined(S_IFDIR)
107 # define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
108 #endif
109 #if !defined(S_ISREG) && defined(S_IFREG)
110 # define S_ISREG(Mode) (((Mode) & S_IFMT) == S_IFREG)
111 #endif
112
113 #ifdef STDC_HEADERS
114 # include <stdlib.h>
115 #else
116 char *getenv ();
117 ptr_t malloc(), realloc(), calloc();
118 void free();
119 #endif
120
121 #if __STDC__
122 # include <stddef.h>
123 #endif
124 #ifdef STDC_HEADERS
125 # include <limits.h>
126 #endif
127 #ifndef CHAR_BIT
128 # define CHAR_BIT 8
129 #endif
130 /* The extra casts work around common compiler bugs.  */
131 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
132 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
133                               ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
134                               : (t) 0))
135 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
136 #ifndef CHAR_MAX
137 # define CHAR_MAX TYPE_MAXIMUM (char)
138 #endif
139 #ifndef INT_MAX
140 # define INT_MAX TYPE_MAXIMUM (int)
141 #endif
142 #ifndef UCHAR_MAX
143 # define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
144 #endif
145
146 #if !defined(STDC_HEADERS) && defined(HAVE_STRING_H) && defined(HAVE_MEMORY_H)
147 # include <memory.h>
148 #endif
149 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
150 # include <string.h>
151 #else
152 # include <strings.h>
153 # undef strchr
154 # define strchr index
155 # undef strrchr
156 # define strrchr rindex
157 # undef memcpy
158 # define memcpy(d, s, n) bcopy (s, d, n)
159 #endif
160 #ifndef HAVE_MEMCHR
161 ptr_t memchr();
162 #endif
163 #if ! defined HAVE_MEMMOVE && ! defined memmove
164 # define memmove(d, s, n) bcopy (s, d, n)
165 #endif
166
167 #include <ctype.h>
168
169 #ifndef isgraph
170 # define isgraph(C) (isprint(C) && !isspace(C))
171 #endif
172
173 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
174 # define IN_CTYPE_DOMAIN(c) 1
175 #else
176 # define IN_CTYPE_DOMAIN(c) isascii(c)
177 #endif
178
179 #define ISALPHA(C)      (IN_CTYPE_DOMAIN (C) && isalpha (C))
180 #define ISUPPER(C)      (IN_CTYPE_DOMAIN (C) && isupper (C))
181 #define ISLOWER(C)      (IN_CTYPE_DOMAIN (C) && islower (C))
182 #define ISDIGIT(C)      (IN_CTYPE_DOMAIN (C) && isdigit (C))
183 #define ISXDIGIT(C)     (IN_CTYPE_DOMAIN (C) && isxdigit (C))
184 #define ISSPACE(C)      (IN_CTYPE_DOMAIN (C) && isspace (C))
185 #define ISPUNCT(C)      (IN_CTYPE_DOMAIN (C) && ispunct (C))
186 #define ISALNUM(C)      (IN_CTYPE_DOMAIN (C) && isalnum (C))
187 #define ISPRINT(C)      (IN_CTYPE_DOMAIN (C) && isprint (C))
188 #define ISGRAPH(C)      (IN_CTYPE_DOMAIN (C) && isgraph (C))
189 #define ISCNTRL(C)      (IN_CTYPE_DOMAIN (C) && iscntrl (C))
190
191 #define TOLOWER(C) (ISUPPER(C) ? tolower(C) : (C))
192
193 #if ENABLE_NLS
194 # include <libintl.h>
195 # define _(String) gettext (String)
196 #else
197 # define _(String) String
198 #endif
199 #define N_(String) String
200
201 #if HAVE_SETLOCALE
202 # include <locale.h>
203 #endif
204
205 #ifndef initialize_main
206 #define initialize_main(argcp, argvp)
207 #endif