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