]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - gnu/usr.bin/grep/system.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / gnu / usr.bin / grep / system.h
1 /* Portability cruft.  Include after config.h and sys/types.h.
2    Copyright 1996, 1998, 1999, 2000 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 #ifdef __BEOS__
57 # undef O_BINARY /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
58 #endif
59 #ifdef HAVE_DOS_FILE_CONTENTS
60 # include <io.h>
61 # ifdef HAVE_SETMODE
62 #  define SET_BINARY(fd)  setmode (fd, O_BINARY)
63 # else
64 #  define SET_BINARY(fd)  _setmode (fd, O_BINARY)
65 # endif
66 #endif
67
68 #ifdef HAVE_DOS_FILE_NAMES
69 # define IS_SLASH(c) ((c) == '/' || (c) == '\\')
70 # define FILESYSTEM_PREFIX_LEN(f) ((f)[0] && (f)[1] == ':' ? 2 : 0)
71 #endif
72
73 #ifndef IS_SLASH
74 # define IS_SLASH(c) ((c) == '/')
75 #endif
76
77 #ifndef FILESYSTEM_PREFIX_LEN
78 # define FILESYSTEM_PREFIX_LEN(f) 0
79 #endif
80
81 int isdir PARAMS ((char const *));
82
83 #ifdef HAVE_DIR_EACCES_BUG
84 # ifdef EISDIR
85 #  define is_EISDIR(e, f) \
86      ((e) == EISDIR \
87       || ((e) == EACCES && isdir (f) && ((e) = EISDIR, 1)))
88 # else
89 #  define is_EISDIR(e, f) ((e) == EACCES && isdir (f))
90 # endif
91 #endif
92
93 #ifndef is_EISDIR
94 # ifdef EISDIR
95 #  define is_EISDIR(e, f) ((e) == EISDIR)
96 # else
97 #  define is_EISDIR(e, f) 0
98 # endif
99 #endif
100
101 #if STAT_MACROS_BROKEN
102 # undef S_ISDIR
103 # undef S_ISREG
104 #endif
105 #if !defined(S_ISDIR) && defined(S_IFDIR)
106 # define S_ISDIR(Mode) (((Mode) & S_IFMT) == S_IFDIR)
107 #endif
108 #if !defined(S_ISREG) && defined(S_IFREG)
109 # define S_ISREG(Mode) (((Mode) & S_IFMT) == S_IFREG)
110 #endif
111
112 #ifdef STDC_HEADERS
113 # include <stdlib.h>
114 #else
115 char *getenv ();
116 ptr_t malloc(), realloc(), calloc();
117 void free();
118 #endif
119
120 #if __STDC__
121 # include <stddef.h>
122 #endif
123 #ifdef STDC_HEADERS
124 # include <limits.h>
125 #endif
126 #ifndef CHAR_BIT
127 # define CHAR_BIT 8
128 #endif
129 /* The extra casts work around common compiler bugs.  */
130 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
131 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
132                               ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
133                               : (t) 0))
134 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
135 #ifndef CHAR_MAX
136 # define CHAR_MAX TYPE_MAXIMUM (char)
137 #endif
138 #ifndef INT_MAX
139 # define INT_MAX TYPE_MAXIMUM (int)
140 #endif
141 #ifndef UCHAR_MAX
142 # define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
143 #endif
144
145 #if !defined(STDC_HEADERS) && defined(HAVE_STRING_H) && defined(HAVE_MEMORY_H)
146 # include <memory.h>
147 #endif
148 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
149 # include <string.h>
150 #else
151 # include <strings.h>
152 # undef strchr
153 # define strchr index
154 # undef strrchr
155 # define strrchr rindex
156 # undef memcpy
157 # define memcpy(d, s, n) bcopy (s, d, n)
158 #endif
159 #ifndef HAVE_MEMCHR
160 ptr_t memchr();
161 #endif
162 #if ! defined HAVE_MEMMOVE && ! defined memmove
163 # define memmove(d, s, n) bcopy (s, d, n)
164 #endif
165
166 #include <ctype.h>
167
168 #ifndef isgraph
169 # define isgraph(C) (isprint(C) && !isspace(C))
170 #endif
171
172 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
173 # define IN_CTYPE_DOMAIN(c) 1
174 #else
175 # define IN_CTYPE_DOMAIN(c) isascii(c)
176 #endif
177
178 #define ISALPHA(C)      (IN_CTYPE_DOMAIN (C) && isalpha (C))
179 #define ISUPPER(C)      (IN_CTYPE_DOMAIN (C) && isupper (C))
180 #define ISLOWER(C)      (IN_CTYPE_DOMAIN (C) && islower (C))
181 #define ISDIGIT(C)      (IN_CTYPE_DOMAIN (C) && isdigit (C))
182 #define ISXDIGIT(C)     (IN_CTYPE_DOMAIN (C) && isxdigit (C))
183 #define ISSPACE(C)      (IN_CTYPE_DOMAIN (C) && isspace (C))
184 #define ISPUNCT(C)      (IN_CTYPE_DOMAIN (C) && ispunct (C))
185 #define ISALNUM(C)      (IN_CTYPE_DOMAIN (C) && isalnum (C))
186 #define ISPRINT(C)      (IN_CTYPE_DOMAIN (C) && isprint (C))
187 #define ISGRAPH(C)      (IN_CTYPE_DOMAIN (C) && isgraph (C))
188 #define ISCNTRL(C)      (IN_CTYPE_DOMAIN (C) && iscntrl (C))
189
190 #define TOLOWER(C) (ISUPPER(C) ? tolower(C) : (C))
191
192 #if ENABLE_NLS
193 # include <libintl.h>
194 # define _(String) gettext (String)
195 #else
196 # define _(String) String
197 #endif
198 #define N_(String) String
199
200 #if HAVE_SETLOCALE
201 # include <locale.h>
202 #endif
203
204 #ifndef initialize_main
205 #define initialize_main(argcp, argvp)
206 #endif