]>
Commit | Line | Data |
---|---|---|
87aabbff | 1 | /* System-dependent definitions for Bison. |
45aa0550 | 2 | |
6e26ca8c | 3 | Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. |
a0f6b076 AD |
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 | ||
d968a24b JT |
19 | #ifndef BISON_SYSTEM_H |
20 | #define BISON_SYSTEM_H | |
21 | ||
56100c60 | 22 | #if HAVE_CONFIG_H |
d968a24b JT |
23 | # include <config.h> |
24 | #endif | |
25 | ||
6e26ca8c | 26 | #include <limits.h> |
deedb0b7 | 27 | #include <stddef.h> |
ceed8467 | 28 | #include <stdio.h> |
6e26ca8c PE |
29 | #include <stdlib.h> |
30 | #include <string.h> | |
ceed8467 | 31 | |
87aabbff PE |
32 | /* Verify a requirement at compile-time (unlike assert, which is runtime). */ |
33 | #define verify(name, assertion) struct name {char name[(assertion) ? 1 : -1];} | |
340ef489 | 34 | |
27b0ffea AD |
35 | #if HAVE_SYS_TYPES_H |
36 | # include <sys/types.h> | |
37 | #endif | |
38 | ||
499daa50 | 39 | #if HAVE_UNISTD_H |
a0f6b076 | 40 | # include <unistd.h> |
7bb4d914 JT |
41 | #endif |
42 | ||
6e26ca8c PE |
43 | #if HAVE_INTTYPES_H |
44 | # include <inttypes.h> | |
45 | #endif | |
46 | #if HAVE_STDINT_H | |
47 | # include <stdint.h> | |
48 | #endif | |
62a3e4f0 | 49 | |
6e26ca8c | 50 | #if ! HAVE_UINTPTR_T |
deedb0b7 PE |
51 | /* This isn't perfect, but it's good enough for Bison, which needs |
52 | only to hash pointers. */ | |
53 | typedef size_t uintptr_t; | |
54 | #endif | |
55 | ||
982cc302 | 56 | #include <xalloc.h> |
deedb0b7 | 57 | #define CALLOC(P, N) ((P) = xcalloc (N, sizeof *(P))) |
1f65350a PE |
58 | #define MALLOC(P, N) ((P) = xnmalloc (N, sizeof *(P))) |
59 | #define REALLOC(P, N) ((P) = xnrealloc (P, N, sizeof *(P))) | |
a4b36db4 | 60 | |
273a74fa | 61 | |
b77b9ee0 AD |
62 | /*---------------------. |
63 | | Missing prototypes. | | |
64 | `---------------------*/ | |
65 | ||
1f65350a | 66 | #include <stpcpy.h> |
b77b9ee0 AD |
67 | |
68 | ||
a0f6b076 AD |
69 | /*-----------------. |
70 | | GCC extensions. | | |
71 | `-----------------*/ | |
72 | ||
48e28efa PE |
73 | /* Use this to suppress gcc's `...may be used before initialized' |
74 | warnings. */ | |
75 | #ifdef lint | |
76 | # define IF_LINT(Code) Code | |
77 | #else | |
78 | # define IF_LINT(Code) /* empty */ | |
79 | #endif | |
80 | ||
a0f6b076 AD |
81 | #ifndef __attribute__ |
82 | /* This feature is available in gcc versions 2.5 and later. */ | |
44ea3fbd MA |
83 | # if !defined (__GNUC__) || __GNUC__ < 2 || \ |
84 | (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ | |
a0f6b076 AD |
85 | # define __attribute__(Spec) /* empty */ |
86 | # endif | |
e9955c83 AD |
87 | #endif |
88 | ||
a0f6b076 AD |
89 | /* The __-protected variants of `format' and `printf' attributes |
90 | are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ | |
e9955c83 AD |
91 | #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) |
92 | # define __format__ format | |
93 | # define __printf__ printf | |
a0f6b076 AD |
94 | #endif |
95 | ||
e9955c83 AD |
96 | #ifndef ATTRIBUTE_NORETURN |
97 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | |
98 | #endif | |
99 | ||
100 | #ifndef ATTRIBUTE_UNUSED | |
101 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | |
102 | #endif | |
a0f6b076 AD |
103 | |
104 | /*------. | |
105 | | NLS. | | |
106 | `------*/ | |
107 | ||
6e26ca8c | 108 | #include <locale.h> |
f2d78a99 | 109 | |
982cc302 | 110 | #include <gettext.h> |
e0327bc8 AD |
111 | #define _(Msgid) gettext (Msgid) |
112 | #define N_(Msgid) (Msgid) | |
f2d78a99 | 113 | |
a0f6b076 AD |
114 | |
115 | /*-------------------------------. | |
116 | | Fix broken compilation flags. | | |
117 | `-------------------------------*/ | |
118 | ||
8a278a04 | 119 | #ifndef LOCALEDIR |
a0f6b076 | 120 | # define LOCALEDIR "/usr/local/share/locale" |
8a278a04 | 121 | #endif |
d968a24b | 122 | |
ceed8467 | 123 | |
015acc48 AD |
124 | /*-----------. |
125 | | Booleans. | | |
126 | `-----------*/ | |
127 | ||
f61aad93 | 128 | #include <stdbool.h> |
8c7ebe49 AD |
129 | |
130 | ||
131 | /*-----------. | |
132 | | Obstacks. | | |
133 | `-----------*/ | |
134 | ||
342b8b6e AD |
135 | # define obstack_chunk_alloc xmalloc |
136 | # define obstack_chunk_free free | |
982cc302 | 137 | # include <obstack.h> |
8c7ebe49 | 138 | |
ff4423cc AD |
139 | #define obstack_sgrow(Obs, Str) \ |
140 | obstack_grow (Obs, Str, strlen (Str)) | |
8c7ebe49 AD |
141 | |
142 | #define obstack_fgrow1(Obs, Format, Arg1) \ | |
143 | do { \ | |
144 | char buf[4096]; \ | |
145 | sprintf (buf, Format, Arg1); \ | |
146 | obstack_grow (Obs, buf, strlen (buf)); \ | |
147 | } while (0) | |
dd60faec AD |
148 | |
149 | #define obstack_fgrow2(Obs, Format, Arg1, Arg2) \ | |
150 | do { \ | |
151 | char buf[4096]; \ | |
152 | sprintf (buf, Format, Arg1, Arg2); \ | |
153 | obstack_grow (Obs, buf, strlen (buf)); \ | |
154 | } while (0) | |
896fe5c1 AD |
155 | |
156 | #define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \ | |
157 | do { \ | |
158 | char buf[4096]; \ | |
159 | sprintf (buf, Format, Arg1, Arg2, Arg3); \ | |
160 | obstack_grow (Obs, buf, strlen (buf)); \ | |
161 | } while (0) | |
7de3329e | 162 | |
ff4423cc AD |
163 | #define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \ |
164 | do { \ | |
165 | char buf[4096]; \ | |
166 | sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \ | |
167 | obstack_grow (Obs, buf, strlen (buf)); \ | |
168 | } while (0) | |
169 | ||
7de3329e | 170 | |
7de3329e | 171 | |
381fb12e AD |
172 | /*-----------------------------------------. |
173 | | Extensions to use for the output files. | | |
174 | `-----------------------------------------*/ | |
7de3329e AD |
175 | |
176 | #ifdef VMS | |
177 | /* VMS. */ | |
982cc302 PE |
178 | # define TAB_EXT "_tab" |
179 | # define OUTPUT_EXT ".output" | |
7de3329e AD |
180 | #else /* ! VMS */ |
181 | # ifdef MSDOS | |
182 | /* MS DOS. */ | |
982cc302 PE |
183 | # define TAB_EXT "_tab" |
184 | # define OUTPUT_EXT ".out" | |
7de3329e AD |
185 | # else /* ! MSDOS */ |
186 | /* Standard. */ | |
982cc302 PE |
187 | # define TAB_EXT ".tab" |
188 | # define OUTPUT_EXT ".output" | |
7de3329e AD |
189 | # endif /* ! MSDOS */ |
190 | #endif /* ! VMS */ | |
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 AD |
212 | |
213 | /*---------------------------------------------. | |
214 | | Debugging memory allocation (must be last). | | |
215 | `---------------------------------------------*/ | |
342b8b6e AD |
216 | |
217 | # if WITH_DMALLOC | |
218 | # define DMALLOC_FUNC_CHECK | |
219 | # include <dmalloc.h> | |
220 | # endif /* WITH_DMALLOC */ | |
221 | ||
a4b36db4 | 222 | #endif /* ! BISON_SYSTEM_H */ |