]> git.saurik.com Git - bison.git/blame - src/system.h
Sync.
[bison.git] / src / system.h
CommitLineData
87aabbff 1/* System-dependent definitions for Bison.
45aa0550 2
deb63d81
PE
3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software
4 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
56100c60 23#if HAVE_CONFIG_H
d968a24b
JT
24# include <config.h>
25#endif
26
6e26ca8c 27#include <limits.h>
deedb0b7 28#include <stddef.h>
ceed8467 29#include <stdio.h>
6e26ca8c
PE
30#include <stdlib.h>
31#include <string.h>
ceed8467 32
87aabbff
PE
33/* Verify a requirement at compile-time (unlike assert, which is runtime). */
34#define verify(name, assertion) struct name {char name[(assertion) ? 1 : -1];}
340ef489 35
27b0ffea
AD
36#if HAVE_SYS_TYPES_H
37# include <sys/types.h>
38#endif
39
499daa50 40#if HAVE_UNISTD_H
a0f6b076 41# include <unistd.h>
7bb4d914
JT
42#endif
43
6e26ca8c
PE
44#if HAVE_INTTYPES_H
45# include <inttypes.h>
46#endif
47#if HAVE_STDINT_H
48# include <stdint.h>
49#endif
62a3e4f0 50
6e26ca8c 51#if ! HAVE_UINTPTR_T
deedb0b7
PE
52/* This isn't perfect, but it's good enough for Bison, which needs
53 only to hash pointers. */
54typedef size_t uintptr_t;
55#endif
56
982cc302 57#include <xalloc.h>
a4b36db4 58
273a74fa 59
b77b9ee0
AD
60/*---------------------.
61| Missing prototypes. |
62`---------------------*/
63
1f65350a 64#include <stpcpy.h>
b77b9ee0
AD
65
66
a0f6b076
AD
67/*-----------------.
68| GCC extensions. |
69`-----------------*/
70
48e28efa
PE
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
a0f6b076
AD
79#ifndef __attribute__
80/* This feature is available in gcc versions 2.5 and later. */
44ea3fbd
MA
81# if !defined (__GNUC__) || __GNUC__ < 2 || \
82(__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
a0f6b076
AD
83# define __attribute__(Spec) /* empty */
84# endif
e9955c83
AD
85#endif
86
a0f6b076
AD
87/* The __-protected variants of `format' and `printf' attributes
88 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
e9955c83
AD
89#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
90# define __format__ format
91# define __printf__ printf
a0f6b076
AD
92#endif
93
e9955c83
AD
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
a0f6b076
AD
101
102/*------.
103| NLS. |
104`------*/
105
6e26ca8c 106#include <locale.h>
f2d78a99 107
982cc302 108#include <gettext.h>
e0327bc8
AD
109#define _(Msgid) gettext (Msgid)
110#define N_(Msgid) (Msgid)
f2d78a99 111
a0f6b076
AD
112
113/*-------------------------------.
114| Fix broken compilation flags. |
115`-------------------------------*/
116
8a278a04 117#ifndef LOCALEDIR
a0f6b076 118# define LOCALEDIR "/usr/local/share/locale"
8a278a04 119#endif
d968a24b 120
ceed8467 121
015acc48
AD
122/*-----------.
123| Booleans. |
124`-----------*/
125
f61aad93 126#include <stdbool.h>
8c7ebe49
AD
127
128
129/*-----------.
130| Obstacks. |
131`-----------*/
132
342b8b6e
AD
133# define obstack_chunk_alloc xmalloc
134# define obstack_chunk_free free
982cc302 135# include <obstack.h>
8c7ebe49 136
ff4423cc
AD
137#define obstack_sgrow(Obs, Str) \
138 obstack_grow (Obs, Str, strlen (Str))
8c7ebe49
AD
139
140#define obstack_fgrow1(Obs, Format, Arg1) \
141do { \
142 char buf[4096]; \
143 sprintf (buf, Format, Arg1); \
144 obstack_grow (Obs, buf, strlen (buf)); \
145} while (0)
dd60faec
AD
146
147#define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
148do { \
149 char buf[4096]; \
150 sprintf (buf, Format, Arg1, Arg2); \
151 obstack_grow (Obs, buf, strlen (buf)); \
152} while (0)
896fe5c1
AD
153
154#define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \
155do { \
156 char buf[4096]; \
157 sprintf (buf, Format, Arg1, Arg2, Arg3); \
158 obstack_grow (Obs, buf, strlen (buf)); \
159} while (0)
7de3329e 160
ff4423cc
AD
161#define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
162do { \
163 char buf[4096]; \
164 sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
165 obstack_grow (Obs, buf, strlen (buf)); \
166} while (0)
167
7de3329e 168
7de3329e 169
381fb12e
AD
170/*-----------------------------------------.
171| Extensions to use for the output files. |
172`-----------------------------------------*/
7de3329e 173
deb63d81
PE
174#ifndef OUTPUT_EXT
175# define OUTPUT_EXT ".output"
176#endif
177
178#ifndef TAB_EXT
179# define TAB_EXT ".tab"
180#endif
55b96341 181
381fb12e
AD
182#ifndef DEFAULT_TMPDIR
183# define DEFAULT_TMPDIR "/tmp"
184#endif
185
186
187
381fb12e
AD
188/*---------------------.
189| Free a linked list. |
190`---------------------*/
191
300f275f
AD
192#define LIST_FREE(Type, List) \
193do { \
194 Type *_node, *_next; \
195 for (_node = List; _node; _node = _next) \
196 { \
197 _next = _node->next; \
afbb696d 198 free (_node); \
300f275f
AD
199 } \
200} while (0)
201
381fb12e
AD
202
203/*---------------------------------------------.
204| Debugging memory allocation (must be last). |
205`---------------------------------------------*/
342b8b6e
AD
206
207# if WITH_DMALLOC
208# define DMALLOC_FUNC_CHECK
209# include <dmalloc.h>
210# endif /* WITH_DMALLOC */
211
a4b36db4 212#endif /* ! BISON_SYSTEM_H */