]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake2/qdata_heretic2/common/cmdlib.c
Merge branch 'winconsole' into 'master'
[xonotic/netradiant.git] / tools / quake2 / qdata_heretic2 / common / cmdlib.c
index 514a1c7b16fd02d9f527a3c41bc42d03f20a7f1f..c45ff161bf0232491c73745c8b9e171ec925ff5b 100644 (file)
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 1999-2006 Id Software, Inc. and contributors.
+   Copyright (C) 1999-2007 id Software, Inc. and contributors.
    For a list of contributors, see the accompanying CONTRIBUTORS file.
 
    This file is part of GtkRadiant.
 // Nurail: Swiped from quake3/common
 
 #include "cmdlib.h"
+#include "globaldefs.h"
 #include "mathlib.h"
 #include "inout.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
 #include <direct.h>
 #include <windows.h>
-#endif
-
-#if defined ( __linux__ ) || defined ( __APPLE__ )
+#elif GDEF_OS_NEXT
+#include <libc.h>
+#else // OTHER OSES
 #include <unistd.h>
-#endif
+#endif // OTHER OSES
 
-#ifdef NeXT
-#include <libc.h>
-#endif
+#if !GDEF_OS_WINDOWS
+#define strlwr strlower
+#endif // !GDEF_OS_WINDOWS
 
 #define BASEDIRNAME "h"
-#define PATHSEPERATOR   '/'
+#define PATHSEPERATOR '/'
 
 extern qboolean verbose;
 
@@ -72,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;
@@ -84,16 +85,6 @@ void *SafeMalloc( size_t n, char *desc ){
        return p;
 }
 
-#if defined ( __linux__ ) || defined ( __APPLE__ )
-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;
@@ -113,9 +104,11 @@ char archivedir[1024];
    ===================
  */
 #define MAX_EX_ARGC 1024
+
 int ex_argc;
 char    *ex_argv[MAX_EX_ARGC];
-#ifdef _WIN32
+
+#if GDEF_OS_WINDOWS
 #include "io.h"
 void ExpandWildcards( int *argc, char ***argv ){
        struct _finddata_t fileinfo;
@@ -154,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
 
 /*
 
@@ -342,14 +335,14 @@ double I_FloatTime( void ){
 void Q_getwd( char *out ){
        int i = 0;
 
-#ifdef WIN32
+#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] == '\\' ) {
@@ -361,15 +354,15 @@ void Q_getwd( char *out ){
 
 
 void Q_mkdir( const char *path ){
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
        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 ) );
        }
@@ -799,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 ){
@@ -964,11 +958,7 @@ int ParseNum( const char *str ){
    ============================================================================
  */
 
-#ifdef _SGI_SOURCE
-#define __BIG_ENDIAN__
-#endif
-
-#ifdef __BIG_ENDIAN__
+#if GDEF_ARCH_ENDIAN_BIG
 
 short   LittleShort( short l ){
        byte b1,b2;
@@ -1017,7 +1007,7 @@ float   BigFloat( float l ){
 }
 
 
-#else
+#else // !GDEF_ARCH_ENDIAN_BIG
 
 
 short   BigShort( short l ){
@@ -1065,8 +1055,7 @@ float   LittleFloat( float l ){
        return l;
 }
 
-
-#endif
+#endif // ! GDEF_ARCH_ENDIAN_BIG
 
 
 //=======================================================
@@ -1140,14 +1129,14 @@ void    CreatePath( const char *path ){
        char c;
        char dir[1024];
 
-#ifdef _WIN32
+#if GDEF_OS_WINDOWS
        int olddrive = -1;
 
        if ( path[1] == ':' ) {
                olddrive = _getdrive();
                _chdrive( toupper( path[0] ) - 'A' + 1 );
        }
-#endif
+#endif // !GDEF_OS_WINDOWS
 
        if ( path[1] == ':' ) {
                path += 2;
@@ -1163,11 +1152,11 @@ void    CreatePath( const char *path ){
                }
        }
 
-#ifdef _WIN32
+#if GDEF_OS_WINDOWS
        if ( olddrive != -1 ) {
                _chdrive( olddrive );
        }
-#endif
+#endif // !GDEF_OS_WINDOWS
 }
 
 
@@ -1189,10 +1178,9 @@ void QCopyFile( const char *from, const char *to ){
 }
 
 void Sys_Sleep( int n ){
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
        Sleep( n );
-#endif
-#if defined ( __linux__ ) || defined ( __APPLE__ )
+#else // !GDEF_OS_WINDOWS
        usleep( n * 1000 );
-#endif
+#endif // !GDEF_OS_WINDOWS
 }