From: Thomas Debesse Date: Sat, 27 Jan 2018 22:54:15 +0000 (+0100) Subject: rework GDEF_OS macros X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=692df76213412df4baa68ec14868de8d0082274f;p=xonotic%2Fnetradiant.git rework GDEF_OS macros --- diff --git a/contrib/gtkgensurf/gensurf.h b/contrib/gtkgensurf/gensurf.h index 84a78cd6..8ed2dd53 100644 --- a/contrib/gtkgensurf/gensurf.h +++ b/contrib/gtkgensurf/gensurf.h @@ -57,7 +57,7 @@ extern _QERBrushTable __BRUSHTABLENAME; #define PLUGIN #define Q3RADIANT -//#if GDEF_OS_LINUX || GDEF_OS_MACOS +//#if !GDEF_OS_WINDOWS #if 1 #include #else diff --git a/libs/globaldefs.h b/libs/globaldefs.h index 146dd788..5d170523 100644 --- a/libs/globaldefs.h +++ b/libs/globaldefs.h @@ -49,7 +49,6 @@ #define GDEF_OS_LINUX 0 #endif - #define GDEF_OS_BSD 0 #if defined(__FreeBSD__) @@ -84,6 +83,30 @@ #define GDEF_OS_BSD_DRAGONFLY 0 #endif +#if defined(__osf) || defined(__osf__) || defined(__OSF__) +#define GDEF_OS_OSF1 1 +#else +#define GDEF_OS_OSF1 0 +#endif + +#if defined(_MIPS_ISA) +#define GDEF_OS_IRIX 1 +#else +#define GDEF_OS_IRIX 0 +#endif + +#if defined(NeXT) +#define GDEF_OS_NEXT 1 +#else +#define GDEF_OS_NEXT 0 +#endif + +#if GDEF_OS_LINUX || GDEF_OS_BSD +#define GDEF_OS_XDG 1 +#else +#define GDEF_OS_XDG 0 +#endif + // COMPILER #if defined(_MSC_VER) @@ -122,4 +145,4 @@ #endif #endif -#endif +#endif // !INCLUDED_LIBS_GLOBALDEFS diff --git a/plugins/textool/StdAfx.h b/plugins/textool/StdAfx.h index 2ebd1b01..aee23c53 100644 --- a/plugins/textool/StdAfx.h +++ b/plugins/textool/StdAfx.h @@ -29,7 +29,6 @@ #include #if !GDEF_OS_WINDOWS - // Necessary for proper boolean type declaration #include "qertypes.h" @@ -77,8 +76,7 @@ typedef struct tagRECT long right; long bottom; } RECT, *PRECT, *LPRECT; - -#endif // __linux__ +#endif // !GDEF_OS_WINDOWS // plugin // FIXME TTimo: drop this diff --git a/radiant/environment.cpp b/radiant/environment.cpp index b38ef992..bc64964a 100644 --- a/radiant/environment.cpp +++ b/radiant/environment.cpp @@ -139,8 +139,10 @@ void gamedetect(){ if ( gamedetect_check_game( "nexuiz.game", "data/common-spog.pk3", "nexuiz.exe", buf, p - buf ) ) #elif GDEF_OS_MACOS if ( gamedetect_check_game( "nexuiz.game", "data/common-spog.pk3", "Nexuiz.app/Contents/Info.plist", buf, p - buf ) ) -#else +#elif GDEF_OS_LINUX if ( gamedetect_check_game( "nexuiz.game", "data/common-spog.pk3", "nexuiz-linux-glx.sh", buf, p - buf ) ) +#else + if ( gamedetect_check_game( "nexuiz.game", "data/common-spog.pk3", NULL, buf, p - buf ) ) #endif { return; } diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index 9a07e061..a1c35919 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -213,9 +213,7 @@ void HomePaths_Realise(){ } path.clear(); path << DirectoryCleaned( g_get_home_dir() ) << prefix << "/"; -#endif - -#if GDEF_OS_WINDOWS +#elif GDEF_OS_WINDOWS TCHAR mydocsdir[MAX_PATH + 1]; wchar_t *mydocsdirw; HMODULE shfolder = LoadLibrary( "shfolder.dll" ); @@ -252,9 +250,7 @@ void HomePaths_Realise(){ break; } } -#endif - -#if (GDEF_OS_POSIX && !GDEF_OS_MACOS) +#elif GDEF_OS_XDG path.clear(); path << DirectoryCleaned( g_get_user_data_dir() ) << ( prefix + 1 ) << "/"; if ( file_exists( path.c_str() ) && file_is_directory( path.c_str() ) ) { diff --git a/radiant/server.cpp b/radiant/server.cpp index c9e07780..879770c5 100644 --- a/radiant/server.cpp +++ b/radiant/server.cpp @@ -178,9 +178,9 @@ FunctionPointer findSymbol( const char* symbol ){ } }; -#else +#else // !GDEF_OS_POSIX #error "unsupported platform" -#endif +#endif // !GDEF_OS_POSIX class DynamicLibraryModule { diff --git a/tools/quake2/common/cmdlib.c b/tools/quake2/common/cmdlib.c index 02e0be87..5063f739 100644 --- a/tools/quake2/common/cmdlib.c +++ b/tools/quake2/common/cmdlib.c @@ -32,11 +32,9 @@ #if GDEF_OS_WINDOWS #include #include -#endif - -#if GDEF_OS_LINUX || GDEF_OS_MACOS +#else // !GDEF_OS_WINDOWS #include -#endif +#endif // !GDEF_OS_WINDOWS #ifdef NeXT #include @@ -1177,8 +1175,7 @@ void QCopyFile( const char *from, const char *to ){ void Sys_Sleep( int n ){ #if GDEF_OS_WINDOWS Sleep( n ); -#endif -#if GDEF_OS_LINUX || GDEF_OS_MACOS +#else // !GDEF_OS_WINDOWS usleep( n * 1000 ); -#endif +#endif // !GDEF_OS_WINDOWS } diff --git a/tools/quake2/common/path_init.c b/tools/quake2/common/path_init.c index cd413805..76653141 100644 --- a/tools/quake2/common/path_init.c +++ b/tools/quake2/common/path_init.c @@ -18,30 +18,24 @@ You should have received a copy of the GNU General Public License along with GtkRadiant; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* Nurail: Swiped from Q3Map2 - */ #include "globaldefs.h" -#if GDEF_OS_LINUX || GDEF_OS_MACOS - #define Q_UNIX -#endif - -#ifdef Q_UNIX +#if !GDEF_OS_WINDOWS #include #include #include -#endif - +#endif // !GDEF_OS_WINDOWS /* dependencies */ #include "cmdlib.h" #include "inout.h" - - /* path support */ #define MAX_BASE_PATHS 10 #define MAX_GAME_PATHS 10 @@ -65,9 +59,9 @@ char *gamePaths[ MAX_GAME_PATHS ]; */ char *LokiGetHomeDir( void ){ - #ifndef Q_UNIX + #if GDEF_OS_WINDOWS return NULL; - #else + #else // !GDEF_OS_WINDOWS char *home; uid_t id; struct passwd *pwd; @@ -91,7 +85,7 @@ char *LokiGetHomeDir( void ){ /* return it */ return home; - #endif + #endif // !GDEF_OS_WINDOWS } @@ -102,10 +96,10 @@ char *LokiGetHomeDir( void ){ */ void LokiInitPaths( char *argv0 ){ - #ifndef Q_UNIX + #if GDEF_OS_WINDOWS /* this is kinda crap, but hey */ strcpy( installPath, "../" ); - #else + #else // !GDEF_OS_WINDOWS char temp[ MAX_OS_PATH ]; char *home; char *path; @@ -177,7 +171,7 @@ void LokiInitPaths( char *argv0 ){ /* set home path */ homePath = home; - #endif + #endif // !GDEF_OS_WINDOWS } @@ -223,7 +217,7 @@ void AddBasePath( char *path ){ */ void AddHomeBasePath( char *path ){ - #ifdef Q_UNIX + #if !GDEF_OS_WINDOWS int i; char temp[ MAX_OS_PATH ]; @@ -245,7 +239,7 @@ void AddHomeBasePath( char *path ){ strcpy( basePaths[ 0 ], temp ); CleanPath( basePaths[ 0 ] ); numBasePaths++; - #endif + #endif // !GDEF_OS_WINDOWS } diff --git a/tools/quake2/common/threads.c b/tools/quake2/common/threads.c index d648e99e..1d4e996b 100644 --- a/tools/quake2/common/threads.c +++ b/tools/quake2/common/threads.c @@ -25,8 +25,7 @@ // The below define is necessary to use // pthreads extensions like pthread_mutexattr_settype #define _GNU_SOURCE -#include -#endif +#endif // !GDEF_OS_WINDOWS #include "cmdlib.h" #include "mathlib.h" @@ -101,6 +100,8 @@ void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( } +#if GDEF_OS_WINDOWS + /* =================================================================== @@ -108,9 +109,6 @@ void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( =================================================================== */ -#if GDEF_OS_WINDOWS - -#define USED #include @@ -212,7 +210,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } -#endif +#elif GDEF_OS_OSF1 /* =================================================================== @@ -222,9 +220,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ =================================================================== */ -#ifdef __osf__ -#define USED - int numthreads = 4; void ThreadSetDefault( void ){ @@ -319,7 +314,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } -#endif +#elif GDEF_OS_IRIX /* =================================================================== @@ -329,15 +324,11 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ =================================================================== */ -#ifdef _MIPS_ISA -#define USED - #include #include #include #include - int numthreads = -1; abilock_t lck; @@ -406,8 +397,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } -#endif - +#elif GDEF_OS_LINUX || GDEF_OS_BSD || GDEF_OS_MACOS /* ======================================================================= @@ -417,9 +407,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ ======================================================================= */ -#if GDEF_OS_LINUX || GDEF_OS_MACOS -#define USED - // Setting default Threads to 1 int numthreads = 1; @@ -570,9 +557,10 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ Sys_Printf( " (%i)\n", end - start ); } } -#endif // ifdef __linux__ +#else // UNKNOWN OS + /* ======================================================================= @@ -581,8 +569,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ ======================================================================= */ -#ifndef USED - int numthreads = 1; void ThreadSetDefault( void ){ @@ -617,4 +603,4 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } } -#endif +#endif // UNKNOWN OS diff --git a/tools/quake2/q2map/q2map.h b/tools/quake2/q2map/q2map.h index 644f7b9e..8f4ac8d3 100644 --- a/tools/quake2/q2map/q2map.h +++ b/tools/quake2/q2map/q2map.h @@ -23,19 +23,13 @@ #include "globaldefs.h" /* platform-specific */ -#if GDEF_OS_LINUX || GDEF_OS_MACOS - #define Q_UNIX -#endif - -#ifdef Q_UNIX +#if GDEF_OS_WINDOWS + #include +#else // !GDEF_OS_WINDOWS #include #include #include -#endif - -#if GDEF_OS_WINDOWS - #include -#endif +#endif // !GDEF_OS_WINDOWS #include diff --git a/tools/quake2/qdata_heretic2/common/cmdlib.c b/tools/quake2/qdata_heretic2/common/cmdlib.c index 7a49c52e..c45ff161 100644 --- a/tools/quake2/qdata_heretic2/common/cmdlib.c +++ b/tools/quake2/qdata_heretic2/common/cmdlib.c @@ -31,18 +31,18 @@ #if GDEF_OS_WINDOWS #include #include -#endif - -#if GDEF_OS_LINUX || GDEF_OS_MACOS +#elif GDEF_OS_NEXT +#include +#else // OTHER OSES #include -#endif +#endif // OTHER OSES -#ifdef NeXT -#include -#endif +#if !GDEF_OS_WINDOWS +#define strlwr strlower +#endif // !GDEF_OS_WINDOWS #define BASEDIRNAME "h" -#define PATHSEPERATOR '/' +#define PATHSEPERATOR '/' extern qboolean verbose; @@ -73,7 +73,7 @@ void *safe_malloc_info( size_t size, char* info ){ return p; } -#endif +#endif // !SAFE_MALLOC void *SafeMalloc( size_t n, char *desc ){ void *p; @@ -85,16 +85,6 @@ void *SafeMalloc( size_t n, char *desc ){ return p; } -#if GDEF_OS_LINUX || GDEF_OS_MACOS -void strlwr( char *conv_str ){ - int i; - - for ( i = 0; i < strlen( conv_str ); i++ ) - conv_str[i] = tolower( conv_str[i] ); -} -#endif - - // set these before calling CheckParm int myargc; char **myargv; @@ -114,8 +104,10 @@ char archivedir[1024]; =================== */ #define MAX_EX_ARGC 1024 + int ex_argc; char *ex_argv[MAX_EX_ARGC]; + #if GDEF_OS_WINDOWS #include "io.h" void ExpandWildcards( int *argc, char ***argv ){ @@ -155,10 +147,10 @@ void ExpandWildcards( int *argc, char ***argv ){ *argc = ex_argc; *argv = ex_argv; } -#else +#else // !GDEF_OS_WINDOWS void ExpandWildcards( int *argc, char ***argv ){ } -#endif +#endif // !GDEF_OS_WINDOWS /* @@ -346,11 +338,11 @@ void Q_getwd( char *out ){ #if GDEF_OS_WINDOWS _getcwd( out, 256 ); strcat( out, "\\" ); -#else +#else // !GDEF_OS_WINDOWS // Gef: Changed from getwd() to getcwd() to avoid potential buffer overflow getcwd( out, 256 ); strcat( out, "/" ); -#endif +#endif // !GDEF_OS_WINDOWS while ( out[i] != 0 ) { if ( out[i] == '\\' ) { @@ -366,11 +358,11 @@ void Q_mkdir( const char *path ){ if ( _mkdir( path ) != -1 ) { return; } -#else +#else // !GDEF_OS_WINDOWS if ( mkdir( path, 0777 ) != -1 ) { return; } -#endif +#endif // !GDEF_OS_WINDOWS if ( errno != EEXIST ) { Error( "mkdir %s: %s",path, strerror( errno ) ); } @@ -800,6 +792,7 @@ void StripExtension( char *path ){ Extract file parts ==================== */ + // FIXME: should include the slash, otherwise // backing to an empty path will be wrong when appending a slash void ExtractFilePath( const char *path, char *dest ){ @@ -1014,7 +1007,7 @@ float BigFloat( float l ){ } -#else +#else // !GDEF_ARCH_ENDIAN_BIG short BigShort( short l ){ @@ -1062,8 +1055,7 @@ float LittleFloat( float l ){ return l; } - -#endif +#endif // ! GDEF_ARCH_ENDIAN_BIG //======================================================= @@ -1144,7 +1136,7 @@ void CreatePath( const char *path ){ olddrive = _getdrive(); _chdrive( toupper( path[0] ) - 'A' + 1 ); } -#endif +#endif // !GDEF_OS_WINDOWS if ( path[1] == ':' ) { path += 2; @@ -1164,7 +1156,7 @@ void CreatePath( const char *path ){ if ( olddrive != -1 ) { _chdrive( olddrive ); } -#endif +#endif // !GDEF_OS_WINDOWS } @@ -1188,8 +1180,7 @@ void QCopyFile( const char *from, const char *to ){ void Sys_Sleep( int n ){ #if GDEF_OS_WINDOWS Sleep( n ); -#endif -#if GDEF_OS_LINUX || GDEF_OS_MACOS +#else // !GDEF_OS_WINDOWS usleep( n * 1000 ); -#endif +#endif // !GDEF_OS_WINDOWS } diff --git a/tools/quake2/qdata_heretic2/common/path_init.c b/tools/quake2/qdata_heretic2/common/path_init.c index 14470377..254977bc 100644 --- a/tools/quake2/qdata_heretic2/common/path_init.c +++ b/tools/quake2/qdata_heretic2/common/path_init.c @@ -26,23 +26,16 @@ #include "globaldefs.h" -#if GDEF_OS_LINUX || GDEF_OS_MACOS - #define Q_UNIX -#endif - -#ifdef Q_UNIX +#if !GDEF_OS_WINDOWS #include #include #include -#endif - +#endif // !GDEF_OS_WINDOWS /* dependencies */ #include "cmdlib.h" #include "inout.h" - - /* path support */ #define MAX_BASE_PATHS 10 #define MAX_GAME_PATHS 10 @@ -66,9 +59,9 @@ char *gamePaths[ MAX_GAME_PATHS ]; */ char *LokiGetHomeDir( void ){ - #ifndef Q_UNIX + #if GDEF_OS_WINDOWS return NULL; - #else + #else // !GDEF_OS_WINDOWS char *home; uid_t id; struct passwd *pwd; @@ -92,7 +85,7 @@ char *LokiGetHomeDir( void ){ /* return it */ return home; - #endif + #endif // !GDEF_OS_WINDOWS } @@ -103,10 +96,10 @@ char *LokiGetHomeDir( void ){ */ void LokiInitPaths( char *argv0 ){ - #ifndef Q_UNIX + #if GDEF_OS_WINDOWS /* this is kinda crap, but hey */ strcpy( installPath, "../" ); - #else + #else // !GDEF_OS_WINDOWS char temp[ MAX_OS_PATH ]; char *home; char *path; @@ -178,7 +171,7 @@ void LokiInitPaths( char *argv0 ){ /* set home path */ homePath = home; - #endif + #endif // !GDEF_OS_WINDOWS } @@ -224,7 +217,7 @@ void AddBasePath( char *path ){ */ void AddHomeBasePath( char *path ){ - #ifdef Q_UNIX + #if !GDEF_OS_WINDOWS int i; char temp[ MAX_OS_PATH ]; @@ -246,7 +239,7 @@ void AddHomeBasePath( char *path ){ strcpy( basePaths[ 0 ], temp ); CleanPath( basePaths[ 0 ] ); numBasePaths++; - #endif + #endif // !GDEF_OS_WINDOWS } diff --git a/tools/quake2/qdata_heretic2/common/threads.c b/tools/quake2/qdata_heretic2/common/threads.c index 0ee1e2d5..5fe28940 100644 --- a/tools/quake2/qdata_heretic2/common/threads.c +++ b/tools/quake2/qdata_heretic2/common/threads.c @@ -25,8 +25,7 @@ // The below define is necessary to use // pthreads extensions like pthread_mutexattr_settype #define _GNU_SOURCE -#include -#endif +#endif // !GDEF_OS_WINDOWS #include "cmdlib.h" #include "mathlib.h" @@ -101,6 +100,8 @@ void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( } +#if GDEF_OS_WINDOWS + /* =================================================================== @@ -108,9 +109,6 @@ void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( =================================================================== */ -#if GDEF_OS_WINDOWS - -#define USED #include @@ -211,7 +209,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } -#endif +#elif GDEF_OS_OSF1 /* =================================================================== @@ -221,9 +219,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ =================================================================== */ -#ifdef __osf__ -#define USED - int numthreads = 4; void ThreadSetDefault( void ){ @@ -232,7 +227,6 @@ void ThreadSetDefault( void ){ } } - #include pthread_mutex_t *my_mutex; @@ -318,7 +312,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } -#endif +#elif GDEF_OS_IRIX /* =================================================================== @@ -328,15 +322,11 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ =================================================================== */ -#ifdef _MIPS_ISA -#define USED - #include #include #include #include - int numthreads = -1; abilock_t lck; @@ -405,8 +395,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } -#endif - +#elif GDEF_OS_LINUX || GDEF_OS_BSD || GDEF_OS_MACOS /* ======================================================================= @@ -416,9 +405,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ ======================================================================= */ -#if GDEF_OS_LINUX -#define USED - int numthreads = 4; void ThreadSetDefault( void ){ @@ -571,9 +557,10 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ Sys_Printf( " (%i)\n", end - start ); } } -#endif // ifdef __linux__ +#else // UNKNOWN OS + /* ======================================================================= @@ -582,8 +569,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ ======================================================================= */ -#ifndef USED - int numthreads = 1; void ThreadSetDefault( void ){ @@ -618,4 +603,4 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } } -#endif +#endif // UNKNOWN OS diff --git a/tools/quake2/qdata_heretic2/tmix.c b/tools/quake2/qdata_heretic2/tmix.c index 58cc369f..936cd6e5 100644 --- a/tools/quake2/qdata_heretic2/tmix.c +++ b/tools/quake2/qdata_heretic2/tmix.c @@ -24,6 +24,10 @@ #define MAXFILES 2048 +#if !GDEF_OS_WINDOWS +#define strlwr strlower +#endif // !GDEF_OS_WINDOWS + typedef struct { int x; diff --git a/tools/quake3/common/aselib.c b/tools/quake3/common/aselib.c index bb3be0ea..78549ad0 100644 --- a/tools/quake3/common/aselib.c +++ b/tools/quake3/common/aselib.c @@ -34,6 +34,10 @@ #define VERBOSE( x ) { if ( ase.verbose ) { Sys_Printf x ; } } +#if !GDEF_OS_WINDOWS +#define strlwr strlower +#endif // !GDEF_OS_WINDOWS + typedef struct { float x, y, z; @@ -114,22 +118,6 @@ static char gl_filename[1024]; static void ASE_Process( void ); static void ASE_FreeGeomObject( int ndx ); -#if GDEF_OS_LINUX || GDEF_OS_MACOS - -static char* strlwr( char* string ){ - char *cp; - for ( cp = string; *cp; ++cp ) - { - if ( 'A' <= *cp && *cp <= 'Z' ) { - *cp += 'a' - 'A'; - } - } - - return string; -} - -#endif - /* ** ASE_Load */ diff --git a/tools/quake3/common/cmdlib.c b/tools/quake3/common/cmdlib.c index b74c7b33..90174e36 100644 --- a/tools/quake3/common/cmdlib.c +++ b/tools/quake3/common/cmdlib.c @@ -38,18 +38,14 @@ #if GDEF_OS_WINDOWS #include #include -#endif - -#if GDEF_OS_LINUX || GDEF_OS_MACOS -#include -#endif - -#ifdef NeXT +#elif GDEF_OS_NEXT #include -#endif +#else // OTHER OS +#include +#endif // OTHER OS -#define BASEDIRNAME "quake" // assumed to have a 2 or 3 following -#define PATHSEPERATOR '/' +#define BASEDIRNAME "quake" // assumed to have a 2 or 3 following +#define PATHSEPERATOR '/' #ifdef SAFE_MALLOC void *safe_malloc( size_t size ){ @@ -73,7 +69,7 @@ void *safe_malloc_info( size_t size, char* info ){ return p; } -#endif +#endif // !SAFE_MALLOC // set these before calling CheckParm int myargc; @@ -96,6 +92,7 @@ char archivedir[1024]; #define MAX_EX_ARGC 1024 int ex_argc; char *ex_argv[MAX_EX_ARGC]; + #if GDEF_OS_WINDOWS #include "io.h" void ExpandWildcards( int *argc, char ***argv ){ @@ -135,10 +132,10 @@ void ExpandWildcards( int *argc, char ***argv ){ *argc = ex_argc; *argv = ex_argv; } -#else +#else // !GDEF_OS_WINDOWS void ExpandWildcards( int *argc, char ***argv ){ } -#endif +#endif // !GDEF_OS_WINDOWS /* @@ -296,13 +293,13 @@ void Q_getwd( char *out ){ #if GDEF_OS_WINDOWS _getcwd( out, 256 ); strcat( out, "\\" ); -#else +#else // !GDEF_OS_WINDOWS // Gef: Changed from getwd() to getcwd() to avoid potential buffer overflow if ( !getcwd( out, 256 ) ) { *out = 0; } strcat( out, "/" ); -#endif +#endif // !GDEF_OS_WINDOWS while ( out[i] != 0 ) { if ( out[i] == '\\' ) { @@ -331,14 +328,14 @@ void Q_mkdir( const char *path ){ p = q; } } -#else +#else // !GDEF_OS_WINDOWS if ( mkdir( path, 0777 ) != -1 ) { return; } if ( errno == ENOENT ) { p = strrchr( path, '/' ); } -#endif +#endif // !GDEF_OS_WINDOWS if ( p ) { strncpy( parentbuf, path, sizeof( parentbuf ) ); if ( (int) ( p - path ) < (int) sizeof( parentbuf ) ) { @@ -931,9 +928,7 @@ float BigFloat( float l ){ return l; } - -#else - +#else // !GDEF_ARCH_ENDIAN_BIG short BigShort( short l ){ byte b1,b2; @@ -980,8 +975,7 @@ float LittleFloat( float l ){ return l; } - -#endif +#endif // !GDEF_ARCH_ENDIAN_BIG //======================================================= @@ -1062,7 +1056,7 @@ void CreatePath( const char *path ){ olddrive = _getdrive(); _chdrive( toupper( path[0] ) - 'A' + 1 ); } -#endif +#endif // !GDEF_OS_WINDOWS if ( path[1] == ':' ) { path += 2; @@ -1082,7 +1076,7 @@ void CreatePath( const char *path ){ if ( olddrive != -1 ) { _chdrive( olddrive ); } -#endif +#endif // !>GDEF_OS_WINDOWS } @@ -1106,8 +1100,7 @@ void QCopyFile( const char *from, const char *to ){ void Sys_Sleep( int n ){ #if GDEF_OS_WINDOWS Sleep( n ); -#endif -#if GDEF_OS_LINUX || GDEF_OS_MACOS +#else // !GDEF_OS_WINDOWS usleep( n * 1000 ); -#endif +#endif // !GDEF_OS_WINDOWS } diff --git a/tools/quake3/common/threads.c b/tools/quake3/common/threads.c index 4cb3e4fe..5d81cf5e 100644 --- a/tools/quake3/common/threads.c +++ b/tools/quake3/common/threads.c @@ -21,12 +21,12 @@ #include "globaldefs.h" #include + #if !GDEF_OS_WINDOWS // The below define is necessary to use // pthreads extensions like pthread_mutexattr_settype #define _GNU_SOURCE -#include -#endif +#endif // !GDEF_OS_WINDOWS #include "cmdlib.h" #include "mathlib.h" @@ -111,6 +111,8 @@ void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( } +#if GDEF_OS_WINDOWS + /* =================================================================== @@ -118,9 +120,6 @@ void RunThreadsOnIndividual( int workcnt, qboolean showpacifier, void ( *func )( =================================================================== */ -#if GDEF_OS_WINDOWS - -#define USED #include @@ -221,7 +220,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } -#endif +#elif GDEF_OS_OSF1 /* =================================================================== @@ -231,9 +230,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ =================================================================== */ -#ifdef __osf__ -#define USED - int numthreads = 4; void ThreadSetDefault( void ){ @@ -242,7 +238,6 @@ void ThreadSetDefault( void ){ } } - #include pthread_mutex_t *my_mutex; @@ -328,7 +323,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } -#endif +#elif GDEF_OS_IRIX /* =================================================================== @@ -338,7 +333,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ =================================================================== */ -#ifdef _MIPS_ISA #define USED #include @@ -346,7 +340,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ #include #include - int numthreads = -1; abilock_t lck; @@ -415,8 +408,7 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } -#endif - +#elif GDEF_OS_LINUX || GDEF_OS_BSD || GDEF_OS_MACOS /* ======================================================================= @@ -426,9 +418,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ ======================================================================= */ -#if GDEF_OS_LINUX || GDEF_OS_MACOS -#define USED - #include int numthreads = -1; @@ -597,9 +586,10 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ Sys_Printf( " (%i)\n", end - start ); } } -#endif // ifdef __linux__ +#else // UNKNOWN OS + /* ======================================================================= @@ -608,8 +598,6 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ ======================================================================= */ -#ifndef USED - int numthreads = 1; void ThreadSetDefault( void ){ @@ -643,4 +631,4 @@ void RunThreadsOn( int workcnt, qboolean showpacifier, void ( *func )( int ) ){ } } -#endif +#endif // UNKNOWN OS diff --git a/tools/quake3/common/trilib.c b/tools/quake3/common/trilib.c index 5f403418..72dd5f3c 100644 --- a/tools/quake3/common/trilib.c +++ b/tools/quake3/common/trilib.c @@ -37,11 +37,11 @@ #define FLOAT_END -FLOAT_START #define MAGIC 123322 -//#define NOISY 1 +// #define NOISY 1 -#if GDEF_OS_LINUX || GDEF_OS_MACOS +#if !GDEF_OS_WINDOWS #define strlwr strlower -#endif +#endif // !GDEF_OS_WINDOWS typedef struct { float v[3]; diff --git a/tools/quake3/common/vfs.h b/tools/quake3/common/vfs.h index 9026a296..310d67c5 100644 --- a/tools/quake3/common/vfs.h +++ b/tools/quake3/common/vfs.h @@ -35,15 +35,16 @@ // to get PATH_MAX #include -#if GDEF_OS_LINUX || GDEF_OS_MACOS -#include -#include -#else + +#if GDEF_OS_WINDOWS #include #include #define S_ISDIR( mode ) ( mode & _S_IFDIR ) #define PATH_MAX 260 -#endif +#else // !GDEF_OS_WINDOWS +#include +#include +#endif // !GDEF_OS_WINDOWS #define VFS_MAXDIRS 64 diff --git a/tools/quake3/q3data/md3lib.c b/tools/quake3/q3data/md3lib.c index 93b1dfe0..2bc7e09a 100644 --- a/tools/quake3/q3data/md3lib.c +++ b/tools/quake3/q3data/md3lib.c @@ -21,16 +21,18 @@ #include "globaldefs.h" #include + #if GDEF_OS_WINDOWS #include -#endif +#endif // GDEF_OS_WINDOWS + #include "md3lib.h" -#if GDEF_OS_LINUX || GDEF_OS_MACOS -#define filelength(f) Q_filelength(f) -#else +#if GDEF_OS_WINDOWS #define filelength(f) filelength(fileno(f)) -#endif +#else // !GDEF_OS_WINDOWS +#define filelength(f) Q_filelength(f) +#endif // ! GDEF_OS_WINDOWS /* ** MD3_ComputeTagFromTri diff --git a/tools/quake3/q3data/p3dlib.c b/tools/quake3/q3data/p3dlib.c index 97cc3f6a..ea59bb4d 100644 --- a/tools/quake3/q3data/p3dlib.c +++ b/tools/quake3/q3data/p3dlib.c @@ -24,21 +24,23 @@ #if GDEF_OS_WINDOWS #include -#endif +#endif // GDEF_OS_WINDOWS + #include #include #include #define MAX_POLYSETS 64 -#if GDEF_OS_LINUX || GDEF_OS_MACOS +#if GDEF_OS_WINDOWS + #define filelength(f) filelength(fileno(f)) +#else // !GDEF_OS_WINDOWS #include "cmdlib.h" #define _strcmpi Q_stricmp #define strlwr strlower #define filelength(f) Q_filelength(f) -#else - #define filelength(f) filelength(fileno(f)) -#endif +#endif // !GDEF_OS_WINDOWS + typedef struct { long len; diff --git a/tools/quake3/q3data/q3data.c b/tools/quake3/q3data/q3data.c index 331f6138..0b75861e 100644 --- a/tools/quake3/q3data/q3data.c +++ b/tools/quake3/q3data/q3data.c @@ -20,9 +20,11 @@ */ #include "globaldefs.h" + #if GDEF_OS_WINDOWS #include -#endif +#endif // GDEF_OS_WINDOWS + #include "q3data.h" #include "md3lib.h" @@ -41,9 +43,9 @@ char *moddir = NULL; // some old defined that was in cmdlib lost during merge char writedir[1024]; -#if GDEF_OS_LINUX || GDEF_OS_MACOS +#if !GDEF_OS_WINDOWS #define strlwr strlower -#endif +#endif // !GDEF_OS_WINDOWS /* ======================================================= diff --git a/tools/quake3/q3map2/path_init.c b/tools/quake3/q3map2/path_init.c index 96b33fcb..9c3047de 100644 --- a/tools/quake3/q3map2/path_init.c +++ b/tools/quake3/q3map2/path_init.c @@ -26,18 +26,12 @@ ------------------------------------------------------------------------------- */ - - /* marker */ #define PATH_INIT_C - - /* dependencies */ #include "q3map2.h" - - /* path support */ #define MAX_BASE_PATHS 10 #define MAX_GAME_PATHS 10 @@ -48,11 +42,9 @@ char *homePath; #if GDEF_OS_MACOS char *macLibraryApplicationSupportPath; -#endif - -#if (GDEF_OS_POSIX && !GDEF_OS_MACOS) +#elif GDEF_OS_XDG char *xdgDataHomePath; -#endif // (GDEF_OS_POSIX && !GDEF_OS_MACOS) +#endif // GDEF_OS_XDG char installPath[ MAX_OS_PATH ]; @@ -96,7 +88,7 @@ char *LokiGetHomeDir( void ){ /* return it */ return home; - #endif + #endif // !GDEF_OS_WINDOWS } @@ -124,12 +116,10 @@ void LokiInitPaths( char *argv0 ){ } #if GDEF_OS_MACOS - char *subPath = "/Library/Application Support"; - macLibraryApplicationSupportPath = safe_malloc( sizeof( char ) * ( strlen( home ) + strlen( subPath ) ) ); - sprintf( macLibraryApplicationSupportPath, "%s%s", home, subPath ); - #endif // GDEF_OS_MACOS - - #if (GDEF_OS_POSIX && !GDEF_OS_MACOS) + char *subPath = "/Library/Application Support"; + macLibraryApplicationSupportPath = safe_malloc( sizeof( char ) * ( strlen( home ) + strlen( subPath ) ) ); + sprintf( macLibraryApplicationSupportPath, "%s%s", home, subPath ); + #elif GDEF_OS_XDG xdgDataHomePath = getenv( "XDG_DATA_HOME" ); if ( xdgDataHomePath == NULL ) { @@ -137,7 +127,7 @@ void LokiInitPaths( char *argv0 ){ xdgDataHomePath = safe_malloc( sizeof( char ) * ( strlen( home ) + strlen( subPath ) ) ); sprintf( xdgDataHomePath, "%s%s", home, subPath ); } - #endif // (GDEF_OS_POSIX && !GDEF_OS_MACOS) + #endif // GDEF_OS_XDG #if GDEF_OS_WINDOWS /* this is kinda crap, but hey */ @@ -350,9 +340,7 @@ void AddHomeBasePath( char *path ){ */ tempHomePath = macLibraryApplicationSupportPath; path = path + 1; - #endif // GDEF_OS_MACOS - - #if (GDEF_OS_POSIX && !GDEF_OS_MACOS) + #elif GDEF_OS_XDG /* on Linux, check if game uses ${XDG_DATA_HOME}/prefix instead of ${HOME}/.prefix if yes and home path is not user supplied @@ -375,7 +363,7 @@ void AddHomeBasePath( char *path ){ } path = path + 1; } - #endif // (GDEF_OS_POSIX && !GDEF_OS_MACOS) + #endif // GDEF_OS_XDG /* concatenate home dir and path */ sprintf( temp, "%s/%s", tempHomePath, path ); diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index ce37d76c..0d70d39d 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -89,14 +89,12 @@ ------------------------------------------------------------------------------- */ -#if 1 - #if GDEF_OS_WINDOWS - #define Q_stricmp stricmp - #define Q_strncasecmp strnicmp - #else - #define Q_stricmp strcasecmp - #define Q_strncasecmp strncasecmp - #endif +#if GDEF_OS_WINDOWS + #define Q_stricmp stricmp + #define Q_strncasecmp strnicmp +#else + #define Q_stricmp strcasecmp + #define Q_strncasecmp strncasecmp #endif /* macro version */