]> git.saurik.com Git - bison.git/blob - src/system.h
DJGPP specific file.
[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 #include <limits.h>
24 #include <stddef.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "unlocked-io.h"
29
30 #if HAVE_SYS_TYPES_H
31 # include <sys/types.h>
32 #endif
33
34 #if HAVE_UNISTD_H
35 # include <unistd.h>
36 #endif
37
38 #if HAVE_INTTYPES_H
39 # include <inttypes.h>
40 #endif
41 #if HAVE_STDINT_H
42 # include <stdint.h>
43 #endif
44
45 #if ! HAVE_UINTPTR_T
46 /* This isn't perfect, but it's good enough for Bison, which needs
47 only to hash pointers. */
48 typedef size_t uintptr_t;
49 #endif
50
51 #include <assert.h>
52
53 #include <verify.h>
54 #include <xalloc.h>
55
56
57 /*---------------------.
58 | Missing prototypes. |
59 `---------------------*/
60
61 #include <stpcpy.h>
62
63 /* From lib/basename.c. */
64 char *base_name (char const *name);
65
66
67 /*-----------------.
68 | GCC extensions. |
69 `-----------------*/
70
71 /* Use this to suppress gcc's `...may be used before initialized'
72 warnings. */
73 #ifdef lint
74 # define IF_LINT(Code) Code
75 #else
76 # define IF_LINT(Code) /* empty */
77 #endif
78
79 #ifndef __attribute__
80 /* This feature is available in gcc versions 2.5 and later. */
81 # if !defined (__GNUC__) || __GNUC__ < 2 || \
82 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
83 # define __attribute__(Spec) /* empty */
84 # endif
85 #endif
86
87 /* The __-protected variants of `format' and `printf' attributes
88 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
89 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
90 # define __format__ format
91 # define __printf__ printf
92 #endif
93
94 #ifndef ATTRIBUTE_NORETURN
95 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
96 #endif
97
98 #ifndef ATTRIBUTE_UNUSED
99 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
100 #endif
101
102 /*------.
103 | NLS. |
104 `------*/
105
106 #include <locale.h>
107
108 #include <gettext.h>
109 #define _(Msgid) gettext (Msgid)
110 #define N_(Msgid) (Msgid)
111
112
113 /*-------------------------------.
114 | Fix broken compilation flags. |
115 `-------------------------------*/
116
117 #ifndef LOCALEDIR
118 # define LOCALEDIR "/usr/local/share/locale"
119 #endif
120
121
122 /*-----------.
123 | Booleans. |
124 `-----------*/
125
126 #include <stdbool.h>
127
128
129 /*-----------.
130 | Obstacks. |
131 `-----------*/
132
133 #define obstack_chunk_alloc xmalloc
134 #define obstack_chunk_free free
135 #include <obstack.h>
136
137 #define obstack_sgrow(Obs, Str) \
138 obstack_grow (Obs, Str, strlen (Str))
139
140 #define obstack_fgrow1(Obs, Format, Arg1) \
141 do { \
142 char buf[4096]; \
143 sprintf (buf, Format, Arg1); \
144 obstack_grow (Obs, buf, strlen (buf)); \
145 } while (0)
146
147 #define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
148 do { \
149 char buf[4096]; \
150 sprintf (buf, Format, Arg1, Arg2); \
151 obstack_grow (Obs, buf, strlen (buf)); \
152 } while (0)
153
154 #define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \
155 do { \
156 char buf[4096]; \
157 sprintf (buf, Format, Arg1, Arg2, Arg3); \
158 obstack_grow (Obs, buf, strlen (buf)); \
159 } while (0)
160
161 #define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
162 do { \
163 char buf[4096]; \
164 sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
165 obstack_grow (Obs, buf, strlen (buf)); \
166 } while (0)
167
168
169
170 /*-----------------------------------------.
171 | Extensions to use for the output files. |
172 `-----------------------------------------*/
173
174 #ifndef OUTPUT_EXT
175 # define OUTPUT_EXT ".output"
176 #endif
177
178 #ifndef TAB_EXT
179 # define TAB_EXT ".tab"
180 #endif
181
182 #ifndef DEFAULT_TMPDIR
183 # define DEFAULT_TMPDIR "/tmp"
184 #endif
185
186
187
188 /*---------------------.
189 | Free a linked list. |
190 `---------------------*/
191
192 #define LIST_FREE(Type, List) \
193 do { \
194 Type *_node, *_next; \
195 for (_node = List; _node; _node = _next) \
196 { \
197 _next = _node->next; \
198 free (_node); \
199 } \
200 } while (0)
201
202
203 /*---------------------------------------------.
204 | Debugging memory allocation (must be last). |
205 `---------------------------------------------*/
206
207 # if WITH_DMALLOC
208 # define DMALLOC_FUNC_CHECK
209 # include <dmalloc.h>
210 # endif /* WITH_DMALLOC */
211
212 #endif /* ! BISON_SYSTEM_H */