]>
git.saurik.com Git - bison.git/blob - src/system.h
068b308a8d8bb846b26fedde747a988262d95dc9
1 /* System-dependent definitions for Bison.
3 Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
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)
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.
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. */
19 #ifndef BISON_SYSTEM_H
20 #define BISON_SYSTEM_H
29 /* Verify a requirement at compile-time (unlike assert, which is runtime). */
30 #define verify(name, assertion) struct name {char name[(assertion) ? 1 : -1];}
33 # include <sys/types.h>
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. */
45 # define EXIT_FAILURE 1
49 # define EXIT_SUCCESS 0
56 #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
58 /* An ANSI string.h and pre-ANSI memory.h might conflict. */
59 # if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
61 # endif /* not STDC_HEADERS and HAVE_MEMORY_H */
62 #else /* not STDC_HEADERS and not HAVE_STRING_H */
64 /* memory.h and strings.h conflict on some systems. */
65 #endif /* not STDC_HEADERS and not HAVE_STRING_H */
71 # include <inttypes.h>
78 /* This isn't perfect, but it's good enough for Bison, which needs
79 only to hash pointers. */
80 typedef size_t uintptr_t;
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)))
88 /* From xstrndup.c. */
89 char *xstrndup (const char *s
, size_t n
);
92 /*---------------------.
93 | Missing prototypes. |
94 `---------------------*/
96 #if defined HAVE_DECL_STPCPY && !HAVE_DECL_STPCPY
97 char *stpcpy (char *dest
, const char *src
);
100 #if defined HAVE_DECL_STRCHR && !HAVE_DECL_STRCHR
101 char *strchr (const char *s
, int c
);
104 #if defined HAVE_DECL_STRSPN && !HAVE_DECL_STRSPN
105 size_t strspn (const char *s
, const char *accept
);
108 #if defined HAVE_DECL_STRNLEN && !HAVE_DECL_STRNLEN
109 size_t strnlen (const char *s
, size_t maxlen
);
112 #if defined HAVE_DECL_MEMCHR && !HAVE_DECL_MEMCHR
113 void *memchr (const void *s
, int c
, size_t n
);
116 #if defined HAVE_DECL_MEMRCHR && !HAVE_DECL_MEMRCHR
117 void *memrchr (const void *s
, int c
, size_t n
);
126 /* Use this to suppress gcc's `...may be used before initialized'
129 # define IF_LINT(Code) Code
131 # define IF_LINT(Code) /* empty */
134 #ifndef __attribute__
135 /* This feature is available in gcc versions 2.5 and later. */
136 # if !defined (__GNUC__) || __GNUC__ < 2 || \
137 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
138 # define __attribute__(Spec) /* empty */
142 /* The __-protected variants of `format' and `printf' attributes
143 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
144 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
145 # define __format__ format
146 # define __printf__ printf
149 #ifndef ATTRIBUTE_NORETURN
150 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
153 #ifndef ATTRIBUTE_UNUSED
154 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
165 # define setlocale(Category, Locale)
169 #define _(Msgid) gettext (Msgid)
170 #define N_(Msgid) (Msgid)
173 /*-------------------------------.
174 | Fix broken compilation flags. |
175 `-------------------------------*/
178 # define LOCALEDIR "/usr/local/share/locale"
187 # include <stdbool.h>
189 # ifndef __bool_true_false_are_defined
194 typedef unsigned char _Bool
;
200 # define __bool_true_false_are_defined 1
209 # define obstack_chunk_alloc xmalloc
210 # define obstack_chunk_free free
211 # include <obstack.h>
213 #define obstack_sgrow(Obs, Str) \
214 obstack_grow (Obs, Str, strlen (Str))
216 #define obstack_fgrow1(Obs, Format, Arg1) \
219 sprintf (buf, Format, Arg1); \
220 obstack_grow (Obs, buf, strlen (buf)); \
223 #define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
226 sprintf (buf, Format, Arg1, Arg2); \
227 obstack_grow (Obs, buf, strlen (buf)); \
230 #define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \
233 sprintf (buf, Format, Arg1, Arg2, Arg3); \
234 obstack_grow (Obs, buf, strlen (buf)); \
237 #define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
240 sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
241 obstack_grow (Obs, buf, strlen (buf)); \
246 /*-----------------------------------------.
247 | Extensions to use for the output files. |
248 `-----------------------------------------*/
252 # define TAB_EXT "_tab"
253 # define OUTPUT_EXT ".output"
257 # define TAB_EXT "_tab"
258 # define OUTPUT_EXT ".out"
261 # define TAB_EXT ".tab"
262 # define OUTPUT_EXT ".output"
263 # endif /* ! MSDOS */
266 #ifndef DEFAULT_TMPDIR
267 # define DEFAULT_TMPDIR "/tmp"
272 /*---------------------.
273 | Free a linked list. |
274 `---------------------*/
276 #define LIST_FREE(Type, List) \
278 Type *_node, *_next; \
279 for (_node = List; _node; _node = _next) \
281 _next = _node->next; \
287 /*---------------------------------------------.
288 | Debugging memory allocation (must be last). |
289 `---------------------------------------------*/
292 # define DMALLOC_FUNC_CHECK
293 # include <dmalloc.h>
294 # endif /* WITH_DMALLOC */
296 #endif /* ! BISON_SYSTEM_H */