# 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 '
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 )
{
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);
+#elif defined(WIN32)
+ return _fullpath(resolved_path, path, size);
#else
- return _fullpath(resolved_path, path, size);
+#error "unsupported platform"
#endif
}
}
int Q_stricmp (const char *s1, const char *s2) {
- return stricmp( s1, s2 );
+ return string_equal_nocase( s1, s2 );
}
/*
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;
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);
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);
}
#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];
}
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)
{
return true;
return false;
}
+
#endif
/// \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>
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
// LZ: linux stuff
-#if defined (__linux__) || defined (__APPLE__)
+#if !defined (WIN32)
#include <stdio.h>
#include <stdlib.h>
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
//===========================================================================
#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
}
#endif
// LZ: linux stuff
-#if defined (__linux__) || defined (__APPLE__)
+#if !defined (WIN32)
#include <stdio.h>
#include <stdlib.h>
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
#include <stdio.h>
#include <stdlib.h>
-#if defined(__linux__) || defined(__APPLE__)
+#if !defined(WIN32)
// Necessary for proper boolean type declaration
#include "qertypes.h"
<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
}
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(POSIX)
#include <stdlib.h>
#include <pwd.h>
const char* LINK_NAME =
#if defined (__linux__)
"/proc/self/exe"
-#else
+#else // FreeBSD and OSX
"/proc/curproc/file"
#endif
;
}
}
-#endif
-
-#ifdef WIN32
+#elif defined(WIN32)
#include <windows.h>
#include <shfolder.h>
}
}
+#else
+#error "unsupported platform"
#endif
#ifdef WIN32
#define UNICODE
#include <windows.h>
-#endif
-
-#if defined (__linux__) || defined (__APPLE__)
+#else
#include <errno.h>
#include <unistd.h>
#endif
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)
{
strcat( text, "\n");
LocalFree( lpMsgBuf );
}
+#else
+ if (errno != 0)
+ {
+ strcat( text, "errno: " );
+ strcat( text, strerror (errno));
+ strcat( text, "\n");
+ }
#endif
+
#if 0
// we need to have a current context to call glError()
if (g_glwindow_globals.d_glBase != 0)
void HomePaths_Realise()
{
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(POSIX)
const char* prefix = g_pGameDescription->getKeyValue("prefix");
if(!string_empty(prefix))
{
const char* const c_library_extension =
#if defined(WIN32)
"dll"
-#elif defined(__linux__)
-"so"
#elif defined (__APPLE__)
"dylib"
+#elif defined(__linux__) || defined (__FreeBSD__)
+"so"
#endif
;
const char* ENGINEPATH_ATTRIBUTE =
#if defined(WIN32)
"enginepath_win32"
-#elif defined(__linux__)
+#elif defined(__linux__) || defined (__FreeBSD__)
"enginepath_linux"
#elif defined(__APPLE__)
"enginepath_macos"
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();
// 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);
}
}
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(POSIX)
// ~/.<gameprefix>/<fs_main>
{
StringOutputStream userBasePath(256);
const char* const EXECUTABLE_TYPE =
-#if defined(__linux__)
+#if defined(__linux__) || defined (__FreeBSD__)
"x86"
#elif defined(__APPLE__)
"ppc"
strcat(junkpath, "junk.txt");
char batpath[PATH_MAX];
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(POSIX)
strcpy(batpath, SettingsPath_get());
strcat(batpath, "qe3bsp.sh");
-#endif
-#ifdef WIN32
+#elif defined(WIN32)
strcpy(batpath, SettingsPath_get());
strcat(batpath, "qe3bsp.bat");
+#else
+#error "unsupported platform"
#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);
}
if(written)
{
-#if defined (__linux__) || defined (__APPLE__)
+#if defined (POSIX)
chmod (batpath, 0744);
#endif
globalOutputStream() << "Writing the compile script to '" << batpath << "'\n";
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>
void* (*qglXGetProcAddressARB) (const GLubyte *procName);
typedef void* (*glXGetProcAddressARBProc) (const GLubyte *procName);
+#else
+#error "unsupported platform"
#endif
{
globalOutputStream() << "Shutting down OpenGL module...";
-#ifdef WIN32
+#if defined(WIN32)
qwglCopyContext = 0;
qwglCreateContext = 0;
qwglCreateLayerContext = 0;
qwglGetPixelFormat = 0;
qwglSetPixelFormat = 0;
qwglSwapBuffers = 0;
-#endif
-
-#if defined (__linux__) || defined (__APPLE__)
+#elif defined(XWINDOWS)
qglXChooseVisual = 0;
qglXCreateContext = 0;
qglXDestroyContext = 0;
qglXWaitX = 0;
qglXUseXFont = 0;
qglXGetProcAddressARB = 0;
+#else
+#error "unsupported platform"
#endif
globalOutputStream() << "Done.\n";
QGLFunctionPointer QGL_getExtensionFunc(const char* symbol)
{
-#if defined (__linux__) || defined (__APPLE__)
+#if defined(XWINDOWS)
//ASSERT_NOTNULL(qglXGetProcAddressARB);
if (qglXGetProcAddressARB == 0)
{
{
return (QGLFunctionPointer)qglXGetProcAddressARB(reinterpret_cast<const GLubyte*>(symbol));
}
-#else
+#elif defined(WIN32)
ASSERT_NOTNULL(qwglGetProcAddress);
return qwglGetProcAddress(symbol);
+#else
+#error "unsupported platform"
#endif
}
{
QGL_clear(table);
-#ifdef WIN32
+#if defined(WIN32)
qwglCopyContext = wglCopyContext;
qwglCreateContext = wglCreateContext;
qwglCreateLayerContext = wglCreateLayerContext;
qwglGetPixelFormat = GetPixelFormat;
qwglSetPixelFormat = SetPixelFormat;
qwglSwapBuffers = SwapBuffers;
-#endif
-
-#if defined (__linux__) || defined (__APPLE__)
+#elif defined(XWINDOWS)
qglXChooseVisual = glXChooseVisual;
qglXCreateContext = glXCreateContext;
qglXDestroyContext = glXDestroyContext;
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;
+#else
+#error "unsupported platform"
#endif
return 1;
}
};
-#elif defined(__linux__) || defined (__APPLE__)
+#elif defined(POSIX)
#include <dlfcn.h>
}
};
+#else
+#error "unsupported platform"
#endif
class DynamicLibraryModule
--- /dev/null
+
+#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;
+ }
+}
+
--- /dev/null
+
+#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
-#elif defined(__linux__) || defined (__APPLE__)
+#elif defined(POSIX)
#include <time.h>
#include "sys/time.h"
}
#endif
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
#include <stdlib.h>
bool open_url(const char* url)
{
#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)
{
}
-#include "l_net/l_net.h"
#include <glib/gtimer.h>
#include <glib/garray.h>
#include "xmlstuff.h"
#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
-#error "unknown platform"
+#error "unsupported platform"
#endif
class RunEngineConfiguration
}
-#ifdef WIN32
-#include <windows.h>
-#endif
-
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:
}
break;
case EWatching:
+ {
#ifdef _DEBUG
// some debug checks
if (!m_pInSocket)
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)
{
- // 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;
}
-#endif
+
if (ret == 1)
{
// the socket has been identified, there's something (message or disconnection)
}
}
}
+ }
break;
default:
break;