| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
#ifndef INCLUDED_H_BASIC_H |
|---|
| 8 |
#define INCLUDED_H_BASIC_H |
|---|
| 9 |
|
|---|
| 10 |
#ifdef HAVE_CONFIG_H |
|---|
| 11 |
#include "autoconf.h" |
|---|
| 12 |
#endif |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
#ifdef __riscos |
|---|
| 21 |
# ifndef RISCOS |
|---|
| 22 |
# define RISCOS |
|---|
| 23 |
# endif |
|---|
| 24 |
#endif |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
#if defined(_Windows) || defined(__WINDOWS__) || \ |
|---|
| 31 |
defined(__WIN32__) || defined(WIN32) || \ |
|---|
| 32 |
defined(__WINNT__) || defined(__NT__) |
|---|
| 33 |
# ifndef WINDOWS |
|---|
| 34 |
# define WINDOWS |
|---|
| 35 |
# endif |
|---|
| 36 |
#endif |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
#if !defined(MACH_O_CARBON) && !defined(WINDOWS) && \ |
|---|
| 51 |
!defined(RISCOS) && !defined(GAMEBOY) |
|---|
| 52 |
# define SET_UID |
|---|
| 53 |
#endif |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
#undef PATH_SEP |
|---|
| 68 |
#define PATH_SEP "/" |
|---|
| 69 |
|
|---|
| 70 |
#ifdef WINDOWS |
|---|
| 71 |
# undef PATH_SEP |
|---|
| 72 |
# define PATH_SEP "\\" |
|---|
| 73 |
#endif |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
#ifdef MACH_O_CARBON |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
# define FILE_TYPE_TEXT 'TEXT' |
|---|
| 83 |
# define FILE_TYPE_DATA 'DATA' |
|---|
| 84 |
# define FILE_TYPE_SAVE 'SAVE' |
|---|
| 85 |
# define FILE_TYPE(X) (_ftype = (X)) |
|---|
| 86 |
|
|---|
| 87 |
#else |
|---|
| 88 |
|
|---|
| 89 |
# define FILE_TYPE(X) ((void)0) |
|---|
| 90 |
|
|---|
| 91 |
#endif |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
#include <ctype.h> |
|---|
| 100 |
#include <errno.h> |
|---|
| 101 |
#include <limits.h> |
|---|
| 102 |
#include <assert.h> |
|---|
| 103 |
|
|---|
| 104 |
#include <stdarg.h> |
|---|
| 105 |
#include <stdio.h> |
|---|
| 106 |
#include <stdlib.h> |
|---|
| 107 |
#include <string.h> |
|---|
| 108 |
#include <time.h> |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
#if defined(SET_UID) || defined(MACH_O_CARBON) |
|---|
| 113 |
# include <pwd.h> |
|---|
| 114 |
# include <sys/stat.h> |
|---|
| 115 |
# include <unistd.h> |
|---|
| 116 |
#endif |
|---|
| 117 |
|
|---|
| 118 |
#ifdef SET_UID |
|---|
| 119 |
# include <sys/types.h> |
|---|
| 120 |
#endif |
|---|
| 121 |
|
|---|
| 122 |
#if defined(__DJGPP__) || defined(__MWERKS__) |
|---|
| 123 |
#include <unistd.h> |
|---|
| 124 |
#endif |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
#if defined(MACINTOSH) && defined(__MWERKS__) |
|---|
| 129 |
# include <unix.h> |
|---|
| 130 |
#endif |
|---|
| 131 |
|
|---|
| 132 |
#if defined(WINDOWS) || defined(MSDOS) || defined(USE_EMX) |
|---|
| 133 |
# include <io.h> |
|---|
| 134 |
#endif |
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
#undef bool |
|---|
| 154 |
#define bool bool_hack |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
typedef const char *cptr; |
|---|
| 158 |
typedef int errr; |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
#if defined(HAVE_STDBOOL_H) |
|---|
| 162 |
|
|---|
| 163 |
#include <stdbool.h> |
|---|
| 164 |
|
|---|
| 165 |
#define TRUE true |
|---|
| 166 |
#define FALSE false |
|---|
| 167 |
|
|---|
| 168 |
#else |
|---|
| 169 |
|
|---|
| 170 |
typedef char bool; |
|---|
| 171 |
|
|---|
| 172 |
#undef TRUE |
|---|
| 173 |
#undef FALSE |
|---|
| 174 |
|
|---|
| 175 |
#define TRUE 1 |
|---|
| 176 |
#define FALSE 0 |
|---|
| 177 |
|
|---|
| 178 |
#endif |
|---|
| 179 |
|
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
#if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) || defined HAVE_STDINT_H |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
#include <stdint.h> |
|---|
| 186 |
|
|---|
| 187 |
typedef uint8_t byte; |
|---|
| 188 |
|
|---|
| 189 |
typedef uint16_t u16b; |
|---|
| 190 |
typedef int16_t s16b; |
|---|
| 191 |
|
|---|
| 192 |
typedef uint32_t u32b; |
|---|
| 193 |
typedef int32_t s32b; |
|---|
| 194 |
|
|---|
| 195 |
#define MAX_UCHAR UINT8_MAX |
|---|
| 196 |
#define MAX_SHORT INT16_MAX |
|---|
| 197 |
|
|---|
| 198 |
#else |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
typedef unsigned char byte; |
|---|
| 202 |
typedef signed short s16b; |
|---|
| 203 |
typedef unsigned short u16b; |
|---|
| 204 |
|
|---|
| 205 |
#define MAX_UCHAR UCHAR_MAX |
|---|
| 206 |
#define MAX_SHORT 32767 |
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
#if (UINT_MAX == 0xFFFFFFFFUL) && (ULONG_MAX > 0xFFFFFFFFUL) |
|---|
| 210 |
typedef signed int s32b; |
|---|
| 211 |
typedef unsigned int u32b; |
|---|
| 212 |
#else |
|---|
| 213 |
typedef signed long s32b; |
|---|
| 214 |
typedef unsigned long u32b; |
|---|
| 215 |
#endif |
|---|
| 216 |
|
|---|
| 217 |
#endif |
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
#ifndef NULL |
|---|
| 225 |
# define NULL ((void*)0) |
|---|
| 226 |
#endif |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
#undef MIN |
|---|
| 233 |
#undef MAX |
|---|
| 234 |
#undef ABS |
|---|
| 235 |
#undef SGN |
|---|
| 236 |
|
|---|
| 237 |
#define MIN(a,b) (((a) > (b)) ? (b) : (a)) |
|---|
| 238 |
#define MAX(a,b) (((a) < (b)) ? (b) : (a)) |
|---|
| 239 |
#define ABS(a) (((a) < 0) ? (-(a)) : (a)) |
|---|
| 240 |
#define SGN(a) (((a) < 0) ? (-1) : ((a) != 0)) |
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
#define N_ELEMENTS(a) (sizeof(a) / sizeof((a)[0])) |
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 |
#define A2I(X) ((X) - 'a') |
|---|
| 259 |
#define I2A(X) ((X) + 'a') |
|---|
| 260 |
#define D2I(X) ((X) - '0') |
|---|
| 261 |
#define I2D(X) ((X) + '0') |
|---|
| 262 |
#define KTRL(X) ((X) & 0x1F) |
|---|
| 263 |
#define UN_KTRL(X) ((X) + 64) |
|---|
| 264 |
#define ESCAPE '\033' |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
#define ARROW_DOWN '\x8A' |
|---|
| 271 |
#define ARROW_LEFT '\x8B' |
|---|
| 272 |
#define ARROW_RIGHT '\x8C' |
|---|
| 273 |
#define ARROW_UP '\x8D' |
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
#define isarrow(c) ((c >= ARROW_DOWN) && (c <= ARROW_UP)) |
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
#endif |
|---|
| 280 |
|
|---|
| 281 |
|
|---|