From 78cbc8cc5f1cc45767fe54fd01637c81a557814d Mon Sep 17 00:00:00 2001 From: sezero Date: Sat, 14 Aug 2010 20:55:39 +0000 Subject: [PATCH] added q_stdinc.h, adapted from uhexen2, to tidy up several includes and macros in one place. git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@277 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/common.h | 42 ----------- Quake/host.c | 1 + Quake/host_cmd.c | 1 + Quake/mathlib.c | 1 - Quake/mathlib.h | 8 +-- Quake/menu.c | 1 + Quake/net_bsd.c | 1 + Quake/net_dgrm.c | 1 + Quake/net_loop.c | 1 + Quake/net_main.c | 1 + Quake/net_sdl.c | 1 + Quake/net_sdlnet.c | 1 + Quake/net_sys.h | 8 +-- Quake/net_udp.c | 1 + Quake/net_win.c | 1 + Quake/net_wins.c | 1 + Quake/net_wipx.c | 1 + Quake/q_stdinc.h | 176 +++++++++++++++++++++++++++++++++++++++++++++ Quake/quakedef.h | 26 +------ Quake/server.h | 2 - Quake/sv_main.c | 1 + 21 files changed, 195 insertions(+), 82 deletions(-) create mode 100644 Quake/q_stdinc.h diff --git a/Quake/common.h b/Quake/common.h index 83a30f0d..988290d9 100644 --- a/Quake/common.h +++ b/Quake/common.h @@ -24,26 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // comndef.h -- general definitions -#if !defined BYTE_DEFINED -typedef unsigned char byte; -#define BYTE_DEFINED 1 -#endif - -#undef true -#undef false -#if defined(__cplusplus) -/* do NOT use the bool of C++ because some structures have boolean and they - * expect it to be 4 bytes long. as a hack, typedef it as int. */ -/* DO HOPE that the compiler built-ins for true and false are 1 and 0 ... */ -typedef int qboolean; -#else -typedef enum { - false = 0, - true = 1 -} qboolean; -#endif - -//============================================================================ typedef struct sizebuf_s { @@ -81,28 +61,6 @@ void InsertLinkAfter (link_t *l, link_t *after); //============================================================================ -#ifndef NULL -#if defined(__cplusplus) -#define NULL 0 -#else -#define NULL ((void *)0) -#endif -#endif - -#define Q_MAXCHAR ((char)0x7f) -#define Q_MAXSHORT ((short)0x7fff) -#define Q_MAXINT ((int)0x7fffffff) -#define Q_MAXLONG ((int)0x7fffffff) -#define Q_MAXFLOAT ((int)0x7fffffff) - -#define Q_MINCHAR ((char)0x80) -#define Q_MINSHORT ((short)0x8000) -#define Q_MININT ((int)0x80000000) -#define Q_MINLONG ((int)0x80000000) -#define Q_MINFLOAT ((int)0x7fffffff) - -//============================================================================ - extern qboolean bigendien; extern short (*BigShort) (short l); diff --git a/Quake/host.c b/Quake/host.c index f4ab9c43..968f3a50 100644 --- a/Quake/host.c +++ b/Quake/host.c @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // host.c -- coordinates spawning and killing of local servers #include "quakedef.h" +#include /* diff --git a/Quake/host_cmd.c b/Quake/host_cmd.c index ead7b2d7..11193d37 100644 --- a/Quake/host_cmd.c +++ b/Quake/host_cmd.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" /* for net_defs.h */ #include diff --git a/Quake/mathlib.c b/Quake/mathlib.c index c94ef8c5..af856daa 100644 --- a/Quake/mathlib.c +++ b/Quake/mathlib.c @@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // mathlib.c -- math primitives -#include #include "quakedef.h" vec3_t vec3_origin = {0,0,0}; diff --git a/Quake/mathlib.h b/Quake/mathlib.h index a6b8b8b3..e2f83820 100644 --- a/Quake/mathlib.h +++ b/Quake/mathlib.h @@ -25,13 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // mathlib.h -typedef float vec_t; -typedef vec_t vec3_t[3]; -typedef vec_t vec5_t[5]; - -typedef int fixed4_t; -typedef int fixed8_t; -typedef int fixed16_t; +#include #ifndef M_PI #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h diff --git a/Quake/menu.c b/Quake/menu.c index 91116036..d54389d3 100644 --- a/Quake/menu.c +++ b/Quake/menu.c @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" /* FIXME */ #include "quakedef.h" diff --git a/Quake/net_bsd.c b/Quake/net_bsd.c index ce13cd96..5231aadb 100644 --- a/Quake/net_bsd.c +++ b/Quake/net_bsd.c @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" #include "quakedef.h" diff --git a/Quake/net_dgrm.c b/Quake/net_dgrm.c index 3d89f827..c497b208 100644 --- a/Quake/net_dgrm.c +++ b/Quake/net_dgrm.c @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // This is enables a simple IP banning mechanism #define BAN_TEST +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" #include "quakedef.h" diff --git a/Quake/net_loop.c b/Quake/net_loop.c index b6c97175..03caf54b 100644 --- a/Quake/net_loop.c +++ b/Quake/net_loop.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // net_loop.c +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" #include "quakedef.h" diff --git a/Quake/net_main.c b/Quake/net_main.c index 39c192b8..9eb735cb 100644 --- a/Quake/net_main.c +++ b/Quake/net_main.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // net_main.c +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" #include "quakedef.h" diff --git a/Quake/net_sdl.c b/Quake/net_sdl.c index e1cee530..2e70da16 100644 --- a/Quake/net_sdl.c +++ b/Quake/net_sdl.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" #include "quakedef.h" diff --git a/Quake/net_sdlnet.c b/Quake/net_sdlnet.c index fa69bf79..a02e5fa5 100644 --- a/Quake/net_sdlnet.c +++ b/Quake/net_sdlnet.c @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" #include "quakedef.h" diff --git a/Quake/net_sys.h b/Quake/net_sys.h index 58efc84c..b7fee847 100644 --- a/Quake/net_sys.h +++ b/Quake/net_sys.h @@ -113,10 +113,8 @@ typedef int socklen_t; #define socketerror(x) strerror((x)) -/* Verify that we defined HAVE_SA_LEN correctly - (Expression inside [] evaluates negative if HAVE_SA_LEN not correctly defined, - thowing "error: size of array is negative" at compile time) */ -typedef char _check_sockaddr[2 * (offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET) - 1]; +/* Verify that we defined HAVE_SA_LEN correctly: */ +COMPILE_TIME_ASSERT(sockaddr, offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET); #endif /* end of unix stuff */ @@ -150,7 +148,7 @@ typedef SOCKET sys_socket_t; #define socketerror(x) __WSAE_StrError((x)) /* Verify that we defined HAVE_SA_LEN correctly: */ -typedef char _check_sockaddr[2 * (offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET) - 1]; +COMPILE_TIME_ASSERT(sockaddr, offsetof(struct sockaddr, sa_family) == SA_FAM_OFFSET); #endif /* end of windows stuff */ diff --git a/Quake/net_udp.c b/Quake/net_udp.c index 82d77c56..e9d0c866 100644 --- a/Quake/net_udp.c +++ b/Quake/net_udp.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" #include "quakedef.h" diff --git a/Quake/net_win.c b/Quake/net_win.c index 8627ac77..847cd2e5 100644 --- a/Quake/net_win.c +++ b/Quake/net_win.c @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" #include "quakedef.h" diff --git a/Quake/net_wins.c b/Quake/net_wins.c index fa600de3..a32089fb 100644 --- a/Quake/net_wins.c +++ b/Quake/net_wins.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // net_wins.c +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" #include "quakedef.h" diff --git a/Quake/net_wipx.c b/Quake/net_wipx.c index e7f494b2..fe3e7deb 100644 --- a/Quake/net_wipx.c +++ b/Quake/net_wipx.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // net_wipx.c +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" #include diff --git a/Quake/q_stdinc.h b/Quake/q_stdinc.h new file mode 100644 index 00000000..0b21370a --- /dev/null +++ b/Quake/q_stdinc.h @@ -0,0 +1,176 @@ +/* + q_stdinc.h + includes the minimum necessary stdc headers, + defines common and / or missing types. + + Copyright (C) 1996-1997 Id Software, Inc. + Copyright (C) 2007-2008 O.Sezer + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, + Boston, MA 02110-1301 USA +*/ + +#ifndef __QSTDINC_H +#define __QSTDINC_H + +#include +#include +#include + +/* NOTES on TYPE SIZES: + Quake/Hexen II engine relied on 32 bit int type size + with ILP32 (not LP32) model in mind. We now support + LP64 and LLP64, too. We expect: + sizeof (char) == 1 + sizeof (short) == 2 + sizeof (int) == 4 + sizeof (float) == 4 + sizeof (long) == 4 / 8 + sizeof (pointer *) == 4 / 8 + FIXME: Properly replace certain short and int usage + with int16_t and int32_t. + */ + +#include +#include +#include +#include +#if !(defined(_WIN32) || defined(_WIN64)) +#include /* strcasecmp and strncasecmp */ +#endif /* ! PLATFORM_WINDOWS */ + +/*==========================================================================*/ + +#ifndef NULL +#if defined(__cplusplus) +#define NULL 0 +#else +#define NULL ((void *)0) +#endif +#endif + +#define Q_MAXCHAR ((char)0x7f) +#define Q_MAXSHORT ((short)0x7fff) +#define Q_MAXINT ((int)0x7fffffff) +#define Q_MAXLONG ((int)0x7fffffff) +#define Q_MAXFLOAT ((int)0x7fffffff) + +#define Q_MINCHAR ((char)0x80) +#define Q_MINSHORT ((short)0x8000) +#define Q_MININT ((int)0x80000000) +#define Q_MINLONG ((int)0x80000000) +#define Q_MINFLOAT ((int)0x7fffffff) + +/* Make sure the types really have the right + * sizes: These macros are from SDL headers. + */ +#define COMPILE_TIME_ASSERT(name, x) \ + typedef int dummy_ ## name[(x) * 2 - 1] + +COMPILE_TIME_ASSERT(char, sizeof(char) == 1); +COMPILE_TIME_ASSERT(float, sizeof(float) == 4); +COMPILE_TIME_ASSERT(long, sizeof(long) >= 4); +COMPILE_TIME_ASSERT(int, sizeof(int) == 4); +COMPILE_TIME_ASSERT(short, sizeof(short) == 2); + +/* make sure enums are the size of ints for structure packing */ +typedef enum { + THE_DUMMY_VALUE +} THE_DUMMY_ENUM; +COMPILE_TIME_ASSERT(enum, sizeof(THE_DUMMY_ENUM) == sizeof(int)); + + +/* Provide a substitute for offsetof() if we don't have one. + * This variant works on most (but not *all*) systems... + */ +#ifndef offsetof +#define offsetof(t,m) ((size_t)&(((t *)0)->m)) +#endif + + +/*==========================================================================*/ + +typedef unsigned char byte; + +#undef true +#undef false +#if defined(__cplusplus) +/* do NOT use the bool of C++ because some structures have boolean and they + * expect it to be 4 bytes long. as a hack, typedef it as int. */ +/* DO HOPE that the compiler built-ins for true and false are 1 and 0 ... */ +typedef int qboolean; +#else +typedef enum { + false = 0, + true = 1 +} qboolean; +#endif + + +/*==========================================================================*/ + +/* math */ +typedef float vec_t; +typedef vec_t vec3_t[3]; +typedef vec_t vec5_t[5]; +typedef int fixed4_t; +typedef int fixed8_t; +typedef int fixed16_t; + + +/*==========================================================================*/ + +#if defined(_MSC_VER) +#if defined(_WIN64) +#define ssize_t SSIZE_T +#else +typedef int ssize_t; +#endif /* _WIN64 */ +#endif /* _MSC_VER */ + +/* compatibility with M$ types */ +#if !(defined(_WIN32) || defined(_WIN64)) + +#define PASCAL +#define FAR +#define APIENTRY + +#endif /* ! WINDOWS */ + +#if !defined(__GNUC__) +#define __attribute__(x) +#endif /* __GNUC__ */ + +/* argument format attributes for function + * pointers are supported for gcc >= 3.1 + */ +#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)) +#define __fp_attribute__ __attribute__ +#else +#define __fp_attribute__(x) +#endif + +#if defined(_MSC_VER) && !defined(__cplusplus) +#define inline __inline +#endif /* _MSC_VER */ + +/*==========================================================================*/ + + +#endif /* __QSTDINC_H */ + diff --git a/Quake/quakedef.h b/Quake/quakedef.h index 84aa9de5..a2330c80 100644 --- a/Quake/quakedef.h +++ b/Quake/quakedef.h @@ -42,31 +42,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define GAMENAME "id1" // directory to look in by default -#include -#include -#include -#include -#include -#include -#include //johnfitz - -#if !defined(__GNUC__) -#define __attribute__(x) -#endif /* __GNUC__ */ - -/* argument format attributes for function - * pointers are supported for gcc >= 3.1 - */ -#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)) -#define __fp_attribute__ __attribute__ -#else -#define __fp_attribute__(x) -#endif - -#if defined(_MSC_VER) && !defined(__cplusplus) -#define inline __inline -#endif /* _MSC_VER */ - +#include "q_stdinc.h" #if defined(_WIN32) && !defined(WINDED) diff --git a/Quake/server.h b/Quake/server.h index 32b6c8ae..8c0bd539 100644 --- a/Quake/server.h +++ b/Quake/server.h @@ -186,8 +186,6 @@ extern server_t sv; // local server extern client_t *host_client; -extern jmp_buf host_abortserver; - extern double host_time; extern edict_t *sv_player; diff --git a/Quake/sv_main.c b/Quake/sv_main.c index e539e346..fbc242bb 100644 --- a/Quake/sv_main.c +++ b/Quake/sv_main.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // sv_main.c -- server main program +#include "q_stdinc.h" #include "arch_def.h" #include "net_sys.h" /* for net_defs.h */ #include "quakedef.h"