]> git.saurik.com Git - bison.git/blob - src/system.h
9b874b9595c97fb6a944a2af4a1d887712cc0256
[bison.git] / src / system.h
1 /* System-dependent definitions for Bison.
2
3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software
4 Foundation, Inc.
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,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
20 #ifndef BISON_SYSTEM_H
21 #define BISON_SYSTEM_H
22
23 #if HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <limits.h>
28 #include <stddef.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include "unlocked-io.h"
33
34 #if HAVE_SYS_TYPES_H
35 # include <sys/types.h>
36 #endif
37
38 #if HAVE_UNISTD_H
39 # include <unistd.h>
40 #endif
41
42 #if HAVE_INTTYPES_H
43 # include <inttypes.h>
44 #endif
45 #if HAVE_STDINT_H
46 # include <stdint.h>
47 #endif
48
49 #if ! HAVE_UINTPTR_T
50 /* This isn't perfect, but it's good enough for Bison, which needs
51 only to hash pointers. */
52 typedef size_t uintptr_t;
53 #endif
54
55 #include <verify.h>
56 #include <xalloc.h>
57
58
59 /*---------------------.
60 | Missing prototypes. |
61 `---------------------*/
62
63 #include <stpcpy.h>
64
65 /* From lib/basename.c. */
66 char *base_name (char const *name);
67
68
69 /*-----------------.
70 | GCC extensions. |
71 `-----------------*/
72
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
81 #ifndef __attribute__
82 /* This feature is available in gcc versions 2.5 and later. */
83 # if !defined (__GNUC__) || __GNUC__ < 2 || \
84 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
85 # define __attribute__(Spec) /* empty */
86 # endif
87 #endif
88
89 /* The __-protected variants of `format' and `printf' attributes
90 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
91 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
92 # define __format__ format
93 # define __printf__ printf
94 #endif
95
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
103
104 /*------.
105 | NLS. |
106 `------*/
107
108 #include <locale.h>
109
110 #include <gettext.h>
111 #define _(Msgid) gettext (Msgid)
112 #define N_(Msgid) (Msgid)
113
114
115 /*-------------------------------.
116 | Fix broken compilation flags. |
117 `-------------------------------*/
118
119 #ifndef LOCALEDIR
120 # define LOCALEDIR "/usr/local/share/locale"
121 #endif
122
123
124 /*-----------.
125 | Booleans. |
126 `-----------*/
127
128 #include <stdbool.h>
129
130
131 /*-----------.
132 | Obstacks. |
133 `-----------*/
134
135 #define obstack_chunk_alloc xmalloc
136 #define obstack_chunk_free free
137 #include <obstack.h>
138
139 #define obstack_sgrow(Obs, Str) \
140 obstack_grow (Obs, Str, strlen (Str))
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)
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)
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)
162
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
170
171
172 /*-----------------------------------------.
173 | Extensions to use for the output files. |
174 `-----------------------------------------*/
175
176 #ifndef OUTPUT_EXT
177 # define OUTPUT_EXT ".output"
178 #endif
179
180 #ifndef TAB_EXT
181 # define TAB_EXT ".tab"
182 #endif
183
184 #ifndef DEFAULT_TMPDIR
185 # define DEFAULT_TMPDIR "/tmp"
186 #endif
187
188
189
190 /*---------------------.
191 | Free a linked list. |
192 `---------------------*/
193
194 #define LIST_FREE(Type, List) \
195 do { \
196 Type *_node, *_next; \
197 for (_node = List; _node; _node = _next) \
198 { \
199 _next = _node->next; \
200 free (_node); \
201 } \
202 } while (0)
203
204
205 /*---------------------------------------------.
206 | Debugging memory allocation (must be last). |
207 `---------------------------------------------*/
208
209 # if WITH_DMALLOC
210 # define DMALLOC_FUNC_CHECK
211 # include <dmalloc.h>
212 # endif /* WITH_DMALLOC */
213
214 #endif /* ! BISON_SYSTEM_H */