2005-11-01 20:09:07 +00:00
|
|
|
/* This include file is used in C and C++ sources.
|
|
|
|
Don't use C++ specific code here please.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
------------------------------------------------------------------
|
|
|
|
The Goldware Library
|
|
|
|
Copyright (C) 1990-1999 Odinn Sorensen
|
|
|
|
Copyright (C) 1999-2000 Alexander S. Aganichev
|
|
|
|
------------------------------------------------------------------
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this program; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
MA 02111-1307, USA
|
|
|
|
------------------------------------------------------------------
|
|
|
|
$Id$
|
|
|
|
------------------------------------------------------------------
|
|
|
|
Basic definitions and types.
|
|
|
|
------------------------------------------------------------------
|
|
|
|
*/
|
2000-02-25 10:15:17 +00:00
|
|
|
#ifndef __goldall_h
|
|
|
|
#define __goldall_h
|
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------ */
|
2005-10-23 13:33:46 +00:00
|
|
|
#ifdef __cplusplus
|
2000-02-25 10:15:17 +00:00
|
|
|
#include <cstddef>
|
2005-10-23 13:33:46 +00:00
|
|
|
#endif
|
2000-02-25 10:15:17 +00:00
|
|
|
#include <gcmpall.h>
|
2005-10-09 21:09:37 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include <windows.h>
|
2005-10-20 00:12:33 +00:00
|
|
|
#include <limits.h>
|
2005-12-14 16:18:30 +00:00
|
|
|
#elif defined(__MINGW32__) || defined(__CYGWIN__)
|
2005-10-07 12:41:11 +00:00
|
|
|
#include <stdint.h>
|
2005-11-16 14:49:13 +00:00
|
|
|
#else
|
2005-10-09 21:09:37 +00:00
|
|
|
#endif
|
2000-02-25 10:15:17 +00:00
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------
|
|
|
|
// Disable some MS Visual C warnings */
|
2005-08-26 23:14:24 +00:00
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
2005-11-01 20:09:07 +00:00
|
|
|
/*
|
2005-08-26 23:14:24 +00:00
|
|
|
// C4786: 'identifier' : identifier was truncated to 'number'
|
|
|
|
// characters in the debug information
|
|
|
|
//
|
|
|
|
// C4065: switch statement contains 'default' but no 'case' labels
|
|
|
|
//
|
|
|
|
// C4200: nonstandard extension used : zero-sized array in struct/union
|
2005-11-01 20:09:07 +00:00
|
|
|
*/
|
2005-10-22 02:45:18 +00:00
|
|
|
#pragma warning(disable: 4200 4786 4065)
|
2005-08-26 23:14:24 +00:00
|
|
|
#endif
|
2000-02-25 10:15:17 +00:00
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------
|
|
|
|
// Define portability and shorthand notation */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* GCC after 2.95.x have "and", "not", and "or" predefined */
|
2001-03-03 13:16:14 +00:00
|
|
|
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
|
2000-02-25 10:15:17 +00:00
|
|
|
#ifndef and
|
|
|
|
#define not !
|
|
|
|
#define and &&
|
|
|
|
#define or ||
|
|
|
|
#endif
|
2001-03-03 13:16:14 +00:00
|
|
|
#endif
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
#ifndef true
|
|
|
|
#define true 1
|
|
|
|
#define false 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NO 0
|
|
|
|
#define YES 1
|
|
|
|
#define ALWAYS 2
|
|
|
|
#define ASK 2
|
|
|
|
#define GAUTO 3
|
|
|
|
#define MAYBE 4
|
|
|
|
|
2005-11-03 11:43:11 +00:00
|
|
|
#define NUL ((char)'\x00') /* Common ASCII control codes */
|
2000-02-25 10:15:17 +00:00
|
|
|
#define BEL '\x07'
|
|
|
|
#define BS '\x08'
|
|
|
|
#define HT '\x09'
|
|
|
|
#define LF '\x0A'
|
|
|
|
#define FF '\x0C'
|
|
|
|
#define CR '\x0D'
|
|
|
|
#define ESC '\x1B'
|
|
|
|
|
2006-01-14 20:50:53 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#define __UNIX__
|
|
|
|
#endif
|
|
|
|
|
2000-02-25 10:15:17 +00:00
|
|
|
#ifdef __UNIX__
|
|
|
|
#define NL "\r\n"
|
|
|
|
#else
|
|
|
|
#define NL "\n"
|
|
|
|
#endif
|
|
|
|
|
2006-02-24 12:29:21 +00:00
|
|
|
/* ----------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#define popen(f,m) _popen(f,m)
|
|
|
|
#define pclose(fh) _pclose(fh)
|
|
|
|
#endif
|
|
|
|
|
2006-01-21 00:57:09 +00:00
|
|
|
/* ------------------------------------------------------------------
|
|
|
|
// Spellchecker using dynamic library load */
|
|
|
|
#if !defined(GCFG_NOSPELLDLL) && !defined(__WIN32__)
|
|
|
|
#undef GCFG_NOSPELLDLL
|
|
|
|
#endif
|
2000-02-25 10:15:17 +00:00
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------
|
|
|
|
// Special character constants */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
#define CTRL_A '\x01' /* FidoNet kludge line char */
|
|
|
|
#define SOFTCR '\x8D' /* "Soft" carriage-return */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------
|
|
|
|
// Supplements for the built-in types */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
2005-10-09 21:09:37 +00:00
|
|
|
#ifdef _MSC_VER
|
2005-10-20 00:12:33 +00:00
|
|
|
#if (UCHAR_MAX == 0xFF)
|
|
|
|
typedef signed char int8_t;
|
|
|
|
typedef unsigned char uint8_t;
|
|
|
|
#else
|
2005-10-23 13:33:46 +00:00
|
|
|
#error Dont know how to define 8 bit integers
|
2005-10-20 00:12:33 +00:00
|
|
|
#endif
|
|
|
|
#if (USHRT_MAX == 0xFFFF)
|
|
|
|
typedef signed short int16_t;
|
|
|
|
typedef unsigned short uint16_t;
|
|
|
|
#else
|
2005-10-23 13:33:46 +00:00
|
|
|
#error Dont know how to define 16 bit integers
|
2005-10-20 00:12:33 +00:00
|
|
|
#endif
|
|
|
|
#if (UINT_MAX == 0xFFFFFFFF)
|
|
|
|
typedef signed int int32_t;
|
|
|
|
typedef unsigned int uint32_t;
|
|
|
|
#else
|
2005-10-23 13:33:46 +00:00
|
|
|
#error Dont know how to define 32 bit integers
|
2005-10-20 00:12:33 +00:00
|
|
|
#endif
|
2005-11-03 11:43:11 +00:00
|
|
|
#endif /*#ifdef _MSC_VER */
|
2005-10-18 03:49:35 +00:00
|
|
|
|
2005-12-14 16:18:30 +00:00
|
|
|
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__)
|
2005-10-27 20:40:10 +00:00
|
|
|
typedef unsigned char uint8_t;
|
|
|
|
typedef unsigned short uint16_t;
|
|
|
|
typedef unsigned int uint32_t;
|
|
|
|
|
2006-01-14 22:11:56 +00:00
|
|
|
#if !defined(__APPLE__)
|
2006-02-01 10:06:07 +00:00
|
|
|
#if !defined(__SUNOS__)
|
2005-10-27 20:40:10 +00:00
|
|
|
typedef signed char int8_t;
|
2006-02-01 10:06:07 +00:00
|
|
|
#endif
|
2005-10-27 20:40:10 +00:00
|
|
|
typedef signed short int16_t;
|
|
|
|
typedef signed int int32_t;
|
|
|
|
#endif
|
2006-01-14 22:11:56 +00:00
|
|
|
#endif
|
2005-10-27 20:40:10 +00:00
|
|
|
|
2005-10-18 03:49:35 +00:00
|
|
|
typedef uint8_t byte;
|
|
|
|
typedef uint16_t word;
|
2005-10-07 12:41:11 +00:00
|
|
|
typedef uint32_t dword;
|
2005-10-19 17:26:47 +00:00
|
|
|
|
2006-01-14 23:48:53 +00:00
|
|
|
#if !defined(__APPLE__)
|
2005-10-19 17:26:47 +00:00
|
|
|
typedef unsigned int uint;
|
2006-01-14 23:48:53 +00:00
|
|
|
#endif
|
2005-10-07 12:41:11 +00:00
|
|
|
|
2005-10-22 03:38:17 +00:00
|
|
|
typedef uint8_t bits;
|
2005-10-18 03:49:35 +00:00
|
|
|
typedef uint32_t time32_t; /* 32-bit time_t type */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------ */
|
2005-10-21 02:31:39 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2006-01-17 17:47:35 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
#if defined(__GOLD_GUI__)
|
|
|
|
#define STD_PRINT(out) { \
|
|
|
|
std::strstream str; \
|
|
|
|
str << out; \
|
|
|
|
GUI_Print(str); \
|
|
|
|
}
|
2006-01-20 11:55:12 +00:00
|
|
|
#define STD_PRINTNL(out) { \
|
|
|
|
std::strstream str; \
|
|
|
|
str << out << NL; \
|
|
|
|
GUI_Print(str); \
|
|
|
|
}
|
2006-01-17 17:47:35 +00:00
|
|
|
#else
|
|
|
|
#define STD_PRINT(out) std::cout << out;
|
2006-01-20 11:55:12 +00:00
|
|
|
#define STD_PRINTNL(out) std::cout << out << NL;
|
2006-01-17 17:47:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
/* Common function-pointer types */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
typedef void (*VfvCP)();
|
|
|
|
typedef int (*IfvCP)();
|
|
|
|
typedef int (*IfcpCP)(char*);
|
|
|
|
|
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
/* Function pointer for stdlib qsort(), bsearch() compare functions */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
typedef int (*StdCmpCP)(const void*, const void*);
|
|
|
|
|
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
/* Utility templates */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
template <class T> inline bool in_range(T a, T b, T c) { return (a >= b) and (a <= c); }
|
|
|
|
template <class T> inline T absolute(T a) { return a < 0 ? -a : a; }
|
|
|
|
template <class T> inline int compare_two(T a, T b) { return a < b ? -1 : a > b ? 1 : 0; }
|
2002-09-24 10:16:04 +00:00
|
|
|
template <class T> inline T minimum_of_two(T a, T b) { return (a < b) ? a : b; }
|
|
|
|
template <class T> inline T maximum_of_two(T a, T b) { return (a > b) ? a : b; }
|
2000-02-25 10:15:17 +00:00
|
|
|
template <class T> inline int zero_or_one(T e) { return e ? 1 : 0; }
|
2005-10-25 06:11:09 +00:00
|
|
|
template <class T> inline bool make_bool(T a) { return !!a; }
|
|
|
|
template <class T> inline bool make_bool_not(T a) { return !a; }
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------
|
2000-02-25 10:15:17 +00:00
|
|
|
// Handy macro for safe casting. Public domain by Bob Stout
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Example of CAST macro at work
|
|
|
|
//
|
|
|
|
// union {
|
|
|
|
// char ch[4];
|
|
|
|
// int i[2];
|
|
|
|
// } my_union;
|
|
|
|
//
|
|
|
|
// long longvar;
|
|
|
|
//
|
|
|
|
// longvar = (long)my_union; // Illegal cast
|
|
|
|
// longvar = CAST(long, my_union); // Legal cast
|
|
|
|
//
|
2005-11-01 20:09:07 +00:00
|
|
|
// ------------------------------------------------------------------ */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
#define CAST(new_type,old_object) (*((new_type *)&(old_object)))
|
|
|
|
|
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------ */
|
2005-11-05 23:18:14 +00:00
|
|
|
/* Get size of structure member */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
#define sizeofmember(__struct, __member) sizeof(((__struct*)0)->__member)
|
|
|
|
|
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------ */
|
2005-11-05 23:18:14 +00:00
|
|
|
/* Legacy defines */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
#define RngV in_range
|
|
|
|
#define AbsV absolute
|
|
|
|
#define CmpV compare_two
|
|
|
|
#define MinV minimum_of_two
|
|
|
|
#define MaxV maximum_of_two
|
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------ */
|
2005-10-21 02:31:39 +00:00
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
#endif /*#ifdef __cplusplus*/
|
2000-02-25 10:15:17 +00:00
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------ */
|
2000-02-25 10:15:17 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-11-01 20:09:07 +00:00
|
|
|
/* ------------------------------------------------------------------ */
|