]> git.saurik.com Git - bison.git/blame - src/system.h
* data/yacc.c, data/glr.c, data/lal1.cc: Use similar code to
[bison.git] / src / system.h
CommitLineData
87aabbff 1/* System-dependent definitions for Bison.
45aa0550
PE
2
3 Copyright (C) 2000, 2001, 2002, 2003 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
deedb0b7 26#include <stddef.h>
ceed8467
AD
27#include <stdio.h>
28
87aabbff
PE
29/* Verify a requirement at compile-time (unlike assert, which is runtime). */
30#define verify(name, assertion) struct name {char name[(assertion) ? 1 : -1];}
340ef489 31
27b0ffea
AD
32#if HAVE_SYS_TYPES_H
33# include <sys/types.h>
34#endif
35
499daa50 36#if HAVE_STDLIB_H
a0f6b076 37# include <stdlib.h>
5fcfb6e7
RS
38#endif
39
0f37a994
AD
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
499daa50 52#if HAVE_UNISTD_H
a0f6b076 53# include <unistd.h>
7bb4d914
JT
54#endif
55
5fcfb6e7 56#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
a0f6b076 57# include <string.h>
5fcfb6e7 58/* An ANSI string.h and pre-ANSI memory.h might conflict. */
a0f6b076
AD
59# if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
60# include <memory.h>
61# endif /* not STDC_HEADERS and HAVE_MEMORY_H */
5fcfb6e7 62#else /* not STDC_HEADERS and not HAVE_STRING_H */
a0f6b076 63# include <strings.h>
5fcfb6e7
RS
64/* memory.h and strings.h conflict on some systems. */
65#endif /* not STDC_HEADERS and not HAVE_STRING_H */
f2d78a99 66
930393cf 67#include <limits.h>
62a3e4f0 68
deedb0b7
PE
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. */
80typedef size_t uintptr_t;
81#endif
82
982cc302 83#include <xalloc.h>
deedb0b7
PE
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)))
b77b9ee0 87
a4b36db4 88/* From xstrndup.c. */
a737b216 89char *xstrndup (const char *str, size_t size);
a4b36db4 90
273a74fa 91
b77b9ee0
AD
92/*---------------------.
93| Missing prototypes. |
94`---------------------*/
95
56100c60 96#if defined HAVE_DECL_STPCPY && !HAVE_DECL_STPCPY
930393cf 97char *stpcpy (char *dest, const char *src);
b77b9ee0
AD
98#endif
99
56100c60 100#if defined HAVE_DECL_STRCHR && !HAVE_DECL_STRCHR
a737b216 101char *strchr (const char *str, int ch);
ec2da99f
AD
102#endif
103
56100c60 104#if defined HAVE_DECL_STRSPN && !HAVE_DECL_STRSPN
a737b216 105size_t strspn (const char *str, const char *accept);
ec2da99f
AD
106#endif
107
56100c60 108#if defined HAVE_DECL_STRNLEN && !HAVE_DECL_STRNLEN
a737b216 109size_t strnlen (const char *str, size_t maxlen);
b77b9ee0
AD
110#endif
111
56100c60 112#if defined HAVE_DECL_MEMCHR && !HAVE_DECL_MEMCHR
a737b216 113void *memchr (const void *str, int ch, size_t size);
22312b71
AD
114#endif
115
56100c60 116#if defined HAVE_DECL_MEMRCHR && !HAVE_DECL_MEMRCHR
a737b216 117void *memrchr (const void *str, int ch, size_t size);
ec2da99f
AD
118#endif
119
b77b9ee0
AD
120
121
a0f6b076
AD
122/*-----------------.
123| GCC extensions. |
124`-----------------*/
125
48e28efa
PE
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
a0f6b076
AD
134#ifndef __attribute__
135/* This feature is available in gcc versions 2.5 and later. */
44ea3fbd
MA
136# if !defined (__GNUC__) || __GNUC__ < 2 || \
137(__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
a0f6b076
AD
138# define __attribute__(Spec) /* empty */
139# endif
e9955c83
AD
140#endif
141
a0f6b076
AD
142/* The __-protected variants of `format' and `printf' attributes
143 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
e9955c83
AD
144#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
145# define __format__ format
146# define __printf__ printf
a0f6b076
AD
147#endif
148
e9955c83
AD
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
a0f6b076
AD
156
157/*------.
158| NLS. |
159`------*/
160
56100c60 161#if HAVE_LOCALE_H
f2d78a99
RS
162# include <locale.h>
163#endif
56100c60 164#if !HAVE_SETLOCALE
f2d78a99
RS
165# define setlocale(Category, Locale)
166#endif
167
982cc302 168#include <gettext.h>
e0327bc8
AD
169#define _(Msgid) gettext (Msgid)
170#define N_(Msgid) (Msgid)
f2d78a99 171
a0f6b076
AD
172
173/*-------------------------------.
174| Fix broken compilation flags. |
175`-------------------------------*/
176
8a278a04 177#ifndef LOCALEDIR
a0f6b076 178# define LOCALEDIR "/usr/local/share/locale"
8a278a04 179#endif
d968a24b 180
ceed8467 181
015acc48
AD
182/*-----------.
183| Booleans. |
184`-----------*/
185
78b88816
PE
186#if HAVE_STDBOOL_H
187# include <stdbool.h>
188#else
45aa0550
PE
189# ifndef __bool_true_false_are_defined
190# if ! HAVE__BOOL
191# ifdef __cplusplus
192typedef bool _Bool;
193# else
194typedef unsigned char _Bool;
195# endif
196# endif
197# define bool _Bool
198# define false 0
199# define true 1
200# define __bool_true_false_are_defined 1
201# endif
015acc48 202#endif
8c7ebe49
AD
203
204
205/*-----------.
206| Obstacks. |
207`-----------*/
208
342b8b6e
AD
209# define obstack_chunk_alloc xmalloc
210# define obstack_chunk_free free
982cc302 211# include <obstack.h>
8c7ebe49 212
ff4423cc
AD
213#define obstack_sgrow(Obs, Str) \
214 obstack_grow (Obs, Str, strlen (Str))
8c7ebe49
AD
215
216#define obstack_fgrow1(Obs, Format, Arg1) \
217do { \
218 char buf[4096]; \
219 sprintf (buf, Format, Arg1); \
220 obstack_grow (Obs, buf, strlen (buf)); \
221} while (0)
dd60faec
AD
222
223#define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
224do { \
225 char buf[4096]; \
226 sprintf (buf, Format, Arg1, Arg2); \
227 obstack_grow (Obs, buf, strlen (buf)); \
228} while (0)
896fe5c1
AD
229
230#define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \
231do { \
232 char buf[4096]; \
233 sprintf (buf, Format, Arg1, Arg2, Arg3); \
234 obstack_grow (Obs, buf, strlen (buf)); \
235} while (0)
7de3329e 236
ff4423cc
AD
237#define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
238do { \
239 char buf[4096]; \
240 sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
241 obstack_grow (Obs, buf, strlen (buf)); \
242} while (0)
243
7de3329e 244
7de3329e 245
381fb12e
AD
246/*-----------------------------------------.
247| Extensions to use for the output files. |
248`-----------------------------------------*/
7de3329e
AD
249
250#ifdef VMS
251 /* VMS. */
982cc302
PE
252# define TAB_EXT "_tab"
253# define OUTPUT_EXT ".output"
7de3329e
AD
254#else /* ! VMS */
255# ifdef MSDOS
256 /* MS DOS. */
982cc302
PE
257# define TAB_EXT "_tab"
258# define OUTPUT_EXT ".out"
7de3329e
AD
259# else /* ! MSDOS */
260 /* Standard. */
982cc302
PE
261# define TAB_EXT ".tab"
262# define OUTPUT_EXT ".output"
7de3329e
AD
263# endif /* ! MSDOS */
264#endif /* ! VMS */
55b96341 265
381fb12e
AD
266#ifndef DEFAULT_TMPDIR
267# define DEFAULT_TMPDIR "/tmp"
268#endif
269
270
271
381fb12e
AD
272/*---------------------.
273| Free a linked list. |
274`---------------------*/
275
300f275f
AD
276#define LIST_FREE(Type, List) \
277do { \
278 Type *_node, *_next; \
279 for (_node = List; _node; _node = _next) \
280 { \
281 _next = _node->next; \
282 XFREE (_node); \
283 } \
284} while (0)
285
381fb12e
AD
286
287/*---------------------------------------------.
288| Debugging memory allocation (must be last). |
289`---------------------------------------------*/
342b8b6e
AD
290
291# if WITH_DMALLOC
292# define DMALLOC_FUNC_CHECK
293# include <dmalloc.h>
294# endif /* WITH_DMALLOC */
295
a4b36db4 296#endif /* ! BISON_SYSTEM_H */