Angband
h-basic.h
Go to the documentation of this file.
1 
12 #ifndef INCLUDED_H_BASIC_H
13 #define INCLUDED_H_BASIC_H
14 
18 #ifdef HAVE_CONFIG_H
19 
20 # include "autoconf.h"
21 
22 #else
23 
27 #ifdef _MSC_VER
28 # define inline __inline
29 # define snprintf _snprintf
30 #endif
31 
32 /* Necessary? */
33 #ifdef NDS
34 # include <fat.h>
35 # include <unistd.h>
36 # include <reent.h>
37 # include <sys/iosupport.h>
38 # include <errno.h>
39 #endif
40 
44 # if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
45  || (defined(_MSC_VER) && _MSC_VER >= 1600L)
46 # define HAVE_STDINT_H
47 # endif
48 
49 # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
50 # define HAVE_STDBOOL_H
51 # endif
52 
56 #define HAVE_FCNTL_H
57 #define HAVE_STAT
58 
59 #endif /* HAVE_CONFIG_H */
60 
64 # if defined(_Windows) || defined(__WINDOWS__) || \
65  defined(__WIN32__) || defined(WIN32) || \
66  defined(__WINNT__) || defined(__NT__)
67 # ifndef WINDOWS
68 # define WINDOWS
69 # endif
70 # endif
71 
75 #if !defined(WINDOWS) && !defined(GAMEBOY) && !defined(NDS)
76 # define UNIX
77 
78 # ifndef HAVE_DIRENT_H
79 # define HAVE_DIRENT_H
80 # endif
81 #endif
82 
87 /* #define SETGID */
88 
89 
101 #undef PATH_SEP
102 #define PATH_SEP "/"
103 #define PATH_SEPC '/'
104 
105 #ifdef WINDOWS
106 # undef PATH_SEP
107 # undef PATH_SEPC
108 # define PATH_SEP "\\"
109 # define PATH_SEPC '\\'
110 #endif
111 
112 
119 /* Use various POSIX functions if available */
120 #undef _GNU_SOURCE
121 #define _GNU_SOURCE
122 
124 #include <ctype.h>
125 #include <errno.h>
126 #include <limits.h>
127 #include <assert.h>
128 
129 #include <stdarg.h>
130 #include <stdio.h>
131 #include <stdlib.h>
132 #include <stddef.h>
133 #include <string.h>
134 #include <time.h>
135 
136 #include <wchar.h>
137 #include <wctype.h>
138 
140 #ifdef UNIX
141 # include <pwd.h>
142 # include <sys/stat.h>
143 # include <unistd.h>
144 #endif
145 
146 
147 
165 #ifdef __cplusplus
166 #undef bool
167 #define bool bool_hack
168 #endif
169 
170 typedef int errr;
171 
172 
176 #ifdef HAVE_STDBOOL_H
177 
178  #include <stdbool.h>
179 
180  #undef TRUE
181  #undef FALSE
182 
183  #define TRUE true
184  #define FALSE false
185 
186 #else
187 
188  /* Use a char otherwise */
189  typedef char bool;
190 
191  #undef TRUE
192  #undef FALSE
193 
194  #define TRUE 1
195  #define FALSE 0
196 
197 #endif
198 
199 
200 
204 #ifdef HAVE_STDINT_H
205 
206  /* Use guaranteed-size types */
207  #include <stdint.h>
208 
209  typedef uint8_t byte;
210 
211  typedef uint16_t u16b;
212  typedef int16_t s16b;
213 
214  typedef uint32_t u32b;
215  typedef int32_t s32b;
216 
217  typedef uint64_t u64b;
218  typedef int64_t s64b;
219 
220 #define MAX_UCHAR UINT8_MAX
221 #define MAX_SHORT INT16_MAX
222 
223 #else /* HAVE_STDINT_H */
224 
225  /* Try hacks instead (not guaranteed to work) */
226  typedef unsigned char byte;
227  typedef signed short s16b;
228  typedef unsigned short u16b;
229 
230 #define MAX_UCHAR UCHAR_MAX
231 #define MAX_SHORT 32767
232 
233  /* Detect >32-bit longs */
234  #if (UINT_MAX == 0xFFFFFFFFUL) && (ULONG_MAX > 0xFFFFFFFFUL)
235  typedef signed int s32b;
236  typedef unsigned int u32b;
237  #else
238  typedef signed long s32b;
239  typedef unsigned long u32b;
240  #endif
241 
242 #endif /* HAVE_STDINT_H */
243 
244 
247 #define DSTRINGIFY(x) #x
248 #define DSTRING(x) DSTRINGIFY(x)
249 #define DHERE __FILE__ ":" DSTRING(__LINE__) ": "
250 
251 
258 #undef MIN
259 #undef MAX
260 #undef ABS
261 #undef SGN
262 #undef CMP
263 
264 #define MIN(a,b) (((a) > (b)) ? (b) : (a))
265 #define MAX(a,b) (((a) < (b)) ? (b) : (a))
266 #define ABS(a) (((a) < 0) ? (-(a)) : (a))
267 #define SGN(a) (((a) < 0) ? (-1) : ((a) != 0))
268 #define CMP(a,b) ((a) < (b) ? -1 : ((b) < (a) ? 1 : 0))
269 
270 
280 #define N_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
281 
292 #define A2I(X) ((X) - 'a')
293 #define I2A(X) ((X) + 'a')
294 #define D2I(X) ((X) - '0')
295 #define I2D(X) ((X) + '0')
296 
297 #endif /* INCLUDED_H_BASIC_H */