]>
Commit | Line | Data |
---|---|---|
87aabbff | 1 | /* System-dependent definitions for Bison. |
45aa0550 | 2 | |
c21493b8 PE |
3 | Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free |
4 | Software Foundation, Inc. | |
a0f6b076 AD |
5 | |
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software Foundation, | |
0fb669f9 | 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
a0f6b076 | 19 | |
d968a24b JT |
20 | #ifndef BISON_SYSTEM_H |
21 | #define BISON_SYSTEM_H | |
22 | ||
c21493b8 PE |
23 | /* flex 2.5.31 gratutiously defines macros like INT8_MIN. But this |
24 | runs afoul of pre-C99 compilers that have <inttypes.h> or | |
25 | <stdint.h>, which are included below if available. It also runs | |
26 | afoul of pre-C99 compilers that define these macros in <limits.h>. */ | |
27 | #if ! defined __STDC_VERSION__ || __STDC_VERSION__ < 199901 | |
28 | # undef INT8_MIN | |
29 | # undef INT16_MIN | |
30 | # undef INT32_MIN | |
31 | # undef INT8_MAX | |
32 | # undef INT16_MAX | |
33 | # undef UINT8_MAX | |
34 | # undef INT32_MAX | |
35 | # undef UINT16_MAX | |
36 | # undef UINT32_MAX | |
37 | #endif | |
38 | ||
6e26ca8c | 39 | #include <limits.h> |
deedb0b7 | 40 | #include <stddef.h> |
6e26ca8c PE |
41 | #include <stdlib.h> |
42 | #include <string.h> | |
ceed8467 | 43 | |
27b0ffea AD |
44 | #if HAVE_SYS_TYPES_H |
45 | # include <sys/types.h> | |
46 | #endif | |
47 | ||
499daa50 | 48 | #if HAVE_UNISTD_H |
a0f6b076 | 49 | # include <unistd.h> |
7bb4d914 JT |
50 | #endif |
51 | ||
6e26ca8c PE |
52 | #if HAVE_INTTYPES_H |
53 | # include <inttypes.h> | |
54 | #endif | |
62a3e4f0 | 55 | |
cb48f191 PE |
56 | #include <stdint.h> |
57 | ||
58 | #ifndef UINTPTR_MAX | |
deedb0b7 PE |
59 | /* This isn't perfect, but it's good enough for Bison, which needs |
60 | only to hash pointers. */ | |
61 | typedef size_t uintptr_t; | |
62 | #endif | |
63 | ||
a4b36db4 | 64 | |
cb48f191 PE |
65 | /*---------. |
66 | | Gnulib. | | |
67 | `---------*/ | |
b77b9ee0 | 68 | |
1f65350a | 69 | #include <stpcpy.h> |
cb48f191 PE |
70 | #include <unlocked-io.h> |
71 | #include <verify.h> | |
72 | #include <xalloc.h> | |
7625ec2c | 73 | |
b77b9ee0 | 74 | |
a0f6b076 AD |
75 | /*-----------------. |
76 | | GCC extensions. | | |
77 | `-----------------*/ | |
78 | ||
48e28efa PE |
79 | /* Use this to suppress gcc's `...may be used before initialized' |
80 | warnings. */ | |
81 | #ifdef lint | |
82 | # define IF_LINT(Code) Code | |
83 | #else | |
84 | # define IF_LINT(Code) /* empty */ | |
85 | #endif | |
86 | ||
a0f6b076 AD |
87 | #ifndef __attribute__ |
88 | /* This feature is available in gcc versions 2.5 and later. */ | |
02650b7f PE |
89 | # if (! defined __GNUC__ || __GNUC__ < 2 \ |
90 | || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__) | |
a0f6b076 AD |
91 | # define __attribute__(Spec) /* empty */ |
92 | # endif | |
e9955c83 AD |
93 | #endif |
94 | ||
a0f6b076 AD |
95 | /* The __-protected variants of `format' and `printf' attributes |
96 | are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ | |
e9955c83 AD |
97 | #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) |
98 | # define __format__ format | |
99 | # define __printf__ printf | |
a0f6b076 AD |
100 | #endif |
101 | ||
e9955c83 AD |
102 | #ifndef ATTRIBUTE_NORETURN |
103 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | |
104 | #endif | |
105 | ||
106 | #ifndef ATTRIBUTE_UNUSED | |
107 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | |
108 | #endif | |
a0f6b076 | 109 | |
e9071366 AD |
110 | #define FUNCTION_PRINT() fprintf (stderr, "%s: ", __func__) |
111 | ||
a0f6b076 AD |
112 | /*------. |
113 | | NLS. | | |
114 | `------*/ | |
115 | ||
6e26ca8c | 116 | #include <locale.h> |
f2d78a99 | 117 | |
982cc302 | 118 | #include <gettext.h> |
e0327bc8 AD |
119 | #define _(Msgid) gettext (Msgid) |
120 | #define N_(Msgid) (Msgid) | |
f2d78a99 | 121 | |
a0f6b076 AD |
122 | |
123 | /*-------------------------------. | |
124 | | Fix broken compilation flags. | | |
125 | `-------------------------------*/ | |
126 | ||
8a278a04 | 127 | #ifndef LOCALEDIR |
a0f6b076 | 128 | # define LOCALEDIR "/usr/local/share/locale" |
8a278a04 | 129 | #endif |
d968a24b | 130 | |
ceed8467 | 131 | |
015acc48 AD |
132 | /*-----------. |
133 | | Booleans. | | |
134 | `-----------*/ | |
135 | ||
f61aad93 | 136 | #include <stdbool.h> |
8c7ebe49 AD |
137 | |
138 | ||
139 | /*-----------. | |
140 | | Obstacks. | | |
141 | `-----------*/ | |
142 | ||
04098407 PE |
143 | #define obstack_chunk_alloc xmalloc |
144 | #define obstack_chunk_free free | |
145 | #include <obstack.h> | |
8c7ebe49 | 146 | |
ff4423cc AD |
147 | #define obstack_sgrow(Obs, Str) \ |
148 | obstack_grow (Obs, Str, strlen (Str)) | |
8c7ebe49 AD |
149 | |
150 | #define obstack_fgrow1(Obs, Format, Arg1) \ | |
151 | do { \ | |
152 | char buf[4096]; \ | |
153 | sprintf (buf, Format, Arg1); \ | |
154 | obstack_grow (Obs, buf, strlen (buf)); \ | |
155 | } while (0) | |
dd60faec AD |
156 | |
157 | #define obstack_fgrow2(Obs, Format, Arg1, Arg2) \ | |
158 | do { \ | |
159 | char buf[4096]; \ | |
160 | sprintf (buf, Format, Arg1, Arg2); \ | |
161 | obstack_grow (Obs, buf, strlen (buf)); \ | |
162 | } while (0) | |
896fe5c1 AD |
163 | |
164 | #define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \ | |
165 | do { \ | |
166 | char buf[4096]; \ | |
167 | sprintf (buf, Format, Arg1, Arg2, Arg3); \ | |
168 | obstack_grow (Obs, buf, strlen (buf)); \ | |
169 | } while (0) | |
7de3329e | 170 | |
ff4423cc AD |
171 | #define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \ |
172 | do { \ | |
173 | char buf[4096]; \ | |
174 | sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \ | |
175 | obstack_grow (Obs, buf, strlen (buf)); \ | |
176 | } while (0) | |
177 | ||
7de3329e | 178 | |
7de3329e | 179 | |
381fb12e AD |
180 | /*-----------------------------------------. |
181 | | Extensions to use for the output files. | | |
182 | `-----------------------------------------*/ | |
7de3329e | 183 | |
deb63d81 PE |
184 | #ifndef OUTPUT_EXT |
185 | # define OUTPUT_EXT ".output" | |
186 | #endif | |
187 | ||
188 | #ifndef TAB_EXT | |
189 | # define TAB_EXT ".tab" | |
190 | #endif | |
55b96341 | 191 | |
381fb12e AD |
192 | #ifndef DEFAULT_TMPDIR |
193 | # define DEFAULT_TMPDIR "/tmp" | |
194 | #endif | |
195 | ||
196 | ||
197 | ||
381fb12e AD |
198 | /*---------------------. |
199 | | Free a linked list. | | |
200 | `---------------------*/ | |
201 | ||
300f275f AD |
202 | #define LIST_FREE(Type, List) \ |
203 | do { \ | |
204 | Type *_node, *_next; \ | |
205 | for (_node = List; _node; _node = _next) \ | |
206 | { \ | |
207 | _next = _node->next; \ | |
afbb696d | 208 | free (_node); \ |
300f275f AD |
209 | } \ |
210 | } while (0) | |
211 | ||
381fb12e | 212 | |
68cae94e PE |
213 | /* Assertions. <assert.h>'s assertions are too heavyweight, and can |
214 | be disabled too easily, so implement it separately here. */ | |
215 | #define assert(x) ((void) ((x) || (abort (), 0))) | |
216 | ||
217 | ||
381fb12e AD |
218 | /*---------------------------------------------. |
219 | | Debugging memory allocation (must be last). | | |
220 | `---------------------------------------------*/ | |
342b8b6e AD |
221 | |
222 | # if WITH_DMALLOC | |
223 | # define DMALLOC_FUNC_CHECK | |
224 | # include <dmalloc.h> | |
225 | # endif /* WITH_DMALLOC */ | |
226 | ||
a4b36db4 | 227 | #endif /* ! BISON_SYSTEM_H */ |