]> git.saurik.com Git - bison.git/blob - src/system.h
(alloca): Remove; decl no longer needed.
[bison.git] / src / system.h
1 /* System-dependent definitions for Bison.
2 Copyright (C) 2000, 2001, 2002 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 Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #ifndef BISON_SYSTEM_H
19 #define BISON_SYSTEM_H
20
21 #if HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include <stddef.h>
26 #include <stdio.h>
27
28 /* Verify a requirement at compile-time (unlike assert, which is runtime). */
29 #define verify(name, assertion) struct name {char name[(assertion) ? 1 : -1];}
30
31 #if HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
35 #if HAVE_STDLIB_H
36 # include <stdlib.h>
37 #endif
38
39 /* The following test is to work around the gross typo in
40 systems like Sony NEWS-OS Release 4.0C, whereby EXIT_FAILURE
41 is defined to 0, not 1. */
42 #if !EXIT_FAILURE
43 # undef EXIT_FAILURE
44 # define EXIT_FAILURE 1
45 #endif
46
47 #ifndef EXIT_SUCCESS
48 # define EXIT_SUCCESS 0
49 #endif
50
51 #if HAVE_UNISTD_H
52 # include <unistd.h>
53 #endif
54
55 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
56 # include <string.h>
57 /* An ANSI string.h and pre-ANSI memory.h might conflict. */
58 # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
59 # include <memory.h>
60 # endif /* not STDC_HEADERS and HAVE_MEMORY_H */
61 #else /* not STDC_HEADERS and not HAVE_STRING_H */
62 # include <strings.h>
63 /* memory.h and strings.h conflict on some systems. */
64 #endif /* not STDC_HEADERS and not HAVE_STRING_H */
65
66 #include <limits.h>
67
68 #if HAVE_UINTPTR_T
69 # if HAVE_INTTYPES_H
70 # include <inttypes.h>
71 # else
72 # if HAVE_STDINT_H
73 # include <stdint.h>
74 # endif
75 # endif
76 #else
77 /* This isn't perfect, but it's good enough for Bison, which needs
78 only to hash pointers. */
79 typedef size_t uintptr_t;
80 #endif
81
82 #include <xalloc.h>
83 #define CALLOC(P, N) ((P) = xcalloc (N, sizeof *(P)))
84 #define MALLOC(P, N) ((P) = xmalloc ((N) * sizeof *(P)))
85 #define REALLOC(P, N) ((P) = xrealloc (P, (N) * sizeof *(P)))
86
87 /* From xstrndup.c. */
88 char *xstrndup (const char *s, size_t n);
89
90
91 /*---------------------.
92 | Missing prototypes. |
93 `---------------------*/
94
95 #if defined HAVE_DECL_STPCPY && !HAVE_DECL_STPCPY
96 char *stpcpy (char *dest, const char *src);
97 #endif
98
99 #if defined HAVE_DECL_STRCHR && !HAVE_DECL_STRCHR
100 char *strchr (const char *s, int c);
101 #endif
102
103 #if defined HAVE_DECL_STRSPN && !HAVE_DECL_STRSPN
104 size_t strspn (const char *s, const char *accept);
105 #endif
106
107 #if defined HAVE_DECL_STRNLEN && !HAVE_DECL_STRNLEN
108 size_t strnlen (const char *s, size_t maxlen);
109 #endif
110
111 #if defined HAVE_DECL_MEMCHR && !HAVE_DECL_MEMCHR
112 void *memchr (const void *s, int c, size_t n);
113 #endif
114
115 #if defined HAVE_DECL_MEMRCHR && !HAVE_DECL_MEMRCHR
116 void *memrchr (const void *s, int c, size_t n);
117 #endif
118
119
120
121 /*-----------------.
122 | GCC extensions. |
123 `-----------------*/
124
125 /* Use this to suppress gcc's `...may be used before initialized'
126 warnings. */
127 #ifdef lint
128 # define IF_LINT(Code) Code
129 #else
130 # define IF_LINT(Code) /* empty */
131 #endif
132
133 #ifndef __attribute__
134 /* This feature is available in gcc versions 2.5 and later. */
135 # if !defined (__GNUC__) || __GNUC__ < 2 || \
136 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
137 # define __attribute__(Spec) /* empty */
138 # endif
139 #endif
140
141 /* The __-protected variants of `format' and `printf' attributes
142 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
143 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
144 # define __format__ format
145 # define __printf__ printf
146 #endif
147
148 #ifndef ATTRIBUTE_NORETURN
149 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
150 #endif
151
152 #ifndef ATTRIBUTE_UNUSED
153 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
154 #endif
155
156 /*------.
157 | NLS. |
158 `------*/
159
160 #if HAVE_LOCALE_H
161 # include <locale.h>
162 #endif
163 #if !HAVE_SETLOCALE
164 # define setlocale(Category, Locale)
165 #endif
166
167 #include <gettext.h>
168 #define _(Msgid) gettext (Msgid)
169 #define N_(Msgid) (Msgid)
170
171
172 /*-------------------------------.
173 | Fix broken compilation flags. |
174 `-------------------------------*/
175
176 #ifndef LOCALEDIR
177 # define LOCALEDIR "/usr/local/share/locale"
178 #endif
179
180
181 /*-----------.
182 | Booleans. |
183 `-----------*/
184
185 #if HAVE_STDBOOL_H
186 # include <stdbool.h>
187 #else
188 typedef enum {false = 0, true = 1} bool;
189 #endif
190
191
192 /*-----------.
193 | Obstacks. |
194 `-----------*/
195
196 # define obstack_chunk_alloc xmalloc
197 # define obstack_chunk_free free
198 # include <obstack.h>
199
200 #define obstack_sgrow(Obs, Str) \
201 obstack_grow (Obs, Str, strlen (Str))
202
203 #define obstack_fgrow1(Obs, Format, Arg1) \
204 do { \
205 char buf[4096]; \
206 sprintf (buf, Format, Arg1); \
207 obstack_grow (Obs, buf, strlen (buf)); \
208 } while (0)
209
210 #define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
211 do { \
212 char buf[4096]; \
213 sprintf (buf, Format, Arg1, Arg2); \
214 obstack_grow (Obs, buf, strlen (buf)); \
215 } while (0)
216
217 #define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \
218 do { \
219 char buf[4096]; \
220 sprintf (buf, Format, Arg1, Arg2, Arg3); \
221 obstack_grow (Obs, buf, strlen (buf)); \
222 } while (0)
223
224 #define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
225 do { \
226 char buf[4096]; \
227 sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
228 obstack_grow (Obs, buf, strlen (buf)); \
229 } while (0)
230
231
232
233 /*-----------------------------------------.
234 | Extensions to use for the output files. |
235 `-----------------------------------------*/
236
237 #ifdef VMS
238 /* VMS. */
239 # define TAB_EXT "_tab"
240 # define OUTPUT_EXT ".output"
241 #else /* ! VMS */
242 # ifdef MSDOS
243 /* MS DOS. */
244 # define TAB_EXT "_tab"
245 # define OUTPUT_EXT ".out"
246 # else /* ! MSDOS */
247 /* Standard. */
248 # define TAB_EXT ".tab"
249 # define OUTPUT_EXT ".output"
250 # endif /* ! MSDOS */
251 #endif /* ! VMS */
252
253 #ifndef DEFAULT_TMPDIR
254 # define DEFAULT_TMPDIR "/tmp"
255 #endif
256
257
258
259 /*---------------------.
260 | Free a linked list. |
261 `---------------------*/
262
263 #define LIST_FREE(Type, List) \
264 do { \
265 Type *_node, *_next; \
266 for (_node = List; _node; _node = _next) \
267 { \
268 _next = _node->next; \
269 XFREE (_node); \
270 } \
271 } while (0)
272
273
274 /*---------------------------------------------.
275 | Debugging memory allocation (must be last). |
276 `---------------------------------------------*/
277
278 # if WITH_DMALLOC
279 # define DMALLOC_FUNC_CHECK
280 # include <dmalloc.h>
281 # endif /* WITH_DMALLOC */
282
283 #endif /* ! BISON_SYSTEM_H */