]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
portability fixes
authorspog <spog>
Tue, 9 May 2006 20:51:34 +0000 (20:51 +0000)
committerspog <spog>
Tue, 9 May 2006 20:51:34 +0000 (20:51 +0000)
git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@59 8a3a26a2-13c4-0310-b231-cf6edde360e5

25 files changed:
SConstruct
contrib/bobtoolz/misc.cpp
contrib/camera/funchandlers.cpp
contrib/camera/misc.cpp
contrib/hydratoolz/plugin.cpp
libs/cmdlib/cmdlib.cpp
libs/gtkutil/clipboard.cpp
libs/jpeglib.h
libs/l_net/l_net.c
libs/os/path.h
libs/radiant_jpeglib.h
libs/str.h
plugins/textool/StdAfx.h
radiant/GtkRadiant.vcproj
radiant/environment.cpp
radiant/error.cpp
radiant/mainframe.cpp
radiant/qe3.cpp
radiant/qgl.cpp
radiant/server.cpp
radiant/sockets.cpp [new file with mode: 0644]
radiant/sockets.h [new file with mode: 0644]
radiant/timer.cpp
radiant/url.cpp
radiant/watchbsp.cpp

index d4985c675332b6df5b81053b9d785a74c26ef52e..a8cbf68e0021f70fe10566ed5f3b1e9ce77ceae3 100644 (file)
@@ -167,8 +167,10 @@ LINK = CXX
 # common flags
 warningFlags = '-W -Wall -Wcast-align -Wcast-qual -Wno-unused-parameter '
 warningFlagsCXX = '-Wno-non-virtual-dtor -Wreorder ' # -Wold-style-cast
 # common flags
 warningFlags = '-W -Wall -Wcast-align -Wcast-qual -Wno-unused-parameter '
 warningFlagsCXX = '-Wno-non-virtual-dtor -Wreorder ' # -Wold-style-cast
-CCFLAGS = '' + warningFlags
-CXXFLAGS = '-pipe -DQ_NO_STLPORT ' + warningFlags + warningFlagsCXX
+# POSIX macro: platform supports posix IEEE Std 1003.1:2001
+# XWINDOWS macro: platform supports X-Windows API
+CCFLAGS = '-DPOSIX -DXWINDOWS ' + warningFlags
+CXXFLAGS = '-pipe -DPOSIX -DXWINDOWS ' + warningFlags + warningFlagsCXX
 CPPPATH = []
 if (BUILD == 'debug'):
        CXXFLAGS += '-g -D_DEBUG '
 CPPPATH = []
 if (BUILD == 'debug'):
        CXXFLAGS += '-g -D_DEBUG '
index e07479658a85e85fc5e41c9cb37ef36ac99ca17c..cce40e14f44c4057e6dd30bcb8a4d4da1d4cdc6b 100644 (file)
@@ -190,7 +190,7 @@ extern char* PLUGIN_NAME;
        return buffer;
 }*/
 
        return buffer;
 }*/
 
-#if defined (__linux__) || defined (__APPLE__)
+#if defined (POSIX)
 // the bCreateConsole parameter is ignored on linux ..
 bool Q_Exec( const char *pCmd, bool bCreateConsole )
 {
 // the bCreateConsole parameter is ignored on linux ..
 bool Q_Exec( const char *pCmd, bool bCreateConsole )
 {
index 85af8335bc4dde0cdfe776cb03b799cb2291848e..f958ad96efab17af21a33c442d78ac8ab2e865ab 100644 (file)
@@ -30,10 +30,12 @@ extern GtkWidget *g_pEditModeAddRadioButton;
 
 char* Q_realpath(const char *path, char *resolved_path, size_t size)
 {
 
 char* Q_realpath(const char *path, char *resolved_path, size_t size)
 {
-#if defined  (__linux__) || defined (__APPLE__)
+#if defined(POSIX)
        return realpath(path, resolved_path);
        return realpath(path, resolved_path);
+#elif defined(WIN32)
+       return _fullpath(resolved_path, path, size);
 #else
 #else
-       return _fullpath(resolved_path, path, size);    
+#error "unsupported platform"
 #endif
 }
 
 #endif
 }
 
index 14d611a5ab8afde2ee31c4d85c06d2a4e6a1b8f9..491482482f3bc0db9ea0b31890bf9a5dd2eef172 100644 (file)
@@ -82,7 +82,7 @@ const char* ExtractFilename( const char* path )
 }
 
 int Q_stricmp (const char *s1, const char *s2) {
 }
 
 int Q_stricmp (const char *s1, const char *s2) {
-       return stricmp( s1, s2 );
+       return string_equal_nocase( s1, s2 );
 }
 
 /*
 }
 
 /*
index ef75a753c8295225e0e1b6b0a643f72945ed9993..2298db60bed79410104a82b73bf1b5f0cf8d11fb 100644 (file)
@@ -298,7 +298,7 @@ GSList *AddToWadList(GSList *wadlist, const char *shadername, const char *wad)
 
   for (GSList *l = wadlist; l != NULL ; l = l->next)
   {
 
   for (GSList *l = wadlist; l != NULL ; l = l->next)
   {
-    if (!stricmp((char *)l->data,wadname))
+    if (string_equal_nocase((char *)l->data,wadname))
     {
       free( wadname );
       return wadlist;
     {
       free( wadname );
       return wadlist;
@@ -334,7 +334,7 @@ void UpdateWadKeyPair( void )
   Sys_Printf("Searching for in-use wad files...\n");
   for(pEpair = pEntity->epairs; pEpair != NULL; pEpair = pEpair->next)
   {
   Sys_Printf("Searching for in-use wad files...\n");
   for(pEpair = pEntity->epairs; pEpair != NULL; pEpair = pEpair->next)
   {
-    if (stricmp(pEpair->key,"wad") == 0)
+    if (string_equal_nocase(pEpair->key,"wad"))
     {
       strcpy(wads,pEpair->value);
       ConvertDOSToUnixName(wads,wads);
     {
       strcpy(wads,pEpair->value);
       ConvertDOSToUnixName(wads,wads);
@@ -415,7 +415,7 @@ void UpdateWadKeyPair( void )
   wads[0] = 0;
   while (wadlist)
   {
   wads[0] = 0;
   while (wadlist)
   {
-    if (stricmp((char *)wadlist->data,"common-hydra.wad") == 0)
+    if (string_equal_nocase((char *)wadlist->data,"common-hydra.wad"))
     {
       Sys_Printf("Skipping radiant-supplied wad file %s\n",(char *)wadlist->data);
     }
     {
       Sys_Printf("Skipping radiant-supplied wad file %s\n",(char *)wadlist->data);
     }
index 23fdd5f64448e34919ad360ef0ee84328de72771..a09ed9ead1a39e9106e08a534d85b0bde7c2fea5 100644 (file)
@@ -32,15 +32,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "os/path.h"
 #include "container/array.h"
 
 #include "os/path.h"
 #include "container/array.h"
 
-#ifdef WIN32
-  #include <windows.h>
-#endif
-#if defined (__linux__) || defined (__APPLE__)
-  #include <unistd.h>
-#endif
 
 
+#if defined (POSIX)
+
+#include <unistd.h>
 
 
-#if defined (__linux__) || defined (__APPLE__)
 bool Q_Exec(const char *cmd, char *cmdline, const char *, bool)
 {
   char fullcmd[2048];
 bool Q_Exec(const char *cmd, char *cmdline, const char *, bool)
 {
   char fullcmd[2048];
@@ -82,9 +78,11 @@ bool Q_Exec(const char *cmd, char *cmdline, const char *, bool)
   }
   return true;
 }
   }
   return true;
 }
-#endif
 
 
-#ifdef WIN32
+#elif defined(WIN32)
+
+#include <windows.h>
+
 // NOTE TTimo windows is VERY nitpicky about the syntax in CreateProcess
 bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole)
 {
 // NOTE TTimo windows is VERY nitpicky about the syntax in CreateProcess
 bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole)
 {
@@ -126,5 +124,6 @@ bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateCon
     return true;
   return false;
 }
     return true;
   return false;
 }
+
 #endif
 
 #endif
 
index cbace0bf857c10125f9b9dd174dee9bebb13cbaf..f7b9466ac143e93c2c10af4ff440d86bac95e69a 100644 (file)
@@ -28,7 +28,69 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 /// \file
 /// \brief Platform-independent GTK clipboard support.
 /// \todo Using GDK_SELECTION_CLIPBOARD fails on win32, so we use the win32 API directly for now.
 /// \file
 /// \brief Platform-independent GTK clipboard support.
 /// \todo Using GDK_SELECTION_CLIPBOARD fails on win32, so we use the win32 API directly for now.
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(WIN32)
+
+const char* c_clipboard_format = "RadiantClippings";
+
+#include <windows.h>
+
+void clipboard_copy(ClipboardCopyFunc copy)
+{
+  BufferOutputStream ostream;
+  copy(ostream);
+
+  bool bClipped = false;
+  UINT nClipboard = ::RegisterClipboardFormat(c_clipboard_format);
+  if (nClipboard > 0)
+  {
+    if (::OpenClipboard(0))
+    {
+      EmptyClipboard();
+      std::size_t length = ostream.size();
+      HANDLE h = ::GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, length + sizeof(std::size_t));
+      if (h != 0)
+      {
+        char *buffer = reinterpret_cast<char*>(::GlobalLock(h));
+        *reinterpret_cast<std::size_t*>(buffer) = length;
+        buffer += sizeof(std::size_t);
+        memcpy(buffer, ostream.data(), length);
+        ::GlobalUnlock(h);
+        ::SetClipboardData(nClipboard, h);
+        ::CloseClipboard();
+        bClipped = true;
+      }
+    }
+  }
+
+  if (!bClipped)
+  {
+    globalOutputStream() << "Unable to register Windows clipboard formats, copy/paste between editors will not be possible\n";
+  }
+}
+
+void clipboard_paste(ClipboardPasteFunc paste)
+{
+  UINT nClipboard = ::RegisterClipboardFormat(c_clipboard_format);
+  if (nClipboard > 0 && ::OpenClipboard(0))
+  {
+    if(IsClipboardFormatAvailable(nClipboard))
+    {
+      HANDLE h = ::GetClipboardData(nClipboard);
+      if(h)
+      {
+        const char *buffer = reinterpret_cast<const char*>(::GlobalLock(h));
+        std::size_t length = *reinterpret_cast<const std::size_t*>(buffer);
+        buffer += sizeof(std::size_t);
+        BufferInputStream istream(buffer, length);
+        paste(istream);
+        ::GlobalUnlock(h);
+      }
+    }
+    ::CloseClipboard();
+  }
+}
+
+#else
 
 #include <gtk/gtkclipboard.h>
 
 
 #include <gtk/gtkclipboard.h>
 
@@ -96,67 +158,5 @@ void clipboard_paste(ClipboardPasteFunc paste)
   gtk_clipboard_request_contents (clipboard, gdk_atom_intern(clipboard_targets[0].target, FALSE), clipboard_received, &g_clipboardPasteFunc);
 }
 
   gtk_clipboard_request_contents (clipboard, gdk_atom_intern(clipboard_targets[0].target, FALSE), clipboard_received, &g_clipboardPasteFunc);
 }
 
-#elif defined(WIN32)
-
-const char* c_clipboard_format = "RadiantClippings";
-
-#include <windows.h>
-
-void clipboard_copy(ClipboardCopyFunc copy)
-{
-  BufferOutputStream ostream;
-  copy(ostream);
-
-  bool bClipped = false;
-  UINT nClipboard = ::RegisterClipboardFormat(c_clipboard_format);
-  if (nClipboard > 0)
-  {
-    if (::OpenClipboard(0))
-    {
-      EmptyClipboard();
-      std::size_t length = ostream.size();
-      HANDLE h = ::GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, length + sizeof(std::size_t));
-      if (h != 0)
-      {
-        char *buffer = reinterpret_cast<char*>(::GlobalLock(h));
-        *reinterpret_cast<std::size_t*>(buffer) = length;
-        buffer += sizeof(std::size_t);
-        memcpy(buffer, ostream.data(), length);
-        ::GlobalUnlock(h);
-        ::SetClipboardData(nClipboard, h);
-        ::CloseClipboard();
-        bClipped = true;
-      }
-    }
-  }
-
-  if (!bClipped)
-  {
-    globalOutputStream() << "Unable to register Windows clipboard formats, copy/paste between editors will not be possible\n";
-  }
-}
-
-void clipboard_paste(ClipboardPasteFunc paste)
-{
-  UINT nClipboard = ::RegisterClipboardFormat(c_clipboard_format);
-  if (nClipboard > 0 && ::OpenClipboard(0))
-  {
-    if(IsClipboardFormatAvailable(nClipboard))
-    {
-      HANDLE h = ::GetClipboardData(nClipboard);
-      if(h)
-      {
-        const char *buffer = reinterpret_cast<const char*>(::GlobalLock(h));
-        std::size_t length = *reinterpret_cast<const std::size_t*>(buffer);
-        buffer += sizeof(std::size_t);
-        BufferInputStream istream(buffer, length);
-        paste(istream);
-        ::GlobalUnlock(h);
-      }
-    }
-    ::CloseClipboard();
-  }
-}
-
 
 #endif
 
 #endif
index 212cc85e790dfaa3bef280de3d6a649d27807479..f5b59010370d30f1805b01b71be2b15b7f0b8073 100644 (file)
@@ -40,7 +40,7 @@ extern "C"
 #endif
 
 // LZ: linux stuff
 #endif
 
 // LZ: linux stuff
-#if defined (__linux__) || defined (__APPLE__)
+#if !defined (WIN32)
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
index 7d8f404d3feafb137165b1036605b2a08be4b75f..558ec211944083a1165921a705cb3f01516f9a00 100644 (file)
@@ -83,10 +83,9 @@ void Net_SetAddressPort(address_t *address, int port)
 int Net_AddressCompare(address_t *addr1, address_t *addr2)
 {
 #ifdef WIN32
 int Net_AddressCompare(address_t *addr1, address_t *addr2)
 {
 #ifdef WIN32
-       return stricmp(addr1->ip, addr2->ip);
-#endif
-#ifdef __linux__
-       return strcasecmp(addr1->ip, addr2->ip);
+  return _stricmp(addr1->ip, addr2->ip);
+#else
+  return strcasecmp(addr1->ip, addr2->ip);
 #endif
 } //end of the function Net_AddressCompare
 //===========================================================================
 #endif
 } //end of the function Net_AddressCompare
 //===========================================================================
index cd8b0aa77b214b06c6611d7fa4f60dc97afb10f7..082b56fafe6f458297684ebba5578f1f19bf7337 100644 (file)
@@ -93,7 +93,7 @@ inline bool path_is_absolute(const char* path)
 #if defined(WIN32)
   return path[0] == '/'
     || (path[0] != '\0' && path[1] == ':'); // local drive
 #if defined(WIN32)
   return path[0] == '/'
     || (path[0] != '\0' && path[1] == ':'); // local drive
-#elif defined(__linux__) || defined(__APPLE__)
+#elif defined(POSIX)
   return path[0] == '/';
 #endif
 }
   return path[0] == '/';
 #endif
 }
index 1d2e74ae48d56f16dbdd624089a94f2974015912..b54792fe874fc201a6a32b66de39956dd02e82d0 100644 (file)
@@ -20,7 +20,7 @@ extern "C"
 #endif
 
 // LZ: linux stuff
 #endif
 
 // LZ: linux stuff
-#if defined (__linux__) || defined (__APPLE__)
+#if !defined (WIN32)
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
index 1478ce7ede3fe55ad92a4d2f1e9bf63902c2ba8b..eacac3d65f7c9e410a74d7247e6b28826fedcae7 100644 (file)
@@ -67,7 +67,7 @@ inline char* Q_StrDup(const char* pStr)
   return strcpy(new char[strlen(pStr)+1], pStr); 
 }
 
   return strcpy(new char[strlen(pStr)+1], pStr); 
 }
 
-#if defined (__linux__) || defined (__APPLE__)
+#if !defined(WIN32)
 #define strcmpi strcasecmp
 #define stricmp strcasecmp
 #define strnicmp strncasecmp
 #define strcmpi strcasecmp
 #define stricmp strcasecmp
 #define strnicmp strncasecmp
index e11dd37291b40c709f3b6357a3b42ab3e85ad1bb..f23eeafd6d769eccacbb50310aeb5ba96be12f03 100644 (file)
@@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
 
-#if defined(__linux__) || defined(__APPLE__)
+#if !defined(WIN32)
 
 // Necessary for proper boolean type declaration
 #include "qertypes.h"
 
 // Necessary for proper boolean type declaration
 #include "qertypes.h"
index 1264a5b1e0c246504004617d1caa6a44df1718ea..d020446c4a4a784cca8e6fe4089177076fa4c7d6 100644 (file)
@@ -548,6 +548,12 @@ copy &quot;$(TargetDir)$(TargetName).pdb&quot;  &quot;$(SolutionDir)install&quot
                        <File\r
                                RelativePath=".\shaders.h">\r
                        </File>\r
                        <File\r
                                RelativePath=".\shaders.h">\r
                        </File>\r
+                       <File\r
+                               RelativePath=".\sockets.cpp">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\sockets.h">\r
+                       </File>\r
                        <File\r
                                RelativePath=".\stacktrace.cpp">\r
                        </File>\r
                        <File\r
                                RelativePath=".\stacktrace.cpp">\r
                        </File>\r
index 6728058768dbd8984b6359f195e8203bd14b2afa..a3bfd43f31e9c38f5bafbcaebf67ee9f2d62aee2 100644 (file)
@@ -72,7 +72,7 @@ const char* environment_get_app_path()
 }
 
 
 }
 
 
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(POSIX)
 
 #include <stdlib.h>
 #include <pwd.h>
 
 #include <stdlib.h>
 #include <pwd.h>
@@ -83,7 +83,7 @@ const char* environment_get_app_path()
 const char* LINK_NAME =
 #if defined (__linux__)
   "/proc/self/exe"
 const char* LINK_NAME =
 #if defined (__linux__)
   "/proc/self/exe"
-#else
+#else // FreeBSD and OSX
   "/proc/curproc/file"
 #endif
 ;
   "/proc/curproc/file"
 #endif
 ;
@@ -147,9 +147,7 @@ void environment_init(int argc, char* argv[])
   }
 }
 
   }
 }
 
-#endif
-
-#ifdef WIN32
+#elif defined(WIN32)
 
 #include <windows.h>
 #include <shfolder.h>
 
 #include <windows.h>
 #include <shfolder.h>
@@ -197,4 +195,6 @@ void environment_init(int argc, char* argv[])
   }
 }
 
   }
 }
 
+#else
+#error "unsupported platform"
 #endif
 #endif
index 66794e7aa228b47708703ae0dd6cc306ed0f76d8..0ff75d1cb1730a5508f0b582b58a4c7a75971968 100644 (file)
@@ -32,9 +32,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #ifdef WIN32
 #define UNICODE
 #include <windows.h>
 #ifdef WIN32
 #define UNICODE
 #include <windows.h>
-#endif
-
-#if defined (__linux__) || defined (__APPLE__)
+#else
 #include <errno.h>
 #include <unistd.h>
 #endif
 #include <errno.h>
 #include <unistd.h>
 #endif
@@ -66,15 +64,6 @@ void Error (const char *error, ...)
 
   strcat( text, "\n" );
 
 
   strcat( text, "\n" );
 
-#if defined (__linux__) || defined (__APPLE__)
-  if (errno != 0)
-  {
-    strcat( text, "errno: " );
-    strcat( text, strerror (errno));
-    strcat( text, "\n");
-  }
-#endif
-
 #ifdef WIN32
   if (GetLastError() != 0)
   {
 #ifdef WIN32
   if (GetLastError() != 0)
   {
@@ -110,8 +99,16 @@ void Error (const char *error, ...)
     strcat( text, "\n");
     LocalFree( lpMsgBuf );
   }
     strcat( text, "\n");
     LocalFree( lpMsgBuf );
   }
+#else
+  if (errno != 0)
+  {
+    strcat( text, "errno: " );
+    strcat( text, strerror (errno));
+    strcat( text, "\n");
+  }
 #endif
 
 #endif
 
+
 #if 0
   // we need to have a current context to call glError()
   if (g_glwindow_globals.d_glBase != 0)
 #if 0
   // we need to have a current context to call glError()
   if (g_glwindow_globals.d_glBase != 0)
index e49d7fd92eba67746410c7762e06f6d32fdcd11f..9b36b72cbcdfae0f56d6ce48f53eafc051295edd 100644 (file)
@@ -186,7 +186,7 @@ void VFS_Destroy()
 
 void HomePaths_Realise()
 {
 
 void HomePaths_Realise()
 {
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(POSIX)
   const char* prefix = g_pGameDescription->getKeyValue("prefix");
   if(!string_empty(prefix)) 
   {
   const char* prefix = g_pGameDescription->getKeyValue("prefix");
   if(!string_empty(prefix)) 
   {
@@ -510,10 +510,10 @@ public:
 const char* const c_library_extension =
 #if defined(WIN32)
 "dll"
 const char* const c_library_extension =
 #if defined(WIN32)
 "dll"
-#elif defined(__linux__)
-"so"
 #elif defined (__APPLE__)
 "dylib"
 #elif defined (__APPLE__)
 "dylib"
+#elif defined(__linux__) || defined (__FreeBSD__)
+"so"
 #endif
 ;
 
 #endif
 ;
 
@@ -3499,7 +3499,7 @@ void MainFrame_Construct()
     const char* ENGINEPATH_ATTRIBUTE =
 #if defined(WIN32)
       "enginepath_win32"
     const char* ENGINEPATH_ATTRIBUTE =
 #if defined(WIN32)
       "enginepath_win32"
-#elif defined(__linux__)
+#elif defined(__linux__) || defined (__FreeBSD__)
       "enginepath_linux"
 #elif defined(__APPLE__)
       "enginepath_macos"
       "enginepath_linux"
 #elif defined(__APPLE__)
       "enginepath_macos"
index 11c10418055492ba44313f4136cbb9c626404d86..a526c608d003cc1e63ed23100d94ec3d08a30aeb 100644 (file)
@@ -78,7 +78,7 @@ void QE_InitVFS()
 
   const char* gamename = gamename_get();
   const char* basegame = basegame_get();
 
   const char* gamename = gamename_get();
   const char* basegame = basegame_get();
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(POSIX)
   const char* userRoot = g_qeglobals.m_userEnginePath.c_str();
 #endif
   const char* globalRoot = EnginePath_get();
   const char* userRoot = g_qeglobals.m_userEnginePath.c_str();
 #endif
   const char* globalRoot = EnginePath_get();
@@ -86,7 +86,7 @@ void QE_InitVFS()
   // if we have a mod dir
   if(!string_equal(gamename, basegame))
   {
   // if we have a mod dir
   if(!string_equal(gamename, basegame))
   {
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(POSIX)
     // ~/.<gameprefix>/<fs_game>
     {
       StringOutputStream userGamePath(256);
     // ~/.<gameprefix>/<fs_game>
     {
       StringOutputStream userGamePath(256);
@@ -103,7 +103,7 @@ void QE_InitVFS()
     }
   }
 
     }
   }
 
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(POSIX)
   // ~/.<gameprefix>/<fs_main>
   {
     StringOutputStream userBasePath(256);
   // ~/.<gameprefix>/<fs_main>
   {
     StringOutputStream userBasePath(256);
@@ -172,7 +172,7 @@ bool ConfirmModified(const char* title)
 
 
 const char* const EXECUTABLE_TYPE = 
 
 
 const char* const EXECUTABLE_TYPE = 
-#if defined(__linux__)
+#if defined(__linux__) || defined (__FreeBSD__)
 "x86"
 #elif defined(__APPLE__)
 "ppc"
 "x86"
 #elif defined(__APPLE__)
 "ppc"
@@ -317,20 +317,21 @@ void RunBSP(const char* name)
     strcat(junkpath, "junk.txt");
 
     char batpath[PATH_MAX];
     strcat(junkpath, "junk.txt");
 
     char batpath[PATH_MAX];
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(POSIX)
     strcpy(batpath, SettingsPath_get());
     strcat(batpath, "qe3bsp.sh");
     strcpy(batpath, SettingsPath_get());
     strcat(batpath, "qe3bsp.sh");
-#endif
-#ifdef WIN32
+#elif defined(WIN32)
     strcpy(batpath, SettingsPath_get());
     strcat(batpath, "qe3bsp.bat");
     strcpy(batpath, SettingsPath_get());
     strcat(batpath, "qe3bsp.bat");
+#else
+#error "unsupported platform"
 #endif
     bool written = false;
     {
       TextFileOutputStream batchFile(batpath);
       if(!batchFile.failed())
       {
 #endif
     bool written = false;
     {
       TextFileOutputStream batchFile(batpath);
       if(!batchFile.failed())
       {
-#if defined (__linux__) || defined (__APPLE__)
+#if defined (POSIX)
         batchFile << "#!/bin/sh \n\n";
 #endif
         BatchCommandListener listener(batchFile, junkpath);
         batchFile << "#!/bin/sh \n\n";
 #endif
         BatchCommandListener listener(batchFile, junkpath);
@@ -340,7 +341,7 @@ void RunBSP(const char* name)
     }
     if(written)
     {
     }
     if(written)
     {
-#if defined (__linux__) || defined (__APPLE__)
+#if defined (POSIX)
       chmod (batpath, 0744);
 #endif
       globalOutputStream() << "Writing the compile script to '" << batpath << "'\n";
       chmod (batpath, 0744);
 #endif
       globalOutputStream() << "Writing the compile script to '" << batpath << "'\n";
index af7d397dcd58d387b1d6846527855e50abb6033f..c1e6b23acd3fab8d7a22188c191ffb3dbbc6b2c9 100644 (file)
@@ -75,7 +75,7 @@ int  ( WINAPI * qwglGetLayerPaletteEntries)(HDC, int, int, int, COLORREF *);
 BOOL ( WINAPI * qwglRealizeLayerPalette)(HDC, int, BOOL);
 BOOL ( WINAPI * qwglSwapLayerBuffers)(HDC, UINT);
 
 BOOL ( WINAPI * qwglRealizeLayerPalette)(HDC, int, BOOL);
 BOOL ( WINAPI * qwglSwapLayerBuffers)(HDC, UINT);
 
-#elif defined (__linux__) || defined (__APPLE__)
+#elif defined (XWINDOWS)
 
 #include <GL/glx.h>
 #include <dlfcn.h>
 
 #include <GL/glx.h>
 #include <dlfcn.h>
@@ -101,6 +101,8 @@ void         (*qglXUseXFont)( Font font, int first, int count, int list );
 void*        (*qglXGetProcAddressARB) (const GLubyte *procName);
 typedef void* (*glXGetProcAddressARBProc) (const GLubyte *procName);
 
 void*        (*qglXGetProcAddressARB) (const GLubyte *procName);
 typedef void* (*glXGetProcAddressARBProc) (const GLubyte *procName);
 
+#else
+#error "unsupported platform"
 #endif
 
 
 #endif
 
 
@@ -108,7 +110,7 @@ void QGL_Shutdown(OpenGLBinding& table)
 {
   globalOutputStream() << "Shutting down OpenGL module...";
 
 {
   globalOutputStream() << "Shutting down OpenGL module...";
 
-#ifdef WIN32
+#if defined(WIN32)
   qwglCopyContext              = 0;
   qwglCreateContext            = 0;
   qwglCreateLayerContext       = 0;
   qwglCopyContext              = 0;
   qwglCreateContext            = 0;
   qwglCreateLayerContext       = 0;
@@ -131,9 +133,7 @@ void QGL_Shutdown(OpenGLBinding& table)
   qwglGetPixelFormat           = 0;
   qwglSetPixelFormat           = 0;
   qwglSwapBuffers              = 0;
   qwglGetPixelFormat           = 0;
   qwglSetPixelFormat           = 0;
   qwglSwapBuffers              = 0;
-#endif
-
-#if defined (__linux__) || defined (__APPLE__)
+#elif defined(XWINDOWS)
   qglXChooseVisual             = 0;
   qglXCreateContext            = 0;
   qglXDestroyContext           = 0;
   qglXChooseVisual             = 0;
   qglXCreateContext            = 0;
   qglXDestroyContext           = 0;
@@ -152,6 +152,8 @@ void QGL_Shutdown(OpenGLBinding& table)
   qglXWaitX                    = 0;
   qglXUseXFont                 = 0;
   qglXGetProcAddressARB        = 0;
   qglXWaitX                    = 0;
   qglXUseXFont                 = 0;
   qglXGetProcAddressARB        = 0;
+#else
+#error "unsupported platform"
 #endif
 
   globalOutputStream() << "Done.\n";
 #endif
 
   globalOutputStream() << "Done.\n";
@@ -236,7 +238,7 @@ typedef int (QGL_DLLEXPORT *QGLFunctionPointer)();
 
 QGLFunctionPointer QGL_getExtensionFunc(const char* symbol)
 {
 
 QGLFunctionPointer QGL_getExtensionFunc(const char* symbol)
 {
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(XWINDOWS)
   //ASSERT_NOTNULL(qglXGetProcAddressARB);
   if (qglXGetProcAddressARB == 0)
   {
   //ASSERT_NOTNULL(qglXGetProcAddressARB);
   if (qglXGetProcAddressARB == 0)
   {
@@ -246,9 +248,11 @@ QGLFunctionPointer QGL_getExtensionFunc(const char* symbol)
   {
     return (QGLFunctionPointer)qglXGetProcAddressARB(reinterpret_cast<const GLubyte*>(symbol));
   }
   {
     return (QGLFunctionPointer)qglXGetProcAddressARB(reinterpret_cast<const GLubyte*>(symbol));
   }
-#else
+#elif defined(WIN32)
   ASSERT_NOTNULL(qwglGetProcAddress);
   return qwglGetProcAddress(symbol);
   ASSERT_NOTNULL(qwglGetProcAddress);
   return qwglGetProcAddress(symbol);
+#else
+#error "unsupported platform"
 #endif
 }
 
 #endif
 }
 
@@ -610,7 +614,7 @@ int QGL_Init(OpenGLBinding& table)
 {
   QGL_clear(table);
 
 {
   QGL_clear(table);
 
-#ifdef WIN32
+#if defined(WIN32)
   qwglCopyContext              = wglCopyContext;
   qwglCreateContext            = wglCreateContext;
   qwglCreateLayerContext       = wglCreateLayerContext;
   qwglCopyContext              = wglCopyContext;
   qwglCreateContext            = wglCreateContext;
   qwglCreateLayerContext       = wglCreateLayerContext;
@@ -633,9 +637,7 @@ int QGL_Init(OpenGLBinding& table)
   qwglGetPixelFormat           = GetPixelFormat;
   qwglSetPixelFormat           = SetPixelFormat;
   qwglSwapBuffers              = SwapBuffers;
   qwglGetPixelFormat           = GetPixelFormat;
   qwglSetPixelFormat           = SetPixelFormat;
   qwglSwapBuffers              = SwapBuffers;
-#endif
-
-#if defined (__linux__) || defined (__APPLE__)
+#elif defined(XWINDOWS)
   qglXChooseVisual             = glXChooseVisual;
   qglXCreateContext            = glXCreateContext;
   qglXDestroyContext           = glXDestroyContext;
   qglXChooseVisual             = glXChooseVisual;
   qglXCreateContext            = glXCreateContext;
   qglXDestroyContext           = glXDestroyContext;
@@ -654,12 +656,12 @@ int QGL_Init(OpenGLBinding& table)
   qglXWaitX                    = glXWaitX;
   qglXUseXFont                 = glXUseXFont;
 //  qglXGetProcAddressARB        = glXGetProcAddressARB; // Utah-GLX fix
   qglXWaitX                    = glXWaitX;
   qglXUseXFont                 = glXUseXFont;
 //  qglXGetProcAddressARB        = glXGetProcAddressARB; // Utah-GLX fix
-  qglXGetProcAddressARB = (glXGetProcAddressARBProc)dlsym(NULL, "glXGetProcAddressARB"); 
-#endif
 
 
-#if defined (__linux__) || defined (__APPLE__)
+  qglXGetProcAddressARB = (glXGetProcAddressARBProc)dlsym(NULL, "glXGetProcAddressARB"); 
   if ((qglXQueryExtension == 0) || (qglXQueryExtension(GDK_DISPLAY(),0,0) != True))
     return 0;
   if ((qglXQueryExtension == 0) || (qglXQueryExtension(GDK_DISPLAY(),0,0) != True))
     return 0;
+#else
+#error "unsupported platform"
 #endif
 
   return 1;
 #endif
 
   return 1;
index 193f3e72d76a60b417563b07cf36763c7147b848..28b5659d4ea51e0f65d10bfa2ecff02b4d6d5f45 100644 (file)
@@ -160,7 +160,7 @@ public:
   }
 };
 
   }
 };
 
-#elif defined(__linux__) || defined (__APPLE__)
+#elif defined(POSIX)
 
 #include <dlfcn.h>
 
 
 #include <dlfcn.h>
 
@@ -198,6 +198,8 @@ public:
   }
 };
 
   }
 };
 
+#else
+#error "unsupported platform"
 #endif
 
 class DynamicLibraryModule
 #endif
 
 class DynamicLibraryModule
diff --git a/radiant/sockets.cpp b/radiant/sockets.cpp
new file mode 100644 (file)
index 0000000..6f4298c
--- /dev/null
@@ -0,0 +1,47 @@
+
+#include "sockets.h"
+
+#if defined(WIN32)
+#include <winsock2.h>
+#elif defined (POSIX)
+#include <sys/time.h>
+#define SOCKET_ERROR -1
+#else
+#error "unsupported platform"
+#endif
+
+#ifdef __APPLE__
+#include <unistd.h>
+#endif
+
+int Net_Wait(socket_t *sock, long sec, long usec)
+{
+// used for select()
+#ifdef WIN32
+  TIMEVAL tout = { sec, usec };
+#endif
+#if defined (POSIX)
+       timeval tout;
+       tout.tv_sec = sec;
+       tout.tv_usec = usec;
+#endif
+
+  // select() will identify if the socket needs an update
+  // if the socket is identified that means there's either a message or the connection has been closed/reset/terminated
+  fd_set readfds;
+  FD_ZERO(&readfds);
+  FD_SET(((unsigned int)sock->socket), &readfds);
+       // from select man page:
+       // n is the highest-numbered descriptor in any of the three sets, plus 1
+       // (no use on windows)
+  switch( select( sock->socket + 1, &readfds, NULL, NULL, &tout ) )
+  {
+  case SOCKET_ERROR:
+    return -1;
+  case 0:
+    return 0;
+  default:
+    return 1;
+  }
+}
+
diff --git a/radiant/sockets.h b/radiant/sockets.h
new file mode 100644 (file)
index 0000000..3bc2274
--- /dev/null
@@ -0,0 +1,14 @@
+
+#if !defined(INCLUDED_SOCKETS_H)
+#define INCLUDED_SOCKETS_H
+
+#include "l_net/l_net.h"
+
+// waits for a socket to become ready
+// returns
+// -1: error
+// 0: timeout
+// 1: ready
+int Net_Wait(socket_t *sock, long sec, long usec);
+
+#endif
index bae03afbacf0d6c56054e45337c4cb0ddfefeaf4..617112e1d1ea392a1b10ec502bda7e9de842c9bf 100644 (file)
@@ -67,7 +67,7 @@ MillisecondTime MillisecondTime::current()
 
 
 
 
 
 
-#elif defined(__linux__) || defined (__APPLE__)
+#elif defined(POSIX)
 
 #include <time.h>
 #include "sys/time.h"
 
 #include <time.h>
 #include "sys/time.h"
index 527643e7cd9ffd61fbc0ab795adfe36efdf17063..382dcd90dcb5558d59619f69e27e339b30bb5fe0 100644 (file)
@@ -33,7 +33,7 @@ bool open_url(const char* url)
 }
 #endif
 
 }
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
 #include <stdlib.h>
 bool open_url(const char* url)
 {
 #include <stdlib.h>
 bool open_url(const char* url)
 {
index 8c243930699fc50c1b4a6a04c241103018262b91..ee8912e0b16b81d33745a7aa9d7c2983624f17ad 100644 (file)
@@ -50,21 +50,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include "points.h"
 #include "feedback.h"
 #include "mainframe.h"
 #include "points.h"
 #include "feedback.h"
 #include "mainframe.h"
-
-
-#ifdef WIN32
-//#include <winsock2.h>
-#endif
-
-#if defined (__linux__) || defined (__APPLE__)
-#include <sys/time.h>
-#define SOCKET_ERROR -1
-#endif
-
-#ifdef __APPLE__
-#include <unistd.h>
-#endif
-
+#include "sockets.h"
 
 void message_flush(message_info_t* self)
 {
 
 void message_flush(message_info_t* self)
 {
@@ -93,7 +79,6 @@ void message_print(message_info_t* self, const char* characters, std::size_t len
 }
 
 
 }
 
 
-#include "l_net/l_net.h"
 #include <glib/gtimer.h>
 #include <glib/garray.h>
 #include "xmlstuff.h"
 #include <glib/gtimer.h>
 #include <glib/garray.h>
 #include "xmlstuff.h"
@@ -614,14 +599,14 @@ void CWatchBSP::DoEBeginStep()
 #if defined(WIN32)
 #define ENGINE_ATTRIBUTE "engine_win32"
 #define MP_ENGINE_ATTRIBUTE "mp_engine_win32"
 #if defined(WIN32)
 #define ENGINE_ATTRIBUTE "engine_win32"
 #define MP_ENGINE_ATTRIBUTE "mp_engine_win32"
-#elif defined(__linux__)
+#elif defined(__linux__) || defined (__FreeBSD__)
 #define ENGINE_ATTRIBUTE "engine_linux"
 #define MP_ENGINE_ATTRIBUTE "mp_engine_linux"
 #elif defined(__APPLE__)
 #define ENGINE_ATTRIBUTE "engine_macos"
 #define MP_ENGINE_ATTRIBUTE "mp_engine_macos"
 #else
 #define ENGINE_ATTRIBUTE "engine_linux"
 #define MP_ENGINE_ATTRIBUTE "mp_engine_linux"
 #elif defined(__APPLE__)
 #define ENGINE_ATTRIBUTE "engine_macos"
 #define MP_ENGINE_ATTRIBUTE "mp_engine_macos"
 #else
-#error "unknown platform"
+#error "unsupported platform"
 #endif
 
 class RunEngineConfiguration
 #endif
 
 class RunEngineConfiguration
@@ -678,22 +663,8 @@ inline void GlobalGameDescription_string_write_mapparameter(StringOutputStream&
 }
 
 
 }
 
 
-#ifdef WIN32
-#include <windows.h>
-#endif
-
 void CWatchBSP::RoutineProcessing()
 {
 void CWatchBSP::RoutineProcessing()
 {
-  // used for select()
-#ifdef WIN32
-    TIMEVAL tout = { 0, 0 };
-#endif
-#if defined (__linux__) || defined (__APPLE__)
-               timeval tout;
-               tout.tv_sec = 0;
-               tout.tv_usec = 0;
-#endif
-
   switch (m_eState)
   {
   case EBeginStep:
   switch (m_eState)
   {
   case EBeginStep:
@@ -732,6 +703,7 @@ void CWatchBSP::RoutineProcessing()
     }
     break;
   case EWatching:
     }
     break;
   case EWatching:
+    {
 #ifdef _DEBUG
     // some debug checks
     if (!m_pInSocket)
 #ifdef _DEBUG
     // some debug checks
     if (!m_pInSocket)
@@ -740,33 +712,16 @@ void CWatchBSP::RoutineProcessing()
       return;
     }
 #endif
       return;
     }
 #endif
-    // select() will identify if the socket needs an update
-    // if the socket is identified that means there's either a message or the connection has been closed/reset/terminated
-    fd_set readfds;
-    int ret;
-    FD_ZERO(&readfds);
-    FD_SET(((unsigned int)m_pInSocket->socket), &readfds);
-               // from select man page:
-               // n is the highest-numbered descriptor in any of the three sets, plus 1
-               // (no use on windows)
-    ret = select( m_pInSocket->socket + 1, &readfds, NULL, NULL, &tout );
-    if (ret == SOCKET_ERROR)
-    {
-      globalOutputStream() << "WARNING: SOCKET_ERROR in CWatchBSP::RoutineProcessing\n";
-      globalOutputStream() << "Terminating the connection.\n";
-      EndMonitoringLoop();
-      return;
-    }
-#ifdef _DEBUG
+
+    int ret = Net_Wait(m_pInSocket, 0, 0);
     if (ret == -1)
     {
     if (ret == -1)
     {
-      // we are non-blocking?? we should never get timeout errors
-      globalOutputStream() << "WARNING: unexpected timeout expired in CWatchBSP::Processing\n";
+      globalOutputStream() << "WARNING: SOCKET_ERROR in CWatchBSP::RoutineProcessing\n";
       globalOutputStream() << "Terminating the connection.\n";
       EndMonitoringLoop();
       return;
     }
       globalOutputStream() << "Terminating the connection.\n";
       EndMonitoringLoop();
       return;
     }
-#endif
+
     if (ret == 1)
     {
       // the socket has been identified, there's something (message or disconnection)
     if (ret == 1)
     {
       // the socket has been identified, there's something (message or disconnection)
@@ -872,6 +827,7 @@ void CWatchBSP::RoutineProcessing()
         }
       }
     }
         }
       }
     }
+    }
     break;
   default:
     break;
     break;
   default:
     break;