]>
git.saurik.com Git - bison.git/blob - src/system.h
1 /* System-dependent definitions for Bison.
3 Copyright (C) 2000, 2001, 2002, 2003, 2004 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
32 /* Verify a requirement at compile-time (unlike assert, which is runtime). */
33 #define verify(name, assertion) struct name {char name[(assertion) ? 1 : -1];}
36 # include <sys/types.h>
44 # include <inttypes.h>
51 /* This isn't perfect, but it's good enough for Bison, which needs
52 only to hash pointers. */
53 typedef size_t uintptr_t;
57 #define CALLOC(P, N) ((P) = xcalloc (N, sizeof *(P)))
58 #define MALLOC(P, N) ((P) = xmalloc ((N) * sizeof *(P)))
59 #define REALLOC(P, N) ((P) = xrealloc (P, (N) * sizeof *(P)))
61 /* From xstrndup.c. */
62 char *xstrndup (const char *str
, size_t size
);
65 /*---------------------.
66 | Missing prototypes. |
67 `---------------------*/
69 #if defined HAVE_DECL_STPCPY && !HAVE_DECL_STPCPY
70 char *stpcpy (char *dest
, const char *src
);
73 #if defined HAVE_DECL_STRNLEN && !HAVE_DECL_STRNLEN
74 size_t strnlen (const char *str
, size_t maxlen
);
77 #if defined HAVE_DECL_MEMRCHR && !HAVE_DECL_MEMRCHR
78 void *memrchr (const void *str
, int ch
, size_t size
);
87 /* Use this to suppress gcc's `...may be used before initialized'
90 # define IF_LINT(Code) Code
92 # define IF_LINT(Code) /* empty */
96 /* This feature is available in gcc versions 2.5 and later. */
97 # if !defined (__GNUC__) || __GNUC__ < 2 || \
98 (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
99 # define __attribute__(Spec) /* empty */
103 /* The __-protected variants of `format' and `printf' attributes
104 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
105 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
106 # define __format__ format
107 # define __printf__ printf
110 #ifndef ATTRIBUTE_NORETURN
111 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
114 #ifndef ATTRIBUTE_UNUSED
115 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
125 #define _(Msgid) gettext (Msgid)
126 #define N_(Msgid) (Msgid)
129 /*-------------------------------.
130 | Fix broken compilation flags. |
131 `-------------------------------*/
134 # define LOCALEDIR "/usr/local/share/locale"
149 # define obstack_chunk_alloc xmalloc
150 # define obstack_chunk_free free
151 # include <obstack.h>
153 #define obstack_sgrow(Obs, Str) \
154 obstack_grow (Obs, Str, strlen (Str))
156 #define obstack_fgrow1(Obs, Format, Arg1) \
159 sprintf (buf, Format, Arg1); \
160 obstack_grow (Obs, buf, strlen (buf)); \
163 #define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
166 sprintf (buf, Format, Arg1, Arg2); \
167 obstack_grow (Obs, buf, strlen (buf)); \
170 #define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \
173 sprintf (buf, Format, Arg1, Arg2, Arg3); \
174 obstack_grow (Obs, buf, strlen (buf)); \
177 #define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
180 sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
181 obstack_grow (Obs, buf, strlen (buf)); \
186 /*-----------------------------------------.
187 | Extensions to use for the output files. |
188 `-----------------------------------------*/
192 # define TAB_EXT "_tab"
193 # define OUTPUT_EXT ".output"
197 # define TAB_EXT "_tab"
198 # define OUTPUT_EXT ".out"
201 # define TAB_EXT ".tab"
202 # define OUTPUT_EXT ".output"
203 # endif /* ! MSDOS */
206 #ifndef DEFAULT_TMPDIR
207 # define DEFAULT_TMPDIR "/tmp"
212 /*---------------------.
213 | Free a linked list. |
214 `---------------------*/
216 #define LIST_FREE(Type, List) \
218 Type *_node, *_next; \
219 for (_node = List; _node; _node = _next) \
221 _next = _node->next; \
227 /*---------------------------------------------.
228 | Debugging memory allocation (must be last). |
229 `---------------------------------------------*/
232 # define DMALLOC_FUNC_CHECK
233 # include <dmalloc.h>
234 # endif /* WITH_DMALLOC */
236 #endif /* ! BISON_SYSTEM_H */